From 6acf25bc14a3abe20f1ec3b0fef244811b926858 Mon Sep 17 00:00:00 2001 From: pb Date: Fri, 15 Feb 2008 19:07:48 +0000 Subject: [PATCH] incorporating APLAWS patches 166-168: r1666 | chrisg23 | 2007-09-19 12:40:53 +0200 (Mi, 19 Sep 2007) Currently date order categories work fine unless you have more than one page of objects - as the ordering is only done in xsl, when you have pagination, the java side returns a subset of objects ordered according to order set in jsp page (eg alphabetical) and then that subset is date ordered, but that means that as you page back and forth the date ordering is completely wrong. This change fixes that by enforcing date ordering in the java code if the current category is date ordered. Different object types have different attribute names for date - and only the renderer knows which attributes are available. I have added a method to the definition that gives the definition a reference to the renderer - the renderer now returns a list of attributes which the definition looks through and finds the first attribute that is of type date and uses that as the basis for date ordering if the current category is date ordered.If there is more than one date ordered attribute output in the list, then ensure the one used for ordering in xsl is the first one specified in jsp. I could have just made a setDateOrderAttribute method that takes a string attribute name argument and called that from the jsp page - it would have made the code quite a bit simpler. I chose this route to ensure that the date attribute specified for ordering in java was present in the datacollection, and so that there is no need to edit existing jsp pages. That is probably being overcautious though. Never mind, this works fine anyway - maybe one day I will refactor it to use the simpler approach ------------------------------------------------------------------------ r1667 | chrisg23 | 2007-09-19 12:48:36 +0200 (Mi, 19 Sep 2007) Continuation of changes in r1651 - output publisher flag on index pages too ------------------------------------------------------------------------ r1668 | chrisg23 | 2007-09-19 12:53:08 +0200 (Mi, 19 Sep 2007) See r1661 - ensure that this version of object-list.xsl caters for all listed objects, not just content pages, by referring to displayName (defined in ACSObject and now output on all object lists in default navigation jsp page git-svn-id: https://svn.libreccm.org/ccm/trunk@28 8810af33-2d31-482b-a856-94f89814c4df --- .../navigation/DataCollectionDefinition.java | 51 +++++++++++++++++++ .../navigation/DataCollectionRenderer.java | 5 ++ .../london/navigation/NavigationConfig.java | 25 ++++++++- .../navigation/ui/AbstractObjectList.java | 5 ++ .../ui/DateOrderedCategoryComponent.java | 2 +- .../london/navigation/ui/GreetingItem.java | 4 ++ .../apps/navigation/lib/object-list.xsl | 4 +- 7 files changed, 92 insertions(+), 4 deletions(-) diff --git a/ccm-ldn-navigation/src/com/arsdigita/london/navigation/DataCollectionDefinition.java b/ccm-ldn-navigation/src/com/arsdigita/london/navigation/DataCollectionDefinition.java index d938ef1be..80db78d6b 100755 --- a/ccm-ldn-navigation/src/com/arsdigita/london/navigation/DataCollectionDefinition.java +++ b/ccm-ldn-navigation/src/com/arsdigita/london/navigation/DataCollectionDefinition.java @@ -18,6 +18,7 @@ package com.arsdigita.london.navigation; +import com.arsdigita.bebop.PageState; import com.arsdigita.categorization.Category; @@ -33,13 +34,17 @@ import com.arsdigita.persistence.Filter; import com.arsdigita.persistence.SessionManager; import com.arsdigita.persistence.metadata.ObjectType; +import com.arsdigita.persistence.metadata.Property; import com.arsdigita.util.Assert; import com.arsdigita.util.LockableImpl; import java.util.ArrayList; +import java.util.Date; import java.util.Iterator; +import org.apache.log4j.Logger; + /** * A class for building up a definition of parameters to * later use for a DataCollection of ACSObjects. @@ -58,6 +63,8 @@ public class DataCollectionDefinition extends LockableImpl { private ArrayList m_excludedTypes = new ArrayList(); private ArrayList m_properties = new ArrayList(); + private String m_dateAttribute = null; + public final void setObjectType(String objectType) { Assert.unlocked(this); validateObjectType(objectType); @@ -79,6 +86,39 @@ public class DataCollectionDefinition extends LockableImpl { m_excludedTypes.add( specificObjectType ); } + private static Logger s_log = Logger.getLogger(DataCollectionDefinition.class); + + public void setDateAttribute (DataCollectionRenderer renderer) { + ObjectType type = SessionManager.getMetadataRoot().getObjectType(m_objectType); + s_log.debug("set date attribute for collection of " + type.getQualifiedName()); + if (s_log.isDebugEnabled()) { + Iterator properties = type.getProperties(); + while (properties.hasNext()) { + Property prop = (Property)properties.next(); + s_log.debug("object has property " + prop.getName() + " of class " + prop.getJavaClass().getName()); + } + } + Iterator it = (renderer.getAttributes().iterator()); + while (it.hasNext()) { + String attribute = (String)it.next(); + s_log.debug("renderer is rendering attribute: " + attribute); + Property property = type.getProperty(attribute); + s_log.debug("property of object: " + property); + if (property != null) { + s_log.debug("Property class is " + property.getJavaClass().getName()); + } + if (property != null && property.getJavaClass().getName().equals(Date.class.getName())) { + m_dateAttribute = attribute; + // if more than one date attribute is specified for the type included in this + // definition, then we cannot determine in the code which is to be used as the + // basis for ordering in XSL - therefore return the first encountered date. + // User can control which of the dates is used as basis for sorting by specifying + // that date attribute first in the navigation jsp + break; + } + } + } + private final void validateObjectType(String objectType) { ObjectType type = SessionManager.getMetadataRoot().getObjectType(objectType); Assert.exists(type, ObjectType.class); @@ -134,6 +174,17 @@ public class DataCollectionDefinition extends LockableImpl { property.addProperty( objects ); } + // for date ordered categories, if pagination occurs, we need to ensure + // that primary ordering is the date attribute included in the renderer + // if there is one + s_log.debug("Category is " + model.getCategory().getID() + ": " + model.getCategory().getName()); + s_log.debug("getting data collection. Is category date ordered? " + + Navigation.getConfig().isDateOrderedCategory(model.getCategory(), PageState.getPageState()) + + " date attribute has been set to " + m_dateAttribute); + if (Navigation.getConfig().isDateOrderedCategory(model.getCategory(), PageState.getPageState()) && m_dateAttribute != null) { + objects.addOrder(m_dateAttribute + " desc"); + } + if (m_ordering.size() > 0) { Iterator orders = m_ordering.iterator(); while (orders.hasNext()) { diff --git a/ccm-ldn-navigation/src/com/arsdigita/london/navigation/DataCollectionRenderer.java b/ccm-ldn-navigation/src/com/arsdigita/london/navigation/DataCollectionRenderer.java index 2877feb06..f96cf7b8a 100755 --- a/ccm-ldn-navigation/src/com/arsdigita/london/navigation/DataCollectionRenderer.java +++ b/ccm-ldn-navigation/src/com/arsdigita/london/navigation/DataCollectionRenderer.java @@ -41,6 +41,7 @@ import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.Iterator; +import java.util.List; import org.apache.log4j.Logger; @@ -96,6 +97,10 @@ public class DataCollectionRenderer extends LockableImpl { m_wrapAttributes = wrapAttributes; } + public List getAttributes () { + return m_attributes; + } + /** * @pageNumber current page, starting from 1 */ diff --git a/ccm-ldn-navigation/src/com/arsdigita/london/navigation/NavigationConfig.java b/ccm-ldn-navigation/src/com/arsdigita/london/navigation/NavigationConfig.java index e58eced17..902155df4 100755 --- a/ccm-ldn-navigation/src/com/arsdigita/london/navigation/NavigationConfig.java +++ b/ccm-ldn-navigation/src/com/arsdigita/london/navigation/NavigationConfig.java @@ -18,6 +18,8 @@ package com.arsdigita.london.navigation; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.RequestLocal; import com.arsdigita.categorization.Category; import com.arsdigita.categorization.CategoryCollection; import com.arsdigita.domain.DataObjectNotFoundException; @@ -81,6 +83,13 @@ public final class NavigationConfig extends AbstractConfig { private Category m_defaultCategoryRoot = null; + // maybe 2 lookups in a single request so prevent double overhead + private RequestLocal m_allDateOrderCategories = new RequestLocal () { + public Object initialValue (PageState state) { + return getCurrentDateOrderCategories(); + } + }; + private NavigationModel m_defaultModel = null; private TreeCatProvider m_treeCatProvider = null; @@ -287,7 +296,21 @@ public final class NavigationConfig extends AbstractConfig { * in config * @return */ - public final Collection getDateOrderedCategories() { + public Collection getDateOrderedCategories(PageState state) { + Collection categories = null; + if (state == null) { + categories = getCurrentDateOrderCategories(); + } else { + categories = (Collection)m_allDateOrderCategories.get(state); + } + return categories; + } + + public boolean isDateOrderedCategory (Category cat, PageState state) { + return getDateOrderedCategories(state).contains(cat.getID().toString()); + } + + private Collection getCurrentDateOrderCategories () { if (s_fixedDateOrderCats == null) { populateFixedDateOrderCats(); } diff --git a/ccm-ldn-navigation/src/com/arsdigita/london/navigation/ui/AbstractObjectList.java b/ccm-ldn-navigation/src/com/arsdigita/london/navigation/ui/AbstractObjectList.java index f7b1a9286..f932098ba 100755 --- a/ccm-ldn-navigation/src/com/arsdigita/london/navigation/ui/AbstractObjectList.java +++ b/ccm-ldn-navigation/src/com/arsdigita/london/navigation/ui/AbstractObjectList.java @@ -58,6 +58,11 @@ public abstract class AbstractObjectList protected DataCollection getObjects(HttpServletRequest request, HttpServletResponse response) { + // definition needs to know if the renderer is rendering a date + // attribute so that it can decide whether to order by date for + // a date order category + m_definition.setDateAttribute(m_renderer); + return m_definition.getDataCollection(getModel()); } diff --git a/ccm-ldn-navigation/src/com/arsdigita/london/navigation/ui/DateOrderedCategoryComponent.java b/ccm-ldn-navigation/src/com/arsdigita/london/navigation/ui/DateOrderedCategoryComponent.java index 73b63ddcf..7393c1984 100755 --- a/ccm-ldn-navigation/src/com/arsdigita/london/navigation/ui/DateOrderedCategoryComponent.java +++ b/ccm-ldn-navigation/src/com/arsdigita/london/navigation/ui/DateOrderedCategoryComponent.java @@ -40,7 +40,7 @@ public class DateOrderedCategoryComponent extends SimpleComponent { public void generateXML(PageState state, Element p) { Element content = Navigation.newElement("dateOrderCategories"); exportAttributes(content); - Iterator it = Navigation.getConfig().getDateOrderedCategories().iterator(); + Iterator it = Navigation.getConfig().getDateOrderedCategories(state).iterator(); while(it.hasNext()) { Element categoryElement = content.newChildElement(Navigation.newElement("category")); String[] category = StringUtils.split((String)it.next(), ':'); diff --git a/ccm-ldn-navigation/src/com/arsdigita/london/navigation/ui/GreetingItem.java b/ccm-ldn-navigation/src/com/arsdigita/london/navigation/ui/GreetingItem.java index a48cddc01..479d0100c 100755 --- a/ccm-ldn-navigation/src/com/arsdigita/london/navigation/ui/GreetingItem.java +++ b/ccm-ldn-navigation/src/com/arsdigita/london/navigation/ui/GreetingItem.java @@ -79,6 +79,10 @@ public class GreetingItem extends AbstractComponent { if (PermissionService.checkPermission(edit)) { content.addAttribute("canEdit", "true"); } + PermissionDescriptor publish = new PermissionDescriptor(PrivilegeDescriptor.get(SecurityManager.CMS_PUBLISH), item, currentParty); + if (PermissionService.checkPermission(publish)) { + content.addAttribute("canPublish", "true"); + } ContentBundle bundle = (ContentBundle)item; ContentItem baseItem = bundle.getPrimaryInstance(); diff --git a/ccm-ldn-navigation/web/__ccm__/apps/navigation/lib/object-list.xsl b/ccm-ldn-navigation/web/__ccm__/apps/navigation/lib/object-list.xsl index d3e5205ab..b35077ac6 100755 --- a/ccm-ldn-navigation/web/__ccm__/apps/navigation/lib/object-list.xsl +++ b/ccm-ldn-navigation/web/__ccm__/apps/navigation/lib/object-list.xsl @@ -12,8 +12,8 @@ - - + + |