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
master
pb 2008-02-15 19:07:48 +00:00
parent 00da3505ae
commit 6acf25bc14
7 changed files with 92 additions and 4 deletions

View File

@ -18,6 +18,7 @@
package com.arsdigita.london.navigation; package com.arsdigita.london.navigation;
import com.arsdigita.bebop.PageState;
import com.arsdigita.categorization.Category; import com.arsdigita.categorization.Category;
@ -33,13 +34,17 @@ import com.arsdigita.persistence.Filter;
import com.arsdigita.persistence.SessionManager; import com.arsdigita.persistence.SessionManager;
import com.arsdigita.persistence.metadata.ObjectType; import com.arsdigita.persistence.metadata.ObjectType;
import com.arsdigita.persistence.metadata.Property;
import com.arsdigita.util.Assert; import com.arsdigita.util.Assert;
import com.arsdigita.util.LockableImpl; import com.arsdigita.util.LockableImpl;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import org.apache.log4j.Logger;
/** /**
* A class for building up a definition of parameters to * A class for building up a definition of parameters to
* later use for a DataCollection of ACSObjects. * 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_excludedTypes = new ArrayList();
private ArrayList m_properties = new ArrayList(); private ArrayList m_properties = new ArrayList();
private String m_dateAttribute = null;
public final void setObjectType(String objectType) { public final void setObjectType(String objectType) {
Assert.unlocked(this); Assert.unlocked(this);
validateObjectType(objectType); validateObjectType(objectType);
@ -79,6 +86,39 @@ public class DataCollectionDefinition extends LockableImpl {
m_excludedTypes.add( specificObjectType ); 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) { private final void validateObjectType(String objectType) {
ObjectType type = SessionManager.getMetadataRoot().getObjectType(objectType); ObjectType type = SessionManager.getMetadataRoot().getObjectType(objectType);
Assert.exists(type, ObjectType.class); Assert.exists(type, ObjectType.class);
@ -134,6 +174,17 @@ public class DataCollectionDefinition extends LockableImpl {
property.addProperty( objects ); 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) { if (m_ordering.size() > 0) {
Iterator orders = m_ordering.iterator(); Iterator orders = m_ordering.iterator();
while (orders.hasNext()) { while (orders.hasNext()) {

View File

@ -41,6 +41,7 @@ import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -96,6 +97,10 @@ public class DataCollectionRenderer extends LockableImpl {
m_wrapAttributes = wrapAttributes; m_wrapAttributes = wrapAttributes;
} }
public List getAttributes () {
return m_attributes;
}
/** /**
* @pageNumber current page, starting from 1 * @pageNumber current page, starting from 1
*/ */

View File

@ -18,6 +18,8 @@
package com.arsdigita.london.navigation; package com.arsdigita.london.navigation;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.RequestLocal;
import com.arsdigita.categorization.Category; import com.arsdigita.categorization.Category;
import com.arsdigita.categorization.CategoryCollection; import com.arsdigita.categorization.CategoryCollection;
import com.arsdigita.domain.DataObjectNotFoundException; import com.arsdigita.domain.DataObjectNotFoundException;
@ -81,6 +83,13 @@ public final class NavigationConfig extends AbstractConfig {
private Category m_defaultCategoryRoot = null; 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 NavigationModel m_defaultModel = null;
private TreeCatProvider m_treeCatProvider = null; private TreeCatProvider m_treeCatProvider = null;
@ -287,7 +296,21 @@ public final class NavigationConfig extends AbstractConfig {
* in config * in config
* @return * @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) { if (s_fixedDateOrderCats == null) {
populateFixedDateOrderCats(); populateFixedDateOrderCats();
} }

View File

@ -58,6 +58,11 @@ public abstract class AbstractObjectList
protected DataCollection getObjects(HttpServletRequest request, protected DataCollection getObjects(HttpServletRequest request,
HttpServletResponse response) { 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()); return m_definition.getDataCollection(getModel());
} }

View File

@ -40,7 +40,7 @@ public class DateOrderedCategoryComponent extends SimpleComponent {
public void generateXML(PageState state, Element p) { public void generateXML(PageState state, Element p) {
Element content = Navigation.newElement("dateOrderCategories"); Element content = Navigation.newElement("dateOrderCategories");
exportAttributes(content); exportAttributes(content);
Iterator it = Navigation.getConfig().getDateOrderedCategories().iterator(); Iterator it = Navigation.getConfig().getDateOrderedCategories(state).iterator();
while(it.hasNext()) { while(it.hasNext()) {
Element categoryElement = content.newChildElement(Navigation.newElement("category")); Element categoryElement = content.newChildElement(Navigation.newElement("category"));
String[] category = StringUtils.split((String)it.next(), ':'); String[] category = StringUtils.split((String)it.next(), ':');

View File

@ -79,6 +79,10 @@ public class GreetingItem extends AbstractComponent {
if (PermissionService.checkPermission(edit)) { if (PermissionService.checkPermission(edit)) {
content.addAttribute("canEdit", "true"); 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; ContentBundle bundle = (ContentBundle)item;
ContentItem baseItem = bundle.getPrimaryInstance(); ContentItem baseItem = bundle.getPrimaryInstance();

View File

@ -12,8 +12,8 @@
<xsl:for-each select="nav:item"> <xsl:for-each select="nav:item">
<a> <a>
<xsl:attribute name="href"><xsl:value-of select="nav:path" /></xsl:attribute> <xsl:attribute name="href"><xsl:value-of select="nav:path" /></xsl:attribute>
<xsl:attribute name="title"><xsl:value-of select="nav:attribute[@name='title']" /></xsl:attribute> <xsl:attribute name="title"><xsl:value-of select="nav:attribute[@name='displayName']" /></xsl:attribute>
<xsl:value-of select="nav:attribute[@name='title']" /> <xsl:value-of select="nav:attribute[@name='displayName']" />
</a> </a>
<span class="hide">|</span> <span class="hide">|</span>
</xsl:for-each> </xsl:for-each>