Class FreemarkerTemplateRenderServiceImpl
- All Implemented Interfaces:
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 Summary
FieldsModifier and TypeFieldDescriptionprivate Stringprivate static final StringNumber format keeping a dot as decimal separator, whatever the locale.private freemarker.template.Configurationprivate org.alfresco.service.cmr.repository.ContentServiceprivate static final org.apache.commons.logging.Logprivate org.alfresco.service.cmr.repository.NodeServiceprivate RepoServiceprivate Stringprivate static final longDelay before a template updated in the repository is reloaded. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidprivate freemarker.template.Configurationprivate freemarker.cache.TemplateLoaderRepository first so that a customer override wins, classpath second for the shipped templates.voidDrops the template cache, so that a template just updated in the repository is picked up without waiting for the update delay.booleanTells whether a template resolves, in the repository or on the classpath.private freemarker.template.TemplategetTemplate(String templateName, Locale locale) Renders a template and returns its output.voidRenders a template directly into the given writer, for large outputs.voidsetClasspathPrefix(String classpathPrefix) Setter for the fieldclasspathPrefix.voidsetContentService(org.alfresco.service.cmr.repository.ContentService contentService) Setter for the fieldcontentService.voidsetNodeService(org.alfresco.service.cmr.repository.NodeService nodeService) Setter for the fieldnodeService.voidsetRepoService(RepoService repoService) Setter for the fieldrepoService.voidsetRepositoryFolderPath(String repositoryFolderPath) Setter for the fieldrepositoryFolderPath.
-
Field Details
-
logger
private static final org.apache.commons.logging.Log logger -
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_MSDelay 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
-
repositoryFolderPath
-
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- aNodeServiceobject
-
setContentService
public void setContentService(org.alfresco.service.cmr.repository.ContentService contentService) Setter for the field
contentService.- Parameters:
contentService- aContentServiceobject
-
setRepoService
Setter for the field
repoService.- Parameters:
repoService- aRepoServiceobject
-
setRepositoryFolderPath
Setter for the field
repositoryFolderPath.- Parameters:
repositoryFolderPath- aStringobject, folder holding the overrides
-
setClasspathPrefix
Setter for the field
classpathPrefix.- Parameters:
classpathPrefix- aStringobject, classpath root of the templates
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceorg.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
Renders a template and returns its output.
-
render
Renders a template directly into the given writer, for large outputs.
-
exists
Tells whether a template resolves, in the repository or on the classpath.
- Specified by:
existsin interfaceBeCPGTemplateRenderService- Parameters:
templateName- aStringobjectlocale- aLocaleobject, 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:
clearCachein interfaceBeCPGTemplateRenderService
-
getTemplate
private freemarker.template.Template getTemplate(String templateName, Locale locale) throws IOException - Throws:
IOException
-