WW-1713 Backport to 2.0.x

git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/branches/STRUTS_2_0_X@569304 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nils-Helge Garli
2007-08-24 09:12:20 +00:00
parent accd8b1761
commit da14faef1e
4 changed files with 20 additions and 16 deletions
@@ -382,7 +382,7 @@ public class Form extends ClosingUIBean {
}
}
if (action != null) {
String result = PortletUrlHelper.buildUrl(action, namespace,
String result = PortletUrlHelper.buildUrl(action, namespace, null,
getParameters(), type, portletMode, windowState);
addParameter("action", result);
@@ -250,7 +250,7 @@ public class URL extends Component {
String result;
if (value == null && action != null) {
if (Dispatcher.getInstance().isPortletSupportActive() && PortletActionContext.isPortletRequest()) {
result = PortletUrlHelper.buildUrl(action, namespace, parameters, portletUrlType, portletMode, windowState);
result = PortletUrlHelper.buildUrl(action, namespace, method, parameters, portletUrlType, portletMode, windowState);
}
else {
result = determineActionURL(action, namespace, method, req, res, parameters, scheme, includeContext, encode, forceAddSchemeHostAndPort, escapeAmp);
@@ -22,8 +22,8 @@ package org.apache.struts2.portlet.util;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.StringTokenizer;
@@ -59,15 +59,16 @@ public class PortletUrlHelper {
*
* @param action The action the URL should invoke.
* @param namespace The namespace of the action to invoke.
* @param method The method of the action to invoke.
* @param params The parameters of the URL.
* @param type The type of the url, either <tt>action</tt> or <tt>render</tt>
* @param mode The PortletMode of the URL.
* @param state The WindowState of the URL.
* @return The URL String.
*/
public static String buildUrl(String action, String namespace, Map params,
public static String buildUrl(String action, String namespace, String method, Map params,
String type, String mode, String state) {
return buildUrl(action, namespace, params, null, type, mode, state,
return buildUrl(action, namespace, method, params, null, type, mode, state,
true, true);
}
@@ -76,9 +77,10 @@ public class PortletUrlHelper {
*
* @see #buildUrl(String, String, Map, String, String, String)
*/
public static String buildUrl(String action, String namespace, Map params,
public static String buildUrl(String action, String namespace, String method, Map params,
String scheme, String type, String portletMode, String windowState,
boolean includeContext, boolean encodeResult) {
StringBuffer resultingAction = new StringBuffer();
RenderRequest request = PortletActionContext.getRenderRequest();
RenderResponse response = PortletActionContext.getRenderResponse();
LOG.debug("Creating url. Action = " + action + ", Namespace = "
@@ -102,15 +104,17 @@ public class PortletUrlHelper {
}
}
if (TextUtils.stringSet(namespace)) {
StringBuffer sb = new StringBuffer();
sb.append(namespace);
resultingAction.append(namespace);
if(!action.startsWith("/") && !namespace.endsWith("/")) {
sb.append("/");
resultingAction.append("/");
}
action = sb.append(action).toString();
resultingAction.append(action);
LOG.debug("Resulting actionPath: " + action);
}
params.put(PortletActionConstants.ACTION_PARAM, new String[] { action });
if(TextUtils.stringSet(method)) {
resultingAction.append("!").append(method);
}
params.put(PortletActionConstants.ACTION_PARAM, new String[] { resultingAction.toString() });
PortletURL url = null;
if ("action".equalsIgnoreCase(type)) {
@@ -230,7 +234,7 @@ public class PortletUrlHelper {
public static Map ensureParamsAreStringArrays(Map params) {
Map result = null;
if (params != null) {
result = new HashMap(params.size());
result = new LinkedHashMap(params.size());
Iterator it = params.keySet().iterator();
while (it.hasNext()) {
Object key = it.next();
@@ -95,7 +95,7 @@ public class PortletUrlHelperTest extends TestCase {
renderRequestControl.replay();
renderResponseControl.replay();
portletUrlControl.replay();
PortletUrlHelper.buildUrl("testAction", null,
PortletUrlHelper.buildUrl("testAction", null, null,
new HashMap(), null, null, null);
portletUrlControl.verify();
renderRequestControl.verify();
@@ -113,7 +113,7 @@ public class PortletUrlHelperTest extends TestCase {
renderRequestControl.replay();
renderResponseControl.replay();
portletUrlControl.replay();
PortletUrlHelper.buildUrl("testAction", null,
PortletUrlHelper.buildUrl("testAction", null, null,
new HashMap(), null, "edit", null);
portletUrlControl.verify();
renderRequestControl.verify();
@@ -131,7 +131,7 @@ public class PortletUrlHelperTest extends TestCase {
renderRequestControl.replay();
renderResponseControl.replay();
portletUrlControl.replay();
PortletUrlHelper.buildUrl("testAction", null,
PortletUrlHelper.buildUrl("testAction", null, null,
new HashMap(), null, null, "maximized");
portletUrlControl.verify();
renderRequestControl.verify();
@@ -149,7 +149,7 @@ public class PortletUrlHelperTest extends TestCase {
renderRequestControl.replay();
renderResponseControl.replay();
portletUrlControl.replay();
PortletUrlHelper.buildUrl("testAction", null,
PortletUrlHelper.buildUrl("testAction", null, null,
new HashMap(), "action", null, null);
portletUrlControl.verify();
renderRequestControl.verify();