package jas.util.xml; import jas.util.ColorConverter; import java.awt.Color; import org.w3c.dom.Attr; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.Text; /** * Utility class for traversing XML DOM trees */ public abstract class XMLNodeTraverser { public void traverse(Node node) throws BadXMLException { if (node instanceof Element) { handleElementAttributes((Element) node); } for (Node n = node.getFirstChild(); n != null; n = n.getNextSibling()) { handleSubNode(n,n.getNodeName()); } } protected void handleSubNode(Node node, String name) throws BadXMLException { int type = node.getNodeType(); switch (type) { case Node.ELEMENT_NODE: handleElement((Element) node,name); break; case Node.TEXT_NODE: handleTextNode((Text) node,name); break; default: handleOtherNode(node,name); } } protected void handleElementAttributes(Element node) throws BadXMLException { NamedNodeMap nnm = node.getAttributes(); for (int i=0; i