You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by oh...@apache.org on 2011/04/20 22:14:30 UTC
svn commit: r1095501 - in
/commons/proper/configuration/branches/configuration2_experimental/src:
changes/changes.xml
main/java/org/apache/commons/configuration2/XMLConfiguration.java
test/java/org/apache/commons/configuration2/TestXMLConfiguration.java
Author: oheger
Date: Wed Apr 20 20:14:30 2011
New Revision: 1095501
URL: http://svn.apache.org/viewvc?rev=1095501&view=rev
Log:
[CONFIGURATION-446] Attributes whose value is an empty string are no more removed on saving the configuration. Ported fix to configuration2 branch.
Modified:
commons/proper/configuration/branches/configuration2_experimental/src/changes/changes.xml
commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java
commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java
Modified: commons/proper/configuration/branches/configuration2_experimental/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/changes/changes.xml?rev=1095501&r1=1095500&r2=1095501&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/changes/changes.xml (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/changes/changes.xml Wed Apr 20 20:14:30 2011
@@ -79,6 +79,10 @@
</release>
<release version="1.7" date="in SVN" description="">
+ <action dev="oheger" type="update" issue="CONFIGURATION-446">
+ XMLConfiguration now handles attributes correctly whose value is an
+ empty string.
+ </action>
<action dev="oheger" type="update" issue="CONFIGURATION-439">
Child configuration builders created for a <configuration> element
in a configuration definition file now inherit the configuration and
Modified: commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java?rev=1095501&r1=1095500&r2=1095501&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2/XMLConfiguration.java Wed Apr 20 20:14:30 2011
@@ -1494,6 +1494,7 @@ public class XMLConfiguration extends Ab
{
if (node != null && elem != null)
{
+ boolean hasAttribute = false;
List<ConfigurationNode> attributes = node.getAttributes(name);
StringBuilder buf = new StringBuilder();
char delimiter = (listDelimiter != 0) ? listDelimiter : ATTR_VALUE_DELIMITER;
@@ -1501,6 +1502,7 @@ public class XMLConfiguration extends Ab
{
if (attribute.getValue() != null)
{
+ hasAttribute = true;
if (buf.length() > 0)
{
buf.append(delimiter);
@@ -1513,7 +1515,7 @@ public class XMLConfiguration extends Ab
attribute.setReference(elem);
}
- if (buf.length() < 1)
+ if (!hasAttribute)
{
elem.removeAttribute(name);
}
Modified: commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java?rev=1095501&r1=1095500&r2=1095501&view=diff
==============================================================================
--- commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java (original)
+++ commons/proper/configuration/branches/configuration2_experimental/src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java Wed Apr 20 20:14:30 2011
@@ -1631,6 +1631,23 @@ public class TestXMLConfiguration extend
} */
/**
+ * Tests whether an attribute can be set to an empty string. This test is
+ * related to CONFIGURATION-446.
+ */
+ public void testEmptyAttribute() throws ConfigurationException
+ {
+ String key = "element3[@value]";
+ conf.setProperty(key, "");
+ assertTrue("Key not found", conf.containsKey(key));
+ assertEquals("Wrong value", "", conf.getString(key));
+ conf.save(testSaveConf);
+ conf = new XMLConfiguration();
+ conf.load(testSaveConf);
+ assertTrue("Key not found after save", conf.containsKey(key));
+ assertEquals("Wrong value after save", "", conf.getString(key));
+ }
+
+ /**
* Prepares a configuration object for testing a reload operation.
*
* @return the initialized configuration