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 2012/09/15 21:38:11 UTC
svn commit: r1385157 - in /commons/proper/configuration/trunk/src: changes/
main/java/org/apache/commons/configuration/
test/java/org/apache/commons/configuration/ test/resources/
Author: oheger
Date: Sat Sep 15 19:38:11 2012
New Revision: 1385157
URL: http://svn.apache.org/viewvc?rev=1385157&view=rev
Log:
[CONFIGURATION-505] Removed support for splitting attribute values in XMLConfiguration.
Modified:
commons/proper/configuration/trunk/src/changes/changes.xml
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DefaultConfigurationBuilder.java
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/MultiFileHierarchicalConfiguration.java
commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/XMLConfiguration.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestDefaultConfigurationBuilder.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestHierarchicalXMLConfiguration.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestMultiFileHierarchicalConfiguration.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestVFSConfigurationBuilder.java
commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestXMLConfiguration.java
commons/proper/configuration/trunk/src/test/resources/test.xml
Modified: commons/proper/configuration/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/changes/changes.xml?rev=1385157&r1=1385156&r2=1385157&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/changes/changes.xml (original)
+++ commons/proper/configuration/trunk/src/changes/changes.xml Sat Sep 15 19:38:11 2012
@@ -27,6 +27,11 @@
<body>
<release version="2.0" date="in SVN"
description="TBD">
+ <action dev="oheger" type="update" issue="CONFIGURATION-505">
+ XMLConfiguration no longer supports attributes with multiple values or
+ list delimiter parsing in attributes. This feature was complex and
+ error prone and brought little value to the user.
+ </action>
<action dev="oheger" type="update" issue="CONFIGURATION-500">
XMLConfiguration now adds attributes of elements defining a list to
all list nodes.
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DefaultConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DefaultConfigurationBuilder.java?rev=1385157&r1=1385156&r2=1385157&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DefaultConfigurationBuilder.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/DefaultConfigurationBuilder.java Sat Sep 15 19:38:11 2012
@@ -1776,8 +1776,6 @@ public class DefaultConfigurationBuilder
DefaultConfigurationBuilder parent,
DefaultConfigurationBuilder child)
{
- child.setAttributeSplittingDisabled(parent
- .isAttributeSplittingDisabled());
child.setBasePath(parent.getBasePath());
child.setDelimiterParsingDisabled(parent
.isDelimiterParsingDisabled());
Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/MultiFileHierarchicalConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/MultiFileHierarchicalConfiguration.java?rev=1385157&r1=1385156&r2=1385157&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/MultiFileHierarchicalConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/MultiFileHierarchicalConfiguration.java Sat Sep 15 19:38:11 2012
@@ -810,7 +810,6 @@ public class MultiFileHierarchicalConfig
configuration.setReloadingStrategy(strategy);
}
configuration.setDelimiterParsingDisabled(isDelimiterParsingDisabled());
- configuration.setAttributeSplittingDisabled(isAttributeSplittingDisabled());
configuration.setValidating(validating);
configuration.setSchemaValidation(schemaValidation);
configuration.setEntityResolver(entityResolver);
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=1385157&r1=1385156&r2=1385157&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 Sep 15 19:38:11 2012
@@ -182,9 +182,6 @@ public class XMLConfiguration extends Ab
/** Constant for the xml:space value for preserving whitespace.*/
private static final String VALUE_PRESERVE = "preserve";
- /** Constant for the delimiter for multiple attribute values.*/
- private static final char ATTR_VALUE_DELIMITER = '|';
-
/** Schema Langauge key for the parser */
private static final String JAXP_SCHEMA_LANGUAGE =
"http://java.sun.com/xml/jaxp/properties/schemaLanguage";
@@ -214,9 +211,6 @@ public class XMLConfiguration extends Ab
/** Stores a flag whether DTD or Schema validation is used */
private boolean schemaValidation;
- /** A flag whether attribute splitting is disabled.*/
- private boolean attributeSplittingDisabled;
-
/** The EntityResolver to use */
private EntityResolver entityResolver = new DefaultEntityResolver();
@@ -489,71 +483,6 @@ public class XMLConfiguration extends Ab
}
/**
- * Returns the flag whether attribute splitting is disabled.
- *
- * @return the flag whether attribute splitting is disabled
- * @see #setAttributeSplittingDisabled(boolean)
- * @since 1.6
- */
- public boolean isAttributeSplittingDisabled()
- {
- return attributeSplittingDisabled;
- }
-
- /**
- * <p>
- * Sets a flag whether attribute splitting is disabled.
- * </p>
- * <p>
- * The Configuration API allows adding multiple values to an attribute. This
- * is problematic when storing the configuration because in XML an attribute
- * can appear only once with a single value. To solve this problem, per
- * default multiple attribute values are concatenated using a special
- * separator character and split again when the configuration is loaded. The
- * separator character is either the list delimiter character (see
- * {@link #setListDelimiter(char)}) or the pipe symbol ("|") if
- * list delimiter parsing is disabled.
- * </p>
- * <p>
- * In some constellations the splitting of attribute values can have
- * undesired effects, especially if list delimiter parsing is disabled and
- * attributes may contain the "|" character. In these cases it is
- * possible to disable the attribute splitting mechanism by calling this
- * method with a boolean value set to <b>false</b>. If attribute splitting
- * is disabled, the values of attributes will not be processed, but stored
- * as configuration properties exactly as they are returned by the XML
- * parser.
- * </p>
- * <p>
- * Note that in this mode multiple attribute values cannot be handled
- * correctly. It is possible to create a {@code XMLConfiguration}
- * object, add multiple values to an attribute and save it. When the
- * configuration is loaded again and attribute splitting is disabled, the
- * attribute will only have a single value, which is the concatenation of
- * all values set before. So it lies in the responsibility of the
- * application to carefully set the values of attributes.
- * </p>
- * <p>
- * As is true for the {@link #setDelimiterParsingDisabled(boolean)} method,
- * this method must be called before the configuration is loaded. So it
- * can't be used together with one of the constructors expecting the
- * specification of the file to load. Instead the default constructor has to
- * be used, then {@code setAttributeSplittingDisabled(false)} has to be
- * called, and finally the configuration can be loaded using one of its
- * {@code load()} methods.
- * </p>
- *
- * @param attributeSplittingDisabled <b>true</b> for disabling attribute
- * splitting, <b>false</b> for enabling it
- * @see #setDelimiterParsingDisabled(boolean)
- * @since 1.6
- */
- public void setAttributeSplittingDisabled(boolean attributeSplittingDisabled)
- {
- this.attributeSplittingDisabled = attributeSplittingDisabled;
- }
-
- /**
* Returns the XML document this configuration was loaded from. The return
* value is <b>null</b> if this configuration was not loaded from a XML
* document.
@@ -610,11 +539,11 @@ public class XMLConfiguration extends Ab
* this controls the whitespace handling
* @return a map with all attribute values extracted for the current node
*/
- private Map<String, Collection<String>> constructHierarchy(Node node,
+ private Map<String, String> constructHierarchy(Node node,
Element element, boolean elemRefs, boolean trim)
{
boolean trimFlag = shouldTrim(element, trim);
- Map<String, Collection<String>> attributes =
+ Map<String, String> attributes =
processAttributes(node, element, elemRefs);
StringBuilder buffer = new StringBuilder();
NodeList list = element.getChildNodes();
@@ -626,7 +555,7 @@ public class XMLConfiguration extends Ab
Element child = (Element) w3cNode;
Node childNode = new XMLNode(child.getTagName(),
elemRefs ? child : null);
- Map<String, Collection<String>> attrmap =
+ Map<String, String> attrmap =
constructHierarchy(childNode, child, elemRefs, trimFlag);
node.addChild(childNode);
handleDelimiters(node, childNode, trimFlag, attrmap);
@@ -659,14 +588,14 @@ public class XMLConfiguration extends Ab
* @param elemRefs a flag whether references to the XML elements should be set
* @return a map with all attribute values extracted for the current node
*/
- private Map<String, Collection<String>> processAttributes(Node node,
+ private Map<String, String> processAttributes(Node node,
Element element, boolean elemRefs)
{
NamedNodeMap attributes = element.getAttributes();
- Map<String, Collection<String>> attrmap;
+ Map<String, String> attrmap;
if (attributes.getLength() > 0)
{
- attrmap = new HashMap<String, Collection<String>>();
+ attrmap = new HashMap<String, String>();
}
else
{
@@ -679,20 +608,8 @@ public class XMLConfiguration extends Ab
if (w3cNode instanceof Attr)
{
Attr attr = (Attr) w3cNode;
- List<String> values;
- if (isAttributeSplittingDisabled())
- {
- values = Collections.singletonList(attr.getValue());
- }
- else
- {
- values = PropertyConverter.split(attr.getValue(),
- isDelimiterParsingDisabled() ? ATTR_VALUE_DELIMITER
- : getListDelimiter());
- }
-
- appendAttributes(node, element, elemRefs, attr.getName(), values);
- attrmap.put(attr.getName(), values);
+ appendAttribute(node, element, elemRefs, attr.getName(), attr.getValue());
+ attrmap.put(attr.getName(), attr.getValue());
}
}
@@ -700,23 +617,21 @@ public class XMLConfiguration extends Ab
}
/**
- * Adds attribute nodes to the given node. For each attribute value, a new
+ * Adds an attribute node to the given node. Attributes are represented
+ * as configuration nodes like child nodes. For each attribute value, a new
* attribute node is created and added as child to the current node.
*
* @param node the current node
* @param element the corresponding XML element
* @param attr the name of the attribute
- * @param values the attribute values
+ * @param value the attribute value
*/
- private void appendAttributes(Node node, Element element, boolean elemRefs,
- String attr, Collection<String> values)
+ private void appendAttribute(Node node, Element element, boolean elemRefs,
+ String attr, String value)
{
- for (String value : values)
- {
- Node child = new XMLNode(attr, elemRefs ? element : null);
- child.setValue(value);
- node.addAttribute(child);
- }
+ Node child = new XMLNode(attr, elemRefs ? element : null);
+ child.setValue(value);
+ node.addAttribute(child);
}
/**
@@ -729,7 +644,7 @@ public class XMLConfiguration extends Ab
* @param attrmap a map with the attributes of the current node
*/
private void handleDelimiters(Node parent, Node child, boolean trim,
- Map<String, Collection<String>> attrmap)
+ Map<String, String> attrmap)
{
if (child.getValue() != null)
{
@@ -765,10 +680,9 @@ public class XMLConfiguration extends Ab
{
c = new XMLNode(child.getName(), null);
c.setValue(it.next());
- for (Map.Entry<String, Collection<String>> e : attrmap
- .entrySet())
+ for (Map.Entry<String, String> e : attrmap.entrySet())
{
- appendAttributes(c, null, false, e.getKey(),
+ appendAttribute(c, null, false, e.getKey(),
e.getValue());
}
parent.addChild(c);
@@ -881,8 +795,7 @@ public class XMLConfiguration extends Ab
}
XMLBuilderVisitor builder = new XMLBuilderVisitor(document,
- isDelimiterParsingDisabled() ? (char) 0 : getListDelimiter(),
- isAttributeSplittingDisabled());
+ isDelimiterParsingDisabled() ? (char) 0 : getListDelimiter());
builder.processDocument(getRoot());
initRootElementText(document, getRootNode().getValue());
return document;
@@ -1392,8 +1305,7 @@ public class XMLConfiguration extends Ab
*/
private void updateAttribute()
{
- XMLBuilderVisitor.updateAttribute(getParent(), getName(), getListDelimiter(),
- isAttributeSplittingDisabled());
+ XMLBuilderVisitor.updateAttribute(getParent(), getName());
}
/**
@@ -1455,21 +1367,16 @@ public class XMLConfiguration extends Ab
/** Stores the list delimiter.*/
private final char listDelimiter;
- /** True if attributes should not be split */
- private boolean isAttributeSplittingDisabled;
-
/**
* 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 isAttributeSplittingDisabled true if attribute splitting is disabled.
*/
- public XMLBuilderVisitor(Document doc, char listDelimiter, boolean isAttributeSplittingDisabled)
+ public XMLBuilderVisitor(Document doc, char listDelimiter)
{
document = doc;
this.listDelimiter = listDelimiter;
- this.isAttributeSplittingDisabled = isAttributeSplittingDisabled;
}
/**
@@ -1497,8 +1404,7 @@ public class XMLConfiguration extends Ab
{
if (newNode.isAttribute())
{
- updateAttribute(parent, getElement(parent), newNode.getName(), listDelimiter,
- isAttributeSplittingDisabled);
+ updateAttribute(parent, getElement(parent), newNode.getName());
return null;
}
@@ -1537,44 +1443,56 @@ public class XMLConfiguration extends Ab
* @param node the affected node
* @param elem the element that is associated with this node
* @param name the name of the affected attribute
- * @param listDelimiter the delimiter for attributes with multiple values
- * @param isAttributeSplittingDisabled true if attribute splitting is disabled.
*/
- private static void updateAttribute(Node node, Element elem, String name, char listDelimiter,
- boolean isAttributeSplittingDisabled)
+ private static void updateAttribute(Node node, Element elem, String name)
{
if (node != null && elem != null)
{
- boolean hasAttribute = false;
- List<ConfigurationNode> attrs = node.getAttributes(name);
- StringBuilder buf = new StringBuilder();
- char delimiter = (listDelimiter != 0) ? listDelimiter : ATTR_VALUE_DELIMITER;
- for (ConfigurationNode attr : attrs)
+ List<ConfigurationNode> definedAttrs =
+ fetchDefinedAttributes(node.getAttributes(name));
+
+ if (!definedAttrs.isEmpty())
{
- if (attr.getValue() != null)
+ if (definedAttrs.size() > 1)
{
- hasAttribute = true;
- if (buf.length() > 0)
- {
- buf.append(delimiter);
- }
- String value = isAttributeSplittingDisabled ? attr.getValue().toString()
- : PropertyConverter.escapeDelimiters(attr.getValue().toString(),
- delimiter);
- buf.append(value);
+ throw new ConfigurationRuntimeException(
+ "Multiple values for attribute '" + name
+ + "' are not supported!");
}
- attr.setReference(elem);
+ ConfigurationNode attr = definedAttrs.get(0);
+ elem.setAttribute(name, attr.getValue().toString());
}
-
- if (!hasAttribute)
+ else
{
elem.removeAttribute(name);
}
- else
+ }
+ }
+
+ /**
+ * Returns a list containing only attribute nodes with a defined value.
+ *
+ * @param attrs the list with all attributes
+ * @return a list with the defined attributes
+ */
+ private static List<ConfigurationNode> fetchDefinedAttributes(
+ List<ConfigurationNode> attrs)
+ {
+ if (attrs.isEmpty())
+ {
+ return attrs;
+ }
+
+ List<ConfigurationNode> definedAttrs =
+ new ArrayList<ConfigurationNode>(attrs.size());
+ for (ConfigurationNode attr : attrs)
+ {
+ if (attr.getValue() != null)
{
- elem.setAttribute(name, buf.toString());
+ definedAttrs.add(attr);
}
}
+ return definedAttrs;
}
/**
@@ -1584,16 +1502,12 @@ public class XMLConfiguration extends Ab
*
* @param node the affected node
* @param name the name of the attribute
- * @param listDelimiter the delimiter for attributes with multiple values
- * @param isAttributeSplittingDisabled true if attributes splitting is disabled.
*/
- static void updateAttribute(Node node, String name, char listDelimiter,
- boolean isAttributeSplittingDisabled)
+ static void updateAttribute(Node node, String name)
{
if (node != null)
{
- updateAttribute(node, (Element) node.getReference(), name, listDelimiter,
- isAttributeSplittingDisabled);
+ updateAttribute(node, (Element) node.getReference(), name);
}
}
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestDefaultConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestDefaultConfigurationBuilder.java?rev=1385157&r1=1385156&r2=1385157&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestDefaultConfigurationBuilder.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestDefaultConfigurationBuilder.java Sat Sep 15 19:38:11 2012
@@ -43,7 +43,6 @@ import org.apache.commons.configuration.
import org.apache.commons.configuration.tree.ConfigurationNode;
import org.apache.commons.configuration.tree.DefaultConfigurationNode;
import org.apache.commons.configuration.tree.xpath.XPathExpressionEngine;
-import org.apache.commons.lang.SystemUtils;
import org.apache.commons.lang.text.StrLookup;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -851,7 +850,6 @@ public class TestDefaultConfigurationBui
factory.addProperty("override.configuration[@fileName]",
TEST_FILE.getAbsolutePath());
factory.setBasePath("conf");
- factory.setAttributeSplittingDisabled(true);
factory.setDelimiterParsingDisabled(true);
factory.setListDelimiter('/');
factory.setThrowExceptionOnMissing(true);
@@ -873,9 +871,6 @@ public class TestDefaultConfigurationBui
provider.fetchConfigurationClass(), decl, null);
assertEquals("Wrong base path", factory.getBasePath(),
child.getBasePath());
- assertEquals("Wrong attribute splitting flag",
- factory.isAttributeSplittingDisabled(),
- child.isAttributeSplittingDisabled());
assertEquals("Wrong delimiter parsing flag",
factory.isDelimiterParsingDisabled(),
child.isDelimiterParsingDisabled());
@@ -1171,19 +1166,15 @@ public class TestDefaultConfigurationBui
@Test
public void testExpression() throws Exception
{
- if (SystemUtils.isJavaVersionAtLeast(150))
- {
- factory.setFile(EXPRESSION_FILE);
- factory.setAttributeSplittingDisabled(true);
- System.getProperties().remove("Id");
- org.slf4j.MDC.clear();
-
- CombinedConfiguration config = factory.getConfiguration(true);
- assertTrue("Incorrect configuration",
- config instanceof DynamicCombinedConfiguration);
+ factory.setFile(EXPRESSION_FILE);
+ System.getProperties().remove("Id");
+ org.slf4j.MDC.clear();
- verify("1001", config, 15);
- }
+ CombinedConfiguration config = factory.getConfiguration(true);
+ assertTrue("Incorrect configuration",
+ config instanceof DynamicCombinedConfiguration);
+
+ verify("1001", config, 15);
}
/**
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestHierarchicalXMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestHierarchicalXMLConfiguration.java?rev=1385157&r1=1385156&r2=1385157&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestHierarchicalXMLConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestHierarchicalXMLConfiguration.java Sat Sep 15 19:38:11 2012
@@ -250,7 +250,7 @@ public class TestHierarchicalXMLConfigur
config.setProperty("clear", "yes");
config.setProperty("mean", "now it's simple");
config.addProperty("[@topattr]", "available");
- config.addProperty("[@topattr]", "successfull");
+ config.addProperty("[@topattr_other]", "successfull");
File saveFile = folder.newFile(TEST_SAVENAME);
config.save(saveFile);
@@ -267,7 +267,7 @@ public class TestHierarchicalXMLConfigur
assertEquals("yes", config.getProperty("clear"));
assertEquals("now it's simple", config.getString("mean"));
assertEquals("available", config.getString("[@topattr](0)"));
- assertEquals("successfull", config.getString("[@topattr](1)"));
+ assertEquals("successfull", config.getString("[@topattr_other]"));
}
/**
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestMultiFileHierarchicalConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestMultiFileHierarchicalConfiguration.java?rev=1385157&r1=1385156&r2=1385157&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestMultiFileHierarchicalConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestMultiFileHierarchicalConfiguration.java Sat Sep 15 19:38:11 2012
@@ -143,7 +143,6 @@ public class TestMultiFileHierarchicalCo
Thread.sleep(1100);
XMLConfiguration x = new XMLConfiguration();
x.setFile(output);
- x.setAttributeSplittingDisabled(true);
x.setDelimiterParsingDisabled(true);
x.load();
x.setProperty("rowsPerPage", "35");
@@ -200,7 +199,6 @@ public class TestMultiFileHierarchicalCo
Thread.sleep(500);
XMLConfiguration x = new XMLConfiguration();
x.setFile(output);
- x.setAttributeSplittingDisabled(true);
x.setDelimiterParsingDisabled(true);
x.load();
x.setProperty("rowsPerPage", "35");
@@ -265,7 +263,6 @@ public class TestMultiFileHierarchicalCo
Thread.sleep(1100);
XMLConfiguration x = new XMLConfiguration();
x.setFile(output);
- x.setAttributeSplittingDisabled(true);
x.setDelimiterParsingDisabled(true);
x.load();
x.setProperty("rowsPerPage", "test");
Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestVFSConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestVFSConfigurationBuilder.java?rev=1385157&r1=1385156&r2=1385157&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestVFSConfigurationBuilder.java (original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/TestVFSConfigurationBuilder.java Sat Sep 15 19:38:11 2012
@@ -1149,7 +1149,6 @@ public class TestVFSConfigurationBuilder
Thread.sleep(1100);
XMLConfiguration x = new XMLConfiguration();
x.setFile(output);
- x.setAttributeSplittingDisabled(true);
x.setDelimiterParsingDisabled(true);
x.load();
x.setProperty("rowsPerPage", "test");
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=1385157&r1=1385156&r2=1385157&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 Sep 15 19:38:11 2012
@@ -510,12 +510,6 @@ public class TestXMLConfiguration
conf.addProperty("test.array", "value" + i);
}
- // add an array of strings in an attribute
- for (int i = 1; i < 5; i++)
- {
- conf.addProperty("test.attribute[@array]", "value" + i);
- }
-
// add comma delimited lists with escaped delimiters
conf.addProperty("split.list5", "a\\,b\\,c");
conf.setProperty("element3", "value\\,value1\\,value2");
@@ -868,9 +862,9 @@ public class TestXMLConfiguration
@Test
public void testSplitLists()
{
- assertEquals("a", conf.getString("split.list3[@values]"));
- assertEquals(2, conf.getMaxIndex("split.list3[@values]"));
- assertEquals("a,b,c", conf.getString("split.list4[@values]"));
+ assertEquals("a,b,c", conf.getString("split.list3[@values]"));
+ assertEquals(0, conf.getMaxIndex("split.list3[@values]"));
+ assertEquals("a\\,b\\,c", conf.getString("split.list4[@values]"));
assertEquals("a", conf.getString("split.list1"));
assertEquals(2, conf.getMaxIndex("split.list1"));
assertEquals("a,b,c", conf.getString("split.list2"));
@@ -916,7 +910,6 @@ public class TestXMLConfiguration
XMLConfiguration conf = new XMLConfiguration();
conf.setExpressionEngine(new XPathExpressionEngine());
conf.setDelimiterParsingDisabled(true);
- conf.setAttributeSplittingDisabled(true);
conf.setFile(new File(testProperties));
conf.load();
@@ -937,7 +930,6 @@ public class TestXMLConfiguration
config.setFileName(testFile2);
//config.setExpressionEngine(new XPathExpressionEngine());
config.setDelimiterParsingDisabled(true);
- config.setAttributeSplittingDisabled(true);
config.load();
config.setProperty("Employee[@attr1]", "3,2,1");
assertEquals("3,2,1", config.getString("Employee[@attr1]"));
@@ -946,7 +938,6 @@ public class TestXMLConfiguration
config.setFileName(testSaveFile.getAbsolutePath());
//config.setExpressionEngine(new XPathExpressionEngine());
config.setDelimiterParsingDisabled(true);
- config.setAttributeSplittingDisabled(true);
config.load();
config.setProperty("Employee[@attr1]", "1,2,3");
assertEquals("1,2,3", config.getString("Employee[@attr1]"));
@@ -961,7 +952,6 @@ public class TestXMLConfiguration
checkConfig.setFileName(testSaveFile.getAbsolutePath());
checkConfig.setExpressionEngine(new XPathExpressionEngine());
checkConfig.setDelimiterParsingDisabled(true);
- checkConfig.setAttributeSplittingDisabled(true);
checkConfig.load();
assertEquals("1,2,3", checkConfig.getString("Employee/@attr1"));
assertEquals("one, two, three", checkConfig.getString("Employee/@attr2"));
@@ -1384,17 +1374,6 @@ public class TestXMLConfiguration
}
/**
- * Tests saving and loading a configuration when delimiter parsing is
- * disabled and attributes are involved.
- */
- @Test
- public void testSaveDelimiterParsingDisabledAttrs()
- throws ConfigurationException
- {
- checkSaveDelimiterParsingDisabled("list.delimiter.test[@attr]");
- }
-
- /**
* Helper method for testing saving and loading a configuration when
* delimiter parsing is disabled.
*
@@ -1417,33 +1396,29 @@ public class TestXMLConfiguration
}
/**
- * Tests multiple attribute values in delimiter parsing disabled mode.
+ * Tests that attribute values are not split.
*/
@Test
- public void testDelimiterParsingDisabledMultiAttrValues() throws ConfigurationException
+ public void testNoDelimiterParsingInAttrValues() throws ConfigurationException
{
conf.clear();
conf.setDelimiterParsingDisabled(true);
conf.load();
List<Object> expr = conf.getList("expressions[@value]");
- assertEquals("Wrong list size", 2, expr.size());
- assertEquals("Wrong element 1", "a || (b && c)", expr.get(0));
- assertEquals("Wrong element 2", "!d", expr.get(1));
+ assertEquals("Wrong list size", 1, expr.size());
+ assertEquals("Wrong element 1", "a || (b && c) | !d", expr.get(0));
}
/**
- * Tests using multiple attribute values, which are partly escaped when
- * delimiter parsing is not disabled.
+ * Tries to create an attribute with multiple values.
*/
- @Test
- public void testMultipleAttrValuesEscaped() throws ConfigurationException
+ @Test(expected = ConfigurationRuntimeException.class)
+ public void testAttributeKeyWithMultipleValues()
+ throws ConfigurationException
{
- conf.addProperty("test.dir[@name]", "C:\\Temp\\");
- conf.addProperty("test.dir[@name]", "C:\\Data\\");
- conf.save(testSaveConf);
- XMLConfiguration checkConf = new XMLConfiguration();
- checkConf.setFile(testSaveConf);
- checkSavedConfig(checkConf);
+ conf.addProperty("errorTest[@multiAttr]", Arrays.asList("v1", "v2"));
+ StringWriter out = new StringWriter();
+ conf.save(out);
}
/**
@@ -1670,47 +1645,6 @@ public class TestXMLConfiguration
}
/**
- * Tests whether attribute splitting can be disabled.
- */
- @Test
- public void testAttributeSplittingDisabled() throws ConfigurationException
- {
- List<Object> values = conf.getList("expressions[@value2]");
- assertEquals("Wrong number of attribute values", 2, values.size());
- assertEquals("Wrong value 1", "a", values.get(0));
- assertEquals("Wrong value 2", "b|c", values.get(1));
- XMLConfiguration conf2 = new XMLConfiguration();
- conf2.setAttributeSplittingDisabled(true);
- conf2.setFile(conf.getFile());
- conf2.load();
- assertEquals("Attribute was split", "a,b|c", conf2
- .getString("expressions[@value2]"));
- }
-
- /**
- * Tests disabling both delimiter parsing and attribute splitting.
- */
- @Test
- public void testAttributeSplittingAndDelimiterParsingDisabled()
- throws ConfigurationException
- {
- conf.clear();
- conf.setDelimiterParsingDisabled(true);
- conf.load();
- List<Object> values = conf.getList("expressions[@value2]");
- assertEquals("Wrong number of attribute values", 2, values.size());
- assertEquals("Wrong value 1", "a,b", values.get(0));
- assertEquals("Wrong value 2", "c", values.get(1));
- XMLConfiguration conf2 = new XMLConfiguration();
- conf2.setAttributeSplittingDisabled(true);
- conf2.setDelimiterParsingDisabled(true);
- conf2.setFile(conf.getFile());
- conf2.load();
- assertEquals("Attribute was split", "a,b|c", conf2
- .getString("expressions[@value2]"));
- }
-
- /**
* Tests modifying an XML document and saving it with schema validation enabled.
*/
@Test
Modified: commons/proper/configuration/trunk/src/test/resources/test.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/resources/test.xml?rev=1385157&r1=1385156&r2=1385157&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/resources/test.xml (original)
+++ commons/proper/configuration/trunk/src/test/resources/test.xml Sat Sep 15 19:38:11 2012
@@ -55,7 +55,7 @@ And even longer.
</sublist>
</list>
- <!-- Comma delimited lists -->
+ <!-- Comma delimited lists (work in elements, but not in attributes) -->
<split>
<list1>a,b,c</list1>
<list2>a\,b\,c</list2>
@@ -102,10 +102,10 @@ And even longer.
<a name="u" test="yes">value1,value2</a>
</attrList>
- <!-- An attribute with multiple values and escape characters for testing
- splitting when delimiter parsing is disabled.
+ <!-- An attribute with list delimiter characters for testing that
+ attribute values are not split.
-->
- <expressions value="a \|\| (b && c)|!d"
+ <expressions value="a || (b && c) | !d"
value2="a,b|c"/>
<!-- Tests for handling of spaces -->