Tuesday, January 24, 2017, 9:27:37 PM, David E Jones wrote:

> On Jan 24 2017, at 10:25 am, Daniel Dekany <ddek...@freemail.hu> wrote:
>
>> Tuesday, January 24, 2017, 6:48:16 PM, David E Jones wrote:
>
>>
>
>> > but all other Configuration.getTemplate() methods call this method  
>
>>
>
>> > so it is an easy way to override all Template loading (assuming you  
>> are doing your own caching and so on, which is part of what I wanted  
>> in this case, ie use a managed cache external to FreeMarker that  
>> other things also use instead of the cache internal to FreeMarker).
>
>>
>
>> That's another thing I definitely want to solve in FM3 (I'm not sure  
> if I want to go into that in FM2 though), but by providing a setting  
> like cfg.templateResolver (TemplateResolver interface), which has some
> minimalistic "give me a template like this somehow" method, and  
> default implementation that delegates to TemplateCache.
>
>   
>
> Being able to implement an interface and register it with the Configuration
> would be great, much better than hacking around in the implementation of
> FreeMarker while still being able to override the Template loading behavior
> completely (including caching, location resolution, etc). So yes, this sounds
> great.

Should the TemplateResolver-s (the work name for the new interface)
still get the template name already resolved to absolute and
normalized? So when cfg.getTemplate is called, then it invokes
cfg.templateNameFormat.normalizeAbsoluteName(String) to normalize the
path, and only then it calls the TemplateResolver. Also #import and
such currently calls templateNameFormat.toAbsoluteName(String,
String), and that would happen earlier than TemplateResolver is
involved.

And how would it look... perhaps like this:

    public interface TemplateResolver {

       Template getTemplate(String templatePath, Local lookupLocale, Object 
customLookupCondition)
       throws IOException;

    }

You may notice that it misses the `encoding` and `parsed` parameter of
cfg.getTemplate. That's because I belive that in FM3 we should not
allow specifying those as getTemplate parameters anymore, but that
will be another thread when we get there.

> -David
>
>   
>
>   
>

-- 
Thanks,
 Daniel Dekany

Reply via email to