KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > w3c > dom > ls > LSParserFilter


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
13 package org.w3c.dom.ls;
14
15 import org.w3c.dom.Node JavaDoc;
16 import org.w3c.dom.Element JavaDoc;
17
18 /**
19  * <code>LSParserFilter</code>s provide applications the ability to examine
20  * nodes as they are being constructed while parsing. As each node is
21  * examined, it may be modified or removed, or the entire parse may be
22  * terminated early.
23  * <p> At the time any of the filter methods are called by the parser, the
24  * owner Document and DOMImplementation objects exist and are accessible.
25  * The document element is never passed to the <code>LSParserFilter</code>
26  * methods, i.e. it is not possible to filter out the document element.
27  * <code>Document</code>, <code>DocumentType</code>, <code>Notation</code>,
28  * <code>Entity</code>, and <code>Attr</code> nodes are never passed to the
29  * <code>acceptNode</code> method on the filter. The child nodes of an
30  * <code>EntityReference</code> node are passed to the filter if the
31  * parameter "<a HREF='http://www.w3.org/TR/DOM-Level-3-Core/core.html#parameter-entities'>
32  * 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'>
33  * entities</a>", unexpanded entity reference nodes are never discarded and are always
34  * passed to the filter.
35  * <p> All validity checking while parsing a document occurs on the source
36  * document as it appears on the input stream, not on the DOM document as it
37  * is built in memory. With filters, the document in memory may be a subset
38  * of the document on the stream, and its validity may have been affected by
39  * the filtering.
40  * <p> All default attributes must be present on elements when the elements
41  * are passed to the filter methods. All other default content must be
42  * passed to the filter methods.
43  * <p> DOM applications must not raise exceptions in a filter. The effect of
44  * throwing exceptions from a filter is DOM implementation dependent.
45  * <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
46 and Save Specification</a>.
47  */

48 public interface LSParserFilter {
49     // Constants returned by startElement and acceptNode
50
/**
51      * Accept the node.
52      */

53     public static final short FILTER_ACCEPT = 1;
54     /**
55      * Reject the node and its children.
56      */

57     public static final short FILTER_REJECT = 2;
58     /**
59      * Skip this single node. The children of this node will still be
60      * considered.
61      */

62     public static final short FILTER_SKIP = 3;
63     /**
64      * Interrupt the normal processing of the document.
65      */

66     public static final short FILTER_INTERRUPT = 4;
67
68     /**
69      * The parser will call this method after each <code>Element</code> start
70      * tag has been scanned, but before the remainder of the
71      * <code>Element</code> is processed. The intent is to allow the
72      * element, including any children, to be efficiently skipped. Note that
73      * only element nodes are passed to the <code>startElement</code>
74      * function.
75      * <br>The element node passed to <code>startElement</code> for filtering
76      * will include all of the Element's attributes, but none of the
77      * children nodes. The Element may not yet be in place in the document
78      * being constructed (it may not have a parent node.)
79      * <br>A <code>startElement</code> filter function may access or change
80      * the attributes for the Element. Changing Namespace declarations will
81      * have no effect on namespace resolution by the parser.
82      * <br>For efficiency, the Element node passed to the filter may not be
83      * the same one as is actually placed in the tree if the node is
84      * accepted. And the actual node (node object identity) may be reused
85      * during the process of reading in and filtering a document.
86      * @param elementArg The newly encountered element. At the time this
87      * method is called, the element is incomplete - it will have its
88      * attributes, but no children.
89      * @return
90      * <ul>
91      * <li> <code>FILTER_ACCEPT</code> if the <code>Element</code> should
92      * be included in the DOM document being built.
93      * </li>
94      * <li>
95      * <code>FILTER_REJECT</code> if the <code>Element</code> and all of
96      * its children should be rejected.
97      * </li>
98      * <li> <code>FILTER_SKIP</code> if the
99      * <code>Element</code> should be skipped. All of its children are
100      * inserted in place of the skipped <code>Element</code> node.
101      * </li>
102      * <li>
103      * <code>FILTER_INTERRUPT</code> if the filter wants to stop the
104      * processing of the document. Interrupting the processing of the
105      * document does no longer guarantee that the resulting DOM tree is
106      * XML well-formed. The <code>Element</code> is rejected.
107      * </li>
108      * </ul> Returning
109      * any other values will result in unspecified behavior.
110      */

111     public short startElement(Element JavaDoc elementArg);
112
113     /**
114      * This method will be called by the parser at the completion of the
115      * parsing of each node. The node and all of its descendants will exist
116      * and be complete. The parent node will also exist, although it may be
117      * incomplete, i.e. it may have additional children that have not yet
118      * been parsed. Attribute nodes are never passed to this function.
119      * <br>From within this method, the new node may be freely modified -
120      * children may be added or removed, text nodes modified, etc. The state
121      * of the rest of the document outside this node is not defined, and the
122      * affect of any attempt to navigate to, or to modify any other part of
123      * the document is undefined.
124      * <br>For validating parsers, the checks are made on the original
125      * document, before any modification by the filter. No validity checks
126      * are made on any document modifications made by the filter.
127      * <br>If this new node is rejected, the parser might reuse the new node
128      * and any of its descendants.
129      * @param nodeArg The newly constructed element. At the time this method
130      * is called, the element is complete - it has all of its children
131      * (and their children, recursively) and attributes, and is attached
132      * as a child to its parent.
133      * @return
134      * <ul>
135      * <li> <code>FILTER_ACCEPT</code> if this <code>Node</code> should
136      * be included in the DOM document being built.
137      * </li>
138      * <li>
139      * <code>FILTER_REJECT</code> if the <code>Node</code> and all of its
140      * children should be rejected.
141      * </li>
142      * <li> <code>FILTER_SKIP</code> if the
143      * <code>Node</code> should be skipped and the <code>Node</code>
144      * should be replaced by all the children of the <code>Node</code>.
145      * </li>
146      * <li>
147      * <code>FILTER_INTERRUPT</code> if the filter wants to stop the
148      * processing of the document. Interrupting the processing of the
149      * document does no longer guarantee that the resulting DOM tree is
150      * XML well-formed. The <code>Node</code> is accepted and will be the
151      * last completely parsed node.
152      * </li>
153      * </ul>
154      */

155     public short acceptNode(Node JavaDoc nodeArg);
156
157     /**
158      * Tells the <code>LSParser</code> what types of nodes to show to the
159      * method <code>LSParserFilter.acceptNode</code>. If a node is not shown
160      * to the filter using this attribute, it is automatically included in
161      * the DOM document being built. See <code>NodeFilter</code> for
162      * definition of the constants. The constants <code>SHOW_ATTRIBUTE</code>
163      * , <code>SHOW_DOCUMENT</code>, <code>SHOW_DOCUMENT_TYPE</code>,
164      * <code>SHOW_NOTATION</code>, <code>SHOW_ENTITY</code>, and
165      * <code>SHOW_DOCUMENT_FRAGMENT</code> are meaningless here. Those nodes
166      * will never be passed to <code>LSParserFilter.acceptNode</code>.
167      * <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>]
168      * .
169      */

170     public int getWhatToShow();
171
172 }
173
Popular Tags