Commons Configuration
  1. Commons Configuration
  2. CONFIGURATION-41

[configuration] Output format of FileConfiguration classes

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.1
    • Fix Version/s: 1.2
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: Windows 2000
      Platform: Other

      Description

      I am using Commons Configuration 1.1.

      Saving 'FielConfiguration's the configuration files will be overwritten every time.
      Bad if you have formatted them with descriptions and comments ... but this is
      not so important.

      Not so good is, that in the class:

      PropertiesConfiguration:
      '\n' is used as "line separator" and not the "System.getProperty("line.separator")".
      So, on Windows systems the configuration files are badly readable.

      XMLConfiguration:
      The encoding is not looped though to the encoding in the XML head declaration.
      Every time "UTF-8" is set (<?xml version="1.0" encoding="UTF-8"?>)
      I would prefer that my encoding (setEncoding()) is reflected in the XML document.

      Is there a reason that it is implemented like you do?

      Attached are patches which would resolve the problems (if you want):

      PropertiesConfiguration.java:

      properties_lineseparator.patch

      136a137,138
      > private static final String lineSeparator =
      System.getProperty("line.separator");
      >
      344c346
      < out.write("\n");

      > out.write(lineSeparator);
      349c351
      < out.write("\n");

      > out.write(lineSeparator);
      486c488
      < write('\n');

      > write(lineSeparator);
      511c513
      < write("# " + comment + "\n");

      > write("# " + comment + lineSeparator);

      XMLConfiguration.java:

      XML_encoding.patch
      446a447
      > transformer.setOutputProperty(OutputKeys.ENCODING, getEncoding());

        Activity

        Hide
        Kay Doebl added a comment -

        Created an attachment (id=16829)
        Patch for the properties lineSeparator problem

        Show
        Kay Doebl added a comment - Created an attachment (id=16829) Patch for the properties lineSeparator problem
        Hide
        Kay Doebl added a comment -

        Created an attachment (id=16830)
        Patch for the encoding problem

        Show
        Kay Doebl added a comment - Created an attachment (id=16830) Patch for the encoding problem
        Hide
        Emmanuel Bourg added a comment -

        Good point for the line separator, that makes sense to use the system line
        separator. java.util.Properties uses BufferedWriter.newLine() which uses the
        line.separator system property.

        Regarding the encoding with XMLConfiguration, did you try with a nightly build ?

        Show
        Emmanuel Bourg added a comment - Good point for the line separator, that makes sense to use the system line separator. java.util.Properties uses BufferedWriter.newLine() which uses the line.separator system property. Regarding the encoding with XMLConfiguration, did you try with a nightly build ?
        Hide
        Oliver Heger added a comment -

        XMLConfiguration indeed did not output any specific encoding, so that the
        default encoding was always used. I added two test cases and applied the patch
        for that part of this issue.

        Many thanks!

        It would be nice if XMLConfiguration also could detect the encoding from parsed
        documents. However I have not found a portable way to do this yet. With JDK 1.5
        it is easy, but for older versions?

        Show
        Oliver Heger added a comment - XMLConfiguration indeed did not output any specific encoding, so that the default encoding was always used. I added two test cases and applied the patch for that part of this issue. Many thanks! It would be nice if XMLConfiguration also could detect the encoding from parsed documents. However I have not found a portable way to do this yet. With JDK 1.5 it is easy, but for older versions?
        Hide
        Oliver Heger added a comment -

        Patch applied for PropertiesConfiguration with some tweaks. Thanks again!

        Show
        Oliver Heger added a comment - Patch applied for PropertiesConfiguration with some tweaks. Thanks again!

          People

          • Assignee:
            Unassigned
            Reporter:
            Kay Doebl
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development