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