org.itsnat.core.domutil
Class ItsNatTreeWalker

java.lang.Object
  extended by org.itsnat.core.domutil.ItsNatTreeWalker

public class ItsNatTreeWalker
extends java.lang.Object

Utility class used to easily iterate a DOM tree, specially DOM elements.

Most of methods have been inspired by org.w3c.dom.traversal.TreeWalker.

Author:
Jose Maria Arranz Santamaria

Constructor Summary
ItsNatTreeWalker()
           
 
Method Summary
static int getChildElementCount(org.w3c.dom.Node node)
          Returns the number of child elements of the specified node.
static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node node)
          Returns the first direct child org.w3c.dom.Element below the specified node.
static org.w3c.dom.Element getFirstChildElementWithTagName(org.w3c.dom.Node parent, java.lang.String tagName)
          Returns the first direct child element with the specified tag name.
static org.w3c.dom.Element getFirstChildElementWithTagNameNS(org.w3c.dom.Node parent, java.lang.String namespaceURI, java.lang.String localName)
          Returns the first direct child element with the specified namespace and local name.
static org.w3c.dom.Element getFirstDeepestChildElement(org.w3c.dom.Node node)
          Returns the first and deepest element below the specified node.
static org.w3c.dom.Element getLastChildElement(org.w3c.dom.Node node)
          Returns the last direct child org.w3c.dom.Element below the specified node.
static org.w3c.dom.Element getNextElement(org.w3c.dom.Node node)
          Returns the next org.w3c.dom.Element following the specified node in document order.
static org.w3c.dom.Node getNextNode(org.w3c.dom.Node node)
          Returns the next node following the specified node in document order.
static org.w3c.dom.Element getNextSiblingElement(org.w3c.dom.Node node)
          Returns the next sibling org.w3c.dom.Element following the specified node.
static org.w3c.dom.Element getParentElement(org.w3c.dom.Node node)
          Returns the first parent org.w3c.dom.Element of specified node.
static org.w3c.dom.Element getPreviousElement(org.w3c.dom.Node node)
          Returns the previous org.w3c.dom.Element following the specified node in document order.
static org.w3c.dom.Node getPreviousNode(org.w3c.dom.Node node)
          Returns the previous node following the specified node in document order.
static org.w3c.dom.Element getPreviousSiblingElement(org.w3c.dom.Node node)
          Returns the previous sibling org.w3c.dom.Element following the specified node.
static boolean hasChildElements(org.w3c.dom.Node node)
          Informs whether the specified node has child elements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ItsNatTreeWalker

public ItsNatTreeWalker()
Method Detail

hasChildElements

public static boolean hasChildElements(org.w3c.dom.Node node)
Informs whether the specified node has child elements.

Parameters:
node - the node to inspect.
Returns:
true if the specified node has child elements.

getChildElementCount

public static int getChildElementCount(org.w3c.dom.Node node)
Returns the number of child elements of the specified node.

Parameters:
node - the node to inspect.
Returns:
the number of child elements.

getFirstChildElement

public static org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node node)
Returns the first direct child org.w3c.dom.Element below the specified node. Any child non-element is ignored.

Parameters:
node - the node parent.
Returns:
the first child element. Null if the parent node has no child element.

getLastChildElement

public static org.w3c.dom.Element getLastChildElement(org.w3c.dom.Node node)
Returns the last direct child org.w3c.dom.Element below the specified node. Any child non-element is ignored.

Parameters:
node - the node parent.
Returns:
the last child element. Null if the parent node has no child element.

getNextSiblingElement

public static org.w3c.dom.Element getNextSiblingElement(org.w3c.dom.Node node)
Returns the next sibling org.w3c.dom.Element following the specified node. Any non-element is ignored.

Parameters:
node - the original node.
Returns:
the next sibling element. Null if the node has no next sibling element (last child element).

getPreviousSiblingElement

public static org.w3c.dom.Element getPreviousSiblingElement(org.w3c.dom.Node node)
Returns the previous sibling org.w3c.dom.Element following the specified node. Any non-element is ignored.

Parameters:
node - the original node.
Returns:
the previous sibling element. Null if the node has no previous sibling element (first child element).

getParentElement

public static org.w3c.dom.Element getParentElement(org.w3c.dom.Node node)
Returns the first parent org.w3c.dom.Element of specified node. Any non-element parent is ignored.

Parameters:
node - the original node.
Returns:
the first parent element. Null if the node has no parent element (for instance, the document root element).

getPreviousElement

public static org.w3c.dom.Element getPreviousElement(org.w3c.dom.Node node)
Returns the previous org.w3c.dom.Element following the specified node in document order. Any non-element is ignored.

Parameters:
node - the original node.
Returns:
the previous element. Null if the node has no previous element.

getNextElement

public static org.w3c.dom.Element getNextElement(org.w3c.dom.Node node)
Returns the next org.w3c.dom.Element following the specified node in document order. Any non-element is ignored.

Parameters:
node - the original node.
Returns:
the next element. Null if the node has no next element.

getPreviousNode

public static org.w3c.dom.Node getPreviousNode(org.w3c.dom.Node node)
Returns the previous node following the specified node in document order.

Parameters:
node - the original node.
Returns:
the previous node. Null if the node has no previous node.

getNextNode

public static org.w3c.dom.Node getNextNode(org.w3c.dom.Node node)
Returns the next node following the specified node in document order.

Parameters:
node - the original node.
Returns:
the next node. Null if the node has no next node.

getFirstChildElementWithTagName

public static org.w3c.dom.Element getFirstChildElementWithTagName(org.w3c.dom.Node parent,
                                                                  java.lang.String tagName)
Returns the first direct child element with the specified tag name.

Parameters:
parent - the parent node.
tagName - the tag name to search for, the search is case sensitive.
Returns:
the first direct child element with this tag or null if not found.

getFirstChildElementWithTagNameNS

public static org.w3c.dom.Element getFirstChildElementWithTagNameNS(org.w3c.dom.Node parent,
                                                                    java.lang.String namespaceURI,
                                                                    java.lang.String localName)
Returns the first direct child element with the specified namespace and local name.

Parameters:
parent - the parent node.
namespaceURI - the namespace of the element to search for, the search is case sensitive.
localName - the local name of the element to search for, the search is case sensitive.
Returns:
the first direct child element with this namespace and tag name or null if not found.

getFirstDeepestChildElement

public static org.w3c.dom.Element getFirstDeepestChildElement(org.w3c.dom.Node node)
Returns the first and deepest element below the specified node.

For instance if node is the <table> element:

   <table>
      <tbody>
          <tr>
              <td>One</td>
          </tr>
          <tr>
              <td>Two</td>
          </tr>
      </tbody>
   </table>
 

Returns the <td> element parent of One

Parameters:
node - the parent node to search.
Returns:
the first deepest child element. Null if there is no child element.


Copyright © 2007 Innowhere Software Services S.L. All Rights Reserved.