portals-jetspeed-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From woon...@apache.org
Subject svn commit: r910295 - in /portals/jetspeed-2/portal/trunk: components/jetspeed-portal/src/main/java/org/apache/jetspeed/decoration/ components/jetspeed-portal/src/test/java/org/apache/jetspeed/ components/jetspeed-portlet-factory/src/main/java/org/apac...
Date Mon, 15 Feb 2010 18:45:06 GMT
Author: woonsan
Date: Mon Feb 15 18:45:05 2010
New Revision: 910295

URL: http://svn.apache.org/viewvc?rev=910295&view=rev
Log:
JS2-1106: Enabling auto-switching to edit_defaults mode even when the portlet should not have
support for edit mode if the portlet has public edit render helper method.
Also, now it can retrieve portlet 2.0 @RenderMode annotated helper methods, too. (Previously
it checks doEdit() method only.)

Added:
    portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/util/GenericPortletUtils.java
  (with props)
    portals/jetspeed-2/portal/trunk/jetspeed-commons/src/test/java/org/apache/jetspeed/util/TestGenericPortletUtils.java
  (with props)
Modified:
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/main/java/org/apache/jetspeed/decoration/DecorationValve.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/PortletFactoryMock.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-portlet-factory/src/main/java/org/apache/jetspeed/factory/JetspeedPortletFactory.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-portlet-factory/src/main/java/org/apache/jetspeed/factory/JetspeedPortletInstance.java
    portals/jetspeed-2/portal/trunk/components/jetspeed-portlet-factory/src/main/java/org/apache/jetspeed/factory/JetspeedPortletProxyInstance.java
    portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/factory/PortletFactory.java
    portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/factory/PortletInstance.java
    portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/portlet/PortletObjectProxy.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=910295&r1=910294&r2=910295&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
Mon Feb 15 18:45:05 2010
@@ -26,28 +26,29 @@
 import javax.portlet.PortletMode;
 import javax.portlet.WindowState;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.apache.jetspeed.JetspeedActions;
 import org.apache.jetspeed.PortalReservedParameters;
 import org.apache.jetspeed.cache.CacheElement;
 import org.apache.jetspeed.cache.ContentCacheKey;
 import org.apache.jetspeed.cache.JetspeedContentCache;
+import org.apache.jetspeed.container.PortletWindow;
 import org.apache.jetspeed.container.url.PortalURL;
 import org.apache.jetspeed.decoration.caches.SessionPathResolverCache;
+import org.apache.jetspeed.factory.PortletFactory;
 import org.apache.jetspeed.om.page.ContentFragment;
 import org.apache.jetspeed.om.page.ContentPage;
 import org.apache.jetspeed.om.page.Fragment;
 import org.apache.jetspeed.om.portlet.PortletApplication;
 import org.apache.jetspeed.om.portlet.PortletDefinition;
+import org.apache.jetspeed.om.portlet.Supports;
 import org.apache.jetspeed.pipeline.PipelineException;
 import org.apache.jetspeed.pipeline.valve.AbstractValve;
 import org.apache.jetspeed.pipeline.valve.Valve;
 import org.apache.jetspeed.pipeline.valve.ValveContext;
 import org.apache.jetspeed.request.RequestContext;
 import org.apache.jetspeed.security.SecurityAccessController;
-import org.apache.jetspeed.container.PortletWindow;
-import org.apache.jetspeed.om.portlet.Supports;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Assigns decorations and page actions to all of the portlet Fragments within
@@ -97,32 +98,46 @@
      */
     private boolean autoSwitchingToEditDefaultsModes = true;
          
-     /**
-      * For security constraint checks
-      */
-     protected SecurityAccessController accessController;
-
-     public DecorationValve(DecorationFactory decorationFactory, SecurityAccessController
accessController)
-     {
-         this(decorationFactory, accessController, null);
-     }
+    /**
+     * For security constraint checks
+     */
+    protected SecurityAccessController accessController;
+    
+    /**
+     * For portlet instance helper method support checks.
+     */
+    private PortletFactory portletFactory;
+
+    public DecorationValve(DecorationFactory decorationFactory, SecurityAccessController
accessController)
+    {
+        this(decorationFactory, accessController, null);
+    }
      
-     public DecorationValve(DecorationFactory decorationFactory,
-                            SecurityAccessController accessController, JetspeedContentCache
cache)
-     {    
-         this(decorationFactory, accessController, cache, false);
-     }
+    public DecorationValve(DecorationFactory decorationFactory,
+                           SecurityAccessController accessController, JetspeedContentCache
cache)
+    {    
+        this(decorationFactory, accessController, cache, false);
+    }
      
