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) 2000 World Wide Web Consortium, 32 * (Massachusetts Institute of Technology, Institut National de 33 * Recherche en Informatique et en Automatique, Keio University). All 34 * Rights Reserved. This program is distributed under the W3C's Software 35 * Intellectual Property License. This program is distributed in the 36 * hope that it will be useful, but WITHOUT ANY WARRANTY; without even 37 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 38 * PURPOSE. 39 * See W3C License http://www.w3.org/Consortium/Legal/ for more details. 40 */ 41 42 package org.w3c.dom.traversal; 43 44 import org.w3c.dom.Node; 45 import org.w3c.dom.DOMException; 46 47 /** 48 * <code>TreeWalker</code> objects are used to navigate a document tree or 49 * subtree using the view of the document defined by their 50 * <code>whatToShow</code> flags and filter (if any). Any function which 51 * performs navigation using a <code>TreeWalker</code> will automatically 52 * support any view defined by a <code>TreeWalker</code>. 53 * <p>Omitting nodes from the logical view of a subtree can result in a 54 * structure that is substantially different from the same subtree in the 55 * complete, unfiltered document. Nodes that are siblings in the 56 * <code>TreeWalker</code> view may be children of different, widely 57 * separated nodes in the original view. For instance, consider a 58 * <code>NodeFilter</code> that skips all nodes except for Text nodes and 59 * the root node of a document. In the logical view that results, all text 60 * nodes will be siblings and appear as direct children of the root node, no 61 * matter how deeply nested the structure of the original document. 62 * <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>. 63 * @since 1.9, DOM Level 2 64 */ 65 public interface TreeWalker { 66 /** 67 * The <code>root</code> node of the <code>TreeWalker</code>, as specified 68 * when it was created. 69 */ 70 public Node getRoot(); 71 72 /** 73 * This attribute determines which node types are presented via the 74 * <code>TreeWalker</code>. The available set of constants is defined in 75 * the <code>NodeFilter</code> interface. Nodes not accepted by 76 * <code>whatToShow</code> will be skipped, but their children may still 77 * be considered. Note that this skip takes precedence over the filter, 78 * if any. 79 */ 80 public int getWhatToShow(); 81 82 /** 83 * The filter used to screen nodes. 84 */ 85 public NodeFilter getFilter(); 86 87 /** 88 * The value of this flag determines whether the children of entity 89 * reference nodes are visible to the <code>TreeWalker</code>. If false, 90 * these children and their descendants will be rejected. Note that 91 * this rejection takes precedence over <code>whatToShow</code> and the 92 * filter, if any. 93 * <br> To produce a view of the document that has entity references 94 * expanded and does not expose the entity reference node itself, use 95 * the <code>whatToShow</code> flags to hide the entity reference node 96 * and set <code>expandEntityReferences</code> to true when creating the 97 * <code>TreeWalker</code>. To produce a view of the document that has 98 * entity reference nodes but no entity expansion, use the 99 * <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 * The node at which the <code>TreeWalker</code> is currently positioned. 119 * <br>Alterations to the DOM tree may cause the current node to no longer 120 * be accepted by the <code>TreeWalker</code>'s associated filter. 121 * <code>currentNode</code> may also be explicitly set to any node, 122 * whether or not it is within the subtree specified by the 123 * <code>root</code> node or would be accepted by the filter and 124 * <code>whatToShow</code> flags. Further traversal occurs relative to 125 * <code>currentNode</code> even if it is not part of the current view, 126 * by applying the filters in the requested direction; if no traversal 127 * is possible, <code>currentNode</code> is not changed. 128 * @exception DOMException 129 * NOT_SUPPORTED_ERR: Raised if an attempt is made to set 130 * <code>currentNode</code> to <code>null</code>. 131 */ 132 public void setCurrentNode(Node currentNode) 133 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 }