1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /*
  17. * $Id: DTMFilter.java,v 1.4 2004/02/16 23:03:44 minchau Exp $
  18. */
  19. package com.sun.org.apache.xml.internal.dtm;
  20. /**
  21. * Simple filter for doing node tests. Note the semantics of this are
  22. * somewhat different that the DOM's NodeFilter.
  23. */
  24. public interface DTMFilter
  25. {
  26. // Constants for whatToShow. These are used to set the node type that will
  27. // be traversed. These values may be ORed together before being passed to
  28. // the DTMIterator.
  29. /**
  30. * Show all <code>Nodes</code>.
  31. */
  32. public static final int SHOW_ALL = 0xFFFFFFFF;
  33. /**
  34. * Show <code>Element</code> nodes.
  35. */
  36. public static final int SHOW_ELEMENT = 0x00000001;
  37. /**
  38. * Show <code>Attr</code> nodes. This is meaningful only when creating an
  39. * iterator or tree-walker with an attribute node as its
  40. * <code>root</code> in this case, it means that the attribute node
  41. * will appear in the first position of the iteration or traversal.
  42. * Since attributes are never children of other nodes, they do not
  43. * appear when traversing over the main document tree.
  44. */
  45. public static final int SHOW_ATTRIBUTE = 0x00000002;
  46. /**
  47. * Show <code>Text</code> nodes.
  48. */
  49. public static final int SHOW_TEXT = 0x00000004;
  50. /**
  51. * Show <code>CDATASection</code> nodes.
  52. */
  53. public static final int SHOW_CDATA_SECTION = 0x00000008;
  54. /**
  55. * Show <code>EntityReference</code> nodes. Note that if Entity References
  56. * have been fully expanded while the tree was being constructed, these
  57. * nodes will not appear and this mask has no effect.
  58. */
  59. public static final int SHOW_ENTITY_REFERENCE = 0x00000010;
  60. /**
  61. * Show <code>Entity</code> nodes. This is meaningful only when creating
  62. * an iterator or tree-walker with an<code> Entity</code> node as its
  63. * <code>root</code> in this case, it means that the <code>Entity</code>
  64. * node will appear in the first position of the traversal. Since
  65. * entities are not part of the document tree, they do not appear when
  66. * traversing over the main document tree.
  67. */
  68. public static final int SHOW_ENTITY = 0x00000020;
  69. /**
  70. * Show <code>ProcessingInstruction</code> nodes.
  71. */
  72. public static final int SHOW_PROCESSING_INSTRUCTION = 0x00000040;
  73. /**
  74. * Show <code>Comment</code> nodes.
  75. */
  76. public static final int SHOW_COMMENT = 0x00000080;
  77. /**
  78. * Show <code>Document</code> nodes. (Of course, as with Attributes
  79. * and such, this is meaningful only when the iteration root is the
  80. * Document itself, since Document has no parent.)
  81. */
  82. public static final int SHOW_DOCUMENT = 0x00000100;
  83. /**
  84. * Show <code>DocumentType</code> nodes.
  85. */
  86. public static final int SHOW_DOCUMENT_TYPE = 0x00000200;
  87. /**
  88. * Show <code>DocumentFragment</code> nodes. (Of course, as with
  89. * Attributes and such, this is meaningful only when the iteration
  90. * root is the Document itself, since DocumentFragment has no parent.)
  91. */
  92. public static final int SHOW_DOCUMENT_FRAGMENT = 0x00000400;
  93. /**
  94. * Show <code>Notation</code> nodes. This is meaningful only when creating
  95. * an iterator or tree-walker with a <code>Notation</code> node as its
  96. * <code>root</code> in this case, it means that the
  97. * <code>Notation</code> node will appear in the first position of the
  98. * traversal. Since notations are not part of the document tree, they do
  99. * not appear when traversing over the main document tree.
  100. */
  101. public static final int SHOW_NOTATION = 0x00000800;
  102. /**
  103. * This bit instructs the iterator to show namespace nodes, which
  104. * are modeled by DTM but not by the DOM. Make sure this does not
  105. * conflict with {@link org.w3c.dom.traversal.NodeFilter}.
  106. * <p>
  107. * %REVIEW% Might be safer to start from higher bits and work down,
  108. * to leave room for the DOM to expand its set of constants... Or,
  109. * possibly, to create a DTM-specific field for these additional bits.
  110. */
  111. public static final int SHOW_NAMESPACE = 0x00001000;
  112. /**
  113. * Special bit for filters implementing match patterns starting with
  114. * a function. Make sure this does not conflict with
  115. * {@link org.w3c.dom.traversal.NodeFilter}.
  116. * <p>
  117. * %REVIEW% Might be safer to start from higher bits and work down,
  118. * to leave room for the DOM to expand its set of constants... Or,
  119. * possibly, to create a DTM-specific field for these additional bits.
  120. */
  121. public static final int SHOW_BYFUNCTION = 0x00010000;
  122. /**
  123. * Test whether a specified node is visible in the logical view of a
  124. * <code>DTMIterator</code>. Normally, this function
  125. * will be called by the implementation of <code>DTMIterator</code>
  126. * it is not normally called directly from
  127. * user code.
  128. *
  129. * @param nodeHandle int Handle of the node.
  130. * @param whatToShow one of SHOW_XXX values.
  131. * @return one of FILTER_ACCEPT, FILTER_REJECT, or FILTER_SKIP.
  132. */
  133. public short acceptNode(int nodeHandle, int whatToShow);
  134. /**
  135. * Test whether a specified node is visible in the logical view of a
  136. * <code>DTMIterator</code>. Normally, this function
  137. * will be called by the implementation of <code>DTMIterator</code>
  138. * it is not normally called directly from
  139. * user code.
  140. * <p>
  141. * TODO: Should this be setNameMatch(expandedName) followed by accept()?
  142. * Or will we really be testing a different name at every invocation?
  143. *
  144. * <p>%REVIEW% Under what circumstances will this be used? The cases
  145. * I've considered are just as easy and just about as efficient if
  146. * the name test is performed in the DTMIterator... -- Joe</p>
  147. *
  148. * <p>%REVIEW% Should that 0xFFFF have a mnemonic assigned to it?
  149. * Also: This representation is assuming the expanded name is indeed
  150. * split into high/low 16-bit halfwords. If we ever change the
  151. * balance between namespace and localname bits (eg because we
  152. * decide there are many more localnames than namespaces, which is
  153. * fairly likely), this is going to break. It might be safer to
  154. * encapsulate the details with a makeExpandedName method and make
  155. * that responsible for setting up the wildcard version as well.</p>
  156. *
  157. * @param nodeHandle int Handle of the node.
  158. * @param whatToShow one of SHOW_XXX values.
  159. * @param expandedName a value defining the exanded name as defined in
  160. * the DTM interface. Wild cards will be defined
  161. * by 0xFFFF in the namespace and/or localname
  162. * portion of the expandedName.
  163. * @return one of FILTER_ACCEPT, FILTER_REJECT, or FILTER_SKIP. */
  164. public short acceptNode(int nodeHandle, int whatToShow, int expandedName);
  165. }