286N/A * reserved comment block 286N/A * DO NOT REMOVE OR ALTER! 286N/A * Copyright 1999-2002,2004 The Apache Software Foundation. 286N/A * Licensed under the Apache License, Version 2.0 (the "License"); 286N/A * you may not use this file except in compliance with the License. 286N/A * You may obtain a copy of the License at 286N/A * Unless required by applicable law or agreed to in writing, software 286N/A * distributed under the License is distributed on an "AS IS" BASIS, 286N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 286N/A * See the License for the specific language governing permissions and 286N/A * limitations under the License. 286N/A/** DefaultNodeIterator implements a NodeIterator, which iterates a 286N/A * DOM tree in the expected depth first way. 286N/A * <p>The whatToShow and filter functionality is implemented as expected. 286N/A * <p>This class also has method removeNode to enable iterator "fix-up" 286N/A * on DOM remove. It is expected that the DOM implementation call removeNode 286N/A * right before the actual DOM transformation. If not called by the DOM, 286N/A * the client could call it before doing the removal. 286N/A /** The DocumentImpl which created this iterator, so it can be detached. */ 286N/A /** The whatToShow mask. */ 286N/A /** The NodeFilter reference. */ 286N/A /** If detach is called, the fDetach flag is true, otherwise flase. */ 286N/A // Iterator state - current node and direction. 286N/A // Note: The current node and direction are sufficient to implement 286N/A // the desired behaviour of the current pointer being _between_ 286N/A // two nodes. The fCurrentNode is actually the last node returned, 286N/A // direction is whether the pointer is in front or behind this node. 286N/A // (usually akin to whether the node was returned via nextNode()) 286N/A // (eg fForward = true) or previousNode() (eg fForward = false). 286N/A // Note also, if removing a Node, the fCurrentNode 286N/A // can be placed on a Node which would not pass filters. 286N/A /** The last Node returned. */ 286N/A /** The direction of the iterator on the fCurrentNode. 286N/A * nextNode() == fForward = true; 286N/A * previousNode() == fForward = false; 286N/A /** When TRUE, the children of entites references are returned in the iterator. */ 286N/A /** Public constructor */ 286N/A // Implementation Note: Note that the iterator looks at whatToShow 286N/A // and filter values at each call, and therefore one _could_ add 286N/A // setters for these values and alter them while iterating! 286N/A /** Return the whatToShow value */ 286N/A /** Return the filter */ 286N/A /** Return whether children entity references are included in the iterator. */ 286N/A /** Return the next Node in the Iterator. The node is the next node in 286N/A * depth-first order which also passes the filter, and whatToShow. 286N/A * If there is no next node which passes these criteria, then return null. 286N/A // if root is null there is no next node. 286N/A boolean accepted =
false;
// the next node has not been accepted. 286N/A // if last direction is not forward, repeat node. 286N/A //System.out.println("nextNode():!fForward:"+fCurrentNode.getNodeName()); 286N/A // else get the next node via depth-first 286N/A fForward =
true;
//REVIST: should direction be set forward before null check? 286N/A // nothing in the list. return null. 286N/A // does node pass the filters and whatToShow? 286N/A // if so, then the node is the current node. 286N/A }
// while (!accepted) { 286N/A // no nodes, or no accepted nodes. 286N/A /** Return the previous Node in the Iterator. The node is the next node in 286N/A * _backwards_ depth-first order which also passes the filter, and whatToShow. 286N/A // if the root is null, or the current node is null, return null. 286N/A // get previous node in backwards depth first order. 286N/A // we are going backwards 286N/A // if the new previous node is null, we're at head or past the root, 286N/A // check if node passes filters and whatToShow. 286N/A // if accepted, update the current node, and return it. 286N/A /** The node is accepted if it passes the whatToShow and the filter. */ 286N/A /** Return node, if matches or any parent if matches. */ 286N/A // Additions and removals in the underlying data structure may occur 286N/A // before any iterations, and in this case the reference_node is null. 286N/A // check if the removed node is an _ancestor_ of the 286N/A /** The method nextNode(Node, boolean) returns the next node 286N/A * from the actual DOM tree. 286N/A * The boolean visitChildren determines whether to visit the children. 286N/A * The result is the nextNode. 286N/A // only check children if we visit children. 286N/A //if hasChildren, return 1st child. 286N/A // if hasSibling, return sibling 286N/A // return parent's 1st sibling. 286N/A }
// while (parent != null && parent != fRoot) { 286N/A // end of list, return null 286N/A /** The method previousNode(Node) returns the previous node 286N/A * from the actual DOM tree. 286N/A // if we're at the root, return null. 286N/A //if 1st sibling, return parent 286N/A // if sibling has children, keep getting last child of child. 286N/A /** Fix-up the iterator on a remove. Called by DOM or otherwise, 286N/A * before an actual DOM remove. 286N/A // Implementation note: Fix-up means setting the current node properly 286N/A // normal case: there _are_ nodes following this in the iterator. 286N/A // the last node in the iterator is to be removed, 286N/A // so we set the current node to be the previous one.