mirror of
https://github.com/apache/struts.git
synced 2026-08-11 09:36:57 +00:00
Separating out action mapping parameter handling into new interceptor
WW-2203 git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@592669 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -22,8 +22,6 @@ package org.apache.struts2.dispatcher;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -82,7 +80,6 @@ import freemarker.template.Template;
|
||||
* all requests.
|
||||
*
|
||||
* @see org.apache.struts2.dispatcher.FilterDispatcher
|
||||
* @see org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher
|
||||
*/
|
||||
public class Dispatcher {
|
||||
|
||||
@@ -110,22 +107,22 @@ public class Dispatcher {
|
||||
/**
|
||||
* Store state of StrutsConstants.STRUTS_DEVMODE setting.
|
||||
*/
|
||||
private static boolean devMode;
|
||||
private boolean devMode;
|
||||
|
||||
/**
|
||||
* Store state of StrutsConstants.STRUTS_I18N_ENCODING setting.
|
||||
*/
|
||||
private static String defaultEncoding;
|
||||
private String defaultEncoding;
|
||||
|
||||
/**
|
||||
* Store state of StrutsConstants.STRUTS_LOCALE setting.
|
||||
*/
|
||||
private static String defaultLocale;
|
||||
private String defaultLocale;
|
||||
|
||||
/**
|
||||
* Store state of StrutsConstants.STRUTS_MULTIPART_SAVEDIR setting.
|
||||
*/
|
||||
private static String multipartSaveDir;
|
||||
private String multipartSaveDir;
|
||||
|
||||
/**
|
||||
* Provide list of default configuration files.
|
||||
@@ -189,7 +186,7 @@ public class Dispatcher {
|
||||
* @param servletContext Our servlet context
|
||||
* @param initParams The set of initialization parameters
|
||||
*/
|
||||
public Dispatcher(ServletContext servletContext, Map<String, String> initParams) {
|
||||
public Dispatcher(ServletContext servletContext, Map<String, String> initParams) {
|
||||
this.servletContext = servletContext;
|
||||
this.initParams = initParams;
|
||||
}
|
||||
@@ -229,7 +226,7 @@ public class Dispatcher {
|
||||
public void setMultipartSaveDir(String val) {
|
||||
multipartSaveDir = val;
|
||||
}
|
||||
|
||||
|
||||
@Inject
|
||||
public void setValueStackFactory(ValueStackFactory valueStackFactory) {
|
||||
this.valueStackFactory = valueStackFactory;
|
||||
@@ -508,17 +505,8 @@ Caused by: com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyExcepti
|
||||
// request map wrapping the http request objects
|
||||
Map requestMap = new RequestMap(request);
|
||||
|
||||
// parameters map wrapping the http paraneters.
|
||||
Map params = null;
|
||||
if (mapping != null) {
|
||||
params = mapping.getParams();
|
||||
}
|
||||
Map requestParams = new HashMap(request.getParameterMap());
|
||||
if (params != null) {
|
||||
params.putAll(requestParams);
|
||||
} else {
|
||||
params = requestParams;
|
||||
}
|
||||
// parameters map wrapping the http parameters. ActionMapping parameters are now handled and applied separately
|
||||
Map params = new HashMap(request.getParameterMap());
|
||||
|
||||
// session map wrapping the http session
|
||||
Map session = new SessionMap(request);
|
||||
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* $Id: ApplicationAware.java 471756 2006-11-06 15:01:43Z husted $
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.apache.struts2.interceptor;
|
||||
|
||||
import com.opensymphony.xwork2.interceptor.ParametersInterceptor;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.struts2.dispatcher.mapper.ActionMapping;
|
||||
|
||||
/**
|
||||
* <!-- START SNIPPET: description -->
|
||||
* This interceptor sets all parameters from the action mapping, for this request, on the value stack. It operates
|
||||
* exactly like {@link ParametersInterceptor}, only the parameters come from the {@link ActionMapping}, not the
|
||||
* {@link ActionContext#getParameters()} method.
|
||||
* <!-- END SNIPPET: description -->
|
||||
*
|
||||
* <p/> <u>Interceptor parameters:</u>
|
||||
*
|
||||
* <!-- START SNIPPET: parameters -->
|
||||
*
|
||||
* <ul>
|
||||
*
|
||||
* <li>ordered - set to true if you want the top-down property setter behaviour</li>
|
||||
*
|
||||
* </ul>
|
||||
*
|
||||
* <!-- END SNIPPET: parameters -->
|
||||
*
|
||||
* <p/> <u>Extending the interceptor:</u>
|
||||
*
|
||||
* <!-- START SNIPPET: extending -->
|
||||
*
|
||||
* <p/> The best way to add behavior to this interceptor is to utilize the {@link com.opensymphony.xwork2.interceptor.ParameterNameAware} interface in your
|
||||
* actions. However, if you wish to apply a global rule that isn't implemented in your action, then you could extend
|
||||
* this interceptor and override the {@link #acceptableName(String)} method.
|
||||
*
|
||||
* <!-- END SNIPPET: extending -->
|
||||
*
|
||||
* <p/> <u>Example code:</u>
|
||||
*
|
||||
* <pre>
|
||||
* <!-- START SNIPPET: example -->
|
||||
* <action name="someAction" class="com.examples.SomeAction">
|
||||
* <interceptor-ref name="mapping-params"/>
|
||||
* <result name="success">good_result.ftl</result>
|
||||
* </action>
|
||||
* <!-- END SNIPPET: example -->
|
||||
* </pre>
|
||||
*/
|
||||
public class ActionMappingParametersInteceptor extends ParametersInterceptor {
|
||||
|
||||
/**
|
||||
* @param ac The action context
|
||||
* @return the parameters from the action mapping in the context. If none found, returns
|
||||
* an empty map.
|
||||
*/
|
||||
protected Map retrieveParametersFromContext(ActionContext ac) {
|
||||
ActionMapping mapping = (ActionMapping) ac.get(ServletActionContext.ACTION_MAPPING);
|
||||
if (mapping != null) {
|
||||
return mapping.getParams();
|
||||
} else {
|
||||
return Collections.EMPTY_MAP;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -129,6 +129,7 @@
|
||||
<interceptor name="modelDriven" class="com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor"/>
|
||||
<interceptor name="scopedModelDriven" class="com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor"/>
|
||||
<interceptor name="params" class="com.opensymphony.xwork2.interceptor.ParametersInterceptor"/>
|
||||
<interceptor name="actionMappingParams" class="org.apache.struts2.interceptor.ActionMappingParametersInteceptor"/>
|
||||
<interceptor name="prepare" class="com.opensymphony.xwork2.interceptor.PrepareInterceptor"/>
|
||||
<interceptor name="staticParams" class="com.opensymphony.xwork2.interceptor.StaticParametersInterceptor"/>
|
||||
<interceptor name="scope" class="org.apache.struts2.interceptor.ScopeInterceptor"/>
|
||||
@@ -152,6 +153,7 @@
|
||||
<interceptor-ref name="servletConfig"/>
|
||||
<interceptor-ref name="prepare"/>
|
||||
<interceptor-ref name="checkbox"/>
|
||||
<interceptor-ref name="actionMappingParams"/>
|
||||
<interceptor-ref name="params"/>
|
||||
<interceptor-ref name="conversionError"/>
|
||||
</interceptor-stack>
|
||||
@@ -221,6 +223,7 @@
|
||||
<interceptor-ref name="fileUpload"/>
|
||||
<interceptor-ref name="checkbox"/>
|
||||
<interceptor-ref name="staticParams"/>
|
||||
<interceptor-ref name="actionMappingParams"/>
|
||||
<interceptor-ref name="params"/>
|
||||
<interceptor-ref name="conversionError"/>
|
||||
<interceptor-ref name="validation">
|
||||
@@ -256,6 +259,7 @@
|
||||
<interceptor-ref name="fileUpload"/>
|
||||
<interceptor-ref name="checkbox"/>
|
||||
<interceptor-ref name="staticParams"/>
|
||||
<interceptor-ref name="actionMappingParams"/>
|
||||
<interceptor-ref name="params">
|
||||
<param name="excludeParams">dojo\..*</param>
|
||||
</interceptor-ref>
|
||||
|
||||
Reference in New Issue
Block a user