-     public DecorationValve(DecorationFactory decorationFactory,
-                                 SecurityAccessController accessController, JetspeedContentCache
cache,
-                                 boolean useSessionForThemeCaching)
-     {       
+    public DecorationValve(DecorationFactory decorationFactory,
+                           SecurityAccessController accessController, JetspeedContentCache
cache,
+                           boolean useSessionForThemeCaching)
+    {
+        this(decorationFactory, accessController, cache, useSessionForThemeCaching, null);
+    }
+    
+    public DecorationValve(DecorationFactory decorationFactory,
+                           SecurityAccessController accessController, 
+                           JetspeedContentCache cache, boolean useSessionForThemeCaching,
+                           PortletFactory portletFactory)
+    {       
         this.decorationFactory = decorationFactory;
         this.defaultDecoratorActionsFactory = new DefaultDecoratorActionsFactory();     
  
         //added the accessController in portlet decorater for checking the actions
         this.accessController = accessController;        
         this.cache = cache;
         this.useSessionForThemeCaching = useSessionForThemeCaching;
+        this.portletFactory = portletFactory;
     }
     
     public void invoke(RequestContext requestContext, ValveContext context) throws PipelineException
@@ -393,7 +408,7 @@
                         }
                         if ( ! equalsCurrentMode || isAjaxRequest )
                         {
-                            if ( (supportsPortletMode(supports,customMode) || isAutoSwitchableCustomMode(supports,
customMode))
+                            if ( (supportsPortletMode(supports,customMode) || isAutoSwitchableCustomMode(window,
customMode))
                                  && (!PortletMode.EDIT.equals(customMode) || pageActionAccess.isEditAllowed())
                                  && pageActionAccess.checkPortletMode(fragmentId,
portletName, mappedMode)
                                  )
@@ -697,16 +712,16 @@
         return this.autoSwitchingForConfigMode;
     }
     
-    private boolean isAutoSwitchableCustomMode(List<Supports> supports, PortletMode
customMode)
+    private boolean isAutoSwitchableCustomMode(PortletWindow window, PortletMode customMode)
     {
         if (this.autoSwitchingForConfigMode && JetspeedActions.CONFIG_MODE.equals(customMode))
         {
             return true;
         }
         
-        if (this.autoSwitchingToEditDefaultsModes)
+        if (this.autoSwitchingToEditDefaultsModes && JetspeedActions.EDIT_DEFAULTS_MODE.equals(customMode)
&& portletFactory != null)
         {
-            if (supportsPortletMode(supports,PortletMode.EDIT) && JetspeedActions.EDIT_DEFAULTS_MODE.equals(customMode))
+            if (portletFactory.hasRenderHelperMethod(window.getPortletDefinition(), PortletMode.EDIT))
             {
                 return true;
             }

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/PortletFactoryMock.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/PortletFactoryMock.java?rev=910295&r1=910294&r2=910295&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/PortletFactoryMock.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portal/src/test/java/org/apache/jetspeed/PortletFactoryMock.java
Mon Feb 15 18:45:05 2010
@@ -21,6 +21,7 @@
 import java.util.ResourceBundle;
 
 import javax.portlet.PortletException;
+import javax.portlet.PortletMode;
 import javax.portlet.PortletRequestDispatcher;
 import javax.portlet.PortletURLGenerationListener;
 import javax.portlet.PreferencesValidator;
@@ -84,4 +85,9 @@
     {
         return null;
     }
+
+    public boolean hasRenderHelperMethod(PortletDefinition pd, PortletMode mode)
+    {
+        return false;
+    }
 }
\ No newline at end of file

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portlet-factory/src/main/java/org/apache/jetspeed/factory/JetspeedPortletFactory.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portlet-factory/src/main/java/org/apache/jetspeed/factory/JetspeedPortletFactory.java?rev=910295&r1=910294&r2=910295&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portlet-factory/src/main/java/org/apache/jetspeed/factory/JetspeedPortletFactory.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portlet-factory/src/main/java/org/apache/jetspeed/factory/JetspeedPortletFactory.java
Mon Feb 15 18:45:05 2010
@@ -16,6 +16,7 @@
  */
 package org.apache.jetspeed.factory;
 
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -25,16 +26,16 @@
 import java.util.MissingResourceException;
 import java.util.ResourceBundle;
 
+import javax.portlet.GenericPortlet;
 import javax.portlet.Portlet;
 import javax.portlet.PortletException;
+import javax.portlet.PortletMode;
 import javax.portlet.PortletURLGenerationListener;
 import javax.portlet.PreferencesValidator;
 import javax.portlet.UnavailableException;
 import javax.portlet.filter.PortletFilter;
 import javax.servlet.ServletContext;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 import org.apache.jetspeed.PortalContext;
 import org.apache.jetspeed.container.ContainerInfo;
 import org.apache.jetspeed.container.JetspeedPortletConfig;
@@ -47,8 +48,11 @@
 import org.apache.jetspeed.om.portlet.Listener;
 import org.apache.jetspeed.om.portlet.PortletApplication;
 import org.apache.jetspeed.om.portlet.PortletDefinition;
+import org.apache.jetspeed.util.GenericPortletUtils;
 import org.apache.pluto.container.RequestDispatcherService;
 import org.apache.portals.bridges.common.ServletContextProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * <p>
@@ -704,4 +708,50 @@
         return filterInstance;
     }
 
+    public boolean hasRenderHelperMethod(PortletDefinition pd, PortletMode mode)
+    {
+        PortletInstance portletInstance = null;
+        String paName = pd.getApplication().getName();
+        String pdName = pd.getPortletName();
+        
+        Map<String, PortletInstance> instanceCache = this.portletCache.get(paName);
+        
+        if (instanceCache != null)
+        {
+            portletInstance = instanceCache.get(pdName);
+        }
+        
+        if (portletInstance != null)
+        {
+            return portletInstance.hasRenderHelperMethod(mode);
+        }
+        else
+        {
+            ClassLoader paCl = classLoaderMap.get(paName);
+            
+            if (paCl != null) 
+            {
+                try
+                {
+                    Class<?> portletClazz = paCl.loadClass(pd.getPortletClass());
+                    
+                    if (GenericPortlet.class.isAssignableFrom(portletClazz))
+                    {
+                        Method helperMethod = GenericPortletUtils.getRenderModeHelperMethod((Class<?
extends GenericPortlet>) portletClazz, mode);
+                        
+                        if (helperMethod != null)
+                        {
+                            return true;
+                        }
+                    }
+                }
+                catch (ClassNotFoundException e)
+                {
+                }
+            }
+            
+            return false;
+        }
+    }
+
 }

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portlet-factory/src/main/java/org/apache/jetspeed/factory/JetspeedPortletInstance.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portlet-factory/src/main/java/org/apache/jetspeed/factory/JetspeedPortletInstance.java?rev=910295&r1=910294&r2=910295&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portlet-factory/src/main/java/org/apache/jetspeed/factory/JetspeedPortletInstance.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portlet-factory/src/main/java/org/apache/jetspeed/factory/JetspeedPortletInstance.java
Mon Feb 15 18:45:05 2010
@@ -17,15 +17,21 @@
 package org.apache.jetspeed.factory;
 
 import java.io.IOException;
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
 
 import javax.portlet.ActionRequest;
 import javax.portlet.ActionResponse;
 import javax.portlet.EventPortlet;
 import javax.portlet.EventRequest;
 import javax.portlet.EventResponse;
