AnsweredAssumed Answered

Freemarker Template and rendering to file for policy

Question asked by ajmas on Dec 3, 2010
I am not sure this is the best group, so let me know if there is better one.

I have implemented a policy that will create an external index file for the content in Alfresco. Originally I did all the rendering in a Java class, but have been asked to allow the rendering to be done in a 'Freemarker' template. For this I use the template processor, which I inject in a spring context file (reference to webscripts.repo.templateprocessor). This all works, but only if I place my template in the 'webscripts' directory. Because this template is not really part of a webscript I would rather place in a 'templates' folder in my module, to indicate the different use. For this reason I have decided to use another instance of RepositoryTemplateProcessor with my search path.

The configuration I am using is below. The problem I am having is that when I go to render the template I get an exception:

java.lang.NullPointerException: null
        at org.alfresco.repo.template.FreeMarkerProcessor.getTemplate( [FreeMarkerProcessor.class:na]

At this point getConfig() is returning null, in the method getTemplate(String).

   <bean id="mymodule.templates" parent="templates.classpathstore" init-method="init">
      <property name="mustExist"><value>true</value></property>
      <property name="classPath"><value>alfresco/module/mymodule/templates</value></property>
   <bean id="mymodule.searchpath" class="org.springframework.extensions.webscripts.SearchPath">
      <property name="searchPath">
             <ref bean="" />
             <ref bean="" />
             <ref bean="" />
             <ref bean="" />
             <ref bean="" />
             <ref bean="" />
             <ref bean="" />
             <ref bean="mymodule.templates" />

    <bean id="mymodule.templateprocessor" class="org.alfresco.repo.web.scripts.RepositoryTemplateProcessor">
        <property name="serviceRegistry" ref="ServiceRegistry" />
        <property name="freeMarkerProcessor" ref="freeMarkerProcessor" />
        <property name="searchPath" ref="mymodule.searchpath" />

This code I am using is:

String template = "subpath/mytemplate.xml";
this.templateProcessor.process(template, model, out);

Can anyone suggest what I may be doing wrong?

Also, if there is a better way to define and use non-webscript freemarker templates in Alfreso, while still having TemplateMethod support, I would be interested in finding out.