org.umber.core.text.filters
Class TextResolver

java.lang.Object
  extended byorg.umber.core.text.filters.TextResolver
All Implemented Interfaces:
ITextFilter

public class TextResolver
extends java.lang.Object
implements ITextFilter

Text filter which performs variable lookup and substitution from a Map of values. The syntax of the variable can be defined by either a start and end token, or by a regular expression.

Author:
jsheets

Constructor Summary
TextResolver(java.util.Map map, boolean swallowUndefined)
          Creates a new instance of TextResolver with default token delimiters "${" and "}".
TextResolver(java.util.Map map, java.lang.String regexp, boolean swallowUndefined)
          Creates a new instance of TextResolver with static start and end token delimiters.
TextResolver(java.util.Map map, java.lang.String startToken, java.lang.String endToken, boolean swallowUndefined)
          Creates a new instance of TextResolver with static start and end token delimiters.
 
Method Summary
 java.lang.String filterText(java.lang.String text)
          Sends input document through a modifying filter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextResolver

public TextResolver(java.util.Map map,
                    boolean swallowUndefined)
Creates a new instance of TextResolver with default token delimiters "${" and "}".

Parameters:
map - variable resolution lookup map
swallowUndefined - true to remove variables that don't exist in lookup map, or false to pass them through untouched

TextResolver

public TextResolver(java.util.Map map,
                    java.lang.String startToken,
                    java.lang.String endToken,
                    boolean swallowUndefined)
Creates a new instance of TextResolver with static start and end token delimiters.

Parameters:
map - variable resolution lookup map
startToken - start token to find variables
endToken - end token to find variables
swallowUndefined - true to remove variables that don't exist in lookup map, or false to pass them through untouched

TextResolver

public TextResolver(java.util.Map map,
                    java.lang.String regexp,
                    boolean swallowUndefined)
Creates a new instance of TextResolver with static start and end token delimiters.

Parameters:
map - variable resolution lookup map
regexp - regular expression to find variables
swallowUndefined - true to remove variables that don't exist in lookup map, or false to pass them through untouched
Method Detail

filterText

public java.lang.String filterText(java.lang.String text)
Sends input document through a modifying filter.

This implementation finds and replaces all matching variables by values in the lookup map.

Specified by:
filterText in interface ITextFilter
Parameters:
text - input text document
Returns:
modified version of input document