freemarker.ext.misc
Class Perl5Translate

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

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

Perform Perl 5 translation using the JTR library. A list of translate expressions is passed in, and executed in order on a line-by-line basis. The result of this transformation is always terminated by a newline sequence.

Usage:
From java:

 TemplateModelRoot root = new SimpleHash();

 root.put( "translate", freemarker.ext.misc.Perl5Translate.getInstance() );

 ...
 

From your FM-Classic template:

 The following removes all duplicate spaces:
 <transform translate( "tr/ //s" )>
    This paragraph has  all  excess  spaces  removed.
 </transform>

 ...
 

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

Since:
1.9
Version:
$Id: Perl5Translate.java 1153 2013-04-15 10:59:37Z run2000 $
Author:
Nicholas Cull
See Also:
Serialized Form

Method Summary
 TemplateModel exec(java.util.List<java.lang.String> arguments)
          Executes a method call.
static Perl5Translate getInstance()
          Return a new 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 Perl5Translate getInstance()
Return a new instance of this class. No state is held in the method model itself. Rather, the method model creates a new instance of the transformation class itself whenever it is called. The transformation class holds all state information about the translations.

Returns:
a new instance of the Perl5Substitute method model

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