+import javax.portlet.GenericPortlet;
 import javax.portlet.Portlet;
 import javax.portlet.PortletConfig;
 import javax.portlet.PortletException;
+import javax.portlet.PortletMode;
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
 import javax.portlet.ResourceRequest;
@@ -34,115 +40,152 @@
 import javax.portlet.UnavailableException;
 
 import org.apache.jetspeed.container.JetspeedPortletConfig;
-import org.apache.jetspeed.factory.PortletInstance;
+import org.apache.jetspeed.util.GenericPortletUtils;
 
 /**
  * JetspeedPortletInstance
  * 
  * @author <a href="mailto:ate@douma.nu">Ate Douma</a>
  * @version $Id$
- *
  */
 public class JetspeedPortletInstance implements PortletInstance
 {
-  private Portlet portlet;
-  private JetspeedPortletConfig config;
-  private boolean destroyed;
-  private final String portletName;
-  
-  public JetspeedPortletInstance(String portletName, Portlet portlet)
-  {
-      this.portletName = portletName;
-      this.portlet = portlet;
-  }
-  
-  private void checkAvailable() throws UnavailableException
-  {
-      if ( destroyed )
-      {
-          throw new UnavailableException("Portlet "+portletName+" no longer available");
-      }
-  }
-  
-  public void destroy()
-  {
-      if (!destroyed)
-      {
-          destroyed = true;
-          if ( config != null )
-          {
-              // Portlet really has been put into service, now destroy it.
-              portlet.destroy();
-          }
-      }
-  }
-  
-  public boolean equals(Object obj)
-  {
-    return portlet.equals(obj);
-  }
-  
-  public int hashCode()
-  {
-    return portlet.hashCode();
-  }
-  
-  public void init(PortletConfig config) throws PortletException
-  {
-    portlet.init(config);
-    this.config = (JetspeedPortletConfig)config;
-  }
-  
-  public JetspeedPortletConfig getConfig()
-  {
-      return config;
-  }
-  
-  public void processAction(ActionRequest request, ActionResponse response) throws PortletException,
IOException
-  {
-    checkAvailable();
-    portlet.processAction(request, response);
-  }
-  
-  public void render(RenderRequest request, RenderResponse response) throws PortletException,
IOException
-  {
-    checkAvailable();
-    portlet.render(request, response);
-  }
-  
-  public String toString()
-  {
-      return portlet.toString();
-  }
-
-  public void processEvent(EventRequest request, EventResponse response) throws PortletException,
IOException
-  {
-      if (portlet instanceof EventPortlet)
-      {
-          checkAvailable();
-          ((EventPortlet)portlet).processEvent(request, response);
-      }
-  }
-
-  public void serveResource(ResourceRequest request, ResourceResponse response) throws PortletException,
IOException
-  {
-      if (portlet instanceof ResourceServingPortlet)
-      {
-          checkAvailable();
-          ((ResourceServingPortlet)portlet).serveResource(request, response);
-      }
-  }
-
-  /**
-   * @return Returns the portlet.
-   */
-  public Portlet getRealPortlet()
-  {
-      return portlet;
-  }
-  
-  public boolean isProxyInstance()
-  {
-      return false;
-  }
+    private Portlet portlet;
+    private JetspeedPortletConfig config;
+    private boolean destroyed;
+    private final String portletName;
+    
+    protected Map<PortletMode, Boolean> helperMethodAccessibilities;
+
+    public JetspeedPortletInstance(String portletName, Portlet portlet)
+    {
+        this.portletName = portletName;
+        this.portlet = portlet;
+    }
+
+    private void checkAvailable() throws UnavailableException
+    {
+        if (destroyed)
+        {
+            throw new UnavailableException("Portlet " + portletName + " no longer available");
+        }
+    }
+
+    public void destroy()
+    {
+        if (!destroyed)
+        {
+            destroyed = true;
+            if (config != null)
+            {
+                // Portlet really has been put into service, now destroy it.
+                portlet.destroy();
+            }
+        }
+    }
+
+    public boolean equals(Object obj)
+    {
+        return portlet.equals(obj);
+    }
+
+    public int hashCode()
+    {
+        return portlet.hashCode();
+    }
+
+    public void init(PortletConfig config) throws PortletException
+    {
+        portlet.init(config);
+        this.config = (JetspeedPortletConfig) config;
+    }
+
+    public JetspeedPortletConfig getConfig()
+    {
+        return config;
+    }
+
+    public void processAction(ActionRequest request, ActionResponse response) throws PortletException,
IOException
+    {
+        checkAvailable();
+        portlet.processAction(request, response);
+    }
+
+    public void render(RenderRequest request, RenderResponse response) throws PortletException,
IOException
+    {
+        checkAvailable();
+        portlet.render(request, response);
+    }
+
+    public String toString()
+    {
+        return portlet.toString();
+    }
+
+    public void processEvent(EventRequest request, EventResponse response) throws PortletException,
IOException
+    {
+        if (portlet instanceof EventPortlet)
+        {
+            checkAvailable();
+            ((EventPortlet) portlet).processEvent(request, response);
+        }
+    }
+
+    public void serveResource(ResourceRequest request, ResourceResponse response) throws
PortletException, IOException
+    {
+        if (portlet instanceof ResourceServingPortlet)
+        {
+            checkAvailable();
+            ((ResourceServingPortlet) portlet).serveResource(request, response);
+        }
+    }
+
+    /**
+     * @return Returns the portlet.
+     */
+    public Portlet getRealPortlet()
+    {
+        return portlet;
+    }
+
+    public boolean isProxyInstance()
+    {
+        return false;
+    }
+    
+    public boolean hasRenderHelperMethod(PortletMode mode)
+    {
+        if (helperMethodAccessibilities == null)
+        {
+            helperMethodAccessibilities = Collections.synchronizedMap(new HashMap<PortletMode,
Boolean>());
+        }
+        
+        Boolean accessible = helperMethodAccessibilities.get(mode);
+        
+        if (accessible != null)
+        {
+            return accessible.booleanValue();
+        }
+        else
+        {
+            Method helperMethod = null;
+            Portlet nonProxyPortletObject = getNonProxyPortletObject();
+            
+            if (nonProxyPortletObject instanceof GenericPortlet)
+            {
+                helperMethod = GenericPortletUtils.getRenderModeHelperMethod((GenericPortlet)
nonProxyPortletObject, mode);
+            }
+            
+            boolean helperMethodAccessible = (helperMethod != null);
+            helperMethodAccessibilities.put(mode, helperMethodAccessible ? Boolean.TRUE :
Boolean.FALSE);
+            
+            return helperMethodAccessible;
+        }
+    }
+    
+    protected Portlet getNonProxyPortletObject()
+    {
+        return portlet;
+    }
+    
 }

