You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by cr...@apache.org on 2005/11/16 04:03:22 UTC

svn commit: r344857 - /struts/shale/trunk/core-library/src/java/org/apache/shale/validator/CommonsValidator.java

Author: craigmcc
Date: Tue Nov 15 19:03:20 2005
New Revision: 344857

URL: http://svn.apache.org/viewcvs?rev=344857&view=rev
Log:
[37367] Remove Commons Validator deprecations in preparation for upgrading
to the newly released Commons Validator 1.2.0.

Submitted By:  Rahul Akolkar <rahul AT apache.org>

Modified:
    struts/shale/trunk/core-library/src/java/org/apache/shale/validator/CommonsValidator.java

Modified: struts/shale/trunk/core-library/src/java/org/apache/shale/validator/CommonsValidator.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/java/org/apache/shale/validator/CommonsValidator.java?rev=344857&r1=344856&r2=344857&view=diff
==============================================================================
--- struts/shale/trunk/core-library/src/java/org/apache/shale/validator/CommonsValidator.java (original)
+++ struts/shale/trunk/core-library/src/java/org/apache/shale/validator/CommonsValidator.java Tue Nov 15 19:03:20 2005
@@ -30,6 +30,7 @@
 import java.util.Map;
 import java.util.MissingResourceException;
 import java.util.ResourceBundle;
+import java.util.StringTokenizer;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -47,7 +48,8 @@
 import org.apache.commons.validator.GenericValidator;
 import org.apache.commons.validator.ValidatorAction;
 import org.apache.commons.validator.ValidatorResources;
-import org.apache.commons.validator.ValidatorResourcesInitializer;
+
+import org.xml.sax.SAXException;
 
 /**
  * <p>This is a JSF validator that uses
@@ -373,15 +375,29 @@
       if (validatorResources == null) { 
          InputStream in = external.getResourceAsStream(
                               "/WEB-INF/validator-rules.xml");
-         validatorResources = new ValidatorResources();
          try {
-            ValidatorResourcesInitializer.initialize(validatorResources, in);
+            validatorResources = new ValidatorResources(in);
             applicationMap.put(VALIDATOR_RESOURCES_KEY, validatorResources);
          } catch (IOException ex) {
             logger.log(Level.SEVERE, "can't initialize resources", ex);
             return null;
+         } catch (SAXException ex) {
+            logger.log(Level.SEVERE, "can't initialize resources", ex);
+            return null;
+         } finally {
+            // it's the client's responsibility to close this stream
+            try {
+                if (in != null) in.close();
+            } catch (IOException ex) {
+                logger.log(Level.SEVERE,
+                    "could not close initialization resource stream", ex);
+            }
          }
       }
+      if (validatorResources == null) {
+         // validatorResources could be null if constructor failed in outer try
+         return null;
+      }
       return validatorResources.getValidatorAction(name);
    }
 
@@ -446,7 +462,17 @@
       ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
       if (classLoader == null) classLoader = getClass().getClassLoader();
       try {
-         List params = validatorAction.getMethodParamsList();
+         String methodParams = validatorAction.getMethodParams();
+         // methodParams is a comma separated list of the fully qualified
+         // class names of the method parameters in the correct order
+         StringTokenizer st = new StringTokenizer(methodParams, ",");
+         List params = new ArrayList();
+         while (st.hasMoreTokens()) {
+             String value = st.nextToken().trim();
+             if (value != null && value.length() > 0) {
+                 params.add(value);
+             }
+         }
          paramTypes = new Class[params.size()];
          for (int i = 0; i < paramTypes.length; i++) {
             String paramTypeName = (String) params.get(i);



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org