You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by dd...@apache.org on 2006/12/27 16:25:48 UTC
svn commit: r490514 - in
/struts/struts2/trunk/core/src/main/java/org/apache/struts2/config:
ClasspathConfigurationProvider.java Result.java
Author: ddewolf
Date: Wed Dec 27 07:25:48 2006
New Revision: 490514
URL: http://svn.apache.org/viewvc?view=rev&rev=490514
Log:
WW-1575 Allowing Result parameters to be set on auto config actions
Modified:
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/ClasspathConfigurationProvider.java
struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/Result.java
Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/ClasspathConfigurationProvider.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/ClasspathConfigurationProvider.java?view=diff&rev=490514&r1=490513&r2=490514
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/ClasspathConfigurationProvider.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/ClasspathConfigurationProvider.java Wed Dec 27 07:25:48 2006
@@ -213,7 +213,7 @@
/**
* Register a PageLocation to use to scan for server pages.
- *
+ *
* @param locator
*/
public void setPageLocator(PageLocator locator) {
@@ -236,10 +236,10 @@
// Match Action implementations and classes ending with "Action"
public boolean matches(Class type) {
// TODO: should also find annotated classes
- return (Action.class.isAssignableFrom(type) ||
+ return (Action.class.isAssignableFrom(type) ||
type.getSimpleName().endsWith("Action"));
}
-
+
}, pkgs);
Set<? extends Class<? extends Class>> actionClasses = resolver.getClasses();
@@ -333,7 +333,7 @@
*
* The namespace annotation is honored, if found,
* and the namespace is checked for a parent configuration.
- *
+ *
* @param actionNamespace The configuration namespace
* @param actionPackage The Java package containing our Action classes
* @param actionClass The Action class instance
@@ -445,7 +445,6 @@
actionClass = actionClass.getSuperclass();
}
-
}
/**
@@ -459,7 +458,24 @@
if (cls == NullResult.class) {
cls = null;
}
- return createResultConfig(result.name(), cls, result.value());
+ return createResultConfig(result.name(), cls, result.value(), createParameterMap(result.params()));
+ }
+
+ protected Map<String, String> createParameterMap(String[] parms) {
+ Map<String, String> map = new HashMap<String, String>();
+ int subtract = parms.length % 2;
+ if(subtract != 0) {
+ LOG.warn("Odd number of result parameters key/values specified. The final one will be ignored.");
+ }
+ for (int i = 0; i < parms.length - subtract; i++) {
+ String key = parms[i++];
+ String value = parms[i];
+ map.put(key, value);
+ if(LOG.isDebugEnabled()) {
+ LOG.debug("Adding parmeter["+key+":"+value+"] to result.");
+ }
+ }
+ return map;
}
/**
@@ -485,7 +501,7 @@
}
String location = defaultPagePrefix + fileName;
- return (V) createResultConfig(key, null, location);
+ return (V) createResultConfig(key, null, location, null);
}
}
@@ -497,10 +513,11 @@
* @param key The result type name
* @param resultClass The class for the result type
* @param location Path to the resource represented by this type
- * @return A ResultConfig for key mapped to location
+ * @return A ResultConfig for key mapped to location
*/
- private ResultConfig createResultConfig(Object key, Class<? extends Object> resultClass, String location) {
- Map<? extends Object, ? extends Object> configParams = null;
+ private ResultConfig createResultConfig(Object key, Class<? extends Object> resultClass,
+ String location,
+ Map<? extends Object,? extends Object > configParams) {
if (resultClass == null) {
String defaultResultType = pkgConfig.getFullDefaultResultType();
ResultTypeConfig resultType = pkgConfig.getAllResultTypeConfigs().get(defaultResultType);
@@ -525,6 +542,7 @@
if (configParams != null) {
params.putAll(configParams);
}
+
params.put(defaultParam, location);
return new ResultConfig((String) key, resultClass.getName(), params);
}
Modified: struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/Result.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/Result.java?view=diff&rev=490514&r1=490513&r2=490514
==============================================================================
--- struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/Result.java (original)
+++ struts/struts2/trunk/core/src/main/java/org/apache/struts2/config/Result.java Wed Dec 27 07:25:48 2006
@@ -33,4 +33,5 @@
String name() default Action.SUCCESS;
Class type() default NullResult.class;
String value();
+ String[] params() default {};
}