On 28/10/2011 11:17, Thorsten Scherler wrote:
>>> I tried to use the "string-template" component but I am running into a problem when using $if(boolean)$.
>>> I am ATM integrating Apache Shiro, a security framework that performs authentication, authorization, cryptography, and session management, into c3 and want to use something in the spirit of their taglibs
>>> So what I did is I wrote a ShiroInterpreter implements LanguageInterpreter that can extract this info.
>>> However the interface LanguageInterpreter defines the return type to String.
>>> will fail then interpreting
>>> Caused by: org.stringtemplate.v4.compiler.STException: null
>>> at org.stringtemplate.v4.compiler.Compiler.reportMessageAndThrowSTException(Compiler.java:213) ~[ST4-4.0.4.jar:na]
>>> If I use only $isUser$ I get the correct value. Reading "Conditional subtemplates" 
>>> "You may only test whether an attribute is present or absent, preserving separation of model
>>> and view. The only exception is that if an attribute value is a Boolean object, it will test it for true/false."
>> I think you've hit a bug of StringTemplate transformer: see the attached patch (for cocoon-sample in C3 sources) using conditional and boolean value from sitemap; ST generator works well and ST transformer raises an exception similar to the one reported above.
> Ok I will have a look.
see attached a patch for cocoon-stringtemplate and cocoon-sample that
should fix your issue about $if$ with StringTemplateTransformer.
In fact, I've checked that problems arise with transformer only, while
generator is safe in this respect; this happens because generator let ST
handle the whole file, while transformer doesn't. Transformer's approach
makes it able, however, to parse ST expressions in XML attributes as well.
If you want to try my patch, just apply it to fresh C3 sources, do an
"mvn clean install" of cocoon-stringtemplate and afterwards launch "mvn
jetty:run" under cocoon-sample: you will be able to watch results at
I did not commit this yet because, as you can see from
StringTemplateTransformer's source, my patch is limited to "$if$" case,
and only when the whole $if$ evaluates to CDATA from XML point of view:
i.e. this work
while this does not:
expression evaluated to true
expression evaluated to false
As an alternative to my patch's approach, StringTemplateTransformer
could act in a way similar to StringTemplateGenerator's, i.e. buffering
the whole input document and passing it as a whole to ST: what do you think?
Apache Cocoon Committer and PMC Member