freemarker.ext.misc
Class XmlEscape

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

public final class XmlEscape
extends java.lang.Object
implements TemplateTransformModel2, java.io.Serializable

Performs an XML escape of a given template fragment. Specifically, < > " ' and & are all turned into entities.

Usage:
From java:

 TemplateModelRoot root = new SimpleHash();

 root.put( "xmlEscape", freemarker.ext.misc.XmlEscape.getInstance() );

 ...
 

From your FM-Classic template:

 The following is XML-escaped:
 <transform xmlEscape>
   <p>This paragraph has all XML special characters escaped.</p>
 </transform>

 ...
 

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

Version:
$Id: XmlEscape.java 1101 2013-04-01 04:17:32Z run2000 $
See Also:
HtmlEscape, Serialized Form

Method Summary
static XmlEscape getInstance()
          Retrieve a singleton instance of this class.
 boolean isEmpty()
          Is the object empty?
 void transform(java.io.Reader source, java.io.Writer output)
          Transforms an XML-unescaped stream into XML-escaped form.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

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

transform

public void transform(java.io.Reader source,
                      java.io.Writer output)
               throws java.io.IOException,
                      TemplateModelException
Transforms an XML-unescaped stream into XML-escaped form. This means: < > & ' and " are all escaped into their equivalent entities.

Specified by:
transform in interface TemplateTransformModel2
Parameters:
source - the input to be transformed
output - the destination of the transformation
Throws:
java.io.IOException
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