Commits

mrdon  committed 0c9f96c

Supporting multiple directories for validation files

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

  • Participants
  • Parent commits f142257

Comments (0)

Files changed (1)

File src/java/com/opensymphony/xwork2/validator/DefaultValidatorFactory.java

 import java.io.File;
 import java.io.FilenameFilter;
 import java.io.InputStream;
+import java.io.IOException;
 import java.net.URISyntaxException;
 import java.net.URL;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Arrays;
+import java.util.*;
 
 import com.opensymphony.xwork2.ObjectFactory;
 import com.opensymphony.xwork2.XWorkException;
+import com.opensymphony.xwork2.config.ConfigurationException;
 import com.opensymphony.xwork2.inject.Inject;
 import com.opensymphony.xwork2.util.ClassLoaderUtil;
 import com.opensymphony.xwork2.util.logging.Logger;
             LOG.debug("Loading validator definitions.");
         }
 
-        // Get custom validator configurations via the classpath
-        URL u = ClassLoaderUtil.getResource("", DefaultValidatorFactory.class);
-        File[] files = null;
+        List<File> files = new ArrayList<File>();
         try {
-            System.out.println("looing at :"+u);
-            File f = new File(u.toURI());
-            FilenameFilter filter = new FilenameFilter() {
-                public boolean accept(File file, String fileName) {
-                    return fileName.contains("-validators.xml");
-                }
-            };
-            files = f.listFiles(filter);
-            System.out.println("main url:"+u);
-            System.out.println("files:"+ Arrays.asList(files));
-            System.out.println("full file list: "+Arrays.asList(new File(u.toURI()).list()));
+            // Get custom validator configurations via the classpath
+            Iterator<URL> urls = ClassLoaderUtil.getResources("", DefaultValidatorFactory.class, false);
+            while (urls.hasNext()) {
+                URL u = urls.next();
+                File f = new File(u.toURI());
+                FilenameFilter filter = new FilenameFilter() {
+                    public boolean accept(File file, String fileName) {
+                        return fileName.contains("-validators.xml");
+                    }
+                };
+                files.addAll(Arrays.asList(f.listFiles(filter)));
+            }
         } catch (URISyntaxException e) {
             e.printStackTrace();
             // swallow
+        } catch (IOException e) {
+            throw new ConfigurationException("Unable to parse validators", e);
         }
 
         // Parse default validator configurations
         retrieveValidatorConfiguration(resourceName);
 
         // Add custom (plugin) specific validator configurations
-        if ( files != null && files.length > 0 ) {
-            for (File file : files) {
-                retrieveValidatorConfiguration(file.getName());
-            }
+        for (File file : files) {
+            retrieveValidatorConfiguration(file.getName());
         }
     }