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. */
  80. public Node getCurrentNode();
  81. /**
  82. * The node at which the <code>TreeWalker</code> is currently positioned.
  83. * <br>Alterations to the DOM tree may cause the current node to no longer
  84. * be accepted by the <code>TreeWalker</code>'s associated filter.
  85. * <code>currentNode</code> may also be explicitly set to any node,
  86. * whether or not it is within the subtree specified by the
  87. * <code>root</code> node or would be accepted by the filter and
  88. * <code>whatToShow</code> flags. Further traversal occurs relative to
  89. * <code>currentNode</code> even if it is not part of the current view,
  90. * by applying the filters in the requested direction; if no traversal
  91. * is possible, <code>currentNode</code> is not changed.
  92. * @exception DOMException
  93. * NOT_SUPPORTED_ERR: Raised if an attempt is made to set
  94. * <code>currentNode</code> to <code>null</code>.
  95. */
  96. public void setCurrentNode(Node currentNode)
  97. throws DOMException;
  98. /**
  99. * Moves to and returns the closest visible ancestor node of the current
  100. * node. If the search for <code>parentNode</code> attempts to step
  101. * upward from the <code>TreeWalker</code>'s <code>root</code> node, or
  102. * if it fails to find a visible ancestor node, this method retains the
  103. * current position and returns <code>null</code>.
  104. * @return The new parent node, or <code>null</code> if the current node
  105. * has no parent in the <code>TreeWalker</code>'s logical view.
  106. */
  107. public Node parentNode();
  108. /**
  109. * Moves the <code>TreeWalker</code> to the first visible child of the
  110. * current node, and returns the new node. If the current node has no
  111. * visible children, returns <code>null</code>, and retains the current
  112. * node.
  113. * @return The new node, or <code>null</code> if the current node has no
  114. * visible children in the <code>TreeWalker</code>'s logical view.
  115. */
  116. public Node firstChild();
  117. /**
  118. * Moves the <code>TreeWalker</code> to the last visible child of the
  119. * current node, and returns the new node. If the current node has no
  120. * visible children, returns <code>null</code>, and retains the current
  121. * node.
  122. * @return The new node, or <code>null</code> if the current node has no
  123. * children in the <code>TreeWalker</code>'s logical view.
  124. */
  125. public Node lastChild();
  126. /**
  127. * Moves the <code>TreeWalker</code> to the previous sibling of the
  128. * current node, and returns the new node. If the current node has no
  129. * visible previous sibling, returns <code>null</code>, and retains the
  130. * current node.
  131. * @return The new node, or <code>null</code> if the current node has no
  132. * previous sibling. in the <code>TreeWalker</code>'s logical view.
  133. */
  134. public Node previousSibling();
  135. /**
  136. * Moves the <code>TreeWalker</code> to the next sibling of the current
  137. * node, and returns the new node. If the current node has no visible
  138. * next sibling, returns <code>null</code>, and retains the current node.
  139. * @return The new node, or <code>null</code> if the current node has no
  140. * next sibling. in the <code>TreeWalker</code>'s logical view.
  141. */
  142. public Node nextSibling();
  143. /**
  144. * Moves the <code>TreeWalker</code> to the previous visible node in
  145. * document order relative to the current node, and returns the new
  146. * node. If the current node has no previous node, or if the search for
  147. * <code>previousNode</code> attempts to step upward from the
  148. * <code>TreeWalker</code>'s <code>root</code> node, returns
  149. * <code>null</code>, and retains the current node.
  150. * @return The new node, or <code>null</code> if the current node has no
  151. * previous node in the <code>TreeWalker</code>'s logical view.
  152. */
  153. public Node previousNode();
  154. /**
  155. * Moves the <code>TreeWalker</code> to the next visible node in document
  156. * order relative to the current node, and returns the new node. If the
  157. * current node has no next node, or if the search for nextNode attempts
  158. * to step upward from the <code>TreeWalker</code>'s <code>root</code>
  159. * node, returns <code>null</code>, and retains the current node.
  160. * @return The new node, or <code>null</code> if the current node has no
  161. * next node in the <code>TreeWalker</code>'s logical view.
  162. */
  163. public Node nextNode();
  164. }