freemarker.ext.misc
Class CompressLines

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

public final class CompressLines
extends java.lang.Object
implements TemplateTransformModel, java.io.Serializable

A transform model that strips trailing whitespace from every line, and reduces consecutive blank lines to a single blank line. This transformation is useful as a global filter.

Note: this is not a content-aware filter. Any content inside a <pre> ... </pre> block will also have its whitespace transformed.

Usage:
From java:

 TemplateModelRoot root = new SimpleHash();

 root.put( "compressLines", freemarker.ext.misc.CompressLines.getInstance() );

 ...
 

From your FM-Classic template:

 The following is compressed:
 <transform compressLines>
   <p>This page consists of multiple lines.</p>
   <p>For every line on the page, all trailing whitespace is removed.</p>


   <p>Any blank lines are reduced to a single blank line.</p>
 </transform>

 ...
 

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

Version:
$Id: CompressLines.java 1105 2013-04-09 10:52:59Z run2000 $
See Also:
LegacyCompress, CompressWhitespace, Serialized Form

Method Summary
static CompressLines getInstance()
          Retrieve a singleton instance of this class.
 boolean isEmpty()
          Is the object empty?
 void transform(java.io.Reader source, java.io.PrintWriter output)
          Compresses lines within the marked portion of a FM-Classic template.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static CompressLines getInstance()
Retrieve a singleton instance of this class. Since there is no state information held between calls, there is only a need for one instance.

Returns:
an instance of this CompressLines class

isEmpty

public boolean isEmpty()
                throws TemplateModelException
Is the object empty?

Specified by:
isEmpty in interface TemplateModel
Returns:
false, to indicate non-empty transformation
Throws:
TemplateModelException

transform

public void transform(java.io.Reader source,
                      java.io.PrintWriter output)
               throws java.io.IOException,
                      TemplateModelException
Compresses lines within the marked portion of a FM-Classic template.

Specified by:
transform in interface TemplateTransformModel
Parameters:
source - the input to be transformed
output - the destination of the transformation
Throws:
java.io.IOException
TemplateModelException