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 2013/07/07 18:51:05 UTC

svn commit: r1500482 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/XMLConfiguration.java test/java/org/apache/commons/configuration/TestXMLConfiguration.java

Author: oheger
Date: Sun Jul  7 16:51:05 2013
New Revision: 1500482

URL: http://svn.apache.org/r1500482
Log:
Integrated ListDelimiterHandler with XMLConfiguration.

Rather than calling static methods of PropertyConverter, the
ListDelimiterHandler is now used to escape and to split property values.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/XMLConfiguration.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/XMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/XMLConfiguration.java?rev=1500482&r1=1500481&r2=1500482&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/XMLConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/XMLConfiguration.java Sun Jul  7 16:51:05 2013
@@ -676,7 +676,7 @@ public class XMLConfiguration extends Ba
     {
         if (child.getValue() != null)
         {
-            List<String> values;
+            Collection<String> values;
             if (isDelimiterParsingDisabled())
             {
                 values = new ArrayList<String>();
@@ -684,8 +684,8 @@ public class XMLConfiguration extends Ba
             }
             else
             {
-                values = PropertyConverter.split(child.getValue().toString(),
-                    getListDelimiter(), trim);
+                values = getListDelimiterHandler().split(
+                            child.getValue().toString(), trim);
             }
 
             if (values.size() > 1)
@@ -720,7 +720,7 @@ public class XMLConfiguration extends Ba
             {
                 // we will have to replace the value because it might
                 // contain escaped delimiters
-                child.setValue(values.get(0));
+                child.setValue(values.iterator().next());
             }
         }
     }
@@ -822,8 +822,7 @@ public class XMLConfiguration extends Ba
                 document = newDocument;
             }
 
-            XMLBuilderVisitor builder = new XMLBuilderVisitor(document,
-                    isDelimiterParsingDisabled() ? (char) 0 : getListDelimiter());
+            XMLBuilderVisitor builder = new XMLBuilderVisitor(document, getListDelimiterHandler());
             builder.processDocument(getRootNode());
             initRootElementText(document, getRootNode().getValue());
             return document;
@@ -1309,10 +1308,11 @@ public class XMLConfiguration extends Ba
             }
             else
             {
+                String newValue =
+                        String.valueOf(getListDelimiterHandler().escape(value,
+                                ListDelimiterHandler.NOOP_TRANSFORMER));
                 if (txtNode == null)
                 {
-                    String newValue = isDelimiterParsingDisabled() ? value.toString()
-                        : PropertyConverter.escapeDelimiters(value.toString(), getListDelimiter());
                     txtNode = document.createTextNode(newValue);
                     if (((Element) getReference()).getFirstChild() != null)
                     {
@@ -1326,8 +1326,6 @@ public class XMLConfiguration extends Ba
                 }
                 else
                 {
-                    String newValue = isDelimiterParsingDisabled() ? value.toString()
-                        : PropertyConverter.escapeDelimiters(value.toString(), getListDelimiter());
                     txtNode.setNodeValue(newValue);
                 }
             }
@@ -1398,19 +1396,19 @@ public class XMLConfiguration extends Ba
         /** Stores the document to be constructed. */
         private Document document;
 
-        /** Stores the list delimiter.*/
-        private final char listDelimiter;
+        /** Stores the list delimiter handler .*/
+        private final ListDelimiterHandler listDelimiterHandler;
 
         /**
          * Creates a new instance of {@code XMLBuilderVisitor}.
          *
          * @param doc the document to be created
-         * @param listDelimiter the delimiter for attribute properties with multiple values
+         * @param handler the delimiter handler for properties with multiple values
          */
-        public XMLBuilderVisitor(Document doc, char listDelimiter)
+        public XMLBuilderVisitor(Document doc, ListDelimiterHandler handler)
         {
             document = doc;
-            this.listDelimiter = listDelimiter;
+            listDelimiterHandler = handler;
         }
 
         /**
@@ -1449,11 +1447,10 @@ public class XMLConfiguration extends Ba
                 Element elem = document.createElement(newNode.getName());
                 if (newNode.getValue() != null)
                 {
-                    String txt = newNode.getValue().toString();
-                    if (listDelimiter != 0)
-                    {
-                        txt = PropertyConverter.escapeListDelimiter(txt, listDelimiter);
-                    }
+                    String txt =
+                            String.valueOf(listDelimiterHandler.escape(
+                                    newNode.getValue(),
+                                    ListDelimiterHandler.NOOP_TRANSFORMER));
                     elem.appendChild(document.createTextNode(txt));
                 }
                 if (sibling2 == null)

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java?rev=1500482&r1=1500481&r2=1500482&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java Sun Jul  7 16:51:05 2013
@@ -1033,6 +1033,7 @@ public class TestXMLConfiguration
     public void testInitCopy() throws ConfigurationException
     {
         XMLConfiguration copy = new XMLConfiguration(conf);
+        copy.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
         assertEquals("value", copy.getProperty("element"));
         assertNull("Document was copied, too", copy.getDocument());
         ConfigurationNode root = copy.getRootNode();
@@ -1206,13 +1207,13 @@ public class TestXMLConfiguration
             throws ConfigurationException
     {
         conf.clear();
-        conf.setDelimiterParsingDisabled(true);
+        conf.setListDelimiterHandler(new DisabledListDelimiterHandler());
         load(conf, testProperties);
         conf.setProperty(key, "C:\\Temp\\,C:\\Data\\");
         conf.addProperty(key, "a,b,c");
         saveTestConfig();
         XMLConfiguration checkConf = new XMLConfiguration();
-        checkConf.setDelimiterParsingDisabled(true);
+        checkConf.setListDelimiterHandler(conf.getListDelimiterHandler());
         load(checkConf, testSaveConf.getAbsolutePath());
         ConfigurationAssert.assertEquals(conf, checkConf);
     }
@@ -1546,6 +1547,7 @@ public class TestXMLConfiguration
     public void testSaveWindowsPath() throws ConfigurationException
     {
         conf.clear();
+        conf.setListDelimiterHandler(new DisabledListDelimiterHandler());
         conf.addProperty("path", "C:\\Temp");
         StringWriter writer = new StringWriter();
         new FileHandler(conf).save(writer);