You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Karr, David" <da...@wamu.net> on 2007/03/01 01:26:29 UTC

What tool can I use to substitute marked expressions in a string?

I know that there are several related tools in this area, but I'm not
sure from a superficial look exactly which one I need.

I just need to have a string with occurrences of substrings like
"${foo}", and I need to be able to replace that with a value specified
at run time.  I need to do this directly from Java, and I nee to be able
to specify both the variables (like "foo") and what values will be
substituted for them.

I thought I would do this with JEXL, but that seems to just take a
string like "foo" and not "... Stuff ... ${foo} ...".  I imagine I could
do this semi-manually, by searching for "${.*}" and processing the
contents.  If there's no packaged way to do this already, I'll go down
that path.

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


Re: What tool can I use to substitute marked expressions in a string?

Posted by Stephen Colebourne <sc...@btopenworld.com>.
Karr, David wrote:
> I know that there are several related tools in this area, but I'm not
> sure from a superficial look exactly which one I need.
> 
> I just need to have a string with occurrences of substrings like
> "${foo}", and I need to be able to replace that with a value specified
> at run time.  I need to do this directly from Java, and I nee to be able
> to specify both the variables (like "foo") and what values will be
> substituted for them.
> 
> I thought I would do this with JEXL, but that seems to just take a
> string like "foo" and not "... Stuff ... ${foo} ...".  I imagine I could
> do this semi-manually, by searching for "${.*}" and processing the
> contents.  If there's no packaged way to do this already, I'll go down
> that path.

Try commons-lang StrSubstitutor.

Stephen

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


RE: What tool can I use to substitute marked expressions in a string?

Posted by "Karr, David" <da...@wamu.net>.
That worked perfectly.  Thanks, Craig. 

> -----Original Message-----
> From: craigmcc@gmail.com [mailto:craigmcc@gmail.com] On 
> Behalf Of Craig McClanahan
> Sent: Wednesday, February 28, 2007 4:36 PM
> To: Jakarta Commons Users List
> Subject: Re: What tool can I use to substitute marked 
> expressions in a string?
> 
> On 2/28/07, Karr, David <da...@wamu.net> wrote:
> > I know that there are several related tools in this area, 
> but I'm not 
> > sure from a superficial look exactly which one I need.
> >
> > I just need to have a string with occurrences of substrings like 
> > "${foo}", and I need to be able to replace that with a 
> value specified 
> > at run time.  I need to do this directly from Java, and I nee to be 
> > able to specify both the variables (like "foo") and what 
> values will 
> > be substituted for them.
> >
> > I thought I would do this with JEXL, but that seems to just take a 
> > string like "foo" and not "... Stuff ... ${foo} ...".  I imagine I 
> > could do this semi-manually, by searching for "${.*}" and 
> processing 
> > the contents.  If there's no packaged way to do this 
> already, I'll go 
> > down that path.
> >
> 
> Have a look at Digester's "org.apache.commons.digester.substitution"
> package.  From the javadocs, it looks like 
> MultiVariableExpander can do what you're asking for.

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


Re: What tool can I use to substitute marked expressions in a string?

Posted by Craig McClanahan <cr...@apache.org>.
On 2/28/07, Karr, David <da...@wamu.net> wrote:
> I know that there are several related tools in this area, but I'm not
> sure from a superficial look exactly which one I need.
>
> I just need to have a string with occurrences of substrings like
> "${foo}", and I need to be able to replace that with a value specified
> at run time.  I need to do this directly from Java, and I nee to be able
> to specify both the variables (like "foo") and what values will be
> substituted for them.
>
> I thought I would do this with JEXL, but that seems to just take a
> string like "foo" and not "... Stuff ... ${foo} ...".  I imagine I could
> do this semi-manually, by searching for "${.*}" and processing the
> contents.  If there's no packaged way to do this already, I'll go down
> that path.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>

Have a look at Digester's "org.apache.commons.digester.substitution"
package.  From the javadocs, it looks like MultiVariableExpander can
do what you're asking for.

Craig

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