I'm not totally clear on exactly what functionality you need, but
usually folks who have this problem are good candidates for a template
engine. I've not used them myself and so don't know all the trade-offs,
but groovy.text.GStringTemplateEngine may be appropriate.
Jim
melix wrote:
> Hi,
>
> I'm trying to find out if there's any shorter way to evaluate a GString
> from Java code. The string to be evaluated comes from an XML
> configuration file and includes placeholders. My solution seems rather
> complex for such a basic need, and I'm quite sure there are situations
> where it doesn't work properly :
>
> Binding binding = new Binding();
> ...
> String evaluatedRegex = "\""+ org.apache.commons.lang.StringEscapeUtils.escapeJava(regex)+"\"";
> evaluatedRegex = new GroovyShell(binding).evaluate(evaluatedRegex).toString();
>
> I'd like to be able to write something like :
>
> String evaluatedRegex = new GString(regex, binding).toString();
>
> Or (cleaner) :
>
> String evaluatedRegex = GStringFactory.evaluate(regex, binding);
>
> Thanks
> View this message in context: Evaluating a GString
> <
http://www.nabble.com/Evaluating-a-GString-tp20184911p20184911.html>
> Sent from the groovy - user mailing list archive
> <
http://www.nabble.com/groovy---user-f11867.html> at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email