jaxp/src/share/classes/org/w3c/dom/traversal/TreeWalker.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 6 7f561c08de6b
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * published by the Free Software Foundation.  Sun designates this
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 * particular file as subject to the "Classpath" exception as provided
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * by Sun in the LICENSE file that accompanied this code.
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * accompanied this code).
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 * CA 95054 USA or visit www.sun.com if you need additional information or
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 * have any questions.
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
 * This file is available under and governed by the GNU General Public
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
 * License version 2 only, as published by the Free Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
 * However, the following notice accompanied the original version of this
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
 * file and, per its terms, should not be removed:
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
 * Copyright (c) 2000 World Wide Web Consortium,
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
 * (Massachusetts Institute of Technology, Institut National de
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
 * Recherche en Informatique et en Automatique, Keio University). All
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
 * Rights Reserved. This program is distributed under the W3C's Software
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
 * Intellectual Property License. This program is distributed in the
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
 * hope that it will be useful, but WITHOUT ANY WARRANTY; without even
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
 * PURPOSE.
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 * See W3C License http://www.w3.org/Consortium/Legal/ for more details.
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
package org.w3c.dom.traversal;
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
import org.w3c.dom.Node;
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
import org.w3c.dom.DOMException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
 * <code>TreeWalker</code> objects are used to navigate a document tree or
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
 * subtree using the view of the document defined by their
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
 * <code>whatToShow</code> flags and filter (if any). Any function which
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
 * performs navigation using a <code>TreeWalker</code> will automatically
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
 * support any view defined by a <code>TreeWalker</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
 * <p>Omitting nodes from the logical view of a subtree can result in a
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
 * structure that is substantially different from the same subtree in the
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
 * complete, unfiltered document. Nodes that are siblings in the
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
 * <code>TreeWalker</code> view may be children of different, widely
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
 * separated nodes in the original view. For instance, consider a
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
 * <code>NodeFilter</code> that skips all nodes except for Text nodes and
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
 * the root node of a document. In the logical view that results, all text
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
 * nodes will be siblings and appear as direct children of the root node, no
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
 * matter how deeply nested the structure of the original document.
