org.alfresco.repo.template
Class FreeMarkerProcessor

java.lang.Object
  extended by org.alfresco.repo.processor.BaseProcessor
      extended by 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.


Field Summary
 
Fields inherited from class org.alfresco.repo.processor.BaseProcessor
extension, name, processorExtensions, scriptService, services, templateService
 
Constructor Summary
FreeMarkerProcessor()
           
 
Method Summary
 java.lang.Object convertValue(java.lang.Object value, TemplateImageResolver imageResolver)
          Converts a Java object (e.g.
protected  freemarker.template.Configuration getConfig()
          Get the FreeMarker configuration for this instance
protected  freemarker.template.Configuration getStringConfig(java.lang.String path, java.lang.String template)
          FreeMarker configuration for loading the specified template directly from a String
 void process(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.
 void processString(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.
 void setDefaultEncoding(java.lang.String defaultEncoding)
          Set the default template encoding
 
Methods inherited from class org.alfresco.repo.processor.BaseProcessor
getExtension, getName, getProcessorExtensions, register, registerProcessorExtension, setExtension, setName, setScriptService, setServiceRegistry, setTemplateService
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.alfresco.processor.Processor
getExtension, getName, registerProcessorExtension
 

Constructor Detail

FreeMarkerProcessor

public FreeMarkerProcessor()
Method Detail

setDefaultEncoding

public void setDefaultEncoding(java.lang.String defaultEncoding)
Set the default template encoding

Parameters:
defaultEncoding - the default encoding

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 template
template - 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: TemplateProcessor
Process a template against the supplied data model and write to the out.

Specified by:
process in interface TemplateProcessor
Parameters:
template - Template name/path
model - Object model to process template against
out - Writer object to send output too
See Also:
TemplateProcessor.process(java.lang.String, java.lang.Object, java.io.Writer)

processString

public void processString(java.lang.String template,
                          java.lang.Object model,
                          java.io.Writer out)
Description copied from interface: TemplateProcessor
Process a string template against the supplied data model and write to the out.

Specified by:
processString in interface TemplateProcessor
Parameters:
template - Template string
model - Object model to process template against
out - 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: TemplateValueConverter
Converts a Java object (e.g. one produced by a method call) to one suitable for use within a template.

Specified by:
convertValue in interface TemplateValueConverter
Parameters:
value - the Java object to convert
imageResolver - the image resolver
Returns:
the converted object


Copyright © 2005 - 2010 Alfresco Software, Inc. All Rights Reserved.