Author: ate
Date: Thu Sep  6 04:22:55 2007
New Revision: 573222

URL: http://svn.apache.org/viewvc?rev=573222&view=rev
Log:
WICKET-656: New Wicket Portlet support: adding portlet support with a new 
WicketPortlet, WicketPortletFilter and support classes
See: https://issues.apache.org/jira/browse/WICKET-656#action_12525400
- refactored instantiating Wicket portlet-support entry point classes a little 
to make the easier extendable (like for different portals).
- support for a 
org.apache.wicket.protocol.http.portlet.WicketPortlet.properties file on the 
classpath allowing keeping all portal specific configurations out of a wicket 
portlet application

Modified:
    
wicket/branches/wicket-1.3.0-beta3-portlet-support/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
    
wicket/branches/wicket-1.3.0-beta3-portlet-support/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletRequestContext.java
    
wicket/branches/wicket-1.3.0-beta3-portlet-support/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/WicketFilterPortletContext.java
    
wicket/branches/wicket-1.3.0-beta3-portlet-support/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/WicketPortlet.java

Modified: 
wicket/branches/wicket-1.3.0-beta3-portlet-support/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
URL: 
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.0-beta3-portlet-support/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java?rev=573222&r1=573221&r2=573222&view=diff
==============================================================================
--- 
wicket/branches/wicket-1.3.0-beta3-portlet-support/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
 (original)
+++ 
wicket/branches/wicket-1.3.0-beta3-portlet-support/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
 Thu Sep  6 04:22:55 2007
@@ -456,7 +456,7 @@
                                {
                                        Class portletClass = 
Class.forName("javax.portlet.PortletContext");
                                        portletContextAvailable = Boolean.TRUE;
-                                       filterPortletContext = new 
WicketFilterPortletContext();
+                                       filterPortletContext = 
newWicketFilterPortletContext();
                                }
                                catch (ClassNotFoundException e)
                                {
@@ -476,6 +476,11 @@
                                
Thread.currentThread().setContextClassLoader(previousClassLoader);
                        }
                }
+       }
+       
+       protected WicketFilterPortletContext newWicketFilterPortletContext()
+       {
+               return new WicketFilterPortletContext();
        }
 
     protected void createRequestContext(WebRequest request, WebResponse 
response)

Modified: 
wicket/branches/wicket-1.3.0-beta3-portlet-support/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletRequestContext.java
URL: 
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.0-beta3-portlet-support/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletRequestContext.java?rev=573222&r1=573221&r2=573222&view=diff
==============================================================================
--- 
wicket/branches/wicket-1.3.0-beta3-portlet-support/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletRequestContext.java
 (original)
+++ 
wicket/branches/wicket-1.3.0-beta3-portlet-support/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletRequestContext.java
 Thu Sep  6 04:22:55 2007
