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