Author: niallp
Date: Wed Nov 22 21:42:30 2006
New Revision: 478473

URL: http://svn.apache.org/viewvc?view=rev&rev=478473
Log:
VALIDATOR-209 - Additional constructor for ValidatorResources that takes URL[] 
instead of String[] - thanks to Craig McClanahan

Modified:
    
jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/ValidatorResources.java
    
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/EntityImportTest.java
    jakarta/commons/proper/validator/trunk/xdocs/changes.xml

Modified: 
jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/ValidatorResources.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/ValidatorResources.java?view=diff&rev=478473&r1=478472&r2=478473
==============================================================================
--- 
jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/ValidatorResources.java
 (original)
+++ 
jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/ValidatorResources.java
 Wed Nov 22 21:42:30 2006
@@ -197,7 +197,63 @@
 
         this.process();
     }    
-    
+
+    /**
+     * Create a ValidatorResources object from a URL.
+     *
+     * @param url The URL for the validation.xml
+     * configuration file that will be read into this object.
+     * @throws IOException
+     * @throws SAXException if the validation XML file are not valid or well
+     * formed.
+     * @throws IOException  if an I/O error occurs processing the XML files
+     * @since Validator 1.3.1
+     */
+    public ValidatorResources(URL url)
+            throws IOException, SAXException {
+        this(new URL[]{url});
+    }
+
+    /**
+     * Create a ValidatorResources object from several URL.
+     *
+     * @param urls An array of URL to several validation.xml
+     * configuration files that will be read in order and merged into this 
object.
+     * @throws IOException
+     * @throws SAXException if the validation XML files are not valid or well
+     * formed.
+     * @throws IOException  if an I/O error occurs processing the XML files
+     * @since Validator 1.3.1
+     */
+    public ValidatorResources(URL[] urls)
+            throws IOException, SAXException {
+
+        super();
+
+        Digester digester = initDigester();
+        for (int i = 0; i < urls.length; i++) {
+            digester.push(this);
+            InputStream stream = null;
+            try {
+                stream = urls[i].openStream();
+                org.xml.sax.InputSource source = 
+                     new org.xml.sax.InputSource(urls[i].toExternalForm());
+                source.setByteStream(stream);
+                digester.parse(source);
+            } finally {
+                if (stream != null) {
+                    try {
+                        stream.close();
+                    } catch (IOException e) {
+                        // ignore problem closing
+                    }
+                }
+            } 
+        }
+
+        this.process();
+    }
+
     /**
      *  Initialize the digester.
      */

Modified: 
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/EntityImportTest.java
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/EntityImportTest.java?view=diff&rev=478473&r1=478472&r2=478473
==============================================================================
--- 
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/EntityImportTest.java
 (original)
+++ 
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/EntityImportTest.java
 Wed Nov 22 21:42:30 2006
@@ -61,4 +61,13 @@
         ValidatorResources resources = new 
ValidatorResources(url.toExternalForm());
         assertNotNull("Form should be found", 
resources.getForm(Locale.getDefault(), "byteForm"));
     }  
-}                                                         
+
+    /**
+     * Tests loading ValidatorResources from a URL
+     */
+    public void testParseURL() throws Exception {
+        URL url = getClass().getResource("EntityImportTest-config.xml");
+        ValidatorResources resources = new ValidatorResources(url);
+        assertNotNull("Form should be found", 
resources.getForm(Locale.getDefault(), "byteForm"));
+    }
+}

Modified: jakarta/commons/proper/validator/trunk/xdocs/changes.xml
URL: 
http://svn.apache.org/viewvc/jakarta/commons/proper/validator/trunk/xdocs/changes.xml?view=diff&rev=478473&r1=478472&r2=478473
==============================================================================
--- jakarta/commons/proper/validator/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/validator/trunk/xdocs/changes.xml Wed Nov 22 
21:42:30 2006
@@ -40,6 +40,9 @@
   <body>
 
     <release version="1.3.1" date="Pending">
+      <action dev="niallp" type="update" issue="VALIDATOR-209" due-to="Craig 
McClanahan">
+        Additional constructor for ValidatorResources that takes URL[] instead 
of String[].
+      </action>
       <action dev="niallp" type="fix" issue="VALIDATOR-195" due-to="Vijay 
Pandey">
         Fix loading of Digester rules for custom ValidatorResources 
implementations.
       </action>



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to