freemarker.ext.misc
Class Pipeline

java.lang.Object
  extended by freemarker.ext.misc.Pipeline
All Implemented Interfaces:
TemplateMethodModel2, TemplateModel, java.io.Serializable

public final class Pipeline
extends java.lang.Object
implements TemplateMethodModel2, java.io.Serializable

A class for chaining multiple transformations into a single model without having to nest <transform> tags. A slightly more elegant way to handle transformation pipelines.

Transformations are called from leftmost argument to rightmost in order. This differs from nesting <transform> tags where the innermost is called first, and the outermost is called last.

Usage:
From java:

 TemplateModelRoot root = new SimpleHash();

 root.put( "pipeline", freemarker.ext.misc.Pipeline.getInstance() );

 ...
 

From your FM-Classic template:

 The following is transformed with a pipeline:
 <transform pipeline( transform1, transform2, transform3, transform4 )>
   This output is transformed by all the transformations in the pipeline.
 </transform>

 ...
 

In the example, the transformations are applied in the following order:

Source => Transform 1 => Transform 2 => Transform 3 => Transform 4 = > Output

Note:
Pipeline is a singleton instance. Use the getInstance() method to retrieve instances of this model.

Since:
1.9
Version:
$Id: Pipeline.java 1088 2013-03-29 05:52:17Z run2000 $
Author:
Nicholas Cull
See Also:
Serialized Form

Method Summary
 TemplateModel exec(java.util.List<TemplateModel> arguments)
          Construct a new transform pipeline with the given transform models.
static Pipeline getInstance()
          Return a new instance of this class.
 boolean isEmpty()
          Is the current method model empty.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static Pipeline getInstance()
Return a new instance of this class. No state is held in the method model itself. Rather, the method model creates a new instance of the transformation class itself whenever it is called. The transformation class holds all state information about the pipeline.

Returns:
a new instance of the Pipeline method model

isEmpty

public boolean isEmpty()
Is the current method model empty.

Specified by:
isEmpty in interface TemplateModel
Returns:
false, indicating that this method model is not empty

exec

public TemplateModel exec(java.util.List<TemplateModel> arguments)
                   throws TemplateModelException
Construct a new transform pipeline with the given transform models. The models will be called in leftmost to rightmost order.

Specified by:
exec in interface TemplateMethodModel2
Parameters:
arguments - a List of TemplateTransformModel or TemplateTransformModel2 models to be chained into a single pipeline
Returns:
a new TemplateTransformModel2 that represents all the transform models in a single pipeline
Throws:
TemplateModelException