org.writersforge.catalan.transform.xform
Class InsertProcessor

java.lang.Object
  extended byorg.writersforge.catalan.transform.BaseNodeProcessor
      extended byorg.writersforge.catalan.transform.xform.XFormProcessor
          extended byorg.writersforge.catalan.transform.xform.InsertProcessor
All Implemented Interfaces:
org.writersforge.bellows.traverse.NodeProcessor

public class InsertProcessor
extends XFormProcessor

A Datum-only NodeProcessor for inserting static XML content into other parts of the same XML tree. Works on element content or on attributes.

Author:
jsheets

Constructor Summary
InsertProcessor(org.writersforge.bellows.Datum xml)
          Creates a new instance of InsertProcessor from the XML spec.
InsertProcessor(java.lang.String query, org.writersforge.bellows.Datum newContent, int position, boolean expand)
          Creates a new instance of InsertProcessor for element creation.
InsertProcessor(java.lang.String query, java.lang.String propertyName, java.lang.String propertyValue)
          Creates a new instance of InsertProcessor for attribute creation.
 
Method Summary
 void start(java.util.List nodes)
          Starts a new traversal.
protected  org.writersforge.bellows.Datum transformNode(org.writersforge.bellows.Datum node, org.writersforge.bellows.Datum root)
          Performs an in-place transformation on the supplied Datum tree.
 
Methods inherited from class org.writersforge.catalan.transform.xform.XFormProcessor
getQuery, getQueryNodes, processNode
 
Methods inherited from class org.writersforge.catalan.transform.BaseNodeProcessor
addLeftover, end, getLeftovers, getNodes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InsertProcessor

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

Parameters:
xml - XML initializing spec

InsertProcessor

public InsertProcessor(java.lang.String query,
                       org.writersforge.bellows.Datum newContent,
                       int position,
                       boolean expand)
Creates a new instance of InsertProcessor for element creation. If the expand parameter is true, the processor will search the inserted content for query paths in the form of "${query}", for example "${root/child}", and insert the results of that query at that point as Datum content.

Parameters:
query - Bellows query path to select the source node(s)
newContent - static XML to insert
position - the index position to insert nodes, or -1 to insert at end of list
expand - if true, resolve embedded query paths into live data

InsertProcessor

public InsertProcessor(java.lang.String query,
                       java.lang.String propertyName,
                       java.lang.String propertyValue)
Creates a new instance of InsertProcessor for attribute creation.

Parameters:
query - Bellows query path to select the source node(s)
propertyName - name of new attribute to create
propertyValue - value of new attribute
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

transformNode

protected org.writersforge.bellows.Datum transformNode(org.writersforge.bellows.Datum node,
                                                       org.writersforge.bellows.Datum root)
Performs an in-place transformation on the supplied Datum tree.

Specified by:
transformNode in class XFormProcessor
Parameters:
node - the current node to operate upon
root - the root of the entire XML tree
Returns:
the new root Datum object (usually the same one)