You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by rg...@apache.org on 2009/06/22 05:32:45 UTC
svn commit: r787127 - in /commons/proper/configuration/trunk:
src/java/org/apache/commons/configuration/XMLConfiguration.java
src/test/org/apache/commons/configuration/TestXMLConfiguration.java
xdocs/changes.xml
Author: rgoers
Date: Mon Jun 22 03:32:38 2009
New Revision: 787127
URL: http://svn.apache.org/viewvc?rev=787127&view=rev
Log:
Fix CONFIGURATION-388 - delimiters will not be escaped if delimiter parsing/attribute splitting are disabled
Modified:
commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java
commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
commons/proper/configuration/trunk/xdocs/changes.xml
Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java?rev=787127&r1=787126&r2=787127&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java Mon Jun 22 03:32:38 2009
@@ -833,7 +833,8 @@
}
XMLBuilderVisitor builder = new XMLBuilderVisitor(document,
- isDelimiterParsingDisabled() ? (char) 0 : getListDelimiter());
+ isDelimiterParsingDisabled() ? (char) 0 : getListDelimiter(),
+ isAttributeSplittingDisabled());
builder.processDocument(getRoot());
initRootElementText(document, getRootNode().getValue());
return document;
@@ -1309,9 +1310,9 @@
{
if (txtNode == null)
{
- txtNode = document
- .createTextNode(PropertyConverter.escapeDelimiters(
- value.toString(), getListDelimiter()));
+ String newValue = isDelimiterParsingDisabled() ? value.toString() :
+ PropertyConverter.escapeDelimiters(value.toString(), getListDelimiter());
+ txtNode = document.createTextNode(newValue);
if (((Element) getReference()).getFirstChild() != null)
{
((Element) getReference()).insertBefore(txtNode,
@@ -1324,8 +1325,9 @@
}
else
{
- txtNode.setNodeValue(PropertyConverter.escapeDelimiters(
- value.toString(), getListDelimiter()));
+ String newValue = isDelimiterParsingDisabled() ? value.toString() :
+ PropertyConverter.escapeDelimiters(value.toString(), getListDelimiter());
+ txtNode.setNodeValue(newValue);
}
}
}
@@ -1336,7 +1338,8 @@
*/
private void updateAttribute()
{
- XMLBuilderVisitor.updateAttribute(getParent(), getName(), getListDelimiter());
+ XMLBuilderVisitor.updateAttribute(getParent(), getName(), getListDelimiter(),
+ isAttributeSplittingDisabled());
}
/**
@@ -1399,16 +1402,21 @@
private char listDelimiter = AbstractConfiguration.
getDefaultListDelimiter();
+ /** True if attributes should not be split */
+ private boolean isAttributeSplittingDisabled;
+
/**
* Creates a new instance of <code>XMLBuilderVisitor</code>
*
* @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)
+ public XMLBuilderVisitor(Document doc, char listDelimiter, boolean isAttributeSplittingDisabled)
{
document = doc;
this.listDelimiter = listDelimiter;
+ this.isAttributeSplittingDisabled = isAttributeSplittingDisabled;
}
/**
@@ -1435,7 +1443,8 @@
{
if (newNode.isAttribute())
{
- updateAttribute(parent, getElement(parent), newNode.getName(), listDelimiter);
+ updateAttribute(parent, getElement(parent), newNode.getName(), listDelimiter,
+ isAttributeSplittingDisabled);
return null;
}
@@ -1475,8 +1484,10 @@
* @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)
+ private static void updateAttribute(Node node, Element elem, String name, char listDelimiter,
+ boolean isAttributeSplittingDisabled)
{
if (node != null && elem != null)
{
@@ -1492,8 +1503,10 @@
{
buf.append(delimiter);
}
- buf.append(PropertyConverter.escapeDelimiters(attr
- .getValue().toString(), delimiter));
+ String value = isAttributeSplittingDisabled ? attr.getValue().toString() :
+ PropertyConverter.escapeDelimiters(attr.getValue().toString(),
+ delimiter);
+ buf.append(value);
}
attr.setReference(elem);
}
@@ -1517,12 +1530,15 @@
* @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)
+ static void updateAttribute(Node node, String name, char listDelimiter,
+ boolean isAttributeSplittingDisabled)
{
if (node != null)
{
- updateAttribute(node, (Element) node.getReference(), name, listDelimiter);
+ updateAttribute(node, (Element) node.getReference(), name, listDelimiter,
+ isAttributeSplittingDisabled);
}
}
Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java?rev=787127&r1=787126&r2=787127&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java (original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java Mon Jun 22 03:32:38 2009
@@ -76,6 +76,7 @@
private String testProperties2 = new File("conf/testDigesterConfigurationInclude1.xml").getAbsolutePath();
private String testBasePath = new File("conf").getAbsolutePath();
private File testSaveConf = new File("target/testsave.xml");
+ private File testSaveFile = new File("target/testsample2.xml");
private String testFile2 = new File("conf/sample.xml").getAbsolutePath();
private XMLConfiguration conf;
@@ -782,6 +783,67 @@
assertEquals("a\\,b\\,c", conf2.getString("split/list2"));
}
+ /**
+ * Tests string properties with list delimiters when delimiter parsing
+ * is disabled
+ */
+ public void testSaveWithDelimiterParsingDisabled() throws ConfigurationException {
+ XMLConfiguration conf = new XMLConfiguration();
+ conf.setExpressionEngine(new XPathExpressionEngine());
+ conf.setDelimiterParsingDisabled(true);
+ conf.setAttributeSplittingDisabled(true);
+ conf.setFile(new File(testProperties));
+ conf.load();
+
+ 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,b,c", conf.getString("split/list1"));
+ assertEquals(0, conf.getMaxIndex("split/list1"));
+ assertEquals("a\\,b\\,c", conf.getString("split/list2"));
+ // save the configuration
+ conf.save(testSaveConf.getAbsolutePath());
+
+ // read the configuration and compare the properties
+ XMLConfiguration checkConfig = new XMLConfiguration();
+ checkConfig.setFileName(testSaveConf.getAbsolutePath());
+ checkSavedConfig(checkConfig);
+ XMLConfiguration config = new XMLConfiguration();
+ 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]"));
+ config.save(testSaveFile.getAbsolutePath());
+ config = new XMLConfiguration();
+ 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]"));
+ config.setProperty("Employee[@attr2]", "one, two, three");
+ assertEquals("one, two, three", config.getString("Employee[@attr2]"));
+ config.setProperty("Employee.text", "a,b,d");
+ assertEquals("a,b,d", config.getString("Employee.text"));
+ config.setProperty("Employee.Salary", "100,000");
+ assertEquals("100,000", config.getString("Employee.Salary"));
+ config.save(testSaveFile.getAbsolutePath());
+ checkConfig = new XMLConfiguration();
+ 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"));
+ assertEquals("a,b,d", checkConfig.getString("Employee/text"));
+ assertEquals("100,000", checkConfig.getString("Employee/Salary"));
+ }
+
/**
* Tests whether a DTD can be accessed.
*/
Modified: commons/proper/configuration/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/xdocs/changes.xml?rev=787127&r1=787126&r2=787127&view=diff
==============================================================================
--- commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ commons/proper/configuration/trunk/xdocs/changes.xml Mon Jun 22 03:32:38 2009
@@ -23,6 +23,9 @@
<body>
<release version="1.7" date="in SVN" description="">
+ <action dev="rgoers" type="fix" issue="CONFIGURATION-388">
+ Attribute or element values will not be escaped when attribute or element splitting are disabled.
+ </action>
<action dev="ebourg" type="fix" issue="CONFIGURATION-362">
Empty dictionaries in a PropertyList configuration are now preserved when the configuration is saved.
</action>
@@ -31,7 +34,7 @@
clearProperty() methods.
</action>
<action dev="rgoers" type="add" issue="CONFIGURATION-380">
- Add ExprLookup to allow expressions to be evaluated in configurations. When
+ Add ExprLookup to allow expressions to be evaluated in configurations. When
used, this requires that Apache Commons Jexl be added as a dependency to
projects using Commons Configuration.
</action>
@@ -101,7 +104,7 @@
</action>
<action dev="rgoers" type="add" issue="CONFIGURATION-356">
Added getConfigurations and getConfigurationNameList.
- </action>
+ </action>
<action dev="rgoers" type="add" issue="CONFIGURATION-257">
Allow configurations to be validated using XML Schemas.
</action>
@@ -122,12 +125,12 @@
Allow system properties to be set from a configuration file.
</action>
<action dev="rgoers" type="add" issue="CONFIGURATION-351">
- Allow variable resolvers to be defined configured in
+ Allow variable resolvers to be defined configured in
DefaultConfigurationBuilder.
</action>
<action dev="rgoers" type="add" issue="CONFIGURATION-350">
Added MultiFileHierarchicalConfiguration, DynamicCombinedConfiguration
- and PatternSubtreeConfigurationWrapper.
+ and PatternSubtreeConfigurationWrapper.
</action>
<action dev="oheger" type="add" issue="CONFIGURATION-349" due-to="Ralph Goers">
The visibility of DefaultConfigurationBuilder.XMLConfigurationProvider
@@ -744,7 +747,7 @@
</action>
<action dev="oheger" type="update" issue="CONFIGURATION-63">
Loading of file-based configurations no longer throws a NullPointerException
- in setups where the thread context class loader is not set.
+ in setups where the thread context class loader is not set.
</action>
<action dev="oheger" type="update">
The dependency to dom4j was removed; it was only used by two test classes,
@@ -855,7 +858,7 @@
ConfigurationMap.
</action>
</release>
-
+
<release version="1.2-rc1" date="2005-11-11">
<action dev="oheger" type="update" issue="CONFIGURATION-33">
The reload() method in AbstractFileConfiguration was updated to prevent
@@ -1077,7 +1080,7 @@
</action>
<action dev="ebourg" type="update" issue="CONFIGURATION-58">
Fixed getLongArray(), getFloatArray() and getDoubleArray() in DataConfiguration,
- the values were cast into integers.
+ the values were cast into integers.
</action>
</release>
@@ -1124,7 +1127,7 @@
</action>
<action dev="ebourg" type="fix">
Calling getProperties on a JNDIConfiguration no longer throws an
- UnsupportedOperationException.
+ UnsupportedOperationException.
</action>
<action dev="ebourg" type="remove">
Removed the getPropertyDirect method from AbstractConfiguration,
@@ -1177,8 +1180,8 @@
XMLConfiguration to AbstractFileConfiguration.
</action>
<action dev="epugh" type="remove">
- Remove deprecated getVector() implementations.
- </action>
+ Remove deprecated getVector() implementations.
+ </action>
<action dev="ebourg" type="add" issue="CONFIGURATION-147">
File based configurations can now be automatically reloaded when the
underlying file is modified.