|
From: <cgy...@vh...> - 2006-06-22 15:12:40
|
Author: cgyg9330
Date: 2006-06-22 17:07:41 +0200 (Thu, 22 Jun 2006)
New Revision: 1234
Added:
trunk/ccm-ldn-navigation/src/com/arsdigita/london/navigation/ui/DateOrderedCategoryComponent.java
Modified:
trunk/ccm-ldn-navigation/src/com/arsdigita/london/navigation/NavigationConfig.java
trunk/ccm-ldn-navigation/src/com/arsdigita/london/navigation/NavigationConfig_parameter.properties
trunk/ccm-ldn-navigation/web/packages/navigation/templates/default.jsp
Log:
Integrated patch from SF: [ 1474127 ] date order categories
Modified: trunk/ccm-ldn-navigation/src/com/arsdigita/london/navigation/NavigationConfig.java
===================================================================
--- trunk/ccm-ldn-navigation/src/com/arsdigita/london/navigation/NavigationConfig.java 2006-06-22 14:05:49 UTC (rev 1233)
+++ trunk/ccm-ldn-navigation/src/com/arsdigita/london/navigation/NavigationConfig.java 2006-06-22 15:07:41 UTC (rev 1234)
@@ -19,12 +19,16 @@
package com.arsdigita.london.navigation;
import com.arsdigita.categorization.Category;
+import com.arsdigita.categorization.CategoryCollection;
+import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.runtime.AbstractConfig;
import com.arsdigita.util.Assert;
+import com.arsdigita.util.StringUtils;
import com.arsdigita.util.UncheckedWrapperException;
import com.arsdigita.util.parameter.Parameter;
import com.arsdigita.util.parameter.BooleanParameter;
import com.arsdigita.util.parameter.IntegerParameter;
+import com.arsdigita.util.parameter.StringArrayParameter;
import com.arsdigita.util.parameter.StringParameter;
import com.arsdigita.util.parameter.ClassParameter;
import com.arsdigita.util.parameter.URLParameter;
@@ -34,8 +38,12 @@
import java.io.InputStream;
import java.io.IOException;
+import java.math.BigDecimal;
import java.net.MalformedURLException;
import java.net.URL;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
import java.lang.reflect.Constructor;
@@ -57,6 +65,11 @@
private final Parameter m_traversalAdapters;
private final Parameter m_categoryMenuShowNephews;
private final Parameter m_categoryMenuShowGrandChildren;
+ private final Parameter m_dateOrderCategories;
+ private final Parameter m_topLevelDateOrderCategories;
+
+
+ private static Set s_fixedDateOrderCats = null;
private Category m_defaultCategoryRoot = null;
@@ -103,6 +116,17 @@
("com.arsdigita.london.navigation.category_menu_show_grand_children",
Parameter.OPTIONAL, new Boolean(false));
+ m_dateOrderCategories =
+ new StringArrayParameter(
+ "com.arsdigita.london.navigation.date_order_categories",
+ Parameter.OPTIONAL,
+ new String[0]);
+
+ m_topLevelDateOrderCategories =
+ new StringArrayParameter(
+ "com.arsdigita.london.navigation.top_level_date_order_categories",
+ Parameter.OPTIONAL,
+ new String[0]);
register(m_indexPageCacheLifetime);
register(m_generateItemURL);
register(m_defaultTemplate);
@@ -114,6 +138,8 @@
register(m_traversalAdapters);
register(m_categoryMenuShowNephews);
register(m_categoryMenuShowGrandChildren);
+ register(m_dateOrderCategories);
+ register(m_topLevelDateOrderCategories);
loadInfo();
}
@@ -196,4 +222,88 @@
public final boolean getCategoryMenuShowGrandChildren() {
return ((Boolean)get(m_categoryMenuShowGrandChildren)).booleanValue();
}
+
+ /**
+ * retrieve a collection of categories to order by date. Collection includes
+ * categories directly specified as date ordered and also all subcategories of
+ * categories specified as being top level date ordered categories
+ * in config
+ * @return
+ */
+ public final Collection getDateOrderedCategories() {
+ if (s_fixedDateOrderCats == null) {
+ populateFixedDateOrderCats();
+ }
+
+ String[] topLevelCats = (String[]) get(m_topLevelDateOrderCategories);
+ Set allCats = new HashSet();
+ allCats.addAll(s_fixedDateOrderCats);
+ for (int i = 0; i < topLevelCats.length; i++) {
+ try {
+
+ String[] categoryArray = StringUtils.split(topLevelCats[i], ':');
+ String order = "";
+ if (categoryArray.length > 1) {
+ order = ":" + categoryArray[1];
+ }
+ Category topLevelCat = new Category(new BigDecimal(categoryArray[0]));
+ s_log.debug("retrieved top level category " + topLevelCat);
+ Set childCats = new HashSet();
+ CategoryCollection children = topLevelCat.getDescendants();
+ while (children.next()) {
+ BigDecimal id = children.getCategory().getID();
+ childCats.add(id.toString() + order);
+ }
+
+ allCats.addAll(childCats);
+ } catch (DataObjectNotFoundException e) {
+ // non existent category id specified in configuration. Output warning to
+ // logs and continue
+ s_log.warn("Category with id " + topLevelCats[i] +
+ " specified in configuration as a top level date order category, but the category" +
+ "does not exist");
+ } catch (NumberFormatException e) {
+ // non number specified in configuration. Output warning to
+ // logs and continue
+ s_log.warn("Category with id " + topLevelCats[i] +
+ " specified in configuration as a top level date order category, but this is not a valid number");
+ }
+
+ }
+ return allCats;
+
+ }
+
+ // synchronised because set isn't - potential to
+ // create and cache very odd set if navigation page is accessed
+ // concurrently first time after server restart
+ private synchronized void populateFixedDateOrderCats() {
+
+ String[] catArray = (String[]) get(m_dateOrderCategories);
+ s_fixedDateOrderCats = new HashSet();
+ for (int i = 0; i < catArray.length; i++) {
+ try {
+ // don't need to do this, as including invalid or non existent
+ // ids will not have any adverse effects, but this gives us a chance to
+ // provide some warning to the users when they find that a category
+ // they expected to be date ordered isn't because they mistyped etc.
+ // This only occurs once, first time navigation page is accessed after
+ // server restart
+ String[] category = StringUtils.split(catArray[i], ':');
+ Category cat = new Category(new BigDecimal(category[0]));
+ } catch (DataObjectNotFoundException e) {
+ // non existent category id specified in configuration. Output warning to
+ // logs and continue
+ s_log.warn("Category with id " + catArray[i] +
+ " specified in configuration as a date ordered category, but the category" +
+ "does not exist");
+ } catch (NumberFormatException e) {
+ // non number specified in configuration. Output warning to
+ // logs and continue
+ s_log.warn("Category with id " + catArray[i] +
+ " specified in configuration as a date ordered category, but this is not a valid number");
+ }
+ s_fixedDateOrderCats.add(catArray[i]);
+ }
+ }
}
Modified: trunk/ccm-ldn-navigation/src/com/arsdigita/london/navigation/NavigationConfig_parameter.properties
===================================================================
--- trunk/ccm-ldn-navigation/src/com/arsdigita/london/navigation/NavigationConfig_parameter.properties 2006-06-22 14:05:49 UTC (rev 1233)
+++ trunk/ccm-ldn-navigation/src/com/arsdigita/london/navigation/NavigationConfig_parameter.properties 2006-06-22 15:07:41 UTC (rev 1234)
@@ -52,3 +52,13 @@
com.arsdigita.london.navigation.category_menu_show_grand_children.purpose=Whether CategoryMenu should display the categories which are grand children to the current category
com.arsdigita.london.navigation.category_menu_show_grand_children.example=false
com.arsdigita.london.navigation.category_menu_show_grand_children.format=[boolean]
+
+com.arsdigita.london.navigation.date_order_categories.title=Date Order Categories
+com.arsdigita.london.navigation.date_order_categories.purpose=Specify which nav categories should have items sorted by date
+com.arsdigita.london.navigation.date_order_categories.example=68594,345:ascending,687493
+com.arsdigita.london.navigation.date_order_categories.format=[string,string,string]
+
+com.arsdigita.london.navigation.top_level_date_order_categories.title=Top level date order categories
+com.arsdigita.london.navigation.top_level_date_order_categories.purpose=Categories which will have all their children date ordered
+com.arsdigita.london.navigation.top_level_date_order_categories.example=68594,345:ascending
+com.arsdigita.london.navigation.top_level_date_order_categories.format=[string,string,string]
Added: trunk/ccm-ldn-navigation/src/com/arsdigita/london/navigation/ui/DateOrderedCategoryComponent.java
===================================================================
--- trunk/ccm-ldn-navigation/src/com/arsdigita/london/navigation/ui/DateOrderedCategoryComponent.java 2006-06-22 14:05:49 UTC (rev 1233)
+++ trunk/ccm-ldn-navigation/src/com/arsdigita/london/navigation/ui/DateOrderedCategoryComponent.java 2006-06-22 15:07:41 UTC (rev 1234)
@@ -0,0 +1,60 @@
+/*
+* Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public License
+* as published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+package com.arsdigita.london.navigation.ui;
+
+import java.util.Iterator;
+import java.util.List;
+
+
+import com.arsdigita.bebop.PageState;
+import com.arsdigita.bebop.SimpleComponent;
+import com.arsdigita.london.navigation.Navigation;
+import com.arsdigita.util.StringUtils;
+import com.arsdigita.xml.Element;
+
+/**
+ * @author chr...@we...
+ *
+ * Simple Component to output categories specified as date ordered in configuration.
+ * each category also has an order that should be used in stylesheet
+ *
+ */
+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();
+ while(it.hasNext()) {
+ Element categoryElement = content.newChildElement(Navigation.newElement("category"));
+ String[] category = StringUtils.split((String)it.next(), ':');
+ categoryElement.addAttribute("id", category[0]);
+ String order = "descending";
+ if (category.length > 1) {
+ order = category[1];
+
+ }
+ categoryElement.addAttribute("order", order);
+ }
+ p.addContent(content);
+
+ }
+
+
+}
Modified: trunk/ccm-ldn-navigation/web/packages/navigation/templates/default.jsp
===================================================================
--- trunk/ccm-ldn-navigation/web/packages/navigation/templates/default.jsp 2006-06-22 14:05:49 UTC (rev 1233)
+++ trunk/ccm-ldn-navigation/web/packages/navigation/templates/default.jsp 2006-06-22 15:07:41 UTC (rev 1234)
@@ -43,10 +43,13 @@
((com.arsdigita.london.navigation.ui.object.SimpleObjectList) itemList).getRenderer().setPageSize(30);
((com.arsdigita.london.navigation.ui.object.SimpleObjectList) itemList).getRenderer().addAttribute("objectType");
((com.arsdigita.london.navigation.ui.object.SimpleObjectList) itemList).getRenderer().addAttribute("title");
+ ((com.arsdigita.london.navigation.ui.object.SimpleObjectList) itemList).getRenderer().addAttribute("launchDate");
</jsp:scriptlet>
<define:component name="assignedTerms"
classname="com.arsdigita.london.navigation.ui.CategoryIndexAssignedTerms"/>
+ <define:component name="dateOrderCategories"
+ classname="com.arsdigita.london.navigation.ui.DateOrderedCategoryComponent"/>
</define:page>
<show:all/>
|