Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/org/w3c/dom/traversal/TreeWalker.java
86410 views
/*1* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation. Oracle designates this6* particular file as subject to the "Classpath" exception as provided7* by Oracle in the LICENSE file that accompanied this code.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324/*25* This file is available under and governed by the GNU General Public26* License version 2 only, as published by the Free Software Foundation.27* However, the following notice accompanied the original version of this28* file and, per its terms, should not be removed:29*30* Copyright (c) 2000 World Wide Web Consortium,31* (Massachusetts Institute of Technology, Institut National de32* Recherche en Informatique et en Automatique, Keio University). All33* Rights Reserved. This program is distributed under the W3C's Software34* Intellectual Property License. This program is distributed in the35* hope that it will be useful, but WITHOUT ANY WARRANTY; without even36* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR37* PURPOSE.38* See W3C License http://www.w3.org/Consortium/Legal/ for more details.39*/4041package org.w3c.dom.traversal;4243import org.w3c.dom.Node;44import org.w3c.dom.DOMException;4546/**47* <code>TreeWalker</code> objects are used to navigate a document tree or48* subtree using the view of the document defined by their49* <code>whatToShow</code> flags and filter (if any). Any function which50* performs navigation using a <code>TreeWalker</code> will automatically51* support any view defined by a <code>TreeWalker</code>.52* <p>Omitting nodes from the logical view of a subtree can result in a53* structure that is substantially different from the same subtree in the54* complete, unfiltered document. Nodes that are siblings in the55* <code>TreeWalker</code> view may be children of different, widely56* separated nodes in the original view. For instance, consider a57* <code>NodeFilter</code> that skips all nodes except for Text nodes and58* the root node of a document. In the logical view that results, all text59* nodes will be siblings and appear as direct children of the root node, no60* matter how deeply nested the structure of the original document.61* <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>.62* @since DOM Level 263*/64public interface TreeWalker {65/**66* The <code>root</code> node of the <code>TreeWalker</code>, as specified67* when it was created.68*/69public Node getRoot();7071/**72* This attribute determines which node types are presented via the73* <code>TreeWalker</code>. The available set of constants is defined in74* the <code>NodeFilter</code> interface. Nodes not accepted by75* <code>whatToShow</code> will be skipped, but their children may still76* be considered. Note that this skip takes precedence over the filter,77* if any.78*/79public int getWhatToShow();8081/**82* The filter used to screen nodes.83*/84public NodeFilter getFilter();8586/**87* The value of this flag determines whether the children of entity88* reference nodes are visible to the <code>TreeWalker</code>. If false,89* these children and their descendants will be rejected. Note that90* this rejection takes precedence over <code>whatToShow</code> and the91* filter, if any.92* <br> To produce a view of the document that has entity references93* expanded and does not expose the entity reference node itself, use94* the <code>whatToShow</code> flags to hide the entity reference node95* and set <code>expandEntityReferences</code> to true when creating the96* <code>TreeWalker</code>. To produce a view of the document that has97* entity reference nodes but no entity expansion, use the98* <code>whatToShow</code> flags to show the entity reference node and99* set <code>expandEntityReferences</code> to false.100*/101public boolean getExpandEntityReferences();102103/**104* The node at which the <code>TreeWalker</code> is currently positioned.105* <br>Alterations to the DOM tree may cause the current node to no longer106* be accepted by the <code>TreeWalker</code>'s associated filter.107* <code>currentNode</code> may also be explicitly set to any node,108* whether or not it is within the subtree specified by the109* <code>root</code> node or would be accepted by the filter and110* <code>whatToShow</code> flags. Further traversal occurs relative to111* <code>currentNode</code> even if it is not part of the current view,112* by applying the filters in the requested direction; if no traversal113* is possible, <code>currentNode</code> is not changed.114*/115public Node getCurrentNode();116/**117* The node at which the <code>TreeWalker</code> is currently positioned.118* <br>Alterations to the DOM tree may cause the current node to no longer119* be accepted by the <code>TreeWalker</code>'s associated filter.120* <code>currentNode</code> may also be explicitly set to any node,121* whether or not it is within the subtree specified by the122* <code>root</code> node or would be accepted by the filter and123* <code>whatToShow</code> flags. Further traversal occurs relative to124* <code>currentNode</code> even if it is not part of the current view,125* by applying the filters in the requested direction; if no traversal126* is possible, <code>currentNode</code> is not changed.127* @exception DOMException128* NOT_SUPPORTED_ERR: Raised if an attempt is made to set129* <code>currentNode</code> to <code>null</code>.130*/131public void setCurrentNode(Node currentNode)132throws DOMException;133134/**135* Moves to and returns the closest visible ancestor node of the current136* node. If the search for <code>parentNode</code> attempts to step137* upward from the <code>TreeWalker</code>'s <code>root</code> node, or138* if it fails to find a visible ancestor node, this method retains the139* current position and returns <code>null</code>.140* @return The new parent node, or <code>null</code> if the current node141* has no parent in the <code>TreeWalker</code>'s logical view.142*/143public Node parentNode();144145/**146* Moves the <code>TreeWalker</code> to the first visible child of the147* current node, and returns the new node. If the current node has no148* visible children, returns <code>null</code>, and retains the current149* node.150* @return The new node, or <code>null</code> if the current node has no151* visible children in the <code>TreeWalker</code>'s logical view.152*/153public Node firstChild();154155/**156* Moves the <code>TreeWalker</code> to the last visible child of the157* current node, and returns the new node. If the current node has no158* visible children, returns <code>null</code>, and retains the current159* node.160* @return The new node, or <code>null</code> if the current node has no161* children in the <code>TreeWalker</code>'s logical view.162*/163public Node lastChild();164165/**166* Moves the <code>TreeWalker</code> to the previous sibling of the167* current node, and returns the new node. If the current node has no168* visible previous sibling, returns <code>null</code>, and retains the169* current node.170* @return The new node, or <code>null</code> if the current node has no171* previous sibling. in the <code>TreeWalker</code>'s logical view.172*/173public Node previousSibling();174175/**176* Moves the <code>TreeWalker</code> to the next sibling of the current177* node, and returns the new node. If the current node has no visible178* next sibling, returns <code>null</code>, and retains the current node.179* @return The new node, or <code>null</code> if the current node has no180* next sibling. in the <code>TreeWalker</code>'s logical view.181*/182public Node nextSibling();183184/**185* Moves the <code>TreeWalker</code> to the previous visible node in186* document order relative to the current node, and returns the new187* node. If the current node has no previous node, or if the search for188* <code>previousNode</code> attempts to step upward from the189* <code>TreeWalker</code>'s <code>root</code> node, returns190* <code>null</code>, and retains the current node.191* @return The new node, or <code>null</code> if the current node has no192* previous node in the <code>TreeWalker</code>'s logical view.193*/194public Node previousNode();195196/**197* Moves the <code>TreeWalker</code> to the next visible node in document198* order relative to the current node, and returns the new node. If the199* current node has no next node, or if the search for nextNode attempts200* to step upward from the <code>TreeWalker</code>'s <code>root</code>201* node, returns <code>null</code>, and retains the current node.202* @return The new node, or <code>null</code> if the current node has no203* next node in the <code>TreeWalker</code>'s logical view.204*/205public Node nextNode();206207}208209210