commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r156237 - in jakarta/commons/proper/configuration/trunk: src/java/org/apache/commons/configuration/ src/test/org/apache/commons/configuration/ xdocs/
Date Sat, 05 Mar 2005 10:26:25 GMT
Author: oheger
Date: Sat Mar  5 02:26:22 2005
New Revision: 156237

URL: http://svn.apache.org/viewcvs?view=rev&rev=156237
Log:
Documentation update for FileConfiguration.load() methods, fix for a problem with XMLConfiguration
and loading multiple files

Modified:
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java
    jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java
    jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
    jakarta/commons/proper/configuration/trunk/xdocs/changes.xml

Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java?view=diff&r1=156236&r2=156237
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractFileConfiguration.java
Sat Mar  5 02:26:22 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright 2004 The Apache Software Foundation.
+ * Copyright 2004-2005 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.
@@ -54,6 +54,20 @@
  * directory or a URL. It can be set using the <code>setBasePath()</code>
  * method. The file name, non surprisingly, defines the name of the configuration
  * file.</li></ul></p>
+ * <p>Note that the <code>load()</code> methods do not wipe out the configuration's
+ * content before the new configuration file is loaded. Thus it is very easy to
+ * construct a union configuration by simply loading multiple configuration
+ * files, e.g.</p>
+ * <p><pre>
+ * config.load(configFile1);
+ * config.load(configFile2);
+ * </pre></p>
+ * <p>After executing this code fragment, the resulting configuration will
+ * contain both the properties of configFile1 and configFile2. On the other
+ * hand, if the current configuration file is to be reloaded, <code>clear()</code>
+ * should be called first. Otherwise the properties are doubled. This behavior
+ * is analogous to the behavior of the <code>load(InputStream)</code> method
+ * in <code>java.util.Properties</code>.</p>
  *
  * @author Emmanuel Bourg
  * @version $Revision$, $Date$

Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java?view=diff&r1=156236&r2=156237
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java
Sat Mar  5 02:26:22 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * Copyright 2001-2005 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.
@@ -262,8 +262,10 @@
     }
 
     /**
-     * Load the properties from the given input stream and using the specified
-     * encoding.
+     * Load the properties from the given reader.
+     * Note that the <code>clear()</code> method is not called, so
+     * the properties contained in the loaded file will be added to the
+     * actual set of properties.
      *
      * @param in An InputStream.
      *

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?view=diff&r1=156236&r2=156237
==============================================================================
--- 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 Mar  5 02:26:22 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright 2004 The Apache Software Foundation.
+ * Copyright 2004-2005 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.
@@ -228,10 +228,11 @@
      * Initializes this configuration from an XML document.
      * 
      * @param document the document to be parsed
+     * @param elemRefs a flag whether references to the XML elements should be set
      */
-    public void initProperties(Document document)
+    public void initProperties(Document document, boolean elemRefs)
     {
-        constructHierarchy(getRoot(), document.getDocumentElement());
+        constructHierarchy(getRoot(), document.getDocumentElement(), elemRefs);
     }
 
     /**
@@ -240,8 +241,9 @@
      * 
      * @param node the actual node
      * @param element the actual XML element
+     * @param elemRefs a flag whether references to the XML elements should be set
      */
-    private void constructHierarchy(Node node, Element element)
+    private void constructHierarchy(Node node, Element element, boolean elemRefs)
     {
         processAttributes(node, element);
         StringBuffer buffer = new StringBuffer();
@@ -252,8 +254,9 @@
             if (w3cNode instanceof Element)
             {
                 Element child = (Element) w3cNode;
-                Node childNode = new XMLNode(child.getTagName(), child);
-                constructHierarchy(childNode, child);
+                Node childNode = new XMLNode(child.getTagName(), 
+                        (elemRefs) ? child : null);
+                constructHierarchy(childNode, child, elemRefs);
                 node.addChild(childNode);
             }
             else if (w3cNode instanceof Text)
@@ -370,15 +373,26 @@
         delegate.load(in, encoding);
     }
 
