1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. *
  5. * Copyright (c) 1999 The Apache Software Foundation. All rights
  6. * reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * 3. The end-user documentation included with the redistribution,
  21. * if any, must include the following acknowledgment:
  22. * "This product includes software developed by the
  23. * Apache Software Foundation (http://www.apache.org/)."
  24. * Alternately, this acknowledgment may appear in the software itself,
  25. * if and wherever such third-party acknowledgments normally appear.
  26. *
  27. * 4. The names "Xalan" and "Apache Software Foundation" must
  28. * not be used to endorse or promote products derived from this
  29. * software without prior written permission. For written
  30. * permission, please contact apache@apache.org.
  31. *
  32. * 5. Products derived from this software may not be called "Apache",
  33. * nor may "Apache" appear in their name, without prior written
  34. * permission of the Apache Software Foundation.
  35. *
  36. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  37. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  38. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  39. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  40. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  41. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  42. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  43. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  44. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  46. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  47. * SUCH DAMAGE.
  48. * ====================================================================
  49. *
  50. * This software consists of voluntary contributions made by many
  51. * individuals on behalf of the Apache Software Foundation and was
  52. * originally based on software copyright (c) 1999, Lotus
  53. * Development Corporation., http://www.lotus.com. For more
  54. * information on the Apache Software Foundation, please see
  55. * <http://www.apache.org/>.
  56. */
  57. package org.apache.xml.dtm;
  58. /**
  59. * Simple filter for doing node tests. Note the semantics of this are
  60. * somewhat different that the DOM's NodeFilter.
  61. */
  62. public interface DTMFilter
  63. {
  64. // Constants for whatToShow. These are used to set the node type that will
  65. // be traversed. These values may be ORed together before being passed to
  66. // the DTMIterator.
  67. /**
  68. * Show all <code>Nodes</code>.
  69. */
  70. public static final int SHOW_ALL = 0xFFFFFFFF;
  71. /**
  72. * Show <code>Element</code> nodes.
  73. */
  74. public static final int SHOW_ELEMENT = 0x00000001;
  75. /**
  76. * Show <code>Attr</code> nodes. This is meaningful only when creating an
  77. * iterator or tree-walker with an attribute node as its
  78. * <code>root</code> in this case, it means that the attribute node
  79. * will appear in the first position of the iteration or traversal.
  80. * Since attributes are never children of other nodes, they do not
  81. * appear when traversing over the main document tree.
  82. */
  83. public static final int SHOW_ATTRIBUTE = 0x00000002;
  84. /**
  85. * Show <code>Text</code> nodes.
  86. */
  87. public static final int SHOW_TEXT = 0x00000004;
  88. /**
  89. * Show <code>CDATASection</code> nodes.
  90. */
  91. public static final int SHOW_CDATA_SECTION = 0x00000008;
  92. /**
  93. * Show <code>EntityReference</code> nodes. Note that if Entity References
  94. * have been fully expanded while the tree was being constructed, these
  95. * nodes will not appear and this mask has no effect.
  96. */
  97. public static final int SHOW_ENTITY_REFERENCE = 0x00000010;
  98. /**
  99. * Show <code>Entity</code> nodes. This is meaningful only when creating
  100. * an iterator or tree-walker with an<code> Entity</code> node as its
  101. * <code>root</code> in this case, it means that the <code>Entity</code>
  102. * node will appear in the first position of the traversal. Since
  103. * entities are not part of the document tree, they do not appear when
  104. * traversing over the main document tree.
  105. */
  106. public static final int SHOW_ENTITY = 0x00000020;
  107. /**
  108. * Show <code>ProcessingInstruction</code> nodes.
  109. */
  110. public static final int SHOW_PROCESSING_INSTRUCTION = 0x00000040;
  111. /**
  112. * Show <code>Comment</code> nodes.
  113. */
  114. public static final int SHOW_COMMENT = 0x00000080;
  115. /**
  116. * Show <code>Document</code> nodes. (Of course, as with Attributes
  117. * and such, this is meaningful only when the iteration root is the
  118. * Document itself, since Document has no parent.)
  119. */
  120. public static final int SHOW_DOCUMENT = 0x00000100;
  121. /**
  122. * Show <code>DocumentType</code> nodes.
  123. */
  124. public static final int SHOW_DOCUMENT_TYPE = 0x00000200;
  125. /**
  126. * Show <code>DocumentFragment</code> nodes. (Of course, as with
  127. * Attributes and such, this is meaningful only when the iteration
  128. * root is the Document itself, since DocumentFragment has no parent.)
  129. */
  130. public static final int SHOW_DOCUMENT_FRAGMENT = 0x00000400;
  131. /**
  132. * Show <code>Notation</code> nodes. This is meaningful only when creating
  133. * an iterator or tree-walker with a <code>Notation</code> node as its
  134. * <code>root</code> in this case, it means that the
  135. * <code>Notation</code> node will appear in the first position of the
  136. * traversal. Since notations are not part of the document tree, they do
  137. * not appear when traversing over the main document tree.
  138. */
  139. public static final int SHOW_NOTATION = 0x00000800;
  140. /**
  141. * This bit instructs the iterator to show namespace nodes, which
  142. * are modeled by DTM but not by the DOM. Make sure this does not
  143. * conflict with {@link org.w3c.dom.traversal.NodeFilter}.
  144. * <p>
  145. * %REVIEW% Might be safer to start from higher bits and work down,
  146. * to leave room for the DOM to expand its set of constants... Or,
  147. * possibly, to create a DTM-specific field for these additional bits.
  148. */
  149. public static final int SHOW_NAMESPACE = 0x00001000;
  150. /**
  151. * Special bit for filters implementing match patterns starting with
  152. * a function. Make sure this does not conflict with
  153. * {@link org.w3c.dom.traversal.NodeFilter}.
  154. * <p>
  155. * %REVIEW% Might be safer to start from higher bits and work down,
  156. * to leave room for the DOM to expand its set of constants... Or,
  157. * possibly, to create a DTM-specific field for these additional bits.
  158. */
  159. public static final int SHOW_BYFUNCTION = 0x00010000;
  160. /**
  161. * Test whether a specified node is visible in the logical view of a
  162. * <code>DTMIterator</code>. Normally, this function
  163. * will be called by the implementation of <code>DTMIterator</code>
  164. * it is not normally called directly from
  165. * user code.
  166. *
  167. * @param nodeHandle int Handle of the node.
  168. * @param whatToShow one of SHOW_XXX values.
  169. * @return one of FILTER_ACCEPT, FILTER_REJECT, or FILTER_SKIP.
  170. */
  171. public short acceptNode(int nodeHandle, int whatToShow);
  172. /**
  173. * Test whether a specified node is visible in the logical view of a
  174. * <code>DTMIterator</code>. Normally, this function
  175. * will be called by the implementation of <code>DTMIterator</code>
  176. * it is not normally called directly from
  177. * user code.
  178. * <p>
  179. * TODO: Should this be setNameMatch(expandedName) followed by accept()?
  180. * Or will we really be testing a different name at every invocation?
  181. *
  182. * <p>%REVIEW% Under what circumstances will this be used? The cases
  183. * I've considered are just as easy and just about as efficient if
  184. * the name test is performed in the DTMIterator... -- Joe</p>
  185. *
  186. * <p>%REVIEW% Should that 0xFFFF have a mnemonic assigned to it?
  187. * Also: This representation is assuming the expanded name is indeed
  188. * split into high/low 16-bit halfwords. If we ever change the
  189. * balance between namespace and localname bits (eg because we
  190. * decide there are many more localnames than namespaces, which is
  191. * fairly likely), this is going to break. It might be safer to
  192. * encapsulate the details with a makeExpandedName method and make
  193. * that responsible for setting up the wildcard version as well.</p>
  194. *
  195. * @param nodeHandle int Handle of the node.
  196. * @param whatToShow one of SHOW_XXX values.
  197. * @param expandedName a value defining the exanded name as defined in
  198. * the DTM interface. Wild cards will be defined
  199. * by 0xFFFF in the namespace and/or localname
  200. * portion of the expandedName.
  201. * @return one of FILTER_ACCEPT, FILTER_REJECT, or FILTER_SKIP. */
  202. public short acceptNode(int nodeHandle, int whatToShow, int expandedName);
  203. }