Commits

Anonymous committed 9af5a86

Load & Apply <param> under <result-type> in xwork configuration.
Issue number: XW-319
Submitted by: Neo
Reviewed by: Rainer Hermanns

git-svn-id: http://svn.opensymphony.com/svn/xwork/trunk@747e221344d-f017-0410-9bd5-d282ab1896d7

  • Participants
  • Parent commits b326941

Comments (0)

Files changed (2)

File src/java/com/opensymphony/xwork/config/entities/ResultTypeConfig.java

  */
 package com.opensymphony.xwork.config.entities;
 
+import java.util.Map;
+import java.util.TreeMap;
+
 
 /**
- * Created by IntelliJ IDEA.
- * User: Mike
- * Date: May 6, 2003
- * Time: 1:24:41 PM
- * To change this template use Options | File Templates.
+ * Configuration class for result types.
+ *
+ * @author Mike
+ * @author Rainer Hermanns
+ * @author Neo
  */
 public class ResultTypeConfig {
 
     private Class clazz;
     private String name;
 
+    private Map params;
 
     public ResultTypeConfig() {
     }
         return name;
     }
 
-    public boolean equals(Object o) {
-        if (this == o) {
-            return true;
+    public void addParam(String key, String value) {
+        if (params == null) {
+            params = new TreeMap();
         }
+        params.put(key, value);
+    }
 
-        if (!(o instanceof ResultTypeConfig)) {
-            return false;
-        }
+    public Map getParams() {
+        return this.params;
+    }
 
-        final ResultTypeConfig resultTypeConfig = (ResultTypeConfig) o;
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
 
-        if ((clazz != null) ? (!clazz.equals(resultTypeConfig.clazz)) : (resultTypeConfig.clazz != null)) {
-            return false;
-        }
+        final ResultTypeConfig that = (ResultTypeConfig) o;
 
-        if ((name != null) ? (!name.equals(resultTypeConfig.name)) : (resultTypeConfig.name != null)) {
-            return false;
-        }
+        if (clazz != null ? !clazz.equals(that.clazz) : that.clazz != null) return false;
+        if (name != null ? !name.equals(that.name) : that.name != null) return false;
+        if (params != null ? !params.equals(that.params) : that.params != null) return false;
 
         return true;
     }
 
     public int hashCode() {
         int result;
-        result = ((name != null) ? name.hashCode() : 0);
-        result = (29 * result) + ((clazz != null) ? clazz.hashCode() : 0);
-
+        result = (clazz != null ? clazz.hashCode() : 0);
+        result = 29 * result + (name != null ? name.hashCode() : 0);
+        result = 29 * result + (params != null ? params.hashCode() : 0);
         return result;
     }
 }

File src/java/com/opensymphony/xwork/config/providers/XmlConfigurationProvider.java

 /**
  * Looks in the classpath for "xwork.xml" and uses it for the XWork configuration.
  *
- * @author $Author$
+ * @author tmjee
+ * @author Rainer Hermanns
+ * @author Neo
  * @version $Revision$
  */
 public class XmlConfigurationProvider implements ConfigurationProvider {
             }
 
             ResultTypeConfig resultType = new ResultTypeConfig(name, clazz);
+            // load param of result type
+            NodeList params = resultTypeElement.getElementsByTagName("param");
+            for (int j = 0; j < params.getLength(); j++) {
+                Element param = (Element) params.item(j);
+                resultType.addParam(param.getAttribute("name"), param.getTextContent());
+            }
             packageContext.addResultTypeConfig(resultType);
 
             // set the default result type
                     LOG.error("Result type '" + resultType + "' is invalid. Modify your xwork.xml file.");
                 }
 
-                Map params = XmlHelper.getParams(resultElement);
+                Map resultParams = XmlHelper.getParams(resultElement);
 
-                if (params.size() == 0) // maybe we just have a body - therefore a default parameter
+                if (resultParams.size() == 0) // maybe we just have a body - therefore a default parameter
                 {
                     // if <result ...>something</result> then we add a parameter of 'something' as this is the most used result param
                     if ((resultElement.getChildNodes().getLength() == 1) && (resultElement.getChildNodes().item(0).getNodeType() == Node.TEXT_NODE))
                     {
-                        params = new TreeMap();
+                        resultParams = new TreeMap();
 
                         try {
                             String paramName = (String) resultClass.getField("DEFAULT_PARAM").get(null);
                             if (paramValue != null) {
                                 paramValue = paramValue.trim();
                             }
-                            params.put(paramName, paramValue);
+                            resultParams.put(paramName, paramValue);
                         } catch (Throwable t) {
                         }
                     }
                 }
 
+                // create new param map, so that the result param can override the config param
+                Map params = new TreeMap();
+                Map configParams = config.getParams();
+                if (configParams != null) {
+                    params.putAll(configParams);
+                }
+                params.putAll(resultParams);
+
                 ResultConfig resultConfig = new ResultConfig(resultName, resultClass, params);
                 results.put(resultConfig.getName(), resultConfig);
             }