commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <oliver.he...@oliver-heger.de>
Subject Re: [configuration] Variable Interpolation doesn't happen in subset() and configurationAt()
Date Fri, 01 Dec 2006 18:31:57 GMT
I will have a look. Maybe the problem has something to do with the 
conversion of the properties configuration to a hierarchical one?

Oliver

Mark Diggory wrote:
> Actually, your example works for me too, but my real case still doesn't
> heres more detail:
> 
> my instatiation of Configuration looks more like this
> 
> CombinedConfiguration configuration = new CombinedConfiguration();
>> configuration.addConfiguration(
>>                 new PropertiesConfiguration(new
>> File(configProperty).toURL())
>>             );
>>
> 
> My properties file looks like this:
> 
> # DSpace installation directory
>> dspace.dir = /dspace
>> # Example Apache HTTPD configuration
>> # config.template.apache13.conf = ${dspace.dir}/config/httpd.conf
>> config.template.log4j.properties = ${dspace.dir}/config/log4j.properties
>> config.template.log4j-handle-plugin.properties = ${dspace.dir
>> }/config/log4j-handle-plugin.properties
>> config.template.oaicat.properties = 
>> ${dspace.dir}/config/oaicat.properties
>>
> 
> I then go on to do my test:
> 
> 
>>         System.out.println(configuration.getString("dspace.dir"));
>>         System.out.println(configuration.getString("
>> config.template.log4j.properties"));
>>         System.out.println(configuration.getString("
>> config.template.log4j-handle-plugin.properties"));
>>         System.out.println(configuration.getString("
>> config.template.oaicat.properties"));
>>
>>         Configuration subset = configuration.subset("config.template");
>>
>>         this.assertEquals(
>>                     configuration.getString("
>> config.template.log4j.properties"),
>>                     subset.getString("log4j.properties")
>>                     );
>>
>>         this.assertEquals(
>>                 configuration.getString("
>> config.template.log4j-handle-plugin.properties"),
>>                 subset.getString("log4j-handle-plugin.properties")
>>                 );
>>
>>         this.assertEquals(
>>                 
>> configuration.getString("config.template.oaicat.properties
>> "),
>>                 subset.getString("oaicat.properties")
>>                 );
>>
>>
> 
> Thanks,
> Mark
> 
> On 11/30/06, Oliver Heger <oliver.heger@oliver-heger.de> wrote:
>>
>> Mark Diggory wrote:
>> > I'm trying to use variable interpolation in version 1.3 I'm unsure of
>> the
>> > behavior with Sub-configurations. I'm wondering if interpolation should
>> > work
>> > in these as well (i.e. using the entire configuration to interpolate
>> > against. For instance if I have
>> >
>> > base.dir=/home/foo
>> >
>> > test.absolute.dir.x=${base.dir}/mypath
>> > test.absolute.dir.y=${base.dir}/mypath1
>> > test.absolute.dir.z=${base.dir}/mypath2
>> >
>> > If I call something like:
>> >
>> > Configuration config = configuration.configurationAt("test.absolute.dir
>> ");
>> > for (Iterator iter = config.getKeys(); iter.hasNext();)
>> >        {
>> >            String key = (String) iter.next();
>> >            System.out.println(key + "=" + config.getString(key));
>> >        }
>> >
>> > this prints out
>> >
>> > x=${base.dir}/mypath
>> > y=${base.dir}/mypath1
>> > z=${base.dir}/mypath2
>> >
>> > I was naively expecting
>> >
>> > x=/home/foo/mypath
>> > y=/home/foo/mypath1
>> > z=/home/foo/mypath2
>> >
>> > Thoughts?
>> > Mark
>> >
>>
>> Not sure what happens here. Based on your code fragment I added the
>> following test case to TestSubnodeConfiguration [1]:
>>
>>
>>      public void testInterpolationFromConfigurationAt()
>>      {
>>          parent.addProperty("base.dir", "/home/foo");
>>          parent.addProperty("test.absolute.dir.dir1", "${base.dir
>> }/path1");
>>          parent.addProperty("test.absolute.dir.dir2", "${base.dir
>> }/path2");
>>          parent.addProperty("test.absolute.dir.dir3", "${base.dir
>> }/path3");
>>
>>          Configuration sub = parent.configurationAt("test.absolute.dir");
>>          for(int i = 1; i < 4; i++)
>>          {
>>              assertEquals("Wrong interpolation in parent",
>> "/home/foo/path" + i, parent.getString("test.absolute.dir.dir" + i));
>>              assertEquals("Wrong interpolation in subnode",
>> "/home/foo/path" + i, sub.getString("dir" + i));
>>          }
>>      }
>>
>> and it works. SubnodeConfiguration overloads the interpolate() method
>> and calls interpolate() on its parent. So the whole key should be
>> evaluated.
>>
>> Don't know why you get different results. Do you use special expression
>> engines or something like that?
>>
>> Oliver
>>
>> [1]
>>
>> http://svn.apache.org/repos/asf/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestSubnodeConfiguration.java

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


Mime
View raw message