[pal-cvs 3260] [994] apply patch ' Optional portlet session caching of layout view templates'

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2008年 6月 25日 (水) 14:12:59 JST


Revision: 994
          http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=pal&view=rev&rev=994
Author:   sone
Date:     2008-06-25 14:12:58 +0900 (Wed, 25 Jun 2008)

Log Message:
-----------
apply patch 'Optional portlet session caching of layout view templates'

Modified Paths:
--------------
    pal-portal/branches/pal-portal-1.x/portal/jetspeed-2/layout-portlets/src/java/org/apache/jetspeed/portlets/layout/LayoutPortlet.java
    pal-portal/branches/pal-portal-1.x/portal/jetspeed-2/layout-portlets/src/webapp/WEB-INF/jetspeed-portlet.xml
    pal-portal/branches/pal-portal-1.x/portal/jetspeed-2/src/webapp/WEB-INF/conf/jetspeed.properties


-------------- next part --------------
Modified: pal-portal/branches/pal-portal-1.x/portal/jetspeed-2/layout-portlets/src/java/org/apache/jetspeed/portlets/layout/LayoutPortlet.java
===================================================================
--- pal-portal/branches/pal-portal-1.x/portal/jetspeed-2/layout-portlets/src/java/org/apache/jetspeed/portlets/layout/LayoutPortlet.java	2008-06-19 22:26:05 UTC (rev 993)
+++ pal-portal/branches/pal-portal-1.x/portal/jetspeed-2/layout-portlets/src/java/org/apache/jetspeed/portlets/layout/LayoutPortlet.java	2008-06-25 05:12:58 UTC (rev 994)
@@ -38,6 +38,7 @@
 import org.apache.jetspeed.CommonPortletServices;
 import org.apache.jetspeed.JetspeedActions;
 import org.apache.jetspeed.PortalReservedParameters;
+import org.apache.jetspeed.administration.PortalConfiguration;
 import org.apache.jetspeed.capabilities.CapabilityMap;
 import org.apache.jetspeed.components.portletentity.PortletEntityAccessComponent;
 import org.apache.jetspeed.components.portletregistry.PortletRegistry;
@@ -93,6 +94,8 @@
 
     protected TemplateLocator decorationLocator;
 
+    protected boolean storeViewPageInSession;
+
     private Map layoutTemplatesCache = new HashMap();
 
     public static final String DEFAULT_TEMPLATE_EXT = ".vm";
@@ -131,6 +134,14 @@
         if (null == windowAccess) { throw new PortletException(
                 "Failed to find the Window Access on portlet initialization"); }
 
