1 23 24 package org.enhydra.xml.lazydom; 25 26 import org.enhydra.xml.dom.DOMOps; 27 import org.enhydra.xml.dom.DOMTraversal; 28 import org.w3c.dom.Document ; 29 import org.w3c.dom.DocumentType ; 30 import org.w3c.dom.Element ; 31 import org.w3c.dom.Node ; 32 33 37 40 46 public class LazyDOMTraversal extends DOMTraversal { 47 48 private LazyDocument fLazyDoc; 49 50 56 public LazyDOMTraversal(DOMTraversal.Handler handler, 57 int options) { 58 super(handler, options); 59 } 60 61 64 public LazyDOMTraversal(int options) { 65 super(options); 66 } 67 68 74 public void traverse(Node root) { 75 Node lazyRoot = DOMOps.getActualNode(root); 77 fLazyDoc = (LazyDocument)lazyRoot.getOwnerDocument(); 78 if (fLazyDoc == null) { 79 fLazyDoc = (LazyDocument)lazyRoot; 80 } 81 if (fLazyDoc.isTemplateNode()) { 82 throw new LazyDOMError("LazyDOMTraversal used on template document"); 83 } 84 85 fDepth = 0; 86 fProcessingAttribute = false; 87 processNode(lazyRoot); 88 } 89 90 94 public void processChildren(Node node) { 95 if (node instanceof LazyParent) { 96 LazyParent lazyNode = (LazyParent)node; 97 if (lazyNode.isTemplateNode()) { 98 super.processChildren(lazyNode); 100 } else if (lazyNode.areChildrenExpanded()) { 101 super.processChildren(lazyNode); 103 } else { 104 super.processChildren(lazyNode.getTemplateNode()); 106 } 107 } 108 } 109 110 114 public void processAttributes(Element element) { 115 LazyElement lazyElement = (LazyElement)element; 116 if (lazyElement.isTemplateNode()) { 117 super.processAttributes(lazyElement); 119 } else if (lazyElement.areAttributesExpanded()) { 120 super.processAttributes(lazyElement); 122 } else { 123 super.processAttributes(lazyElement.getTemplateElement()); 125 } 126 } 127 128 133 public void processDocumentType(Document document) { 134 LazyDocument lazyDoc = (LazyDocument)document; 135 if (lazyDoc.isTemplateNode()) { 136 super.processDocumentType(document); 138 } else if (lazyDoc.isDocTypeExpanded()) { 139 super.processDocumentType(document); 141 } else { 142 super.processDocumentType(lazyDoc.getTemplateDocument()); 144 } 145 } 146 147 152 public void processDocumentTypeContents(DocumentType documentType) { 153 LazyDocumentType lazyDocType = (LazyDocumentType)documentType; 154 if (lazyDocType.isTemplateNode()) { 155 super.processDocumentTypeContents(lazyDocType); 157 } else if (lazyDocType.isContentsExpanded()) { 158 super.processDocumentTypeContents(lazyDocType); 160 } else { 161 super.processDocumentTypeContents(lazyDocType.getTemplateDocumentType()); 163 } 164 } 165 166 171 protected void processNode(Node node) { 172 LazyNode lazyNode = (LazyNode)node; 173 if (lazyNode.isTemplateNode()) { 174 LazyNode instanceNode = fLazyDoc.getExpandedNode(lazyNode.getNodeId()); 175 if (instanceNode != null) { 176 super.processNode(instanceNode); 178 } else { 179 super.processNode(lazyNode); 181 } 182 } else { 183 super.processNode(lazyNode); 185 } 186 } 187 } 188 | Popular Tags |