Return-Path: X-Original-To: apmail-commons-commits-archive@minotaur.apache.org Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E3F3E10527 for ; Mon, 21 Oct 2013 21:09:33 +0000 (UTC) Received: (qmail 75920 invoked by uid 500); 21 Oct 2013 21:07:43 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 75861 invoked by uid 500); 21 Oct 2013 21:07:41 -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 75852 invoked by uid 99); 21 Oct 2013 21:07:38 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Oct 2013 21:07:38 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Oct 2013 21:07:34 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 87BC123889ED; Mon, 21 Oct 2013 21:07:13 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1534371 - in /commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE: ./ src/changes/ src/main/java/org/apache/commons/configuration/ src/test/java/org/apache/commons/configuration/ src/test/resources/ Date: Mon, 21 Oct 2013 21:07:13 -0000 To: commits@commons.apache.org From: henning@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131021210713.87BC123889ED@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: henning Date: Mon Oct 21 21:07:12 2013 New Revision: 1534371 URL: http://svn.apache.org/r1534371 Log: Backport CONFIGURATION-555 from r1527396. Modified: commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/RELEASE-NOTES.txt commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/changes/changes.xml commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/main/java/org/apache/commons/configuration/XMLConfiguration.java commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/test/resources/test.xml Modified: commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/RELEASE-NOTES.txt URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/RELEASE-NOTES.txt?rev=1534371&r1=1534370&r2=1534371&view=diff ============================================================================== --- commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/RELEASE-NOTES.txt (original) +++ commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/RELEASE-NOTES.txt Mon Oct 21 21:07:12 2013 @@ -36,6 +36,12 @@ BUG FIXES IN 1.10 XMLConfiguration now adds attributes of elements defining a list to all list nodes. +* [CONFIGURATION-555] XMLConfiguration doesn't seem to be preserving whitespace + for the current node where xml:space="preserve" is set. + + Fixed a bug in the handling of the xml:space attribute in XMLConfiguration. + The attribute is now also applied to the current element, not only to sub elements. + * [CONFIGURATION-556] Regression with SystemProperties in 1.8 and 1.9 In 1.7 and before, any change to the system properties was immediately reflected in a Modified: commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/changes/changes.xml URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/changes/changes.xml?rev=1534371&r1=1534370&r2=1534371&view=diff ============================================================================== --- commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/changes/changes.xml (original) +++ commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/changes/changes.xml Mon Oct 21 21:07:12 2013 @@ -31,6 +31,11 @@ XMLConfiguration now adds attributes of elements defining a list to all list nodes. + + Fixed a bug in the handling of the xml:space attribute in + XMLConfiguration. The attribute is now also applied to the current + element, not only to sub elements. + In 1.7 and before, any change to the system properties was immediately reflected in a SystemConfiguration object. This Modified: commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/main/java/org/apache/commons/configuration/XMLConfiguration.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/main/java/org/apache/commons/configuration/XMLConfiguration.java?rev=1534371&r1=1534370&r2=1534371&view=diff ============================================================================== --- commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/main/java/org/apache/commons/configuration/XMLConfiguration.java (original) +++ commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/main/java/org/apache/commons/configuration/XMLConfiguration.java Mon Oct 21 21:07:12 2013 @@ -46,9 +46,11 @@ import javax.xml.transform.TransformerFa import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import org.apache.commons.collections.CollectionUtils; 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.lang.StringUtils; import org.apache.commons.logging.LogFactory; import org.w3c.dom.Attr; import org.w3c.dom.CDATASection; @@ -605,10 +607,13 @@ public class XMLConfiguration extends Ab * * @param node the actual node * @param element the actual XML element - * @param elemRefs a flag whether references to the XML elements should be set - * @param trim a flag whether the text content of elements should be trimmed; - * this controls the whitespace handling - * @return a map with all attribute values extracted for the current node + * @param elemRefs a flag whether references to the XML elements should be + * set + * @param trim a flag whether the text content of elements should be + * trimmed; this controls the whitespace handling + * @return a map with all attribute values extracted for the current node; + * this map also contains the value of the trim flag for this node + * under the key {@value #ATTR_SPACE} */ private Map> constructHierarchy(Node node, Element element, boolean elemRefs, boolean trim) @@ -616,6 +621,7 @@ public class XMLConfiguration extends Ab boolean trimFlag = shouldTrim(element, trim); Map> attributes = processAttributes(node, element, elemRefs); + attributes.put(ATTR_SPACE, Collections.singleton(String.valueOf(trimFlag))); StringBuilder buffer = new StringBuilder(); NodeList list = element.getChildNodes(); for (int i = 0; i < list.getLength(); i++) @@ -629,7 +635,9 @@ public class XMLConfiguration extends Ab Map> attrmap = constructHierarchy(childNode, child, elemRefs, trimFlag); node.addChild(childNode); - handleDelimiters(node, childNode, trimFlag, attrmap); + Collection attrSpace = attrmap.remove(ATTR_SPACE); + Boolean childTrim = CollectionUtils.isEmpty(attrSpace) ? Boolean.FALSE : Boolean.valueOf(attrSpace.iterator().next()); + handleDelimiters(node, childNode, childTrim.booleanValue(), attrmap); } else if (w3cNode instanceof Text) { @@ -638,11 +646,7 @@ public class XMLConfiguration extends Ab } } - String text = buffer.toString(); - if (trimFlag) - { - text = text.trim(); - } + String text = determineValue(node, buffer.toString(), trimFlag); if (text.length() > 0 || (!node.hasChildren() && node != getRoot())) { node.setValue(text); @@ -651,6 +655,28 @@ public class XMLConfiguration extends Ab } /** + * Determines the value of a configuration node. This method mainly checks + * whether the text value is to be trimmed or not. This is normally defined + * by the trim flag. However, if the node has children and its content is + * only whitespace, then it makes no sense to store any value; this would + * only scramble layout when the configuration is saved again. + * + * @param node the current {@code ConfigurationNode} + * @param content the text content of this node + * @param trimFlag the trim flag + * @return the value to be stored for this node + */ + private static String determineValue(ConfigurationNode node, + String content, boolean trimFlag) + { + boolean shouldTrim = + trimFlag + || (StringUtils.isBlank(content) && node + .getChildrenCount() > 0); + return shouldTrim ? content.trim() : content; + } + + /** * Helper method for constructing node objects for the attributes of the * given XML element. * @@ -663,15 +689,7 @@ public class XMLConfiguration extends Ab Element element, boolean elemRefs) { NamedNodeMap attributes = element.getAttributes(); - Map> attrmap; - if (attributes.getLength() > 0) - { - attrmap = new HashMap>(); - } - else - { - attrmap = Collections.emptyMap(); - } + Map> attrmap = new HashMap>(); for (int i = 0; i < attributes.getLength(); ++i) { Modified: commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java?rev=1534371&r1=1534370&r2=1534371&view=diff ============================================================================== --- commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java (original) +++ commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java Mon Oct 21 21:07:12 2013 @@ -1648,6 +1648,16 @@ public class TestXMLConfiguration } /** + * Tests whether the xml:space attribute works directly on the current + * element. This test is related to CONFIGURATION-555. + */ + @Test + public void testPreserveSpaceOnElement() + { + assertEquals("Wrong value", " preserved ", conf.getString("spaceElement")); + } + + /** * Tests whether the xml:space attribute can be overridden in nested * elements. */ Modified: commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/test/resources/test.xml URL: http://svn.apache.org/viewvc/commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/test/resources/test.xml?rev=1534371&r1=1534370&r2=1534371&view=diff ============================================================================== --- commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/test/resources/test.xml (original) +++ commons/proper/configuration/branches/CONFIGURATION_1_X_MAINTENANCE/src/test/resources/test.xml Mon Oct 21 21:07:12 2013 @@ -115,4 +115,5 @@ And even longer. Some text Some other text + preserved