You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by MASTRELLA STEFANO <sm...@sogei.it> on 2006/11/30 11:22:17 UTC

Variable interpolation in composite configuration

Hi everybody,

What I need to is to reference some key in a configuration file from
another config file.
As an example cosider to have this configuration file for the
CompositeConfiguration


**********************composite-config.xml**********************

<?xml version="1.0" encoding="ISO-8859-1" ?>

<configuration>
  <properties fileName="config1.properties"/>
  <xml fileName="config2.xml"/>
</configuration>

and the following configuration file specified above

**********************config1.properties**********************
key1.property=1

********************** config2.xml **********************

<conf>
   <value name="${key1.property }"/>
</conf>

As the CompositeConfiguration load first the cofig1.properties when I
try to look for the key "value[@name]" or "value/@name" (xpath version)
with this snippet of code


ConfigurationFactory factory = new ConfigurationFactory();

URL configURL = new File("config-composite.xml").toURL();

factory.setConfigurationURL(configURL);

Configuration config = factory.getConfiguration();

String prop = config.getString("value[@name]");


I'd expected to see the value "1" as defined in config.properties,
instead of ${key1.property}.

Is there any mistakes in what I thought?
There's something more to do for variable interpolation?

TIA

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


Re: Variable interpolation in composite configuration

Posted by Oliver Heger <ol...@oliver-heger.de>.
Hi,

interpolation should work with a CompositeConfiguration. There are some 
unit tests that check this.

 From your XML configuration file:
 > ********************** config2.xml **********************
 >
 > <conf>
 >    <value name="${key1.property }"/>
 > </conf>

There is an additional space before the closing curly bracket in the 
variable. Is this a typo? This will cause the problem.

Oliver

MASTRELLA STEFANO wrote:
> Hi everybody,
> 
> What I need to is to reference some key in a configuration file from
> another config file.
> As an example cosider to have this configuration file for the
> CompositeConfiguration
> 
> 
> **********************composite-config.xml**********************
> 
> <?xml version="1.0" encoding="ISO-8859-1" ?>
> 
> <configuration>
>   <properties fileName="config1.properties"/>
>   <xml fileName="config2.xml"/>
> </configuration>
> 
> and the following configuration file specified above
> 
> **********************config1.properties**********************
> key1.property=1
> 
> ********************** config2.xml **********************
> 
> <conf>
>    <value name="${key1.property }"/>
> </conf>
> 
> As the CompositeConfiguration load first the cofig1.properties when I
> try to look for the key "value[@name]" or "value/@name" (xpath version)
> with this snippet of code
> 
> 
> ConfigurationFactory factory = new ConfigurationFactory();
> 
> URL configURL = new File("config-composite.xml").toURL();
> 
> factory.setConfigurationURL(configURL);
> 
> Configuration config = factory.getConfiguration();
> 
> String prop = config.getString("value[@name]");
> 
> 
> I'd expected to see the value "1" as defined in config.properties,
> instead of ${key1.property}.
> 
> Is there any mistakes in what I thought?
> There's something more to do for variable interpolation?
> 
> TIA
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 


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