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>NodeIterators</code> are used to step through a set of nodes, e.g.
  17. * the set of nodes in a <code>NodeList</code>, the document subtree
  18. * governed by a particular <code>Node</code>, the results of a query, or
  19. * any other set of nodes. The set of nodes to be iterated is determined by
  20. * the implementation of the <code>NodeIterator</code>. DOM Level 2
  21. * specifies a single <code>NodeIterator</code> implementation for
  22. * document-order traversal of a document subtree. Instances of these
  23. * <code>NodeIterators</code> are created by calling
  24. * <code>DocumentTraversal</code><code>.createNodeIterator()</code>.
  25. * <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>.
  26. * @since DOM Level 2
  27. */
  28. public interface NodeIterator {
  29. /**
  30. * The root node of the <code>NodeIterator</code>, as specified when it
  31. * was created.
  32. */
  33. public Node getRoot();
  34. /**
  35. * This attribute determines which node types are presented via the
  36. * <code>NodeIterator</code>. The available set of constants is defined
  37. * in the <code>NodeFilter</code> interface. Nodes not accepted by
  38. * <code>whatToShow</code> will be skipped, but their children may still
  39. * be considered. Note that this skip takes precedence over the filter,
  40. * if any.
  41. */
  42. public int getWhatToShow();
  43. /**
  44. * The <code>NodeFilter</code> used to screen nodes.
  45. */
  46. public NodeFilter getFilter();
  47. /**
  48. * The value of this flag determines whether the children of entity
  49. * reference nodes are visible to the <code>NodeIterator</code>. If
  50. * false, these children and their descendants will be rejected. Note
  51. * that this rejection takes precedence over <code>whatToShow</code> and
  52. * the filter. Also note that this is currently the only situation where
  53. * <code>NodeIterators</code> may reject a complete subtree rather than
  54. * skipping individual nodes.
  55. * <br>
  56. * <br> To produce a view of the document that has entity references
  57. * expanded and does not expose the entity reference node itself, use
  58. * the <code>whatToShow</code> flags to hide the entity reference node
  59. * and set <code>expandEntityReferences</code> to true when creating the
  60. * <code>NodeIterator</code>. To produce a view of the document that has
  61. * entity reference nodes but no entity expansion, use the
  62. * <code>whatToShow</code> flags to show the entity reference node and
  63. * set <code>expandEntityReferences</code> to false.
  64. */
  65. public boolean getExpandEntityReferences();
  66. /**
  67. * Returns the next node in the set and advances the position of the
  68. * <code>NodeIterator</code> in the set. After a
  69. * <code>NodeIterator</code> is created, the first call to
  70. * <code>nextNode()</code> returns the first node in the set.
  71. * @return The next <code>Node</code> in the set being iterated over, or
  72. * <code>null</code> if there are no more members in that set.
  73. * @exception DOMException
  74. * INVALID_STATE_ERR: Raised if this method is called after the
  75. * <code>detach</code> method was invoked.
  76. */
  77. public Node nextNode()
  78. throws DOMException;
  79. /**
  80. * Returns the previous node in the set and moves the position of the
  81. * <code>NodeIterator</code> backwards in the set.
  82. * @return The previous <code>Node</code> in the set being iterated over,
  83. * or <code>null</code> if there are no more members in that set.
  84. * @exception DOMException
  85. * INVALID_STATE_ERR: Raised if this method is called after the
  86. * <code>detach</code> method was invoked.
  87. */
  88. public Node previousNode()
  89. throws DOMException;
  90. /**
  91. * Detaches the <code>NodeIterator</code> from the set which it iterated
  92. * over, releasing any computational resources and placing the
  93. * <code>NodeIterator</code> in the INVALID state. After
  94. * <code>detach</code> has been invoked, calls to <code>nextNode</code>
  95. * or <code>previousNode</code> will raise the exception
  96. * INVALID_STATE_ERR.
  97. */
  98. public void detach();
  99. }