struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject svn commit: r1293791 - in /struts/struts2/trunk/xwork-core/src: main/java/com/opensymphony/xwork2/validator/ test/java/com/opensymphony/xwork2/validator/
Date Sun, 26 Feb 2012 09:28:10 GMT
Author: lukaszlenart
Date: Sun Feb 26 09:28:10 2012
New Revision: 1293791

URL: http://svn.apache.org/viewvc?rev=1293791&view=rev
Log:
WW-3753 -  adheres AnnotationActionValidatorManager to  ActionValidatorManager interface's
contract

Modified:
    struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/AnnotationActionValidatorManager.java
    struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/ValidationInterceptor.java
    struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationActionValidatorManagerTest.java

Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/AnnotationActionValidatorManager.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/AnnotationActionValidatorManager.java?rev=1293791&r1=1293790&r2=1293791&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/AnnotationActionValidatorManager.java
(original)
+++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/AnnotationActionValidatorManager.java
Sun Feb 26 09:28:10 2012
@@ -75,7 +75,7 @@ public class AnnotationActionValidatorMa
     }
 
     public List<Validator> getValidators(Class clazz, String context, String method)
{
-        final String validatorKey = buildValidatorKey(clazz);
+        final String validatorKey = buildValidatorKey(clazz, context);
         final List<ValidatorConfig> cfgs;
 
         if (validatorCache.containsKey(validatorKey)) {
@@ -216,23 +216,36 @@ public class AnnotationActionValidatorMa
      * @param clazz the action.
      * @return a validator key which is the class name plus context.
      */
-    protected static String buildValidatorKey(Class clazz) {
+    protected static String buildValidatorKey(Class clazz, String context) {
         ActionInvocation invocation = ActionContext.getContext().getActionInvocation();
         ActionProxy proxy = invocation.getProxy();
         ActionConfig config = proxy.getConfig();
 
-        //the key needs to use the name of the action from the config file,
-        //instead of the url, so wild card actions will have the same validator
-        //see WW-2996
         StringBuilder sb = new StringBuilder(clazz.getName());
         sb.append("/");
         if (StringUtils.isNotBlank(config.getPackageName())) {
             sb.append(config.getPackageName());
             sb.append("/");
         }
-        sb.append(config.getName());
-        sb.append("|");
-        sb.append(proxy.getMethod());
+
+        // the key needs to use the name of the action from the config file,
+        // instead of the url, so wild card actions will have the same validator
+        // see WW-2996
+
+        // UPDATE:
+        // WW-3753 Using the config name instead of the context only for
+        // wild card actions to keep the flexibility provided
+        // by the original design (such as mapping different contexts
+        // to the same action and method if desired)
+        String configName = config.getName();
+        if (configName.contains(ActionConfig.WILDCARD)) {
+            sb.append(configName);
+            sb.append("|");
+            sb.append(proxy.getMethod());
+        } else {
+            sb.append(context);
+        }
+        
         return sb.toString();
     }
 

Modified: struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/ValidationInterceptor.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/ValidationInterceptor.java?rev=1293791&r1=1293790&r2=1293791&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/ValidationInterceptor.java
(original)
+++ struts/struts2/trunk/xwork-core/src/main/java/com/opensymphony/xwork2/validator/ValidationInterceptor.java
Sun Feb 26 09:28:10 2012
@@ -19,7 +19,6 @@ import com.opensymphony.xwork2.ActionInv
 import com.opensymphony.xwork2.ActionProxy;
 import com.opensymphony.xwork2.Validateable;
 import com.opensymphony.xwork2.inject.Inject;
-import com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor;
 import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
 import com.opensymphony.xwork2.interceptor.PrefixMethodInvocationUtil;
 import com.opensymphony.xwork2.util.logging.Logger;
@@ -206,7 +205,8 @@ public class ValidationInterceptor exten
 
         //the action name has to be from the url, otherwise validators that use aliases,
like
         //MyActio-someaction-validator.xml will not be found, see WW-3194
-        String context = proxy.getActionName();
+        //UPDATE:  see WW-3753
+        String context = this.getValidationContext(proxy);
         String method = proxy.getMethod();
 
         if (log.isDebugEnabled()) {
@@ -264,5 +264,26 @@ public class ValidationInterceptor exten
         
         return invocation.invoke();
     }
+    
+    /**
+     * Returns the context that will be used by the
+     * {@link ActionValidatorManager} to associate the action invocation with
+     * the appropriate {@link ValidatorConfig ValidatorConfigs}.
+     * <p>
+     * The context returned is used in the pattern
+     * <i>ActionClass-context-validation.xml</i>
+     * <p>
+     * The default context is the action name from the URL, but the method can
+     * be overridden to implement custom contexts.
+     * <p>
+     * This can be useful in cases in which a single action and a single model
+     * require vastly different validation based on some condition.
+     * 
+     * @return the Context
+     */
+    protected String getValidationContext(ActionProxy proxy) {
+        // This method created for WW-3753
+        return proxy.getActionName();
+    }
 
 }

Modified: struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationActionValidatorManagerTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationActionValidatorManagerTest.java?rev=1293791&r1=1293790&r2=1293791&view=diff
==============================================================================
--- struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationActionValidatorManagerTest.java
(original)
+++ struts/struts2/trunk/xwork-core/src/test/java/com/opensymphony/xwork2/validator/AnnotationActionValidatorManagerTest.java
Sun Feb 26 09:28:10 2012
@@ -70,8 +70,8 @@ public class AnnotationActionValidatorMa
     }
 
     public void testBuildValidatorKey() {
-        String validatorKey = AnnotationActionValidatorManager.buildValidatorKey(SimpleAnnotationAction.class);
-        assertEquals(SimpleAnnotationAction.class.getName() + "/packageName/name|execute",
validatorKey);
+        String validatorKey = AnnotationActionValidatorManager.buildValidatorKey(SimpleAnnotationAction.class,
"name");
+        assertEquals(SimpleAnnotationAction.class.getName() + "/packageName/name", validatorKey);
     }
 
     public void testBuildsValidatorsForAlias() {



Mime
View raw message