Author: oheger
Date: Sat Jan 23 16:10:47 2010
New Revision: 902431
URL: http://svn.apache.org/viewvc?rev=902431&view=rev
Log:
[CONFIGURATION-403] Fixed XMLConfiguration.load() so that an empty
configuration that was saved and reloaded is still considered empty.
Modified:
commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java
commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
commons/proper/configuration/trunk/xdocs/changes.xml
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=902431&r1=902430&r2=902431&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
Sat Jan 23 16:10:47 2010
@@ -21,9 +21,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
-import java.io.Writer;
-import java.io.StringWriter;
import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.Writer;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
@@ -46,9 +46,9 @@
import javax.xml.transform.dom.DOMSource;
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.apache.commons.configuration.resolver.EntityRegistry;
+import org.apache.commons.configuration.tree.ConfigurationNode;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Attr;
import org.w3c.dom.CDATASection;
@@ -639,7 +639,7 @@
{
text = text.trim();
}
- if (text.length() > 0 || !node.hasChildren())
+ if (text.length() > 0 || (!node.hasChildren() && node != getRoot()))
{
node.setValue(text);
}
Modified:
commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java?rev=902431&r1=902430&r2=902431&view=diff
==============================================================================
---
commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
(original)
+++
commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
Sat Jan 23 16:10:47 2010
@@ -937,6 +937,18 @@
}
/**
+ * Tests the isEmpty() method for an empty configuration that was reloaded.
+ */
+ public void testEmptyReload() throws ConfigurationException
+ {
+ XMLConfiguration config = new XMLConfiguration();
+ assertTrue("Newly created configuration not empty", config.isEmpty());
+ config.save(testSaveConf);
+ config.load(testSaveConf);
+ assertTrue("Reloaded configuration not empty", config.isEmpty());
+ }
+
+ /**
* Tests whether the encoding is correctly detected by the XML parser. This
* is done by loading an XML file with the encoding "UTF-16". If this
* encoding is not detected correctly, an exception will be thrown that
Modified: commons/proper/configuration/trunk/xdocs/changes.xml
URL:
http://svn.apache.org/viewvc/commons/proper/configuration/trunk/xdocs/changes.xml?rev=902431&r1=902430&r2=902431&view=diff
==============================================================================
--- commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ commons/proper/configuration/trunk/xdocs/changes.xml Sat Jan 23 16:10:47
2010
@@ -23,6 +23,11 @@
<body>
<release version="1.7" date="in SVN" description="">
+ <action dev="oheger" type="fix" issue="CONFIGURATION-403">
+ When an empty XMLConfiguration was saved and reloaded the root element
+ was assigned an empty text value. Because of this isEmpty() returned
+ false for this configuration. This has been fixed.
+ </action>
<action dev="oheger" type="add" issue="CONFIGURATION-399">
Default variable interpolation now supports the env: prefix for
referencing environment variables.