Modified: portals/jetspeed-2/portal/trunk/components/jetspeed-portlet-factory/src/main/java/org/apache/jetspeed/factory/JetspeedPortletProxyInstance.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/components/jetspeed-portlet-factory/src/main/java/org/apache/jetspeed/factory/JetspeedPortletProxyInstance.java?rev=910295&r1=910294&r2=910295&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/components/jetspeed-portlet-factory/src/main/java/org/apache/jetspeed/factory/JetspeedPortletProxyInstance.java
(original)
+++ portals/jetspeed-2/portal/trunk/components/jetspeed-portlet-factory/src/main/java/org/apache/jetspeed/factory/JetspeedPortletProxyInstance.java
Mon Feb 15 18:45:05 2010
@@ -29,6 +29,9 @@
  */
 public class JetspeedPortletProxyInstance extends JetspeedPortletInstance
 {
+    
+    private Portlet proxiedPortlet;
+    
     public JetspeedPortletProxyInstance(String portletName, Portlet portlet, 
                                         boolean autoSwitchEditDefaultsModeToEditMode, 
                                         boolean autoSwitchConfigMode, String customConfigModePortletUniqueName)
@@ -36,6 +39,7 @@
         super(portletName, 
               (Portlet) PortletObjectProxy.createProxy(portlet, autoSwitchEditDefaultsModeToEditMode,

                                                        autoSwitchConfigMode, customConfigModePortletUniqueName));
+        this.proxiedPortlet = portlet;
     }
     
     public JetspeedPortletProxyInstance(String portletName, Portlet portlet, 
@@ -47,10 +51,19 @@
               (Portlet) PortletObjectProxy.createProxy(portlet, autoSwitchEditDefaultsModeToEditMode,

                                                        autoSwitchConfigMode, customConfigModePortletUniqueName,
                                                        autoSwitchPreviewMode, customPreviewModePortletUniqueName));
