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 2005/10/28 20:52:13 UTC
svn commit: r329269 - in /jakarta/commons/proper/configuration/trunk:
src/java/org/apache/commons/configuration/XMLConfiguration.java
src/test/org/apache/commons/configuration/TestXMLConfiguration.java
xdocs/changes.xml
Author: oheger
Date: Fri Oct 28 11:51:39 2005
New Revision: 329269
URL: http://svn.apache.org/viewcvs?rev=329269&view=rev
Log:
Updated XMLConfiguration to output the set encoding in the generated xml documents. Thanks to Kay Doebl for the patch.
Modified:
jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.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/XMLConfiguration.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java?rev=329269&r1=329268&r2=329269&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 Fri Oct 28 11:51:39 2005
@@ -630,6 +630,10 @@
Result result = new StreamResult(writer);
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ if (getEncoding() != null)
+ {
+ transformer.setOutputProperty(OutputKeys.ENCODING, getEncoding());
+ }
transformer.transform(source, result);
}
catch (TransformerException e)
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=329269&r1=329268&r2=329269&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 Fri Oct 28 11:51:39 2005
@@ -23,6 +23,7 @@
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringReader;
+import java.io.StringWriter;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
@@ -45,6 +46,9 @@
*/
public class TestXMLConfiguration extends TestCase
{
+ /** Constant for the used encoding.*/
+ static final String ENCODING = "ISO-8859-1";
+
/** The File that we test with */
private String testProperties = new File("conf/test.xml").getAbsolutePath();
private String testProperties2 = new File("conf/testDigesterConfigurationInclude1.xml").getAbsolutePath();
@@ -754,6 +758,38 @@
conf = new XMLConfiguration();
conf.load(file);
assertEquals("test3_yoge", conf.getString("yoge"));
+ }
+
+ /**
+ * Tests whether the encoding is written to the generated XML file.
+ */
+ public void testSaveWithEncoding() throws ConfigurationException
+ {
+ conf = new XMLConfiguration();
+ conf.setProperty("test", "a value");
+ conf.setEncoding(ENCODING);
+
+ StringWriter out = new StringWriter();
+ conf.save(out);
+ assertTrue("Encoding was not written to file", out.toString().indexOf(
+ "encoding=\"" + ENCODING + "\"") >= 0);
+ }
+
+ /**
+ * Tests whether a default encoding is used if no specific encoding is set.
+ * According to the XSLT specification (http://www.w3.org/TR/xslt#output)
+ * this should be either UTF-8 or UTF-16.
+ */
+ public void testSaveWithNullEncoding() throws ConfigurationException
+ {
+ conf = new XMLConfiguration();
+ conf.setProperty("testNoEncoding", "yes");
+ conf.setEncoding(null);
+
+ StringWriter out = new StringWriter();
+ conf.save(out);
+ assertTrue("Encoding was written to file", out.toString().indexOf(
+ "encoding=\"UTF-") >= 0);
}
/**
Modified: jakarta/commons/proper/configuration/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/configuration/trunk/xdocs/changes.xml?rev=329269&r1=329268&r2=329269&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/configuration/trunk/xdocs/changes.xml Fri Oct 28 11:51:39 2005
@@ -23,6 +23,11 @@
<body>
<release version="1.2-dev" date="in SVN">
+ <action dev="oheger" type="update" due-to="Kay Doebl" issue="37293">
+ XMLConfiguration now prints the used encoding in the xml declaration of
+ generated files. In earlier versions always the default encoding was
+ written.
+ </action>
<action dev="ebourg" type="update" issue="36991">
PropertiesConfiguration now translates properly the escaped unicode
characters (like \u1234) used in the property keys. This complies with
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org