1. /*
  2. * Copyright (c) 2000 World Wide Web Consortium,
  3. * (Massachusetts Institute of Technology, Institut National de
  4. * Recherche en Informatique et en Automatique, Keio University). All
  5. * Rights Reserved. This program is distributed under the W3C's Software
  6. * Intellectual Property License. This program is distributed in the
  7. * hope that it will be useful, but WITHOUT ANY WARRANTY; without even
  8. * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  9. * PURPOSE.
  10. * See W3C License http://www.w3.org/Consortium/Legal/ for more details.
  11. */
  12. package org.w3c.dom.traversal;
  13. import org.w3c.dom.Node;
  14. import org.w3c.dom.DOMException;
  15. /**
  16. * <code>TreeWalker</code> objects are used to navigate a document tree or
  17. * subtree using the view of the document defined by their
  18. * <code>whatToShow</code> flags and filter (if any). Any function which
  19. * performs navigation using a <code>TreeWalker</code> will automatically
  20. * support any view defined by a <code>TreeWalker</code>.
  21. * <p>Omitting nodes from the logical view of a subtree can result in a
  22. * structure that is substantially different from the same subtree in the
  23. * complete, unfiltered document. Nodes that are siblings in the
  24. * <code>TreeWalker</code> view may be children of different, widely
  25. * separated nodes in the original view. For instance, consider a
  26. * <code>NodeFilter</code> that skips all nodes except for Text nodes and
  27. * the root node of a document. In the logical view that results, all text
  28. * nodes will be siblings and appear as direct children of the root node, no
  29. * matter how deeply nested the structure of the original document.
  30. * <p>See also the <a href='http://www.w3.org/TR/2000/REC-DOM-Level-2-Traversal-Range-20001113'>Document Object Model (DOM) Level 2 Traversal and Range Specification</a>.
  31. * @since DOM Level 2
  32. */
  33. public interface TreeWalker {
  34. /**
  35. * The <code>root</code> node of the <code>TreeWalker</code>, as specified
  36. * when it was created.
  37. */
  38. public Node getRoot();
  39. /**
  40. * This attribute determines which node types are presented via the
  41. * <code>TreeWalker</code>. The available set of constants is defined in
  42. * the <code>NodeFilter</code> interface. Nodes not accepted by
  43. * <code>whatToShow</code> will be skipped, but their children may still
  44. * be considered. Note that this skip takes precedence over the filter,
  45. * if any.
  46. */
  47. public int getWhatToShow();
  48. /**
  49. * The filter used to screen nodes.
  50. */
  51. public NodeFilter getFilter();
  52. /**
  53. * The value of this flag determines whether the children of entity
  54. * reference nodes are visible to the <code>TreeWalker</code>. If false,
  55. * these children and their descendants will be rejected. Note that
  56. * this rejection takes precedence over <code>whatToShow</code> and the
  57. * filter, if any.
  58. * <br> To produce a view of the document that has entity references
  59. * expanded and does not expose the entity reference node itself, use
  60. * the <code>whatToShow</code> flags to hide the entity reference node
  61. * and set <code>expandEntityReferences</code> to true when creating the
  62. * <code>TreeWalker</code>. To produce a view of the document that has
  63. * entity reference nodes but no entity expansion, use the
  64. * <code>whatToShow</code> flags to show the entity reference node and
  65. * set <code>expandEntityReferences</code> to false.
  66. */
  67. public boolean getExpandEntityReferences();
  68. /**
  69. * The node at which the <code>TreeWalker</code> is currently positioned.
  70. * <br>Alterations to the DOM tree may cause the current node to no longer
  71. * be accepted by the <code>TreeWalker</code>'s associated filter.
  72. * <code>currentNode</code> may also be explicitly set to any node,
  73. * whether or not it is within the subtree specified by the
  74. * <code>root</code> node or would be accepted by the filter and
  75. * <code>whatToShow</code> flags. Further traversal occurs relative to
  76. * <code>currentNode</code> even if it is not part of the current view,
  77. * by applying the filters in the requested direction; if no traversal
  78. * is possible, <code>currentNode</code> is not changed.
  79. * @exception DOMException
  80. * NOT_SUPPORTED_ERR: Raised if an attempt is made to set
  81. * <code>currentNode</code> to <code>null</code>.
  82. */
  83. public Node getCurrentNode();
  84. /**
  85. * The node at which the <code>TreeWalker</code> is currently positioned.
  86. * <br>Alterations to the DOM tree may cause the current node to no longer
  87. * be accepted by the <code>TreeWalker</code>'s associated filter.
  88. * <code>currentNode</code> may also be explicitly set to any node,
  89. * whether or not it is within the subtree specified by the
  90. * <code>root</code> node or would be accepted by the filter and
  91. * <code>whatToShow</code> flags. Further traversal occurs relative to
  92. * <code>currentNode</code> even if it is not part of the current view,
  93. * by applying the filters in the requested direction; if no traversal
  94. * is possible, <code>currentNode</code> is not changed.
  95. * @exception DOMException
  96. * NOT_SUPPORTED_ERR: Raised if an attempt is made to set
  97. * <code>currentNode</code> to <code>null</code>.
  98. */
  99. public void setCurrentNode(Node currentNode)
  100. throws DOMException;
  101. /**
  102. * Moves to and returns the closest visible ancestor node of the current
  103. * node. If the search for <code>parentNode</code> attempts to step
  104. * upward from the <code>TreeWalker</code>'s <code>root</code> node, or
  105. * if it fails to find a visible ancestor node, this method retains the
  106. * current position and returns <code>null</code>.
  107. * @return The new parent node, or <code>null</code> if the current node
  108. * has no parent in the <code>TreeWalker</code>'s logical view.
  109. */
  110. public Node parentNode();
  111. /**
  112. * Moves the <code>TreeWalker</code> to the first visible child of the
  113. * current node, and returns the new node. If the current node has no
  114. * visible children, returns <code>null</code>, and retains the current
  115. * node.
  116. * @return The new node, or <code>null</code> if the current node has no
  117. * visible children in the <code>TreeWalker</code>'s logical view.
  118. */
  119. public Node firstChild();
  120. /**
  121. * Moves the <code>TreeWalker</code> to the last visible child of the
  122. * current node, and returns the new node. If the current node has no
  123. * visible children, returns <code>null</code>, and retains the current
  124. * node.
  125. * @return The new node, or <code>null</code> if the current node has no
  126. * children in the <code>TreeWalker</code>'s logical view.
  127. */
  128. public Node lastChild();
  129. /**
  130. * Moves the <code>TreeWalker</code> to the previous sibling of the
  131. * current node, and returns the new node. If the current node has no
  132. * visible previous sibling, returns <code>null</code>, and retains the
  133. * current node.
  134. * @return The new node, or <code>null</code> if the current node has no
  135. * previous sibling. in the <code>TreeWalker</code>'s logical view.
  136. */
  137. public Node previousSibling();
  138. /**
  139. * Moves the <code>TreeWalker</code> to the next sibling of the current
  140. * node, and returns the new node. If the current node has no visible
  141. * next sibling, returns <code>null</code>, and retains the current node.
  142. * @return The new node, or <code>null</code> if the current node has no
  143. * next sibling. in the <code>TreeWalker</code>'s logical view.
  144. */
  145. public Node nextSibling();
  146. /**
  147. * Moves the <code>TreeWalker</code> to the previous visible node in
  148. * document order relative to the current node, and returns the new
  149. * node. If the current node has no previous node, or if the search for
  150. * <code>previousNode</code> attempts to step upward from the
  151. * <code>TreeWalker</code>'s <code>root</code> node, returns
  152. * <code>null</code>, and retains the current node.
  153. * @return The new node, or <code>null</code> if the current node has no
  154. * previous node in the <code>TreeWalker</code>'s logical view.
  155. */
  156. public Node previousNode();
  157. /**
  158. * Moves the <code>TreeWalker</code> to the next visible node in document
  159. * order relative to the current node, and returns the new node. If the
  160. * current node has no next node, or if the search for nextNode attempts
  161. * to step upward from the <code>TreeWalker</code>'s <code>root</code>
  162. * node, returns <code>null</code>, and retains the current node.
  163. * @return The new node, or <code>null</code> if the current node has no
  164. * next node in the <code>TreeWalker</code>'s logical view.
  165. */
  166. public Node nextNode();
  167. }