1 23 24 package org.enhydra.xml.lazydom; 25 26 import org.enhydra.xml.dom.DOMOps; 27 import org.enhydra.xml.dom.SimpleDOMTraversal; 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 public class LazyDOMSimpleTraversal extends SimpleDOMTraversal { 38 39 private LazyDocument fLazyDoc; 40 41 46 public LazyDOMSimpleTraversal(SimpleDOMTraversal.Handler handler) { 47 super(handler); 48 } 49 50 56 public void traverse(Node root) { 57 Node lazyRoot = DOMOps.getActualNode(root); 59 fLazyDoc = (LazyDocument)lazyRoot.getOwnerDocument(); 60 if (fLazyDoc == null) { 61 fLazyDoc = (LazyDocument)lazyRoot; 62 } 63 if (fLazyDoc.isTemplateNode()) { 64 throw new LazyDOMError("LazyDOMSimpleTraversal used on template document"); 65 } 66 processNode(lazyRoot); 67 } 68 69 73 public void processChildren(Node node) { 74 if (node instanceof LazyParent) { 75 LazyParent lazyNode = (LazyParent)node; 76 if (lazyNode.isTemplateNode()) { 77 super.processChildren(lazyNode); 79 } else if (lazyNode.areChildrenExpanded()) { 80 super.processChildren(lazyNode); 82 } else { 83 super.processChildren(lazyNode.getTemplateNode()); 85 } 86 } 87 } 88 89 94 public void processAttributes(Element element) { 95 LazyElement lazyElement = (LazyElement)element; 96 if (lazyElement.isTemplateNode()) { 97 super.processAttributes(lazyElement); 99 } else if (lazyElement.areAttributesExpanded()) { 100 super.processAttributes(lazyElement); 102 } else { 103 super.processAttributes(lazyElement.getTemplateElement()); 105 } 106 } 107 108 113 public void processDocumentType(Document document) { 114 LazyDocument lazyDoc = (LazyDocument)document; 115 if (lazyDoc.isTemplateNode()) { 116 super.processDocumentType(document); 118 } else if (lazyDoc.isDocTypeExpanded()) { 119 super.processDocumentType(document); 121 } else { 122 super.processDocumentType(lazyDoc.getTemplateDocument()); 124 } 125 } 126 127 132 public void processDocumentTypeContents(DocumentType documentType) { 133 LazyDocumentType lazyDocType = (LazyDocumentType)documentType; 134 if (lazyDocType.isTemplateNode()) { 135 super.processDocumentTypeContents(lazyDocType); 137 } else if (lazyDocType.isContentsExpanded()) { 138 super.processDocumentTypeContents(lazyDocType); 140 } else { 141 super.processDocumentTypeContents(lazyDocType.getTemplateDocumentType()); 143 } 144 } 145 146 151 protected void processNode(Node node) { 152 LazyNode lazyNode = (LazyNode)node; 153 if (lazyNode.isTemplateNode()) { 154 LazyNode instanceNode = fLazyDoc.getExpandedNode(lazyNode.getNodeId()); 155 if (instanceNode != null) { 156 super.processNode(instanceNode); 158 } else { 159 super.processNode(lazyNode); 161 } 162 } else { 163 super.processNode(lazyNode); 165 } 166 } 167 } 168 | Popular Tags |