1 18 19 package org.apache.batik.dom.traversal; 20 21 import java.util.Iterator ; 22 import java.util.LinkedList ; 23 import java.util.List ; 24 25 import org.apache.batik.dom.AbstractDocument; 26 import org.w3c.dom.DOMException ; 27 import org.w3c.dom.Node ; 28 import org.w3c.dom.traversal.NodeFilter; 29 import org.w3c.dom.traversal.NodeIterator; 30 import org.w3c.dom.traversal.TreeWalker; 31 32 38 public class TraversalSupport { 39 40 43 protected List iterators; 44 45 48 public TraversalSupport() { 49 } 50 51 54 public static TreeWalker createTreeWalker(AbstractDocument doc, 55 Node root, 56 int whatToShow, 57 NodeFilter filter, 58 boolean entityReferenceExpansion) { 59 if (root == null) { 60 throw doc.createDOMException 61 (DOMException.NOT_SUPPORTED_ERR, "null.root", null); 62 } 63 return new DOMTreeWalker(root, whatToShow, filter, 64 entityReferenceExpansion); 65 } 66 67 70 public NodeIterator createNodeIterator(AbstractDocument doc, 71 Node root, 72 int whatToShow, 73 NodeFilter filter, 74 boolean entityReferenceExpansion) 75 throws DOMException { 76 if (root == null) { 77 throw doc.createDOMException 78 (DOMException.NOT_SUPPORTED_ERR, "null.root", null); 79 } 80 NodeIterator result = new DOMNodeIterator(doc, root, whatToShow, 81 filter, 82 entityReferenceExpansion); 83 if (iterators == null) { 84 iterators = new LinkedList (); 85 } 86 iterators.add(result); 87 88 return result; 89 } 90 91 94 public void nodeToBeRemoved(Node removedNode) { 95 if (iterators != null) { 96 Iterator it = iterators.iterator(); 97 while (it.hasNext()) { 98 ((DOMNodeIterator)it.next()).nodeToBeRemoved(removedNode); 99 } 100 } 101 } 102 103 106 public void detachNodeIterator(NodeIterator it) { 107 iterators.remove(it); 108 } 109 } 110 | Popular Tags |