+    /**
+     * Load the properties from the given reader.
+     * Note that the <code>clear()</code> method is not called, so
+     * the properties contained in the loaded file will be added to the
+     * actual set of properties.
+     *
+     * @param in An InputStream.
+     *
+     * @throws ConfigurationException
+     */
     public void load(Reader in) throws ConfigurationException
     {
         try
         {
             DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
             Document newDocument = builder.parse(new InputSource(in));
+            Document oldDocument = document;
             document = null;
-            initProperties(newDocument);
-            document = newDocument;
+            initProperties(newDocument, oldDocument == null);
+            document = (oldDocument == null) ? newDocument : oldDocument;
         }
         catch (Exception e)
         {

Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java?view=diff&r1=156236&r2=156237
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java
(original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java
Sat Mar  5 02:26:22 2005
@@ -1,7 +1,7 @@
 package org.apache.commons.configuration;
 
 /*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * Copyright 2001-2005 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.
@@ -48,6 +48,18 @@
     {
         String loaded = conf.getString("configuration.loaded");
         assertEquals("true", loaded);
+    }
+    
+    /**
+     * Tests if properties can be appended by simply calling load() another
+     * time.
+     */
+    public void testAppend() throws Exception
+    {
+        File file2 = new File("conf/threesome.properties");
+        conf.load(file2);
+        assertEquals("aaa", conf.getString("test.threesome.one"));
+        assertEquals("true", conf.getString("configuration.loaded"));
     }
 
     /**

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?view=diff&r1=156236&r2=156237
==============================================================================
--- 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 Mar  5 02:26:22 2005
@@ -1,5 +1,5 @@
 /*
- * Copyright 2001-2004 The Apache Software Foundation.
+ * Copyright 2001-2005 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.
@@ -32,6 +32,7 @@
 {
     /** The File that we test with */
     private String testProperties = new File("conf/test.xml").getAbsolutePath();
+    private String testProperties2 = new File("conf/testDigesterConfigurationInclude1.xml").getAbsolutePath();
     private String testBasePath = new File("conf").getAbsolutePath();
     private File testSaveConf = new File("target/testsave.xml");
 
@@ -387,5 +388,28 @@
         conf2 = new XMLConfiguration(conf.getFile());
         Configuration sub = conf2.subset("clear");
         assertTrue(sub.isEmpty());
+    }
+    
+    /**
+     * Tests if a second file can be appended to a first.
+     */
+    public void testAppend() throws Exception
+    {
+        conf = new XMLConfiguration();
+        conf.setFileName(testProperties);
+        conf.load();
+        conf.load(testProperties2);
+        assertEquals("value", conf.getString("element"));
+        assertEquals("tasks", conf.getString("table.name"));
+        
+        if (testSaveConf.exists())
+        {
+            assertTrue(testSaveConf.delete());
+        }
+        conf.save(testSaveConf);
+        
+        conf = new XMLConfiguration(testSaveConf);
+        assertEquals("value", conf.getString("element"));
+        assertEquals("tasks", conf.getString("table.name"));
     }
 }

Modified: jakarta/commons/proper/configuration/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/xdocs/changes.xml?view=diff&r1=156236&r2=156237
==============================================================================
--- jakarta/commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/configuration/trunk/xdocs/changes.xml Sat Mar  5 02:26:22 2005
@@ -1,4 +1,19 @@
 <?xml version="1.0"?>
+<!--
+   Copyright 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.
+-->
 <document>
   <properties>
     <title>Changes</title>
@@ -8,6 +23,11 @@
   <body>
 
     <release version="1.1-rc2" date="in CVS">
+      <action dev="oheger" type="update" issue="33814">
+        Updated documentation for FileConfiguration's load() methods. Fixed a
+        problem in XMLConfiguration with the output of the save() method when
+        multiple files were loaded.
+      </action>
       <action dev="ebourg" type="update">
         Fixed a bug in FileChangedReloadingStrategy preventing the detection
         of a file change in some cases.



---------------------------------------------------------------------
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