|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.enhydra.xml.dom.DOMTraversal
Class that traverse a DOM tree or subtree, calling handler methods for each node. It is up to the handler methods to make a decision on processing child and element nodes by explictly calling the methods to continue the traversal. This is gives the handler more control and actually kept the code simpler for both this class and the client.
While DOM traversal is straight-forward, traversing the LazyDOM while avoiding expansion made things tricker. This class, and the derived class for the LazyDOM, handles these special cases.
Inner Class Summary | |
static interface |
DOMTraversal.Handler
Interface for node callback object. |
class |
DOMTraversal.NodeHandler
Implementation of handler that calls a single method for all node types. |
Field Summary | |
static int |
ALL_ATTRIBUTES
Option flag to indicate that unspecified attributes should be included. |
protected int |
fDepth
Current traversal tree depth |
protected DOMTraversal.Handler |
fHandler
Handler object for the traversal |
protected int |
fOptions
Options controlling the traversal. |
protected boolean |
fProcessingAttribute
Are we processing an attribute or its children? |
static int |
SORT_ATTRIBUTES
Option flag to indicate that attributes should be sorted before calling the handlers. |
Constructor Summary | |
DOMTraversal(DOMTraversal.Handler handler,
int options)
Constructor. |
|
DOMTraversal(int options)
Default constructor, set handler later. |
Method Summary | |
int |
getDepth()
Get the current depth in the DOM tree that is being traversed. |
static DOMTraversal |
getTraverser(DOMTraversal.Handler handler,
int options,
Node node)
Factory method to create a traverser based on the type of a document. |
void |
processAttributes(Element element)
Process the attributes of an element. |
void |
processChildren(Node node)
Process the children of a node. |
void |
processDocumentType(Document document)
Process a DocumentType attribute of a Document node, if it exists. |
void |
processDocumentTypeContents(DocumentType documentType)
Process the contents of a DocumentType node, |
boolean |
processingAttribute()
Are we currently processing an attribute node or its descendents? |
protected void |
processNode(Node node)
Processing based on node type. |
void |
setHandler(DOMTraversal.Handler handler)
Set the handler. |
void |
traverse(Node root)
Traverse a DOM tree or subtree. |
Methods inherited from class java.lang.Object |
|
Field Detail |
public static final int SORT_ATTRIBUTES
public static final int ALL_ATTRIBUTES
protected DOMTraversal.Handler fHandler
protected int fOptions
protected int fDepth
protected boolean fProcessingAttribute
Constructor Detail |
public DOMTraversal(DOMTraversal.Handler handler, int options)
handler
- The object that will be called to handle each
node.options
- Bit set of the option flags.public DOMTraversal(int options)
Method Detail |
public void setHandler(DOMTraversal.Handler handler)
public void traverse(Node root)
root
- The root of the DOM tree or subtree that is to
be traversed.DOMError
- Any internal exceptions are encapsulated
in this error.public final int getDepth()
public final boolean processingAttribute()
public void processChildren(Node node)
public void processAttributes(Element element)
public void processDocumentType(Document document)
public void processDocumentTypeContents(DocumentType documentType)
protected void processNode(Node node)
public static DOMTraversal getTraverser(DOMTraversal.Handler handler, int options, Node node)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |