commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgo...@apache.org
Subject svn commit: r729581 - in /commons/proper/configuration/trunk: ./ conf/ src/java/org/apache/commons/configuration/ src/java/org/apache/commons/configuration/resolver/ src/site/ src/test/org/apache/commons/configuration/ xdocs/ xdocs/userguide/
Date Sat, 27 Dec 2008 02:27:50 GMT
Author: rgoers
Date: Fri Dec 26 18:27:49 2008
New Revision: 729581

URL: http://svn.apache.org/viewvc?rev=729581&view=rev
Log:
CONFIGURATION-257 and CONFIGURATION-355 Add support for enhanced EntityResolvers and Schema validation

Added:
    commons/proper/configuration/trunk/conf/catalog.xml   (with props)
    commons/proper/configuration/trunk/conf/resolver.dtd   (with props)
    commons/proper/configuration/trunk/conf/sample.xml   (with props)
    commons/proper/configuration/trunk/conf/sample.xsd   (with props)
    commons/proper/configuration/trunk/conf/testResolver.xml   (with props)
    commons/proper/configuration/trunk/conf/testValidation.xml   (with props)
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/CatalogResolver.java   (with props)
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/DefaultEntityResolver.java   (with props)
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/EntityRegistry.java   (with props)
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/package.html
    commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestCatalogResolver.java   (with props)
Modified:
    commons/proper/configuration/trunk/conf/testGlobalLookup.xml   (props changed)
    commons/proper/configuration/trunk/conf/testMultiConfiguration_1001.xml   (contents, props changed)
    commons/proper/configuration/trunk/conf/testMultiConfiguration_1002.xml   (contents, props changed)
    commons/proper/configuration/trunk/conf/testMultiConfiguration_1003.xml   (contents, props changed)
    commons/proper/configuration/trunk/conf/testMultiConfiguration_1004.xml   (props changed)
    commons/proper/configuration/trunk/conf/testMultiConfiguration_default.xml   (props changed)
    commons/proper/configuration/trunk/conf/testPatternSubtreeConfig.xml   (props changed)
    commons/proper/configuration/trunk/pom.xml
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DefaultConfigurationBuilder.java
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java
    commons/proper/configuration/trunk/src/site/site.xml
    commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDefaultConfigurationBuilder.java
    commons/proper/configuration/trunk/xdocs/changes.xml
    commons/proper/configuration/trunk/xdocs/dependencies.xml
    commons/proper/configuration/trunk/xdocs/index.xml
    commons/proper/configuration/trunk/xdocs/userguide/howto_xml.xml

Added: commons/proper/configuration/trunk/conf/catalog.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/conf/catalog.xml?rev=729581&view=auto
==============================================================================
--- commons/proper/configuration/trunk/conf/catalog.xml (added)
+++ commons/proper/configuration/trunk/conf/catalog.xml Fri Dec 26 18:27:49 2008
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
+
+  <public publicId="-//Apache//DTD Resolver Test V1.0//EN"
+          uri="resolver.dtd"/>
+  <rewriteSystem systemIdStartString="http://java.sun.com/dtd/"
+                 rewritePrefix="./"/>
+  <rewriteSystem systemIdStartString="http://commons.apache.org/" rewritePrefix="./"/>
+</catalog>
\ No newline at end of file

Propchange: commons/proper/configuration/trunk/conf/catalog.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/trunk/conf/catalog.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/proper/configuration/trunk/conf/catalog.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: commons/proper/configuration/trunk/conf/resolver.dtd
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/conf/resolver.dtd?rev=729581&view=auto
==============================================================================
--- commons/proper/configuration/trunk/conf/resolver.dtd (added)
+++ commons/proper/configuration/trunk/conf/resolver.dtd Fri Dec 26 18:27:49 2008
@@ -0,0 +1,19 @@
+<!--
+  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.
+-->
+<!ELEMENT test (foo|bar)+>
+<!ELEMENT foo EMPTY>
+<!ELEMENT bar EMPTY>
\ No newline at end of file

Propchange: commons/proper/configuration/trunk/conf/resolver.dtd
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/proper/configuration/trunk/conf/sample.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/conf/sample.xml?rev=729581&view=auto
==============================================================================
--- commons/proper/configuration/trunk/conf/sample.xml (added)
+++ commons/proper/configuration/trunk/conf/sample.xml Fri Dec 26 18:27:49 2008
@@ -0,0 +1,12 @@
+<?xml version="1.0" ?>
+<Employees xmlns="http://commons.apache.org/employee"
+           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+           xsi:schemaLocation="http://commons.apache.org/employee http://commons.apache.org/sample.xsd">
+  <Employee>
+    <SSN>555121211</SSN>
+    <Name>John Doe</Name>
+    <DateOfBirth>1975-05-15</DateOfBirth>
+    <EmployeeType>Exempt</EmployeeType>
+    <Salary>100000</Salary>
+  </Employee>
+</Employees>
\ No newline at end of file

Propchange: commons/proper/configuration/trunk/conf/sample.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/trunk/conf/sample.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/proper/configuration/trunk/conf/sample.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: commons/proper/configuration/trunk/conf/sample.xsd
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/conf/sample.xsd?rev=729581&view=auto
==============================================================================
--- commons/proper/configuration/trunk/conf/sample.xsd (added)
+++ commons/proper/configuration/trunk/conf/sample.xsd Fri Dec 26 18:27:49 2008
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://commons.apache.org/employee" xmlns:xs="http://www.w3.org/2001/XMLSchema">
+  <xs:element name="Employees" type="emp:EmployeesType" xmlns:emp="http://commons.apache.org/employee"/>
+  <xs:complexType name="EmployeeType">
+    <xs:sequence>
+      <xs:element type="xs:string" name="SSN"/>
+      <xs:element type="xs:string" name="Name"/>
+      <xs:element type="xs:string" name="DateOfBirth"/>
+      <xs:element type="xs:string" name="EmployeeType"/>
+      <xs:element type="xs:string" name="Salary"/>
+    </xs:sequence>
+  </xs:complexType>
+  <xs:complexType name="EmployeesType">
+    <xs:sequence>
+      <xs:element type="emp:EmployeeType" name="Employee" xmlns:emp="http://commons.apache.org/employee"/>
+    </xs:sequence>
+  </xs:complexType>
+</xs:schema>
\ No newline at end of file

