WW-2881 - Generic ActionMapping.param

- applied patch by Mathias Bogaert

git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@747124 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
René Gielen
2009-02-23 20:15:45 +00:00
parent 50fd30b972
commit 703faa0af8
6 changed files with 14 additions and 20 deletions
@@ -38,7 +38,7 @@ public class ActionMapping {
private String namespace;
private String method;
private String extension;
private Map params;
private Map<String, Object> params;
private Result result;
/**
@@ -63,7 +63,7 @@ public class ActionMapping {
* @param method The method
* @param params The extra parameters
*/
public ActionMapping(String name, String namespace, String method, Map params) {
public ActionMapping(String name, String namespace, String method, Map<String, Object> params) {
this.name = name;
this.namespace = namespace;
this.method = method;
@@ -87,7 +87,7 @@ public class ActionMapping {
/**
* @return The extra parameters
*/
public Map getParams() {
public Map<String, Object> getParams() {
return params;
}
@@ -147,7 +147,7 @@ public class ActionMapping {
/**
* @param params The extra parameters for this mapping
*/
public void setParams(Map params) {
public void setParams(Map<String, Object> params) {
this.params = params;
}
@@ -110,7 +110,6 @@ public class Restful2ActionMapper extends DefaultActionMapper {
* @see org.apache.struts2.dispatcher.mapper.ActionMapper#getMapping(javax.servlet.http.HttpServletRequest)
*/
public ActionMapping getMapping(HttpServletRequest request, ConfigurationManager configManager) {
if (!isSlashesInActionNames()) {
throw new IllegalStateException("This action mapper requires the setting 'slashesInActionNames' to be set to 'true'");
}
@@ -174,7 +173,7 @@ public class Restful2ActionMapper extends DefaultActionMapper {
if (idParameterName != null && id != null) {
if (mapping.getParams() == null) {
mapping.setParams(new HashMap());
mapping.setParams(new HashMap<String, Object>());
}
mapping.getParams().put(idParameterName, id);
}
@@ -206,7 +205,7 @@ public class Restful2ActionMapper extends DefaultActionMapper {
}
if (parameters.size() > 0) {
if (mapping.getParams() == null) {
mapping.setParams(new HashMap());
mapping.setParams(new HashMap<String, Object>());
}
mapping.getParams().putAll(parameters);
}
@@ -252,7 +251,4 @@ public class Restful2ActionMapper extends DefaultActionMapper {
public void setIdParameterName(String idParameterName) {
this.idParameterName = idParameterName;
}
}
@@ -78,7 +78,7 @@ public class RestfulActionMapper implements ActionMapper {
}
String actionName = uri.substring(1, nextSlash);
HashMap<String,String> parameters = new HashMap<String,String>();
Map<String, Object> parameters = new HashMap<String, Object>();
try {
StringTokenizer st = new StringTokenizer(uri.substring(nextSlash), "/");
boolean isNameTok = true;
@@ -121,9 +121,8 @@ public class RestfulActionMapper implements ActionMapper {
*/
public String getUriFromActionMapping(ActionMapping mapping) {
String base = mapping.getNamespace() + mapping.getName();
for (Iterator iterator = mapping.getParams().entrySet().iterator(); iterator.hasNext();) {
Map.Entry entry = (Map.Entry) iterator.next();
String name = (String) entry.getKey();
for (Map.Entry<String, Object> entry : mapping.getParams().entrySet()) {
String name = entry.getKey();
if (name.equals(mapping.getName() + "Id")) {
base = base + "/" + entry.getValue();
break;
@@ -79,12 +79,12 @@ public class ActionMappingParametersInteceptor extends ParametersInterceptor {
* an empty map.
*/
@Override
protected Map retrieveParameters(ActionContext ac) {
protected Map<String, Object> retrieveParameters(ActionContext ac) {
ActionMapping mapping = (ActionMapping) ac.get(ServletActionContext.ACTION_MAPPING);
if (mapping != null) {
return mapping.getParams();
} else {
return Collections.EMPTY_MAP;
return Collections.emptyMap();
}
}
@@ -22,7 +22,6 @@
package org.apache.struts2.dispatcher.mapper;
import org.apache.struts2.StrutsTestCase;
import org.apache.struts2.StrutsConstants;
import com.mockobjects.servlet.MockHttpServletRequest;
import com.opensymphony.xwork2.config.ConfigurationManager;
import com.opensymphony.xwork2.config.Configuration;
@@ -41,13 +41,13 @@ public class RestfulActionMapperTest extends TestCase {
ActionMapping am = new ActionMapping();
am.setName("view");
am.setNamespace("secure");
am.setParams(Collections.EMPTY_MAP);
am.setParams(Collections.<String, Object>emptyMap());
assertEquals("secureview", mapper.getUriFromActionMapping(am));
}
public void testGetUriParam() {
Map param = new HashMap();
Map<String, Object> param = new HashMap<String, Object>();
param.put("article", "123");
ActionMapping am = new ActionMapping();
am.setName("view");
@@ -58,7 +58,7 @@ public class RestfulActionMapperTest extends TestCase {
}
public void testGetUriParamId() {
Map param = new HashMap();
Map<String, Object> param = new HashMap<String, Object>();
param.put("article", "123");
param.put("viewId", "456");
ActionMapping am = new ActionMapping();