Author: oheger
Date: Sat Nov 8 13:05:23 2008
New Revision: 712431
URL: http://svn.apache.org/viewvc?rev=712431&view=rev
Log:
CONFIGURATION-345: Ensure that "ISO-8859-1" is used as default encoding, even by the constructors
of the super class.
Modified:
commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java
commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java
commons/proper/configuration/trunk/xdocs/changes.xml
Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java?rev=712431&r1=712430&r2=712431&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java
Sat Nov 8 13:05:23 2008
@@ -213,11 +213,6 @@
/** Allow file inclusion or not */
private boolean includesAllowed;
- // initialization block to set the encoding before loading the file in the constructors
- {
- setEncoding(DEFAULT_ENCODING);
- }
-
/**
* Creates an empty PropertyConfiguration object which can be
* used to synthesize a new Properties file by adding values and
@@ -344,6 +339,19 @@
}
/**
+ * Returns the encoding to be used when loading or storing configuration
+ * data. This implementation ensures that the default encoding will be used
+ * if none has been set explicitly.
+ *
+ * @return the encoding
+ */
+ public String getEncoding()
+ {
+ String enc = super.getEncoding();
+ return (enc != null) ? enc : DEFAULT_ENCODING;
+ }
+
+ /**
* Returns the associated layout object.
*
* @return the associated layout object
Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java?rev=712431&r1=712430&r2=712431&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java
Sat Nov 8 13:05:23 2008
@@ -21,6 +21,7 @@
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Reader;
@@ -826,6 +827,36 @@
}
/**
+ * Tests whether the correct default encoding is used when loading a
+ * properties file. This test is related to CONFIGURATION-345.
+ */
+ public void testLoadWithDefaultEncoding() throws ConfigurationException
+ {
+ class PropertiesConfigurationTestImpl extends PropertiesConfiguration
+ {
+ String loadEncoding;
+
+ public PropertiesConfigurationTestImpl(String fileName)
+ throws ConfigurationException
+ {
+ super(fileName);
+ }
+
+ public void load(InputStream in, String encoding)
+ throws ConfigurationException
+ {
+ loadEncoding = encoding;
+ super.load(in, encoding);
+ }
+ }
+
+ PropertiesConfigurationTestImpl testConf = new PropertiesConfigurationTestImpl(
+ testProperties);
+ assertEquals("Default encoding not used", "ISO-8859-1",
+ testConf.loadEncoding);
+ }
+
+ /**
* Creates a configuration that can be used for testing copy operations.
*
* @return the configuration to be copied
Modified: commons/proper/configuration/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/xdocs/changes.xml?rev=712431&r1=712430&r2=712431&view=diff
==============================================================================
--- commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ commons/proper/configuration/trunk/xdocs/changes.xml Sat Nov 8 13:05:23 2008
@@ -38,6 +38,10 @@
configuration nodes for properties with multiple values. This
improves compatibility with queries.
</action>
+ <action dev="oheger" type="fix" issue="CONFIGURATION-345">
+ PropertiesConfiguration now per default uses the encoding "ISO-8859-1"
+ for loading properties files.
+ </action>
<action dev="oheger" type="fix" issue="CONFIGURATION-344">
CombinedConfiguration could cause a deadlock when it was accessed while
concurrently a reload of one of its child configuration happened. This
|