freemarker.ext.misc
Class CompressWhitespace

java.lang.Object
  |
  +--freemarker.ext.misc.CompressWhitespace
All Implemented Interfaces:
TemplateModel, TemplateTransformModel2

public final class CompressWhitespace
extends java.lang.Object
implements TemplateTransformModel2

A transform model that compresses each occurrence of consecutive whitespace down to a single space character. Leading and trailing whitespace is also removed.

Usage:
From java:

 TemplateModelRoot root = new SimpleHash();

 root.put( "compressWhitespace", freemarker.ext.misc.CompressWhitespace.getInstance() );

 ...
 

From your FM-Classic template:

 The following is compressed:
 <transform compressWhitespace>
   <p>This paragraph has all whitespace reduced to a single
   space character.</p>
 </transform>

 ...
 

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

Version:
$Id: CompressWhitespace.java,v 1.11 2003/11/17 13:06:24 run2000 Exp $
See Also:
LegacyCompress

Constructor Summary
CompressWhitespace()
          Deprecated. use the getInstance() method to avoid excessive object creation
 
Method Summary
static CompressWhitespace getInstance()
          Retrieve a singleton instance of this class.
 boolean isEmpty()
          Is the object empty?
 void transform(java.io.Reader source, java.io.Writer output)
          Compresses whitespace within the marked portion of a FreeMarker template.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompressWhitespace

public CompressWhitespace()
Deprecated. use the getInstance() method to avoid excessive object creation

Creates new CompressWhitespace.
Method Detail

getInstance

public static CompressWhitespace 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 CompressWhitespace class

transform

public void transform(java.io.Reader source,
                      java.io.Writer output)
               throws java.io.IOException,
                      TemplateModelException
Compresses whitespace within the marked portion of a FreeMarker template.
Specified by:
transform in interface TemplateTransformModel2
Parameters:
source - the input to be transformed
output - the destination of the transformation

isEmpty

public boolean isEmpty()
                throws TemplateModelException
Is the object empty?
Specified by:
isEmpty in interface TemplateModel
Returns:
false, to indicate this object is not empty