You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by eb...@apache.org on 2005/01/03 12:58:46 UTC
cvs commit: jakarta-commons/configuration/src/test/org/apache/commons/configuration TestPropertiesConfiguration.java
ebourg 2005/01/03 03:58:46
Modified: configuration/src/java/org/apache/commons/configuration
PropertiesConfiguration.java
configuration/src/test/org/apache/commons/configuration
TestPropertiesConfiguration.java
Log:
Changed PropertyWriter and unescapeJava to make them independant from the static delimiter. This will allow instance specific delimiters.
Revision Changes Path
1.18 +16 -13 jakarta-commons/configuration/src/java/org/apache/commons/configuration/PropertiesConfiguration.java
Index: PropertiesConfiguration.java
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/src/java/org/apache/commons/configuration/PropertiesConfiguration.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- PropertiesConfiguration.java 4 Dec 2004 15:45:40 -0000 1.17
+++ PropertiesConfiguration.java 3 Jan 2005 11:58:46 -0000 1.18
@@ -34,7 +34,7 @@
* This is the "classic" Properties loader which loads the values from
* a single or multiple files (which can be chained with "include =".
* All given path references are either absolute or relative to the
- * file name supplied in the Constructor.
+ * file name supplied in the constructor.
* <p>
* In this class, empty PropertyConfigurations can be built, properties
* added and later saved. include statements are (obviously) not supported
@@ -72,16 +72,16 @@
* If a property is named "include" (or whatever is defined by
* setInclude() and getInclude() and the value of that property is
* the full path to a file on disk, that file will be included into
- * the ConfigurationsRepository. You can also pull in files relative
- * to the parent configuration file. So if you have something
- * like the following:
+ * the configuration. You can also pull in files relative to the parent
+ * configuration file. So if you have something like the following:
*
* include = additional.properties
*
* Then "additional.properties" is expected to be in the same
* directory as the parent configuration file.
*
- * Duplicate name values will be replaced, so be careful.
+ * The properties in the included file are added to the parent configuration,
+ * they do not replace existing properties with the same key.
*
* </li>
* </ul>
@@ -284,7 +284,7 @@
}
else
{
- addProperty(key, unescapeJava(value));
+ addProperty(key, unescapeJava(value, getDelimiter()));
}
}
}
@@ -304,7 +304,7 @@
{
try
{
- PropertiesWriter out = new PropertiesWriter(writer);
+ PropertiesWriter out = new PropertiesWriter(writer, getDelimiter());
out.writeComment("written by PropertiesConfiguration");
out.writeComment(new Date().toString());
@@ -413,14 +413,17 @@
*/
public static class PropertiesWriter extends FilterWriter
{
+ private char delimiter;
+
/**
* Constructor.
*
* @param writer a Writer object providing the underlying stream
*/
- public PropertiesWriter(Writer writer) throws IOException
+ public PropertiesWriter(Writer writer, char delimiter)
{
super(writer);
+ this.delimiter = delimiter;
}
/**
@@ -437,7 +440,7 @@
if (value != null)
{
String v = StringEscapeUtils.escapeJava(String.valueOf(value));
- v = StringUtils.replace(v, String.valueOf(getDelimiter()), "\\" + getDelimiter());
+ v = StringUtils.replace(v, String.valueOf(delimiter), "\\" + delimiter);
write(v);
}
@@ -480,7 +483,7 @@
*
* @throws IllegalArgumentException if the Writer is <code>null</code>
*/
- protected static String unescapeJava(String str)
+ protected static String unescapeJava(String str, char delimiter)
{
if (str == null)
{
@@ -548,9 +551,9 @@
else if (ch=='b'){
out.append('\b');
}
- else if (ch==getDelimiter()){
+ else if (ch==delimiter){
out.append('\\');
- out.append(getDelimiter());
+ out.append(delimiter);
}
else if (ch=='u'){
// uh-oh, we're in unicode country....
1.18 +2 -2 jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java
Index: TestPropertiesConfiguration.java
===================================================================
RCS file: /home/cvs/jakarta-commons/configuration/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- TestPropertiesConfiguration.java 4 Dec 2004 15:45:39 -0000 1.17
+++ TestPropertiesConfiguration.java 3 Jan 2005 11:58:46 -0000 1.18
@@ -254,7 +254,7 @@
public void testUnescapeJava()
{
- assertEquals("test\\,test", PropertiesConfiguration.unescapeJava("test\\,test"));
+ assertEquals("test\\,test", PropertiesConfiguration.unescapeJava("test\\,test", ','));
}
public void testMixedArray()
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org