Class FreemarkerTemplateRenderServiceImpl

java.lang.Object
fr.becpg.repo.template.impl.FreemarkerTemplateRenderServiceImpl
All Implemented Interfaces:
BeCPGTemplateRenderService, org.springframework.beans.factory.InitializingBean

public class FreemarkerTemplateRenderServiceImpl extends Object implements BeCPGTemplateRenderService, org.springframework.beans.factory.InitializingBean

FreeMarker implementation of BeCPGTemplateRenderService, backed by a private Configuration.

A private configuration is used rather than the Alfresco TemplateService because the latter resolves templates by repository path only: a template read from the repository could not pull in a shared macro library, which is exactly what a family of templates needs. It also lets the number format be pinned to computer, without which a coordinate such as 144.5 would be written 144,5 in a French locale and would silently corrupt any XML output.

Templates using the .ftlx extension are auto-escaped as XML, which is what SVG output requires; plain .ftl templates stay unescaped.

Version:
$Id: $Id
Author:
matthieu
  • Field Details

    • logger

      private static final org.apache.commons.logging.Log logger
    • COMPUTER_NUMBER_FORMAT

      private static final String COMPUTER_NUMBER_FORMAT
      Number format keeping a dot as decimal separator, whatever the locale.
      See Also:
    • TEMPLATE_UPDATE_DELAY_MS

      private static final long TEMPLATE_UPDATE_DELAY_MS
      Delay before a template updated in the repository is reloaded.
      See Also:
    • nodeService

      private org.alfresco.service.cmr.repository.NodeService nodeService
    • contentService

      private org.alfresco.service.cmr.repository.ContentService contentService
    • repoService

      private RepoService repoService
    • repositoryFolderPath

      private String repositoryFolderPath
    • classpathPrefix

      private String classpathPrefix
    • configuration

      private freemarker.template.Configuration configuration
  • Constructor Details

    • FreemarkerTemplateRenderServiceImpl

      public FreemarkerTemplateRenderServiceImpl()
  • Method Details

    • setNodeService

      public void setNodeService(org.alfresco.service.cmr.repository.NodeService nodeService)

      Setter for the field nodeService.

      Parameters:
      nodeService - a NodeService object
    • setContentService

      public void setContentService(org.alfresco.service.cmr.repository.ContentService contentService)

      Setter for the field contentService.

      Parameters:
      contentService - a ContentService object
    • setRepoService

      public void setRepoService(RepoService repoService)

      Setter for the field repoService.

      Parameters:
      repoService - a RepoService object
    • setRepositoryFolderPath

      public void setRepositoryFolderPath(String repositoryFolderPath)

      Setter for the field repositoryFolderPath.

      Parameters:
      repositoryFolderPath - a String object, folder holding the overrides
    • setClasspathPrefix

      public void setClasspathPrefix(String classpathPrefix)

      Setter for the field classpathPrefix.

      Parameters:
      classpathPrefix - a String object, classpath root of the templates
    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
    • buildConfiguration

      private freemarker.template.Configuration buildConfiguration()
    • buildTemplateLoader

      private freemarker.cache.TemplateLoader buildTemplateLoader()
      Repository first so that a customer override wins, classpath second for the shipped templates. Stickiness must stay off, otherwise a template freshly added to the repository would keep being served from the classpath until the cache expires.
    • render

      public String render(String templateName, Locale locale, Map<String,Object> model)

      Renders a template and returns its output.

      Specified by:
      render in interface BeCPGTemplateRenderService
      Parameters:
      templateName - a String object
      locale - a Locale object, the current locale is used when null
      model - a Map object
      Returns:
      a String object
    • render

      public void render(String templateName, Locale locale, Map<String,Object> model, Writer writer)

      Renders a template directly into the given writer, for large outputs.

      Specified by:
      render in interface BeCPGTemplateRenderService
      Parameters:
      templateName - a String object
      locale - a Locale object, the current locale is used when null
      model - a Map object
      writer - a Writer object
    • exists

      public boolean exists(String templateName, Locale locale)

      Tells whether a template resolves, in the repository or on the classpath.

      Specified by:
      exists in interface BeCPGTemplateRenderService
      Parameters:
      templateName - a String object
      locale - a Locale object, the current locale is used when null
      Returns:
      a boolean
    • clearCache

      public void clearCache()

      Drops the template cache, so that a template just updated in the repository is picked up without waiting for the update delay.

      Specified by:
      clearCache in interface BeCPGTemplateRenderService
    • getTemplate

      private freemarker.template.Template getTemplate(String templateName, Locale locale) throws IOException
      Throws:
      IOException