org.writersforge.catalan.transform.text
Class Concatenator

java.lang.Object
  extended byorg.writersforge.catalan.transform.BaseNodeProcessor
      extended byorg.writersforge.catalan.transform.text.Concatenator
All Implemented Interfaces:
org.writersforge.bellows.traverse.NodeProcessor

public class Concatenator
extends BaseNodeProcessor

A processor which converts all input nodes into String formats and concatenates them into a single output String node. Calls String.valueOf() on most nodes, but will convert Datum trees into XML before concatenating them.

Author:
jsheets

Constructor Summary
Concatenator(org.writersforge.bellows.Datum xml)
          Creates a new instance of Concatenator from the XML spec.
Concatenator(int count, java.lang.String separator)
          Creates a new instance of Concatenator with a maximum node count and a separator.
 
Method Summary
 void end(java.util.List nodes)
          Ends the current traversal.
 java.util.List processNode(java.lang.Object node)
          Process a single node.
 void start(java.util.List nodes)
          Starts a new traversal.
 
Methods inherited from class org.writersforge.catalan.transform.BaseNodeProcessor
addLeftover, getLeftovers, getNodes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Concatenator

public Concatenator(org.writersforge.bellows.Datum xml)
Creates a new instance of Concatenator from the XML spec.

Parameters:
xml - XML initializing spec

Concatenator

public Concatenator(int count,
                    java.lang.String separator)
Creates a new instance of Concatenator with a maximum node count and a separator. The separator text is placed between each node in the final output, but not before the first node or after the last node.

Parameters:
count - the maximum number of input data nodes to concatenate
separator - text to place between each node in the final output
Method Detail

start

public void start(java.util.List nodes)
Starts a new traversal. This method initializes the processor for a new traversal over a set of nodes. The nodes are not actually traversed or processed at this point, but the processor is allowed to perform any pre-traversal calculations, for example storing the total number of nodes for index calculations.

Specified by:
start in interface org.writersforge.bellows.traverse.NodeProcessor
Overrides:
start in class BaseNodeProcessor
Parameters:
nodes - the list of nodes that will later be traversed

end

public void end(java.util.List nodes)
Ends the current traversal. Any post-processing on the post-traversal nodes should be done here, for example removing duplicate nodes. This method should also clean up any temporary states created during a traversal. After end(), the processor should be ready for the next new traversal.

Specified by:
end in interface org.writersforge.bellows.traverse.NodeProcessor
Overrides:
end in class BaseNodeProcessor
Parameters:
nodes - the list of nodes that has just been traversed

processNode

public java.util.List processNode(java.lang.Object node)
Process a single node. The processing action can be any arbitrary task, such as text replacement, data restructuring, or even statistical gathering. The processor should return a processed version of the node; this can be the same object untouched, or the same object modified, or a new set of objects.

Parameters:
node - the node to process
Returns:
a List of processing results (can be empty)