Propchange: commons/proper/configuration/trunk/conf/sample.xsd
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/trunk/conf/sample.xsd
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/proper/configuration/trunk/conf/sample.xsd
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Propchange: commons/proper/configuration/trunk/conf/testGlobalLookup.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/trunk/conf/testGlobalLookup.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/proper/configuration/trunk/conf/testGlobalLookup.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: commons/proper/configuration/trunk/conf/testMultiConfiguration_1001.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/conf/testMultiConfiguration_1001.xml?rev=729581&r1=729580&r2=729581&view=diff
==============================================================================
--- commons/proper/configuration/trunk/conf/testMultiConfiguration_1001.xml (original)
+++ commons/proper/configuration/trunk/conf/testMultiConfiguration_1001.xml Fri Dec 26 18:27:49 2008
@@ -1,15 +1,15 @@
-<?xml version="1.0" encoding="ISO-8859-1" ?>
-<configuration>
-  <colors>
-    <background>#808080</background>
-    <text>#000000</text>
-    <header>#008000</header>
-    <link normal="#000080" visited="#800080"/>
-    <default>${colors.header}</default>
-  </colors>
-  <rowsPerPage>15</rowsPerPage>
-  <buttons>
-    <name>OK,Cancel,Help</name>
-  </buttons>
-  <numberFormat pattern="###\,###.##"/>
-</configuration>
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<configuration>
+  <colors>
+    <background>#808080</background>
+    <text>#000000</text>
+    <header>#008000</header>
+    <link normal="#000080" visited="#800080"/>
+    <default>${colors.header}</default>
+  </colors>
+  <rowsPerPage>15</rowsPerPage>
+  <buttons>
+    <name>OK,Cancel,Help</name>
+  </buttons>
+  <numberFormat pattern="###\,###.##"/>
+</configuration>

Propchange: commons/proper/configuration/trunk/conf/testMultiConfiguration_1001.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/trunk/conf/testMultiConfiguration_1001.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/proper/configuration/trunk/conf/testMultiConfiguration_1001.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: commons/proper/configuration/trunk/conf/testMultiConfiguration_1002.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/conf/testMultiConfiguration_1002.xml?rev=729581&r1=729580&r2=729581&view=diff
==============================================================================
--- commons/proper/configuration/trunk/conf/testMultiConfiguration_1002.xml (original)
+++ commons/proper/configuration/trunk/conf/testMultiConfiguration_1002.xml Fri Dec 26 18:27:49 2008
@@ -1,15 +1,15 @@
-<?xml version="1.0" encoding="ISO-8859-1" ?>
-<configuration>
-  <colors>
-    <background>#2222222</background>
-    <text>#000000</text>
-    <header>#222222</header>
-    <link normal="#020202" visited="#202020"/>
-    <default>${colors.header3}</default>
-  </colors>
-  <rowsPerPage>25</rowsPerPage>
-  <buttons>
-    <name>OK-2,Cancel-2,Help-2</name>
-  </buttons>
-  <numberFormat pattern="###\,###.##"/>
-</configuration>
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<configuration>
+  <colors>
+    <background>#2222222</background>
+    <text>#000000</text>
+    <header>#222222</header>
+    <link normal="#020202" visited="#202020"/>
+    <default>${colors.header3}</default>
+  </colors>
+  <rowsPerPage>25</rowsPerPage>
+  <buttons>
+    <name>OK-2,Cancel-2,Help-2</name>
+  </buttons>
+  <numberFormat pattern="###\,###.##"/>
+</configuration>

Propchange: commons/proper/configuration/trunk/conf/testMultiConfiguration_1002.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/trunk/conf/testMultiConfiguration_1002.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/proper/configuration/trunk/conf/testMultiConfiguration_1002.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: commons/proper/configuration/trunk/conf/testMultiConfiguration_1003.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/conf/testMultiConfiguration_1003.xml?rev=729581&r1=729580&r2=729581&view=diff
==============================================================================
--- commons/proper/configuration/trunk/conf/testMultiConfiguration_1003.xml (original)
+++ commons/proper/configuration/trunk/conf/testMultiConfiguration_1003.xml Fri Dec 26 18:27:49 2008
@@ -1,15 +1,15 @@
-<?xml version="1.0" encoding="ISO-8859-1" ?>
-<configuration>
-  <colors>
-    <background>#333333</background>
-    <text>#FFFFFF</text>
-    <header>#333333</header>
-    <link normal="#030303" visited="#303030"/>
-    <default>${colors.header3}</default>
-  </colors>
-  <rowsPerPage>35</rowsPerPage>
-  <buttons>
-    <name>OK-3,Cancel-3,Help-3</name>
-  </buttons>
-  <numberFormat pattern="###\,###.##"/>
-</configuration>
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<configuration>
+  <colors>
+    <background>#333333</background>
+    <text>#FFFFFF</text>
+    <header>#333333</header>
+    <link normal="#030303" visited="#303030"/>
+    <default>${colors.header3}</default>
+  </colors>
+  <rowsPerPage>35</rowsPerPage>
+  <buttons>
+    <name>OK-3,Cancel-3,Help-3</name>
+  </buttons>
+  <numberFormat pattern="###\,###.##"/>
+</configuration>

Propchange: commons/proper/configuration/trunk/conf/testMultiConfiguration_1003.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/trunk/conf/testMultiConfiguration_1003.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/proper/configuration/trunk/conf/testMultiConfiguration_1003.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Propchange: commons/proper/configuration/trunk/conf/testMultiConfiguration_1004.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/trunk/conf/testMultiConfiguration_1004.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/proper/configuration/trunk/conf/testMultiConfiguration_1004.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Propchange: commons/proper/configuration/trunk/conf/testMultiConfiguration_default.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/trunk/conf/testMultiConfiguration_default.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/proper/configuration/trunk/conf/testMultiConfiguration_default.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Propchange: commons/proper/configuration/trunk/conf/testPatternSubtreeConfig.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/trunk/conf/testPatternSubtreeConfig.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/proper/configuration/trunk/conf/testPatternSubtreeConfig.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: commons/proper/configuration/trunk/conf/testResolver.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/conf/testResolver.xml?rev=729581&view=auto
==============================================================================
--- commons/proper/configuration/trunk/conf/testResolver.xml (added)
+++ commons/proper/configuration/trunk/conf/testResolver.xml Fri Dec 26 18:27:49 2008
@@ -0,0 +1,22 @@
+<?xml version="1.0"?>
+<!--
+  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.
+-->
+<!DOCTYPE test PUBLIC "-//Apache//DTD Resolver Test V1.0//EN"
+                      "http://example.com/does-not-exist">
+<test>
+<foo/>
+</test>
\ No newline at end of file

