freemarker.ext.misc
Class Translate

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

public class Translate
extends java.lang.Object
implements TemplateMethodModel, java.io.Serializable

A method model that implements the Perl 5 translate function. This uses the JTR library to perform the translation.

Usage:
From java:

 TemplateModelRoot root = new SimpleHash();

 root.put( "translate", new freemarker.ext.misc.Translate() );

 ...
 

From your FM-Classic template:

 The following is stripped of all duplicate spaces:
 <assign text = "   This paragraph has  all  excess  spaces  removed.">
 <assign output = translate( "tr/ //s", text )>

 ${output}

 The result is ${output.result}, the number of matches was ${output.matches}.
 ...
 

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

Since:
1.9
Version:
$Id: Translate.java 1093 2005-08-30 12:23:57Z run2000 $
Author:
Nicholas Cull
See Also:
Serialized Form

Method Summary
 TemplateModel exec(java.util.List<java.lang.String> arguments)
          Executes a method call.
static Translate getInstance()
          Retrieve a singleton instance of this class.
 boolean isEmpty()
          Is the object empty?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

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

isEmpty

public boolean isEmpty()
                throws TemplateModelException
Description copied from interface: TemplateModel
Is the object empty?

Specified by:
isEmpty in interface TemplateModel
Returns:
true if this object is empty, otherwise false
Throws:
TemplateModelException

exec

public TemplateModel exec(java.util.List<java.lang.String> arguments)
                   throws TemplateModelException
Description copied from interface: TemplateMethodModel
Executes a method call. Arguments are passed as a List of String objects.

Specified by:
exec in interface TemplateMethodModel
Parameters:
arguments - a List of String objects containing the values of the arguments passed to the method.
Returns:
the TemplateModel produced by the method, or null.
Throws:
TemplateModelException