commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vinicius Carvalho <java.vinic...@gmail.com>
Subject Re: Commons Configuration - Variable interpolation not working
Date Tue, 29 Nov 2011 13:05:20 GMT
Tks, just saw that on values, we have some values that were not working. I
understand that interpolation should only happen on string values, but
limiting it to usage of getString would be a problem to me, the way we use
is to just use getProperty we don't mind the type for now.

I've fixed it with a hack, unfortunately we do need to have replacement on
keys as well.

Regards

On Tue, Nov 29, 2011 at 12:30 PM, Jörg Schaible <joerg.schaible@scalaris.com
> wrote:

> Hi,
>
> Vinicius Carvalho wrote:
>
> > Hi there! I'm trying to get Variable interpolation to work. But it seems
> > that either I missed something at the docs or there's a bug here.
> >
> > All I need is to replace a ${app} on my properties file to contain a
> > string instead
> >
> > so whenever I have ${app}.maxUsers=10 I want AppName.maxUsers=10
> >
> > Here's some code:
> >
> > private class AppInterpolator extends StrLookup{
> > @Override
> > public String lookup(String var) {
> > return "#{"+appName+"}";
> > }
> >  }
> >
> > ConfigurationInterpolator.registerGlobalLookup("app", new
> > AppInterpolator());
> > config = new CompositeConfiguration();
> > PropertiesConfiguration localProps = new
> >
>
> PropertiesConfiguration(this.getClass().getClassLoader().getResource(PROPERTIES_FILE_NAME));
> > this.config.addConfiguration(localProps);
> >
> >
> > But after using config.getProperty("") I've noticed that the property
> here
> > is ${app}.maxUsers and not AppName.maxUsers
> >
> > I've also noticed that it seems that PropertiesFile does not reference
> > ConfigurationInterpolator at all.
> >
> > Any ideas on how to fix this?
>
> Let me cite the Javadoc or AbstractConfiguration:
>
> "Support for variable interpolation. Property values containing special
> variable tokens (like ${var}) will be replaced by their corresponding
> values."
>
> *values*, not *keys*
>
> - Jörg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message