You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by oh...@apache.org on 2005/08/06 17:35:36 UTC

svn commit: r230551 - in /jakarta/commons/proper/configuration/trunk: conf/testDtd.xml src/java/org/apache/commons/configuration/XMLConfiguration.java src/test/org/apache/commons/configuration/TestXMLConfiguration.java xdocs/changes.xml

Author: oheger
Date: Sat Aug  6 08:35:14 2005
New Revision: 230551

URL: http://svn.apache.org/viewcvs?rev=230551&view=rev
Log:
Updated XMLConfiguration to set a valid system id in the InputSource used for loading files; corresponding test case

Added:
    jakarta/commons/proper/configuration/trunk/conf/testDtd.xml   (with props)
Modified:
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java
    jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
    jakarta/commons/proper/configuration/trunk/xdocs/changes.xml

Added: jakarta/commons/proper/configuration/trunk/conf/testDtd.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/conf/testDtd.xml?rev=230551&view=auto
==============================================================================
--- jakarta/commons/proper/configuration/trunk/conf/testDtd.xml (added)
+++ jakarta/commons/proper/configuration/trunk/conf/testDtd.xml Sat Aug  6 08:35:14 2005
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!-- Tests whether a DTD can be referenced when loaded from XMLConfiguration -->
+<!DOCTYPE properties SYSTEM "properties.dtd">
+<properties version="1.0">
+  <entry key="test1">value1</entry>
+  <entry key="test2">value2</entry>
+</properties>
\ No newline at end of file

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

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

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

Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java?rev=230551&r1=230550&r2=230551&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java Sat Aug  6 08:35:14 2005
@@ -51,13 +51,20 @@
 import org.apache.commons.configuration.reloading.ReloadingStrategy;
 
 /**
- * A specialized hierarchical configuration class that is able to parse XML
- * documents.
+ * <p>A specialized hierarchical configuration class that is able to parse XML
+ * documents.</p>
  * 
  * <p>The parsed document will be stored keeping its structure. The class also
  * tries to preserve as much information from the loaded XML document as
  * possible, including comments and processing instructions. These will be
- * contained in documents created by the <code>save()</code> methods, too.
+ * contained in documents created by the <code>save()</code> methods, too.</p>
+ * 
+ * <p>Like other file based configuration classes this class maintains the name
+ * and path to the loaded configuration file. These properties can be altered
+ * using several setter methods, but they are not modified by <code>save()</code>
+ * and <code>load()</code> methods. If XML documents contain relative paths to
+ * other documents (e.g. to a DTD), these references are resolved based on the
+ * path set for this configuration.</p>
  * 
  * @since commons-configuration 1.0
  * 
@@ -498,6 +505,12 @@
     {
         try
         {
+            URL sourceURL = delegate.getURL();
+            if (sourceURL != null)
+            {
+                source.setSystemId(sourceURL.toString());
+            }
+            
             DocumentBuilder builder = createDocumentBuilder();
             Document newDocument = builder.parse(source);
             Document oldDocument = document;

Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java?rev=230551&r1=230550&r2=230551&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java Sat Aug  6 08:35:14 2005
@@ -588,4 +588,14 @@
         assertEquals(2, conf.getMaxIndex("split.list1"));
         assertEquals("a,b,c", conf.getString("split.list2"));
     }
+    
+    /**
+     * Tests whether a DTD can be accessed.
+     */
+    public void testDtd() throws ConfigurationException
+    {
+        conf = new XMLConfiguration("testDtd.xml");
+        assertEquals("value1", conf.getString("entry(0)"));
+        assertEquals("test2", conf.getString("entry(1)[@key]"));
+    }
 }

Modified: jakarta/commons/proper/configuration/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/xdocs/changes.xml?rev=230551&r1=230550&r2=230551&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/configuration/trunk/xdocs/changes.xml Sat Aug  6 08:35:14 2005
@@ -23,6 +23,11 @@
   <body>
 
     <release version="1.2-dev" date="in SVN">
+      <action dev="oheger" type="add">
+        XMLConfiguration now sets a valid system id in the InputSource used for
+        loading files. This enables XML parsers to correctly resolve relative
+        files, e.g. DTDs.
+      </action>
       <action dev="ebourg" type="update" issue="35903">
         getKeys() in HierarchicalConfiguration now returns the keys in the same order the properties were inserted.
       </action>



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