You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Peter Verhas (JIRA)" <ji...@apache.org> on 2008/12/21 13:18:44 UTC

[jira] Created: (CONFIGURATION-354) XML configuration handles non-default list delimiter bad way

XML configuration handles non-default list delimiter bad way
------------------------------------------------------------

                 Key: CONFIGURATION-354
                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-354
             Project: Commons Configuration
          Issue Type: Bug
    Affects Versions: 1.5
         Environment: Windows XP Home edition, Java 1.6.0_07
            Reporter: Peter Verhas
            Priority: Minor


When setting the list separator character the XML configuration engine does not handle the lists properly. Sample code:

Junit test code:
{code}
    public void testConfig() {
        CompositeConfiguration conf = null;
        try {
            conf = (CompositeConfiguration) new ConfigurationFactory("config.xml").getConfiguration();
        } catch (ConfigurationException ex) {
            Logger.getLogger(TestConfig.class.getName()).log(Level.SEVERE, null, ex);
            return;
        }
        PrintStream o = System.out;
        conf.setListDelimiter(conf.getString("list.delimiter").charAt(0));
        o.println("c=" + conf.getString("c"));
        o.println("x="+conf.getString("key.subkey(1)"));
        o.print(System.getProperty("java.version"));
    }
{code}

The config.xml contains
{code}
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <xml fileName="application.xml"/>
</configuration>
{code}

and finally the application.xml is
{code}
<?xml version="1.0" encoding="windows-1250"?>
<konfig>
    <list><delimiter>\,</delimiter></list>
    <key>
        <subkey>one,two,three</subkey>
        <subkey >four</subkey>
    </key>
    <c>${key.subkey(1)}</c>
</konfig>
{code}

The resulting output is:
{code}
c=two
x=two
1.6.0_07
{code}

This is correct so far. This is the case when I comment out the {{setListDelimiter}} code line. After this I change the application.xml to
{code}
<?xml version="1.0" encoding="windows-1250"?>
<konfig>
    <list><delimiter>;</delimiter></list>
    <key>
        <subkey>one;two;three</subkey>
        <subkey >four</subkey>
    </key>
    <c>${key.subkey(1)}</c>
</konfig>
{code}

even though I expect the same result what I got was:
{code}
c=four
x=four
1.6.0_07
{code}

Do I miss some point or {{setListDelimiter}} does not work for XML files?


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (CONFIGURATION-354) XML configuration handles non-default list delimiter bad way

Posted by "Peter Verhas (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CONFIGURATION-354?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Peter Verhas closed CONFIGURATION-354.
--------------------------------------

       Resolution: Fixed
    Fix Version/s: 1.5

I tried to modify the {{config.xml}} file as you pointed and it works fine. This also means that now I did try it out for {{ConfigurationFactory}}. :-)

I was not aware that {{config.txt}} may also define the list delimiter.

As for my case this is a very good practice. I am developing company policy regarding the use of commons config and I will discourage to use list inside XML configuration. This means that listDelimiter will be set to something like

{code}
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <xml fileName="application.xml" listDelimiter="\u0000"/>
</configuration>
{code}

which will prevent to interpret any probable character as list delimiter.

Thanks,
Peter

> XML configuration handles non-default list delimiter bad way
> ------------------------------------------------------------
>
>                 Key: CONFIGURATION-354
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-354
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.5
>         Environment: Windows XP Home edition, Java 1.6.0_07
>            Reporter: Peter Verhas
>            Priority: Minor
>             Fix For: 1.5
>
>
> When setting the list separator character the XML configuration engine does not handle the lists properly. Sample code:
> Junit test code:
> {code}
>     public void testConfig() {
>         CompositeConfiguration conf = null;
>         try {
>             conf = (CompositeConfiguration) new ConfigurationFactory("config.xml").getConfiguration();
>         } catch (ConfigurationException ex) {
>             Logger.getLogger(TestConfig.class.getName()).log(Level.SEVERE, null, ex);
>             return;
>         }
>         PrintStream o = System.out;
>         conf.setListDelimiter(conf.getString("list.delimiter").charAt(0));
>         o.println("c=" + conf.getString("c"));
>         o.println("x="+conf.getString("key.subkey(1)"));
>         o.print(System.getProperty("java.version"));
>     }
> {code}
> The config.xml contains
> {code}
> <?xml version="1.0" encoding="utf-8"?>
> <configuration>
>   <xml fileName="application.xml"/>
> </configuration>
> {code}
> and finally the application.xml is
> {code}
> <?xml version="1.0" encoding="windows-1250"?>
> <konfig>
>     <list><delimiter>\,</delimiter></list>
>     <key>
>         <subkey>one,two,three</subkey>
>         <subkey >four</subkey>
>     </key>
>     <c>${key.subkey(1)}</c>
> </konfig>
> {code}
> The resulting output is:
> {code}
> c=two
> x=two
> 1.6.0_07
> {code}
> This is correct so far. This is the case when I comment out the {{setListDelimiter}} code line. After this I change the application.xml to
> {code}
> <?xml version="1.0" encoding="windows-1250"?>
> <konfig>
>     <list><delimiter>;</delimiter></list>
>     <key>
>         <subkey>one;two;three</subkey>
>         <subkey >four</subkey>
>     </key>
>     <c>${key.subkey(1)}</c>
> </konfig>
> {code}
> even though I expect the same result what I got was:
> {code}
> c=four
> x=four
> 1.6.0_07
> {code}
> Do I miss some point or {{setListDelimiter}} does not work for XML files?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CONFIGURATION-354) XML configuration handles non-default list delimiter bad way

