You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2012/02/24 09:14:55 UTC
svn commit: r1293127 - in
/struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2:
components/PortletUrlRenderer.java portlet/context/PortletActionContext.java
Author: lukaszlenart
Date: Fri Feb 24 08:14:55 2012
New Revision: 1293127
URL: http://svn.apache.org/viewvc?rev=1293127&view=rev
Log:
WW-3763 restores the old behaviour of Portlet plugin, to allow use portlets in standalone application as well
Modified:
struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/components/PortletUrlRenderer.java
struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/context/PortletActionContext.java
Modified: struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/components/PortletUrlRenderer.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/components/PortletUrlRenderer.java?rev=1293127&r1=1293126&r2=1293127&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/components/PortletUrlRenderer.java (original)
+++ struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/components/PortletUrlRenderer.java Fri Feb 24 08:14:55 2012
@@ -39,7 +39,6 @@ import java.io.Writer;
* Implementation of the {@link UrlRenderer} interface that renders URLs for portlet environments.
*
* @see UrlRenderer
- *
*/
public class PortletUrlRenderer implements UrlRenderer {
@@ -62,31 +61,30 @@ public class PortletUrlRenderer implemen
}
@Inject
- public void setActionMapper( ActionMapper actionMapper) {
+ public void setActionMapper(ActionMapper actionMapper) {
servletRenderer.setActionMapper(actionMapper);
}
- /**
- * {@inheritDoc}
- */
- public void renderUrl(Writer writer, UrlProvider urlComponent) {
- String scheme = urlComponent.getHttpServletRequest().getScheme();
-
- if (urlComponent.getScheme() != null) {
- scheme = urlComponent.getScheme();
+ /**
+ * {@inheritDoc}
+ */
+ public void renderUrl(Writer writer, UrlProvider urlComponent) {
+ if (PortletActionContext.getPortletContext() == null || "none".equalsIgnoreCase(urlComponent.getPortletUrlType())) {
+ servletRenderer.renderUrl(writer, urlComponent);
+ return;
}
String result;
if (onlyActionSpecified(urlComponent)) {
- 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.getValue(), urlComponent.getParameters());
- }
- else {
- result = createDefaultUrl(urlComponent);
+ 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.getValue(), urlComponent.getParameters());
+ } else {
+ result = createDefaultUrl(urlComponent);
}
final String anchor = urlComponent.getAnchor();
- if ( anchor != null && anchor.length() > 0 ) {
+ if (anchor != null && anchor.length() > 0) {
result += '#' + anchor;
}
@@ -104,17 +102,17 @@ public class PortletUrlRenderer implemen
throw new StrutsException("IOError: " + e.getMessage(), e);
}
}
- }
+ }
- 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.getNamespace(), urlComponent.getMethod(), urlComponent.getParameters(),
+ 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.getNamespace(), urlComponent.getMethod(), urlComponent.getParameters(),
urlComponent.getPortletUrlType(), urlComponent.getPortletMode(), urlComponent.getWindowState());
- return result;
- }
+ return result;
+ }
private boolean onlyValueSpecified(UrlProvider urlComponent) {
return urlComponent.getValue() != null && urlComponent.getAction() == null;
@@ -124,59 +122,56 @@ public class PortletUrlRenderer implemen
return urlComponent.getValue() == null && urlComponent.getAction() != null;
}
- /**
- * {@inheritDoc}
- */
- public void renderFormUrl(Form formComponent) {
- if(PortletActionContext.getPortletContext() == null) {
+ /**
+ * {@inheritDoc}
+ */
+ public void renderFormUrl(Form formComponent) {
+ if (PortletActionContext.getPortletContext() == null) {
servletRenderer.renderFormUrl(formComponent);
+ return;
+ }
+ 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();
}
- else {
- 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 (StringUtils.isNotEmpty(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, 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));
+ }
+ 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));
}
}
+ }
- }
-
- public void beforeRenderUrl(UrlProvider urlComponent) {
- if(PortletActionContext.getPortletContext() == null) {
- servletRenderer.beforeRenderUrl(urlComponent);
- }
- }
+ public void beforeRenderUrl(UrlProvider urlComponent) {
+ if (PortletActionContext.getPortletContext() == null) {
+ servletRenderer.beforeRenderUrl(urlComponent);
+ }
+ }
}
Modified: struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/context/PortletActionContext.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/context/PortletActionContext.java?rev=1293127&r1=1293126&r2=1293127&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/context/PortletActionContext.java (original)
+++ struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/context/PortletActionContext.java Fri Feb 24 08:14:55 2012
@@ -20,7 +20,9 @@
*/
package org.apache.struts2.portlet.context;
-import java.util.Map;
+import com.opensymphony.xwork2.ActionContext;
+import org.apache.struts2.StrutsStatics;
+import org.apache.struts2.dispatcher.mapper.ActionMapping;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
@@ -30,13 +32,19 @@ import javax.portlet.PortletRequest;
import javax.portlet.PortletResponse;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
+import java.util.Map;
-import org.apache.struts2.StrutsStatics;
-import org.apache.struts2.dispatcher.mapper.ActionMapping;
-
-import com.opensymphony.xwork2.ActionContext;
-
-import static org.apache.struts2.portlet.PortletConstants.*;
+import static org.apache.struts2.portlet.PortletConstants.ACTION_PHASE;
+import static org.apache.struts2.portlet.PortletConstants.DEFAULT_ACTION_FOR_MODE;
+import static org.apache.struts2.portlet.PortletConstants.EVENT_PHASE;
+import static org.apache.struts2.portlet.PortletConstants.MODE_NAMESPACE_MAP;
+import static org.apache.struts2.portlet.PortletConstants.PHASE;
+import static org.apache.struts2.portlet.PortletConstants.PORTLET_CONFIG;
+import static org.apache.struts2.portlet.PortletConstants.PORTLET_NAMESPACE;
+import static org.apache.struts2.portlet.PortletConstants.RENDER_PHASE;
+import static org.apache.struts2.portlet.PortletConstants.REQUEST;
+import static org.apache.struts2.portlet.PortletConstants.RESPONSE;
+import static org.apache.struts2.portlet.PortletConstants.SERVE_RESOURCE_PHASE;
/**
@@ -118,7 +126,7 @@ public class PortletActionContext {
* @return The portlet namespace as defined in <code>portlet.xml</code> and <code>struts.xml</code>
*/
public static String getPortletNamespace() {
- return (String)getContext().get(PORTLET_NAMESPACE);
+ return (String) getContext().get(PORTLET_NAMESPACE);
}
/**
@@ -143,7 +151,7 @@ public class PortletActionContext {
* Get the phase that the portlet is executing in.
*
* @return {@link PortletActionConstants#RENDER_PHASE} in render phase, and
- * {@link PortletActionConstants#ACTION_PHASE} in the event phase.
+ * {@link PortletActionConstants#ACTION_PHASE} in the event phase.
*/
public static Integer getPhase() {
return (Integer) getContext().get(PHASE);
@@ -192,7 +200,7 @@ public class PortletActionContext {
* @return The default action mapping for the current portlet mode.
*/
public static ActionMapping getDefaultActionForMode() {
- return (ActionMapping)getContext().get(DEFAULT_ACTION_FOR_MODE);
+ return (ActionMapping) getContext().get(DEFAULT_ACTION_FOR_MODE);
}
/**
@@ -201,20 +209,21 @@ public class PortletActionContext {
* @return The map of the namespaces for each mode.
*/
public static Map getModeNamespaceMap() {
- return (Map)getContext().get(MODE_NAMESPACE_MAP);
+ return (Map) getContext().get(MODE_NAMESPACE_MAP);
}
-
+
/**
* Get the portlet context.
+ *
* @return The portlet context.
*/
public static PortletContext getPortletContext() {
- return (PortletContext)getContext().get(StrutsStatics.STRUTS_PORTLET_CONTEXT);
+ return (PortletContext) getContext().get(StrutsStatics.STRUTS_PORTLET_CONTEXT);
}
- public static boolean isEvent() {
- return EVENT_PHASE.equals(getPhase());
- }
+ public static boolean isEvent() {
+ return EVENT_PHASE.equals(getPhase());
+ }
/**
* Whether JSR286 features are supported.
@@ -222,7 +231,11 @@ public class PortletActionContext {
* @return <code>true</code> if {@link javax.portlet.PortletContext#getMajorVersion()} returns a value greater than 1
*/
public static boolean isJSR268Supported() {
- return getPortletContext().getMajorVersion() > 1;
+ PortletContext ctx = getPortletContext();
+ if (ctx == null) {
+ return false; // fallback to old behaviour, check WW-3763
+ }
+ return ctx.getMajorVersion() > 1;
}
}