diff options
Diffstat (limited to 'libjava/classpath/external/w3c_dom/org/w3c/dom/traversal')
4 files changed, 525 insertions, 0 deletions
diff --git a/libjava/classpath/external/w3c_dom/org/w3c/dom/traversal/DocumentTraversal.java b/libjava/classpath/external/w3c_dom/org/w3c/dom/traversal/DocumentTraversal.java new file mode 100644 index 000000000..e68d656f2 --- /dev/null +++ b/libjava/classpath/external/w3c_dom/org/w3c/dom/traversal/DocumentTraversal.java @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. + * See W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ + +package org.w3c.dom.traversal; + +import org.w3c.dom.Node; +import org.w3c.dom.DOMException; + +/** + * <code>DocumentTraversal</code> contains methods that create + * <code>NodeIterators</code> and <code>TreeWalkers</code> to traverse a + * node and its children in document order (depth first, pre-order + * traversal, which is equivalent to the order in which the start tags occur + * in the text representation of the document). In DOMs which support the + * Traversal feature, <code>DocumentTraversal</code> will be implemented by + * the same objects that implement the Document interface. + * <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>. + * @since DOM Level 2 + */ +public interface DocumentTraversal { + /** + * Create a new <code>NodeIterator</code> over the subtree rooted at the + * specified node. + * @param root The node which will be iterated together with its + * children. The <code>NodeIterator</code> is initially positioned + * just before this node. The <code>whatToShow</code> flags and the + * filter, if any, are not considered when setting this position. The + * root must not be <code>null</code>. + * @param whatToShow This flag specifies which node types may appear in + * the logical view of the tree presented by the + * <code>NodeIterator</code>. See the description of + * <code>NodeFilter</code> for the set of possible <code>SHOW_</code> + * values.These flags can be combined using <code>OR</code>. + * @param filter The <code>NodeFilter</code> to be used with this + * <code>NodeIterator</code>, or <code>null</code> to indicate no + * filter. + * @param entityReferenceExpansion The value of this flag determines + * whether entity reference nodes are expanded. + * @return The newly created <code>NodeIterator</code>. + * @exception DOMException + * NOT_SUPPORTED_ERR: Raised if the specified <code>root</code> is + * <code>null</code>. + */ + public NodeIterator createNodeIterator(Node root, + int whatToShow, + NodeFilter filter, + boolean entityReferenceExpansion) + throws DOMException; + + /** + * Create a new <code>TreeWalker</code> over the subtree rooted at the + * specified node. + * @param root The node which will serve as the <code>root</code> for the + * <code>TreeWalker</code>. The <code>whatToShow</code> flags and the + * <code>NodeFilter</code> are not considered when setting this value; + * any node type will be accepted as the <code>root</code>. The + * <code>currentNode</code> of the <code>TreeWalker</code> is + * initialized to this node, whether or not it is visible. The + * <code>root</code> functions as a stopping point for traversal + * methods that look upward in the document structure, such as + * <code>parentNode</code> and nextNode. The <code>root</code> must + * not be <code>null</code>. + * @param whatToShow This flag specifies which node types may appear in + * the logical view of the tree presented by the + * <code>TreeWalker</code>. See the description of + * <code>NodeFilter</code> for the set of possible <code>SHOW_</code> + * values.These flags can be combined using <code>OR</code>. + * @param filter The <code>NodeFilter</code> to be used with this + * <code>TreeWalker</code>, or <code>null</code> to indicate no filter. + * @param entityReferenceExpansion If this flag is false, the contents of + * <code>EntityReference</code> nodes are not presented in the logical + * view. + * @return The newly created <code>TreeWalker</code>. + * @exception DOMException + * NOT_SUPPORTED_ERR: Raised if the specified <code>root</code> is + * <code>null</code>. + */ + public TreeWalker createTreeWalker(Node root, + int whatToShow, + NodeFilter filter, + boolean entityReferenceExpansion) + throws DOMException; + +} diff --git a/libjava/classpath/external/w3c_dom/org/w3c/dom/traversal/NodeFilter.java b/libjava/classpath/external/w3c_dom/org/w3c/dom/traversal/NodeFilter.java new file mode 100644 index 000000000..554775078 --- /dev/null +++ b/libjava/classpath/external/w3c_dom/org/w3c/dom/traversal/NodeFilter.java @@ -0,0 +1,144 @@ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. + * See W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ + +package org.w3c.dom.traversal; + +import org.w3c.dom.Node; + +/** + * Filters are objects that know how to "filter out" nodes. If a + * <code>NodeIterator</code> or <code>TreeWalker</code> is given a + * <code>NodeFilter</code>, it applies the filter before it returns the next + * node. If the filter says to accept the node, the traversal logic returns + * it; otherwise, traversal looks for the next node and pretends that the + * node that was rejected was not there. + * <p>The DOM does not provide any filters. <code>NodeFilter</code> is just an + * interface that users can implement to provide their own filters. + * <p><code>NodeFilters</code> do not need to know how to traverse from node + * to node, nor do they need to know anything about the data structure that + * is being traversed. This makes it very easy to write filters, since the + * only thing they have to know how to do is evaluate a single node. One + * filter may be used with a number of different kinds of traversals, + * encouraging code reuse. + * <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>. + * @since DOM Level 2 + */ +public interface NodeFilter { + // Constants returned by acceptNode + /** + * Accept the node. Navigation methods defined for + * <code>NodeIterator</code> or <code>TreeWalker</code> will return this + * node. + */ + public static final short FILTER_ACCEPT = 1; + /** + * Reject the node. Navigation methods defined for + * <code>NodeIterator</code> or <code>TreeWalker</code> will not return + * this node. For <code>TreeWalker</code>, the children of this node + * will also be rejected. <code>NodeIterators</code> treat this as a + * synonym for <code>FILTER_SKIP</code>. + */ + public static final short FILTER_REJECT = 2; + /** + * Skip this single node. Navigation methods defined for + * <code>NodeIterator</code> or <code>TreeWalker</code> will not return + * this node. For both <code>NodeIterator</code> and + * <code>TreeWalker</code>, the children of this node will still be + * considered. + */ + public static final short FILTER_SKIP = 3; + + // Constants for whatToShow + /** + * Show all <code>Nodes</code>. + */ + public static final int SHOW_ALL = 0xFFFFFFFF; + /** + * Show <code>Element</code> nodes. + */ + public static final int SHOW_ELEMENT = 0x00000001; + /** + * Show <code>Attr</code> nodes. This is meaningful only when creating an + * <code>NodeIterator</code> or <code>TreeWalker</code> with an + * attribute node as its <code>root</code>; in this case, it means that + * the attribute node will appear in the first position of the iteration + * or traversal. Since attributes are never children of other nodes, + * they do not appear when traversing over the document tree. + */ + public static final int SHOW_ATTRIBUTE = 0x00000002; + /** + * Show <code>Text</code> nodes. + */ + public static final int SHOW_TEXT = 0x00000004; + /** + * Show <code>CDATASection</code> nodes. + */ + public static final int SHOW_CDATA_SECTION = 0x00000008; + /** + * Show <code>EntityReference</code> nodes. + */ + public static final int SHOW_ENTITY_REFERENCE = 0x00000010; + /** + * Show <code>Entity</code> nodes. This is meaningful only when creating + * an <code>NodeIterator</code> or <code>TreeWalker</code> with an + * <code>Entity</code> node as its <code>root</code>; in this case, it + * means that the <code>Entity</code> node will appear in the first + * position of the traversal. Since entities are not part of the + * document tree, they do not appear when traversing over the document + * tree. + */ + public static final int SHOW_ENTITY = 0x00000020; + /** + * Show <code>ProcessingInstruction</code> nodes. + */ + public static final int SHOW_PROCESSING_INSTRUCTION = 0x00000040; + /** + * Show <code>Comment</code> nodes. + */ + public static final int SHOW_COMMENT = 0x00000080; + /** + * Show <code>Document</code> nodes. + */ + public static final int SHOW_DOCUMENT = 0x00000100; + /** + * Show <code>DocumentType</code> nodes. + */ + public static final int SHOW_DOCUMENT_TYPE = 0x00000200; + /** + * Show <code>DocumentFragment</code> nodes. + */ + public static final int SHOW_DOCUMENT_FRAGMENT = 0x00000400; + /** + * Show <code>Notation</code> nodes. This is meaningful only when creating + * an <code>NodeIterator</code> or <code>TreeWalker</code> with a + * <code>Notation</code> node as its <code>root</code>; in this case, it + * means that the <code>Notation</code> node will appear in the first + * position of the traversal. Since notations are not part of the + * document tree, they do not appear when traversing over the document + * tree. + */ + public static final int SHOW_NOTATION = 0x00000800; + + /** + * Test whether a specified node is visible in the logical view of a + * <code>TreeWalker</code> or <code>NodeIterator</code>. This function + * will be called by the implementation of <code>TreeWalker</code> and + * <code>NodeIterator</code>; it is not normally called directly from + * user code. (Though you could do so if you wanted to use the same + * filter to guide your own application logic.) + * @param n The node to check to see if it passes the filter or not. + * @return A constant to determine whether the node is accepted, + * rejected, or skipped, as defined above. + */ + public short acceptNode(Node n); + +} diff --git a/libjava/classpath/external/w3c_dom/org/w3c/dom/traversal/NodeIterator.java b/libjava/classpath/external/w3c_dom/org/w3c/dom/traversal/NodeIterator.java new file mode 100644 index 000000000..40deef2f3 --- /dev/null +++ b/libjava/classpath/external/w3c_dom/org/w3c/dom/traversal/NodeIterator.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. + * See W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ + +package org.w3c.dom.traversal; + +import org.w3c.dom.Node; +import org.w3c.dom.DOMException; + +/** + * <code>NodeIterators</code> are used to step through a set of nodes, e.g. + * the set of nodes in a <code>NodeList</code>, the document subtree + * governed by a particular <code>Node</code>, the results of a query, or + * any other set of nodes. The set of nodes to be iterated is determined by + * the implementation of the <code>NodeIterator</code>. DOM Level 2 + * specifies a single <code>NodeIterator</code> implementation for + * document-order traversal of a document subtree. Instances of these + * <code>NodeIterators</code> are created by calling + * <code>DocumentTraversal</code><code>.createNodeIterator()</code>. + * <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>. + * @since DOM Level 2 + */ +public interface NodeIterator { + /** + * The root node of the <code>NodeIterator</code>, as specified when it + * was created. + */ + public Node getRoot(); + + /** + * This attribute determines which node types are presented via the + * <code>NodeIterator</code>. The available set of constants is defined + * in the <code>NodeFilter</code> interface. Nodes not accepted by + * <code>whatToShow</code> will be skipped, but their children may still + * be considered. Note that this skip takes precedence over the filter, + * if any. + */ + public int getWhatToShow(); + + /** + * The <code>NodeFilter</code> used to screen nodes. + */ + public NodeFilter getFilter(); + + /** + * The value of this flag determines whether the children of entity + * reference nodes are visible to the <code>NodeIterator</code>. If + * false, these children and their descendants will be rejected. Note + * that this rejection takes precedence over <code>whatToShow</code> and + * the filter. Also note that this is currently the only situation where + * <code>NodeIterators</code> may reject a complete subtree rather than + * skipping individual nodes. + * <br> + * <br> To produce a view of the document that has entity references + * expanded and does not expose the entity reference node itself, use + * the <code>whatToShow</code> flags to hide the entity reference node + * and set <code>expandEntityReferences</code> to true when creating the + * <code>NodeIterator</code>. To produce a view of the document that has + * entity reference nodes but no entity expansion, use the + * <code>whatToShow</code> flags to show the entity reference node and + * set <code>expandEntityReferences</code> to false. + */ + public boolean getExpandEntityReferences(); + + /** + * Returns the next node in the set and advances the position of the + * <code>NodeIterator</code> in the set. After a + * <code>NodeIterator</code> is created, the first call to + * <code>nextNode()</code> returns the first node in the set. + * @return The next <code>Node</code> in the set being iterated over, or + * <code>null</code> if there are no more members in that set. + * @exception DOMException + * INVALID_STATE_ERR: Raised if this method is called after the + * <code>detach</code> method was invoked. + */ + public Node nextNode() + throws DOMException; + + /** + * Returns the previous node in the set and moves the position of the + * <code>NodeIterator</code> backwards in the set. + * @return The previous <code>Node</code> in the set being iterated over, + * or <code>null</code> if there are no more members in that set. + * @exception DOMException + * INVALID_STATE_ERR: Raised if this method is called after the + * <code>detach</code> method was invoked. + */ + public Node previousNode() + throws DOMException; + + /** + * Detaches the <code>NodeIterator</code> from the set which it iterated + * over, releasing any computational resources and placing the + * <code>NodeIterator</code> in the INVALID state. After + * <code>detach</code> has been invoked, calls to <code>nextNode</code> + * or <code>previousNode</code> will raise the exception + * INVALID_STATE_ERR. + */ + public void detach(); + +} diff --git a/libjava/classpath/external/w3c_dom/org/w3c/dom/traversal/TreeWalker.java b/libjava/classpath/external/w3c_dom/org/w3c/dom/traversal/TreeWalker.java new file mode 100644 index 000000000..74527f30d --- /dev/null +++ b/libjava/classpath/external/w3c_dom/org/w3c/dom/traversal/TreeWalker.java @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2000 World Wide Web Consortium, + * (Massachusetts Institute of Technology, Institut National de + * Recherche en Informatique et en Automatique, Keio University). All + * Rights Reserved. This program is distributed under the W3C's Software + * Intellectual Property License. This program is distributed in the + * hope that it will be useful, but WITHOUT ANY WARRANTY; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. + * See W3C License http://www.w3.org/Consortium/Legal/ for more details. + */ + +package org.w3c.dom.traversal; + +import org.w3c.dom.Node; +import org.w3c.dom.DOMException; + +/** + * <code>TreeWalker</code> objects are used to navigate a document tree or + * subtree using the view of the document defined by their + * <code>whatToShow</code> flags and filter (if any). Any function which + * performs navigation using a <code>TreeWalker</code> will automatically + * support any view defined by a <code>TreeWalker</code>. + * <p>Omitting nodes from the logical view of a subtree can result in a + * structure that is substantially different from the same subtree in the + * complete, unfiltered document. Nodes that are siblings in the + * <code>TreeWalker</code> view may be children of different, widely + * separated nodes in the original view. For instance, consider a + * <code>NodeFilter</code> that skips all nodes except for Text nodes and + * the root node of a document. In the logical view that results, all text + * nodes will be siblings and appear as direct children of the root node, no + * matter how deeply nested the structure of the original document. + * <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>. + * @since DOM Level 2 + */ +public interface TreeWalker { + /** + * The <code>root</code> node of the <code>TreeWalker</code>, as specified + * when it was created. + */ + public Node getRoot(); + + /** + * This attribute determines which node types are presented via the + * <code>TreeWalker</code>. The available set of constants is defined in + * the <code>NodeFilter</code> interface. Nodes not accepted by + * <code>whatToShow</code> will be skipped, but their children may still + * be considered. Note that this skip takes precedence over the filter, + * if any. + */ + public int getWhatToShow(); + + /** + * The filter used to screen nodes. + */ + public NodeFilter getFilter(); + + /** + * The value of this flag determines whether the children of entity + * reference nodes are visible to the <code>TreeWalker</code>. If false, + * these children and their descendants will be rejected. Note that + * this rejection takes precedence over <code>whatToShow</code> and the + * filter, if any. + * <br> To produce a view of the document that has entity references + * expanded and does not expose the entity reference node itself, use + * the <code>whatToShow</code> flags to hide the entity reference node + * and set <code>expandEntityReferences</code> to true when creating the + * <code>TreeWalker</code>. To produce a view of the document that has + * entity reference nodes but no entity expansion, use the + * <code>whatToShow</code> flags to show the entity reference node and + * set <code>expandEntityReferences</code> to false. + */ + public boolean getExpandEntityReferences(); + + /** + * The node at which the <code>TreeWalker</code> is currently positioned. + * <br>Alterations to the DOM tree may cause the current node to no longer + * be accepted by the <code>TreeWalker</code>'s associated filter. + * <code>currentNode</code> may also be explicitly set to any node, + * whether or not it is within the subtree specified by the + * <code>root</code> node or would be accepted by the filter and + * <code>whatToShow</code> flags. Further traversal occurs relative to + * <code>currentNode</code> even if it is not part of the current view, + * by applying the filters in the requested direction; if no traversal + * is possible, <code>currentNode</code> is not changed. + */ + public Node getCurrentNode(); + /** + * The node at which the <code>TreeWalker</code> is currently positioned. + * <br>Alterations to the DOM tree may cause the current node to no longer + * be accepted by the <code>TreeWalker</code>'s associated filter. + * <code>currentNode</code> may also be explicitly set to any node, + * whether or not it is within the subtree specified by the + * <code>root</code> node or would be accepted by the filter and + * <code>whatToShow</code> flags. Further traversal occurs relative to + * <code>currentNode</code> even if it is not part of the current view, + * by applying the filters in the requested direction; if no traversal + * is possible, <code>currentNode</code> is not changed. + * @exception DOMException + * NOT_SUPPORTED_ERR: Raised if an attempt is made to set + * <code>currentNode</code> to <code>null</code>. + */ + public void setCurrentNode(Node currentNode) + throws DOMException; + + /** + * Moves to and returns the closest visible ancestor node of the current + * node. If the search for <code>parentNode</code> attempts to step + * upward from the <code>TreeWalker</code>'s <code>root</code> node, or + * if it fails to find a visible ancestor node, this method retains the + * current position and returns <code>null</code>. + * @return The new parent node, or <code>null</code> if the current node + * has no parent in the <code>TreeWalker</code>'s logical view. + */ + public Node parentNode(); + + /** + * Moves the <code>TreeWalker</code> to the first visible child of the + * current node, and returns the new node. If the current node has no + * visible children, returns <code>null</code>, and retains the current + * node. + * @return The new node, or <code>null</code> if the current node has no + * visible children in the <code>TreeWalker</code>'s logical view. + */ + public Node firstChild(); + + /** + * Moves the <code>TreeWalker</code> to the last visible child of the + * current node, and returns the new node. If the current node has no + * visible children, returns <code>null</code>, and retains the current + * node. + * @return The new node, or <code>null</code> if the current node has no + * children in the <code>TreeWalker</code>'s logical view. + */ + public Node lastChild(); + + /** + * Moves the <code>TreeWalker</code> to the previous sibling of the + * current node, and returns the new node. If the current node has no + * visible previous sibling, returns <code>null</code>, and retains the + * current node. + * @return The new node, or <code>null</code> if the current node has no + * previous sibling. in the <code>TreeWalker</code>'s logical view. + */ + public Node previousSibling(); + + /** + * Moves the <code>TreeWalker</code> to the next sibling of the current + * node, and returns the new node. If the current node has no visible + * next sibling, returns <code>null</code>, and retains the current node. + * @return The new node, or <code>null</code> if the current node has no + * next sibling. in the <code>TreeWalker</code>'s logical view. + */ + public Node nextSibling(); + + /** + * Moves the <code>TreeWalker</code> to the previous visible node in + * document order relative to the current node, and returns the new + * node. If the current node has no previous node, or if the search for + * <code>previousNode</code> attempts to step upward from the + * <code>TreeWalker</code>'s <code>root</code> node, returns + * <code>null</code>, and retains the current node. + * @return The new node, or <code>null</code> if the current node has no + * previous node in the <code>TreeWalker</code>'s logical view. + */ + public Node previousNode(); + + /** + * Moves the <code>TreeWalker</code> to the next visible node in document + * order relative to the current node, and returns the new node. If the + * current node has no next node, or if the search for nextNode attempts + * to step upward from the <code>TreeWalker</code>'s <code>root</code> + * node, returns <code>null</code>, and retains the current node. + * @return The new node, or <code>null</code> if the current node has no + * next node in the <code>TreeWalker</code>'s logical view. + */ + public Node nextNode(); + +} |