Package org.alfresco.repo.template
Class FreeMarkerProcessor
- java.lang.Object
-
- org.alfresco.repo.processor.BaseProcessor
-
- org.alfresco.repo.template.FreeMarkerProcessor
-
- All Implemented Interfaces:
org.alfresco.processor.Processor,TemplateProcessor,TemplateValueConverter
public class FreeMarkerProcessor extends BaseProcessor implements TemplateProcessor, TemplateValueConverter
FreeMarker implementation of the template processor interface.Service to process FreeMarker template files loaded from various sources including the classpath, repository and directly from a String.
The template is processed against a data model generally consisting of a map of named objects. FreeMarker can natively handle any POJO objects using standard bean notation syntax. It has support for walking List objects. A 'standard' data model helper is provided to help generate an object model containing well known objects such as the Company Home, User Home and current User nodes. It also provides helpful util classes to process Date objects and repository specific custom methods.
- Author:
- Kevin Roast
-
-
Field Summary
-
Fields inherited from class org.alfresco.repo.processor.BaseProcessor
extension, name, processorExtensions, scriptService, services, templateService
-
-
Constructor Summary
Constructors Constructor Description FreeMarkerProcessor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.ObjectconvertValue(java.lang.Object value, TemplateImageResolver imageResolver)Converts a Java object (e.g.protected freemarker.template.ConfigurationgetConfig()Get the FreeMarker configuration for this instanceprotected freemarker.template.ConfigurationgetStringConfig(java.lang.String path, java.lang.String template)FreeMarker configuration for loading the specified template directly from a Stringvoidprocess(java.lang.String template, java.lang.Object model, java.io.Writer out)Process a template against the supplied data model and write to the out.voidprocess(java.lang.String template, java.lang.Object model, java.io.Writer out, java.util.Locale locale)Process a template in the given locale against the supplied data model and write to the out.voidprocessString(java.lang.String template, java.lang.Object model, java.io.Writer out)Process a string template against the supplied data model and write to the out.voidsetDefaultEncoding(java.lang.String defaultEncoding)Set the default template encodingvoidsetLocalizedLookup(boolean localizedLookup)Enable or disable Freemarker's localized lookup feature-
Methods inherited from class org.alfresco.repo.processor.BaseProcessor
getExtension, getName, getProcessorExtensions, register, registerProcessorExtension, setExtension, setName, setScriptService, setServiceRegistry, setTemplateService
-
-
-
-
Method Detail
-
setDefaultEncoding
public void setDefaultEncoding(java.lang.String defaultEncoding)
Set the default template encoding- Parameters:
defaultEncoding- the default encoding
-
setLocalizedLookup
public void setLocalizedLookup(boolean localizedLookup)
Enable or disable Freemarker's localized lookup feature
-
getConfig
protected freemarker.template.Configuration getConfig()
Get the FreeMarker configuration for this instance- Returns:
- FreeMarker configuration
-
getStringConfig
protected freemarker.template.Configuration getStringConfig(java.lang.String path, java.lang.String template)FreeMarker configuration for loading the specified template directly from a String- Parameters:
path- Pseudo Path to the templatetemplate- Template content- Returns:
- FreeMarker configuration
-
process
public void process(java.lang.String template, java.lang.Object model, java.io.Writer out)Description copied from interface:TemplateProcessorProcess a template against the supplied data model and write to the out.- Specified by:
processin interfaceTemplateProcessor- Parameters:
template- Template name/pathmodel- Object model to process template againstout- Writer object to send output too- See Also:
TemplateProcessor.process(java.lang.String, java.lang.Object, java.io.Writer)
-
process
public void process(java.lang.String template, java.lang.Object model, java.io.Writer out, java.util.Locale locale)Description copied from interface:TemplateProcessorProcess a template in the given locale against the supplied data model and write to the out.- Specified by:
processin interfaceTemplateProcessor- Parameters:
template- Template name/pathmodel- Object model to process template againstout- Writer object to send output toolocale- The Locale to process the template in- See Also:
TemplateProcessor.process(java.lang.String, java.lang.Object, java.io.Writer, java.util.Locale)
-
processString
public void processString(java.lang.String template, java.lang.Object model, java.io.Writer out)Description copied from interface:TemplateProcessorProcess a string template against the supplied data model and write to the out.- Specified by:
processStringin interfaceTemplateProcessor- Parameters:
template- Template stringmodel- Object model to process template againstout- Writer object to send output too- See Also:
TemplateProcessor.processString(java.lang.String, java.lang.Object, java.io.Writer)
-
convertValue
public java.lang.Object convertValue(java.lang.Object value, TemplateImageResolver imageResolver)Description copied from interface:TemplateValueConverterConverts a Java object (e.g. one produced by a method call) to one suitable for use within a template.- Specified by:
convertValuein interfaceTemplateValueConverter- Parameters:
value- the Java object to convertimageResolver- the image resolver- Returns:
- the converted object
-
-