freemarker.ext.misc
Class NormalizeNewlines

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

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

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 1105 2013-04-09 10:52:59Z run2000 $
See Also:
CompressLines, Serialized Form

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
 

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
Throws:
TemplateModelException

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
Throws:
TemplateModelException