Posted by "Oliver Heger (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CONFIGURATION-354?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12658399#action_12658399 ] 

Oliver Heger commented on CONFIGURATION-354:
--------------------------------------------

The handling of list delimiters is always a source of problems and confusion.

However, in this case it really works as designed. The problem is that you call {{setListDelimiter()}} *after* loading the configuration. Citing the Javadocs of {{setListDelimiter()}}:

??Change the list delimiter for this configuration. Note: this change will only be effective for new parsings. If you want it to take effect for all loaded properties use the no arg constructor and call this method before setting the source.??

In your case this means you have to specify the list delimiter before the configuration is actually loaded by the configuration factory. This can be done in {{config.xml}} by specifying an additional attribute for the {{<xml>}} element:

{code}
  <xml fileName="application.xml" listDelimiter=";"/>
{code}

(Note: I have not tried this out for {{ConfigurationFactory}}, but it will work using {{DefaultConfigurationBuilder}}. It is recommended to use the latter class; its API is almost identical to {{ConfigurationFactory}}, but it provides many more features.)

You first experiment works because with "," you are using the default list delimiter. So the call to {{setListDelimiter()}} does not change anything.

> XML configuration handles non-default list delimiter bad way
> ------------------------------------------------------------
>
>                 Key: CONFIGURATION-354
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-354
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.5
>         Environment: Windows XP Home edition, Java 1.6.0_07
>            Reporter: Peter Verhas
>            Priority: Minor
>
> When setting the list separator character the XML configuration engine does not handle the lists properly. Sample code:
> Junit test code:
> {code}
>     public void testConfig() {
>         CompositeConfiguration conf = null;
>         try {
>             conf = (CompositeConfiguration) new ConfigurationFactory("config.xml").getConfiguration();
>         } catch (ConfigurationException ex) {
>             Logger.getLogger(TestConfig.class.getName()).log(Level.SEVERE, null, ex);
>             return;
>         }
>         PrintStream o = System.out;
>         conf.setListDelimiter(conf.getString("list.delimiter").charAt(0));
>         o.println("c=" + conf.getString("c"));
>         o.println("x="+conf.getString("key.subkey(1)"));
>         o.print(System.getProperty("java.version"));
>     }
> {code}
> The config.xml contains
> {code}
> <?xml version="1.0" encoding="utf-8"?>
> <configuration>
>   <xml fileName="application.xml"/>
> </configuration>
> {code}
> and finally the application.xml is
> {code}
> <?xml version="1.0" encoding="windows-1250"?>
> <konfig>
>     <list><delimiter>\,</delimiter></list>
>     <key>
>         <subkey>one,two,three</subkey>
>         <subkey >four</subkey>
>     </key>
>     <c>${key.subkey(1)}</c>
> </konfig>
> {code}
> The resulting output is:
> {code}
> c=two
> x=two
> 1.6.0_07
> {code}
> This is correct so far. This is the case when I comment out the {{setListDelimiter}} code line. After this I change the application.xml to
> {code}
> <?xml version="1.0" encoding="windows-1250"?>
> <konfig>
>     <list><delimiter>;</delimiter></list>
>     <key>
>         <subkey>one;two;three</subkey>
>         <subkey >four</subkey>
>     </key>
>     <c>${key.subkey(1)}</c>
> </konfig>
> {code}
> even though I expect the same result what I got was:
> {code}
> c=four
> x=four
> 1.6.0_07
> {code}
> Do I miss some point or {{setListDelimiter}} does not work for XML files?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.