commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Oliver Heger (JIRA)" <>
Subject [jira] Commented: (LANG-482) Enhance StrSubstitutor to support nested ${var-${subvr}} expansion
Date Sat, 02 Oct 2010 19:23:32 GMT


Oliver Heger commented on LANG-482:

I did some experiments and have a working solution now (well, some more tests are needed).

I agree that this should be a feature which can be enabled or disabled. However, I am not
sure about the best way to pass this flag to the StrSubstitutor instance. There are lots of
different replace() methods, and it would probably make no sense to overload all of them with
an additional flag. Because the replace behavior is a more global setting it would be better
to set the flag when the instance is constructed. But this is not straightforward either because
there are many overloaded constructors.

One option would be to use the builder approach - we have already done this for other classes
in lang3. This is probably the most convenient way to create instances with different options.
I am unsure whether we should drop the existing constructors. Typically if a builder is used,
it is the only way to create instances of the associated class. But in terms of backwards
compatibility it would be better to keep the constructors.

OTOH StrSubstitutor is not immutable, there are setters for all properties. So a simple set
method for the new flag would do the trick.


> Enhance StrSubstitutor to support nested ${var-${subvr}} expansion
> ------------------------------------------------------------------
>                 Key: LANG-482
>                 URL:
>             Project: Commons Lang
>          Issue Type: Improvement
>          Components: lang.text.*
>            Reporter: Rob Walker
>            Priority: Minor
>             Fix For: 3.1
>         Attachments:
> t would be really handy of StrSubstitutor could support nested variable interpolation:
> org.osgi.framework.system.packages=org.osgi.framework; version=1.4.0, \
> org.osgi.service.packageadmin; version=1.2.0, \
> org.osgi.service.startlevel; version=1.1.0, \
> org.osgi.service.url; version=1.0.0, \
> org.osgi.util.tracker; version=1.3.3 \
> ${jre-${java.specification.version}}
> The process being to expand innermost variable references first and work outwards - this
allows for very advance config, such as the above, which can dynamically detect the Java version
and expand a JRE version specific property into the property being defined.
> Looking at the implementation, it seems it might be a fairly straightforward enhancement
> private int substitute(StrBuilder buf, int offset, int length, List priorVariables)
> The code already has the cyclic map in place.
> I already have code that achieves this within Apache Felix, so I will see if I can retro-fit
a similar model to the above and if so submit a patch. 

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

View raw message