cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Francesco Chicchiriccò <>
Subject Re: [c3] Implementing presentation logic in c3
Date Fri, 28 Oct 2011 09:31:37 GMT
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
>>> <shiro:notAuthenticated>
>>>       Please<a href="login.jsp">login</a>.
>>> </shiro:notAuthenticated>
>>> 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.
>>> <map:transform type="string-template">
>>>     <map:parameter name="isUser" value="{shiro:authenticated}"/>
>>> </map:transform>
>>> will fail then interpreting
>>> $if(!isUser)$
>>>     <a href="/logout">/logout</a>
>>> $else$
>>>     <a href="/login">/login</a>
>>> $endif$
>>> with
>>> ...
>>> Caused by: org.stringtemplate.v4.compiler.STException: null
>>> 	at org.stringtemplate.v4.compiler.Compiler.reportMessageAndThrowSTException(
>>> 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 
http://localhost:8888/string-template/generator and 

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

<a alt="$parameter$" href="$if(!booleanParameter)$
expression evaluated to true
expression evaluated to false

while this does not:

<element>expression evaluated to true</element>
<element>expression evaluated to false</element>

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?


Francesco Chicchiriccò

Apache Cocoon Committer and PMC Member

View raw message