freemarker.ext.misc
Class Translate

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

public final 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}.
 ...
 

Since:
1.9
Version:
$Id: Translate.java 1084 2013-03-27 10:12:06Z run2000 $
Author:
Nicholas Cull
See Also:
Serialized Form

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

Constructor Detail

Translate

public Translate()
Method Detail

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