org.umber.catalan.transform.text
Class TextReplacer

java.lang.Object
  extended byorg.umber.catalan.transform.BaseNodeProcessor
      extended byorg.umber.catalan.transform.text.TextProcessor
          extended byorg.umber.catalan.transform.text.TextReplacer
All Implemented Interfaces:
INodeProcessor

public class TextReplacer
extends TextProcessor

A text processor which performs a simple search and replace action. Each TextReplacer instance will only handle a single static text replacement, but might replace it multiple times in the same text node. Thus, to change all instances of "pre" to "post" and all instances of "before" to "after", you would have to create two separate TextReplacer objects. This processor accepts only String input, and produces only String output.

Author:
jsheets

Constructor Summary
TextReplacer(Datum xml)
          Creates a new instance of TextReplacer from the XML spec.
TextReplacer(java.lang.String searchText, java.lang.String replaceText)
          Creates a new instance of TextReplacer.
 
Method Summary
protected  java.util.List processText(java.lang.String text)
          Processes the text node.
 void setReplaceCount(int count)
          Assigns the maximum number of times per node that the processor will replace text.
 java.lang.String toString()
          Convert this object to a String value.
 
Methods inherited from class org.umber.catalan.transform.text.TextProcessor
processNode
 
Methods inherited from class org.umber.catalan.transform.BaseNodeProcessor
addLeftover, end, getLeftovers, getNodes, start
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TextReplacer

public TextReplacer(Datum xml)
Creates a new instance of TextReplacer from the XML spec.

Parameters:
xml - XML initializing spec

TextReplacer

public TextReplacer(java.lang.String searchText,
                    java.lang.String replaceText)
Creates a new instance of TextReplacer.

Parameters:
searchText - text to search for in the input
replaceText - text to replace in the output
Method Detail

processText

protected java.util.List processText(java.lang.String text)
Processes the text node. Not called for non-String nodes.

Specified by:
processText in class TextProcessor
Parameters:
text - the text to process
Returns:
the processed text

setReplaceCount

public void setReplaceCount(int count)
Assigns the maximum number of times per node that the processor will replace text. For example, if you only want to replace the first two occurrences of the search text in a node, set the replace count to 2. Set to Integer.MAX_VALUE by default.

Parameters:
count - the maximum number of occurrences to replace

toString

public java.lang.String toString()
Convert this object to a String value.

Returns:
stringified object