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:56 UTC
svn commit: rev 46203 - in cocoon/trunk/src/blocks/portal/java/org/apache/cocoon: environment/portlet portlet
Author: vgritsenko
Date: Thu Sep 16 13:00:54 2004
New Revision: 46203
Modified:
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/environment/portlet/PortletEnvironment.java
cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portlet/CocoonPortlet.java
cocoon/trunk/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/trunk/src/blocks/portal/java/org/apache/cocoon/environment/portlet/PortletEnvironment.java
==============================================================================
--- cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/environment/portlet/PortletEnvironment.java (original)
+++ cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/environment/portlet/PortletEnvironment.java Thu Sep 16 13:00:54 2004
@@ -100,6 +100,7 @@
* and PortletResponse objects
*/
public PortletEnvironment(String servletPath,
+ String pathInfo,
String uri,
javax.portlet.ActionRequest request,
javax.portlet.ActionResponse response,
@@ -111,8 +112,6 @@
throws IOException {
super(uri, null, null);
- String pathInfo = request.getParameter(PARAMETER_PATH_INFO);
-
this.request = new ActionRequest(servletPath, pathInfo, request, this);
this.request.setCharacterEncoding(defaultFormEncoding);
this.request.setContainerEncoding(containerEncoding);
@@ -131,6 +130,7 @@
* and PortletResponse objects
*/
public PortletEnvironment(String servletPath,
+ String pathInfo,
String uri,
javax.portlet.RenderRequest request,
javax.portlet.RenderResponse response,
@@ -141,8 +141,6 @@
int defaultSessionScope)
throws IOException {
super(uri, null, null);
-
- String pathInfo = request.getParameter(PARAMETER_PATH_INFO);
this.request = new RenderRequest(servletPath, pathInfo, request, this);
this.request.setCharacterEncoding(defaultFormEncoding);
Modified: cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portlet/CocoonPortlet.java
==============================================================================
--- cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portlet/CocoonPortlet.java (original)
+++ cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portlet/CocoonPortlet.java Thu Sep 16 13:00:54 2004
@@ -69,6 +69,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;
@@ -512,8 +513,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);
}
}
@@ -1100,24 +1101,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;
}
@@ -1125,7 +1114,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);
@@ -1263,24 +1252,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;
}
@@ -1289,7 +1266,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);
@@ -1420,6 +1397,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)
@@ -1475,6 +1476,7 @@
* Create the environment for the request
*/
protected Environment getEnvironment(String servletPath,
+ String pathInfo,
String uri,
ActionRequest req,
ActionResponse res)
@@ -1486,6 +1488,7 @@
formEncoding = this.defaultFormEncoding;
}
env = new PortletEnvironment(servletPath,
+ pathInfo,
uri,
req,
res,
@@ -1502,6 +1505,7 @@
* Create the environment for the request
*/
protected Environment getEnvironment(String servletPath,
+ String pathInfo,
String uri,
RenderRequest req,
RenderResponse res)
@@ -1513,6 +1517,7 @@
formEncoding = this.defaultFormEncoding;
}
env = new PortletEnvironment(servletPath,
+ pathInfo,
uri,
req,
res,
Modified: cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portlet/ManagedCocoonPortlet.java
==============================================================================
--- cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portlet/ManagedCocoonPortlet.java (original)
+++ cocoon/trunk/src/blocks/portal/java/org/apache/cocoon/portlet/ManagedCocoonPortlet.java Thu Sep 16 13:00:54 2004
@@ -54,6 +54,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;
@@ -299,8 +300,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);
}
}
@@ -357,24 +358,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;
}
@@ -382,7 +371,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);
@@ -511,24 +500,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;
}
@@ -537,7 +514,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);
@@ -656,6 +633,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)
@@ -711,6 +712,7 @@
* Create the environment for the request
*/
protected Environment getEnvironment(String servletPath,
+ String pathInfo,
String uri,
ActionRequest req,
ActionResponse res)
@@ -722,6 +724,7 @@
formEncoding = this.defaultFormEncoding;
}
env = new PortletEnvironment(servletPath,
+ pathInfo,
uri,
req,
res,
@@ -738,6 +741,7 @@
* Create the environment for the request
*/
protected Environment getEnvironment(String servletPath,
+ String pathInfo,
String uri,
RenderRequest req,
RenderResponse res)
@@ -749,6 +753,7 @@
formEncoding = this.defaultFormEncoding;
}
env = new PortletEnvironment(servletPath,
+ pathInfo,
uri,
req,
res,