Propchange: commons/proper/configuration/trunk/conf/testResolver.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/trunk/conf/testResolver.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/proper/configuration/trunk/conf/testResolver.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: commons/proper/configuration/trunk/conf/testValidation.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/conf/testValidation.xml?rev=729581&view=auto
==============================================================================
--- commons/proper/configuration/trunk/conf/testValidation.xml (added)
+++ commons/proper/configuration/trunk/conf/testValidation.xml Fri Dec 26 18:27:49 2008
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!-- Test configuration definition file that demonstrates complex initialization -->
+<configuration>
+  <header>
+    <result delimiterParsingDisabled="true">
+      <nodeCombiner config-class="org.apache.commons.configuration.tree.OverrideCombiner"/>
+      <expressionEngine config-class="org.apache.commons.configuration.tree.xpath.XPathExpressionEngine"/>
+    </result>
+    <entity-resolver catalogFiles="conf/catalog.xml"/>    
+  </header>
+  <system/>
+  <properties fileName="test.properties.xml" throwExceptionOnMissing="true"
+    config-name="properties">
+  </properties>
+  <xml fileName="sample.xml" config-name="xml" schemaValidation="true"/>
+</configuration>
\ No newline at end of file

Propchange: commons/proper/configuration/trunk/conf/testValidation.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/trunk/conf/testValidation.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/proper/configuration/trunk/conf/testValidation.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Modified: commons/proper/configuration/trunk/pom.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/pom.xml?rev=729581&r1=729580&r2=729581&view=diff
==============================================================================
--- commons/proper/configuration/trunk/pom.xml (original)
+++ commons/proper/configuration/trunk/pom.xml Fri Dec 26 18:27:49 2008
@@ -287,6 +287,13 @@
       <artifactId>xml-apis</artifactId>
       <version>1.0.b2</version>
       <scope>provided</scope>
+    </dependency>    
+
+    <dependency>
+      <groupId>xml-resolver</groupId>
+      <artifactId>xml-resolver</artifactId>
+      <version>1.2</version>
+      <optional>true</optional>
     </dependency>
 
     <dependency>
@@ -461,7 +468,25 @@
             <tarLongFileMode>gnu</tarLongFileMode>
           </configuration>
         </plugin>
+        <!-- Uncomment to instrument with Clover
+        <plugin>
+          <groupId>com.atlassian.maven.plugins</groupId>
+          <artifactId>maven-clover2-plugin</artifactId>
+          <version>2.4.2</version>
+          <configuration>
+            <jdk>1.4</jdk>
+          </configuration>
+          <executions>
+            <execution>
+              <phase>pre-site</phase>
+              <goals>
+                <goal>instrument</goal>
+              </goals>
+            </execution>
+          </executions>
+        </plugin>  -->
       </plugins>
+
     </build>
 
   <reporting>
@@ -522,6 +547,12 @@
           <excludeFilterFile>conf/findbugs-exclude-filter.xml</excludeFilterFile>
        </configuration>
       </plugin>
+      <!-- Uncomment to generate clover report
+      <plugin>
+        <groupId>com.atlassian.maven.plugins</groupId>
+        <artifactId>maven-clover2-plugin</artifactId>
+        <version>2.4.2</version>
+      </plugin> -->
     </plugins>
   </reporting>
 

Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DefaultConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DefaultConfigurationBuilder.java?rev=729581&r1=729580&r2=729581&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DefaultConfigurationBuilder.java (original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/DefaultConfigurationBuilder.java Fri Dec 26 18:27:49 2008
@@ -35,8 +35,11 @@
 import org.apache.commons.configuration.tree.DefaultExpressionEngine;
 import org.apache.commons.configuration.tree.OverrideCombiner;
 import org.apache.commons.configuration.tree.UnionCombiner;
+import org.apache.commons.configuration.resolver.EntityRegistry;
+import org.apache.commons.configuration.resolver.CatalogResolver;
 import org.apache.commons.lang.text.StrLookup;
 import org.apache.commons.logging.LogFactory;
+import org.xml.sax.EntityResolver;
 
 /**
  * <p>
@@ -159,6 +162,16 @@
  * attribute of the result element.
  * </p>
  * <p>
+ * A custom EntityResolver can be used for all XMLConfigurations by adding
+ * <pre>
+ * &lt;entity-resolver config-class="EntityResolver fully qualified class name"&gt;
+ * </pre>
+ * The CatalogResolver can be used for all XMLConfiguration by adding
+ * <pre>
+ * &lt;entity-resolver catalogFiles="comma separated list of catalog files"&gt;
+ * </pre>
+ * </p>
+ * <p>
  * Additional ConfigurationProviders can be added by configuring them in the <em>header</em>
  * section.
  * <pre>
@@ -319,6 +332,11 @@
             + ".lookups.lookup";
 
     /**
+     * Constant for the key for defining entity resolvers
+     */
+    static final String KEY_ENTITY_RESOLVER = SEC_HEADER + ".entity-resolver";
+
+    /**
      * Constant for the prefix attribute for lookups.
      */
     static final String KEY_LOOKUP_KEY = XMLBeanDeclaration.ATTR_PREFIX + "prefix]";
@@ -549,6 +567,7 @@
         }
 
         initSystemProperties();
+        configureEntityResolver();
         registerConfiguredProviders();
         registerConfiguredLookups();
 
@@ -703,6 +722,15 @@
         }
     }
 
+    protected void configureEntityResolver() throws ConfigurationException
+    {
+        if (getMaxIndex(KEY_ENTITY_RESOLVER) == 0)
+        {
+            XMLBeanDeclaration decl = new XMLBeanDeclaration(this, KEY_ENTITY_RESOLVER, true);
+            setEntityResolver((EntityResolver) BeanHelper.createBean(decl, CatalogResolver.class));
+        }
+    }
+
     /**
      * Performs interpolation. This method will not only take this configuration
      * instance into account (which is the one that loaded the configuration
@@ -1382,11 +1410,19 @@
             XMLConfiguration config = (XMLConfiguration) super
                     .getEmptyConfiguration(decl);
 
-            // copy the registered entities
             DefaultConfigurationBuilder builder = decl
                     .getConfigurationBuilder();
-            config.getRegisteredEntities().putAll(
+            EntityResolver resolver = builder.getEntityResolver();
+            if (resolver instanceof EntityRegistry)
+            {
+                // copy the registered entities
+                config.getRegisteredEntities().putAll(
                     builder.getRegisteredEntities());
+            }
+            else
+            {
+                config.setEntityResolver(resolver);
+            }
             return config;
         }
     }

Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java?rev=729581&r1=729580&r2=729581&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java Fri Dec 26 18:27:49 2008
@@ -23,7 +23,6 @@
 import java.io.Reader;
 import java.io.Writer;
 import java.net.URL;
-import java.net.URLConnection;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -46,6 +45,8 @@
 import javax.xml.transform.stream.StreamResult;
 
 import org.apache.commons.configuration.tree.ConfigurationNode;
+import org.apache.commons.configuration.resolver.EntityRegistry;
+import org.apache.commons.configuration.resolver.DefaultEntityResolver;
 import org.w3c.dom.Attr;
 import org.w3c.dom.CDATASection;
 import org.w3c.dom.DOMException;
@@ -163,7 +164,7 @@
  * @version $Revision$, $Date$
  */
 public class XMLConfiguration extends AbstractHierarchicalFileConfiguration
