freemarker.ext.misc
Class NormalizeNewlines

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

public final class NormalizeNewlines
extends java.lang.Object
implements TemplateTransformModel

Transformer that supports FreeMarker legacy behaviour: all newlines appearing within the transformed area will be transformed into the platform's default newline. Unlike the old behaviour, however, newlines generated by the data model are also converted. Legacy behaviour was to leave newlines in the data model unaltered.

Usage:
From java:

 TemplateModelRoot root = new SimpleHash();

 root.put( "normalizeNewlines", freemarker.ext.misc.NormalizeNewlines.getInstance() );

 ...
 

From your FM-Classic template:

 <transform normalizeNewlines>
   <html>
   <head>
   ...
   <p>This template has all newlines normalized to the current platform's
   default.</p>
   ...
   </body>
   </html>
 </transform>
 

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

Version:
$Id: NormalizeNewlines.java,v 1.8 2003/11/08 06:03:14 run2000 Exp $

Constructor Summary
NormalizeNewlines()
          Deprecated. use the getInstance() method to avoid excessive object creation
 
Method Summary
static NormalizeNewlines getInstance()
          Retrieve a singleton instance of this class.
 boolean isEmpty()
          Is the object empty?
 void transform(java.io.Reader source, java.io.PrintWriter output)
          Performs newline normalization on FM-Classic output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NormalizeNewlines

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

Creates new NormalizeNewlines.
Method Detail

getInstance

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

transform

public void transform(java.io.Reader source,
                      java.io.PrintWriter output)
               throws TemplateModelException
Performs newline normalization on FM-Classic output.
Specified by:
transform in interface TemplateTransformModel
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