mirror of
https://github.com/apache/struts.git
synced 2026-08-06 15:17:00 +00:00
WW-5259 Extracts UrlHelper#parseQueryString into a dedicated bean
This commit is contained in:
@@ -20,8 +20,7 @@ package org.apache.struts2;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import org.apache.struts2.dispatcher.Parameter;
|
||||
import org.apache.struts2.views.util.DefaultUrlHelper;
|
||||
import org.apache.struts2.views.util.UrlHelper;
|
||||
import org.apache.struts2.url.QueryStringParser;
|
||||
|
||||
import javax.servlet.Servlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
@@ -53,11 +52,13 @@ public abstract class JSPRuntime {
|
||||
int i = location.indexOf("?");
|
||||
if (i > 0) {
|
||||
//extract params from the url and add them to the request
|
||||
final UrlHelper urlHelperGetInstance = ServletActionContext.getContext().getInstance(UrlHelper.class);
|
||||
final UrlHelper contextUrlHelper = (urlHelperGetInstance != null ? urlHelperGetInstance : (UrlHelper) ActionContext.getContext().get(StrutsConstants.STRUTS_URL_HELPER));
|
||||
final UrlHelper urlHelper = (contextUrlHelper != null ? contextUrlHelper : new DefaultUrlHelper());
|
||||
ActionContext actionContext = ServletActionContext.getActionContext();
|
||||
if (actionContext == null) {
|
||||
throw new StrutsException("Running out of action context!");
|
||||
}
|
||||
final QueryStringParser parser = actionContext.getInstance(QueryStringParser.class);
|
||||
String query = location.substring(i + 1);
|
||||
Map<String, Object> queryParams = urlHelper.parseQueryString(query, true);
|
||||
Map<String, Object> queryParams = parser.parse(query, true);
|
||||
if (queryParams != null && !queryParams.isEmpty()) {
|
||||
Map<String, Parameter> newParams = new HashMap<>();
|
||||
for (Map.Entry<String, Object> entry : queryParams.entrySet()) {
|
||||
|
||||
@@ -35,10 +35,9 @@ import junit.framework.TestCase;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.struts2.dispatcher.HttpParameters;
|
||||
import org.apache.struts2.jasper.runtime.InstanceHelper;
|
||||
import org.apache.struts2.url.QueryStringParser;
|
||||
import org.apache.struts2.url.StrutsQueryStringParser;
|
||||
import org.apache.struts2.url.StrutsUrlDecoder;
|
||||
import org.apache.struts2.url.StrutsUrlEncoder;
|
||||
import org.apache.struts2.views.util.DefaultUrlHelper;
|
||||
import org.apache.struts2.views.util.UrlHelper;
|
||||
import org.apache.tomcat.InstanceManager;
|
||||
import org.easymock.EasyMock;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
@@ -58,6 +57,8 @@ import java.util.Map;
|
||||
import java.util.concurrent.BrokenBarrierException;
|
||||
import java.util.concurrent.CyclicBarrier;
|
||||
|
||||
import static org.apache.struts2.ServletActionContext.STRUTS_VALUESTACK_KEY;
|
||||
|
||||
|
||||
public class EmbeddedJSPResultTest extends TestCase {
|
||||
private HttpServletRequest request;
|
||||
@@ -324,18 +325,19 @@ public class EmbeddedJSPResultTest extends TestCase {
|
||||
HttpSession session = EasyMock.createNiceMock(HttpSession.class);
|
||||
EasyMock.replay(session);
|
||||
|
||||
EasyMock.expect(request.getSession()).andReturn(session).anyTimes();
|
||||
EasyMock.expect(request.getParameterMap()).andReturn(params).anyTimes();
|
||||
EasyMock.expect(request.getParameter("username")).andAnswer(() -> ActionContext.getContext().getParameters().get("username").getValue());
|
||||
EasyMock.expect(request.getAttribute("something")).andReturn("somethingelse").anyTimes();
|
||||
|
||||
EasyMock.replay(request);
|
||||
|
||||
//mock value stack
|
||||
ValueStack valueStack = EasyMock.createNiceMock(ValueStack.class);
|
||||
EasyMock.expect(valueStack.getActionContext()).andReturn(ActionContext.getContext()).anyTimes();
|
||||
EasyMock.replay(valueStack);
|
||||
|
||||
EasyMock.expect(request.getSession()).andReturn(session).anyTimes();
|
||||
EasyMock.expect(request.getParameterMap()).andReturn(params).anyTimes();
|
||||
EasyMock.expect(request.getParameter("username")).andAnswer(() -> ActionContext.getContext().getParameters().get("username").getValue());
|
||||
EasyMock.expect(request.getAttribute(STRUTS_VALUESTACK_KEY)).andReturn(valueStack).anyTimes();
|
||||
EasyMock.expect(request.getAttribute("something")).andReturn("somethingelse").anyTimes();
|
||||
|
||||
EasyMock.replay(request);
|
||||
|
||||
//mock converter
|
||||
XWorkConverter converter = new DummyConverter();
|
||||
|
||||
@@ -350,10 +352,8 @@ public class EmbeddedJSPResultTest extends TestCase {
|
||||
EasyMock.expect(container.getInstanceNames(FileManager.class)).andReturn(new HashSet<>()).anyTimes();
|
||||
EasyMock.expect(container.getInstance(FileManager.class)).andReturn(fileManager).anyTimes();
|
||||
|
||||
DefaultUrlHelper urlHelper = new DefaultUrlHelper();
|
||||
urlHelper.setDecoder(new StrutsUrlDecoder());
|
||||
urlHelper.setEncoder(new StrutsUrlEncoder());
|
||||
EasyMock.expect(container.getInstance(UrlHelper.class)).andReturn(urlHelper).anyTimes();
|
||||
QueryStringParser queryStringParser = new StrutsQueryStringParser(new StrutsUrlDecoder());
|
||||
EasyMock.expect(container.getInstance(QueryStringParser.class)).andReturn(queryStringParser).anyTimes();
|
||||
FileManagerFactory fileManagerFactory = new DummyFileManagerFactory();
|
||||
EasyMock.expect(container.getInstance(FileManagerFactory.class)).andReturn(fileManagerFactory).anyTimes();
|
||||
|
||||
|
||||
+7
-12
@@ -26,10 +26,9 @@ import com.opensymphony.xwork2.util.ValueStack;
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
import org.apache.struts2.dispatcher.mapper.DefaultActionMapper;
|
||||
import org.apache.struts2.junit.StrutsTestCase;
|
||||
import org.apache.struts2.url.StrutsParametersStringBuilder;
|
||||
import org.apache.struts2.url.StrutsUrlDecoder;
|
||||
import org.apache.struts2.url.QueryStringBuilder;
|
||||
import org.apache.struts2.url.StrutsQueryStringBuilder;
|
||||
import org.apache.struts2.url.StrutsUrlEncoder;
|
||||
import org.apache.struts2.views.util.DefaultUrlHelper;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
@@ -37,7 +36,7 @@ import org.springframework.mock.web.MockServletContext;
|
||||
public class JSONActionRedirectResultTest extends StrutsTestCase {
|
||||
|
||||
private DefaultActionMapper actionMapper;
|
||||
private DefaultUrlHelper urlHelper;
|
||||
private QueryStringBuilder queryStringBuilder;
|
||||
|
||||
MockActionInvocation invocation;
|
||||
MockHttpServletResponse response;
|
||||
@@ -50,7 +49,7 @@ public class JSONActionRedirectResultTest extends StrutsTestCase {
|
||||
JSONActionRedirectResult result = new JSONActionRedirectResult();
|
||||
result.setActionName("targetAction");
|
||||
result.setActionMapper(actionMapper);
|
||||
result.setUrlHelper(urlHelper);
|
||||
result.setQueryStringBuilder(queryStringBuilder);
|
||||
|
||||
Object action = new Object();
|
||||
stack.push(action);
|
||||
@@ -69,7 +68,7 @@ public class JSONActionRedirectResultTest extends StrutsTestCase {
|
||||
JSONActionRedirectResult result = new JSONActionRedirectResult();
|
||||
result.setActionName("targetAction");
|
||||
result.setActionMapper(actionMapper);
|
||||
result.setUrlHelper(urlHelper);
|
||||
result.setQueryStringBuilder(queryStringBuilder);
|
||||
|
||||
request.setParameter("struts.enableJSONValidation", "true");
|
||||
request.setParameter("struts.validateOnly", "false");
|
||||
@@ -89,7 +88,7 @@ public class JSONActionRedirectResultTest extends StrutsTestCase {
|
||||
JSONActionRedirectResult result = new JSONActionRedirectResult();
|
||||
result.setActionName("targetAction");
|
||||
result.setActionMapper(actionMapper);
|
||||
result.setUrlHelper(urlHelper);
|
||||
result.setQueryStringBuilder(queryStringBuilder);
|
||||
|
||||
request.setParameter("struts.enableJSONValidation", "true");
|
||||
request.setParameter("struts.validateOnly", "true");
|
||||
@@ -126,10 +125,6 @@ public class JSONActionRedirectResultTest extends StrutsTestCase {
|
||||
this.invocation.setProxy(mockActionProxy);
|
||||
|
||||
this.actionMapper = new DefaultActionMapper();
|
||||
this.urlHelper = new DefaultUrlHelper();
|
||||
StrutsUrlEncoder encoder = new StrutsUrlEncoder();
|
||||
this.urlHelper.setParametersStringBuilder(new StrutsParametersStringBuilder(encoder));
|
||||
this.urlHelper.setEncoder(encoder);
|
||||
this.urlHelper.setDecoder(new StrutsUrlDecoder());
|
||||
this.queryStringBuilder = new StrutsQueryStringBuilder(new StrutsUrlEncoder());
|
||||
}
|
||||
}
|
||||
|
||||
+40
-37
@@ -18,7 +18,6 @@
|
||||
*/
|
||||
package org.apache.struts2.components;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -27,6 +26,7 @@ import org.apache.struts2.dispatcher.mapper.ActionMapper;
|
||||
import org.apache.struts2.portlet.context.PortletActionContext;
|
||||
import org.apache.struts2.portlet.util.PortletUrlHelper;
|
||||
import org.apache.struts2.portlet.util.PortletUrlHelperJSR286;
|
||||
import org.apache.struts2.url.QueryStringParser;
|
||||
import org.apache.struts2.views.util.UrlHelper;
|
||||
|
||||
import javax.portlet.PortletMode;
|
||||
@@ -66,6 +66,11 @@ public class PortletUrlRenderer implements UrlRenderer {
|
||||
servletRenderer.setUrlHelper(urlHelper);
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setQueryStringParser(QueryStringParser queryStringParser) {
|
||||
this.servletRenderer.setQueryStringParser(queryStringParser);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
@@ -75,37 +80,35 @@ public class PortletUrlRenderer implements UrlRenderer {
|
||||
return;
|
||||
}
|
||||
String result;
|
||||
if (isPortletModeChange(urlComponent,PortletActionContext.getRequest().getPortletMode())
|
||||
&& StringUtils.isEmpty(urlComponent.getNamespace()))
|
||||
{
|
||||
String mode = urlComponent.getPortletMode();
|
||||
PortletMode portletMode = new PortletMode(mode);
|
||||
String action = urlComponent.getAction();
|
||||
if (StringUtils.isEmpty(action)) {
|
||||
action = PortletActionContext.getModeActionMap().get(portletMode).getName();
|
||||
}
|
||||
String modeNamespace = PortletActionContext.getModeNamespaceMap().get(portletMode);
|
||||
result = portletUrlHelper.buildUrl(action, modeNamespace, urlComponent.getMethod(),
|
||||
urlComponent.getParameters(), urlComponent.getPortletUrlType(), mode, urlComponent.getWindowState());
|
||||
if (isPortletModeChange(urlComponent, PortletActionContext.getRequest().getPortletMode())
|
||||
&& StringUtils.isEmpty(urlComponent.getNamespace())) {
|
||||
String mode = urlComponent.getPortletMode();
|
||||
PortletMode portletMode = new PortletMode(mode);
|
||||
String action = urlComponent.getAction();
|
||||
if (StringUtils.isEmpty(action)) {
|
||||
action = PortletActionContext.getModeActionMap().get(portletMode).getName();
|
||||
}
|
||||
String modeNamespace = PortletActionContext.getModeNamespaceMap().get(portletMode);
|
||||
result = portletUrlHelper.buildUrl(action, modeNamespace, urlComponent.getMethod(),
|
||||
urlComponent.getParameters(), urlComponent.getPortletUrlType(), mode, urlComponent.getWindowState());
|
||||
|
||||
} else {
|
||||
String namespace = urlComponent.determineNamespace(urlComponent.getNamespace(), urlComponent.getStack(), urlComponent.getHttpServletRequest());
|
||||
urlComponent.setNamespace(namespace);
|
||||
if (onlyActionSpecified(urlComponent)) {
|
||||
if (StringUtils.isNotEmpty(urlComponent.getAction())) {
|
||||
String action = urlComponent.findString(urlComponent.getAction());
|
||||
String namespace = urlComponent.determineNamespace(urlComponent.getNamespace(), urlComponent.getStack(), urlComponent.getHttpServletRequest());
|
||||
urlComponent.setNamespace(namespace);
|
||||
if (onlyActionSpecified(urlComponent)) {
|
||||
if (StringUtils.isNotEmpty(urlComponent.getAction())) {
|
||||
String action = urlComponent.findString(urlComponent.getAction());
|
||||
result = portletUrlHelper.buildUrl(action, urlComponent.getNamespace(), urlComponent.getMethod(),
|
||||
urlComponent.getParameters(), urlComponent.getPortletUrlType(), urlComponent.getPortletMode(), urlComponent.getWindowState());
|
||||
}
|
||||
else {
|
||||
urlComponent.getParameters(), urlComponent.getPortletUrlType(), urlComponent.getPortletMode(), urlComponent.getWindowState());
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
urlComponent.getParameters(), urlComponent.getPortletUrlType(), urlComponent.getPortletMode(), urlComponent.getWindowState());
|
||||
}
|
||||
} else if (onlyValueSpecified(urlComponent)) {
|
||||
result = portletUrlHelper.buildResourceUrl(urlComponent.getValue(), urlComponent.getParameters());
|
||||
} else {
|
||||
result = createDefaultUrl(urlComponent);
|
||||
}
|
||||
}
|
||||
String anchor = urlComponent.getAnchor();
|
||||
if (StringUtils.isNotEmpty(anchor)) {
|
||||
@@ -128,19 +131,19 @@ public class PortletUrlRenderer implements UrlRenderer {
|
||||
}
|
||||
}
|
||||
|
||||
boolean isPortletModeChange(UrlProvider urlComponent,PortletMode currentMode) {
|
||||
if (StringUtils.isNotEmpty(urlComponent.getPortletMode())) {
|
||||
PortletMode newPortletMode = new PortletMode(urlComponent.getPortletMode());
|
||||
return !(newPortletMode.equals(currentMode));
|
||||
boolean isPortletModeChange(UrlProvider urlComponent, PortletMode currentMode) {
|
||||
if (StringUtils.isNotEmpty(urlComponent.getPortletMode())) {
|
||||
PortletMode newPortletMode = new PortletMode(urlComponent.getPortletMode());
|
||||
return !(newPortletMode.equals(currentMode));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private String createDefaultUrl(UrlProvider urlComponent) {
|
||||
ActionInvocation ai = urlComponent.getStack().getActionContext().getActionInvocation();
|
||||
String action = ai.getProxy().getActionName();
|
||||
return portletUrlHelper.buildUrl(action, urlComponent.getNamespace(), urlComponent.getMethod(), urlComponent.getParameters(),
|
||||
urlComponent.getPortletUrlType(), urlComponent.getPortletMode(), urlComponent.getWindowState());
|
||||
urlComponent.getPortletUrlType(), urlComponent.getPortletMode(), urlComponent.getWindowState());
|
||||
}
|
||||
|
||||
private boolean onlyValueSpecified(UrlProvider urlComponent) {
|
||||
@@ -160,7 +163,7 @@ public class PortletUrlRenderer implements UrlRenderer {
|
||||
return;
|
||||
}
|
||||
String namespace = formComponent.determineNamespace(formComponent.namespace, formComponent.getStack(),
|
||||
formComponent.request);
|
||||
formComponent.request);
|
||||
String action;
|
||||
if (formComponent.action != null) {
|
||||
action = formComponent.findString(formComponent.action);
|
||||
@@ -177,7 +180,7 @@ public class PortletUrlRenderer implements UrlRenderer {
|
||||
}
|
||||
if (action != null) {
|
||||
String result = portletUrlHelper.buildUrl(action, namespace, null,
|
||||
formComponent.getParameters(), type, formComponent.portletMode, formComponent.windowState);
|
||||
formComponent.getParameters(), type, formComponent.portletMode, formComponent.windowState);
|
||||
formComponent.addParameter("action", result);
|
||||
|
||||
|
||||
|
||||
+124
-123
@@ -21,11 +21,11 @@ package org.apache.struts2.portlet.result;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.config.entities.ResultConfig;
|
||||
import com.opensymphony.xwork2.inject.Inject;
|
||||
import org.apache.struts2.result.ServletActionRedirectResult;
|
||||
import org.apache.struts2.dispatcher.mapper.ActionMapper;
|
||||
import org.apache.struts2.dispatcher.mapper.ActionMapping;
|
||||
import org.apache.struts2.portlet.PortletConstants;
|
||||
import org.apache.struts2.views.util.UrlHelper;
|
||||
import org.apache.struts2.result.ServletActionRedirectResult;
|
||||
import org.apache.struts2.url.QueryStringBuilder;
|
||||
|
||||
import javax.portlet.PortletMode;
|
||||
import java.util.Arrays;
|
||||
@@ -34,11 +34,10 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
* Portlet modification of the {@link ServletActionRedirectResult}.
|
||||
*
|
||||
* <p>
|
||||
* <!-- START SNIPPET: description -->
|
||||
*
|
||||
* <p>
|
||||
* This result uses the {@link ActionMapper} provided by the
|
||||
* <code>ActionMapperFactory</code> to instruct the render phase to invoke the
|
||||
* specified action and (optional) namespace. This is better than the
|
||||
@@ -48,31 +47,31 @@ import java.util.Map;
|
||||
* and your application will still work. It is strongly recommended that if you
|
||||
* are redirecting to another action, you use this result rather than the
|
||||
* standard redirect result.
|
||||
*
|
||||
* <p>
|
||||
* See examples below for an example of how request parameters could be passed
|
||||
* in.
|
||||
*
|
||||
* <p>
|
||||
* <!-- END SNIPPET: description -->
|
||||
*
|
||||
* <p>
|
||||
* <b>This result type takes the following parameters:</b>
|
||||
*
|
||||
* <p>
|
||||
* <!-- START SNIPPET: params -->
|
||||
*
|
||||
*
|
||||
* <ul>
|
||||
*
|
||||
*
|
||||
* <li><b>actionName (default)</b> - the name of the action that will be
|
||||
* redirect to</li>
|
||||
*
|
||||
*
|
||||
* <li><b>namespace</b> - used to determine which namespace the action is in
|
||||
* that we're redirecting to . If namespace is null, this defaults to the
|
||||
* current namespace</li>
|
||||
*
|
||||
*
|
||||
* </ul>
|
||||
*
|
||||
* <p>
|
||||
* <!-- END SNIPPET: params -->
|
||||
*
|
||||
* <p>
|
||||
* <b>Example:</b>
|
||||
*
|
||||
*
|
||||
* <pre>
|
||||
* <!-- START SNIPPET: example -->
|
||||
* <package name="public" extends="struts-default">
|
||||
@@ -84,19 +83,19 @@ import java.util.Map;
|
||||
* </result>
|
||||
* </action>
|
||||
* </package>
|
||||
*
|
||||
*
|
||||
* <package name="secure" extends="struts-default" namespace="/secure">
|
||||
* <-- Redirect to an action in the same namespace -->
|
||||
* <action name="dashboard" class="...">
|
||||
* <result>dashboard.jsp</result>
|
||||
* <result name="error" type="redirect-action">error</result>
|
||||
* </action>
|
||||
*
|
||||
*
|
||||
* <action name="error" class="...">
|
||||
* <result>error.jsp</result>
|
||||
* </action>
|
||||
* </package>
|
||||
*
|
||||
*
|
||||
* <package name="passingRequestParameters" extends="struts-default" namespace="/passingRequestParameters">
|
||||
* <-- Pass parameters (reportType, width and height) -->
|
||||
* <!--
|
||||
@@ -113,106 +112,109 @@ import java.util.Map;
|
||||
* </result>
|
||||
* </action>
|
||||
* </package>
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* <!-- END SNIPPET: example -->
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
* @see ActionMapper
|
||||
*/
|
||||
public class PortletActionRedirectResult extends PortletResult {
|
||||
|
||||
private static final long serialVersionUID = -7627388936683562557L;
|
||||
private static final long serialVersionUID = -7627388936683562557L;
|
||||
|
||||
/** The default parameter */
|
||||
public static final String DEFAULT_PARAM = "actionName";
|
||||
/**
|
||||
* The default parameter
|
||||
*/
|
||||
public static final String DEFAULT_PARAM = "actionName";
|
||||
|
||||
protected String actionName;
|
||||
protected String namespace;
|
||||
protected String method;
|
||||
protected String actionName;
|
||||
protected String namespace;
|
||||
protected String method;
|
||||
|
||||
private Map<String, Object> requestParameters = new LinkedHashMap<String, Object>();
|
||||
private ActionMapper actionMapper;
|
||||
private UrlHelper urlHelper;
|
||||
private final Map<String, Object> requestParameters = new LinkedHashMap<>();
|
||||
|
||||
public PortletActionRedirectResult() {
|
||||
super();
|
||||
}
|
||||
private ActionMapper actionMapper;
|
||||
private QueryStringBuilder queryStringBuilder;
|
||||
|
||||
public PortletActionRedirectResult(String actionName) {
|
||||
this(null, actionName, null);
|
||||
}
|
||||
public PortletActionRedirectResult() {
|
||||
super();
|
||||
}
|
||||
|
||||
public PortletActionRedirectResult(String actionName, String method) {
|
||||
this(null, actionName, method);
|
||||
}
|
||||
public PortletActionRedirectResult(String actionName) {
|
||||
this(null, actionName, null);
|
||||
}
|
||||
|
||||
public PortletActionRedirectResult(String namespace, String actionName, String method) {
|
||||
super(null);
|
||||
this.namespace = namespace;
|
||||
this.actionName = actionName;
|
||||
this.method = method;
|
||||
}
|
||||
public PortletActionRedirectResult(String actionName, String method) {
|
||||
this(null, actionName, method);
|
||||
}
|
||||
|
||||
protected List<String> prohibitedResultParam = Arrays.asList(DEFAULT_PARAM, "namespace", "method", "encode", "parse",
|
||||
"location", "prependServletContext");
|
||||
public PortletActionRedirectResult(String namespace, String actionName, String method) {
|
||||
super(null);
|
||||
this.namespace = namespace;
|
||||
this.actionName = actionName;
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setActionMapper(ActionMapper actionMapper) {
|
||||
this.actionMapper = actionMapper;
|
||||
}
|
||||
protected List<String> prohibitedResultParam = Arrays.asList(DEFAULT_PARAM, "namespace", "method", "encode", "parse",
|
||||
"location", "prependServletContext");
|
||||
|
||||
@Inject
|
||||
public void setUrlHelper(UrlHelper urlHelper) {
|
||||
this.urlHelper = urlHelper;
|
||||
public void setActionMapper(ActionMapper actionMapper) {
|
||||
this.actionMapper = actionMapper;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setQueryStringBuilder(QueryStringBuilder queryStringBuilder) {
|
||||
this.queryStringBuilder = queryStringBuilder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see com.opensymphony.xwork2.Result#execute(com.opensymphony.xwork2.ActionInvocation)
|
||||
*/
|
||||
public void execute(ActionInvocation invocation) throws Exception {
|
||||
if (invocation == null) {
|
||||
throw new IllegalArgumentException("Invocation cannot be null!");
|
||||
}
|
||||
* @see com.opensymphony.xwork2.Result#execute(com.opensymphony.xwork2.ActionInvocation)
|
||||
*/
|
||||
public void execute(ActionInvocation invocation) throws Exception {
|
||||
if (invocation == null) {
|
||||
throw new IllegalArgumentException("Invocation cannot be null!");
|
||||
}
|
||||
|
||||
actionName = conditionalParse(actionName, invocation);
|
||||
parseLocation = false;
|
||||
actionName = conditionalParse(actionName, invocation);
|
||||
parseLocation = false;
|
||||
|
||||
String portletNamespace = (String)invocation.getInvocationContext().get(PortletConstants.PORTLET_NAMESPACE);
|
||||
if (portletMode != null) {
|
||||
Map<PortletMode, String> namespaceMap = getNamespaceMap(invocation);
|
||||
namespace = namespaceMap.get(portletMode);
|
||||
}
|
||||
if (namespace == null) {
|
||||
namespace = invocation.getProxy().getNamespace();
|
||||
} else {
|
||||
namespace = conditionalParse(namespace, invocation);
|
||||
}
|
||||
if (method == null) {
|
||||
method = "";
|
||||
} else {
|
||||
method = conditionalParse(method, invocation);
|
||||
}
|
||||
String portletNamespace = (String) invocation.getInvocationContext().get(PortletConstants.PORTLET_NAMESPACE);
|
||||
if (portletMode != null) {
|
||||
Map<PortletMode, String> namespaceMap = getNamespaceMap(invocation);
|
||||
namespace = namespaceMap.get(portletMode);
|
||||
}
|
||||
if (namespace == null) {
|
||||
namespace = invocation.getProxy().getNamespace();
|
||||
} else {
|
||||
namespace = conditionalParse(namespace, invocation);
|
||||
}
|
||||
if (method == null) {
|
||||
method = "";
|
||||
} else {
|
||||
method = conditionalParse(method, invocation);
|
||||
}
|
||||
|
||||
String resultCode = invocation.getResultCode();
|
||||
if (resultCode != null) {
|
||||
ResultConfig resultConfig = invocation.getProxy().getConfig().getResults().get(resultCode);
|
||||
Map<String, String> resultConfigParams = resultConfig.getParams();
|
||||
String resultCode = invocation.getResultCode();
|
||||
if (resultCode != null) {
|
||||
ResultConfig resultConfig = invocation.getProxy().getConfig().getResults().get(resultCode);
|
||||
Map<String, String> resultConfigParams = resultConfig.getParams();
|
||||
for (Map.Entry<String, String> e : resultConfigParams.entrySet()) {
|
||||
if (!prohibitedResultParam.contains(e.getKey())) {
|
||||
requestParameters.put(e.getKey(), e.getValue() == null ? "" : conditionalParse(e.getValue(), invocation));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
StringBuilder tmpLocation = new StringBuilder(actionMapper.getUriFromActionMapping(new ActionMapping(actionName,
|
||||
(portletNamespace == null ? namespace : portletNamespace + namespace), method, null)));
|
||||
urlHelper.buildParametersString(requestParameters, tmpLocation, "&");
|
||||
ActionMapping actionMapping = new ActionMapping(actionName, (portletNamespace == null ? namespace : portletNamespace + namespace), method, null);
|
||||
StringBuilder tmpLocation = new StringBuilder(actionMapper.getUriFromActionMapping(actionMapping));
|
||||
queryStringBuilder.build(requestParameters, tmpLocation, "&");
|
||||
|
||||
setLocation(tmpLocation.toString());
|
||||
setLocation(tmpLocation.toString());
|
||||
|
||||
super.execute(invocation);
|
||||
}
|
||||
super.execute(invocation);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<PortletMode, String> getNamespaceMap(ActionInvocation invocation) {
|
||||
@@ -220,43 +222,42 @@ public class PortletActionRedirectResult extends PortletResult {
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the action name
|
||||
*
|
||||
* @param actionName The name
|
||||
*/
|
||||
public void setActionName(String actionName) {
|
||||
this.actionName = actionName;
|
||||
}
|
||||
* Sets the action name
|
||||
*
|
||||
* @param actionName The name
|
||||
*/
|
||||
public void setActionName(String actionName) {
|
||||
this.actionName = actionName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the namespace
|
||||
*
|
||||
* @param namespace The namespace
|
||||
*/
|
||||
public void setNamespace(String namespace) {
|
||||
this.namespace = namespace;
|
||||
}
|
||||
/**
|
||||
* Sets the namespace
|
||||
*
|
||||
* @param namespace The namespace
|
||||
*/
|
||||
public void setNamespace(String namespace) {
|
||||
this.namespace = namespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the method
|
||||
*
|
||||
* @param method The method
|
||||
*/
|
||||
public void setMethod(String method) {
|
||||
this.method = method;
|
||||
}
|
||||
/**
|
||||
* Sets the method
|
||||
*
|
||||
* @param method The method
|
||||
*/
|
||||
public void setMethod(String method) {
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a request parameter to be added to the redirect url
|
||||
*
|
||||
* @param key The parameter name
|
||||
* @param value The parameter value
|
||||
*
|
||||
* @return the portlet action redirect result
|
||||
*/
|
||||
public PortletActionRedirectResult addParameter(String key, Object value) {
|
||||
requestParameters.put(key, String.valueOf(value));
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* Adds a request parameter to be added to the redirect url
|
||||
*
|
||||
* @param key The parameter name
|
||||
* @param value The parameter value
|
||||
* @return the portlet action redirect result
|
||||
*/
|
||||
public PortletActionRedirectResult addParameter(String key, Object value) {
|
||||
requestParameters.put(key, String.valueOf(value));
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user