You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by wo...@apache.org on 2010/07/17 01:56:17 UTC

svn commit: r964985 - in /portals/jetspeed-2/portal/trunk: components/jetspeed-portal/src/main/java/org/apache/jetspeed/decoration/DecorationValve.java jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml

Author: woonsan
Date: Fri Jul 16 23:56:17 2010
New Revision: 964985

URL: http://svn.apache.org/viewvc?rev=964985&view=rev
Log:
JS2-1203: Exposing the default decorator actions factory as a constructor arg to allow injection in spring assembly.

Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/decoration/DecorationValve.java
    portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/decoration/DecorationValve.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/decoration/DecorationValve.java?rev=964985&r1=964984&r2=964985&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/decoration/DecorationValve.java (original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/decoration/DecorationValve.java Fri Jul 16 23:56:17 2010
@@ -21,6 +21,7 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.Properties;
 
 import javax.portlet.PortletMode;
@@ -63,7 +64,7 @@ import org.slf4j.LoggerFactory;
  * 
  * @author <href a="mailto:weaver@apache.org">Scott T. Weaver</a>
  * @author <href a="mailto:firevelocity@gmail.com">Vivek Kumar</a>
- *
+ * @version $Id$
  */
 public class DecorationValve extends AbstractValve implements Valve
 {
@@ -74,9 +75,11 @@ public class DecorationValve extends Abs
     
     private final DecorationFactory decorationFactory;
 
-    private HashMap decoratorActionsAdapterCache = new HashMap();
+    private Map<String, DecoratorActionsFactory> decoratorActionsAdapterCache = Collections.synchronizedMap(new HashMap<String, DecoratorActionsFactory>());
     
     private DecoratorActionsFactory defaultDecoratorActionsFactory;
+    
+    private String defaultDecoratorActionsFactoryClassName;
 
     private JetspeedContentCache cache = null;
     
@@ -130,9 +133,19 @@ public class DecorationValve extends Abs
                            SecurityAccessController accessController, 
                            JetspeedContentCache cache, boolean useSessionForThemeCaching,
                            PortletFactory portletFactory)
-    {       
+    {
+        this(decorationFactory, accessController, cache, useSessionForThemeCaching, null, new DefaultDecoratorActionsFactory());
+    }
+    
+    public DecorationValve(DecorationFactory decorationFactory,
+                           SecurityAccessController accessController, 
+                           JetspeedContentCache cache, boolean useSessionForThemeCaching,
+                           PortletFactory portletFactory,
+                           DecoratorActionsFactory defaultDecoratorActionsFactory)
+    {
         this.decorationFactory = decorationFactory;
-        this.defaultDecoratorActionsFactory = new DefaultDecoratorActionsFactory();        
+        this.defaultDecoratorActionsFactory = defaultDecoratorActionsFactory;
+        this.defaultDecoratorActionsFactoryClassName = defaultDecoratorActionsFactory.getClass().getName();
         //added the accessController in portlet decorater for checking the actions
         this.accessController = accessController;        
         this.cache = cache;
@@ -298,37 +311,33 @@ public class DecorationValve extends Abs
     
     public DecoratorActionsFactory getDecoratorActionsAdapter(Decoration decoration)
     {
-        // FIXME: why always get this property
+        // read custom decorator actions factory class name from the decoration properties.
         String decoratorActionsAdapterClassName = decoration.getProperty("actions.factory");
-        if ( decoratorActionsAdapterClassName == null )
+        if (decoratorActionsAdapterClassName == null || "".equals(decoratorActionsAdapterClassName) || decoratorActionsAdapterClassName.equals(defaultDecoratorActionsFactoryClassName))
         {
-            decoratorActionsAdapterClassName = defaultDecoratorActionsFactory.getClass().getName();
+            return defaultDecoratorActionsFactory;
         }
-        synchronized (decoratorActionsAdapterCache)
+        
+        DecoratorActionsFactory adapter = (DecoratorActionsFactory) decoratorActionsAdapterCache.get(decoratorActionsAdapterClassName);
+        
+        if (adapter == null)
         {
-            DecoratorActionsFactory adapter = (DecoratorActionsFactory)decoratorActionsAdapterCache.get(decoratorActionsAdapterClassName);
-            if ( adapter == null )
+            try
             {
-                try
-                {
-                    adapter = (DecoratorActionsFactory)Class.forName(decoratorActionsAdapterClassName).newInstance();
-                    adapter.setMaximizeOnEdit(this.maxOnEdit);
-                    adapter.setMaximizeOnConfig(this.maxOnConfig);
-                    adapter.setMaximizeOnEditDefaults(this.maxOnEditDefaults);
-                }
-                catch (Exception e)
-                {
-                    log.error("Failed to instantiate custom DecoratorActionsAdaptor "+decoratorActionsAdapterClassName+", falling back to default.",e);
-                    adapter = (DecoratorActionsFactory)decoratorActionsAdapterCache.get(defaultDecoratorActionsFactory.getClass().getName());
-                    if ( adapter == null )
-                    {
-                        adapter = defaultDecoratorActionsFactory;
-                    }
-                }
-                decoratorActionsAdapterCache.put(decoratorActionsAdapterClassName,adapter);
+                adapter = (DecoratorActionsFactory) Class.forName(decoratorActionsAdapterClassName).newInstance();
+                adapter.setMaximizeOnEdit(this.maxOnEdit);
+                adapter.setMaximizeOnConfig(this.maxOnConfig);
+                adapter.setMaximizeOnEditDefaults(this.maxOnEditDefaults);
+                decoratorActionsAdapterCache.put(decoratorActionsAdapterClassName, adapter);
+            }
+            catch (Exception e)
+            {
+                adapter = defaultDecoratorActionsFactory;
+                log.error("Failed to instantiate custom DecoratorActionsAdaptor " + decoratorActionsAdapterClassName + ", falling back to default.", e);
             }
-            return adapter;
         }
+        
+        return adapter;
     }
     
     /**

Modified: portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml?rev=964985&r1=964984&r2=964985&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml (original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-portal-resources/src/main/resources/assembly/pipelines.xml Fri Jul 16 23:56:17 2010
@@ -442,6 +442,13 @@
       <ref bean="portletFactory" />
     </constructor-arg>
     
+    <!-- default decorator actions factory -->
+    <constructor-arg index='5'>
+      <bean class="org.apache.jetspeed.decoration.DefaultDecoratorActionsFactory">
+        <meta key="j2:cat" value="default" />
+      </bean>
+    </constructor-arg>
+    
     <!-- When clicking on Edit Mode, also switch to Maximize -->
     <property name="maximizeOnEdit">
       <value>false</value>



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org