org.openpipeline.pipeline.item
Class Item

java.lang.Object
  extended by org.openpipeline.pipeline.item.Item

public class Item
extends Object

An Item is the main object that the pipeline operates on. An Item is a document, database record, or other data structure that contains fields and text. The pipeline passes an Item from one Stage to the next where it gets transformed in some manner at each step.

An Item is similar to a DOM tree. It maps very closely to an XML-like data structure. Each tag in an XML document is a Node. See the Node class for more on the structure of Nodes.

Each item can carry a unique ID. See setItemId(String)/getItemId().

Each item can carry attribute definitions. An "attribute" in this case is a path through the tags of the document. See AttributeDef for more.

Each item can carry an "action". An action can be ACTION_ADD, ACTION_UPDATE, or ACTION_DELETE. The action is intended to tell the last stage in the pipeline what to do with the item. See setAction(int).


Field Summary
static int ACTION_ADD
           
static int ACTION_DELETE
           
static int ACTION_UPDATE
           
 
Constructor Summary
Item()
           
Item(int bufSize)
          Constructor
 
Method Summary
 void appendXMLtoBuffer(FastStringBuffer xmlBuf)
           
 void appendXMLtoBuffer(FastStringBuffer xmlBuf, boolean includeAnnotations)
           
 void clear()
           
 int getAction()
           
 Map<String,AttributeDef> getAttributeDefs()
          Return a Map of AttributeDef objects, where the key is the attributeId and the value is the AttributeDef.
 FastStringBuffer getBuffer()
           
 String getItemId()
          Get the itemId, the primary key for this item.
 Node getRootNode()
           
 boolean hasAttributeDefs()
          Return true if this item has any AttributeDefs attached to it.
 void importXML(Reader in)
          Parses the specified XML and populates this item, creating nodes as needed.
 void importXML(String xml)
          Convenience method equivalent to importXML(new StringReader(xml));
 void setAction(int action)
           
 void setAttributeDefs(Map<String,AttributeDef> attributeDefs)
          Set a Map of AttributeDef objects, where the key is the attributeId and the value is the AttributeDef.
 void setItemId(String itemId)
          Set the itemId, the primary key for this item.
 void setRootNode(Node newRoot)
           
 String toString()
           
 void visitNodes(NodeVisitor visitor)
          This method makes it easier for a class to process all the nodes in an item.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ACTION_ADD

public static final int ACTION_ADD
See Also:
Constant Field Values

ACTION_UPDATE

public static final int ACTION_UPDATE
See Also:
Constant Field Values

ACTION_DELETE

public static final int ACTION_DELETE
See Also:
Constant Field Values
Constructor Detail

Item

public Item()

Item

public Item(int bufSize)
Constructor

Parameters:
bufSize - the starting size of the internal text buffer
Method Detail

getRootNode

public Node getRootNode()

setRootNode

public void setRootNode(Node newRoot)

clear

public void clear()

getBuffer

public FastStringBuffer getBuffer()

getAction

public int getAction()

setAction

public void setAction(int action)

setItemId

public void setItemId(String itemId)
Set the itemId, the primary key for this item.

Parameters:
itemId - the itemId

getItemId

public String getItemId()
Get the itemId, the primary key for this item.

Returns:
the itemId, or null if one has not been set

importXML

public void importXML(String xml)
Convenience method equivalent to importXML(new StringReader(xml));

Parameters:
xml - the XML to import
Throws:
IOException
See Also:
XMLFilter

importXML

public void importXML(Reader in)
Parses the specified XML and populates this item, creating nodes as needed. Replaces any existing data.

Parameters:
in - a stream of characters that contains XML.
Throws:
IOException
See Also:
XMLFilter

toString

public String toString()
Overrides:
toString in class Object

appendXMLtoBuffer

public void appendXMLtoBuffer(FastStringBuffer xmlBuf)

appendXMLtoBuffer

public void appendXMLtoBuffer(FastStringBuffer xmlBuf,
                              boolean includeAnnotations)

visitNodes

public void visitNodes(NodeVisitor visitor)
                throws PipelineException
This method makes it easier for a class to process all the nodes in an item. The class should implement the NodeVisitor interface. This method will cause the NodeVisitor.processNode() method to be called once for each node in this item. Within the processNode() method, it's typical to have code like this:
 switch (node.getType()) {
 case Node.TEXT:
     // deal with text node
     break;
 case Node.TAG:
 case Node.ATTRIBUTE:
     // etc
     break;
 }
 

Parameters:
visitor - the class that will visit each node
Throws:
PipelineException - some recoverable exception

getAttributeDefs

public Map<String,AttributeDef> getAttributeDefs()
Return a Map of AttributeDef objects, where the key is the attributeId and the value is the AttributeDef.

Returns:
the Map, or null if none has been defined

setAttributeDefs

public void setAttributeDefs(Map<String,AttributeDef> attributeDefs)
Set a Map of AttributeDef objects, where the key is the attributeId and the value is the AttributeDef.

Parameters:
attributeDefs - the Map of AttributeDefs

hasAttributeDefs

public boolean hasAttributeDefs()
Return true if this item has any AttributeDefs attached to it.

Returns:
true if AttributeDefs have been defined