+        PortalConfiguration portalConfiguration = (PortalConfiguration) getPortletContext()
+                .getAttribute(CommonPortletServices.CPS_PORTAL_CONFIGURATION);
+        if (null == portalConfiguration) { throw new PortletException(
+                "Failed to find the Portal Configuration on portlet initialization"); }
+
+        storeViewPageInSession = portalConfiguration.getBoolean(
+                "layout.page.storeViewPageInSession", true);
+
         templateLocator = (TemplateLocator) getPortletContext().getAttribute(
                 "TemplateLocator");
         decorationLocator = (TemplateLocator) getPortletContext().getAttribute(
@@ -152,8 +163,8 @@
 
         try
         {
-            String helpPage = (String) request.getPortletSession()
-                    .getAttribute(PortalReservedParameters.PAGE_LAYOUT_HELP);
+            String helpPage = getCachedLayoutViewPage(request,
+                    PortalReservedParameters.PAGE_LAYOUT_HELP);
             if (helpPage == null)
             {
                 PortletPreferences prefs = request.getPreferences();
@@ -163,7 +174,7 @@
                     helpPage = this.getInitParameter(PARAM_HELP_PAGE);
                     if (helpPage == null) helpPage = "columns";
                 }
-                request.getPortletSession().setAttribute(
+                cacheLayoutViewPage(request,
                         PortalReservedParameters.PAGE_LAYOUT_HELP, helpPage);
             }
 
@@ -243,7 +254,7 @@
             JetspeedPowerTool jpt = getJetspeedPowerTool(request);
             if (maximized)
             {
-                viewPage = (String) request.getPortletSession().getAttribute(
+                viewPage = getCachedLayoutViewPage(request,
                         PortalReservedParameters.PAGE_LAYOUT_MAX);
                 if (viewPage == null)
                 {
@@ -254,13 +265,13 @@
                         viewPage = this.getInitParameter(PARAM_MAX_PAGE);
                         if (viewPage == null) viewPage = "maximized";
                     }
-                    request.getPortletSession().setAttribute(
+                    cacheLayoutViewPage(request,
                             PortalReservedParameters.PAGE_LAYOUT_MAX, viewPage);
                 }
             }
             else if (solo)
             {
-                viewPage = (String) request.getPortletSession().getAttribute(
+                viewPage = getCachedLayoutViewPage(request,
                         PortalReservedParameters.PAGE_LAYOUT_SOLO);
                 if (viewPage == null)
                 {
@@ -274,15 +285,13 @@
                             viewPage = "solo";
                         }
                     }
-                    request.getPortletSession()
-                            .setAttribute(
-                                    PortalReservedParameters.PAGE_LAYOUT_SOLO,
-                                    viewPage);
+                    cacheLayoutViewPage(request,
+                            PortalReservedParameters.PAGE_LAYOUT_SOLO, viewPage);
                 }
             }
             else
             {
-                viewPage = (String) request.getPortletSession().getAttribute(
+                viewPage = getCachedLayoutViewPage(request,
                         PortalReservedParameters.PAGE_LAYOUT_VIEW);
                 if (viewPage == null)
                 {
@@ -293,10 +302,9 @@
                         viewPage = this.getInitParameter(PARAM_VIEW_PAGE);
                         if (viewPage == null) viewPage = "columns";
                     }
-                    request.getPortletSession()
-                            .setAttribute(
-                                    PortalReservedParameters.PAGE_LAYOUT_VIEW,
-                                    viewPage);
+
+                    cacheLayoutViewPage(request,
+                            PortalReservedParameters.PAGE_LAYOUT_VIEW, viewPage);
                 }
             }
 
@@ -804,6 +812,49 @@
         return props;
     }
 
+    /**
+     * Retrieve the cached layout view page location. This method provides an
+     * easy way to turn on/off caching of layout view page locations. By
+     * default, view page locations are stored in the portlet session. Set the
+     * Jetspeed property <code>layout.page.storeViewPageInSession</code> to
+     * <code>true</code> / <code>false</code> to turn on / off caching.
+     * 
+     * @param request
+     *            portlet request
+     * @param viewPageType
+     *            the view page type, see the
+     *            PortalReservedParameters.PAGE_LAYOUT_* parameters.
+     * @return the cached view page location
+     */
+    protected String getCachedLayoutViewPage(RenderRequest request,
+            String viewPageType)
+    {
+        return storeViewPageInSession ? (String) request.getPortletSession()
+                .getAttribute(viewPageType) : null;
+    }
+
+    /**
+     * Cache a layout view page location. By default, the value is stored in the
+     * portlet session.
+     * 
+     * @param request
+     *            portlet request
+     * @param viewPageType
+     *            the type of the view page (e.g. help, maximized view, solo,
+     *            etc.). See the PortalReservedParameters.PAGE_LAYOUT_*
+     *            parameters.
+     * @param page
+     *            the view page to cache
+     */
+    protected void cacheLayoutViewPage(RenderRequest request,
+            String viewPageType, String page)
+    {
+        if (storeViewPageInSession)
+        {
+            request.getPortletSession().setAttribute(viewPageType, page);
+        }
+    }
+
     class CachedTemplate
     {
 

Modified: pal-portal/branches/pal-portal-1.x/portal/jetspeed-2/layout-portlets/src/webapp/WEB-INF/jetspeed-portlet.xml
===================================================================
--- pal-portal/branches/pal-portal-1.x/portal/jetspeed-2/layout-portlets/src/webapp/WEB-INF/jetspeed-portlet.xml	2008-06-19 22:26:05 UTC (rev 993)
+++ pal-portal/branches/pal-portal-1.x/portal/jetspeed-2/layout-portlets/src/webapp/WEB-INF/jetspeed-portlet.xml	2008-06-25 05:12:58 UTC (rev 994)
@@ -43,6 +43,7 @@
         <js:service name='Desktop'/>
         <js:service name='decorationContentCache'/>
         <js:service name='portletContentCache'/>        
+           <js:service name='PortalConfiguration'/>
 	</js:services>
 	
 </portlet-app>

Modified: pal-portal/branches/pal-portal-1.x/portal/jetspeed-2/src/webapp/WEB-INF/conf/jetspeed.properties
===================================================================
--- pal-portal/branches/pal-portal-1.x/portal/jetspeed-2/src/webapp/WEB-INF/conf/jetspeed.properties	2008-06-19 22:26:05 UTC (rev 993)
+++ pal-portal/branches/pal-portal-1.x/portal/jetspeed-2/src/webapp/WEB-INF/conf/jetspeed.properties	2008-06-25 05:12:58 UTC (rev 994)
@@ -193,6 +193,8 @@
 #-------------------------------------------------------------------------
 # the default page layout if none is specified
 layout.page.default = jetspeed-layouts::VelocityTwoColumns
+# optimization for looking up LayoutPortlet Page template, default == true
+layout.page.storeViewPageInSession = true
 
 #-------------------------------------------------------------------------
 # D E C O R A T O R S


pal-cvs メーリングリストの案内
Back to archive index