Re: Feature question FM2 / FM3: Hook into loops

2017-02-23 Thread Christoph Rüger
Thanks, good stuff.

2017-02-24 6:29 GMT+01:00 Jacques Le Roux :

> +1 for timeout
>
> Jacques
>
>
>
> Le 24/02/2017 à 01:12, Daniel Dekany a écrit :
>
>> There's a hidden feature in FreeMarker 2 that allows templates be
>> interrupted with Thread.interrupt(). This can be used to limit the
>> template execution time (one thread processes the template, the other
>> waits for it to finish with a timeout, and then interrupts the
>> template processing thread). To see this in action, go to
>> http://freemarker-online.kenshoo.com/ and enter some very long loop.
>> The processing will be aborted with timeout. The related part of the
>> source code is around here:
>> https://github.com/kenshoo/freemarker-online/blob/master/src
>> /main/java/com/kenshoo/freemarker/services/FreeMarkerService.java#L123
>>
>> That's the closes I can think of right now. But I'm open to ideas,
>> because this used to be concern if you allow users to write templates.
>>
>> The problem with limiting #list iterations is that you can nest
>> #list-s into each other, so it's easy to square, cube, etc. your
>> iteration limit. (There are other fun ways of doing infinitely running
>> templates too, like with recursion. That's why simply measuring how
>> long the template is running is certainly the most robust solution.)
>>
>> If you have some collections that you know shouldn't be fully listed,
>> then perhaps you should wrap those into your own TemplateSequenceModel
>> implementation.
>>
>>
>> Thursday, February 23, 2017, 3:14:06 PM, Christoph Rüger wrote:
>>
>> We would like to hook into loops (<#list>) to e.g. count the number of
>>> iterations and react based on some business conditions. For example stop
>>> with an Exception after 10k iterations.
>>>
>>> I would think about some kind of callback which we can register which is
>>> called by freemarker inside <#list> iterations, so that our callback code
>>> can do whatever is needed.
>>>
>>> Is something like that possible already (haven't checked code yet) or
>>> planned for FM3?
>>>
>>> Thanks
>>> Christoph
>>>
>>>
>


-- 
Christoph Rüger, Geschäftsführer
Synesty  - Anbinden und Automatisieren ohne
Programmieren - Automatisierung, Schnittstellen, Datenfeeds

Xing: https://www.xing.com/profile/Christoph_Rueger2
LinkedIn: http://www.linkedin.com/pub/christoph-rueger/a/685/198

-- 
Synesty GmbH
Moritz-von-Rohr-Str. 1a
07745 Jena
Tel.: +49 3641 559649
Fax.: +49 3641 5596499
Internet: http://synesty.com

Geschäftsführer: Christoph Rüger
Unternehmenssitz: Jena
Handelsregister B beim Amtsgericht: Jena
Handelsregister-Nummer: HRB 508766
Ust-IdNr.: DE287564982


Re: Feature question FM2 / FM3: Hook into loops

2017-02-23 Thread Jacques Le Roux

+1 for timeout

Jacques


Le 24/02/2017 à 01:12, Daniel Dekany a écrit :

There's a hidden feature in FreeMarker 2 that allows templates be
interrupted with Thread.interrupt(). This can be used to limit the
template execution time (one thread processes the template, the other
waits for it to finish with a timeout, and then interrupts the
template processing thread). To see this in action, go to
http://freemarker-online.kenshoo.com/ and enter some very long loop.
The processing will be aborted with timeout. The related part of the
source code is around here:
https://github.com/kenshoo/freemarker-online/blob/master/src/main/java/com/kenshoo/freemarker/services/FreeMarkerService.java#L123

That's the closes I can think of right now. But I'm open to ideas,
because this used to be concern if you allow users to write templates.

The problem with limiting #list iterations is that you can nest
#list-s into each other, so it's easy to square, cube, etc. your
iteration limit. (There are other fun ways of doing infinitely running
templates too, like with recursion. That's why simply measuring how
long the template is running is certainly the most robust solution.)

If you have some collections that you know shouldn't be fully listed,
then perhaps you should wrap those into your own TemplateSequenceModel
implementation.


Thursday, February 23, 2017, 3:14:06 PM, Christoph Rüger wrote:


We would like to hook into loops (<#list>) to e.g. count the number of
iterations and react based on some business conditions. For example stop
with an Exception after 10k iterations.

I would think about some kind of callback which we can register which is
called by freemarker inside <#list> iterations, so that our callback code
can do whatever is needed.

Is something like that possible already (haven't checked code yet) or
planned for FM3?

Thanks
Christoph





RE: Feature question FM2 / FM3: Hook into loops

2017-02-23 Thread Mickel Daelmans | Add to Favorites
Something like http://freemarker.org/docs/ref_directive_list.html#autoid_107 ?

Or use your own iterator:

<#assign i = 0 />
<#list items as item>
   <#assign i = i + 1 />
   <#if i == 1>
//break / stop / throw exception
   
   
   //do stuff in loop



Mickel Daelmans
Developer
 

Goeman Borgesiuslaan 77
3515 ET Utrecht
T. 030-7551560
W. www.addtofavorites.nl
 
Alles weten over transactionele e-mail?
Volg onze mailroad pagina op LinkedIn
===
De inhoud van deze e-mail, inclusief bijlagen, is vertrouwelijk en enkel 
bestemd voor de geadresseerde. Indien dit bericht niet voor u is bestemd, 
verzoeken wij u het te vernietigen, de inhoud daarvan op geen enkele wijze te 
gebruiken of te openbaren en direct contact met ons op te nemen. Op al onze 
werkzaamheden zijn onze Algemene Voorwaarden van toepassing, waarin een 
aansprakelijkheidsbeperking is opgenomen. Onze Algemene Voorwaarden worden op 
verzoek toegezonden. Add to Favorites B.V. is gevestigd te Utrecht (KvK Utrecht 
nr. 17228639).


-Oorspronkelijk bericht-
Van: Christoph Rüger [mailto:c.rue...@synesty.com] 
Verzonden: donderdag 23 februari 2017 15:14
Aan: Freemarker dev Mailinglist
Onderwerp: Feature question FM2 / FM3: Hook into loops

We would like to hook into loops (<#list>) to e.g. count the number of 
iterations and react based on some business conditions. For example stop with 
an Exception after 10k iterations.

I would think about some kind of callback which we can register which is called 
by freemarker inside <#list> iterations, so that our callback code can do 
whatever is needed.

Is something like that possible already (haven't checked code yet) or planned 
for FM3?

Thanks
Christoph

--
Synesty GmbH
Moritz-von-Rohr-Str. 1a
07745 Jena
Tel.: +49 3641 559649
Fax.: +49 3641 5596499
Internet: http://synesty.com

Geschäftsführer: Christoph Rüger
Unternehmenssitz: Jena
Handelsregister B beim Amtsgericht: Jena
Handelsregister-Nummer: HRB 508766
Ust-IdNr.: DE287564982


Feature question FM2 / FM3: Hook into loops

2017-02-23 Thread Christoph Rüger
We would like to hook into loops (<#list>) to e.g. count the number of
iterations and react based on some business conditions. For example stop
with an Exception after 10k iterations.

I would think about some kind of callback which we can register which is
called by freemarker inside <#list> iterations, so that our callback code
can do whatever is needed.

Is something like that possible already (haven't checked code yet) or
planned for FM3?

Thanks
Christoph

-- 
Synesty GmbH
Moritz-von-Rohr-Str. 1a
07745 Jena
Tel.: +49 3641 559649
Fax.: +49 3641 5596499
Internet: http://synesty.com

Geschäftsführer: Christoph Rüger
Unternehmenssitz: Jena
Handelsregister B beim Amtsgericht: Jena
Handelsregister-Nummer: HRB 508766
Ust-IdNr.: DE287564982


Re: [FM3] Remove some deprecated FTL constructs

2017-02-23 Thread Woonsan Ko
On Thu, Feb 23, 2017 at 12:31 AM, Daniel Dekany  wrote:
> Thursday, February 23, 2017, 12:22:52 AM, Woonsan Ko wrote:
>
>> On Wed, Feb 22, 2017 at 4:06 AM, Daniel Dekany  wrote:
>>> I would like to remove these deprecated FM2 FTL constructs in FM3:
>>>
>>> - #escape, #no_escape (recently deprecated in favor of 
>>> http://freemarker.org/docs/dgui_misc_autoescaping.html)
>> I'm very fine with dropping this, but I'm just curious about a 'corner
>> case'. In the '"Markup output" values' section, it explains an
>> interesting case that the caller of a macro can decide whether or not
>> the message argument should be escaped.
>> Is there a similar way to achieve that after dropping them?
>
> You mean this:
>
> <@infoBox "Foo & bar" />
> <@infoBox "Foo bar"?no_esc />
>
> <#macro infoBox message>
>   
> ${message}
>   
> 
>
> That thing works exactly because of the new escaping mechanism. It has
> nothing to do with the legacy #escape, #no_escape. So, yes, it works
> without them.

Ah, right. I confused myself with the builtin. Sorry for that and thanks!

Woonsan

>
>>> - .template_name in favor of .current_template_name (there's also 
>>> .main_template_name)
>> +1
>>
>>> - http://freemarker.org/docs/ref_depr_numerical_interpolation.html
>> +1
>>
>>> - http://freemarker.org/docs/ref_depr_directive.html
>> +1
>>
>>> - http://freemarker.org/docs/ref_depr_builtin.html
>> +1
>>
>> Regards,
>>
>> Woonsan
>>
>>>
>>> Any thoughts?
>>>
>>> Some other changes were agreed upon earlier (but weren't implemented yet):
>>>
>>> - Remove tag syntax autodetection (<#> VS [#]). Use file extension (or
>>>   TemplateConfigurator-s associated otherwise) to decide the syntax.
>>>   This is to help tooling (not even the JBoss Eclipse plugin managed
>>>   to correctly deal with it).
>>>
>>> - Only keep the camel case naming convention, not only because it has
>>>   become the dominant convention nowadays, but because the data-model
>>>   uses that anyway (as it comes from Java).
>>>
>>> As you might notice, currently the focus is on removing stuff, because
>>> doing that the earliest makes refactoring less expensive.
>>>
>>> --
>>> Thanks,
>>>  Daniel Dekany
>>>
>>
>
> --
> Thanks,
>  Daniel Dekany
>