1. /*
  2. * Copyright (c) 2004 World Wide Web Consortium,
  3. *
  4. * (Massachusetts Institute of Technology, European Research Consortium for
  5. * Informatics and Mathematics, Keio University). All Rights Reserved. This
  6. * work is distributed under the W3C(r) Software License [1] in the hope that
  7. * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
  8. * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. *
  10. * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
  11. */
  12. package org.w3c.dom.ls;
  13. import org.w3c.dom.Node;
  14. import org.w3c.dom.Element;
  15. /**
  16. * <code>LSParserFilter</code>s provide applications the ability to examine
  17. * nodes as they are being constructed while parsing. As each node is
  18. * examined, it may be modified or removed, or the entire parse may be
  19. * terminated early.
  20. * <p> At the time any of the filter methods are called by the parser, the
  21. * owner Document and DOMImplementation objects exist and are accessible.
  22. * The document element is never passed to the <code>LSParserFilter</code>
  23. * methods, i.e. it is not possible to filter out the document element.
  24. * <code>Document</code>, <code>DocumentType</code>, <code>Notation</code>,
  25. * <code>Entity</code>, and <code>Attr</code> nodes are never passed to the
  26. * <code>acceptNode</code> method on the filter. The child nodes of an
  27. * <code>EntityReference</code> node are passed to the filter if the
  28. * parameter "<a href='http://www.w3.org/TR/DOM-Level-3-Core/core.html#parameter-entities'>
  29. * entities</a>" is set to <code>false</code>. Note that, as described by the parameter "<a href='http://www.w3.org/TR/DOM-Level-3-Core/core.html#parameter-entities'>
  30. * entities</a>", unexpanded entity reference nodes are never discarded and are always
  31. * passed to the filter.
  32. * <p> All validity checking while parsing a document occurs on the source
  33. * document as it appears on the input stream, not on the DOM document as it
  34. * is built in memory. With filters, the document in memory may be a subset
  35. * of the document on the stream, and its validity may have been affected by
  36. * the filtering.
  37. * <p> All default attributes must be present on elements when the elements
  38. * are passed to the filter methods. All other default content must be
  39. * passed to the filter methods.
  40. * <p> DOM applications must not raise exceptions in a filter. The effect of
  41. * throwing exceptions from a filter is DOM implementation dependent.
  42. * <p>See also the <a href='http://www.w3.org/TR/2004/REC-DOM-Level-3-LS-20040407'>Document Object Model (DOM) Level 3 Load
  43. and Save Specification</a>.
  44. */
  45. public interface LSParserFilter {
  46. // Constants returned by startElement and acceptNode
  47. /**
  48. * Accept the node.
  49. */
  50. public static final short FILTER_ACCEPT = 1;
  51. /**
  52. * Reject the node and its children.
  53. */
  54. public static final short FILTER_REJECT = 2;
  55. /**
  56. * Skip this single node. The children of this node will still be
  57. * considered.
  58. */
  59. public static final short FILTER_SKIP = 3;
  60. /**
  61. * Interrupt the normal processing of the document.
  62. */
  63. public static final short FILTER_INTERRUPT = 4;
  64. /**
  65. * The parser will call this method after each <code>Element</code> start
  66. * tag has been scanned, but before the remainder of the
  67. * <code>Element</code> is processed. The intent is to allow the
  68. * element, including any children, to be efficiently skipped. Note that
  69. * only element nodes are passed to the <code>startElement</code>
  70. * function.
  71. * <br>The element node passed to <code>startElement</code> for filtering
  72. * will include all of the Element's attributes, but none of the
  73. * children nodes. The Element may not yet be in place in the document
  74. * being constructed (it may not have a parent node.)
  75. * <br>A <code>startElement</code> filter function may access or change
  76. * the attributes for the Element. Changing Namespace declarations will
  77. * have no effect on namespace resolution by the parser.
  78. * <br>For efficiency, the Element node passed to the filter may not be
  79. * the same one as is actually placed in the tree if the node is
  80. * accepted. And the actual node (node object identity) may be reused
  81. * during the process of reading in and filtering a document.
  82. * @param elementArg The newly encountered element. At the time this
  83. * method is called, the element is incomplete - it will have its
  84. * attributes, but no children.
  85. * @return
  86. * <ul>
  87. * <li> <code>FILTER_ACCEPT</code> if the <code>Element</code> should
  88. * be included in the DOM document being built.
  89. * </li>
  90. * <li>
  91. * <code>FILTER_REJECT</code> if the <code>Element</code> and all of
  92. * its children should be rejected.
  93. * </li>
  94. * <li> <code>FILTER_SKIP</code> if the
  95. * <code>Element</code> should be skipped. All of its children are
  96. * inserted in place of the skipped <code>Element</code> node.
  97. * </li>
  98. * <li>
  99. * <code>FILTER_INTERRUPT</code> if the filter wants to stop the
  100. * processing of the document. Interrupting the processing of the
  101. * document does no longer guarantee that the resulting DOM tree is
  102. * XML well-formed. The <code>Element</code> is rejected.
  103. * </li>
  104. * </ul> Returning
  105. * any other values will result in unspecified behavior.
  106. */
  107. public short startElement(Element elementArg);
  108. /**
  109. * This method will be called by the parser at the completion of the
  110. * parsing of each node. The node and all of its descendants will exist
  111. * and be complete. The parent node will also exist, although it may be
  112. * incomplete, i.e. it may have additional children that have not yet
  113. * been parsed. Attribute nodes are never passed to this function.
  114. * <br>From within this method, the new node may be freely modified -
  115. * children may be added or removed, text nodes modified, etc. The state
  116. * of the rest of the document outside this node is not defined, and the
  117. * affect of any attempt to navigate to, or to modify any other part of
  118. * the document is undefined.
  119. * <br>For validating parsers, the checks are made on the original
  120. * document, before any modification by the filter. No validity checks
  121. * are made on any document modifications made by the filter.
  122. * <br>If this new node is rejected, the parser might reuse the new node
  123. * and any of its descendants.
  124. * @param nodeArg The newly constructed element. At the time this method
  125. * is called, the element is complete - it has all of its children
  126. * (and their children, recursively) and attributes, and is attached
  127. * as a child to its parent.
  128. * @return
  129. * <ul>
  130. * <li> <code>FILTER_ACCEPT</code> if this <code>Node</code> should
  131. * be included in the DOM document being built.
  132. * </li>
  133. * <li>
  134. * <code>FILTER_REJECT</code> if the <code>Node</code> and all of its
  135. * children should be rejected.
  136. * </li>
  137. * <li> <code>FILTER_SKIP</code> if the
  138. * <code>Node</code> should be skipped and the <code>Node</code>
  139. * should be replaced by all the children of the <code>Node</code>.
  140. * </li>
  141. * <li>
  142. * <code>FILTER_INTERRUPT</code> if the filter wants to stop the
  143. * processing of the document. Interrupting the processing of the
  144. * document does no longer guarantee that the resulting DOM tree is
  145. * XML well-formed. The <code>Node</code> is accepted and will be the
  146. * last completely parsed node.
  147. * </li>
  148. * </ul>
  149. */
  150. public short acceptNode(Node nodeArg);
  151. /**
  152. * Tells the <code>LSParser</code> what types of nodes to show to the
  153. * method <code>LSParserFilter.acceptNode</code>. If a node is not shown
  154. * to the filter using this attribute, it is automatically included in
  155. * the DOM document being built. See <code>NodeFilter</code> for
  156. * definition of the constants. The constants <code>SHOW_ATTRIBUTE</code>
  157. * , <code>SHOW_DOCUMENT</code>, <code>SHOW_DOCUMENT_TYPE</code>,
  158. * <code>SHOW_NOTATION</code>, <code>SHOW_ENTITY</code>, and
  159. * <code>SHOW_DOCUMENT_FRAGMENT</code> are meaningless here. Those nodes
  160. * will never be passed to <code>LSParserFilter.acceptNode</code>.
  161. * <br> The constants used here are defined in [<a href='http://www.w3.org/TR/2000/REC-DOM-Level-2-Traversal-Range-20001113'>DOM Level 2 Traversal and Range</a>]
  162. * .
  163. */
  164. public int getWhatToShow();
  165. }