From: <fa...@vh...> - 2005-09-12 15:15:18
|
Author: fabrice Date: 2005-09-12 17:06:00 +0200 (Mon, 12 Sep 2005) New Revision: 793 Modified: ccm-ldn-portal/trunk/src/com/arsdigita/london/portal/ui/portlet/ContentDirectoryPortletRenderer.java Log: Output the sortKey Modified: ccm-ldn-portal/trunk/src/com/arsdigita/london/portal/ui/portlet/ContentDirectoryPortletRenderer.java =================================================================== --- ccm-ldn-portal/trunk/src/com/arsdigita/london/portal/ui/portlet/ContentDirectoryPortletRenderer.java 2005-09-12 15:05:35 UTC (rev 792) +++ ccm-ldn-portal/trunk/src/com/arsdigita/london/portal/ui/portlet/ContentDirectoryPortletRenderer.java 2005-09-12 15:06:00 UTC (rev 793) @@ -15,33 +15,29 @@ package com.arsdigita.london.portal.ui.portlet; +import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.portal.AbstractPortletRenderer; import com.arsdigita.categorization.Category; import com.arsdigita.categorization.CategoryCollection; - +import com.arsdigita.london.portal.portlet.ContentDirectoryPortlet; +import com.arsdigita.london.portal.ui.PortalConstants; import com.arsdigita.persistence.OID; - -import com.arsdigita.bebop.PageState; - +import com.arsdigita.portal.Portlet; import com.arsdigita.web.URL; import com.arsdigita.web.ParameterMap; import com.arsdigita.web.Web; - import com.arsdigita.xml.Element; import com.arsdigita.xml.XML; - - -import com.arsdigita.london.portal.portlet.ContentDirectoryPortlet; -import com.arsdigita.london.portal.ui.PortalConstants; -import com.arsdigita.bebop.portal.AbstractPortletRenderer; - import org.apache.log4j.Logger; import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Iterator; -import java.util.List; -import java.util.ArrayList; +import java.util.TreeSet; public class ContentDirectoryPortletRenderer extends AbstractPortletRenderer { @@ -69,6 +65,7 @@ CategoryCollection cats = root.getDescendants(); cats.addEqualsFilter("parents.link.relationType", "child"); + cats.addPath("parents.link.sortKey"); cats.addPath("parents.id"); cats.addOrder("parents.link.sortKey"); @@ -77,13 +74,14 @@ Category cat = cats.getCategory(); BigDecimal parentID = (BigDecimal)cats.get("parents.id"); - List childList = (List)children.get(parentID); + TreeSet childList = (TreeSet) children.get(parentID); if (childList == null) { - childList = new ArrayList(); + childList = new TreeSet(); children.put(parentID, childList); } - childList.add(cat); + childList.add(new CategorySortKeyPair + (cat, (BigDecimal)cats.get("parents.link.sortKey"))); } processChildren(element, root, children, 1, m_portlet.getDepth()); @@ -95,13 +93,15 @@ int depth, int maxDepth) { if (depth <= maxDepth) { - List c = (List)children.get(cat.getID()); + TreeSet c = (TreeSet) children.get(cat.getID()); if (c != null) { Iterator i = c.iterator(); while (i.hasNext()) { - Category child = (Category)i.next(); + CategorySortKeyPair pair = (CategorySortKeyPair) i.next(); + Category child = pair.getCategory(); + BigDecimal childSortKey = pair.getSortKey(); if (child.isEnabled()) { - Element el = generateCategory(child, depth); + Element el = generateCategory(child, depth, childSortKey); parent.addContent(el); processChildren(el, child, children, depth+1, maxDepth); @@ -112,7 +112,8 @@ } public Element generateCategory(Category cat, - int depth) { + int depth, + BigDecimal childSortKey) { Element el = new Element(depth == 1 ? "portlet:contentDirectoryEntry" : "portlet:contentDirectorySubentry", @@ -123,6 +124,7 @@ el.addAttribute("description", cat.getDescription()); el.addAttribute("isAbstract", cat.isAbstract() ? "1" : "0"); el.addAttribute("url", redirectURL(cat.getOID())); + el.addAttribute("sortKey", XML.format(childSortKey)); return el; } @@ -140,4 +142,23 @@ "/redirect/", map )).toString(); } + private class CategorySortKeyPair implements Comparable { + private Category m_category; + private BigDecimal m_sortKey; + + public CategorySortKeyPair(Category category, BigDecimal sortKey) { + m_category = category; + m_sortKey = sortKey; + } + public Category getCategory() { + return m_category; + } + public BigDecimal getSortKey() { + return m_sortKey; + } + + public int compareTo(Object o) { + return m_sortKey.compareTo(((CategorySortKeyPair)o).m_sortKey); + } + } } |