Author: rgielen
Date: Thu Nov 5 23:54:25 2009
New Revision: 833247
URL:
http://svn.apache.org/viewvc?rev=833247&view=revLog:
SB-109:
Update JSR268 plugin to Struts > 2.1.8.1
Modified:
struts/sandbox/trunk/struts2-portlet2-plugin/pom.xml
struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/components/PortletUrlRenderer.java
struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/PortletActionConstants.java
struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/dispatcher/DispatcherServlet.java
struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/dispatcher/Jsr168Dispatcher.java
struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/dispatcher/Jsr286Dispatcher.java
struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptor.java
struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/result/PortletResult.java
struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/util/PortletUrlHelper.java
struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/PortletApplicationMapTest.java
struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java
Modified: struts/sandbox/trunk/struts2-portlet2-plugin/pom.xml
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-portlet2-plugin/pom.xml?rev=833247&r1=833246&r2=833247&view=diff==============================================================================
--- struts/sandbox/trunk/struts2-portlet2-plugin/pom.xml (original)
+++ struts/sandbox/trunk/struts2-portlet2-plugin/pom.xml Thu Nov 5 23:54:25 2009
@@ -27,7 +27,7 @@
<parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-plugins</artifactId>
- <version>2.1.3-SNAPSHOT</version>
+ <version>2.2.0-SNAPSHOT</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-portlet2-plugin</artifactId>
@@ -35,9 +35,10 @@
<name>Struts 2 Portlet 2.0 Plugin</name>
<scm>
- <connection>scm:svn:
https://boss.bekk.no/repos/projects/struts2-portlet2-plugin/</connection>
- <developerConnection>scm:svn:
https://boss.bekk.no/repos/projects/struts2-portlet2-plugin</developerConnection>
- <url>
https://boss.bekk.no/repos/projects/struts2-portlet2-plugin</url>
+ <connection>scm:svn:
http://svn.apache.org/repos/asf/struts/sandbox/trunk/struts2-portlet2-plugin/</connection>
+ <developerConnection>scm:svn:
https://svn.apache.org/repos/asf/struts/sandbox/trunk/struts2-portlet2-plugin/+ </developerConnection>
+ <url>
http://svn.apache.org/repos/asf/struts/sandbox/trunk/struts2-portlet2-plugin/</url>
</scm>
<dependencies>
@@ -48,14 +49,14 @@
<version>3.8.1</version>
</dependency>
- <dependency>
+ <dependency>
<groupId>javax.servlet</groupId>
<artifactId>jsp-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
- <!-- Velocity -->
+ <!-- Velocity -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
@@ -91,7 +92,7 @@
<version>2.0</version>
<scope>test</scope>
</dependency>
- <dependency>
+ <dependency>
<groupId>jmock</groupId>
<artifactId>jmock</artifactId>
<version>1.0.1</version>
@@ -112,7 +113,7 @@
<scope>test</scope>
</dependency>
- <dependency>
+ <dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.9</version>
@@ -124,48 +125,57 @@
<groupId>org.springframework</groupId>
<artifactId>spring-mock</artifactId>
<version>2.0.7</version>
- <scope>test</scope>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-portlet</artifactId>
+ <version>2.0.7</version>
+ <scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-portlet</artifactId>
- <version>2.0.7</version>
- <scope>test</scope>
- </dependency>
- <dependency>
+ <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>2.0.7</version>
- <scope>test</scope>
+ <scope>test</scope>
</dependency>
- <dependency>
+ <dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
- <version>1.1.1</version>
- <scope>test</scope>
+ <version>1.1.1</version>
+ <scope>test</scope>
</dependency>
- <dependency>
+ <dependency>
<groupId>${pom.groupId}</groupId>
<artifactId>struts2-junit-plugin</artifactId>
<version>${pom.version}</version>
<scope>test</scope>
</dependency>
- </dependencies>
- <repositories>
- <repository>
- <id>apache.snapshots</id>
- <name>Apache Maven Repository (Snapshots and Test Builds)</name>
- <url>
http://people.apache.org/repo/m2-snapshot-repository</url>
- <releases><enabled>false</enabled></releases>
- <snapshots><enabled>true</enabled></snapshots>
- </repository>
- <repository>
- <id>exo</id>
- <name>Exlolab repository</name>
- <url>
http://maven2.exoplatform.org/maven/</url>
- <releases><enabled>true</enabled></releases>
- <snapshots><enabled>false</enabled></snapshots>
- </repository>
-
- </repositories>
+ </dependencies>
+
+ <repositories>
+ <repository>
+ <id>apache.snapshots</id>
+ <name>Apache Maven Repository (Snapshots and Test Builds)</name>
+ <url>
http://people.apache.org/repo/m2-snapshot-repository</url>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </repository>
+ <repository>
+ <id>exo</id>
+ <name>Exlolab repository</name>
+ <url>
http://maven2.exoplatform.org/maven/</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+
+ </repositories>
</project>
Modified: struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/components/PortletUrlRenderer.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/components/PortletUrlRenderer.java?rev=833247&r1=833246&r2=833247&view=diff==============================================================================
--- struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/components/PortletUrlRenderer.java (original)
+++ struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/components/PortletUrlRenderer.java Thu Nov 5 23:54:25 2009
@@ -22,42 +22,60 @@
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
-import com.opensymphony.xwork2.util.TextUtils;
+import com.opensymphony.xwork2.inject.Inject;
import org.apache.struts2.StrutsException;
+import org.apache.struts2.dispatcher.mapper.ActionMapper;
import org.apache.struts2.portlet.util.PortletUrlHelper;
+import org.apache.struts2.portlet.context.PortletActionContext;
+import org.apache.commons.lang.xwork.StringUtils;
import java.io.IOException;
import java.io.Writer;
/**
* Implementation of the {@link UrlRenderer} interface that renders URLs for portlet environments.
- *
+ *
* @see UrlRenderer
*
*/
public class PortletUrlRenderer implements UrlRenderer {
-
+
+ /**
+ * The servlet renderer used when not executing in a portlet context.
+ */
+ private UrlRenderer servletRenderer = null;
+
+ public PortletUrlRenderer() {
+ this.servletRenderer = new ServletUrlRenderer();
+ }
+
+ @Inject
+ public void setActionMapper( ActionMapper actionMapper) {
+ servletRenderer.setActionMapper(actionMapper);
+ }
+
/**
* {@inheritDoc}
*/
- public void renderUrl(Writer writer, URL urlComponent) {
- String scheme = urlComponent.req.getScheme();
+ public void renderUrl(Writer writer, UrlProvider urlComponent) {
+ String scheme = urlComponent.getHttpServletRequest().getScheme();
- if (urlComponent.scheme != null) {
- scheme = urlComponent.scheme;
- }
+ if (urlComponent.getScheme() != null) {
+ scheme = urlComponent.getScheme();
+ }
String result;
if (onlyActionSpecified(urlComponent)) {
- result = PortletUrlHelper.buildUrl(urlComponent.action, urlComponent.namespace, urlComponent.method, urlComponent.parameters, urlComponent.portletUrlType, urlComponent.portletMode, urlComponent.windowState);
+ result = PortletUrlHelper.buildUrl(urlComponent.getAction(), urlComponent.getNamespace(), urlComponent.getMethod(), urlComponent.getParameters(), urlComponent.getPortletUrlType(), urlComponent.getPortletMode(), urlComponent.getWindowState());
} else if(onlyValueSpecified(urlComponent)){
- result = PortletUrlHelper.buildResourceUrl(urlComponent.value, urlComponent.parameters);
+ result = PortletUrlHelper.buildResourceUrl(urlComponent.getValue(), urlComponent.getParameters());
}
else {
result = createDefaultUrl(urlComponent);
}
- if ( urlComponent.anchor != null && urlComponent.anchor.length() > 0 ) {
- result += '#' + urlComponent.anchor;
+ final String anchor = urlComponent.getAnchor();
+ if ( anchor != null && anchor.length() > 0 ) {
+ result += '#' + anchor;
}
String var = urlComponent.getVar();
@@ -66,7 +84,7 @@
urlComponent.putInContext(result);
// add to the request and page scopes as well
- urlComponent.req.setAttribute(var, result);
+ urlComponent.getHttpServletRequest().setAttribute(var, result);
} else {
try {
writer.write(result);
@@ -76,69 +94,77 @@
}
}
- private String createDefaultUrl(URL urlComponent) {
+ private String createDefaultUrl(UrlProvider urlComponent) {
String result;
ActionInvocation ai = (ActionInvocation)urlComponent.getStack().getContext().get(
ActionContext.ACTION_INVOCATION);
String action = ai.getProxy().getActionName();
- result = PortletUrlHelper.buildUrl(action, urlComponent.namespace, urlComponent.method, urlComponent.parameters, urlComponent.portletUrlType, urlComponent.portletMode, urlComponent.windowState);
+ result = PortletUrlHelper.buildUrl(action, urlComponent.getNamespace(), urlComponent.getMethod(), urlComponent.getParameters(),
+ urlComponent.getPortletUrlType(), urlComponent.getPortletMode(), urlComponent.getWindowState());
return result;
}
- private boolean onlyValueSpecified(URL urlComponent) {
- return urlComponent.value != null && urlComponent.action == null;
- }
-
- private boolean onlyActionSpecified(URL urlComponent) {
- return urlComponent.value == null && urlComponent.action != null;
- }
+ private boolean onlyValueSpecified(UrlProvider urlComponent) {
+ return urlComponent.getValue() != null && urlComponent.getAction() == null;
+ }
+
+ private boolean onlyActionSpecified(UrlProvider urlComponent) {
+ return urlComponent.getValue() == null && urlComponent.getAction() != null;
+ }
/**
* {@inheritDoc}
*/
public void renderFormUrl(Form formComponent) {
- String action = null;
- if (formComponent.action != null) {
- action = formComponent.findString(formComponent.action);
+ if(PortletActionContext.getPortletContext() == null) {
+ servletRenderer.renderFormUrl(formComponent);
}
else {
- ActionInvocation ai = (ActionInvocation) formComponent.getStack().getContext().get(ActionContext.ACTION_INVOCATION);
- action = ai.getProxy().getActionName();
- }
+ String namespace = formComponent.determineNamespace(formComponent.namespace, formComponent.getStack(),
+ formComponent.request);
+ String action = null;
+ if (formComponent.action != null) {
+ action = formComponent.findString(formComponent.action);
+ }
+ else {
+ ActionInvocation ai = (ActionInvocation) formComponent.getStack().getContext().get(ActionContext.ACTION_INVOCATION);
+ action = ai.getProxy().getActionName();
+ }
- String type = "action";
- if (TextUtils.stringSet(formComponent.method)) {
- if ("GET".equalsIgnoreCase(formComponent.method.trim())) {
- type = "render";
+ String type = "action";
+ if (StringUtils.isNotEmpty(formComponent.method)) {
+ if ("GET".equalsIgnoreCase(formComponent.method.trim())) {
+ type = "render";
+ }
}
- }
- if (action != null) {
- String result = PortletUrlHelper.buildUrl(action, formComponent.namespace, null,
- formComponent.getParameters(), type, formComponent.portletMode, formComponent.windowState);
- formComponent.addParameter("action", result);
-
-
- // name/id: cut out anything between / and . should be the id and
- // name
- String id = formComponent.getId();
- if (id == null) {
- int slash = action.lastIndexOf('/');
- int dot = action.indexOf('.', slash);
- if (dot != -1) {
- id = action.substring(slash + 1, dot);
- } else {
- id = action.substring(slash + 1);
+ if (action != null) {
+ String result = PortletUrlHelper.buildUrl(action, namespace, null,
+ formComponent.getParameters(), type, formComponent.portletMode, formComponent.windowState);
+ formComponent.addParameter("action", result);
+
+
+ // name/id: cut out anything between / and . should be the id and
+ // name
+ String id = formComponent.getId();
+ if (id == null) {
+ int slash = action.lastIndexOf('/');
+ int dot = action.indexOf('.', slash);
+ if (dot != -1) {
+ id = action.substring(slash + 1, dot);
+ } else {
+ id = action.substring(slash + 1);
+ }
+ formComponent.addParameter("id", formComponent.escape(id));
}
- formComponent.addParameter("id", formComponent.escape(id));
}
}
-
}
- public void beforeRenderUrl(URL arg0) {
- // TODO Auto-generated method stub
-
+ public void beforeRenderUrl(UrlProvider urlComponent) {
+ if(PortletActionContext.getPortletContext() == null) {
+ servletRenderer.beforeRenderUrl(urlComponent);
+ }
}
}
Modified: struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/PortletActionConstants.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/PortletActionConstants.java?rev=833247&r1=833246&r2=833247&view=diff==============================================================================
--- struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/PortletActionConstants.java (original)
+++ struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/PortletActionConstants.java Thu Nov 5 23:54:25 2009
@@ -1,5 +1,5 @@
/*
- * $Id: PortletActionConstants.java 566324 2007-08-15 20:14:20Z nilsga $
+ * $Id: PortletActionConstants.java 671156 2008-06-24 12:33:59Z nilsga $
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,14 +18,14 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.struts2.portlet;
+import org.apache.struts2.ServletActionContext;
import org.apache.struts2.portlet.dispatcher.DispatcherServlet;
/**
- * Interface defining some constants used in the Struts portlet implementation.
- *
- * @deprecated Use the {@link PortletContstants} class instead.
+ * Interface defining some constants used in the Struts portlet implementation
*
*/
public interface PortletActionConstants {
@@ -54,13 +54,13 @@
* Constant used for the render phase (
* {@link javax.portlet.Portlet#render(javax.portlet.RenderRequest, javax.portlet.RenderResponse)})
*/
- Integer RENDER_PHASE = PortletContstants.RENDER_PHASE;
+ Integer RENDER_PHASE = new Integer(1);
/**
* Constant used for the event phase (
* {@link javax.portlet.Portlet#processAction(javax.portlet.ActionRequest, javax.portlet.ActionResponse)})
*/
- Integer EVENT_PHASE = PortletContstants.ACTION_PHASE;
+ Integer EVENT_PHASE = new Integer(2);
/**
* Key used for looking up and storing the
@@ -107,22 +107,22 @@
* {@link org.apache.struts2.portlet.context.PortletActionContext}.
*/
String DEFAULT_ACTION_FOR_MODE = "struts.portlet.defaultActionForMode";
-
+
/**
- * Key for request attribute indicating if the action has been reset.
+ * Key for request attribute indicating if the action has been reset.
*/
String ACTION_RESET = "struts.portlet.actionReset";
-
+
/**
* Key for session attribute indicating the location of the render direct action.
*/
String RENDER_DIRECT_LOCATION = "struts.portlet.renderDirectLocation";
-
+
/**
* Key for the dispatch instruction for the {@link DispatcherServlet}
*/
String DISPATCH_TO = "struts.portlet.dispatchTo";
-
+
/**
* Session key where the value stack from the event phase is stored.
*/
@@ -132,4 +132,9 @@
* Default name of dispatcher servlet in web.xml
*/
String DEFAULT_DISPATCHER_SERVLET_NAME = "Struts2PortletDispatcherServlet";
+
+ /**
+ * Key for the action mapping in the context
+ */
+ String ACTION_MAPPING = ServletActionContext.ACTION_MAPPING;
}
Modified: struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/dispatcher/DispatcherServlet.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/dispatcher/DispatcherServlet.java?rev=833247&r1=833246&r2=833247&view=diff==============================================================================
--- struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/dispatcher/DispatcherServlet.java (original)
+++ struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/dispatcher/DispatcherServlet.java Thu Nov 5 23:54:25 2009
@@ -29,8 +29,7 @@
import org.apache.struts2.dispatcher.StrutsRequestWrapper;
import org.apache.struts2.portlet.PortletActionConstants;
-
-import com.opensymphony.xwork2.util.TextUtils;
+import org.apache.commons.lang.xwork.StringUtils;
public class DispatcherServlet extends HttpServlet implements PortletActionConstants {
@@ -40,7 +39,7 @@
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String dispatchTo = (String) request.getAttribute(DISPATCH_TO);
HttpServletRequest wrapper = wrapRequestIfNecessary(request);
- if(TextUtils.stringSet(dispatchTo)) {
+ if(StringUtils.isNotEmpty(dispatchTo)) {
request.getRequestDispatcher(dispatchTo).include(wrapper, response);
}
}
Modified: struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/dispatcher/Jsr168Dispatcher.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/dispatcher/Jsr168Dispatcher.java?rev=833247&r1=833246&r2=833247&view=diff==============================================================================
--- struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/dispatcher/Jsr168Dispatcher.java (original)
+++ struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/dispatcher/Jsr168Dispatcher.java Thu Nov 5 23:54:25 2009
@@ -1,5 +1,5 @@
/*
- * $Id: Jsr168Dispatcher.java 602665 2007-12-09 12:11:25Z mrdon $
+ * $Id: Jsr168Dispatcher.java 759140 2009-03-27 13:51:52Z nilsga $
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,35 +18,19 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.struts2.portlet.dispatcher;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-import javax.portlet.ActionRequest;
-import javax.portlet.ActionResponse;
-import javax.portlet.Event;
-import javax.portlet.EventRequest;
-import javax.portlet.EventResponse;
-import javax.portlet.GenericPortlet;
-import javax.portlet.PortletConfig;
-import javax.portlet.PortletException;
-import javax.portlet.PortletMode;
-import javax.portlet.PortletRequest;
-import javax.portlet.PortletResponse;
-import javax.portlet.RenderRequest;
-import javax.portlet.RenderResponse;
-import javax.portlet.ResourceRequest;
-import javax.portlet.ResourceResponse;
-import javax.portlet.WindowState;
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+package org.apache.struts2.portlet.dispatcher;
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ActionProxy;
+import com.opensymphony.xwork2.ActionProxyFactory;
+import com.opensymphony.xwork2.config.ConfigurationException;
+import com.opensymphony.xwork2.inject.Container;
+import com.opensymphony.xwork2.util.FileManager;
+import com.opensymphony.xwork2.util.LocalizedTextUtil;
+import com.opensymphony.xwork2.util.logging.Logger;
+import com.opensymphony.xwork2.util.logging.LoggerFactory;
+import org.apache.commons.lang.xwork.StringUtils;
import org.apache.struts2.StrutsConstants;
import org.apache.struts2.StrutsException;
import org.apache.struts2.StrutsStatics;
@@ -57,6 +41,7 @@
import org.apache.struts2.dispatcher.mapper.ActionMapper;
import org.apache.struts2.dispatcher.mapper.ActionMapping;
import org.apache.struts2.dispatcher.multipart.MultiPartRequestWrapper;
+import org.apache.struts2.portlet.PortletActionConstants;
import org.apache.struts2.portlet.PortletApplicationMap;
import org.apache.struts2.portlet.PortletRequestMap;
import org.apache.struts2.portlet.PortletSessionMap;
@@ -66,641 +51,566 @@
import org.apache.struts2.portlet.servlet.PortletServletResponse;
import org.apache.struts2.util.AttributeMap;
-import com.opensymphony.xwork2.ActionContext;
-import com.opensymphony.xwork2.ActionProxy;
-import com.opensymphony.xwork2.ActionProxyFactory;
-import com.opensymphony.xwork2.config.ConfigurationException;
-import com.opensymphony.xwork2.inject.Container;
-import com.opensymphony.xwork2.util.FileManager;
-import com.opensymphony.xwork2.util.LocalizedTextUtil;
-import com.opensymphony.xwork2.util.TextUtils;
-import com.opensymphony.xwork2.util.logging.Logger;
-import com.opensymphony.xwork2.util.logging.LoggerFactory;
-
-import static org.apache.struts2.portlet.PortletContstants.*;
+import javax.portlet.*;
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
/**
* <!-- START SNIPPET: javadoc -->
* <p>
- * Struts JSR-168 portlet dispatcher. Similar to the WW2 Servlet dispatcher, but
- * adjusted to a portal environment. The portlet is configured through the
- * <tt>portlet.xml</tt> descriptor. Examples and descriptions follow below:
+ * Struts JSR-168 portlet dispatcher. Similar to the WW2 Servlet dispatcher,
+ * but adjusted to a portal environment. The portlet is configured through the <tt>portlet.xml</tt>
+ * descriptor. Examples and descriptions follow below:
* </p>
* <!-- END SNIPPET: javadoc -->
- *
+ *
* @author Nils-Helge Garli
* @author Rainer Hermanns
- *
- * <p>
- * <b>Init parameters</b>
- * </p>
- * <!-- START SNIPPET: params --> <table class="confluenceTable">
+ *
+ * <p><b>Init parameters</b></p>
+ * <!-- START SNIPPET: params -->
+ * <table class="confluenceTable">
* <tr>
- * <th class="confluenceTh">Name</th>
+ * <th class="confluenceTh">Name</th>
* <th class="confluenceTh">Description</th>
* <th class="confluenceTh">Default value</th>
* </tr>
* <tr>
- * <td class="confluenceTd">portletNamespace</td>
- * <td class="confluenceTd">The namespace for the portlet in the xwork
- * configuration. This namespace is prepended to all action lookups, and makes
- * it possible to host multiple portlets in the same portlet application. If
- * this parameter is set, the complete namespace will be
- * <tt>/portletNamespace/modeNamespace/actionName</tt></td>
- * <td class="confluenceTd">The default namespace</td>
+ * <td class="confluenceTd">portletNamespace</td><td class="confluenceTd">The namespace for the portlet in the xwork configuration. This
+ * namespace is prepended to all action lookups, and makes it possible to host multiple
+ * portlets in the same portlet application. If this parameter is set, the complete namespace
+ * will be <tt>/portletNamespace/modeNamespace/actionName</tt></td><td class="confluenceTd">The default namespace</td>
* </tr>
* <tr>
- * <td class="confluenceTd">viewNamespace</td>
- * <td class="confluenceTd">Base namespace in the xwork configuration for the
- * <tt>view</tt> portlet mode</td>
- * <td class="confluenceTd">The default namespace</td>
+ * <td class="confluenceTd">viewNamespace</td><td class="confluenceTd">Base namespace in the xwork configuration for the <tt>view</tt> portlet
+ * mode</td><td class="confluenceTd">The default namespace</td>
* </tr>
* <tr>
- * <td class="confluenceTd">editNamespace</td>
- * <td class="confluenceTd">Base namespace in the xwork configuration for the
- * <tt>edit</tt> portlet mode</td>
- * <td class="confluenceTd">The default namespace</td>
+ * <td class="confluenceTd">editNamespace</td><td class="confluenceTd">Base namespace in the xwork configuration for the <tt>edit</tt> portlet
+ * mode</td><td class="confluenceTd">The default namespace</td>
* </tr>
* <tr>
- * <td class="confluenceTd">helpNamespace</td>
- * <td class="confluenceTd">Base namespace in the xwork configuration for the
- * <tt>help</tt> portlet mode</td>
- * <td class="confluenceTd">The default namespace</td>
+ * <td class="confluenceTd">helpNamespace</td><td class="confluenceTd">Base namespace in the xwork configuration for the <tt>help</tt> portlet
+ * mode</td><td class="confluenceTd">The default namespace</td>
* </tr>
* <tr>
- * <td class="confluenceTd">defaultViewAction</td>
- * <td class="confluenceTd">Default action to invoke in the <tt>view</tt>
- * portlet mode if no action is specified</td>
- * <td class="confluenceTd"><tt>default</tt></td>
+ * <td class="confluenceTd">defaultViewAction</td><td class="confluenceTd">Default action to invoke in the <tt>view</tt> portlet mode if no action is
+ * specified</td><td class="confluenceTd"><tt>default</tt></td>
* </tr>
* <tr>
- * <td class="confluenceTd">defaultEditAction</td>
- * <td class="confluenceTd">Default action to invoke in the <tt>edit</tt>
- * portlet mode if no action is specified</td>
- * <td class="confluenceTd"><tt>default</tt></td>
+ * <td class="confluenceTd">defaultEditAction</td><td class="confluenceTd">Default action to invoke in the <tt>edit</tt> portlet mode if no action is
+ * specified</td><td class="confluenceTd"><tt>default</tt></td>
* </tr>
* <tr>
- * <td class="confluenceTd">defaultHelpAction</td>
- * <td class="confluenceTd">Default action to invoke in the <tt>help</tt>
- * portlet mode if no action is specified</td>
- * <td class="confluenceTd"><tt>default</tt></td>
+ * <td class="confluenceTd">defaultHelpAction</td><td class="confluenceTd">Default action to invoke in the <tt>help</tt> portlet mode if no action is
+ * specified</td><td class="confluenceTd"><tt>default</tt></td>
* </tr>
- * </table> <!-- END SNIPPET: params -->
- * <p>
- * <b>Example:</b>
- * </p>
- *
+ * </table>
+ * <!-- END SNIPPET: params -->
+ * <p><b>Example:</b></p>
* <pre>
- * <!-- START SNIPPET: example -->
- *
- * <init-param>
- * <!-- The view mode namespace. Maps to a namespace in the xwork config file -->
- * <name>viewNamespace</name>
- * <value>/view</value>
- * </init-param>
- * <init-param>
+ * <!-- START SNIPPET: example -->
+ *
+ * <init-param>
+ * <!-- The view mode namespace. Maps to a namespace in the xwork config file -->
+ * <name>viewNamespace</name>
+ * <value>/view</value>
+ * </init-param>
+ * <init-param>
+ * <!-- The default action to invoke in view mode -->
+ * <name>defaultViewAction</name>
+ * <value>index</value>
+ * </init-param>
+ * <init-param>
+ * <!-- The view mode namespace. Maps to a namespace in the xwork config file -->
+ * <name>editNamespace</name>
+ * <value>/edit</value>
+ * </init-param>
+ * <init-param>
* <!-- The default action to invoke in view mode -->
- * <name>defaultViewAction</name>
+ * <name>defaultEditAction</name>
* <value>index</value>
- * </init-param>
- * <init-param>
- * <!-- The view mode namespace. Maps to a namespace in the xwork config file -->
- * <name>editNamespace</name>
- * <value>/edit</value>
- * </init-param>
- * <init-param>
- * <!-- The default action to invoke in view mode -->
- * <name>defaultEditAction</name>
- * <value>index</value>
- * </init-param>
- * <init-param>
- * <!-- The view mode namespace. Maps to a namespace in the xwork config file -->
- * <name>helpNamespace</name>
- * <value>/help</value>
- * </init-param>
- * <init-param>
- * <!-- The default action to invoke in view mode -->
- * <name>defaultHelpAction</name>
- * <value>index</value>
- * </init-param>
- *
- * <!-- END SNIPPET: example -->
+ * </init-param>
+ * <init-param>
+ * <!-- The view mode namespace. Maps to a namespace in the xwork config file -->
+ * <name>helpNamespace</name>
+ * <value>/help</value>
+ * </init-param>
+ * <init-param>
+ * <!-- The default action to invoke in view mode -->
+ * <name>defaultHelpAction</name>
+ * <value>index</value>
+ * </init-param>
+ *
+ * <!-- END SNIPPET: example -->
* </pre>
*/
-public class Jsr168Dispatcher extends GenericPortlet implements StrutsStatics {
-
- private static final Logger LOG = LoggerFactory
- .getLogger(Jsr168Dispatcher.class);
-
- protected ActionProxyFactory factory = null;
-
- protected Map<PortletMode, String> modeMap = new HashMap<PortletMode, String>(
- 3);
-
- protected Map<PortletMode, ActionMapping> actionMap = new HashMap<PortletMode, ActionMapping>(
- 3);
-
- protected String portletNamespace = null;
-
- protected Dispatcher dispatcherUtils;
-
- protected ActionMapper actionMapper;
-
- /**
- * Initialize the portlet with the init parameters from <tt>portlet.xml</tt>
- */
- public void init(PortletConfig cfg) throws PortletException {
- super.init(cfg);
- LOG.debug("Initializing portlet " + getPortletName());
-
- Map<String, String> params = new HashMap<String, String>();
- for (Enumeration e = cfg.getInitParameterNames(); e.hasMoreElements();) {
- String name = (String) e.nextElement();
- String value = cfg.getInitParameter(name);
- params.put(name, value);
- }
-
- dispatcherUtils = new Dispatcher(new PortletServletContext(cfg
- .getPortletContext()), params);
- dispatcherUtils.init();
-
- // For testability
- if (factory == null) {
- factory = dispatcherUtils.getConfigurationManager()
- .getConfiguration().getContainer().getInstance(
- ActionProxyFactory.class);
- }
- portletNamespace = cfg.getInitParameter("portletNamespace");
- LOG.debug("PortletNamespace: " + portletNamespace);
- parseModeConfig(actionMap, cfg, PortletMode.VIEW, "viewNamespace",
- "defaultViewAction");
- parseModeConfig(actionMap, cfg, PortletMode.EDIT, "editNamespace",
- "defaultEditAction");
- parseModeConfig(actionMap, cfg, PortletMode.HELP, "helpNamespace",
- "defaultHelpAction");
- parseModeConfig(actionMap, cfg, new PortletMode("config"),
- "configNamespace", "defaultConfigAction");
- parseModeConfig(actionMap, cfg, new PortletMode("about"),
- "aboutNamespace", "defaultAboutAction");
- parseModeConfig(actionMap, cfg, new PortletMode("print"),
- "printNamespace", "defaultPrintAction");
- parseModeConfig(actionMap, cfg, new PortletMode("preview"),
- "previewNamespace", "defaultPreviewAction");
- parseModeConfig(actionMap, cfg, new PortletMode("edit_defaults"),
- "editDefaultsNamespace", "defaultEditDefaultsAction");
- if (!TextUtils.stringSet(portletNamespace)) {
- portletNamespace = "";
- }
- LocalizedTextUtil
- .addDefaultResourceBundle("org/apache/struts2/struts-messages");
-
- Container container = dispatcherUtils.getContainer();
- // check for configuration reloading
- if ("true".equalsIgnoreCase(container.getInstance(String.class,
- StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD))) {
- FileManager.setReloadingConfigs(true);
- }
-
- actionMapper = container.getInstance(ActionMapper.class);
- }
-
- /**
- * Parse the mode to namespace mappings configured in portlet.xml
- *
- * @param actionMap
- * The map with mode <-> default action mapping.
- * @param portletConfig
- * The PortletConfig.
- * @param portletMode
- * The PortletMode.
- * @param nameSpaceParam
- * Name of the init parameter where the namespace for the mode is
- * configured.
- * @param defaultActionParam
- * Name of the init parameter where the default action to execute
- * for the mode is configured.
- */
- void parseModeConfig(Map<PortletMode, ActionMapping> actionMap,
- PortletConfig portletConfig, PortletMode portletMode,
- String nameSpaceParam, String defaultActionParam) {
- String namespace = portletConfig.getInitParameter(nameSpaceParam);
- if (!TextUtils.stringSet(namespace)) {
- namespace = "";
- }
- modeMap.put(portletMode, namespace);
- String defaultAction = portletConfig
- .getInitParameter(defaultActionParam);
- String method = null;
- if (!TextUtils.stringSet(defaultAction)) {
- defaultAction = DEFAULT_ACTION_NAME;
- }
- if (defaultAction.indexOf('!') >= 0) {
- method = defaultAction.substring(defaultAction.indexOf('!') + 1);
- defaultAction = defaultAction.substring(0, defaultAction
- .indexOf('!'));
- }
- StringBuffer fullPath = new StringBuffer();
- if (TextUtils.stringSet(portletNamespace)) {
- fullPath.append(portletNamespace);
- }
- if (TextUtils.stringSet(namespace)) {
- fullPath.append(namespace).append("/");
- } else {
- fullPath.append("/");
- }
- fullPath.append(defaultAction);
- ActionMapping mapping = new ActionMapping();
- mapping.setName(getActionName(fullPath.toString()));
- mapping.setNamespace(getNamespace(fullPath.toString()));
- if (method != null) {
- mapping.setMethod(method);
- }
- actionMap.put(portletMode, mapping);
- }
-
- /**
- * Service an action from the <tt>event</tt> phase.
- *
- * @see javax.portlet.Portlet#processAction(javax.portlet.ActionRequest,
- * javax.portlet.ActionResponse)
- */
- @Override
- public void processAction(ActionRequest request, ActionResponse response)
- throws PortletException, IOException {
- LOG.debug("Entering processAction");
- resetActionContext();
- try {
- serviceAction(request, response, getActionMapping(request),
- getRequestMap(request), getParameterMap(request),
- getSessionMap(request), getApplicationMap(),
- portletNamespace, ACTION_PHASE);
- LOG.debug("Leaving processAction");
- } finally {
- ActionContext.setContext(null);
- }
- }
-
- /**
- * Service an action from the <tt>render</tt> phase.
- *
- * @see javax.portlet.Portlet#render(javax.portlet.RenderRequest,
- * javax.portlet.RenderResponse)
- */
- @Override
- public void render(RenderRequest request, RenderResponse response)
- throws PortletException, IOException {
-
- LOG.debug("Entering render");
- resetActionContext();
- response.setTitle(getTitle(request));
- if (!request.getWindowState().equals(WindowState.MINIMIZED)) {
- try {
- // Check to see if an event set the render to be included
- // directly
- serviceAction(request, response, getActionMapping(request),
- getRequestMap(request), getParameterMap(request),
- getSessionMap(request), getApplicationMap(),
- portletNamespace, RENDER_PHASE);
- LOG.debug("Leaving render");
- } finally {
- resetActionContext();
- }
- }
- }
-
- /**
- * Reset the action context.
- */
- protected void resetActionContext() {
- ActionContext.setContext(null);
- }
-
- /**
- * Merges all application and portlet attributes into a single
- * <tt>HashMap</tt> to represent the entire <tt>Action</tt> context.
- *
- * @param requestMap
- * a Map of all request attributes.
- * @param parameterMap
- * a Map of all request parameters.
- * @param sessionMap
- * a Map of all session attributes.
- * @param applicationMap
- * a Map of all servlet context attributes.
- * @param request
- * the PortletRequest object.
- * @param response
- * the PortletResponse object.
- * @param portletConfig
- * the PortletConfig object.
- * @param phase
- * The portlet phase (render or action, see
- * {@link PortletActionConstants})
- * @return a HashMap representing the <tt>Action</tt> context.
- */
- public HashMap createContextMap(Map requestMap, Map parameterMap,
- Map sessionMap, Map applicationMap, PortletRequest request,
- PortletResponse response, PortletConfig portletConfig, Integer phase)
- throws IOException {
-
- // TODO Must put http request/response objects into map for use with
- HttpServletResponse dummyResponse = new PortletServletResponse(response);
- HttpServletRequest dummyRequest = new PortletServletRequest(request,
- getPortletContext());
- ServletContext dummyServletContext = new PortletServletContext(
- getPortletContext());
- if (ACTION_PHASE.equals(phase)) {
- dummyRequest = dispatcherUtils.wrapRequest(dummyRequest,
- dummyServletContext);
- if (dummyRequest instanceof MultiPartRequestWrapper) {
- // Multipart request. Request parameters are encoded in the
- // multipart data,
- // so we need to manually add them to the parameter map.
- parameterMap.putAll(dummyRequest.getParameterMap());
- }
- }
- // ServletActionContext
- HashMap<String, Object> extraContext = new HashMap<String, Object>();
- // The dummy servlet objects. Eases reuse of existing interceptors that
- // uses the servlet objects.
- extraContext.put(StrutsStatics.HTTP_REQUEST, dummyRequest);
- extraContext.put(StrutsStatics.HTTP_RESPONSE, dummyResponse);
- extraContext.put(StrutsStatics.SERVLET_CONTEXT, dummyServletContext);
- // End dummy servlet objects
- extraContext.put(ActionContext.PARAMETERS, parameterMap);
- extraContext.put(ActionContext.SESSION, sessionMap);
- extraContext.put(ActionContext.APPLICATION, applicationMap);
-
- String defaultLocale = dispatcherUtils.getContainer().getInstance(
- String.class, StrutsConstants.STRUTS_LOCALE);
- Locale locale = null;
- if (defaultLocale != null) {
- locale = LocalizedTextUtil.localeFromString(defaultLocale, request
- .getLocale());
- } else {
- locale = request.getLocale();
- }
- extraContext.put(ActionContext.LOCALE, locale);
-
- extraContext.put(StrutsStatics.STRUTS_PORTLET_CONTEXT,
- getPortletContext());
- extraContext.put(REQUEST, request);
- extraContext.put(RESPONSE, response);
- extraContext.put(PORTLET_CONFIG, portletConfig);
- extraContext.put(PORTLET_NAMESPACE, portletNamespace);
- extraContext.put(DEFAULT_ACTION_FOR_MODE, actionMap.get(request
- .getPortletMode()));
- // helpers to get access to request/session/application scope
- extraContext.put("request", requestMap);
- extraContext.put("session", sessionMap);
- extraContext.put("application", applicationMap);
- extraContext.put("parameters", parameterMap);
- extraContext.put(MODE_NAMESPACE_MAP, modeMap);
+public class Jsr168Dispatcher extends GenericPortlet implements StrutsStatics,
+ PortletActionConstants {
- extraContext.put(PHASE, phase);
+ private static final Logger LOG = LoggerFactory.getLogger(Jsr168Dispatcher.class);
- AttributeMap attrMap = new AttributeMap(extraContext);
- extraContext.put("attr", attrMap);
+ private ActionProxyFactory factory = null;
- return extraContext;
- }
-
- /**
- * Loads the action and executes it. This method first creates the action
- * context from the given parameters then loads an <tt>ActionProxy</tt>
- * from the given action name and namespace. After that, the action is
- * executed and output channels throught the response object.
- *
- * @param request
- * the HttpServletRequest object.
- * @param response
- * the HttpServletResponse object.
- * @param mapping
- * the action mapping.
- * @param requestMap
- * a Map of request attributes.
- * @param parameterMap
- * a Map of request parameters.
- * @param sessionMap
- * a Map of all session attributes.
- * @param applicationMap
- * a Map of all application attributes.
- * @param portletNamespace
- * the namespace or context of the action.
- * @param phase
- * The portlet phase (render or action, see
- * {@link PortletActionConstants})
- */
- public void serviceAction(PortletRequest request, PortletResponse response,
- ActionMapping mapping, Map requestMap, Map parameterMap,
- Map sessionMap, Map applicationMap, String portletNamespace,
- Integer phase) throws PortletException {
- LOG.debug("serviceAction");
- String actionName = mapping.getName();
- String namespace = mapping.getNamespace();
- Dispatcher.setInstance(dispatcherUtils);
- try {
- HashMap extraContext = createContextMap(requestMap, parameterMap,
- sessionMap, applicationMap, request, response,
- getPortletConfig(), phase);
- LOG.debug("Creating action proxy for name = " + actionName
- + ", namespace = " + namespace);
- ActionProxy proxy = factory.createActionProxy(namespace,
- actionName, mapping.getMethod(), extraContext);
- request.setAttribute("struts.valueStack", proxy.getInvocation()
- .getStack());
- proxy.execute();
- } catch (ConfigurationException e) {
- LOG.error("Could not find action", e);
- throw new PortletException("Could not find action " + actionName, e);
- } catch (Exception e) {
- LOG.error("Could not execute action", e);
- throw new PortletException("Error executing action " + actionName,
- e);
- } finally {
- Dispatcher.setInstance(null);
- }
- }
-
- /**
- * Returns a Map of all application attributes. Copies all attributes from
- * the {@link PortletActionContext}into an {@link ApplicationMap}.
- *
- * @return a Map of all application attributes.
- */
- protected Map getApplicationMap() {
- return new PortletApplicationMap(getPortletContext());
- }
-
- /**
- * Gets the namespace of the action from the request. The namespace is the
- * same as the portlet mode. E.g, view mode is mapped to namespace
- * <code>view</code>, and edit mode is mapped to the namespace
- * <code>edit</code>
- *
- * @param request
- * the PortletRequest object.
- * @return the namespace of the action.
- */
- protected ActionMapping getActionMapping(final PortletRequest request) {
- ActionMapping mapping = null;
- String actionPath = null;
- if (resetAction(request)) {
- mapping = (ActionMapping) actionMap.get(request.getPortletMode());
- } else {
- actionPath = request.getParameter(ACTION_PARAM);
- if (!TextUtils.stringSet(actionPath)) {
- mapping = (ActionMapping) actionMap.get(request
- .getPortletMode());
- } else {
-
- // Use the usual action mapper, but it is expecting an action
- // extension
- // on the uri, so we add the default one, which should be ok as
- // the
- // portlet is a portlet first, a servlet second
- PortletServletRequest httpRequest = new PortletServletRequest(
- request, getPortletContext());
- mapping = actionMapper.getMapping(httpRequest, dispatcherUtils
- .getConfigurationManager());
- }
- }
-
- if (mapping == null) {
- throw new StrutsException(
- "Unable to locate action mapping for request, probably due to "
- + "an invalid action path: " + actionPath);
- }
- return mapping;
- }
-
- /**
- * Get the namespace part of the action path.
- *
- * @param actionPath
- * Full path to action
- * @return The namespace part.
- */
- String getNamespace(String actionPath) {
- int idx = actionPath.lastIndexOf('/');
- String namespace = "";
- if (idx >= 0) {
- namespace = actionPath.substring(0, idx);
- }
- return namespace;
- }
-
- /**
- * Get the action name part of the action path.
- *
- * @param actionPath
- * Full path to action
- * @return The action name.
- */
- String getActionName(String actionPath) {
- int idx = actionPath.lastIndexOf('/');
- String action = actionPath;
- if (idx >= 0) {
- action = actionPath.substring(idx + 1);
- }
- return action;
- }
-
- /**
- * Returns a Map of all request parameters. This implementation just calls
- * {@link PortletRequest#getParameterMap()}.
- *
- * @param request
- * the PortletRequest object.
- * @return a Map of all request parameters.
- * @throws IOException
- * if an exception occurs while retrieving the parameter map.
- */
- protected Map getParameterMap(PortletRequest request) throws IOException {
- return new HashMap(request.getParameterMap());
- }
-
- /**
- * Returns a Map of all request attributes. The default implementation is to
- * wrap the request in a {@link RequestMap}. Override this method to
- * customize how request attributes are mapped.
- *
- * @param request
- * the PortletRequest object.
- * @return a Map of all request attributes.
- */
- protected Map getRequestMap(PortletRequest request) {
- return new PortletRequestMap(request);
- }
-
- /**
- * Returns a Map of all session attributes. The default implementation is to
- * wrap the reqeust in a {@link SessionMap}. Override this method to
- * customize how session attributes are mapped.
- *
- * @param request
- * the PortletRequest object.
- * @return a Map of all session attributes.
- */
- protected Map getSessionMap(PortletRequest request) {
- return new PortletSessionMap(request);
- }
-
- /**
- * Convenience method to ease testing.
- *
- * @param factory
- */
- protected void setActionProxyFactory(ActionProxyFactory factory) {
- this.factory = factory;
- }
-
- /**
- * Check to see if the action parameter is valid for the current portlet
- * mode. If the portlet mode has been changed with the portal widgets, the
- * action name is invalid, since the action name belongs to the previous
- * executing portlet mode. If this method evaluates to <code>true</code>
- * the <code>default<Mode>Action</code> is used instead.
- *
- * @param request
- * The portlet request.
- * @return <code>true</code> if the action should be reset.
- */
- private boolean resetAction(PortletRequest request) {
- boolean reset = false;
- Map paramMap = request.getParameterMap();
- String[] modeParam = (String[]) paramMap.get(MODE_PARAM);
- if (modeParam != null && modeParam.length == 1) {
- String originatingMode = modeParam[0];
- String currentMode = request.getPortletMode().toString();
- if (!currentMode.equals(originatingMode)) {
- reset = true;
- }
- }
- if (reset) {
- request.setAttribute(ACTION_RESET, Boolean.TRUE);
- } else {
- request.setAttribute(ACTION_RESET, Boolean.FALSE);
- }
- return reset;
- }
-
- public void destroy() {
- if (dispatcherUtils == null) {
- LOG
- .warn("something is seriously wrong, DispatcherUtil is not initialized (null) ");
- } else {
- dispatcherUtils.cleanup();
- }
- }
-
- /**
- * @param actionMapper
- * the actionMapper to set
- */
- public void setActionMapper(ActionMapper actionMapper) {
- this.actionMapper = actionMapper;
- }
+ private Map<PortletMode,String> modeMap = new HashMap<PortletMode,String>(3);
+ private Map<PortletMode,ActionMapping> actionMap = new HashMap<PortletMode,ActionMapping>(3);
+
+ String portletNamespace = null;
+
+ private Dispatcher dispatcherUtils;
+
+ private ActionMapper actionMapper;
+
+ private Container container;
+
+ /**
+ * Initialize the portlet with the init parameters from <tt>portlet.xml</tt>
+ */
+ public void init(PortletConfig cfg) throws PortletException {
+ super.init(cfg);
+ if (LOG.isDebugEnabled()) LOG.debug("Initializing portlet " + getPortletName());
+
+ Map<String,String> params = new HashMap<String,String>();
+ for (Enumeration e = cfg.getInitParameterNames(); e.hasMoreElements(); ) {
+ String name = (String) e.nextElement();
+ String value = cfg.getInitParameter(name);
+ params.put(name, value);
+ }
+
+ dispatcherUtils = new Dispatcher(new PortletServletContext(cfg.getPortletContext()), params);
+ dispatcherUtils.init();
+
+ // For testability
+ if (factory == null) {
+ factory = dispatcherUtils.getConfigurationManager().getConfiguration().getContainer().getInstance(ActionProxyFactory.class);
+ }
+ portletNamespace = cfg.getInitParameter("portletNamespace");
+ if (LOG.isDebugEnabled()) LOG.debug("PortletNamespace: " + portletNamespace);
+ parseModeConfig(actionMap, cfg, PortletMode.VIEW, "viewNamespace",
+ "defaultViewAction");
+ parseModeConfig(actionMap, cfg, PortletMode.EDIT, "editNamespace",
+ "defaultEditAction");
+ parseModeConfig(actionMap, cfg, PortletMode.HELP, "helpNamespace",
+ "defaultHelpAction");
+ parseModeConfig(actionMap, cfg, new PortletMode("config"), "configNamespace",
+ "defaultConfigAction");
+ parseModeConfig(actionMap, cfg, new PortletMode("about"), "aboutNamespace",
+ "defaultAboutAction");
+ parseModeConfig(actionMap, cfg, new PortletMode("print"), "printNamespace",
+ "defaultPrintAction");
+ parseModeConfig(actionMap, cfg, new PortletMode("preview"), "previewNamespace",
+ "defaultPreviewAction");
+ parseModeConfig(actionMap, cfg, new PortletMode("edit_defaults"),
+ "editDefaultsNamespace", "defaultEditDefaultsAction");
+ if (StringUtils.isEmpty(portletNamespace)) {
+ portletNamespace = "";
+ }
+ LocalizedTextUtil
+ .addDefaultResourceBundle("org/apache/struts2/struts-messages");
+
+ container = dispatcherUtils.getContainer();
+ //check for configuration reloading
+ if ("true".equalsIgnoreCase(container.getInstance(String.class, StrutsConstants.STRUTS_CONFIGURATION_XML_RELOAD))) {
+ FileManager.setReloadingConfigs(true);
+ }
+
+ actionMapper = container.getInstance(ActionMapper.class);
+ }
+
+ /**
+ * Parse the mode to namespace mappings configured in portlet.xml
+ * @param actionMap The map with mode <-> default action mapping.
+ * @param portletConfig The PortletConfig.
+ * @param portletMode The PortletMode.
+ * @param nameSpaceParam Name of the init parameter where the namespace for the mode
+ * is configured.
+ * @param defaultActionParam Name of the init parameter where the default action to
+ * execute for the mode is configured.
+ */
+ void parseModeConfig(Map<PortletMode, ActionMapping> actionMap, PortletConfig portletConfig,
+ PortletMode portletMode, String nameSpaceParam,
+ String defaultActionParam) {
+ String namespace = portletConfig.getInitParameter(nameSpaceParam);
+ if (StringUtils.isEmpty(namespace)) {
+ namespace = "";
+ }
+ modeMap.put(portletMode, namespace);
+ String defaultAction = portletConfig
+ .getInitParameter(defaultActionParam);
+ String method = null;
+ if (StringUtils.isEmpty(defaultAction)) {
+ defaultAction = DEFAULT_ACTION_NAME;
+ }
+ if(defaultAction.indexOf('!') >= 0) {
+ method = defaultAction.substring(defaultAction.indexOf('!') + 1);
+ defaultAction = defaultAction.substring(0, defaultAction.indexOf('!'));
+ }
+ StringBuffer fullPath = new StringBuffer();
+ if (StringUtils.isNotEmpty(portletNamespace)) {
+ fullPath.append(portletNamespace);
+ }
+ if (StringUtils.isNotEmpty(namespace)) {
+ fullPath.append(namespace).append("/");
+ } else {
+ fullPath.append("/");
+ }
+ fullPath.append(defaultAction);
+ ActionMapping mapping = new ActionMapping();
+ mapping.setName(getActionName(fullPath.toString()));
+ mapping.setNamespace(getNamespace(fullPath.toString()));
+ if(method != null) {
+ mapping.setMethod(method);
+ }
+ actionMap.put(portletMode, mapping);
+ }
+
+ /**
+ * Service an action from the <tt>event</tt> phase.
+ *
+ * @see javax.portlet.Portlet#processAction(javax.portlet.ActionRequest,
+ * javax.portlet.ActionResponse)
+ */
+ public void processAction(ActionRequest request, ActionResponse response)
+ throws PortletException, IOException {
+ if (LOG.isDebugEnabled()) LOG.debug("Entering processAction");
+ resetActionContext();
+ try {
+ serviceAction(request, response, getRequestMap(request), getParameterMap(request),
+ getSessionMap(request), getApplicationMap(),
+ portletNamespace, EVENT_PHASE);
+ if (LOG.isDebugEnabled()) LOG.debug("Leaving processAction");
+ } finally {
+ ActionContext.setContext(null);
+ }
+ }
+
+ /**
+ * Service an action from the <tt>render</tt> phase.
+ *
+ * @see javax.portlet.Portlet#render(javax.portlet.RenderRequest,
+ * javax.portlet.RenderResponse)
+ */
+ public void render(RenderRequest request, RenderResponse response)
+ throws PortletException, IOException {
+
+ if (LOG.isDebugEnabled()) LOG.debug("Entering render");
+ resetActionContext();
+ response.setTitle(getTitle(request));
+ if(!request.getWindowState().equals(WindowState.MINIMIZED)) {
+ try {
+ // Check to see if an event set the render to be included directly
+ serviceAction(request, response, getRequestMap(request), getParameterMap(request),
+ getSessionMap(request), getApplicationMap(),
+ portletNamespace, RENDER_PHASE);
+ if (LOG.isDebugEnabled()) LOG.debug("Leaving render");
+ } finally {
+ resetActionContext();
+ }
+ }
+ }
+
+ /**
+ * Reset the action context.
+ */
+ void resetActionContext() {
+ ActionContext.setContext(null);
+ }
+
+ /**
+ * Merges all application and portlet attributes into a single
+ * <tt>HashMap</tt> to represent the entire <tt>Action</tt> context.
+ *
+ * @param requestMap a Map of all request attributes.
+ * @param parameterMap a Map of all request parameters.
+ * @param sessionMap a Map of all session attributes.
+ * @param applicationMap a Map of all servlet context attributes.
+ * @param request the PortletRequest object.
+ * @param response the PortletResponse object.
+ * @param portletConfig the PortletConfig object.
+ * @param phase The portlet phase (render or action, see
+ * {@link PortletActionConstants})
+ * @return a HashMap representing the <tt>Action</tt> context.
+ */
+ public HashMap<String, Object> createContextMap(Map<String, Object> requestMap, Map<String, String[]> parameterMap,
+ Map<String, Object> sessionMap, Map<String, Object> applicationMap, PortletRequest request,
+ PortletResponse response, HttpServletRequest servletRequest, HttpServletResponse servletResponse, ServletContext servletContext, PortletConfig portletConfig, Integer phase) throws IOException {
+
+ // TODO Must put http request/response objects into map for use with
+ container.inject(servletRequest);
+
+ // ServletActionContext
+ HashMap<String, Object> extraContext = new HashMap<String, Object>();
+ // The dummy servlet objects. Eases reuse of existing interceptors that uses the servlet objects.
+ extraContext.put(StrutsStatics.HTTP_REQUEST, servletRequest);
+ extraContext.put(StrutsStatics.HTTP_RESPONSE, servletResponse);
+ extraContext.put(StrutsStatics.SERVLET_CONTEXT, servletContext);
+ // End dummy servlet objects
+ extraContext.put(ActionContext.PARAMETERS, parameterMap);
+ extraContext.put(ActionContext.SESSION, sessionMap);
+ extraContext.put(ActionContext.APPLICATION, applicationMap);
+
+ String defaultLocale = dispatcherUtils.getContainer().getInstance(String.class, StrutsConstants.STRUTS_LOCALE);
+ Locale locale = null;
+ if (defaultLocale != null) {
+ locale = LocalizedTextUtil.localeFromString(defaultLocale, request.getLocale());
+ } else {
+ locale = request.getLocale();
+ }
+ extraContext.put(ActionContext.LOCALE, locale);
+
+ extraContext.put(StrutsStatics.STRUTS_PORTLET_CONTEXT, getPortletContext());
+ extraContext.put(REQUEST, request);
+ extraContext.put(RESPONSE, response);
+ extraContext.put(PORTLET_CONFIG, portletConfig);
+ extraContext.put(PORTLET_NAMESPACE, portletNamespace);
+ extraContext.put(DEFAULT_ACTION_FOR_MODE, actionMap.get(request.getPortletMode()));
+ // helpers to get access to request/session/application scope
+ extraContext.put("request", requestMap);
+ extraContext.put("session", sessionMap);
+ extraContext.put("application", applicationMap);
+ extraContext.put("parameters", parameterMap);
+ extraContext.put(MODE_NAMESPACE_MAP, modeMap);
+
+ extraContext.put(PHASE, phase);
+
+ AttributeMap attrMap = new AttributeMap(extraContext);
+ extraContext.put("attr", attrMap);
+
+ return extraContext;
+ }
+
+ /**
+ * Loads the action and executes it. This method first creates the action
+ * context from the given parameters then loads an <tt>ActionProxy</tt>
+ * from the given action name and namespace. After that, the action is
+ * executed and output channels throught the response object.
+ *
+ * @param request the HttpServletRequest object.
+ * @param response the HttpServletResponse object.
+ * @param requestMap a Map of request attributes.
+ * @param parameterMap a Map of request parameters.
+ * @param sessionMap a Map of all session attributes.
+ * @param applicationMap a Map of all application attributes.
+ * @param portletNamespace the namespace or context of the action.
+ * @param phase The portlet phase (render or action, see
+ * {@link PortletActionConstants})
+ */
+ public void serviceAction(PortletRequest request, PortletResponse response, Map<String, Object> requestMap, Map<String, String[]> parameterMap,
+ Map<String, Object> sessionMap, Map<String, Object> applicationMap, String portletNamespace,
+ Integer phase) throws PortletException {
+ if (LOG.isDebugEnabled()) LOG.debug("serviceAction");
+ Dispatcher.setInstance(dispatcherUtils);
+ String actionName = null;
+ String namespace = null;
+ try {
+ ServletContext servletContext = new PortletServletContext(getPortletContext());
+ HttpServletRequest servletRequest = new PortletServletRequest(request, getPortletContext());
+ HttpServletResponse servletResponse = new PortletServletResponse(response);
+ if(EVENT_PHASE.equals(phase)) {
+ servletRequest = dispatcherUtils.wrapRequest(servletRequest, servletContext);
+ if(servletRequest instanceof MultiPartRequestWrapper) {
+ // Multipart request. Request parameters are encoded in the multipart data,
+ // so we need to manually add them to the parameter map.
+ parameterMap.putAll(servletRequest.getParameterMap());
+ }
+ }
+ container.inject(servletRequest);
+ ActionMapping mapping = getActionMapping(request, servletRequest);
+ actionName = mapping.getName();
+ namespace = mapping.getNamespace();
+ HashMap<String, Object> extraContext = createContextMap(requestMap, parameterMap,
+ sessionMap, applicationMap, request, response, servletRequest, servletResponse,
+ servletContext, getPortletConfig(), phase);
+ extraContext.put(PortletActionConstants.ACTION_MAPPING, mapping);
+ LOG.debug("Creating action proxy for name = " + actionName
+ + ", namespace = " + namespace);
+ ActionProxy proxy = factory.createActionProxy(namespace,
+ actionName, mapping.getMethod(), extraContext);
+ request.setAttribute("struts.valueStack", proxy.getInvocation()
+ .getStack());
+ proxy.execute();
+ } catch (ConfigurationException e) {
+ LOG.error("Could not find action", e);
+ throw new PortletException("Could not find action " + actionName, e);
+ } catch (Exception e) {
+ LOG.error("Could not execute action", e);
+ throw new PortletException("Error executing action " + actionName,
+ e);
+ } finally {
+ Dispatcher.setInstance(null);
+ }
+ }
+
+ /**
+ * Returns a Map of all application attributes. Copies all attributes from
+ * the {@link PortletActionContext}into an {@link ApplicationMap}.
+ *
+ * @return a Map of all application attributes.
+ */
+ protected Map getApplicationMap() {
+ return new PortletApplicationMap(getPortletContext());
+ }
+
+ /**
+ * Gets the namespace of the action from the request. The namespace is the
+ * same as the portlet mode. E.g, view mode is mapped to namespace
+ * <code>view</code>, and edit mode is mapped to the namespace
+ * <code>edit</code>
+ *
+ * @param request the PortletRequest object.
+ * @return the namespace of the action.
+ */
+ protected ActionMapping getActionMapping(final PortletRequest portletRequest, final HttpServletRequest servletRequest) {
+ ActionMapping mapping = null;
+ String actionPath = getDefaultActionPath(portletRequest);
+ if (resetAction(portletRequest)) {
+ mapping = (ActionMapping) actionMap.get(portletRequest.getPortletMode());
+ } else {
+ actionPath = servletRequest.getParameter(ACTION_PARAM);
+ if (StringUtils.isEmpty(actionPath)) {
+ mapping = (ActionMapping) actionMap.get(portletRequest
+ .getPortletMode());
+ } else {
+
+ // Use the usual action mapper, but it is expecting an action extension
+ // on the uri, so we add the default one, which should be ok as the
+ // portlet is a portlet first, a servlet second
+ mapping = actionMapper.getMapping(servletRequest, dispatcherUtils.getConfigurationManager());
+ }
+ }
+
+ if (mapping == null) {
+ throw new StrutsException("Unable to locate action mapping for request, probably due to " +
+ "an invalid action path: "+actionPath);
+ }
+ return mapping;
+ }
+
+ protected String getDefaultActionPath( PortletRequest portletRequest ) {
+ return null;
+ }
+
+ /**
+ * Get the namespace part of the action path.
+ * @param actionPath Full path to action
+ * @return The namespace part.
+ */
+ String getNamespace(String actionPath) {
+ int idx = actionPath.lastIndexOf('/');
+ String namespace = "";
+ if (idx >= 0) {
+ namespace = actionPath.substring(0, idx);
+ }
+ return namespace;
+ }
+
+ /**
+ * Get the action name part of the action path.
+ * @param actionPath Full path to action
+ * @return The action name.
+ */
+ String getActionName(String actionPath) {
+ int idx = actionPath.lastIndexOf('/');
+ String action = actionPath;
+ if (idx >= 0) {
+ action = actionPath.substring(idx + 1);
+ }
+ return action;
+ }
+
+ /**
+ * Returns a Map of all request parameters. This implementation just calls
+ * {@link PortletRequest#getParameterMap()}.
+ *
+ * @param request the PortletRequest object.
+ * @return a Map of all request parameters.
+ * @throws IOException if an exception occurs while retrieving the parameter
+ * map.
+ */
+ protected Map<String, String[]> getParameterMap(PortletRequest request) throws IOException {
+ return new HashMap<String, String[]>(request.getParameterMap());
+ }
+
+ /**
+ * Returns a Map of all request attributes. The default implementation is to
+ * wrap the request in a {@link RequestMap}. Override this method to
+ * customize how request attributes are mapped.
+ *
+ * @param request the PortletRequest object.
+ * @return a Map of all request attributes.
+ */
+ protected Map getRequestMap(PortletRequest request) {
+ return new PortletRequestMap(request);
+ }
+
+ /**
+ * Returns a Map of all session attributes. The default implementation is to
+ * wrap the reqeust in a {@link SessionMap}. Override this method to
+ * customize how session attributes are mapped.
+ *
+ * @param request the PortletRequest object.
+ * @return a Map of all session attributes.
+ */
+ protected Map getSessionMap(PortletRequest request) {
+ return new PortletSessionMap(request);
+ }
+
+ /**
+ * Convenience method to ease testing.
+ * @param factory
+ */
+ protected void setActionProxyFactory(ActionProxyFactory factory) {
+ this.factory = factory;
+ }
+
+ /**
+ * Check to see if the action parameter is valid for the current portlet mode. If the portlet
+ * mode has been changed with the portal widgets, the action name is invalid, since the
+ * action name belongs to the previous executing portlet mode. If this method evaluates to
+ * <code>true</code> the <code>default<Mode>Action</code> is used instead.
+ * @param request The portlet request.
+ * @return <code>true</code> if the action should be reset.
+ */
+ private boolean resetAction(PortletRequest request) {
+ boolean reset = false;
+ Map paramMap = request.getParameterMap();
+ String[] modeParam = (String[]) paramMap.get(MODE_PARAM);
+ if (modeParam != null && modeParam.length == 1) {
+ String originatingMode = modeParam[0];
+ String currentMode = request.getPortletMode().toString();
+ if (!currentMode.equals(originatingMode)) {
+ reset = true;
+ }
+ }
+ if(reset) {
+ request.setAttribute(ACTION_RESET, Boolean.TRUE);
+ }
+ else {
+ request.setAttribute(ACTION_RESET, Boolean.FALSE);
+ }
+ return reset;
+ }
+
+ public void destroy() {
+ if (dispatcherUtils == null) {
+ LOG.warn("something is seriously wrong, DispatcherUtil is not initialized (null) ");
+ } else {
+ dispatcherUtils.cleanup();
+ }
+ }
+
+ /**
+ * @param actionMapper the actionMapper to set
+ */
+ public void setActionMapper(ActionMapper actionMapper) {
+ this.actionMapper = actionMapper;
+ }
}
Modified: struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/dispatcher/Jsr286Dispatcher.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/dispatcher/Jsr286Dispatcher.java?rev=833247&r1=833246&r2=833247&view=diff==============================================================================
--- struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/dispatcher/Jsr286Dispatcher.java (original)
+++ struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/dispatcher/Jsr286Dispatcher.java Thu Nov 5 23:54:25 2009
@@ -1,55 +1,42 @@
package org.apache.struts2.portlet.dispatcher;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.portlet.EventRequest;
-import javax.portlet.EventResponse;
-import javax.portlet.PortletException;
-import javax.portlet.ResourceRequest;
-import javax.portlet.ResourceResponse;
-
-import org.apache.struts2.StrutsException;
-import org.apache.struts2.dispatcher.mapper.ActionMapping;
-import org.apache.struts2.portlet.servlet.PortletServletRequest;
-
import com.opensymphony.xwork2.ActionContext;
-import com.opensymphony.xwork2.util.TextUtils;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
+import static org.apache.struts2.portlet.PortletContstants.SERVE_RESOURCE_PHASE;
-import static org.apache.struts2.portlet.PortletContstants.*;
+import javax.portlet.*;
+import java.io.IOException;
public class Jsr286Dispatcher extends Jsr168Dispatcher {
private final static Logger LOG = LoggerFactory.getLogger(Jsr286Dispatcher.class);
-
-
+
+
@Override
- public void processEvent(EventRequest request, EventResponse response)
+ public void processEvent( EventRequest request, EventResponse response)
throws PortletException, IOException {
- LOG.debug("Entering processEvent");
+ if (LOG.isDebugEnabled()) LOG.debug("Entering processEvent");
resetActionContext();
try {
// We'll use the event name as the "action"
- serviceAction(request, response, getActionMapping(request),
+ serviceAction(request, response,
getRequestMap(request), getParameterMap(request),
getSessionMap(request), getApplicationMap(),
portletNamespace, EVENT_PHASE);
- LOG.debug("Leaving processAction");
+ if (LOG.isDebugEnabled()) LOG.debug("Leaving processAction");
} finally {
ActionContext.setContext(null);
}
}
@Override
- public void serveResource(ResourceRequest request, ResourceResponse response)
+ public void serveResource( ResourceRequest request, ResourceResponse response)
throws PortletException, IOException {
- LOG.debug("Entering serveResource");
+ if (LOG.isDebugEnabled()) LOG.debug("Entering serveResource");
resetActionContext();
try {
- serviceAction(request, response, getActionMapping(request),
+ serviceAction(request, response,
getRequestMap(request), getParameterMap(request),
getSessionMap(request), getApplicationMap(),
portletNamespace, SERVE_RESOURCE_PHASE);
@@ -58,38 +45,13 @@
ActionContext.setContext(null);
}
}
-
- /**
- * Gets the action mapping from the event request.
- *
- * @param request
- * the EventRequest object.
- */
- protected ActionMapping getActionMapping(final EventRequest request) {
- ActionMapping mapping = null;
- String actionPath = null;
- actionPath = request.getEvent().getName();
- if (!TextUtils.stringSet(actionPath)) {
- mapping = (ActionMapping) actionMap.get(request.getPortletMode());
- } else {
- Map<String, String[]> extra = new HashMap<String, String[]>();
- extra.put(ACTION_PARAM, new String[]{actionPath});
- // Use the usual action mapper, but it is expecting an action
- // extension
- // on the uri, so we add the default one, which should be ok as the
- // portlet is a portlet first, a servlet second
- PortletServletRequest httpRequest = new PortletServletRequest(
- request, getPortletContext(), extra);
- mapping = actionMapper.getMapping(httpRequest, dispatcherUtils
- .getConfigurationManager());
- }
- if (mapping == null) {
- throw new StrutsException(
- "Unable to locate action mapping for request, probably due to "
- + "an invalid action path: " + actionPath);
- }
- return mapping;
- }
+ @Override
+ protected String getDefaultActionPath( PortletRequest portletRequest ) {
+ if (portletRequest instanceof EventRequest) {
+ return ((EventRequest) portletRequest).getEvent().getName();
+ }
+ return super.getDefaultActionPath(portletRequest);
+ }
}
Modified: struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptor.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptor.java?rev=833247&r1=833246&r2=833247&view=diff==============================================================================
--- struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptor.java (original)
+++ struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptor.java Thu Nov 5 23:54:25 2009
@@ -30,12 +30,12 @@
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.util.CompoundRoot;
-import com.opensymphony.xwork2.util.TextUtils;
import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
import static org.apache.struts2.portlet.PortletContstants.*;
+import org.apache.commons.lang.xwork.StringUtils;
public class PortletStateInterceptor extends AbstractInterceptor {
@@ -71,9 +71,9 @@
@SuppressWarnings("unchecked")
private void restoreStack(ActionInvocation invocation) {
RenderRequest request = (RenderRequest) invocation.getInvocationContext().get(REQUEST);
- if (TextUtils.stringSet(request.getParameter(EVENT_ACTION))) {
+ if (StringUtils.isNotEmpty(request.getParameter(EVENT_ACTION))) {
if(!isProperPrg(invocation)) {
- LOG.debug("Restoring value stack from event phase");
+ if (LOG.isDebugEnabled()) LOG.debug("Restoring value stack from event phase");
ValueStack oldStack = (ValueStack) invocation.getInvocationContext().getSession().get(
STACK_FROM_EVENT_PHASE);
if (oldStack != null) {
@@ -81,11 +81,11 @@
ValueStack currentStack = invocation.getStack();
CompoundRoot root = currentStack.getRoot();
root.addAll(oldRoot);
- LOG.debug("Restored stack");
+ if (LOG.isDebugEnabled()) LOG.debug("Restored stack");
}
}
else {
- LOG.debug("Won't restore stack from event phase since it's a proper PRG request");
+ if (LOG.isDebugEnabled()) LOG.debug("Won't restore stack from event phase since it's a proper PRG request");
}
}
}
Modified: struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/result/PortletResult.java
URL:
http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/result/PortletResult.java?rev=833247&r1=833246&r2=833247&view=diff==============================================================================
--- struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/result/PortletResult.java (original)
+++ struts/sandbox/trunk/struts2-portlet2-plugin/src/main/java/org/apache/struts2/portlet/result/PortletResult.java Thu Nov 5 23:54:25 2009
@@ -41,23 +41,23 @@
import org.apache.struts2.dispatcher.StrutsResultSupport;
import org.apache.struts2.portlet.PortletActionConstants;
import org.apache.struts2.portlet.context.PortletActionContext;
+import org.apache.commons.lang.xwork.StringUtils;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.inject.Inject;
-import com.opensymphony.xwork2.util.TextUtils;
import com.opensymphony.xwork2.util.logging.Logger;
import com.opensymphony.xwork2.util.logging.LoggerFactory;
/**
* Result type that includes a JSP to render.
- *
+ *
*/
public class PortletResult extends StrutsResultSupport implements PortletActionConstants {
private static final long serialVersionUID = 434251393926178567L;
private boolean useDispatcherServlet;
-
+
private String dispatcherServletName = DEFAULT_DISPATCHER_SERVLET_NAME;
/**
@@ -68,7 +68,7 @@
private String contentType = "text/html";
private String title;
-
+
protected PortletMode portletMode;
public PortletResult() {
@@ -83,7 +83,7 @@
* Execute the result. Obtains the
* {@link javax.portlet.PortletRequestDispatcher}from the
* {@link PortletActionContext}and includes the JSP.
- *
+ *
* @see com.opensymphony.xwork2.Result#execute(com.opensymphony.xwork2.ActionInvocation)
*/
public void doExecute(String finalLocation, ActionInvocation actionInvocation) throws Exception {
@@ -99,7 +99,7 @@
/**
* Executes the regular servlet result.
- *
+ *
* @param finalLocation
* @param actionInvocation
*/
@@ -121,16 +121,16 @@
/**
* Executes the action result.
- *
+ *
* @param finalLocation
* @param invocation
*/
protected void executeActionResult(String finalLocation, ActionInvocation invocation) throws Exception {
String phase = (PortletActionContext.isEvent()) ? "Event" : "Action";
- LOG.debug("Executing result in "+phase+" phase");
+ if (LOG.isDebugEnabled()) LOG.debug("Executing result in "+phase+" phase");
StateAwareResponse res = (StateAwareResponse)PortletActionContext.getResponse();
Map sessionMap = invocation.getInvocationContext().getSession();
- LOG.debug("Setting event render parameter: " + finalLocation);
+ if (LOG.isDebugEnabled()) LOG.debug("Setting event render parameter: " + finalLocation);
if (finalLocation.indexOf('?') != -1) {
convertQueryParamsToRenderParams(res, finalLocation.substring(finalLocation.indexOf('?') + 1));
finalLocation = finalLocation.substring(0, finalLocation.indexOf('?'));
@@ -156,7 +156,7 @@
/**
* Converts the query params to render params.
- *
+ *
* @param response
* @param queryParams
*/
@@ -172,21 +172,21 @@
/**
* Executes the render result.
- *
+ *
* @param finalLocation
* @throws PortletException
* @throws IOException
*/
protected void executeMimeResult(final String finalLocation) throws PortletException, IOException {
- LOG.debug("Executing mime result");
+ if (LOG.isDebugEnabled()) LOG.debug("Executing mime result");
PortletContext ctx = PortletActionContext.getPortletContext();
PortletRequest req = PortletActionContext.getRequest();
MimeResponse res = (MimeResponse)PortletActionContext.getResponse();
res.setContentType(contentType);
- if (TextUtils.stringSet(title) && res instanceof RenderResponse) {
+ if (StringUtils.isNotEmpty(title) && res instanceof RenderResponse) {
((RenderResponse)res).setTitle(title);
}
- LOG.debug("Location: " + finalLocation);
+ if (LOG.isDebugEnabled()) LOG.debug("Location: " + finalLocation);
if (useDispatcherServlet) {
req.setAttribute(DISPATCH_TO, finalLocation);
PortletRequestDispatcher dispatcher = ctx.getNamedDispatcher(dispatcherServletName);
@@ -205,7 +205,7 @@
/**
* Sets the content type.
- *
+ *
* @param contentType
* The content type to set.
*/
@@ -215,25 +215,25 @@
/**
* Sets the title.
- *
+ *
* @param title
* The title to set.
*/
public void setTitle(String title) {
this.title = title;
}
-
+
public void setPortletMode(String portletMode) {
if(portletMode != null) {
this.portletMode = new PortletMode(portletMode);
}
}
- @Inject("struts.portlet.useDispatcherServlet")
+ @Inject("struts.portlet.useDispatcherServlet")
public void setUseDispatcherServlet(String useDispatcherServlet) {
this.useDispatcherServlet = "true".equalsIgnoreCase(useDispatcherServlet);
}
-
+
@Inject("struts.portlet.dispatcherServletName")
public void setDispatcherServletName(String dispatcherServletName) {
this.dispatcherServletName = dispatcherServletName;