commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rzo <...@gmx.de>
Subject Re: [Configuration]JEXL question
Date Sat, 29 Aug 2009 18:28:36 GMT
Ralph,

thanks for the fast reply.
In the mean time i decided to try it with groovy.
I have written a groovy expression interpolation which I will be using 
in my project.
If you are interested in this i could put the files on jira.

- Ron


Ralph Goers wrote:
>
> On Aug 29, 2009, at 10:35 AM, Ralph Goers wrote:
>
>>
>> On Aug 29, 2009, at 6:33 AM, rzo wrote:
>>
>>> Hello,
>>>
>>> thanks for mentioning jexl scripting.
>>> I tried it out and have found the following issue:
>>>
>>> evaluating the following:
>>>
>>> test=${expr:if (System.getProperty("user.home").startsWith("C")) 
>>> {"x";} else {"z";}}
>>>
>>> does not seem to work.
>>> Debuging shows that the expression forwarded to jexl is:
>>>
>>> if (System.getProperty("user.home").startsWith("C")) {"x";
>>>
>>> is this a bug ? or is there a way to escape the brackets within 
>>> ${...} ?
>>>
>>
>> The "bug" is actually the way 
>> org.apache.commons.lang.text.StrSubstitutor works. It can configured 
>> be with prefix and suffix characters - the defaults are '{' and '}' 
>> and after finding the prefix it just searches for the first occurance 
>> of the suffix character - unless it finds a recursive variable. So 
>> the string passed to ConfigurationInterpolator is what you show above.
>>
>> However, it might be possible to override the suffix matcher to look 
>> for an escape character.
>>
>
> It occurs to me though that just using a different suffix matcher will 
> not remove the escape character.
>
> One other thought. StrSubstitutor allows the prefix and suffix 
> characters to be replaced, so you should be able to do
>
> conf.getSubstitutor().setVariablePrefix('`');
> conf.getSubstitutor().setVariablesuffix('`');
>
> and then use test="$`expr:if 
> (System.getProperty("user.home").startsWith("C")) {"x";} else {"z";}`
>
> It also supports using strings so you could do:
>
> conf.getSubstitutor.setVariableSuffix("$}";
>
> and then test="${expr:if 
> (System.getProperty("user.home").startsWith("C")) {"x";} else {"z";}$}
>
> Of course, then you would have to use those prefix and suffix 
> characters throughout that configuration.
>
> Ralph
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>


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


Mime
View raw message