freemarker.template
Class TemplateProcessorParameters

java.lang.Object
  extended by freemarker.template.TemplateProcessorParameters

public final class TemplateProcessorParameters
extends java.lang.Object

Parameter class for a Template processor. This is a convenience class for passing parameters to a template processor to apply the template to a model. Any additional parameters can be added to this parameter class without having to alter the method signature of the processor itself.

This is an immutable class. Calls to any of the withXXX() methods return a new object.

Typical usage:

 Reader reader = ...;
 Template template = new Template(reader);
 TemplateProcessorParameters tpp = TemplateProcessorParameters
     .newInstance(writer)
     .withEventHandler(TemplateEventAdapter.DefaultEventAdapter)
     .withEscape(HtmlEscape.getInstance());
 template.process(tpp);
 

Since:
1.9
Version:
$Id: TemplateProcessorParameters.java 1112 2013-04-12 02:59:25Z run2000 $
Author:
Nicholas Cull

Method Summary
 TemplateModel getEscape()
          Get the Template escape model for this parameter object.
 TemplateRuntimeHandler getEventHandler()
          Get the Template runtime handler for this parameter object.
 TemplateWriteableHashModel getModelRoot()
          Get the Template model root for this parameter object.
 java.io.Writer getWriter()
          Get the writer for this parameter object.
static TemplateProcessorParameters newInstance()
          Create a new instance of this template processor parameter class.
static TemplateProcessorParameters newInstance(java.io.Writer writer)
          Create a new instance of this template processor parameter class with the given writer.
 TemplateProcessorParameters withEscape(TemplateModel escape)
          Return a new TemplateProcessorParameters object with the given escape TemplateModel in place of the existing escape.
 TemplateProcessorParameters withEventHandler(TemplateRuntimeHandler eventHandler)
          Return a new TemplateProcessorParameters object with the given event handler in place of the existing event handler.
 TemplateProcessorParameters withModel(TemplateWriteableHashModel modelRoot)
          Return a new TemplateProcessorParameters object with the given template model in place of the existing template model.
 TemplateProcessorParameters withWriter(java.io.Writer writer)
          Return a new TemplateProcessorParameters object with the given writer in place of the existing writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

newInstance

public static TemplateProcessorParameters newInstance()
Create a new instance of this template processor parameter class. The instance contains an empty model root, the standard output stream, and the default event adapter.

Returns:
a new template processor parameter object

newInstance

public static TemplateProcessorParameters newInstance(java.io.Writer writer)
Create a new instance of this template processor parameter class with the given writer. The instance contains an empty model root, the default event adapter, and no template escaper.

Parameters:
writer - the writer to be passed in to the template processor
Returns:
a new TemplateProcessorParameters object with the given writer
Throws:
java.lang.NullPointerException - the writer is null

withWriter

public TemplateProcessorParameters withWriter(java.io.Writer writer)
Return a new TemplateProcessorParameters object with the given writer in place of the existing writer. This ensures that every TemplateProcessorParameters object is immutable.

Parameters:
writer - the writer to use in place of the existing writer
Returns:
a new TemplateProcessorParameters object with the new writer
Throws:
java.lang.NullPointerException - the writer is null

withModel

public TemplateProcessorParameters withModel(TemplateWriteableHashModel modelRoot)
Return a new TemplateProcessorParameters object with the given template model in place of the existing template model. This ensures that every TemplateProcessorParameters object is immutable.

Parameters:
modelRoot - the template model to use in place of the existing template model
Returns:
a new TemplateProcessorParameters object with the new template model
Throws:
java.lang.NullPointerException - the model root is null

withEventHandler

public TemplateProcessorParameters withEventHandler(TemplateRuntimeHandler eventHandler)
Return a new TemplateProcessorParameters object with the given event handler in place of the existing event handler. This ensures that every TemplateProcessorParameters object is immutable.

Parameters:
eventHandler - the event handler to use in place of the existing event handler
Returns:
a new TemplateProcessorParameters object with the new event handler
Throws:
java.lang.NullPointerException - the event handler is null

withEscape

public TemplateProcessorParameters withEscape(TemplateModel escape)
Return a new TemplateProcessorParameters object with the given escape TemplateModel in place of the existing escape. This ensures that every TemplateProcessorParameters object is immutable.

Parameters:
escape - the escape TemplateModel to use in place of the existing escape
Returns:
a new TemplateProcessorParameters object with the new escape TemplateModel

getModelRoot

public TemplateWriteableHashModel getModelRoot()
Get the Template model root for this parameter object.

Returns:
the template model root

getWriter

public java.io.Writer getWriter()
Get the writer for this parameter object.

Returns:
the writer

getEventHandler

public TemplateRuntimeHandler getEventHandler()
Get the Template runtime handler for this parameter object.

Returns:
the runtime handler

getEscape

public TemplateModel getEscape()
Get the Template escape model for this parameter object.

Returns:
the template escape model, possibly null