-    implements EntityResolver
+    implements EntityResolver, EntityRegistry
 {
     /**
      * The serial version UID.
@@ -182,12 +183,17 @@
     /** Constant for the delimiter for multiple attribute values.*/
     private static final char ATTR_VALUE_DELIMITER = '|';
 
+    /** Schema Langauge key for the parser */
+    private static final String JAXP_SCHEMA_LANGUAGE =
+        "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
+
+    /** Schema Language for the parser */
+    private static final String W3C_XML_SCHEMA =
+        "http://www.w3.org/2001/XMLSchema";
+
     /** The document from this configuration's data source. */
     private Document document;
 
-    /** Stores a map with the registered public IDs.*/
-    private Map registeredEntities = new HashMap();
-
     /** Stores the name of the root element. */
     private String rootElementName;
 
@@ -200,12 +206,18 @@
     /** Stores the document builder that should be used for loading.*/
     private DocumentBuilder documentBuilder;
 
-    /** Stores a flag whether DTD validation should be performed.*/
+    /** Stores a flag whether DTD or Schema validation should be performed.*/
     private boolean validating;
 
+    /** Stores a flag whether DTD or Schema validation is used */
+    private boolean schemaValidation;
+
     /** A flag whether attribute splitting is disabled.*/
     private boolean attributeSplittingDisabled;
 
+    /** The EntityResolver to use */
+    private EntityResolver entityResolver = new DefaultEntityResolver();
+
     /**
      * Creates a new instance of <code>XMLConfiguration</code>.
      */
@@ -403,7 +415,7 @@
 
     /**
      * Sets the value of the validating flag. This flag determines whether
-     * DTD validation should be performed when loading XML documents. This
+     * DTD/Schema validation should be performed when loading XML documents. This
      * flag is evaluated only if no custom <code>DocumentBuilder</code> was set.
      *
      * @param validating the validating flag
@@ -411,7 +423,62 @@
      */
     public void setValidating(boolean validating)
     {
-        this.validating = validating;
+        if (!schemaValidation)
+        {
+            this.validating = validating;
+        }
+    }
+
+
+    /**
+     * Returns the value of the schemaValidation flag.
+     *
+     * @return the schemaValidation flag
+     * @since 1.7
+     */
+    public boolean isSchemaValidation()
+    {
+        return schemaValidation;
+    }
+
+    /**
+     * Sets the value of the schemaValidation flag. This flag determines whether
+     * DTD or Schema validation should be used. This
+     * flag is evaluated only if no custom <code>DocumentBuilder</code> was set.
+     * If set to true the XML document must contain a schemaLocation definition
+     * that provides resolvable hints to the required schemas.
+     *
+     * @param schemaValidation the validating flag
+     * @since 1.7
+     */
+    public void setSchemaValidation(boolean schemaValidation)
+    {
+        this.schemaValidation = schemaValidation;
+        if (schemaValidation)
+        {
+            this.validating = true;
+        }
+    }
+
+    /**
+     * Sets a new EntityResolver. Setting this will cause RegisterEntityId to have no
+     * effect.
+     * @param resolver The EntityResolver to use.
+     * @since 1.7
+     */
+    public void setEntityResolver(EntityResolver resolver)
+    {
+        this.entityResolver = resolver;
+    }
+
+    /**
+     * Returns the EntityResolver.
+     * @return The EntityResolver.
+     * @since 1.7
+     */
+    public EntityResolver getEntityResolver()
+    {
+        return this.entityResolver;
     }
 
     /**
@@ -716,9 +783,18 @@
         {
             DocumentBuilderFactory factory = DocumentBuilderFactory
                     .newInstance();
-            factory.setValidating(isValidating());
+            if (isValidating())
+            {
+                factory.setValidating(true);
+                if (isSchemaValidation())
+                {
+                    factory.setNamespaceAware(true);
+                    factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
+                }
+            }
+
             DocumentBuilder result = factory.newDocumentBuilder();
-            result.setEntityResolver(this);
+            result.setEntityResolver(this.entityResolver);
 
             if (isValidating())
             {
@@ -1054,11 +1130,10 @@
      */
     public void registerEntityId(String publicId, URL entityURL)
     {
-        if (publicId == null)
+        if (entityResolver instanceof EntityRegistry)
         {
-            throw new IllegalArgumentException("Public ID must not be null!");
+            ((EntityRegistry) entityResolver).registerEntityId(publicId, entityURL);
         }
-        getRegisteredEntities().put(publicId, entityURL);
     }
 
     /**
@@ -1072,39 +1147,18 @@
      * @return an input source for the specified entity
      * @throws SAXException if a parsing exception occurs
      * @since 1.5
+     * @deprecated Use getEntityResolver().resolveEntity()
      */
     public InputSource resolveEntity(String publicId, String systemId)
             throws SAXException
     {
-        // Has this system identifier been registered?
-        URL entityURL = null;
-        if (publicId != null)
-        {
-            entityURL = (URL) getRegisteredEntities().get(publicId);
-        }
-
-        if (entityURL != null)
+        try
         {
-            // Obtain an InputSource for this URL. This code is based on the
-            // createInputSourceFromURL() method of Commons Digester.
-            try
-            {
-                URLConnection connection = entityURL.openConnection();
-                connection.setUseCaches(false);
-                InputStream stream = connection.getInputStream();
-                InputSource source = new InputSource(stream);
-                source.setSystemId(entityURL.toExternalForm());
-                return source;
-            }
-            catch (IOException e)
-            {
-                throw new SAXException(e);
-            }
+            return entityResolver.resolveEntity(publicId, systemId);
         }
-        else
+        catch (IOException e)
         {
-            // default processing behavior
-            return null;
+            throw new SAXException(e);
         }
     }
 
@@ -1114,9 +1168,13 @@
      *
      * @return a map with the registered entity IDs
      */
-    Map getRegisteredEntities()
+    public Map getRegisteredEntities()
     {
-        return registeredEntities;
+        if (entityResolver instanceof EntityRegistry)
+        {
+            return ((EntityRegistry) entityResolver).getRegisteredEntities();
+        }
+        return new HashMap();
     }
 
     /**

Added: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/CatalogResolver.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/CatalogResolver.java?rev=729581&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/CatalogResolver.java (added)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/CatalogResolver.java Fri Dec 26 18:27:49 2008
@@ -0,0 +1,200 @@
+/*
+ * 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.configuration.resolver;
+
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.apache.xml.resolver.CatalogManager;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.impl.NoOpLog;
+
+import java.net.URL;
+import java.io.InputStream;
+
+/**
+ * Thin wrapper around xml commons CatalogResolver to allow list of catalogs
+ * to be provided.
+ * @author <a
+ * href="http://commons.apache.org/configuration/team-list.html">Commons
+ * Configuration team</a>
+ * @since 1.7
+ * @version $Id$
+ */
+public class CatalogResolver implements EntityResolver
+{
+    /**
+     * Debug everything.
+     */
+    private static final int DEBUG_ALL = 9;
+
+    /**
+     * Debug nothing.
+     */
+    private static final int DEBUG_NONE = 0;
+
+    /**
+     * The CatalogResolver
+     */
+    private org.apache.xml.resolver.tools.CatalogResolver resolver;
+
+    /**
+     * The CatalogManager
+     */
+    private CatalogManager manager = new CatalogManager();
+
+    /**
+     * Stores the logger.
+     */
+    private Log log;
+
+    /**
+     * Constructs the CatalogResolver
+     */
+    public CatalogResolver()
+    {
+        manager.setIgnoreMissingProperties(true);
+        setLogger(null);
+    }
+
+    /**
+     * Set the list of catalog file names
+     *
+     * @param catalogs The delimited list of catalog files.
+     */
+    public void setCatalogFiles(String catalogs)
+    {
+        manager.setCatalogFiles(catalogs);
+        resolver = new org.apache.xml.resolver.tools.CatalogResolver(manager);
+    }
+
+    /**
+     * Enables debug logging of xml-commons Catalog processing.
+     * @param debug True if debugging should be enabled, false otherwise.
+     */
+    public void setDebug(boolean debug)
+    {
+        if (debug)
+        {
+            manager.setVerbosity(DEBUG_ALL);
+        }
+        else
+        {
+            manager.setVerbosity(DEBUG_NONE);
+        }
+    }
+
+    /**
+     * Implements the <code>resolveEntity</code> method
+     * for the SAX interface.
+     * <p/>
+     * <p>Presented with an optional public identifier and a system
+     * identifier, this function attempts to locate a mapping in the
+     * catalogs.</p>
+     * <p/>
+     * <p>If such a mapping is found, the resolver attempts to open
+     * the mapped value as an InputSource and return it. Exceptions are
+     * ignored and null is returned if the mapped value cannot be opened
+     * as an input source.</p>
+     * <p/>
+     * <p>If no mapping is found (or an error occurs attempting to open
+     * the mapped value as an input source), null is returned and the system
+     * will use the specified system identifier as if no entityResolver
+     * was specified.</p>
+     *
+     * @param publicId The public identifier for the entity in question.
+     *                 This may be null.
+     * @param systemId The system identifier for the entity in question.
+     *                 XML requires a system identifier on all external entities, so this
+     *                 value is always specified.
+     * @return An InputSource for the mapped identifier, or null.
+     * @throws SAXException if an error occurs.
+     */
+    public InputSource resolveEntity(String publicId, String systemId)
+            throws SAXException
+    {
+        String resolved = resolver.getResolvedEntity(publicId, systemId);
+
+        if (resolved != null)
+        {
+            String badFilePrefix = "file://";
+            String correctFilePrefix = "file:///";
+
+            // Java 5 has a bug when constructing file URLS
+            if (resolved.startsWith(badFilePrefix) && !resolved.startsWith(correctFilePrefix))
+            {
+                resolved = correctFilePrefix + resolved.substring(badFilePrefix.length());
+            }
+
+            try
+            {
+                InputSource iSource = new InputSource(resolved);
+                iSource.setPublicId(publicId);
+
+                // Ideally this method would not attempt to open the
+                // InputStream, but there is a bug (in Xerces, at least)
+                // that causes the parser to mistakenly open the wrong
+                // system identifier if the returned InputSource does
+                // not have a byteStream.
+                //
+                // It could be argued that we still shouldn't do this here,
+                // but since the purpose of calling the entityResolver is
+                // almost certainly to open the input stream, it seems to
+                // do little harm.
+                //
+                URL url = new URL(resolved);
+                InputStream iStream = url.openStream();
+                iSource.setByteStream(iStream);
+
+                return iSource;
+            }
+            catch (Exception e)
+            {
+                log.debug("Failed to create InputSource for " + resolved + " ("
+                                + e.toString() + ")");
+                return null;
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * Returns the logger used by this configuration object.
+     *
+     * @return the logger
+     */
+    public Log getLogger()
+    {
+        return log;
+    }
+
+    /**
+     * Allows to set the logger to be used by this configuration object. This
+     * method makes it possible for clients to exactly control logging behavior.
+     * Per default a logger is set that will ignore all log messages. Derived
+     * classes that want to enable logging should call this method during their
+     * initialization with the logger to be used.
+     *
+     * @param log the new logger
+     */
+    public void setLogger(Log log)
+    {
+        this.log = (log != null) ? log : new NoOpLog();
+    }
+
+}

Propchange: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/CatalogResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/CatalogResolver.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/DefaultEntityResolver.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/DefaultEntityResolver.java?rev=729581&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/DefaultEntityResolver.java (added)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/DefaultEntityResolver.java Fri Dec 26 18:27:49 2008
@@ -0,0 +1,130 @@
+/*
+ * 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.configuration.resolver;
+
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.EntityResolver;
+
+import java.net.URL;
+import java.net.URLConnection;
+import java.io.InputStream;
+import java.io.IOException;
+import java.util.Map;
+import java.util.HashMap;
+
+/**
+ * The DefaultEntityResolver used by XML Configurations.
+ * @author <a
+ * href="http://commons.apache.org/configuration/team-list.html">Commons
+ * Configuration team</a>
+ * @since 1.7
+ * @version $Id$
+ */
+public class DefaultEntityResolver implements EntityResolver, EntityRegistry
+{
+    /** Stores a map with the registered public IDs.*/
+    private Map registeredEntities = new HashMap();
+
+    /**
+     * <p>
+     * Registers the specified URL for the specified public identifier.
+     * </p>
+     * <p>
+     * This implementation maps <code>PUBLICID</code>'s to URLs (from which
+     * the resource will be loaded). A common use case for this method is to
+     * register local URLs (possibly computed at runtime by a class loader) for
+     * DTDs and Schemas. This allows the performance advantage of using a local
+     * version without having to ensure every <code>SYSTEM</code> URI on every
+     * processed XML document is local. This implementation provides only basic
+     * functionality. If more sophisticated features are required, either calling
+     * <code>XMLConfiguration.setDocumentBuilder(DocumentBuilder)<code> to set a custom
+     * <code>DocumentBuilder</code> (which also can be initialized with a
+     * custom <code>EntityResolver</code>) or creating a custom entity resolver
+     * and registering it with the XMLConfiguration is recommended.
+     * </p>
+     *
+     * @param publicId Public identifier of the Entity to be resolved
+     * @param entityURL The URL to use for reading this Entity
+     * @throws IllegalArgumentException if the public ID is undefined
+     */
+    public void registerEntityId(String publicId, URL entityURL)
+    {
+        if (publicId == null)
+        {
+            throw new IllegalArgumentException("Public ID must not be null!");
+        }
+        getRegisteredEntities().put(publicId, entityURL);
+    }
+
+    /**
+     * Resolves the requested external entity. This is the default
+     * implementation of the <code>EntityResolver</code> interface. It checks
+     * the passed in public ID against the registered entity IDs and uses a
+     * local URL if possible.
+     *
+     * @param publicId the public identifier of the entity being referenced
+     * @param systemId the system identifier of the entity being referenced
+     * @return an input source for the specified entity
+     * @throws org.xml.sax.SAXException if a parsing exception occurs
+     */
+    public InputSource resolveEntity(String publicId, String systemId)
+            throws SAXException
+    {
+        // Has this system identifier been registered?
+        URL entityURL = null;
+        if (publicId != null)
+        {
+            entityURL = (URL) getRegisteredEntities().get(publicId);
+        }
+
+        if (entityURL != null)
+        {
+            // Obtain an InputSource for this URL. This code is based on the
+            // createInputSourceFromURL() method of Commons Digester.
+            try
+            {
+                URLConnection connection = entityURL.openConnection();
+                connection.setUseCaches(false);
+                InputStream stream = connection.getInputStream();
+                InputSource source = new InputSource(stream);
+                source.setSystemId(entityURL.toExternalForm());
+                return source;
+            }
+            catch (IOException e)
+            {
+                throw new SAXException(e);
+            }
+        }
+        else
+        {
+            // default processing behavior
+            return null;
+        }
+    }
+
+    /**
+     * Returns a map with the entity IDs that have been registered using the
+     * <code>registerEntityId()</code> method.
+     *
+     * @return a map with the registered entity IDs
+     */
+    public Map getRegisteredEntities()
+    {
+        return registeredEntities;
+    }
+}

Propchange: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/DefaultEntityResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/DefaultEntityResolver.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/EntityRegistry.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/EntityRegistry.java?rev=729581&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/EntityRegistry.java (added)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/EntityRegistry.java Fri Dec 26 18:27:49 2008
@@ -0,0 +1,63 @@
+/*
+ * 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.configuration.resolver;
+
+import java.net.URL;
+import java.util.Map;
+
+/**
+ * Interface used for registering and retrieving PUBLICID to URL mappings.
+ * @author <a
+ * href="http://commons.apache.org/configuration/team-list.html">Commons
+ * Configuration team</a>
+ * @since 1.7
+ * @version $Id$
+ */
+public interface EntityRegistry
+{
+    /**
+     * <p>
+     * Registers the specified URL for the specified public identifier.
+     * </p>
+     * <p>
+     * This implementation maps <code>PUBLICID</code>'s to URLs (from which
+     * the resource will be loaded). A common use case for this method is to
+     * register local URLs (possibly computed at runtime by a class loader) for
+     * DTDs and Schemas. This allows the performance advantage of using a local
+     * version without having to ensure every <code>SYSTEM</code> URI on every
+     * processed XML document is local. This implementation provides only basic
+     * functionality. If more sophisticated features are required, either calling
+     * <code>XMLConfiguration.setDocumentBuilder(DocumentBuilder)<code> to set a custom
+     * <code>DocumentBuilder</code> (which also can be initialized with a
+     * custom <code>EntityResolver</code>) or creating a custom entity resolver
+     * and registering it with the XMLConfiguration is recommended.
+     * </p>
+     *
+     * @param publicId Public identifier of the Entity to be resolved
+     * @param entityURL The URL to use for reading this Entity
+     * @throws IllegalArgumentException if the public ID is undefined
+     */
+    void registerEntityId(String publicId, URL entityURL);
+
+    /**
+     * Returns a map with the entity IDs that have been registered using the
+     * <code>registerEntityId()</code> method.
+     *
+     * @return a map with the registered entity IDs
+     */
+    Map getRegisteredEntities();
+}

Propchange: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/EntityRegistry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/EntityRegistry.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Added: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/package.html
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/package.html?rev=729581&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/package.html (added)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/resolver/package.html Fri Dec 26 18:27:49 2008
@@ -0,0 +1,31 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<!--
+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.
+-->
+<html>
+<head>
+</head>
+<body>
+
+<p>
+A package containing EntityResolvers.
+</p>
+<p>
+<font size="-2">$Id:  $</font>
+</p>
+
+</body>
+</html>
\ No newline at end of file

Modified: commons/proper/configuration/trunk/src/site/site.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/site/site.xml?rev=729581&r1=729580&r2=729581&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/site/site.xml (original)
+++ commons/proper/configuration/trunk/src/site/site.xml Fri Dec 26 18:27:49 2008
@@ -30,7 +30,7 @@
       <item name="User's Guide"                 href="/userguide/user_guide.html"/>
       <item name="Howtos (1.2 release)"         href="/userguide-1.2/index.html"/>
       <item name="Runtime Dependencies"         href="/dependencies.html"/>
-      <item name="Javadoc (1.4 release)"        href="/apidocs/index.html"/>
+      <item name="Javadoc (current)"            href="/apidocs/index.html"/>
       <item name="Javadoc (old releases)"       href="/javadoc.html"/>
     </menu>
 

Added: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestCatalogResolver.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestCatalogResolver.java?rev=729581&view=auto
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestCatalogResolver.java (added)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestCatalogResolver.java Fri Dec 26 18:27:49 2008
@@ -0,0 +1,111 @@
+/*
+ * 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.configuration;
+
+import junit.framework.TestCase;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.apache.commons.configuration.resolver.CatalogResolver;
+import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.Log;
+
+/**
+ *
+ */
+public class TestCatalogResolver extends TestCase
+{
+    private static final String CATALOG_FILES = "conf/catalog.xml";
+    private static final String PUBLIC_FILE = "conf/testResolver.xml";
+    private static final String REWRITE_SYSTEM_FILE = "conf/test.properties.xml";
+    private static final String REWRITE_SCHEMA_FILE = "conf/sample.xml";
+
+    private CatalogResolver resolver;
+    private XMLConfiguration config;
+
+    /**
+     * Create the test case
+     *
+     * @param testName name of the test case
+     */
+    public TestCatalogResolver(String testName)
+    {
+        super(testName);
+    }
+
+    /**
+     * @return the suite of tests being tested
+     */
+    public static Test suite()
+    {
+        return new TestSuite(TestCatalogResolver.class);
+    }
+
+    protected void setUp() throws Exception
+    {
+        resolver = new CatalogResolver();
+        resolver.setCatalogFiles(CATALOG_FILES);
+        // resolver.setDebug(true);
+        config = new XMLConfiguration();
+        config.setEntityResolver(resolver);
+    }
+
+    protected void tearDown() throws Exception
+    {
+        resolver = null;
+        config = null;
+    }
+
+    public void testPublic() throws Exception
+    {
+        config.setFileName(PUBLIC_FILE);
+        config.load();
+    }
+
+    public void testRewriteSystem() throws Exception
+    {
+        config.setFileName(REWRITE_SYSTEM_FILE);
+        config.load();
+    }
+
+    /**
+     * Tests that the schema can be resolved and that XMLConfiguration will
+     * validate the file using the schema.
+     * @throws Exception
+     */
+    public void testSchemaResolver() throws Exception
+    {
+        config.setFileName(REWRITE_SCHEMA_FILE);
+        config.setSchemaValidation(true);
+        config.load();
+    }
+
+    public void testDebug() throws Exception
+    {
+        resolver.setDebug(true);
+        // There is no really good way to check this except to do something
+        // that causes debug output.
+    }
+
+    public void testLogger() throws Exception
+    {
+        Log log = LogFactory.getLog(this.getClass());
+        resolver.setLogger(log);
+        assertNotNull("No Logger returned", resolver.getLogger());
+        assertTrue("Incorrect Logger", log == resolver.getLogger());
+    }
+
+}

Propchange: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestCatalogResolver.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestCatalogResolver.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestCatalogResolver.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDefaultConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDefaultConfigurationBuilder.java?rev=729581&r1=729580&r2=729581&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDefaultConfigurationBuilder.java (original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestDefaultConfigurationBuilder.java Fri Dec 26 18:27:49 2008
@@ -73,6 +73,9 @@
     private static final File SYSTEM_PROPS_FILE = new File(
             "conf/testSystemProperties.xml");
 
+    private static final File VALIDATION_FILE = new File(
+            "conf/testValidation.xml");
+
     /** Constant for the name of an optional configuration.*/
     private static final String OPTIONAL_NAME = "optionalConfig";
 
@@ -822,6 +825,16 @@
     }
 
 
+    public void testValidation() throws Exception
+    {
+        factory.setFile(VALIDATION_FILE);
+        CombinedConfiguration cc = factory.getConfiguration(true);
+        String value = System.getProperty("key1");
+        assertNotNull("The test key was not located", value);
+        assertEquals("Incorrect value retrieved","value1",value);
+    }
+
+
     /**
      * A specialized combined configuration implementation used for testing
      * custom result classes.

Modified: commons/proper/configuration/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/xdocs/changes.xml?rev=729581&r1=729580&r2=729581&view=diff
==============================================================================
--- commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ commons/proper/configuration/trunk/xdocs/changes.xml Fri Dec 26 18:27:49 2008
@@ -23,6 +23,12 @@
 
   <body>
     <release version="1.7" date="in SVN" description="">
+      <action dev="rgoers" type="add" issue="CONFIGURATION-257">
+        Allow configurations to be validated using XML Schemas.
+      </action>
+      <action dev="rgoers" type="add" issue="CONFIGURATION-355">
+        Allow configurations to be validated using XML Schemas.
+      </action>
     </release>
 
     <release version="1.6" date="2008-12-25"

Modified: commons/proper/configuration/trunk/xdocs/dependencies.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/xdocs/dependencies.xml?rev=729581&r1=729580&r2=729581&view=diff
==============================================================================
--- commons/proper/configuration/trunk/xdocs/dependencies.xml (original)
+++ commons/proper/configuration/trunk/xdocs/dependencies.xml Fri Dec 26 18:27:49 2008
@@ -80,6 +80,7 @@
                         <td>XMLPropertiesConfiguration</td>
                         <td>Java 1.4 or (xml-apis + xerces)</td>
                     </tr>
+
                     <tr>
                         <td>PropertyListConfiguration</td>
                         <td>commons-codec</td>
@@ -96,12 +97,16 @@
                         <td>commons-beanutils</td>
                     </tr>
                     <tr>
+                        <td>EnvironmentConfiguration</td>
+                        <td>Java 1.5 or ant 1.6.5</td>
+                    </tr>
+                    <tr>
                         <td>XPathExpressionEngine</td>
                         <td>commons-jxpath</td>
                     </tr>
                     <tr>
-                        <td>EnvironmentConfiguration</td>
-                        <td>Java 1.5 or ant 1.6.5</td>
+                        <td>CatalogResolver</td>
+                        <td>xml-resolver</td>
                     </tr>
                 </tbody>
             </table>
@@ -153,6 +158,10 @@
                       <td>commons-jxpath</td>
                       <td>1.2, 1.3</td>
                     </tr>
+                    <tr>
+                      <td>xml-resolver</td>
+                      <td>1.2</td>
+                    </tr>
                   </tbody>
                 </table>
                 </li>

Modified: commons/proper/configuration/trunk/xdocs/index.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/xdocs/index.xml?rev=729581&r1=729580&r2=729581&view=diff
==============================================================================
--- commons/proper/configuration/trunk/xdocs/index.xml (original)
+++ commons/proper/configuration/trunk/xdocs/index.xml Fri Dec 26 18:27:49 2008
@@ -23,6 +23,7 @@
     <author email="jason@zenplex.com">Jason van Zyl</author>
     <author email="epugh@upstate.com">Eric Pugh</author>
     <author email="tobrien@discursive.com">Tim O'Brien</author>
+    <author email="rgoers@apache.org">Ralph Goers</author>
     <title>Java Configuration API</title>
   </properties>
 

Modified: commons/proper/configuration/trunk/xdocs/userguide/howto_xml.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/xdocs/userguide/howto_xml.xml?rev=729581&r1=729580&r2=729581&view=diff
==============================================================================
--- commons/proper/configuration/trunk/xdocs/userguide/howto_xml.xml (original)
+++ commons/proper/configuration/trunk/xdocs/userguide/howto_xml.xml Fri Dec 26 18:27:49 2008
@@ -859,10 +859,11 @@
     <section name="Validation of XML configuration files">
         <p>
             XML parsers provide support for validation of XML documents to ensure that they
-            conform to a certain DTD. This feature can be useful for
-            configuration files, too. <code>XMLConfiguration</code> allows to enable
-            validation for the files to load.
+            conform to a certain DTD or XML Schema. This feature can be useful for
+            configuration files, too. <code>XMLConfiguration</code> allows this feature
+            to be enabled when files are loaded.
         </p>
+        <subsection name="Validation using a DTD">
         <p>
             The easiest way to turn on validation is to simply set the
             <code>validating</code> property to true as shown in the
@@ -883,6 +884,30 @@
             a custom <code>ErrorHandler</code> will be registered, which throws
             exceptions on simple and fatal parsing errors.
         </p>
+        </subsection>
+        <subsection name="Validation using a Schema">
+        <p>
+            XML Parsers also provide support for validating XML documents using an
+            XML Schema. XMLConfiguration provides a simple mechanism for enabling
+            this by setting the <code>schemaValidation</code> flag to true. This
+            will also set the <code>validating</code> flag to true so both do not
+            need to be set. The XML Parser will then use the schema defined in the
+            XML document to validate it. Enabling schema validation will also
+            enable the parser's namespace support.
+        </p>
+        <p>
+        <source><![CDATA[
+XMLConfiguration config = new XMLConfiguration();
+config.setFileName("myconfig.xml");
+config.setSchemaValidation(true);
+
+// This will throw a ConfigurationException if the XML document does not
+// conform to its Schema.
+config.load();
+]]></source>
+        </p>
+        </subsection>
+        <subsection name="Default Entity Resolution">
         <p>
             There is also some support for dealing with DTD files. Often the
             DTD of an XML document is stored locally so that it can be quickly
@@ -931,13 +956,71 @@
             configuration is loaded. So you cannot use one of the constructors
             that directly load the configuration.
         </p>
+        </subsection>
+        <subsection name="Enhanced Entity Resolution">
+        <p>
+            While the default entity resolver can be used under certain circumstances,
+            it does not work well when using the DefaultConfigurationBuilder.
+            Furthermore, in many circumstances the programmatic nature of
+            registering entities will tie the application tightly to the
+            XML content. In addition, because it only works with the public id it
+            cannot support XML documents using an XML Schema.
+        </p>
+        <p>
+            <a href="http://xml.apache.org/commons/components/resolver/resolver-article.html#s.whats.wrong">XML
+            Entity and URI Resolvers</a> describes using a set of catalog files to
+            resolve enitities. Commons Configuration provides support for
+            this Catalog Resolver through its own CatalogResolver class.
+        </p>
+         <source><![CDATA[
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<Employees xmlns="http://commons.apache.org/employee"
+           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+           xsi:schemaLocation="http://commons.apache.org/employee http://commons.apache.org/sample.xsd">
+  <Employee>
+    <SSN>555121211</SSN>
+    <Name>John Doe</Name>
+    <DateOfBirth>1975-05-15</DateOfBirth>
+    <EmployeeType>Exempt</EmployeeType>
+    <Salary>100000</Salary>
+  </Employee>
+</Employees>]]></source>
+        <p>
+            The XML sample above is an XML document using a default namespace of
+            http://commons.apache.org/employee. The schemaLocation allows a set
+            of namespaces and hints to the location of their corresponding
+            schemas. When processing the document the parser will pass the hint,
+            in this case http://commons.apache.org/sample.xsd, to the entity resolver
+            as the system id. More information on using schema locations can be found
+            at <a href="http://www.w3.org/TR/xmlschema-0/#schemaLocation">schemaLocation</a>.
+        </p>
+        <p>
+            The example that follows shows how to use the CatalogResolver when
+            processing an XMLConfiguration. It should be noted that by using the
+            setEntityResolver method any EntityResolver may be used, not just those
+            provided by Commons Configuration.
+        </p>
+        <source><![CDATA[
+CatalogResolver resolver = new CatalogResolver();
+resolver.setCatalogFiles("local/catalog.xml","http://test.org/catalogs/catalog1.xml");
+XMLConfiguration config = new XMLConfiguration();
+config.setEntityResolver(resolver);
+config.setSchemaValidation(true);  // enable schema validation
+config.setFileName("config.xml");
+config.load();
+]]></source>
+        </subsection>
+        <subsection name="Extending Validation and Entity Resolution">
         <p>
-            While using the <code>validating</code> flag is a simple means of
-            enabling validation it cannot fullfil more complex requirements,
-            e.g. schema validation. To be able to deal with such requirements
-            XMLConfiguration provides a generic way of setting up the XML
-            parser to use: A preconfigured <code>DocumentBuilder</code> object
-            can be passed to the <code>setDocumentBuilder()</code> method.
+            The mechanisms provided with Commons Configuration will hopefully be
+            sufficient in most cases, however there will certainly be circumstances
+            where they are not. XMLConfiguration provides two extension mechanisms
+            that should provide applications with all the flexibility they may
+            need. The first, registering a custom Entity Resolver has already been
+            discussed in the preceeding section. The second is that XMLConfiguration
+            provides a generic way of setting up the XML parser to use: A preconfigured
+            <code>DocumentBuilder</code> object can be passed to the
+            <code>setDocumentBuilder()</code> method.
         </p>
         <p>
             So an application can create a <code>DocumentBuilder</code> object
@@ -951,6 +1034,7 @@
             that the <code>registerEntityId()</code> method has no effect in
             this mode.
         </p>
+        </subsection>
     </section>
 </body>
 



Mime
View raw message