001 /*
002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
003 *
004 * This code is free software; you can redistribute it and/or modify it
005 * under the terms of the GNU General Public License version 2 only, as
006 * published by the Free Software Foundation. Sun designates this
007 * particular file as subject to the "Classpath" exception as provided
008 * by Sun in the LICENSE file that accompanied this code.
009 *
010 * This code is distributed in the hope that it will be useful, but WITHOUT
011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
013 * version 2 for more details (a copy is included in the LICENSE file that
014 * accompanied this code).
015 *
016 * You should have received a copy of the GNU General Public License version
017 * 2 along with this work; if not, write to the Free Software Foundation,
018 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
019 *
020 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
021 * CA 95054 USA or visit www.sun.com if you need additional information or
022 * have any questions.
023 */
024
025 /*
026 * This file is available under and governed by the GNU General Public
027 * License version 2 only, as published by the Free Software Foundation.
028 * However, the following notice accompanied the original version of this
029 * file and, per its terms, should not be removed:
030 *
031 * Copyright (c) 2000 World Wide Web Consortium,
032 * (Massachusetts Institute of Technology, Institut National de
033 * Recherche en Informatique et en Automatique, Keio University). All
034 * Rights Reserved. This program is distributed under the W3C's Software
035 * Intellectual Property License. This program is distributed in the
036 * hope that it will be useful, but WITHOUT ANY WARRANTY; without even
037 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
038 * PURPOSE.
039 * See W3C License http://www.w3.org/Consortium/Legal/ for more details.
040 */
041
042 package org.w3c.dom.traversal;
043
044 import org.w3c.dom.Node;
045 import org.w3c.dom.DOMException;
046
047 /**
048 * <code>TreeWalker</code> objects are used to navigate a document tree or
049 * subtree using the view of the document defined by their
050 * <code>whatToShow</code> flags and filter (if any). Any function which
051 * performs navigation using a <code>TreeWalker</code> will automatically
052 * support any view defined by a <code>TreeWalker</code>.
053 * <p>Omitting nodes from the logical view of a subtree can result in a
054 * structure that is substantially different from the same subtree in the
055 * complete, unfiltered document. Nodes that are siblings in the
056 * <code>TreeWalker</code> view may be children of different, widely
057 * separated nodes in the original view. For instance, consider a
058 * <code>NodeFilter</code> that skips all nodes except for Text nodes and
059 * the root node of a document. In the logical view that results, all text
060 * nodes will be siblings and appear as direct children of the root node, no
061 * matter how deeply nested the structure of the original document.
062 * <p>See also the <a href='http://www.w3.org/TR/2000/REC-DOM-Level-2-Traversal-Range-20001113'>Document Object Model (DOM) Level 2 Traversal and Range Specification</a>.
063 * @since DOM Level 2
064 */
065 public interface TreeWalker {
066 /**
067 * The <code>root</code> node of the <code>TreeWalker</code>, as specified
068 * when it was created.
069 */
070 public Node getRoot();
071
072 /**
073 * This attribute determines which node types are presented via the
074 * <code>TreeWalker</code>. The available set of constants is defined in
075 * the <code>NodeFilter</code> interface. Nodes not accepted by
076 * <code>whatToShow</code> will be skipped, but their children may still
077 * be considered. Note that this skip takes precedence over the filter,
078 * if any.
079 */
080 public int getWhatToShow();
081
082 /**
083 * The filter used to screen nodes.
084 */
085 public NodeFilter getFilter();
086
087 /**
088 * The value of this flag determines whether the children of entity
089 * reference nodes are visible to the <code>TreeWalker</code>. If false,
090 * these children and their descendants will be rejected. Note that
091 * this rejection takes precedence over <code>whatToShow</code> and the
092 * filter, if any.
093 * <br> To produce a view of the document that has entity references
094 * expanded and does not expose the entity reference node itself, use
095 * the <code>whatToShow</code> flags to hide the entity reference node
096 * and set <code>expandEntityReferences</code> to true when creating the
097 * <code>TreeWalker</code>. To produce a view of the document that has
098 * entity reference nodes but no entity expansion, use the
099 * <code>whatToShow</code> flags to show the entity reference node and
100 * set <code>expandEntityReferences</code> to false.
101 */
102 public boolean getExpandEntityReferences();
103
104 /**
105 * The node at which the <code>TreeWalker</code> is currently positioned.
106 * <br>Alterations to the DOM tree may cause the current node to no longer
107 * be accepted by the <code>TreeWalker</code>'s associated filter.
108 * <code>currentNode</code> may also be explicitly set to any node,
109 * whether or not it is within the subtree specified by the
110 * <code>root</code> node or would be accepted by the filter and
111 * <code>whatToShow</code> flags. Further traversal occurs relative to
112 * <code>currentNode</code> even if it is not part of the current view,
113 * by applying the filters in the requested direction; if no traversal
114 * is possible, <code>currentNode</code> is not changed.
115 */
116 public Node getCurrentNode();
117
118 /**
119 * The node at which the <code>TreeWalker</code> is currently positioned.
120 * <br>Alterations to the DOM tree may cause the current node to no longer
121 * be accepted by the <code>TreeWalker</code>'s associated filter.
122 * <code>currentNode</code> may also be explicitly set to any node,
123 * whether or not it is within the subtree specified by the
124 * <code>root</code> node or would be accepted by the filter and
125 * <code>whatToShow</code> flags. Further traversal occurs relative to
126 * <code>currentNode</code> even if it is not part of the current view,
127 * by applying the filters in the requested direction; if no traversal
128 * is possible, <code>currentNode</code> is not changed.
129 * @exception DOMException
130 * NOT_SUPPORTED_ERR: Raised if an attempt is made to set
131 * <code>currentNode</code> to <code>null</code>.
132 */
133 public void setCurrentNode(Node currentNode) throws DOMException;
134
135 /**
136 * Moves to and returns the closest visible ancestor node of the current
137 * node. If the search for <code>parentNode</code> attempts to step
138 * upward from the <code>TreeWalker</code>'s <code>root</code> node, or
139 * if it fails to find a visible ancestor node, this method retains the
140 * current position and returns <code>null</code>.
141 * @return The new parent node, or <code>null</code> if the current node
142 * has no parent in the <code>TreeWalker</code>'s logical view.
143 */
144 public Node parentNode();
145
146 /**
147 * Moves the <code>TreeWalker</code> to the first visible child of the
148 * current node, and returns the new node. If the current node has no
149 * visible children, returns <code>null</code>, and retains the current
150 * node.
151 * @return The new node, or <code>null</code> if the current node has no
152 * visible children in the <code>TreeWalker</code>'s logical view.
153 */
154 public Node firstChild();
155
156 /**
157 * Moves the <code>TreeWalker</code> to the last visible child of the
158 * current node, and returns the new node. If the current node has no
159 * visible children, returns <code>null</code>, and retains the current
160 * node.
161 * @return The new node, or <code>null</code> if the current node has no
162 * children in the <code>TreeWalker</code>'s logical view.
163 */
164 public Node lastChild();
165
166 /**
167 * Moves the <code>TreeWalker</code> to the previous sibling of the
168 * current node, and returns the new node. If the current node has no
169 * visible previous sibling, returns <code>null</code>, and retains the
170 * current node.
171 * @return The new node, or <code>null</code> if the current node has no
172 * previous sibling. in the <code>TreeWalker</code>'s logical view.
173 */
174 public Node previousSibling();
175
176 /**
177 * Moves the <code>TreeWalker</code> to the next sibling of the current
178 * node, and returns the new node. If the current node has no visible
179 * next sibling, returns <code>null</code>, and retains the current node.
180 * @return The new node, or <code>null</code> if the current node has no
181 * next sibling. in the <code>TreeWalker</code>'s logical view.
182 */
183 public Node nextSibling();
184
185 /**
186 * Moves the <code>TreeWalker</code> to the previous visible node in
187 * document order relative to the current node, and returns the new
188 * node. If the current node has no previous node, or if the search for
189 * <code>previousNode</code> attempts to step upward from the
190 * <code>TreeWalker</code>'s <code>root</code> node, returns
191 * <code>null</code>, and retains the current node.
192 * @return The new node, or <code>null</code> if the current node has no
193 * previous node in the <code>TreeWalker</code>'s logical view.
194 */
195 public Node previousNode();
196
197 /**
198 * Moves the <code>TreeWalker</code> to the next visible node in document
199 * order relative to the current node, and returns the new node. If the
200 * current node has no next node, or if the search for nextNode attempts
201 * to step upward from the <code>TreeWalker</code>'s <code>root</code>
202 * node, returns <code>null</code>, and retains the current node.
203 * @return The new node, or <code>null</code> if the current node has no
204 * next node in the <code>TreeWalker</code>'s logical view.
205 */
206 public Node nextNode();
207
208 }
|