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 parameter 60 * "<a href='https://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#parameter-entities'>entities</a>" 61 * is set to <code>false</code>. Note that, as described by the parameter 62 * "<a href='https://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html#parameter-entities'>entities</a>", 63 * unexpanded entity reference nodes are never discarded and are always 64 * passed to the filter. 65 * <p> All validity checking while parsing a document occurs on the source 66 * document as it appears on the input stream, not on the DOM document as it 67 * is built in memory. With filters, the document in memory may be a subset 68 * of the document on the stream, and its validity may have been affected by 69 * the filtering. 70 * <p> All default attributes must be present on elements when the elements 71 * are passed to the filter methods. All other default content must be 72 * passed to the filter methods. 73 * <p> DOM applications must not raise exceptions in a filter. The effect of 74 * throwing exceptions from a filter is DOM implementation dependent. 75 * <p>See also the <a href='http://www.w3.org/TR/2004/REC-DOM-Level-3-LS-20040407'> 76 Document Object Model (DOM) Level 3 Load and Save Specification</a>. 77 * 78 * @since 1.5 79 */ 80 public interface LSParserFilter { 81 // Constants returned by startElement and acceptNode 82 /** 83 * Accept the node. 84 */ 85 public static final short FILTER_ACCEPT = 1; 86 /** 87 * Reject the node and its children. 88 */ 89 public static final short FILTER_REJECT = 2; 90 /** 91 * Skip this single node. The children of this node will still be 92 * considered. 93 */ 94 public static final short FILTER_SKIP = 3; 95 /** 96 * Interrupt the normal processing of the document. 97 */ 98 public static final short FILTER_INTERRUPT = 4; 99 100 /** 101 * The parser will call this method after each <code>Element</code> start 102 * tag has been scanned, but before the remainder of the 103 * <code>Element</code> is processed. The intent is to allow the 104 * element, including any children, to be efficiently skipped. Note that 105 * only element nodes are passed to the <code>startElement</code> 106 * function. 107 * <br>The element node passed to <code>startElement</code> for filtering 108 * will include all of the Element's attributes, but none of the 109 * children nodes. The Element may not yet be in place in the document 110 * being constructed (it may not have a parent node.) 111 * <br>A <code>startElement</code> filter function may access or change 112 * the attributes for the Element. Changing Namespace declarations will 113 * have no effect on namespace resolution by the parser. 114 * <br>For efficiency, the Element node passed to the filter may not be 115 * the same one as is actually placed in the tree if the node is 116 * accepted. And the actual node (node object identity) may be reused 117 * during the process of reading in and filtering a document. 118 * @param elementArg The newly encountered element. At the time this 119 * method is called, the element is incomplete - it will have its 120 * attributes, but no children. 121 * @return 122 * <ul> 123 * <li> <code>FILTER_ACCEPT</code> if the <code>Element</code> should 124 * be included in the DOM document being built. 125 * </li> 126 * <li> 127 * <code>FILTER_REJECT</code> if the <code>Element</code> and all of 128 * its children should be rejected. 129 * </li> 130 * <li> <code>FILTER_SKIP</code> if the 131 * <code>Element</code> should be skipped. All of its children are 132 * inserted in place of the skipped <code>Element</code> node. 133 * </li> 134 * <li> 135 * <code>FILTER_INTERRUPT</code> if the filter wants to stop the 136 * processing of the document. Interrupting the processing of the 137 * document does no longer guarantee that the resulting DOM tree is 138 * XML well-formed. The <code>Element</code> is rejected. 139 * </li> 140 * </ul> Returning 141 * any other values will result in unspecified behavior. 142 */ startElement(Element elementArg)143 public short startElement(Element elementArg); 144 145 /** 146 * This method will be called by the parser at the completion of the 147 * parsing of each node. The node and all of its descendants will exist 148 * and be complete. The parent node will also exist, although it may be 149 * incomplete, i.e. it may have additional children that have not yet 150 * been parsed. Attribute nodes are never passed to this function. 151 * <br>From within this method, the new node may be freely modified - 152 * children may be added or removed, text nodes modified, etc. The state 153 * of the rest of the document outside this node is not defined, and the 154 * affect of any attempt to navigate to, or to modify any other part of 155 * the document is undefined. 156 * <br>For validating parsers, the checks are made on the original 157 * document, before any modification by the filter. No validity checks 158 * are made on any document modifications made by the filter. 159 * <br>If this new node is rejected, the parser might reuse the new node 160 * and any of its descendants. 161 * @param nodeArg The newly constructed element. At the time this method 162 * is called, the element is complete - it has all of its children 163 * (and their children, recursively) and attributes, and is attached 164 * as a child to its parent. 165 * @return 166 * <ul> 167 * <li> <code>FILTER_ACCEPT</code> if this <code>Node</code> should 168 * be included in the DOM document being built. 169 * </li> 170 * <li> 171 * <code>FILTER_REJECT</code> if the <code>Node</code> and all of its 172 * children should be rejected. 173 * </li> 174 * <li> <code>FILTER_SKIP</code> if the 175 * <code>Node</code> should be skipped and the <code>Node</code> 176 * should be replaced by all the children of the <code>Node</code>. 177 * </li> 178 * <li> 179 * <code>FILTER_INTERRUPT</code> if the filter wants to stop the 180 * processing of the document. Interrupting the processing of the 181 * document does no longer guarantee that the resulting DOM tree is 182 * XML well-formed. The <code>Node</code> is accepted and will be the 183 * last completely parsed node. 184 * </li> 185 * </ul> 186 */ acceptNode(Node nodeArg)187 public short acceptNode(Node nodeArg); 188 189 /** 190 * Tells the <code>LSParser</code> what types of nodes to show to the 191 * method <code>LSParserFilter.acceptNode</code>. If a node is not shown 192 * to the filter using this attribute, it is automatically included in 193 * the DOM document being built. See <code>NodeFilter</code> for 194 * definition of the constants. The constants <code>SHOW_ATTRIBUTE</code> 195 * , <code>SHOW_DOCUMENT</code>, <code>SHOW_DOCUMENT_TYPE</code>, 196 * <code>SHOW_NOTATION</code>, <code>SHOW_ENTITY</code>, and 197 * <code>SHOW_DOCUMENT_FRAGMENT</code> are meaningless here. Those nodes 198 * will never be passed to <code>LSParserFilter.acceptNode</code>. 199 * <br> The constants used here are defined in 200 * [<a href='http://www.w3.org/TR/2000/REC-DOM-Level-2-Traversal-Range-20001113'>DOM Level 2 Traversal and Range</a>]. 201 */ getWhatToShow()202 public int getWhatToShow(); 203 204 } 205