@@ -42,6 +42,7 @@
  */
 public class PortletRequestContext extends RequestContext
 {
+       private final WicketFilterPortletContext filterContext;
        private final PortletConfig portletConfig;
        private final PortletRequest portletRequest;
        private final PortletResponse portletResponse;
@@ -55,38 +56,9 @@
        private final boolean resourceRequest;
        private String[] lastEncodedUrl = new String[2];
 
-       private static final String 
SERVLET_RESOURCE_URL_PORTLET_WINDOW_ID_PREFIX = "/ps:";
-       
-    public static final String decodePortletWindowId(String pathInfo)
-    {
-               String portletWindowId = null;
-       if (pathInfo != null && 
pathInfo.startsWith(SERVLET_RESOURCE_URL_PORTLET_WINDOW_ID_PREFIX))
-       {
-               int nextPath = pathInfo.indexOf('/',1);
-               if (nextPath > -1)
-               {
-                       portletWindowId = 
pathInfo.substring(SERVLET_RESOURCE_URL_PORTLET_WINDOW_ID_PREFIX.length(),nextPath);
-               }
-               else
-               {
-                       portletWindowId = 
pathInfo.substring(SERVLET_RESOURCE_URL_PORTLET_WINDOW_ID_PREFIX.length());
-               }
-       }
-       return portletWindowId;
-    }
-    
-    public static final String stripWindowIdFromPathInfo(String pathInfo)
-    {
-       if (pathInfo != null && 
pathInfo.startsWith(SERVLET_RESOURCE_URL_PORTLET_WINDOW_ID_PREFIX))
-       {
-               int nextPath = pathInfo.indexOf('/',1);
-               pathInfo = nextPath > -1 ? pathInfo.substring(nextPath) : null;
-       }
-       return pathInfo;
-    }
-    
-    public PortletRequestContext(ServletWebRequest request, WebResponse 
response)
+    public PortletRequestContext(WicketFilterPortletContext filterContext, 
ServletWebRequest request, WebResponse response)
     {
+       this.filterContext = filterContext;
        HttpServletRequest servletRequest = request.getHttpServletRequest();
        this.portletConfig = 
(PortletConfig)servletRequest.getAttribute("javax.portlet.config");
        this.portletRequest = 
(PortletRequest)servletRequest.getAttribute("javax.portlet.request");
@@ -210,7 +182,7 @@
        {
                if ( path != null )
                {
-                       String url = 
(SERVLET_RESOURCE_URL_PORTLET_WINDOW_ID_PREFIX.substring(1) + 
getPortletWindowId() + "/" + path);
+                       String url = 
filterContext.encodeWindowIdInPath(getPortletWindowId(), path);
                        return saveLastEncodedUrl(url,url);
                }
                return null;

Modified: 
wicket/branches/wicket-1.3.0-beta3-portlet-support/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/WicketFilterPortletContext.java
URL: 
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.0-beta3-portlet-support/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/WicketFilterPortletContext.java?rev=573222&r1=573221&r2=573222&view=diff
==============================================================================
--- 
wicket/branches/wicket-1.3.0-beta3-portlet-support/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/WicketFilterPortletContext.java
 (original)
+++ 
wicket/branches/wicket-1.3.0-beta3-portlet-support/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/WicketFilterPortletContext.java
 Thu Sep  6 04:22:55 2007
@@ -38,6 +38,8 @@
  */
 public class WicketFilterPortletContext
 {
+       private static final String 
SERVLET_RESOURCE_URL_PORTLET_WINDOW_ID_PREFIX = "/ps:";
+       
        public void initFilter(FilterConfig filterConfig, WebApplication 
webApplication) throws ServletException
     {
         
webApplication.getRequestCycleSettings().setRenderStrategy(IRequestCycleSettings.REDIRECT_TO_RENDER);
@@ -65,11 +67,11 @@
                ServletContext context = config.getServletContext();
                HttpServletRequest request = filterRequestContext.getRequest();
                String pathInfo = 
request.getRequestURI().substring(request.getContextPath().length()+filterPath.length());
-               String portletWindowId = 
PortletRequestContext.decodePortletWindowId(pathInfo);
+               String portletWindowId = decodePortletWindowId(pathInfo);
                if (portletWindowId != null)
                {
                HttpSession proxiedSession = 
ServletPortletSessionProxy.createProxy(request, portletWindowId);        
-               pathInfo = 
PortletRequestContext.stripWindowIdFromPathInfo(pathInfo);
+               pathInfo = stripWindowIdFromPathInfo(pathInfo);
                filterRequestContext.setRequest(new 
PortletServletRequestWrapper(context,request,proxiedSession, filterPath, 
pathInfo));                
                }
         }
@@ -79,9 +81,52 @@
     {
        if 
(request.getHttpServletRequest().getAttribute("javax.portlet.config") != null)
        {
-               new PortletRequestContext((ServletWebRequest)request, response);
+               newPortletRequestContext((ServletWebRequest)request, response);
                return true;
        }
         return false;
+    }
+    
+    public String getServletResourceUrlPortletWindowIdPrefix()
+    {
+       return SERVLET_RESOURCE_URL_PORTLET_WINDOW_ID_PREFIX;
+    }
+
+    public String decodePortletWindowId(String pathInfo)
+    {
+               String portletWindowId = null;
+       if (pathInfo != null && 
pathInfo.startsWith(getServletResourceUrlPortletWindowIdPrefix()))
+       {
+               int nextPath = pathInfo.indexOf('/',1);
+               if (nextPath > -1)
+               {
+                       portletWindowId = 
pathInfo.substring(getServletResourceUrlPortletWindowIdPrefix().length(),nextPath);
+               }
+               else
+               {
+                       portletWindowId = 
pathInfo.substring(getServletResourceUrlPortletWindowIdPrefix().length());
+               }
+       }
+       return portletWindowId;
+    }
+    
+    public String stripWindowIdFromPathInfo(String pathInfo)
+    {
+       if (pathInfo != null && 
pathInfo.startsWith(getServletResourceUrlPortletWindowIdPrefix()))
+       {
+               int nextPath = pathInfo.indexOf('/',1);
+               pathInfo = nextPath > -1 ? pathInfo.substring(nextPath) : null;
+       }
+       return pathInfo;
+    }
+    
+    public String encodeWindowIdInPath(String windowId, CharSequence path)
+    {
+               return 
(getServletResourceUrlPortletWindowIdPrefix().substring(1) + windowId + "/" + 
path);
+    }
+
+    protected void newPortletRequestContext(ServletWebRequest request, 
WebResponse response)
+    {
+               new PortletRequestContext(this, request, response);
     }
 }

Modified: 
wicket/branches/wicket-1.3.0-beta3-portlet-support/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/WicketPortlet.java
URL: 
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.0-beta3-portlet-support/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/WicketPortlet.java?rev=573222&r1=573221&r2=573222&view=diff
==============================================================================
--- 
wicket/branches/wicket-1.3.0-beta3-portlet-support/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/WicketPortlet.java
 (original)
+++ 
wicket/branches/wicket-1.3.0-beta3-portlet-support/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/WicketPortlet.java
 Thu Sep  6 04:22:55 2007
@@ -17,7 +17,9 @@
 package org.apache.wicket.protocol.http.portlet;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.HashMap;
+import java.util.Properties;
 
 import javax.portlet.ActionRequest;
 import javax.portlet.ActionResponse;
@@ -58,6 +60,7 @@
        public static final String RESPONSE_STATE_ATTR = 
WicketResponseState.class.getName();
        public static final String RESOURCE_URL_FACTORY_ATTR = 
PortletResourceURLFactory.class.getName();
        public static final String PORTLET_RESOURCE_URL_ATTR = "resourceUrl";
+       public static final String WICKET_PORTLET_PROPERTIES = 
WicketPortlet.class.getName().replace('.', '/')+".properties";
 
        private ServletContextProvider servletContextProvider;
        private PortletResourceURLFactory resourceURLFactory;
@@ -66,6 +69,7 @@
        public void init(PortletConfig config) throws PortletException
        {
                super.init(config);
+               Properties wicketPortletProperties = null;
                String contextProviderClassName = 
getContextProviderClassNameParameter(config);
                if (contextProviderClassName == null)
                {
@@ -74,10 +78,15 @@
                }
                if (contextProviderClassName == null)
                {
+                       wicketPortletProperties = 
getWicketPortletProperties(wicketPortletProperties);
+                       contextProviderClassName = 
wicketPortletProperties.getProperty(ServletContextProvider.class.getName());
+               }
+               if (contextProviderClassName == null)
+               {
                        throw new PortletException("Portlet " + 
config.getPortletName()
                                        + " is incorrectly configured. Init 
parameter "
-                                       + PARAM_SERVLET_CONTEXT_PROVIDER + " 
not specified, nor context parameter "
-                                       + 
ServletContextProvider.class.getName() + ".");
+                                       + PARAM_SERVLET_CONTEXT_PROVIDER + " 
not specified, nor as context parameter "
+                                       + 
ServletContextProvider.class.getName() + " or as property in 
"+WICKET_PORTLET_PROPERTIES + " in the classpath.");
                }
                try
                {
@@ -101,10 +110,15 @@
                }
                if (resourceURLFactoryClassName == null)
                {
+                       wicketPortletProperties = 
getWicketPortletProperties(wicketPortletProperties);
+                       resourceURLFactoryClassName = 
wicketPortletProperties.getProperty(PortletResourceURLFactory.class.getName());
+               }
+               if (resourceURLFactoryClassName == null)
+               {
                        throw new PortletException("Portlet " + 
config.getPortletName()
                                        + " is incorrectly configured. Init 
parameter "
-                                       + PARAM_PORTLET_RESOURCE_URL_FACTORY + 
" not specified, nor context parameter "
-                                       + 
PortletResourceURLFactory.class.getName() + ".");
+                                       + PARAM_PORTLET_RESOURCE_URL_FACTORY + 
" not specified, nor as context parameter "
+                                       + 
PortletResourceURLFactory.class.getName() + " or as property in 
"+WICKET_PORTLET_PROPERTIES + " in the classpath.");
                }
                try
                {
@@ -140,6 +154,27 @@
                                wicketFilterPath += "/";
                        }
                }
+       }
+       
+       protected Properties getWicketPortletProperties(Properties properties) 
throws PortletException
+       {
+               if (properties == null)
+               {
+                       properties = new Properties();
+               }
+               InputStream is = 
Thread.currentThread().getContextClassLoader().getResourceAsStream(WICKET_PORTLET_PROPERTIES);
+               if (is != null)
+               {
+                       try
+                       {
+                               properties.load(is);
+                       }
+                       catch (IOException e)
+                       {
+                               throw new PortletException("Failed to load 
WicketPortlet.properties from classpath", e);
+                       }
+               }
+               return properties;
        }
 
        public void processAction(ActionRequest request, ActionResponse 
response)


Reply via email to