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 -
Method Summary
Modifier and TypeMethodDescriptionconvertValue(Object value, TemplateImageResolver imageResolver) Converts a Java object (e.g.protected freemarker.template.ConfigurationGet the FreeMarker configuration for this instanceprotected freemarker.template.ConfigurationgetStringConfig(String path, String template) FreeMarker configuration for loading the specified template directly from a StringvoidProcess a template against the supplied data model and write to the out.voidProcess a template in the given locale against the supplied data model and write to the out.voidprocessString(String template, Object model, Writer out) Process a string template against the supplied data model and write to the out.voidsetDefaultEncoding(String defaultEncoding) Set the default template encodingvoidsetLocalizedLookup(boolean localizedLookup) Enable or disable Freemarker's localized lookup featureMethods inherited from class org.alfresco.repo.processor.BaseProcessor
getExtension, getName, getProcessorExtensions, register, registerProcessorExtension, setExtension, setName, setScriptService, setServiceRegistry, setTemplateServiceMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.alfresco.processor.Processor
getExtension, getName, registerProcessorExtension
-
Constructor Details
-
FreeMarkerProcessor
public FreeMarkerProcessor()
-
-
Method Details
-
setDefaultEncoding
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
FreeMarker configuration for loading the specified template directly from a String- Parameters:
path- Pseudo Path to the templatetemplate- Template content- Returns:
- FreeMarker configuration
-
process
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:
-
process
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:
-
processString
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:
-
convertValue
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
-