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

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

    [ 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.