Author: mrdon Date: Wed Nov 7 01:34:04 2007 New Revision: 592669 URL: http://svn.apache.org/viewvc?rev=592669&view=rev Log: Separating out action mapping parameter handling into new interceptor WW-2203
Added: struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/ActionMappingParametersInteceptor.java Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java struts/struts2/trunk/core/src/main/resources/struts-default.xml Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java?rev=592669&r1=592668&r2=592669&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java (original) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/dispatcher/Dispatcher.java Wed Nov 7 01:34:04 2007 @@ -22,8 +22,6 @@ 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 @@ * all requests. * * @see org.apache.struts2.dispatcher.FilterDispatcher - * @see org.apache.struts2.portlet.dispatcher.Jsr168Dispatcher */ public class Dispatcher { @@ -110,22 +107,22 @@ /** * 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 @@ * @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 void setMultipartSaveDir(String val) { multipartSaveDir = val; } - + @Inject public void setValueStackFactory(ValueStackFactory valueStackFactory) { this.valueStackFactory = valueStackFactory; @@ -508,17 +505,8 @@ // 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); Added: struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/ActionMappingParametersInteceptor.java URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/ActionMappingParametersInteceptor.java?rev=592669&view=auto ============================================================================== --- struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/ActionMappingParametersInteceptor.java (added) +++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/interceptor/ActionMappingParametersInteceptor.java Wed Nov 7 01:34:04 2007 @@ -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 [EMAIL PROTECTED] ParametersInterceptor}, only the parameters come from the [EMAIL PROTECTED] ActionMapping}, not the + * [EMAIL PROTECTED] 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 [EMAIL PROTECTED] 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 [EMAIL PROTECTED] #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; + } + } +} Modified: struts/struts2/trunk/core/src/main/resources/struts-default.xml URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/resources/struts-default.xml?rev=592669&r1=592668&r2=592669&view=diff ============================================================================== --- struts/struts2/trunk/core/src/main/resources/struts-default.xml (original) +++ struts/struts2/trunk/core/src/main/resources/struts-default.xml Wed Nov 7 01:34:04 2007 @@ -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>