You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by oh...@apache.org on 2006/01/02 16:57:23 UTC
svn commit: r365366 - in /jakarta/commons/proper/configuration/trunk:
src/java/org/apache/commons/configuration/
src/java/org/apache/commons/configuration/web/
src/test/org/apache/commons/configuration/ xdocs/
Author: oheger
Date: Mon Jan 2 07:56:51 2006
New Revision: 365366
URL: http://svn.apache.org/viewcvs?rev=365366&view=rev
Log:
Huge patch from Jorge Ferrer to implement instance specific list delimiters
Modified:
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractConfiguration.java
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationConverter.java
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/MapConfiguration.java
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLPropertiesConfiguration.java
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/web/AppletConfiguration.java
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/web/ServletConfiguration.java
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/web/ServletContextConfiguration.java
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/web/ServletFilterConfiguration.java
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationConverter.java
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java
jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
jakarta/commons/proper/configuration/trunk/xdocs/changes.xml
Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractConfiguration.java?rev=365366&r1=365365&r2=365366&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractConfiguration.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/AbstractConfiguration.java Mon Jan 2 07:56:51 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2005 The Apache Software Foundation.
+ * Copyright 2001-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
@@ -47,8 +47,17 @@
/** end token */
protected static final String END_TOKEN = "}";
- /** The property delimiter used while parsing (a comma). */
- private static char delimiter = ',';
+ /** The default value for listDelimiter */
+ private static char defaultListDelimiter = ',';
+
+ /** Delimiter used to convert single values to lists */
+ private char listDelimiter = defaultListDelimiter;
+
+ /**
+ * When set to true the given configuration delimiter will not be used
+ * while parsing for this configuration.
+ */
+ private boolean delimiterParsingDisabled = false;
/**
* Whether the configuration should throw NoSuchElementExceptions or simply
@@ -58,13 +67,25 @@
/**
* For configurations extending AbstractConfiguration, allow them to change
- * the delimiter from the default comma (",").
+ * the listDelimiter from the default comma (","). This value will be used
+ * only when creating new configurations. Those already created will not be
+ * affected by this change
*
- * @param delimiter The new delimiter
+ * @param delimiter The new listDelimiter
+ */
+ public static void setDefaultListDelimiter(char delimiter)
+ {
+ AbstractConfiguration.defaultListDelimiter = delimiter;
+ }
+
+ /**
+ * @deprecated Use AbstractConfiguration.setDefaultListDelimiter(char)
+ * instead
+ * @param delimiter
*/
public static void setDelimiter(char delimiter)
{
- AbstractConfiguration.delimiter = delimiter;
+ setDefaultListDelimiter(delimiter);
}
/**
@@ -72,9 +93,67 @@
*
* @return The delimiter in use
*/
+ public static char getDefaultListDelimiter()
+ {
+ return AbstractConfiguration.defaultListDelimiter;
+ }
+
+ /**
+ * @deprecated Use AbstractConfiguration.getDefaultListDelimiter() instead
+ */
public static char getDelimiter()
{
- return AbstractConfiguration.delimiter;
+ return getDefaultListDelimiter();
+ }
+
+ /**
+ * Change the list delimiter for this configuration.
+ *
+ * Note: this change will only be effective for new parsings. If you
+ * want it to take effect for all loaded properties use the no arg constructor
+ * and call this method before setting the source.
+ *
+ * @param listDelimiter The new listDelimiter
+ */
+ public void setListDelimiter(char listDelimiter)
+ {
+ this.listDelimiter = listDelimiter;
+ }
+
+ /**
+ * Retrieve the delimiter for this configuration. The default
+ * is the value of defaultListDelimiter.
+ *
+ * @return The listDelimiter in use
+ */
+ public char getListDelimiter()
+ {
+ return listDelimiter;
+ }
+
+ /**
+ * Determine if this configuration is using delimiters when parsing
+ * property values to convert them to lists of values. Defaults to false
+ * @return true if delimiters are not being used
+ */
+ public boolean isDelimiterParsingDisabled()
+ {
+ return delimiterParsingDisabled;
+ }
+
+ /**
+ * Set whether this configuration should use delimiters when parsing
+ * property values to convert them to lists of values. By default delimiter
+ * parsing is enabled
+ *
+ * Note: this change will only be effective for new parsings. If you
+ * want it to take effect for all loaded properties use the no arg constructor
+ * and call this method before setting source.
+ * @param delimiterParsingDisabled
+ */
+ public void setDelimiterParsingDisabled(boolean delimiterParsingDisabled)
+ {
+ this.delimiterParsingDisabled = delimiterParsingDisabled;
}
/**
@@ -108,10 +187,17 @@
*/
public void addProperty(String key, Object value)
{
- Iterator it = PropertyConverter.toIterator(value, getDelimiter());
- while (it.hasNext())
+ if (!isDelimiterParsingDisabled())
+ {
+ Iterator it = PropertyConverter.toIterator(value, getListDelimiter());
+ while (it.hasNext())
+ {
+ addPropertyDirect(key, it.next());
+ }
+ }
+ else
{
- addPropertyDirect(key, it.next());
+ addPropertyDirect(key, value);
}
}
Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationConverter.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationConverter.java?rev=365366&r1=365365&r2=365366&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationConverter.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/ConfigurationConverter.java Mon Jan 2 07:56:51 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2005 The Apache Software Foundation.
+ * Copyright 2001-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
@@ -106,7 +106,7 @@
Properties props = new Properties();
char delimiter = (config instanceof AbstractConfiguration)
- ? ((AbstractConfiguration) config).getDelimiter() : ',';
+ ? ((AbstractConfiguration) config).getListDelimiter() : ',';
Iterator keys = config.getKeys();
while (keys.hasNext())
Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java?rev=365366&r1=365365&r2=365366&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/HierarchicalConfiguration.java Mon Jan 2 07:56:51 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2005 The Apache Software Foundation.
+ * Copyright 2001-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
@@ -26,6 +26,7 @@
import java.util.Stack;
import org.apache.commons.collections.set.ListOrderedSet;
+import org.apache.commons.collections.iterators.SingletonIterator;
import org.apache.commons.configuration.tree.DefaultConfigurationNode;
import org.apache.commons.lang.StringUtils;
@@ -367,7 +368,15 @@
public void setProperty(String key, Object value)
{
Iterator itNodes = fetchNodeList(key).iterator();
- Iterator itValues = PropertyConverter.toIterator(value, getDelimiter());
+ Iterator itValues;
+ if (!isDelimiterParsingDisabled())
+ {
+ itValues = PropertyConverter.toIterator(value, getListDelimiter());
+ }
+ else
+ {
+ itValues = new SingletonIterator(value);
+ }
while (itNodes.hasNext() && itValues.hasNext())
{
((Node) itNodes.next()).setValue(itValues.next());
Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/MapConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/MapConfiguration.java?rev=365366&r1=365365&r2=365366&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/MapConfiguration.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/MapConfiguration.java Mon Jan 2 07:56:51 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2004-2005 The Apache Software Foundation.
+ * Copyright 2004-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
@@ -58,9 +58,9 @@
public Object getProperty(String key)
{
Object value = map.get(key);
- if (value instanceof String)
+ if ((value instanceof String) && (!isDelimiterParsingDisabled()))
{
- List list = PropertyConverter.split((String) value, getDelimiter());
+ List list = PropertyConverter.split((String) value, getListDelimiter());
return list.size() > 1 ? list : value;
}
else
Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java?rev=365366&r1=365365&r2=365366&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java Mon Jan 2 07:56:51 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2005 The Apache Software Foundation.
+ * Copyright 2001-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
@@ -74,7 +74,7 @@
* key = This property, has multiple, values
* </pre>
* will result in a property with three values. You can change the value
- * delmiter using the <code>{@link AbstractConfiguration#setDelimiter(char)}</code>
+ * delimiter using the <code>{@link AbstractConfiguration#setListDelimiter(char)}</code>
* method. Setting the delimiter to 0 will disable value splitting completely.
* </li>
* <li>
@@ -348,7 +348,15 @@
{
if (getIncludesAllowed())
{
- String [] files = StringUtils.split(value, getDelimiter());
+ String [] files;
+ if (!isDelimiterParsingDisabled())
+ {
+ files = StringUtils.split(value, getListDelimiter());
+ }
+ else
+ {
+ files = new String[]{value};
+ }
for (int i = 0; i < files.length; i++)
{
loadIncludeFile(files[i].trim());
@@ -357,7 +365,7 @@
}
else
{
- addProperty(StringEscapeUtils.unescapeJava(key), unescapeJava(value, getDelimiter()));
+ addProperty(StringEscapeUtils.unescapeJava(key), unescapeJava(value, getListDelimiter()));
}
}
@@ -383,7 +391,7 @@
enterNoReload();
try
{
- PropertiesWriter out = new PropertiesWriter(writer, getDelimiter());
+ PropertiesWriter out = new PropertiesWriter(writer, getListDelimiter());
if (header != null)
{
Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java?rev=365366&r1=365365&r2=365366&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java Mon Jan 2 07:56:51 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2004-2005 The Apache Software Foundation.
+ * Copyright 2004-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
@@ -38,6 +38,7 @@
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
+import org.apache.commons.collections.iterators.SingletonIterator;
import org.w3c.dom.Attr;
import org.w3c.dom.CDATASection;
import org.w3c.dom.DOMException;
@@ -354,7 +355,16 @@
if (w3cNode instanceof Attr)
{
Attr attr = (Attr) w3cNode;
- for (Iterator it = PropertyConverter.split(attr.getValue(), getDelimiter()).iterator(); it.hasNext();)
+ Iterator it;
+ if (isDelimiterParsingDisabled())
+ {
+ it = new SingletonIterator(attr.getValue());
+ }
+ else
+ {
+ it = PropertyConverter.split(attr.getValue(), getListDelimiter()).iterator();
+ }
+ while (it.hasNext())
{
Node child = new XMLNode(attr.getName(),
elemRefs ? element : null);
@@ -376,8 +386,18 @@
{
if (child.getValue() != null)
{
- List values = PropertyConverter.split(child.getValue().toString(),
- getDelimiter());
+ List values;
+ if (isDelimiterParsingDisabled())
+ {
+ values = new ArrayList();
+ values.add(child.getValue().toString());
+ }
+ else
+ {
+ values = PropertyConverter.split(child.getValue().toString(),
+ getListDelimiter());
+ }
+
if (values.size() > 1)
{
// remove the original child
@@ -460,7 +480,7 @@
document = newDocument;
}
- XMLBuilderVisitor builder = new XMLBuilderVisitor(document);
+ XMLBuilderVisitor builder = new XMLBuilderVisitor(document, getListDelimiter());
builder.processDocument(getRoot());
return document;
} /* try */
@@ -692,7 +712,7 @@
{
txtNode = document
.createTextNode(PropertyConverter.escapeDelimiters(
- value.toString(), getDelimiter()));
+ value.toString(), getListDelimiter()));
if (((Element) getReference()).getFirstChild() != null)
{
((Element) getReference()).insertBefore(txtNode,
@@ -706,7 +726,7 @@
else
{
txtNode.setNodeValue(PropertyConverter.escapeDelimiters(
- value.toString(), getDelimiter()));
+ value.toString(), getListDelimiter()));
}
}
}
@@ -717,7 +737,7 @@
*/
private void updateAttribute()
{
- XMLBuilderVisitor.updateAttribute(getParent(), getName());
+ XMLBuilderVisitor.updateAttribute(getParent(), getName(), getListDelimiter());
}
/**
@@ -775,15 +795,21 @@
{
/** Stores the document to be constructed. */
private Document document;
+
+ /** Stores the list delimiter.*/
+ private char listDelimiter = AbstractConfiguration.
+ getDefaultListDelimiter();
/**
* 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
*/
- public XMLBuilderVisitor(Document doc)
+ public XMLBuilderVisitor(Document doc, char listDelimiter)
{
document = doc;
+ this.listDelimiter = listDelimiter;
}
/**
@@ -810,7 +836,7 @@
{
if (newNode.isAttribute())
{
- updateAttribute(parent, getElement(parent), newNode.getName());
+ updateAttribute(parent, getElement(parent), newNode.getName(), listDelimiter);
return null;
}
@@ -820,7 +846,7 @@
if (newNode.getValue() != null)
{
elem.appendChild(document.createTextNode(
- PropertyConverter.escapeDelimiters(newNode.getValue().toString(), getDelimiter())));
+ PropertyConverter.escapeDelimiters(newNode.getValue().toString(), listDelimiter)));
}
if (sibling2 == null)
{
@@ -845,8 +871,9 @@
* @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 vor attributes with multiple values
*/
- private static void updateAttribute(Node node, Element elem, String name)
+ private static void updateAttribute(Node node, Element elem, String name, char listDelimiter)
{
if (node != null && elem != null)
{
@@ -859,10 +886,10 @@
{
if (buf.length() > 0)
{
- buf.append(getDelimiter());
+ buf.append(listDelimiter);
}
buf.append(PropertyConverter.escapeDelimiters(attr
- .getValue().toString(), getDelimiter()));
+ .getValue().toString(), getDefaultListDelimiter()));
}
attr.setReference(elem);
}
@@ -885,12 +912,13 @@
*
* @param node the affected node
* @param name the name of the attribute
+ * @param listDelimiter the delimiter vor attributes with multiple values
*/
- static void updateAttribute(Node node, String name)
+ static void updateAttribute(Node node, String name, char listDelimiter)
{
if (node != null)
{
- updateAttribute(node, (Element) node.getReference(), name);
+ updateAttribute(node, (Element) node.getReference(), name, listDelimiter);
}
}
Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLPropertiesConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLPropertiesConfiguration.java?rev=365366&r1=365365&r2=365366&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLPropertiesConfiguration.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLPropertiesConfiguration.java Mon Jan 2 07:56:51 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2004-2005 The Apache Software Foundation.
+ * Copyright 2004-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
@@ -203,7 +203,7 @@
{
// escape the value
String v = StringEscapeUtils.escapeXml(String.valueOf(value));
- v = StringUtils.replace(v, String.valueOf(getDelimiter()), "\\" + getDelimiter());
+ v = StringUtils.replace(v, String.valueOf(getListDelimiter()), "\\" + getListDelimiter());
out.println(" <entry key=\"" + k + "\">" + v + "</entry>");
}
Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/web/AppletConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/web/AppletConfiguration.java?rev=365366&r1=365365&r2=365366&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/web/AppletConfiguration.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/web/AppletConfiguration.java Mon Jan 2 07:56:51 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2004-2005 The Apache Software Foundation.
+ * Copyright 2004-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
@@ -51,9 +51,13 @@
public Object getProperty(String key)
{
Object value = applet.getParameter(key);
- List list = PropertyConverter.split((String) value, getDelimiter());
+ if (!isDelimiterParsingDisabled())
+ {
+ List list = PropertyConverter.split((String) value, getListDelimiter());
+ value = list.size() > 1 ? list : value;
+ }
- return list.size() > 1 ? list : value;
+ return value;
}
public Iterator getKeys()
Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/web/ServletConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/web/ServletConfiguration.java?rev=365366&r1=365365&r2=365366&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/web/ServletConfiguration.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/web/ServletConfiguration.java Mon Jan 2 07:56:51 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2004-2005 The Apache Software Foundation.
+ * Copyright 2004-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
@@ -62,9 +62,13 @@
public Object getProperty(String key)
{
Object value = config.getInitParameter(key);
- List list = PropertyConverter.split((String) value, getDelimiter());
+ if (!isDelimiterParsingDisabled())
+ {
+ List list = PropertyConverter.split((String) value, getListDelimiter());
+ value = list.size() > 1 ? list : value;
+ }
- return list.size() > 1 ? list : value;
+ return value;
}
public Iterator getKeys()
Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/web/ServletContextConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/web/ServletContextConfiguration.java?rev=365366&r1=365365&r2=365366&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/web/ServletContextConfiguration.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/web/ServletContextConfiguration.java Mon Jan 2 07:56:51 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2004-2005 The Apache Software Foundation.
+ * Copyright 2004-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
@@ -63,9 +63,13 @@
public Object getProperty(String key)
{
Object value = context.getInitParameter(key);
- List list = PropertyConverter.split((String) value, getDelimiter());
+ if (!isDelimiterParsingDisabled())
+ {
+ List list = PropertyConverter.split((String) value, getListDelimiter());
+ value = list.size() > 1 ? list : value;
+ }
- return list.size() > 1 ? list : value;
+ return value;
}
public Iterator getKeys()
Modified: jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/web/ServletFilterConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/web/ServletFilterConfiguration.java?rev=365366&r1=365365&r2=365366&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/web/ServletFilterConfiguration.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/web/ServletFilterConfiguration.java Mon Jan 2 07:56:51 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2004-2005 The Apache Software Foundation.
+ * Copyright 2004-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
@@ -50,9 +50,13 @@
public Object getProperty(String key)
{
Object value = config.getInitParameter(key);
- List list = PropertyConverter.split((String) value, getDelimiter());
+ if (!isDelimiterParsingDisabled())
+ {
+ List list = PropertyConverter.split((String) value, getListDelimiter());
+ value = list.size() > 1 ? list : value;
+ }
- return list.size() > 1 ? list : value;
+ return value;
}
public Iterator getKeys()
Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationConverter.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationConverter.java?rev=365366&r1=365365&r2=365366&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationConverter.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestConfigurationConverter.java Mon Jan 2 07:56:51 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2005 The Apache Software Foundation.
+ * Copyright 2001-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
@@ -100,7 +100,7 @@
assertEquals("'interpolated-array' property", "teststring,teststring", props.getProperty("interpolated-array"));
// change the list delimiter
- BaseConfiguration.setDelimiter(';');
+ config.setListDelimiter(';');
props = ConfigurationConverter.getProperties(config);
assertEquals("'array' property", "item 1;item 2", props.getProperty("array"));
}
Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java?rev=365366&r1=365365&r2=365366&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java Mon Jan 2 07:56:51 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2005 The Apache Software Foundation.
+ * Copyright 2001-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
@@ -325,16 +325,41 @@
assertEquals("'test.multilines' property", property, conf.getString("test.multilines"));
}
- public void testChangingDelimiter() throws Exception
+ public void testChangingDefaultListDelimiter() throws Exception
{
PropertiesConfiguration pc = new PropertiesConfiguration(testProperties);
assertEquals(4, pc.getList("test.mixed.array").size());
- char delimiter = PropertiesConfiguration.getDelimiter();
- PropertiesConfiguration.setDelimiter('^');
+ char delimiter = PropertiesConfiguration.getDefaultListDelimiter();
+ PropertiesConfiguration.setDefaultListDelimiter('^');
pc = new PropertiesConfiguration(testProperties);
assertEquals(2, pc.getList("test.mixed.array").size());
- PropertiesConfiguration.setDelimiter(delimiter);
+ PropertiesConfiguration.setDefaultListDelimiter(delimiter);
+ }
+
+ public void testChangingListDelimiter() throws Exception
+ {
+ PropertiesConfiguration pc1 = new PropertiesConfiguration(testProperties);
+ assertEquals(4, pc1.getList("test.mixed.array").size());
+
+ PropertiesConfiguration pc2 = new PropertiesConfiguration();
+ pc2.setListDelimiter('^');
+ pc2.setFileName(testProperties);
+ pc2.load();
+ assertEquals("Should obtain the first value", "a", pc2.getString("test.mixed.array"));
+ assertEquals(2, pc2.getList("test.mixed.array").size());
+ }
+
+ public void testDisableListDelimiter() throws Exception
+ {
+ PropertiesConfiguration pc1 = new PropertiesConfiguration(testProperties);
+ assertEquals(4, pc1.getList("test.mixed.array").size());
+
+ PropertiesConfiguration pc2 = new PropertiesConfiguration();
+ pc2.setDelimiterParsingDisabled(true);
+ pc2.setFileName(testProperties);
+ pc2.load();
+ assertEquals(2, pc2.getList("test.mixed.array").size());
}
/**
Modified: jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java?rev=365366&r1=365365&r2=365366&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java (original)
+++ jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java Mon Jan 2 07:56:51 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2005 The Apache Software Foundation.
+ * Copyright 2001-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
@@ -683,6 +683,24 @@
assertEquals("a,b,c", conf.getString("split.list2"));
}
+ /**
+ * Tests string properties with list delimiters when delimiter parsing
+ * is disabled
+ */
+ public void testDelimiterParsingDisabled() throws ConfigurationException {
+ XMLConfiguration conf2 = new XMLConfiguration();
+ conf2.setDelimiterParsingDisabled(true);
+ conf2.setFile(new File(testProperties));
+ conf2.load();
+
+ assertEquals("a,b,c", conf2.getString("split.list3[@values]"));
+ assertEquals(0, conf2.getMaxIndex("split.list3[@values]"));
+ assertEquals("a\\,b\\,c", conf2.getString("split.list4[@values]"));
+ assertEquals("a,b,c", conf2.getString("split.list1"));
+ assertEquals(0, conf2.getMaxIndex("split.list1"));
+ assertEquals("a\\,b\\,c", conf2.getString("split.list2"));
+ }
+
/**
* Tests whether a DTD can be accessed.
*/
Modified: jakarta/commons/proper/configuration/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/xdocs/changes.xml?rev=365366&r1=365365&r2=365366&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/configuration/trunk/xdocs/changes.xml Mon Jan 2 07:56:51 2006
@@ -22,6 +22,19 @@
<body>
+ <release version="1.3-SNAPSHOT" date="in SVN">
+ <action dev="oheger" type="update" issue="35828" due-to="Jorge Ferrer">
+ All configuration classes derived from AbstractConfiguration now allow
+ to set an instance specific list delimiter. This can be done through
+ the new method setListDelimiter(). As before it is possible to define
+ a default list delimiter, which will be used if no instance specific
+ delimiter is set. This can be done using the new setDefaultListDelimiter()
+ method (the methods get/setDelimiter() have been deprecated). With the
+ new setDelimiterParsingDisabled() method parsing of lists can be
+ disabled at all.
+ </action>
+ </release>
+
<release version="1.2" date="2005-12-17">
</release>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org