How does one analyse a FreeMarker template??

11 messages Options
Embed this post
Permalink
TomFennelly

How does one analyse a FreeMarker template??

Reply Threaded More More options
Print post
Permalink
Hi.

I would like to be able to analyse a FreeMarker template. I thought I
had the answer when I saw I could access the root TemplateElement
through the Template instance, but alas, when I look closer (at
IteratorBlock, DollarVariable etc) I see that the info I'd like access
to on these objects is private, with no getter methods etc.

Is there another way I can go about this?

Regards,

Tom.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Guo Du

Re: How does one analyse a FreeMarker template??

Reply Threaded More More options
Print post
Permalink
On Tue, Nov 10, 2009 at 11:14 PM, Tom Fennelly <[hidden email]> wrote:
> I would like to be able to analyse a FreeMarker template. I thought I
> had the answer when I saw I could access the root TemplateElement
> through the Template instance, but alas, when I look closer (at

FreeMarker is very dynamic, it's not easy to tell the output in
runtime unless it's been rendered.

Alternative, you could do static analysis the  template by track the
template source used by provider your own template loader:
freemarker.template.Configuration.setTemplateLoader

Good luck!

-Guo

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
TomFennelly

Re: How does one analyse a FreeMarker template??

Reply Threaded More More options
Print post
Permalink
Thanks Guo...

Guo Du wrote:
> FreeMarker is very dynamic, it's not easy to tell the output in
> runtime unless it's been rendered.
>  
I'm not actually trying to figure out the output that a template might
produce.  I'm looking to get the "model" that describes a given
FreeMarker template.  The TemplateElement (and its implementations)
returned from the Template.getRootTreeNode() would be perfect for what I
want, accept that all the interesting data they have is private and not
exposed via getters - see the IteratorBlock and DollarVariable classes.
> Alternative, you could do static analysis the  template by track the
> template source used by provider your own template loader:
> freemarker.template.Configuration.setTemplateLoader
Sure... I wanted to avoid writing the template analysis code myself, if
possible.  That sounds a bit like reinventing the wheel if this is
something that the FreeMarker runtime API can already do.

Thanks for your help Guo!!!

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Daniel Dekany

Re: How does one analyse a FreeMarker template??

Reply Threaded More More options
Print post
Permalink
In reply to this post by TomFennelly
Wednesday, November 11, 2009, 12:14:25 AM, Tom Fennelly wrote:

> Hi.
>
> I would like to be able to analyse a FreeMarker template. I thought I
> had the answer when I saw I could access the root TemplateElement
> through the Template instance, but alas, when I look closer (at
> IteratorBlock, DollarVariable etc) I see that the info I'd like access
> to on these objects is private, with no getter methods etc.
>
> Is there another way I can go about this?

There isn't... except, of course, that you copy the relevant parts of
the project, creating your own parser for this purpose. The license
allows that. (FM 2.4 will have much better API for this kind of thing,
as you can see in 2.4preview-1 release, but it's a question if there
will be a 2.4-final ever...)

> Regards,
>
> Tom.

--
Best regards,
 Daniel Dekany


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
JeremyChone

Re: How does one analyse a FreeMarker template??

Reply Threaded More More options
Print post
Permalink
I really hope there will be a 2.4-final, it really really looks great. 

On Wed, Nov 11, 2009 at 8:15 AM, Daniel Dekany <[hidden email]> wrote:
Wednesday, November 11, 2009, 12:14:25 AM, Tom Fennelly wrote:

> Hi.
>
> I would like to be able to analyse a FreeMarker template. I thought I
> had the answer when I saw I could access the root TemplateElement
> through the Template instance, but alas, when I look closer (at
> IteratorBlock, DollarVariable etc) I see that the info I'd like access
> to on these objects is private, with no getter methods etc.
>
> Is there another way I can go about this?

There isn't... except, of course, that you copy the relevant parts of
the project, creating your own parser for this purpose. The license
allows that. (FM 2.4 will have much better API for this kind of thing,
as you can see in 2.4preview-1 release, but it's a question if there
will be a 2.4-final ever...)

> Regards,
>
> Tom.

--
Best regards,
 Daniel Dekany


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user



--
Jeremy Chone
+1 415 699 9912
CTO, VP Product Development and Operations,
www.iJuris.com

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Guo Du

Re: How does one analyse a FreeMarker template??

Reply Threaded More More options
Print post
Permalink
In reply to this post by TomFennelly
On Tue, Nov 10, 2009 at 11:50 PM, Tom Fennelly <[hidden email]> wrote:
> FreeMarker template.  The TemplateElement (and its implementations)
> returned from the Template.getRootTreeNode() would be perfect for what I
> want, accept that all the interesting data they have is private and not
> exposed via getters - see the IteratorBlock and DollarVariable classes.

You could use reflect api to get the field event it's private. It's
kind of hack instead of proper solution anyway :(
http://tutorials.jenkov.com/java-reflection/private-fields-and-methods.html

-Guo

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
TomFennelly

Re: How does one analyse a FreeMarker template??

Reply Threaded More More options
Print post
Permalink
In reply to this post by Daniel Dekany
Thanks Daniel.

I was going to try avoid having to create a new parser with javacc by
trying to extract the info manually from the getNodeName and
getDescription methods... i.e.... a total hack.  After a little
investigation, I think it might be a hack too far, so I think I'll go
back again and look at creating a new parser :)

Thanks for the help!!

T.


Daniel Dekany wrote:

> Wednesday, November 11, 2009, 12:14:25 AM, Tom Fennelly wrote:
>
>  
>> Hi.
>>
>> I would like to be able to analyse a FreeMarker template. I thought I
>> had the answer when I saw I could access the root TemplateElement
>> through the Template instance, but alas, when I look closer (at
>> IteratorBlock, DollarVariable etc) I see that the info I'd like access
>> to on these objects is private, with no getter methods etc.
>>
>> Is there another way I can go about this?
>>    
>
> There isn't... except, of course, that you copy the relevant parts of
> the project, creating your own parser for this purpose. The license
> allows that. (FM 2.4 will have much better API for this kind of thing,
> as you can see in 2.4preview-1 release, but it's a question if there
> will be a 2.4-final ever...)
>
>  
>> Regards,
>>
>> Tom.
>>    
>
>  

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
TomFennelly

Re: How does one analyse a FreeMarker template??

Reply Threaded More More options
Print post
Permalink
In reply to this post by Guo Du
Yeah... can't take the risk of doing that Guo... it will too likely
result in security exceptions!!

Thanks for the suggestion.


Guo Du wrote:

> On Tue, Nov 10, 2009 at 11:50 PM, Tom Fennelly <[hidden email]> wrote:
>  
>> FreeMarker template.  The TemplateElement (and its implementations)
>> returned from the Template.getRootTreeNode() would be perfect for what I
>> want, accept that all the interesting data they have is private and not
>> exposed via getters - see the IteratorBlock and DollarVariable classes.
>>    
>
> You could use reflect api to get the field event it's private. It's
> kind of hack instead of proper solution anyway :(
> http://tutorials.jenkov.com/java-reflection/private-fields-and-methods.html
>
> -Guo
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> FreeMarker-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>
>  

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Jonathan Revusky-3

Re: How does one analyse a FreeMarker template??

Reply Threaded More More options
Print post
Permalink
In reply to this post by Daniel Dekany
On Wed, Nov 11, 2009 at 5:15 PM, Daniel Dekany <[hidden email]> wrote:

> Wednesday, November 11, 2009, 12:14:25 AM, Tom Fennelly wrote:
>
>> Hi.
>>
>> I would like to be able to analyse a FreeMarker template. I thought I
>> had the answer when I saw I could access the root TemplateElement
>> through the Template instance, but alas, when I look closer (at
>> IteratorBlock, DollarVariable etc) I see that the info I'd like access
>> to on these objects is private, with no getter methods etc.
>>
>> Is there another way I can go about this?
>
> There isn't... except, of course, that you copy the relevant parts of
> the project, creating your own parser for this purpose. The license
> allows that. (FM 2.4 will have much better API for this kind of thing,
> as you can see in 2.4preview-1 release, but it's a question if there
> will be a 2.4-final ever...)

Well, I would encourage Tom to use the 2.4 preview that is available.
That, after all, is why one uses a preview or beta version of
software, isn't it? That the bleeding edge stuff has features that you
need that are lacking in the stable version.

In any case, one can continue to use 2.3.15 in production to render
templates, but use the 2.4 for the software that analyzes templates,
no?

JR


>
>> Regards,
>>
>> Tom.
>
> --
> Best regards,
>  Daniel Dekany
>
>
> ------------------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
> trial. Simplify your report design, integration and deployment - and focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
> _______________________________________________
> FreeMarker-user mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/freemarker-user
>

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
TomFennelly

Re: How does one analyse a FreeMarker template??

Reply Threaded More More options
Print post
Permalink

Jonathan Revusky wrote:
> Well, I would encourage Tom to use the 2.4 preview that is available.
> That, after all, is why one uses a preview or beta version of
> software, isn't it? That the bleeding edge stuff has features that you
> need that are lacking in the stable version.
>
> In any case, one can continue to use 2.3.15 in production to render
> templates, but use the 2.4 for the software that analyzes templates,
> no?
>  

Hi Jonathan.

As it turns out, we will actually need the ability to analyse FreeMarker
templates in production.

A little context.... we (JBoss) are building Eclipse data mapping tools
(as part of JBoss Tools), whereby a user selects a target message model
(XSD, CSV, EDI etc schemas) and is able to use the tooling to map data
onto a representation of the selected model.  To cut a long story
short... the plan is to have the eclipse tooling generate FreeMarker
templates based on the chosen model + the mappings.  The generated
templates will be used by the runtime transformation engine (Smooks).  
So, the eclipse tooling needs to be able to read existing FreeMarker
templates and work out what data is being "mapped" into them.  Hope that
20,000ft explanation makes sense :)

So, I'd be more than happy to use the preview if the timelines I'm
working against matched up.  I really need something working by early
Dec and it sounds as though FM 2.4 is not that close to being released,
right?

T.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
Attila Szegedi-3

Re: How does one analyse a FreeMarker template??

Reply Threaded More More options
Print post
Permalink
In reply to this post by Jonathan Revusky-3
FWIW, at my company, we do exactly that - we use FreeMarker 2.3.x to render templates, and we have one developer who wrote a nifty static template analyser using 2.4 preview.

Attila.

On 2009.11.11., at 20:25, Jonathan Revusky wrote:

> On Wed, Nov 11, 2009 at 5:15 PM, Daniel Dekany <[hidden email]> wrote:
>> Wednesday, November 11, 2009, 12:14:25 AM, Tom Fennelly wrote:
>>
>>> Hi.
>>>
>>> I would like to be able to analyse a FreeMarker template. I thought I
>>> had the answer when I saw I could access the root TemplateElement
>>> through the Template instance, but alas, when I look closer (at
>>> IteratorBlock, DollarVariable etc) I see that the info I'd like access
>>> to on these objects is private, with no getter methods etc.
>>>
>>> Is there another way I can go about this?
>>
>> There isn't... except, of course, that you copy the relevant parts of
>> the project, creating your own parser for this purpose. The license
>> allows that. (FM 2.4 will have much better API for this kind of thing,
>> as you can see in 2.4preview-1 release, but it's a question if there
>> will be a 2.4-final ever...)
>
> Well, I would encourage Tom to use the 2.4 preview that is available.
> That, after all, is why one uses a preview or beta version of
> software, isn't it? That the bleeding edge stuff has features that you
> need that are lacking in the stable version.
>
> In any case, one can continue to use 2.3.15 in production to render
> templates, but use the 2.4 for the software that analyzes templates,
> no?
>
> JR
>
>
>>
>>> Regards,
>>>
>>> Tom.
>>
>> --
>> Best regards,
>>  Daniel Dekany

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
FreeMarker-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/freemarker-user