commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mr...@apache.org
Subject svn commit: r264695 - in /jakarta/commons/proper/validator/trunk/src: share/org/apache/commons/validator/ test/org/apache/commons/validator/
Date Tue, 30 Aug 2005 03:58:09 GMT
Author: mrdon
Date: Mon Aug 29 20:58:06 2005
New Revision: 264695

URL: http://svn.apache.org/viewcvs?rev=264695&view=rev
Log:
 * Adding support for passing validator xml uris, enabling entity
   imports
 * Adding unit tests
 PR: 27258

Added:
    jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/EntityImportTest.java
    jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/byteform.xml
    jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/validator-import.xml
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/ValidatorTestSuite.java

Modified: jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/ValidatorResources.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/ValidatorResources.java?rev=264695&r1=264694&r2=264695&view=diff
==============================================================================
--- 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
Mon Aug 29 20:58:06 2005
@@ -142,6 +142,56 @@
 
         super();
 
+        Digester digester = initDigester();
+        for (int i = 0; i < streams.length; i++) {
+            digester.push(this);
+            digester.parse(streams[i]);
+        }
+
+        this.process();
+    }
+    
+    /**
+     * Create a ValidatorResources object from an uri
+     *
+     * @param uri The location of a validation.xml configuration file. 
+     * @throws IOException
+     * @throws SAXException if the validation XML files are not valid or well
+     * formed.
+     * @since Validator 1.1
+     */
+    public ValidatorResources(String url) throws IOException, SAXException {
+        this(new String[]{url});
+    }
+
+    /**
+     * Create a ValidatorResources object from several uris
+     *
+     * @param uris An array of uris 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.
+     * @since Validator 1.1
+     */
+    public ValidatorResources(String[] uris)
+            throws IOException, SAXException {
+
+        super();
+
+        Digester digester = initDigester();
+        for (int i = 0; i < uris.length; i++) {
+            digester.push(this);
+            digester.parse(uris[i]);
+        }
+
+        this.process();
+    }    
+    
+    /**
+     *  Initialize the digester.
+     */
+    private Digester initDigester() {
         URL rulesUrl = this.getClass().getResource("digester-rules.xml");
         Digester digester = DigesterLoader.createDigester(rulesUrl);
         digester.setNamespaceAware(true);
@@ -155,13 +205,7 @@
                 digester.register(registrations[i], url.toString());
             }
         }
-
-        for (int i = 0; i < streams.length; i++) {
-            digester.push(this);
-            digester.parse(streams[i]);
-        }
-
-        this.process();
+        return digester;
     }
 
     /**
@@ -324,7 +368,7 @@
 
         this.processForms();
     }
-
+    
     /**
      * <p>Process the <code>Form</code> objects.  This clones the <code>Field</code>s
      * that don't exist in a <code>FormSet</code> compared to its parent

Added: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/EntityImportTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/EntityImportTest.java?rev=264695&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/EntityImportTest.java
(added)
+++ jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/EntityImportTest.java
Mon Aug 29 20:58:06 2005
@@ -0,0 +1,68 @@
+/*
+ * $Header: /home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/ByteTest.java,v
1.14 2004/02/21 17:10:30 rleland Exp $
+ * $Revision: 1.14 $
+ * $Date: 2004/02/21 17:10:30 $
+ *
+ * ====================================================================
+ * Copyright 2001-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.commons.validator;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import java.io.IOException;
+import org.xml.sax.SAXException;
+import java.util.Locale;
+import java.net.URL;
+
+
+/**                                                       
+ * Tests entity imports.
+ */
+public class EntityImportTest extends TestCommon {
+
+    public EntityImportTest(String name) {
+        super(name);
+    }
+
+    /**
+     * Start the tests.
+     *
+     * @param theArgs the arguments. Not used
+     */
+    public static void main(String[] theArgs) {
+        junit.awtui.TestRunner.main(new String[]{EntityImportTest.class.getName()});
+    }
+
+    /**
+     * @return a test suite (<code>TestSuite</code>) that includes all methods
+     *         starting with "test"
+     */
+    public static Test suite() {
+        // All methods starting with "test" will be executed in the test suite.
+        return new TestSuite(EntityImportTest.class);
+    }
+
+    /**
+     * Tests the entity import loading the <code>byteForm</code> form.
+     */
+    public void testEntityImport() throws Exception {
+        URL url = getClass().getResource("validator-import.xml");
+        ValidatorResources resources = new ValidatorResources(url.toExternalForm());
+        assertNotNull("Form should be found", resources.getForm(Locale.getDefault(), "byteForm"));
+    }  
+}                                                         

Modified: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/ValidatorTestSuite.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/ValidatorTestSuite.java?rev=264695&r1=264694&r2=264695&view=diff
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/ValidatorTestSuite.java
(original)
+++ jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/ValidatorTestSuite.java
Mon Aug 29 20:58:06 2005
@@ -40,6 +40,7 @@
     public static Test suite() {
        TestSuite suite = new TestSuite();
 
+       suite.addTest(EntityImportTest.suite());
        suite.addTest(DateTest.suite());
        suite.addTest(RequiredNameTest.suite());
        suite.addTest(RequiredIfTest.suite());

Added: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/byteform.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/byteform.xml?rev=264695&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/byteform.xml
(added)
+++ jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/byteform.xml
Mon Aug 29 20:58:06 2005
@@ -0,0 +1,3 @@
+<form name="byteForm">
+ <field property="byte" depends="byte"/>    
+</form>

Added: jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/validator-import.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/validator-import.xml?rev=264695&view=auto
==============================================================================
--- jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/validator-import.xml
(added)
+++ jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/validator-import.xml
Mon Aug 29 20:58:06 2005
@@ -0,0 +1,17 @@
+<!DOCTYPE form-validation PUBLIC
+     "-//Apache Software Foundation//DTD Commons Validator Rules Configuration 1.1//EN"
+     "http://jakarta.apache.org/commons/dtds/validator_1_1.dtd" 
+     [<!ENTITY byteform SYSTEM "byteform.xml">]>
+     
+<form-validation>
+   <global>
+      <validator name="byte"
+                 classname="org.apache.commons.validator.TestTypeValidator"
+                 method="validateByte"
+                 methodParams="java.lang.Object,org.apache.commons.validator.Field"
+                 msg=""/>
+   </global>
+   <formset>
+        &byteform;
+   </formset>   
+</form-validation>



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


Mime
View raw message