Java Mailing List Archive

http://www.junlu.com/

Home » FreeMarker-user »

Re: [FreeMarker-user] Detect invalid directives

John Todd

2011-10-19

Replies: Find Java Web Hosting

Author LoginPost Reply
On 10/19/11 04:29, Daniel Dekany wrote:
> Wednesday, October 19, 2011, 5:55:18 AM, John Todd wrote:
>
>> Hello,
>>
>>  I would like to handle invalid directives however they are just
>> passing through the templating engine as text, e.g. using the following
>> FTL "blah.ftl":
>>
>> This is [#blah]content[/#blah]. This is [#fu] content.
> That's not possible, unless you pre-process the templates with a
> custom TemplateLoader that replaces "[#blah]" with "[[#-- --]#blah]"
> or like.
>
> Out of curiosity, why do you need this?
We use the templating engine extensively for on-demand personalization
of content and would like to reject templating requests at the time the
template is passed to our system if the template contains unknown
directives and just reject the request.

So, you're saying it's not possible to catch such exceptions or the
behavior I'm seeing is not possible?

thx,
jt

>> and the code:
>>
>> public class App {
>>
>>   public static void main(String[] args) throws Exception {
>>      Configuration cfg = new Configuration();
>>      cfg.setTagSyntax(Configuration.SQUARE_BRACKET_TAG_SYNTAX);
>>    
>>      cfg.setDirectoryForTemplateLoading(new
>> File(System.getProperty("user.dir")));
>>    
>>      System.out.println("Compiling template: blah.ftl");
>>      FileReader reader = new
>> FileReader(System.getProperty("user.dir") + "/blah.ftl");
>>      // Expect ParseException
>>      Template template = new Template("blah.ftl", reader, cfg);
>>
>>      System.out.println("Getting template from Configuration.");
>>      // Also expect ParseException
>>      template = cfg.getTemplate("blah.ftl");
>>      StringWriter writer = new StringWriter();
>>      template.process(new HashMap(), writer);
>>      System.out.println("Output: " + writer.toString());
>>   }
>> }
>>
>> I get the output:
>>
>> This is [#blah]content[/#blah]. This is [#fu] content.
>>
>> In each Template reference, I'm expecting a compilation error w/
>> "Unknown directive" per the FMParser.jj grammar. Any suggestions?
>>
>> Thanks,
>>
>> John T.


------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2d-oct
_______________________________________________
FreeMarker-user mailing list
FreeMarker-user@(protected)
https://lists.sourceforge.net/lists/listinfo/freemarker-user
©2008 junlu.com - Jax Systems, LLC, U.S.A.