Author: oheger Date: Wed Apr 13 11:53:10 2005 New Revision: 161196 URL: http://svn.apache.org/viewcvs?view=rev&rev=161196 Log: Fix for issue 34442: XMLConfiguration.save() won't forget attributes any more.
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 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=161195&r2=161196 ============================================================================== --- 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 Wed Apr 13 11:53:10 2005 @@ -213,6 +213,16 @@ } /** + * Removes all properties from this configuration. If this configuration + * was loaded from a file, the associated DOM document is also cleared. + */ + public void clear() + { + super.clear(); + document = null; + } + + /** * @inheritDoc */ public void setProperty(String key, Object value) @@ -242,7 +252,7 @@ */ private void constructHierarchy(Node node, Element element, boolean elemRefs) { - processAttributes(node, element); + processAttributes(node, element, elemRefs); StringBuffer buffer = new StringBuffer(); NodeList list = element.getChildNodes(); for (int i = 0; i < list.getLength(); i++) @@ -275,8 +285,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 processAttributes(Node node, Element element) + private void processAttributes(Node node, Element element, boolean elemRefs) { NamedNodeMap attributes = element.getAttributes(); for (int i = 0; i < attributes.getLength(); ++i) @@ -287,7 +298,8 @@ Attr attr = (Attr) w3cNode; for (Iterator it = PropertyConverter.split(attr.getValue(), getDelimiter()).iterator(); it.hasNext();) { - Node child = new XMLNode(ConfigurationKey.constructAttributeKey(attr.getName()), element); + Node child = new XMLNode(ConfigurationKey.constructAttributeKey(attr.getName()), + (elemRefs) ? element : null); child.setValue(it.next()); node.addChild(child); } 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=161195&r2=161196 ============================================================================== --- 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 Wed Apr 13 11:53:10 2005 @@ -411,5 +411,19 @@ conf = new XMLConfiguration(testSaveConf); assertEquals("value", conf.getString("element")); assertEquals("tasks", conf.getString("table.name")); + assertEquals("application", conf.getString("[EMAIL PROTECTED]")); + } + + /** + * Tests saving attributes (related to issue 34442). + */ + public void testSaveAttributes() throws Exception + { + conf.clear(); + conf.load(); + conf.save(testSaveConf); + conf = new XMLConfiguration(); + conf.load(testSaveConf); + assertEquals("foo", conf.getString("[EMAIL PROTECTED]")); } } 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=161195&r2=161196 ============================================================================== --- jakarta/commons/proper/configuration/trunk/xdocs/changes.xml (original) +++ jakarta/commons/proper/configuration/trunk/xdocs/changes.xml Wed Apr 13 11:53:10 2005 @@ -23,6 +23,11 @@ <body> <release version="1.2-dev" date="in SVN"> + <action dev="oheger" type="update" due-to="Mi Zhang" issue="34442"> + Fixed a bug which causes XMLConfiguration.save to lose attribute values + under some circumstances. The clear() method now also ensures that the + associated DOM document is always cleared. + </action> <action dev="ebourg" type="update" due-to="Kunihara Tetsuya" issue="34204"> XMLConfiguration now parse the configuration using the encoding declared in the XML header instead of the OS default encoding. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]