Author: niallp
Date: Wed Nov 22 15:51:09 2006
New Revision: 478392
URL: http://svn.apache.org/viewvc?view=rev&rev=478392
Log:
VALIDATOR-195 - Fix loading of Digester rules for custom ValidatorResources
implementations - thanks to Vijay Pandey
Added:
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/CustomValidatorResourcesTest.java
(with props)
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/custom/
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/custom/CustomValidatorResources.java
(with props)
Modified:
jakarta/commons/proper/validator/trunk/src/share/org/apache/commons/validator/ValidatorResources.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=478392&r1=478391&r2=478392
==============================================================================
---
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 15:51:09 2006
@@ -54,6 +54,9 @@
*/
public class ValidatorResources implements Serializable {
+ /** Name of the digester validator rules file */
+ private static final String VALIDATOR_RULES = "digester-rules.xml";
+
/**
* The set of public identifiers, and corresponding resource names, for
* the versions of the configuration file DTDs that we know about. There
@@ -199,7 +202,14 @@
* Initialize the digester.
*/
private Digester initDigester() {
- URL rulesUrl = this.getClass().getResource("digester-rules.xml");
+ URL rulesUrl = this.getClass().getResource(VALIDATOR_RULES);
+ if (rulesUrl == null) {
+ // Fix for Issue# VALIDATOR-195
+ rulesUrl = ValidatorResources.class.getResource(VALIDATOR_RULES);
+ }
+ if (getLog().isDebugEnabled()) {
+ getLog().debug("Loading rules from '" + rulesUrl + "'");
+ }
Digester digester = DigesterLoader.createDigester(rulesUrl);
digester.setNamespaceAware(true);
digester.setValidating(true);
Added:
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/CustomValidatorResourcesTest.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/CustomValidatorResourcesTest.java?view=auto&rev=478392
==============================================================================
---
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/CustomValidatorResourcesTest.java
(added)
+++
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/CustomValidatorResourcesTest.java
Wed Nov 22 15:51:09 2006
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 java.io.InputStream;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.apache.commons.validator.custom.CustomValidatorResources;
+
+/**
+ * Test custom ValidatorResources.
+ *
+ * @version $Revision$ $Date$
+ */
+public class CustomValidatorResourcesTest extends TestCase {
+
+ /**
+ * Construct a test case with the specified name.
+ * @param name Name of the test
+ */
+ public CustomValidatorResourcesTest(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[]
{ValidatorResultsTest.class.getName()});
+ }
+
+ /**
+ * Create a Test Suite
+ * @return a test suite (<code>TestSuite</code>) that includes all methods
+ * starting with "test"
+ */
+ public static Test suite() {
+ return new TestSuite(CustomValidatorResourcesTest.class);
+ }
+
+ /**
+ * Set up.
+ */
+ protected void setUp() {
+ }
+
+ /**
+ * Tear Down
+ */
+ protected void tearDown() {
+ }
+
+ /**
+ * Test creating a custom validator resources.
+ */
+ public void testCustomResources() {
+ // Load resources
+ InputStream in = null;
+ ValidatorResources resources = null;
+
+ try {
+ in = this.getClass().getResourceAsStream("TestNumber-config.xml");
+ resources = new CustomValidatorResources(in);
+ } catch(Exception e) {
+ fail("Error loading resources: " + e);
+ } finally {
+ try {
+ if (in != null) {
+ in.close();
+ }
+ } catch(Exception e) {
+ }
+ }
+ }
+
+}
Propchange:
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/CustomValidatorResourcesTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/CustomValidatorResourcesTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Added:
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/custom/CustomValidatorResources.java
URL:
http://svn.apache.org/viewvc/jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/custom/CustomValidatorResources.java?view=auto&rev=478392
==============================================================================
---
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/custom/CustomValidatorResources.java
(added)
+++
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/custom/CustomValidatorResources.java
Wed Nov 22 15:51:09 2006
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.custom;
+
+import java.io.InputStream;
+import java.io.IOException;
+import org.xml.sax.SAXException;
+import org.apache.commons.validator.ValidatorResources;
+
+/**
+ * Custom ValidatorResources implementation.
+ *
+ * @version $Revision$ $Date$
+ */
+public class CustomValidatorResources extends ValidatorResources {
+
+ /**
+ * Create a custom ValidatorResources object from an uri
+ *
+ * @param in InputStream for the validation.xml configuration file.
+ * @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
+ */
+ public CustomValidatorResources(InputStream in) throws IOException,
SAXException {
+ super(in);
+ }
+
+}
\ No newline at end of file
Propchange:
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/custom/CustomValidatorResources.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
jakarta/commons/proper/validator/trunk/src/test/org/apache/commons/validator/custom/CustomValidatorResources.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
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=478392&r1=478391&r2=478392
==============================================================================
--- jakarta/commons/proper/validator/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/validator/trunk/xdocs/changes.xml Wed Nov 22
15:51:09 2006
@@ -40,6 +40,9 @@
<body>
<release version="1.3.1" date="Pending">
+ <action dev="niallp" type="fix" issue="VALIDATOR-195" due-to="Vijay
Pandey">
+ Fix loading of Digester rules for custom ValidatorResources
implementations.
+ </action>
<action dev="niallp" type="fix" issue="VALIDATOR-19" due-to="Masahiro
Honda">
Validator incorrectly storing itself under the FORM_PARAM key rather
than
the Form.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]