commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r331016 - in /jakarta/commons/proper/configuration/trunk: src/java/org/apache/commons/configuration/PropertiesConfiguration.java src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java xdocs/changes.xml
Date Sat, 05 Nov 2005 18:58:56 GMT
Author: oheger
Date: Sat Nov  5 10:58:40 2005
New Revision: 331016

URL: http://svn.apache.org/viewcvs?rev=331016&view=rev
Log:
Updated PropertiesConfiguration to use the platform specific line separator when writing files.
Thanks to Kay Doebl for the patch.

Modified:
    jakarta/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/PropertiesConfiguration.java
    jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java
    jakarta/commons/proper/configuration/trunk/xdocs/changes.xml

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=331016&r1=331015&r2=331016&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
Sat Nov  5 10:58:40 2005
@@ -159,6 +159,9 @@
      */
     private static final String DEFAULT_ENCODING = "ISO-8859-1";
 
+    /** Constant for the platform specific line separator.*/
+    private static final String LINE_SEPARATOR = System.getProperty("line.separator");
+
     /** Constant for the radix of hex numbers.*/
     private static final int HEX_RADIX = 16;
 
@@ -383,12 +386,12 @@
                 {
                     out.writeComment(line);
                 }
-                out.write("\n");
+                out.writeln(null);
             }
 
             out.writeComment("written by PropertiesConfiguration");
             out.writeComment(new Date().toString());
-            out.write("\n");
+            out.writeln(null);
 
             Iterator keys = getKeys();
             while (keys.hasNext())
@@ -549,7 +552,7 @@
                 write(v);
             }
 
-            write('\n');
+            writeln(null);
         }
 
         /**
@@ -574,7 +577,7 @@
          */
         public void writeComment(String comment) throws IOException
         {
-            write("# " + comment + "\n");
+            writeln("# " + comment);
         }
 
         /**
@@ -605,6 +608,22 @@
             }
 
             return newkey.toString();
+        }
+
+        /**
+         * Helper method for writing a line with the platform specific line
+         * ending.
+         *
+         * @param s the content of the line (may be <b>null</b>)
+         * @throws IOException if an error occurs
+         */
+        private void writeln(String s) throws IOException
+        {
+            if (s != null)
+            {
+                write(s);
+            }
+            write(LINE_SEPARATOR);
         }
 
     } // class PropertiesWriter

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=331016&r1=331015&r2=331016&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
Sat Nov  5 10:58:40 2005
@@ -20,6 +20,7 @@
 import java.io.FileWriter;
 import java.io.PrintWriter;
 import java.io.StringReader;
+import java.io.StringWriter;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -397,5 +398,24 @@
         assertEquals(true, config.getBoolean("deeptest"));
         assertEquals(true, config.getBoolean("deepinclude"));
         assertFalse(config.containsKey("deeptestinvalid"));
+    }
+
+    /**
+     * Tests whether the correct line separator is used.
+     */
+    public void testLineSeparator() throws ConfigurationException
+    {
+        final String EOL = System.getProperty("line.separator");
+        conf = new PropertiesConfiguration();
+        conf.setHeader("My header");
+        conf.setProperty("prop", "value");
+
+        StringWriter out = new StringWriter();
+        conf.save(out);
+        String content = out.toString();
+        assertTrue("Header could not be found", content.indexOf("# My header"
+                + EOL + EOL) == 0);
+        assertTrue("Property could not be found", content
+                .indexOf("prop = value" + EOL) > 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=331016&r1=331015&r2=331016&view=diff
==============================================================================
--- jakarta/commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/configuration/trunk/xdocs/changes.xml Sat Nov  5 10:58:40 2005
@@ -31,7 +31,8 @@
       <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.
+        written. PropertiesConfiguration now always uses the platform specific
+        line separator when saving files.
       </action>
       <action dev="ebourg" type="update" issue="36991">
         PropertiesConfiguration now translates properly the escaped unicode



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message