edu.uci.isr.yancees.util
Class DOMNodeAdapter

java.lang.Object
  extended by edu.uci.isr.yancees.util.DOMNodeAdapter

public class DOMNodeAdapter
extends java.lang.Object

This class wraps a DOM node and returns the text we want to display in the tree. It also returns children, index values, and child counts. This class is used by the Managers, by the Event class and others to perform common operations around the DOM tree.


Field Summary
static java.lang.String CONTEXT_SEPARATOR
           
static java.lang.String TYPE_ATTRIBUTE
           
 
Constructor Summary
DOMNodeAdapter(org.w3c.dom.Node node)
           
DOMNodeAdapter(org.w3c.dom.Node node, java.lang.String[] validNames)
           
DOMNodeAdapter(org.w3c.dom.Node node, java.lang.String[] validNames, boolean doFilter)
           
 
Method Summary
 DOMNodeAdapter child(int searchIndex)
          Gets the child indexed.
 int childCount()
          Count the number of children of the current node.
 org.w3c.dom.Node[] getElementsByName(java.lang.String tagName)
          Searches the current DOM tree recursively looking for elements with the provided name.
 org.w3c.dom.Node getFirstElementByName(java.lang.String tagName)
          Searches the current DOM tree recursively looking for the first element with the provided name.
static java.lang.String getFullContext(org.w3c.dom.Node father)
          This method is declared static for performance reasons, preventing the creation of a DOMNodeAdapter for each node that one would like to parse.
 java.lang.String getFullPath()
           
static java.lang.String getFullPath(org.w3c.dom.Node father)
          This method is declared static for performance reasons, preventing the creation of a DOMNodeAdapter for each node that one would like to parse.
 java.lang.String getHTMLContent()
          Prints the HTML content of the current Node.
 java.lang.String getNodeText()
           
 org.w3c.dom.Node[] getVisibleElementsBFS()
           
 org.w3c.dom.Node[] getVisibleElementsDFS()
           
 boolean hasChildElement(java.lang.String elementName)
           
 int index(DOMNodeAdapter child)
           
 boolean isFilteringNodes()
           
 boolean isTreeElement(java.lang.String elementName)
          Used to filter the XML Schema elements to consider while parsing this DOM tree.
 void printNodeTree()
          Recursively parsers the dom model, using the facilities of the DOMNodeAdapter class, and prints it to the standard output.
 void printNodeTree(org.w3c.dom.Node n)
          Recursively parsers the dom model, using the facilities of the DOMNodeAdapter class, and prints it to the standard output.
 void setFilterNodes(boolean mode)
          Sets the display of visible tree nodes to be active or inactive.
 void setVisibleTreeElementNames(java.lang.String[] names)
          Allows the specification of a list of elements to filter in all operations.
 java.lang.String toString()
          Return a string that identifies this node in the tree
 java.lang.String toXML()
           
 java.lang.String toXMLIndented()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE_ATTRIBUTE

public static final java.lang.String TYPE_ATTRIBUTE
See Also:
Constant Field Values

CONTEXT_SEPARATOR

public static final java.lang.String CONTEXT_SEPARATOR
See Also:
Constant Field Values
Constructor Detail

DOMNodeAdapter

public DOMNodeAdapter(org.w3c.dom.Node node)

DOMNodeAdapter

public DOMNodeAdapter(org.w3c.dom.Node node,
                      java.lang.String[] validNames)
Parameters:
node - is the head of the subtree
validNames - is the visibleTreeElementNames

DOMNodeAdapter

public DOMNodeAdapter(org.w3c.dom.Node node,
                      java.lang.String[] validNames,
                      boolean doFilter)
Parameters:
node - is the head of the subtree
validNames - is the visibleTreeElementNames
Method Detail

toString

public java.lang.String toString()
Return a string that identifies this node in the tree

Overrides:
toString in class java.lang.Object

getHTMLContent

public java.lang.String getHTMLContent()
Prints the HTML content of the current Node. You can probably use it to display the current node content in a web browser.


getVisibleElementsDFS

public org.w3c.dom.Node[] getVisibleElementsDFS()
Returns:
a list of elements which are visible according to the filter specified with the setVisibleTreeElementNames() method. The answer is given as a list of nodes obtained in a Depth First Search (DFS) search of the tree.

getVisibleElementsBFS

public org.w3c.dom.Node[] getVisibleElementsBFS()
Returns:
a list of elements which are visible according to the filter specified with the setVisibleTreeElementNames() method. The answer is given as a list of nodes obtained in a Breadth first Search (BFS) search of the tree.

getFullPath

public java.lang.String getFullPath()
Returns:
the full path name from this node to the very father of the tree

index

public int index(DOMNodeAdapter child)
Parameters:
child - a node to be searched among the immediate chindren of this node.
Returns:
the index of a provided node in the current represented node (and its sub-elements) in this DOMNodeAdapter. Returns -1 if the provided node is not a child of the current node.

child

public DOMNodeAdapter child(int searchIndex)
Gets the child indexed. If compression is on, considers only nodes of type ELEMENT_TYPE.

Parameters:
searchIndex - is the index of the children of current node to be returned as a DOMNodeAdapter

childCount

public int childCount()
Count the number of children of the current node. Counts only the element type nodes.


hasChildElement

public boolean hasChildElement(java.lang.String elementName)
Parameters:
elementName - is the name of the ELEMENT_TYPE node to search
Returns:
true if the current node has a child element called elementName

getNodeText

public java.lang.String getNodeText()
Returns:
the text 'value' of a node like value or null in case this value does not exist or this operatio does not apply to the current node.

getElementsByName

public org.w3c.dom.Node[] getElementsByName(java.lang.String tagName)
Searches the current DOM tree recursively looking for elements with the provided name.


getFirstElementByName

public org.w3c.dom.Node getFirstElementByName(java.lang.String tagName)
Searches the current DOM tree recursively looking for the first element with the provided name.

Returns:
the first occurrence of the provided element or null if not found.

isTreeElement

public boolean isTreeElement(java.lang.String elementName)
Used to filter the XML Schema elements to consider while parsing this DOM tree. It uses the contents of the treeElementNames for that.


setVisibleTreeElementNames

public void setVisibleTreeElementNames(java.lang.String[] names)
Allows the specification of a list of elements to filter in all operations. The other elements, not specified in this list are not considered.


setFilterNodes

public void setFilterNodes(boolean mode)
Sets the display of visible tree nodes to be active or inactive.


isFilteringNodes

public boolean isFilteringNodes()
Returns:
whether the display of only visibleTreeNodes is on or off

printNodeTree

public void printNodeTree()
Recursively parsers the dom model, using the facilities of the DOMNodeAdapter class, and prints it to the standard output.


printNodeTree

public void printNodeTree(org.w3c.dom.Node n)
Recursively parsers the dom model, using the facilities of the DOMNodeAdapter class, and prints it to the standard output.


toXML

public java.lang.String toXML()
Returns:
a compact xml version of the dom tree headed in this adapter.

toXMLIndented

public java.lang.String toXMLIndented()
Returns:
a human-readable xml text, with enters and indentation, of the tree this object represents.

getFullPath

public static java.lang.String getFullPath(org.w3c.dom.Node father)
This method is declared static for performance reasons, preventing the creation of a DOMNodeAdapter for each node that one would like to parse.

Returns:
the full path name from this node to the very father of the tree

getFullContext

public static java.lang.String getFullContext(org.w3c.dom.Node father)
This method is declared static for performance reasons, preventing the creation of a DOMNodeAdapter for each node that one would like to parse.

Returns:
the full context (path without the node name) from this node to the very father of the tree.