commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1502858 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/XMLConfiguration.java test/java/org/apache/commons/configuration/TestXMLConfiguration.java
Date Sat, 13 Jul 2013 19:35:47 GMT
Author: oheger
Date: Sat Jul 13 19:35:47 2013
New Revision: 1502858

URL: http://svn.apache.org/r1502858
Log:
Removed references to old list splitting properties form XMLConfiguration.

The Javadocs related to list splitting were adapted. In the test class,
unnecessary calls to disable delimiter parsing were removed.

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=1502858&r1=1502857&r2=1502858&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
Sat Jul 13 19:35:47 2013
@@ -113,27 +113,19 @@ import org.xml.sax.helpers.DefaultHandle
  * XMLConfiguration config = new XMLConfiguration();
  * config.addProperty("test.dir[@name]", "C:\\Temp\\");
  * config.addProperty("test.dir[@name]", "D:\\Data\\");
- * </pre></p>
- *
- * <p>Because in XML such a constellation is not directly supported (an attribute
- * can appear only once for a single element), the values are concatenated to a
- * single value. If delimiter parsing is enabled (refer to the
- * {@link #setDelimiterParsingDisabled(boolean)} method), the
- * current list delimiter character will be used as separator. Otherwise the
- * pipe symbol ("|") will be used for this purpose. No matter which character is
- * used as delimiter, it can always be escaped with a backslash. A backslash
- * itself can also be escaped with another backslash. Consider the following
- * example fragment from a configuration file:
- * <pre>
- * &lt;directories names="C:\Temp\\|D:\Data\"/&gt;
  * </pre>
- * Here the backslash after Temp is escaped. This is necessary because it
- * would escape the list delimiter (the pipe symbol assuming that list delimiter
- * parsing is disabled) otherwise. So this attribute would have two values.</p>
+ * However, in XML such a constellation is not supported; an attribute
+ * can appear only once for a single element. Therefore, an attempt to save
+ * a configuration which violates this condition will throw an exception.</p>
  *
- * <p>Note: You should ensure that the <em>delimiter parsing disabled</em>
- * property is always consistent when you load and save a configuration file.
- * Otherwise the values of properties can become corrupted.</p>
+ * <p>Like other {@code Configuration} implementations, {@code XMLConfiguration}
+ * uses a {@link ListDelimiterHandler} object for controlling list split
+ * operations. Per default, a list delimiter handler object is set which
+ * disables this feature. XML has a built-in support for complex structures
+ * including list properties; therefore, list splitting is not that relevant
+ * for this configuration type. Nevertheless, by setting an alternative
+ * {@code ListDelimiterHandler} implementation, this feature can be enabled.
+ * It works as for any other concrete {@code Configuration} implementation.</p>
  *
  * <p>Whitespace in the content of XML documents is trimmed per default. In most
  * cases this is desired. However, sometimes whitespace is indeed important and
@@ -676,17 +668,9 @@ public class XMLConfiguration extends Ba
     {
         if (child.getValue() != null)
         {
-            Collection<String> values;
-            if (isDelimiterParsingDisabled())
-            {
-                values = new ArrayList<String>();
-                values.add(child.getValue().toString());
-            }
-            else
-            {
-                values = getListDelimiterHandler().split(
+            Collection<String> values =
+                    getListDelimiterHandler().split(
                             child.getValue().toString(), trim);
-            }
 
             if (values.size() > 1)
             {

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=1502858&r1=1502857&r2=1502858&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
Sat Jul 13 19:35:47 2013
@@ -755,7 +755,6 @@ public class TestXMLConfiguration
     @Test
     public void testDelimiterParsingDisabled() throws ConfigurationException {
         XMLConfiguration conf2 = new XMLConfiguration();
-        conf2.setDelimiterParsingDisabled(true);
         load(conf2, testProperties);
 
         assertEquals("a,b,c", conf2.getString("split.list3[@values]"));
@@ -775,7 +774,6 @@ public class TestXMLConfiguration
     {
         XMLConfiguration conf2 = new XMLConfiguration();
         conf2.setExpressionEngine(new XPathExpressionEngine());
-        conf2.setDelimiterParsingDisabled(true);
         load(conf2, testProperties);
 
         assertEquals("a,b,c", conf2.getString("split/list3/@values"));
@@ -794,7 +792,6 @@ public class TestXMLConfiguration
     public void testSaveWithDelimiterParsingDisabled() throws ConfigurationException {
         conf = new XMLConfiguration();
         conf.setExpressionEngine(new XPathExpressionEngine());
-        conf.setDelimiterParsingDisabled(true);
         load(conf, testProperties);
 
         assertEquals("a,b,c", conf.getString("split/list3/@values"));
@@ -808,14 +805,12 @@ public class TestXMLConfiguration
 
         XMLConfiguration config = new XMLConfiguration();
         //config.setExpressionEngine(new XPathExpressionEngine());
-        config.setDelimiterParsingDisabled(true);
         load(config, testFile2);
         config.setProperty("Employee[@attr1]", "3,2,1");
         assertEquals("3,2,1", config.getString("Employee[@attr1]"));
         new FileHandler(config).save(testSaveFile);
         config = new XMLConfiguration();
         //config.setExpressionEngine(new XPathExpressionEngine());
-        config.setDelimiterParsingDisabled(true);
         load(config, testSaveFile.getAbsolutePath());
         config.setProperty("Employee[@attr1]", "1,2,3");
         assertEquals("1,2,3", config.getString("Employee[@attr1]"));
@@ -828,7 +823,6 @@ public class TestXMLConfiguration
         new FileHandler(config).save(testSaveFile);
         XMLConfiguration checkConfig = new XMLConfiguration();
         checkConfig.setExpressionEngine(new XPathExpressionEngine());
-        checkConfig.setDelimiterParsingDisabled(true);
         load(checkConfig, testSaveFile.getAbsolutePath());
         assertEquals("1,2,3", checkConfig.getString("Employee/@attr1"));
         assertEquals("one, two, three", checkConfig.getString("Employee/@attr2"));
@@ -1225,7 +1219,6 @@ public class TestXMLConfiguration
     public void testNoDelimiterParsingInAttrValues() throws ConfigurationException
     {
         conf.clear();
-        conf.setDelimiterParsingDisabled(true);
         load(conf, testProperties);
         List<Object> expr = conf.getList("expressions[@value]");
         assertEquals("Wrong list size", 1, expr.size());
@@ -1605,7 +1598,6 @@ public class TestXMLConfiguration
             throws ConfigurationException
     {
         String prop = "delimiterListProp";
-        conf.setDelimiterParsingDisabled(true);
         List<String> list = Arrays.asList("val", "val2", "val3");
         conf.setProperty(prop, list);
         saveTestConfig();
@@ -1623,7 +1615,7 @@ public class TestXMLConfiguration
             throws ConfigurationException
     {
         String prop = "delimiterListProp";
-        conf.setDelimiterParsingDisabled(true);
+        conf.setListDelimiterHandler(DisabledListDelimiterHandler.INSTANCE);
         List<String> list = Arrays.asList("val", "val2", "val3");
         conf.addProperty(prop, list);
         saveTestConfig();



Mime
View raw message