+        this.proxiedPortlet = portlet;
     }
     
+    @Override
     public boolean isProxyInstance()
     {
         return true;
     }
+    
+    @Override
+    protected Portlet getNonProxyPortletObject()
+    {
+        return proxiedPortlet;
+    }
+    
 }

Modified: portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/factory/PortletFactory.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/factory/PortletFactory.java?rev=910295&r1=910294&r2=910295&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/factory/PortletFactory.java
(original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/factory/PortletFactory.java
Mon Feb 15 18:45:05 2010
@@ -21,8 +21,11 @@
 import java.util.ResourceBundle;
 
 import javax.portlet.PortletException;
+import javax.portlet.PortletMode;
 import javax.portlet.PortletURLGenerationListener;
 import javax.portlet.PreferencesValidator;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
 import javax.servlet.ServletContext;
 
 import org.apache.jetspeed.PortalContext;
@@ -57,4 +60,27 @@
     ResourceBundle getResourceBundle(PortletDefinition pd, Locale locale);
     List<PortletURLGenerationListener> getPortletApplicationListeners(PortletApplication
pa) throws PortletException;
     PortletFilterInstance getPortletFilterInstance(PortletApplication pa, String filterName)
throws PortletException;
+    
+    /**
+     * Returns true when the portlet class is type of javax.portlet.GenericPortlet
+     * and it contains a helper method for the portlet mode with public access.
+     * <P>
+     * The helper methods can be overriden from the <CODE>javax.portlet.GenericPortlet</CODE>
such as the following methods</CODE> 
+     * or annotated with <CODE>@RenderMode (javax.portlet.RenderMode)</CODE>.
+     * <ul>
+     *   <li><code>doView</code> for handling <code>view</code>
requests</li>
+     *   <li><code>doEdit</code> for handling <code>edit</code>
requests</li>
+     *   <li><code>doHelp</code> for handling <code>help</code>
requests</li>
+     * </ul>
+     * </P>
+     * 
+     * @param mode
+     * @return
+     * 
+     * @see javax.portlet.RenderMode
+     * @see javax.portlet.GenericPortlet#doView(RenderRequest, RenderResponse)
+     * @see javax.portlet.GenericPortlet#doEdit(RenderRequest, RenderResponse)
+     * @see javax.portlet.GenericPortlet#doHelp(RenderRequest, RenderResponse)
+     */
+    boolean hasRenderHelperMethod( PortletDefinition pd, PortletMode mode );
 }

