Return-Path: Delivered-To: apmail-commons-commits-archive@locus.apache.org Received: (qmail 62242 invoked from network); 23 Mar 2008 19:32:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 23 Mar 2008 19:32:16 -0000 Received: (qmail 42240 invoked by uid 500); 23 Mar 2008 19:32:13 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 42207 invoked by uid 500); 23 Mar 2008 19:32:13 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 42198 invoked by uid 99); 23 Mar 2008 19:32:13 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 23 Mar 2008 12:32:13 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 23 Mar 2008 19:31:31 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id D8B971A9832; Sun, 23 Mar 2008 12:31:50 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r640241 - in /commons/proper/configuration/branches/configuration2_experimental: src/main/java/org/apache/commons/configuration2/XMLConfiguration.java src/test/java/org/apache/commons/configuration2/TestXMLConfiguration.java xdocs/changes.xml Date: Sun, 23 Mar 2008 19:31:50 -0000 To: commits@commons.apache.org From: oheger@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080323193150.D8B971A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: oheger Date: Sun Mar 23 12:31:49 2008 New Revision: 640241 URL: http://svn.apache.org/viewvc?rev=640241&view=rev Log: CONFIGURATION-316: Applying changes to configuration2 branch Modified: 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 commons/proper/configuration/branches/configuration2_experimental/xdocs/changes.xml 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=640241&r1=640240&r2=640241&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 Sun Mar 23 12:31:49 2008 @@ -624,6 +624,7 @@ XMLBuilderVisitor builder = new XMLBuilderVisitor(document, isDelimiterParsingDisabled() ? (char) 0 : getListDelimiter()); visit(getRootNode(), builder); + initRootElementText(document, getRootNode().getValue()); return document; } catch (DOMException domEx) @@ -633,6 +634,34 @@ catch (ParserConfigurationException pex) { throw new ConfigurationException(pex); + } + } + + /** + * Sets the text of the root element of a newly created XML Document. + * + * @param doc the document + * @param value the new text to be set + */ + private void initRootElementText(Document doc, Object value) + { + Element elem = doc.getDocumentElement(); + NodeList children = elem.getChildNodes(); + + // Remove all existing text nodes + for (int i = 0; i < children.getLength(); i++) + { + org.w3c.dom.Node nd = children.item(i); + if (nd.getNodeType() == org.w3c.dom.Node.TEXT_NODE) + { + elem.removeChild(nd); + } + } + + if (value != null) + { + // Add a new text node + elem.appendChild(doc.createTextNode(String.valueOf(value))); } } 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=640241&r1=640240&r2=640241&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 Sun Mar 23 12:31:49 2008 @@ -1006,6 +1006,36 @@ } /** + * Tests setting text of the root element. + */ + public void testSetTextRootElement() throws ConfigurationException + { + conf.setProperty("", "Root text"); + conf.save(testSaveConf); + XMLConfiguration copy = new XMLConfiguration(); + copy.setFile(testSaveConf); + checkSavedConfig(copy); + } + + /** + * Tests removing the text of the root element. + */ + public void testClearTextRootElement() throws ConfigurationException + { + final String xml = "text"; + conf.clear(); + StringReader in = new StringReader(xml); + conf.load(in); + assertEquals("Wrong text of root", "text", conf.getString("")); + + conf.clearProperty(""); + conf.save(testSaveConf); + XMLConfiguration copy = new XMLConfiguration(); + copy.setFile(testSaveConf); + checkSavedConfig(copy); + } + + /** * Tests list nodes with multiple values and attributes. */ public void testListWithAttributes() Modified: commons/proper/configuration/branches/configuration2_experimental/xdocs/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/configuration2_experimental/xdocs/changes.xml?rev=640241&r1=640240&r2=640241&view=diff ============================================================================== --- commons/proper/configuration/branches/configuration2_experimental/xdocs/changes.xml (original) +++ commons/proper/configuration/branches/configuration2_experimental/xdocs/changes.xml Sun Mar 23 12:31:49 2008 @@ -66,6 +66,10 @@ + + Changing the text of the root element of an XMLConfiguration had no + effect when the configuration was saved. This has been fixed. + CombinedConfiguration used to send two EVENT_COMBINED_INVALIDATE events for each modified child configuration. Now this event is sent only