You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2007/12/12 08:29:02 UTC

svn commit: r603497 - in /cocoon/branches/BRANCH_2_1_X/src/blocks/portal: conf/portal.samplesxconf java/org/apache/cocoon/portal/impl/PageLabelManager.java

Author: cziegeler
Date: Tue Dec 11 23:29:01 2007
New Revision: 603497

URL: http://svn.apache.org/viewvc?rev=603497&view=rev
Log:
Store page labels in the profile and not in the user session.

Modified:
    cocoon/branches/BRANCH_2_1_X/src/blocks/portal/conf/portal.samplesxconf
    cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/PageLabelManager.java

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/conf/portal.samplesxconf
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/portal/conf/portal.samplesxconf?rev=603497&r1=603496&r2=603497&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/conf/portal.samplesxconf (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/conf/portal.samplesxconf Tue Dec 11 23:29:01 2007
@@ -336,12 +336,20 @@
             <renderers default="column">
                 <renderer name="column"/>
             </renderers>
+            <aspects>
+                <!-- This aspect stores the page label information - you can remove it, if you don't use page labels. -->
+                <aspect auto-create="false" class="java.util.HashMap" name="page-labels" store="memory">
+            <aspects>
         </layout>
         <layout name="row" 
                 class="org.apache.cocoon.portal.layout.impl.CompositeLayoutImpl">
             <renderers default="row">
                 <renderer name="row"/>
             </renderers>
+            <aspects>
+                <!-- This aspect stores the page label information - you can remove it, if you don't use page labels. -->
+                <aspect auto-create="false" class="java.util.HashMap" name="page-labels" store="memory">
+            <aspects>
         </layout>
         <layout name="tab" 
                 class="org.apache.cocoon.portal.layout.impl.CompositeLayoutImpl"
@@ -349,6 +357,10 @@
             <renderers default="tab">
                 <renderer name="tab"/>
             </renderers>
+            <aspects>
+                <!-- This aspect stores the page label information - you can remove it, if you don't use page labels. -->
+                <aspect auto-create="false" class="java.util.HashMap" name="page-labels" store="memory">
+            <aspects>
         </layout>
         <layout name="rawtab" 
                 class="org.apache.cocoon.portal.layout.impl.CompositeLayoutImpl"
@@ -356,6 +368,10 @@
             <renderers default="rawtab">
                 <renderer name="rawtab"/>
             </renderers>
+            <aspects>
+                <!-- This aspect stores the page label information - you can remove it, if you don't use page labels. -->
+                <aspect auto-create="false" class="java.util.HashMap" name="page-labels" store="memory">
+            <aspects>
         </layout>
         <layout name="linktab"
                 class="org.apache.cocoon.portal.layout.impl.CompositeLayoutImpl"
@@ -363,6 +379,10 @@
             <renderers default="linktab">
                 <renderer name="linktab"/>
             </renderers>
+            <aspects>
+                <!-- This aspect stores the page label information - you can remove it, if you don't use page labels. -->
+                <aspect auto-create="false" class="java.util.HashMap" name="page-labels" store="memory">
+            <aspects>
         </layout>
         <layout name="frame" 
                 class="org.apache.cocoon.portal.layout.impl.FrameLayout"

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/PageLabelManager.java
URL: http://svn.apache.org/viewvc/cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/PageLabelManager.java?rev=603497&r1=603496&r2=603497&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/PageLabelManager.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portal/impl/PageLabelManager.java Tue Dec 11 23:29:01 2007
@@ -21,6 +21,10 @@
 import java.util.List;
 import java.util.Map;
 
+import org.apache.avalon.framework.activity.Disposable;
+import org.apache.avalon.framework.component.Component;
+import org.apache.avalon.framework.configuration.Configurable;
+import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.context.Context;
 import org.apache.avalon.framework.context.ContextException;
 import org.apache.avalon.framework.context.Contextualizable;
@@ -29,20 +33,15 @@
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.Serviceable;
 import org.apache.avalon.framework.thread.ThreadSafe;
-import org.apache.avalon.framework.CascadingRuntimeException;
-import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.component.Component;
-import org.apache.avalon.framework.configuration.Configurable;
-import org.apache.avalon.framework.configuration.Configuration;
+import org.apache.cocoon.components.ContextHelper;
+import org.apache.cocoon.environment.ObjectModelHelper;
+import org.apache.cocoon.environment.Request;
 import org.apache.cocoon.portal.PortalService;
-import org.apache.cocoon.portal.layout.Layout;
+import org.apache.cocoon.portal.event.impl.ChangeAspectDataEvent;
 import org.apache.cocoon.portal.layout.CompositeLayout;
 import org.apache.cocoon.portal.layout.Item;
+import org.apache.cocoon.portal.layout.Layout;
 import org.apache.cocoon.portal.layout.NamedItem;
-import org.apache.cocoon.portal.event.impl.ChangeAspectDataEvent;
-import org.apache.cocoon.environment.Request;
-import org.apache.cocoon.environment.ObjectModelHelper;
-import org.apache.cocoon.components.ContextHelper;
 
 /**
  * Manages the various activities required for page labels.
@@ -64,29 +63,29 @@
 
     /** The service manager */
     protected ServiceManager manager;
-    /** The portal Service */
-    protected PortalService service;
+    /** The portal service */
+    protected PortalService portalService;
     /** The cocoon context */
     protected Context context;
     protected String aspectName = null;
     private String requestParameterName;
 
-   //boolean to determine if page label should use directory structure
+    /** boolean to determine if page label should use directory structure */
     private boolean useUrlPath;
     private boolean nonStickyTabs;
     private boolean marshallEvents;
 
     protected static final String LABEL_ARRAY = PageLabelManager.class.getName() + "A";
-    protected static final String LABEL_MAP = PageLabelManager.class.getName() + "M";
+    protected static final String LABEL_MAP = "page-labels";
     protected static final String EVENT_MAP = PageLabelManager.class.getName() + "E";
     private static final String DEFAULT_REQUEST_PARAMETER_NAME = "pageLabel";
 
-    /* (non-Javadoc)
+    /**
      * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
      */
     public void service(ServiceManager manager) throws ServiceException {
         this.manager = manager;
-        this.service = (PortalService) this.manager.lookup(PortalService.ROLE);
+        this.portalService = (PortalService) this.manager.lookup(PortalService.ROLE);
     }
 
     /**
@@ -94,7 +93,7 @@
      */
     public void dispose() {
         if (this.manager != null) {
-            this.manager.release(this.service);
+            this.manager.release(this.portalService);
             this.manager = null;
         }
     }
@@ -187,25 +186,24 @@
      * Return the Map that contains events for all the page labels.
      * @return The Map to use for converting events to and from urls.
      */
-    public Map getPageEventMap()
-    {
-        PortalService service = null;
-        try {
-            service = (PortalService) this.manager.lookup(PortalService.ROLE);
-            Map map = (Map) service.getAttribute(EVENT_MAP);
-            if (null == map) {
-                map = new HashMap();
-                service.setAttribute(EVENT_MAP, map);
-            }
-
-            return map;
-        }
-        catch (ServiceException ce) {
-            throw new CascadingRuntimeException("Unable to lookup component.", ce);
+    public Map getPageEventMap() {
+        Map map = (Map) portalService.getAttribute(EVENT_MAP);
+        if (null == map) {
+            map = new HashMap();
+            portalService.setAttribute(EVENT_MAP, map);
         }
-        finally {
-            this.manager.release(service);
+
+        return map;
+    }
+
+    protected Map getLabelMap() {
+        final Layout rootLayout = portalService.getComponentManager().getProfileManager().getPortalLayout(null, null);
+        Map map = (Map) rootLayout.getAspectData(LABEL_MAP);
+        if (null == map) {
+            map = this.initializeLabels();
+            rootLayout.setAspectData(LABEL_MAP, map);
         }
+        return map;
     }
 
     /**
@@ -216,54 +214,21 @@
      *         should occur.
      */
     public List getPageLabelEvents(String pageLabel) {
-        PortalService service = null;
-        try {
-            service = (PortalService) this.manager.lookup(PortalService.ROLE);
-            Map map = (Map) service.getAttribute(LABEL_MAP);
-            if (null == map) {
-                map = initializeLabels(service);
-                service.setAttribute(LABEL_MAP, map);
-            }
+        final Map labelMap = this.getLabelMap();
+        List list = (List) labelMap.get(pageLabel);
 
-            List list = (List) map.get(pageLabel);
-
-            if (list == null) {
-                list = new ArrayList();
-                map.put(pageLabel, list);
-            }
-
-            return list;
-        }
-        catch (ServiceException ce) {
-            throw new CascadingRuntimeException("Unable to lookup component.", ce);
-        }
-        finally {
-            this.manager.release(service);
+        if (list == null) {
+            list = new ArrayList();
+            labelMap.put(pageLabel, list);
         }
+
+        return list;
     }
 
     public boolean isLabel(String pageLabel) {
-        PortalService service = null;
-        try
-        {
-            service = (PortalService) this.manager.lookup(PortalService.ROLE);
-            Map map = (Map) service.getAttribute(LABEL_MAP);
-            if (null == map)
-            {
-                map = initializeLabels(service);
-                service.setAttribute(LABEL_MAP, map);
-            }
+        final Map labelMap = this.getLabelMap();
 
-            return map.containsKey(pageLabel);
-        }
-        catch (ServiceException ce)
-        {
-            throw new CascadingRuntimeException("Unable to lookup component.", ce);
-        }
-        finally
-        {
-            this.manager.release(service);
-        }
+        return labelMap.containsKey(pageLabel);
     }
 
     /**
@@ -273,27 +238,17 @@
         return this.marshallEvents;
     }
 
-    /*
+    /**
      * Return the array containing the current and previous labels.
      */
     private String[] getLabels() {
-        PortalService service = null;
-        try {
-            service = (PortalService) this.manager.lookup(PortalService.ROLE);
-            String[] labels = (String[]) service.getAttribute(LABEL_ARRAY);
-            if (null == labels) {
-                labels = new String[2];
-                labels[0] = getRoot();
-                service.setAttribute(LABEL_ARRAY, labels);
-            }
-            return labels;
-        }
-        catch (ServiceException ce) {
-            throw new CascadingRuntimeException("Unable to lookup component.", ce);
-        }
-        finally {
-            this.manager.release(service);
+        String[] labels = (String[]) portalService.getAttribute(LABEL_ARRAY);
+        if (null == labels) {
+            labels = new String[2];
+            labels[0] = getRoot();
+            portalService.setAttribute(LABEL_ARRAY, labels);
         }
+        return labels;
     }
 
     /**
@@ -302,28 +257,22 @@
      * @param service The portal service
      * @return The page label map.
      */
-    private Map initializeLabels(PortalService service) {
-        Map map = new HashMap();
+    private Map initializeLabels() {
+        final Map map = new HashMap();
 
-        Layout portalLayout = service.getEntryLayout(null);
-        if (portalLayout == null) {
-            portalLayout =
-                service.getComponentManager().getProfileManager().getPortalLayout(null, null);
-        }
+        final Layout portalLayout =
+            portalService.getComponentManager().getProfileManager().getPortalLayout(null, null);
 
         if (portalLayout instanceof CompositeLayout) {
-            populate((CompositeLayout) portalLayout, map, "", new ArrayList());
+            this.populate((CompositeLayout) portalLayout, map, "", new ArrayList());
         }
 
         return map;
     }
 
     private String getRoot() {
-        Layout portalLayout = service.getEntryLayout(null);
-        if (portalLayout == null) {
-            portalLayout =
-                service.getComponentManager().getProfileManager().getPortalLayout(null, null);
-        }
+        final Layout portalLayout =
+            portalService.getComponentManager().getProfileManager().getPortalLayout(null, null);
 
         if (portalLayout instanceof CompositeLayout) {
             return getRoot((CompositeLayout)portalLayout, new StringBuffer(""));