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. /**
  15. * Filters are objects that know how to "filter out" nodes. If a
  16. * <code>NodeIterator</code> or <code>TreeWalker</code> is given a
  17. * <code>NodeFilter</code>, it applies the filter before it returns the next
  18. * node. If the filter says to accept the node, the traversal logic returns
  19. * it; otherwise, traversal looks for the next node and pretends that the
  20. * node that was rejected was not there.
  21. * <p>The DOM does not provide any filters. <code>NodeFilter</code> is just an
  22. * interface that users can implement to provide their own filters.
  23. * <p><code>NodeFilters</code> do not need to know how to traverse from node
  24. * to node, nor do they need to know anything about the data structure that
  25. * is being traversed. This makes it very easy to write filters, since the
  26. * only thing they have to know how to do is evaluate a single node. One
  27. * filter may be used with a number of different kinds of traversals,
  28. * encouraging code reuse.
  29. * <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>.
  30. * @since DOM Level 2
  31. */
  32. public interface NodeFilter {
  33. // Constants returned by acceptNode
  34. /**
  35. * Accept the node. Navigation methods defined for
  36. * <code>NodeIterator</code> or <code>TreeWalker</code> will return this
  37. * node.
  38. */
  39. public static final short FILTER_ACCEPT = 1;
  40. /**
  41. * Reject the node. Navigation methods defined for
  42. * <code>NodeIterator</code> or <code>TreeWalker</code> will not return
  43. * this node. For <code>TreeWalker</code>, the children of this node
  44. * will also be rejected. <code>NodeIterators</code> treat this as a
  45. * synonym for <code>FILTER_SKIP</code>.
  46. */
  47. public static final short FILTER_REJECT = 2;
  48. /**
  49. * Skip this single node. Navigation methods defined for
  50. * <code>NodeIterator</code> or <code>TreeWalker</code> will not return
  51. * this node. For both <code>NodeIterator</code> and
  52. * <code>TreeWalker</code>, the children of this node will still be
  53. * considered.
  54. */
  55. public static final short FILTER_SKIP = 3;
  56. // Constants for whatToShow
  57. /**
  58. * Show all <code>Nodes</code>.
  59. */
  60. public static final int SHOW_ALL = 0xFFFFFFFF;
  61. /**
  62. * Show <code>Element</code> nodes.
  63. */
  64. public static final int SHOW_ELEMENT = 0x00000001;
  65. /**
  66. * Show <code>Attr</code> nodes. This is meaningful only when creating an
  67. * <code>NodeIterator</code> or <code>TreeWalker</code> with an
  68. * attribute node as its <code>root</code> in this case, it means that
  69. * the attribute node will appear in the first position of the iteration
  70. * or traversal. Since attributes are never children of other nodes,
  71. * they do not appear when traversing over the document tree.
  72. */
  73. public static final int SHOW_ATTRIBUTE = 0x00000002;
  74. /**
  75. * Show <code>Text</code> nodes.
  76. */
  77. public static final int SHOW_TEXT = 0x00000004;
  78. /**
  79. * Show <code>CDATASection</code> nodes.
  80. */
  81. public static final int SHOW_CDATA_SECTION = 0x00000008;
  82. /**
  83. * Show <code>EntityReference</code> nodes.
  84. */
  85. public static final int SHOW_ENTITY_REFERENCE = 0x00000010;
  86. /**
  87. * Show <code>Entity</code> nodes. This is meaningful only when creating
  88. * an <code>NodeIterator</code> or <code>TreeWalker</code> with an
  89. * <code>Entity</code> node as its <code>root</code> in this case, it
  90. * means that the <code>Entity</code> node will appear in the first
  91. * position of the traversal. Since entities are not part of the
  92. * document tree, they do not appear when traversing over the document
  93. * tree.
  94. */
  95. public static final int SHOW_ENTITY = 0x00000020;
  96. /**
  97. * Show <code>ProcessingInstruction</code> nodes.
  98. */
  99. public static final int SHOW_PROCESSING_INSTRUCTION = 0x00000040;
  100. /**
  101. * Show <code>Comment</code> nodes.
  102. */
  103. public static final int SHOW_COMMENT = 0x00000080;
  104. /**
  105. * Show <code>Document</code> nodes.
  106. */
  107. public static final int SHOW_DOCUMENT = 0x00000100;
  108. /**
  109. * Show <code>DocumentType</code> nodes.
  110. */
  111. public static final int SHOW_DOCUMENT_TYPE = 0x00000200;
  112. /**
  113. * Show <code>DocumentFragment</code> nodes.
  114. */
  115. public static final int SHOW_DOCUMENT_FRAGMENT = 0x00000400;
  116. /**
  117. * Show <code>Notation</code> nodes. This is meaningful only when creating
  118. * an <code>NodeIterator</code> or <code>TreeWalker</code> with a
  119. * <code>Notation</code> node as its <code>root</code> in this case, it
  120. * means that the <code>Notation</code> node will appear in the first
  121. * position of the traversal. Since notations are not part of the
  122. * document tree, they do not appear when traversing over the document
  123. * tree.
  124. */
  125. public static final int SHOW_NOTATION = 0x00000800;
  126. /**
  127. * Test whether a specified node is visible in the logical view of a
  128. * <code>TreeWalker</code> or <code>NodeIterator</code>. This function
  129. * will be called by the implementation of <code>TreeWalker</code> and
  130. * <code>NodeIterator</code> it is not normally called directly from
  131. * user code. (Though you could do so if you wanted to use the same
  132. * filter to guide your own application logic.)
  133. * @param n The node to check to see if it passes the filter or not.
  134. * @return A constant to determine whether the node is accepted,
  135. * rejected, or skipped, as defined above.
  136. */
  137. public short acceptNode(Node n);
  138. }