7f561c08de6b Initial load
duke
parents:
diff changeset
    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>.
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
 * @since DOM Level 2
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
public interface TreeWalker {
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
     * The <code>root</code> node of the <code>TreeWalker</code>, as specified
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
     * when it was created.
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
    public Node getRoot();
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
     * This attribute determines which node types are presented via the
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
     * <code>TreeWalker</code>. The available set of constants is defined in
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
     * the <code>NodeFilter</code> interface.  Nodes not accepted by
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
     * <code>whatToShow</code> will be skipped, but their children may still
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
     * be considered. Note that this skip takes precedence over the filter,
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
     * if any.
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
    public int getWhatToShow();
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
     * The filter used to screen nodes.
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
    public NodeFilter getFilter();
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
     * The value of this flag determines whether the children of entity
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
     * reference nodes are visible to the <code>TreeWalker</code>. If false,
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
     * these children  and their descendants will be rejected. Note that
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
     * this rejection takes precedence over <code>whatToShow</code> and the
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
     * filter, if any.
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
     * <br> To produce a view of the document that has entity references
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
     * expanded and does not expose the entity reference node itself, use
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
     * the <code>whatToShow</code> flags to hide the entity reference node
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
     * and set <code>expandEntityReferences</code> to true when creating the
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
     * <code>TreeWalker</code>. To produce a view of the document that has
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
     * entity reference nodes but no entity expansion, use the
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
     * <code>whatToShow</code> flags to show the entity reference node and
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
     * set <code>expandEntityReferences</code> to false.
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
    public boolean getExpandEntityReferences();
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
     * The node at which the <code>TreeWalker</code> is currently positioned.
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
     * <br>Alterations to the DOM tree may cause the current node to no longer
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
     * be accepted by the <code>TreeWalker</code>'s associated filter.
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
     * <code>currentNode</code> may also be explicitly set to any node,
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
     * whether or not it is within the subtree specified by the
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
     * <code>root</code> node or would be accepted by the filter and
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
     * <code>whatToShow</code> flags. Further traversal occurs relative to
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
     * <code>currentNode</code> even if it is not part of the current view,
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
     * by applying the filters in the requested direction; if no traversal
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
     * is possible, <code>currentNode</code> is not changed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
    public Node getCurrentNode();
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
     * The node at which the <code>TreeWalker</code> is currently positioned.
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
     * <br>Alterations to the DOM tree may cause the current node to no longer
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
     * be accepted by the <code>TreeWalker</code>'s associated filter.
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
     * <code>currentNode</code> may also be explicitly set to any node,
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
     * whether or not it is within the subtree specified by the
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
     * <code>root</code> node or would be accepted by the filter and
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
     * <code>whatToShow</code> flags. Further traversal occurs relative to
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
     * <code>currentNode</code> even if it is not part of the current view,
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
     * by applying the filters in the requested direction; if no traversal
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
     * is possible, <code>currentNode</code> is not changed.
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
     * @exception DOMException
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
     *   NOT_SUPPORTED_ERR: Raised if an attempt is made to set
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
     *   <code>currentNode</code> to <code>null</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
    public void setCurrentNode(Node currentNode)
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
                         throws DOMException;
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
     * Moves to and returns the closest visible ancestor node of the current
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
     * node. If the search for <code>parentNode</code> attempts to step
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
     * upward from the <code>TreeWalker</code>'s <code>root</code> node, or
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
     * if it fails to find a visible ancestor node, this method retains the
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
     * current position and returns <code>null</code>.
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
     * @return The new parent node, or <code>null</code> if the current node
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
     *   has no parent  in the <code>TreeWalker</code>'s logical view.
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
    public Node parentNode();
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
     * Moves the <code>TreeWalker</code> to the first visible child of the
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
     * current node, and returns the new node. If the current node has no
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
     * visible children, returns <code>null</code>, and retains the current
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
     * node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
     * @return The new node, or <code>null</code> if the current node has no
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
     *   visible children  in the <code>TreeWalker</code>'s logical view.
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
    public Node firstChild();
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
     * Moves the <code>TreeWalker</code> to the last visible child of the
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
     * current node, and returns the new node. If the current node has no
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
     * visible children, returns <code>null</code>, and retains the current
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
     * node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
     * @return The new node, or <code>null</code> if the current node has no
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
     *   children  in the <code>TreeWalker</code>'s logical view.
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
    public Node lastChild();
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
     * Moves the <code>TreeWalker</code> to the previous sibling of the
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
     * current node, and returns the new node. If the current node has no
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
     * visible previous sibling, returns <code>null</code>, and retains the
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
     * current node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
     * @return The new node, or <code>null</code> if the current node has no
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
     *   previous sibling.  in the <code>TreeWalker</code>'s logical view.
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
    public Node previousSibling();
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
     * Moves the <code>TreeWalker</code> to the next sibling of the current
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
     * node, and returns the new node. If the current node has no visible
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
     * next sibling, returns <code>null</code>, and retains the current node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
     * @return The new node, or <code>null</code> if the current node has no
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
     *   next sibling.  in the <code>TreeWalker</code>'s logical view.
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
    public Node nextSibling();
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
     * Moves the <code>TreeWalker</code> to the previous visible node in
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
     * document order relative to the current node, and returns the new
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
     * node. If the current node has no previous node,  or if the search for
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
     * <code>previousNode</code> attempts to step upward from the
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
     * <code>TreeWalker</code>'s <code>root</code> node,  returns
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
     * <code>null</code>, and retains the current node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
     * @return The new node, or <code>null</code> if the current node has no
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
     *   previous node  in the <code>TreeWalker</code>'s logical view.
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
    public Node previousNode();
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
    /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
     * Moves the <code>TreeWalker</code> to the next visible node in document
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
     * order relative to the current node, and returns the new node. If the
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
     * current node has no next node, or if the search for nextNode attempts
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
     * to step upward from the <code>TreeWalker</code>'s <code>root</code>
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
     * node, returns <code>null</code>, and retains the current node.
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
     * @return The new node, or <code>null</code> if the current node has no
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
     *   next node  in the <code>TreeWalker</code>'s logical view.
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
    public Node nextNode();
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
}