Modified: portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/factory/PortletInstance.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/factory/PortletInstance.java?rev=910295&r1=910294&r2=910295&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/factory/PortletInstance.java
(original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-api/src/main/java/org/apache/jetspeed/factory/PortletInstance.java
Mon Feb 15 18:45:05 2010
@@ -18,6 +18,9 @@
 
 import javax.portlet.EventPortlet;
 import javax.portlet.Portlet;
+import javax.portlet.PortletMode;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
 import javax.portlet.ResourceServingPortlet;
 
 import org.apache.jetspeed.container.JetspeedPortletConfig;
@@ -31,7 +34,47 @@
  */
 public interface PortletInstance extends Portlet, EventPortlet, ResourceServingPortlet
 {
+    
+    /**
+     * Returns Jetspeed portlet config object.
+     * @return
+     */
     JetspeedPortletConfig getConfig();
+    
+    /**
+     * Returns the real portlet object instance. This portlet object instance
+     * can be a proxy instance. You can check if it is a proxy by using {@link #isProxyInstance()}.
+     * @return
+     */
     Portlet getRealPortlet();
+    
+    /**
+     * True if the real portlet object instance is a proxy instance.
+     * @return
+     */
     boolean isProxyInstance();
+    
+    /**
+     * Returns true when the real portlet object instance is type of javax.portlet.GenericPortlet
+     * and the instance contains a helper method for the portlet mode with public access.
+     * <P>
+     * The helper methods can be overriden from the <CODE>javax.portlet.GenericPortlet</CODE>
such as the following methods</CODE> 
+     * or annotated with <CODE>@RenderMode (javax.portlet.RenderMode)</CODE>.
+     * <ul>
+     *   <li><code>doView</code> for handling <code>view</code>
requests</li>
+     *   <li><code>doEdit</code> for handling <code>edit</code>
requests</li>
+     *   <li><code>doHelp</code> for handling <code>help</code>
requests</li>
+     * </ul>
+     * </P>
+     * 
+     * @param mode
+     * @return
+     * 
+     * @see javax.portlet.RenderMode
+     * @see javax.portlet.GenericPortlet#doView(RenderRequest, RenderResponse)
+     * @see javax.portlet.GenericPortlet#doEdit(RenderRequest, RenderResponse)
+     * @see javax.portlet.GenericPortlet#doHelp(RenderRequest, RenderResponse)
+     */
+    boolean hasRenderHelperMethod(PortletMode mode);
+    
 }
\ No newline at end of file

Modified: portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/portlet/PortletObjectProxy.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/portlet/PortletObjectProxy.java?rev=910295&r1=910294&r2=910295&view=diff
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/portlet/PortletObjectProxy.java
(original)
+++ portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/portlet/PortletObjectProxy.java
Mon Feb 15 18:45:05 2010
@@ -20,7 +20,6 @@
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
 import java.lang.reflect.Proxy;
 import java.util.HashSet;
 import java.util.List;
@@ -50,6 +49,7 @@
 import org.apache.jetspeed.om.portlet.PortletDefinition;
 import org.apache.jetspeed.om.portlet.Supports;
 import org.apache.jetspeed.util.BaseObjectProxy;
+import org.apache.jetspeed.util.GenericPortletUtils;
 
 /**
  * PortletObjectProxy
@@ -149,17 +149,11 @@
         
         if (portletObject instanceof GenericPortlet)
         {
-            try
-            {
-                this.portletDoEditMethod = this.portletObject.getClass().getMethod("doEdit",
new Class [] { RenderRequest.class, RenderResponse.class });
-                
-                if (Modifier.isPublic(this.portletDoEditMethod.getModifiers()))
-                {
-                    this.genericPortletInvocable = true;
-                }
-            }
-            catch (NoSuchMethodException e)
+            this.portletDoEditMethod = GenericPortletUtils.getRenderModeHelperMethod((GenericPortlet)
portletObject, PortletMode.EDIT);
+            
+            if (this.portletDoEditMethod != null)
             {
+                this.genericPortletInvocable = true;
             }
         }
     }

Added: portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/util/GenericPortletUtils.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/util/GenericPortletUtils.java?rev=910295&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/util/GenericPortletUtils.java
(added)
+++ portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/util/GenericPortletUtils.java
Mon Feb 15 18:45:05 2010
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.util;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+import javax.portlet.GenericPortlet;
+import javax.portlet.PortletMode;
+import javax.portlet.RenderMode;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+/**
+ * GenericPortletUtils
+ * 
+ * @version $Id$
+ */
+public class GenericPortletUtils
+{
+    
+    private GenericPortletUtils()
+    {
+    }
+    
+    /**
+     * Finds the helper method from the portlet object extending <CODE>javax.portlet.GenericPortlet</CODE>.
+     * <P>
+     * <EM>Note: the helper method can be retrieved only when the method is public.</EM>
+     * </P>
+     * 
+     * @param genericPortletClazz the portlet object extending <CODE>javax.portlet.GenericPortlet</CODE>
+     * @param mode the portlet mode for the helper method
+     * @return
+     * @see javax.portlet.GenericPortlet
+     */
+    public static Method getRenderModeHelperMethod(GenericPortlet genericPortlet, PortletMode
mode)
+    {
+        return getRenderModeHelperMethod(genericPortlet.getClass(), mode);
+    }
+    
+    /**
+     * Finds the helper method from the portlet class extending <CODE>javax.portlet.GenericPortlet</CODE>.
+     * <P>
+     * <EM>Note: the helper method can be retrieved only when the method is public.</EM>
+     * </P>
+     * 
+     * @param genericPortletClazz the portlet class extending <CODE>javax.portlet.GenericPortlet</CODE>
+     * @param mode the portlet mode for the helper method
+     * @return
+     * @see javax.portlet.GenericPortlet
+     */
+    public static Method getRenderModeHelperMethod(Class<? extends GenericPortlet>
genericPortletClazz, PortletMode mode)
+    {
+        Method helperMethod = null;
+        String modeName = mode.toString();
+        
+        for (Method method : genericPortletClazz.getMethods()) {
+            Annotation[] annotations = method.getAnnotations();
+            
+            if (annotations != null) {
+                for (Annotation annotation : annotations) {
+                    Class<? extends Annotation> annotationType = annotation.annotationType();
+                    
+                    if (RenderMode.class.equals(annotationType)) 
+                    {
+                        String name = ((RenderMode) annotation).name();
+                        
+                        if (modeName.equals(name))
+                        {
+                            if (Modifier.isPublic(method.getModifiers()))
+                            {
+                                return method;
+                            }
+                            else
+                            {
+                                return null;
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        
+        try
+        {
+            if (PortletMode.EDIT.equals(mode))
+            {
+                helperMethod = genericPortletClazz.getMethod("doEdit", new Class [] { RenderRequest.class,
RenderResponse.class });
+            }
+            else if (PortletMode.HELP.equals(mode))
+            {
+                helperMethod = genericPortletClazz.getMethod("doHelp", new Class [] { RenderRequest.class,
RenderResponse.class });
+            }
+            else if (PortletMode.VIEW.equals(mode))
+            {
+                helperMethod = genericPortletClazz.getMethod("doView", new Class [] { RenderRequest.class,
RenderResponse.class });
+            }
+        }
+        catch (NoSuchMethodException e)
+        {
+        }
+        
+        if (helperMethod != null && Modifier.isPublic(helperMethod.getModifiers()))
+        {
+            return helperMethod;
+        }
+        
+        return null;
+    }
+    
+}

Propchange: portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/util/GenericPortletUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/util/GenericPortletUtils.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/trunk/jetspeed-commons/src/main/java/org/apache/jetspeed/util/GenericPortletUtils.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: portals/jetspeed-2/portal/trunk/jetspeed-commons/src/test/java/org/apache/jetspeed/util/TestGenericPortletUtils.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/portal/trunk/jetspeed-commons/src/test/java/org/apache/jetspeed/util/TestGenericPortletUtils.java?rev=910295&view=auto
==============================================================================
--- portals/jetspeed-2/portal/trunk/jetspeed-commons/src/test/java/org/apache/jetspeed/util/TestGenericPortletUtils.java
(added)
+++ portals/jetspeed-2/portal/trunk/jetspeed-commons/src/test/java/org/apache/jetspeed/util/TestGenericPortletUtils.java
Mon Feb 15 18:45:05 2010
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jetspeed.util;
+
+import java.lang.reflect.Method;
+
+import javax.portlet.GenericPortlet;
+import javax.portlet.PortletMode;
+import javax.portlet.RenderMode;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+import junit.framework.TestCase;
+
+public class TestGenericPortletUtils extends TestCase
+{
+    private GenericPortlet genericPortletWithProtectedDoEdit;
+    private GenericPortlet genericPortletWithPublicDoEdit;
+    private GenericPortlet genericPortletWithAnnotatedProtectedDoEdit;
+    private GenericPortlet genericPortletWithAnnotatedPublicDoEdit;
+    
+    public void setUp()
+    {
+        genericPortletWithProtectedDoEdit = new GenericPortletWithProtectedDoEdit();
+        genericPortletWithPublicDoEdit = new GenericPortletWithPublicDoEdit();
+        genericPortletWithAnnotatedProtectedDoEdit = new GenericPortletWithAnnotatedProtectedDoEdit();
+        genericPortletWithAnnotatedPublicDoEdit = new GenericPortletWithAnnotatedPublicDoEdit();
+    }
+    
+    public void testRenderModeHelperMethods()
+    {
+        Method helperMethod = GenericPortletUtils.getRenderModeHelperMethod(genericPortletWithProtectedDoEdit,
PortletMode.EDIT);
+        assertNull("The helper method should not be found.", helperMethod);
+        
+        helperMethod = GenericPortletUtils.getRenderModeHelperMethod(genericPortletWithPublicDoEdit,
PortletMode.EDIT);
+        assertNotNull("The helper method should be found.", helperMethod);
+        assertEquals("doEdit", helperMethod.getName());
+        
+        helperMethod = GenericPortletUtils.getRenderModeHelperMethod(genericPortletWithAnnotatedProtectedDoEdit,
PortletMode.EDIT);
+        assertNull("The helper method should not be found.", helperMethod);
+        
+        helperMethod = GenericPortletUtils.getRenderModeHelperMethod(genericPortletWithAnnotatedPublicDoEdit,
PortletMode.EDIT);
+        assertNotNull("The helper method should be found.", helperMethod);
+        assertEquals("myEdit", helperMethod.getName());
+    }
+    
+    public class GenericPortletWithProtectedDoEdit extends GenericPortlet
+    {
+    }
+    
+    public class GenericPortletWithPublicDoEdit extends GenericPortlet
+    {
+        @RenderMode(name="help")
+        public void myHelp(RenderRequest request, RenderResponse response)
+        {
+        }
+        
+        @Override
+        public void doEdit(RenderRequest request, RenderResponse response)
+        {
+        }
+    }
+    
+    public class GenericPortletWithAnnotatedProtectedDoEdit extends GenericPortlet
+    {
+        @RenderMode(name="edit")
+        protected void myEdit(RenderRequest request, RenderResponse response)
+        {
+        }
+    }
+    
+    public class GenericPortletWithAnnotatedPublicDoEdit extends GenericPortlet
+    {
+        @RenderMode(name="edit")
+        public void myEdit(RenderRequest request, RenderResponse response)
+        {
+        }
+        
+        @Override
+        public void doEdit(RenderRequest request, RenderResponse response)
+        {
+        }
+    }
+    
+}

Propchange: portals/jetspeed-2/portal/trunk/jetspeed-commons/src/test/java/org/apache/jetspeed/util/TestGenericPortletUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: portals/jetspeed-2/portal/trunk/jetspeed-commons/src/test/java/org/apache/jetspeed/util/TestGenericPortletUtils.java
------------------------------------------------------------------------------
    svn:keywords = Id

Propchange: portals/jetspeed-2/portal/trunk/jetspeed-commons/src/test/java/org/apache/jetspeed/util/TestGenericPortletUtils.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

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=910295&r1=910294&r2=910295&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
Mon Feb 15 18:45:05 2010
@@ -374,17 +374,35 @@
   
   <bean id="DecorationValve" class="org.apache.jetspeed.decoration.DecorationValve" init-method="initialize">
     <meta key="j2:cat" value="default" />
+    
+    <!-- decoration factory -->
     <constructor-arg index='0'>
       <ref bean="DecorationFactory" />
     </constructor-arg>
+    
+    <!-- security access controller -->
     <constructor-arg index='1'>
       <ref bean="org.apache.jetspeed.security.SecurityAccessController" />
     </constructor-arg>
+    
+    <!-- decoration cache. set to null by default. -->
     <!-- 
-      <constructor-arg index='3'>
+    <constructor-arg index='2'>
       <ref bean="decorationContentCache"/>
-      </constructor-arg>            
+    </constructor-arg>
     -->
+    <constructor-arg index='2'><null/></constructor-arg>
+    
+    <!-- Flag to use http session for theme caching -->
+    <constructor-arg index='3'>
+      <value>false</value>
+    </constructor-arg>
+    
+    <!-- portlet factory -->
+    <constructor-arg index='4'>
+      <ref bean="portletFactory" />
+    </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


Mime
View raw message