You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2004/09/16 22:00:29 UTC

svn commit: rev 46202 - in cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon: environment/portlet portlet

Author: vgritsenko
Date: Thu Sep 16 13:00:29 2004
New Revision: 46202

Modified:
   cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/environment/portlet/PortletEnvironment.java
   cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portlet/CocoonPortlet.java
   cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portlet/ManagedCocoonPortlet.java
Log:
Portal block: Changed pathInfo and servletPath logic. pathInfo always starts
with '/', while servletPath always has no '/' at the end.                   



Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/environment/portlet/PortletEnvironment.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/environment/portlet/PortletEnvironment.java	(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/environment/portlet/PortletEnvironment.java	Thu Sep 16 13:00:29 2004
@@ -32,7 +32,7 @@
  *
  * @author <a href="mailto:alex.rudnev@dc.gov">Alex Rudnev</a>
  * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
- * @version CVS $Id: PortletEnvironment.java,v 1.3 2004/05/01 00:05:44 joerg Exp $
+ * @version CVS $Id$
  */
 public class PortletEnvironment extends AbstractEnvironment implements Redirector, PermanentRedirector {
 
@@ -108,6 +108,7 @@
      * and PortletResponse objects
      */
     public PortletEnvironment(String servletPath,
+                              String pathInfo,
                               String uri,
                               String root,
                               javax.portlet.ActionRequest request,
@@ -120,8 +121,6 @@
     throws IOException {
         super(uri, null, root, null);
 
-        String pathInfo = request.getParameter(PARAMETER_PATH_INFO);
-
         this.request = new ActionRequest(servletPath, pathInfo, request, this);
         this.request.setCharacterEncoding(defaultFormEncoding);
         this.request.setContainerEncoding(containerEncoding);
@@ -140,6 +139,7 @@
      * and PortletResponse objects
      */
     public PortletEnvironment(String servletPath,
+                              String pathInfo,
                               String uri,
                               String root,
                               javax.portlet.RenderRequest request,
@@ -151,8 +151,6 @@
                               int defaultSessionScope)
     throws IOException {
         super(uri, null, root, null);
-
-        String pathInfo = request.getParameter(PARAMETER_PATH_INFO);
 
         this.request = new RenderRequest(servletPath, pathInfo, request, this);
         this.request.setCharacterEncoding(defaultFormEncoding);

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portlet/CocoonPortlet.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portlet/CocoonPortlet.java	(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portlet/CocoonPortlet.java	Thu Sep 16 13:00:29 2004
@@ -68,6 +68,7 @@
 import javax.portlet.PortletSession;
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
+import javax.portlet.PortletRequest;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
@@ -510,8 +511,8 @@
             if (this.servletPath.startsWith("/")) {
                 this.servletPath = this.servletPath.substring(1);
             }
-            if (this.servletPath.length() > 0 && this.servletPath.charAt(0) != '/') {
-                this.servletPath += '/';
+            if (this.servletPath.endsWith("/")) {
+                this.servletPath = servletPath.substring(0, servletPath.length() - 1);
             }
         }
 
@@ -1098,24 +1099,12 @@
         // We got it... Process the request
         String servletPath = this.servletPath;
         if (servletPath == null) {
-            servletPath = "portlets/" + getPortletConfig().getPortletName() + '/';
+            servletPath = "portlets/" + getPortletConfig().getPortletName();
         }
+        String pathInfo = getPathInfo(request);
 
         String uri = servletPath;
-        String pathInfo = request.getParameter(PortletEnvironment.PARAMETER_PATH_INFO);
-        if (storeSessionPath) {
-            final PortletSession session = request.getPortletSession(true);
-            if (pathInfo == null) {
-                pathInfo = (String)session.getAttribute(PortletEnvironment.PARAMETER_PATH_INFO);
-            } else {
-                session.setAttribute(PortletEnvironment.PARAMETER_PATH_INFO, pathInfo);
-            }
-        }
-
         if (pathInfo != null) {
-            if (pathInfo.length() > 0 && pathInfo.charAt(0) == '/') {
-                pathInfo = pathInfo.substring(1);
-            }
             uri += pathInfo;
         }
 
@@ -1123,7 +1112,7 @@
 
         Environment env;
         try {
-            env = getEnvironment(servletPath, uri, request, res);
+            env = getEnvironment(servletPath, pathInfo, uri, request, res);
         } catch (Exception e) {
             if (getLogger().isErrorEnabled()) {
                 getLogger().error("Problem with Cocoon portlet", e);
@@ -1261,24 +1250,12 @@
         // We got it... Process the request
         String servletPath = this.servletPath;
         if (servletPath == null) {
-            servletPath = "portlets/" + getPortletConfig().getPortletName() + '/';
+            servletPath = "portlets/" + getPortletConfig().getPortletName();
         }
+        String pathInfo = getPathInfo(request);
 
         String uri = servletPath;
-        String pathInfo = request.getParameter(PortletEnvironment.PARAMETER_PATH_INFO);
-        if (storeSessionPath) {
-            final PortletSession session = request.getPortletSession(true);
-            if (pathInfo == null) {
-                pathInfo = (String)session.getAttribute(PortletEnvironment.PARAMETER_PATH_INFO);
-            } else {
-                session.setAttribute(PortletEnvironment.PARAMETER_PATH_INFO, pathInfo);
-            }
-        }
-
         if (pathInfo != null) {
-            if (pathInfo.length() > 0 && pathInfo.charAt(0) == '/') {
-                pathInfo = pathInfo.substring(1);
-            }
             uri += pathInfo;
         }
 
@@ -1287,7 +1264,7 @@
 
         Environment env;
         try {
-            env = getEnvironment(servletPath, uri, request, res);
+            env = getEnvironment(servletPath, pathInfo, uri, request, res);
         } catch (Exception e) {
             if (getLogger().isErrorEnabled()) {
                 getLogger().error("Problem with Cocoon portlet", e);
@@ -1418,6 +1395,30 @@
         }
     }
 
+    private String getPathInfo(PortletRequest request) {
+        PortletSession session = null;
+
+        String pathInfo = request.getParameter(PortletEnvironment.PARAMETER_PATH_INFO);
+        if (storeSessionPath) {
+            session = request.getPortletSession(true);
+            if (pathInfo == null) {
+                pathInfo = (String)session.getAttribute(PortletEnvironment.PARAMETER_PATH_INFO);
+            }
+        }
+
+        // Make sure it starts with or equals to '/'
+        if (pathInfo == null) {
+            pathInfo = "/";
+        } else if (!pathInfo.startsWith("/")) {
+            pathInfo = '/' + pathInfo;
+        }
+
+        if (storeSessionPath) {
+            session.setAttribute(PortletEnvironment.PARAMETER_PATH_INFO, pathInfo);
+        }
+        return pathInfo;
+    }
+
     protected void manageException(ActionRequest req, ActionResponse res, Environment env,
                                    String uri, String title, String message, String description,
                                    Exception e)
@@ -1473,6 +1474,7 @@
      * Create the environment for the request
      */
     protected Environment getEnvironment(String servletPath,
+                                         String pathInfo,
                                          String uri,
                                          ActionRequest req,
                                          ActionResponse res)
@@ -1484,6 +1486,7 @@
             formEncoding = this.defaultFormEncoding;
         }
         env = new PortletEnvironment(servletPath,
+                                     pathInfo,
                                      uri,
                                      this.portletContextURL,
                                      req,
@@ -1501,6 +1504,7 @@
      * Create the environment for the request
      */
     protected Environment getEnvironment(String servletPath,
+                                         String pathInfo,
                                          String uri,
                                          RenderRequest req,
                                          RenderResponse res)
@@ -1512,6 +1516,7 @@
             formEncoding = this.defaultFormEncoding;
         }
         env = new PortletEnvironment(servletPath,
+                                     pathInfo,
                                      uri,
                                      this.portletContextURL,
                                      req,

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portlet/ManagedCocoonPortlet.java
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portlet/ManagedCocoonPortlet.java	(original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/portal/java/org/apache/cocoon/portlet/ManagedCocoonPortlet.java	Thu Sep 16 13:00:29 2004
@@ -48,6 +48,7 @@
 import javax.portlet.PortletSession;
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
+import javax.portlet.PortletRequest;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
@@ -339,8 +340,8 @@
             if (this.servletPath.startsWith("/")) {
                 this.servletPath = this.servletPath.substring(1);
             }
-            if (this.servletPath.length() > 0 && this.servletPath.charAt(0) != '/') {
-                this.servletPath += '/';
+            if (this.servletPath.endsWith("/")) {
+                this.servletPath = servletPath.substring(0, servletPath.length() - 1);
             }
         }
 
@@ -397,24 +398,12 @@
         // We got it... Process the request
         String servletPath = this.servletPath;
         if (servletPath == null) {
-            servletPath = "portlets/" + getPortletConfig().getPortletName() + '/';
+            servletPath = "portlets/" + getPortletConfig().getPortletName();
         }
+        String pathInfo = getPathInfo(request);
 
         String uri = servletPath;
-        String pathInfo = request.getParameter(PortletEnvironment.PARAMETER_PATH_INFO);
-        if (storeSessionPath) {
-            final PortletSession session = request.getPortletSession(true);
-            if (pathInfo == null) {
-                pathInfo = (String)session.getAttribute(PortletEnvironment.PARAMETER_PATH_INFO);
-            } else {
-                session.setAttribute(PortletEnvironment.PARAMETER_PATH_INFO, pathInfo);
-            }
-        }
-
         if (pathInfo != null) {
-            if (pathInfo.length() > 0 && pathInfo.charAt(0) == '/') {
-                pathInfo = pathInfo.substring(1);
-            }
             uri += pathInfo;
         }
 
@@ -422,7 +411,7 @@
 
         Environment env;
         try {
-            env = getEnvironment(servletPath, uri, request, res);
+            env = getEnvironment(servletPath, pathInfo, uri, request, res);
         } catch (Exception e) {
             if (getLogger().isErrorEnabled()) {
                 getLogger().error("Problem with Cocoon portlet", e);
@@ -551,24 +540,12 @@
         // We got it... Process the request
         String servletPath = this.servletPath;
         if (servletPath == null) {
-            servletPath = "portlets/" + getPortletConfig().getPortletName() + '/';
+            servletPath = "portlets/" + getPortletConfig().getPortletName();
         }
+        String pathInfo = getPathInfo(request);
 
         String uri = servletPath;
-        String pathInfo = request.getParameter(PortletEnvironment.PARAMETER_PATH_INFO);
-        if (storeSessionPath) {
-            final PortletSession session = request.getPortletSession(true);
-            if (pathInfo == null) {
-                pathInfo = (String)session.getAttribute(PortletEnvironment.PARAMETER_PATH_INFO);
-            } else {
-                session.setAttribute(PortletEnvironment.PARAMETER_PATH_INFO, pathInfo);
-            }
-        }
-
         if (pathInfo != null) {
-            if (pathInfo.length() > 0 && pathInfo.charAt(0) == '/') {
-                pathInfo = pathInfo.substring(1);
-            }
             uri += pathInfo;
         }
 
@@ -577,7 +554,7 @@
 
         Environment env;
         try {
-            env = getEnvironment(servletPath, uri, request, res);
+            env = getEnvironment(servletPath, pathInfo, uri, request, res);
         } catch (Exception e) {
             if (getLogger().isErrorEnabled()) {
                 getLogger().error("Problem with Cocoon portlet", e);
@@ -696,6 +673,30 @@
         }
     }
 
+    private String getPathInfo(PortletRequest request) {
+        PortletSession session = null;
+
+        String pathInfo = request.getParameter(PortletEnvironment.PARAMETER_PATH_INFO);
+        if (storeSessionPath) {
+            session = request.getPortletSession(true);
+            if (pathInfo == null) {
+                pathInfo = (String)session.getAttribute(PortletEnvironment.PARAMETER_PATH_INFO);
+            }
+        }
+
+        // Make sure it starts with or equals to '/'
+        if (pathInfo == null) {
+            pathInfo = "/";
+        } else if (!pathInfo.startsWith("/")) {
+            pathInfo = '/' + pathInfo;
+        }
+
+        if (storeSessionPath) {
+            session.setAttribute(PortletEnvironment.PARAMETER_PATH_INFO, pathInfo);
+        }
+        return pathInfo;
+    }
+
     protected void manageException(ActionRequest req, ActionResponse res, Environment env,
                                    String uri, String title, String message, String description,
                                    Exception e)
@@ -751,6 +752,7 @@
      * Create the environment for the request
      */
     protected Environment getEnvironment(String servletPath,
+                                         String pathInfo,
                                          String uri,
                                          ActionRequest req,
                                          ActionResponse res)
@@ -762,6 +764,7 @@
             formEncoding = this.defaultFormEncoding;
         }
         env = new PortletEnvironment(servletPath,
+                                     pathInfo,
                                      uri,
                                      this.portletContextURL,
                                      req,
@@ -779,6 +782,7 @@
      * Create the environment for the request
      */
     protected Environment getEnvironment(String servletPath,
+                                         String pathInfo,
                                          String uri,
                                          RenderRequest req,
                                          RenderResponse res)
@@ -790,6 +794,7 @@
             formEncoding = this.defaultFormEncoding;
         }
         env = new PortletEnvironment(servletPath,
+                                     pathInfo,
                                      uri,
                                      this.portletContextURL,
                                      req,