1 23 24 package org.enhydra.xml.xmlc.compiler; 25 26 import java.io.PrintWriter ; 27 import java.util.Vector ; 28 29 import org.enhydra.xml.xmlc.dom.XMLCDocument; 30 import org.w3c.dom.Attr ; 31 import org.w3c.dom.Document ; 32 import org.w3c.dom.Element ; 33 import org.w3c.dom.NamedNodeMap ; 34 import org.w3c.dom.Node ; 35 36 39 class PrintInfo { 40 43 private Vector urls = new Vector (); 44 45 48 private Vector ids = new Vector (); 49 50 53 public PrintInfo(Document doc, XMLCDocument xmlcDoc) { 54 getNodeInfo(doc, xmlcDoc); 55 } 56 57 60 private void getElementURLs(Element element, XMLCDocument xmlcDoc) { 61 NamedNodeMap attrs = element.getAttributes(); 62 if (attrs != null) { 63 for (int idx = 0; idx < attrs.getLength(); idx++) { 64 Attr attr = (Attr )attrs.item(idx); 65 if (xmlcDoc.isURLAttribute(element, attr.getNodeName())) { 66 urls.addElement(attr.getValue()); 67 } 68 } 69 } 70 } 71 72 75 private void getNodeInfo(Node node, XMLCDocument xmlcDoc) { 76 if (node instanceof Element ) { 77 Element elem = (Element )node; 78 getElementURLs(elem, xmlcDoc); 79 String id = xmlcDoc.getElementId(elem); 80 if ((id != null) && (id.length() > 0)) { 81 ids.addElement(id + " => " 82 + xmlcDoc.nodeClassToInterface(node)); 83 } 84 } 85 86 for (Node child = node.getFirstChild(); child != null; 87 child = child.getNextSibling()) { 88 getNodeInfo(child, xmlcDoc); 89 } 90 } 91 92 95 protected void printInfo(PrintWriter out) { 96 int idx; 97 98 out.println("Element IDs:"); 99 for (idx = 0; idx < ids.size(); idx++) { 100 out.println(" " + ids.elementAt(idx)); 101 } 102 out.println("Document URLs:"); 103 for (idx = 0; idx < urls.size(); idx++) { 104 out.println(" " + urls.elementAt(idx)); 105 } 106 } 107 } 108 | Popular Tags |