1 16 19 20 package com.sun.org.apache.xml.internal.utils; 21 22 import java.util.Enumeration ; 23 import java.util.Hashtable ; 24 import java.util.Vector ; 25 26 import org.w3c.dom.Document ; 27 import org.w3c.dom.Element ; 28 import org.w3c.dom.Node ; 29 30 41 public abstract class Hashtree2Node 42 { 43 44 63 public static void appendHashToNode(Hashtable hash, String name, 64 Node container, Document factory) 65 { 66 if ((null == container) || (null == factory) || (null == hash)) 68 { 69 return; 70 } 71 72 String elemName = null; 74 if ((null == name) || ("".equals(name))) 75 elemName = "appendHashToNode"; 76 else 77 elemName = name; 78 79 try 80 { 81 Element hashNode = factory.createElement(elemName); 82 container.appendChild(hashNode); 83 84 Enumeration keys = hash.keys(); 85 Vector v = new Vector (); 86 87 while (keys.hasMoreElements()) 88 { 89 Object key = keys.nextElement(); 90 String keyStr = key.toString(); 91 Object item = hash.get(key); 92 93 if (item instanceof Hashtable ) 94 { 95 v.addElement(keyStr); 99 v.addElement((Hashtable ) item); 100 } 101 else 102 { 103 try 104 { 105 Element node = factory.createElement("item"); 107 node.setAttribute("key", keyStr); 108 node.appendChild(factory.createTextNode((String )item)); 109 hashNode.appendChild(node); 110 } 111 catch (Exception e) 112 { 113 Element node = factory.createElement("item"); 114 node.setAttribute("key", keyStr); 115 node.appendChild(factory.createTextNode("ERROR: Reading " + key + " threw: " + e.toString())); 116 hashNode.appendChild(node); 117 } 118 } 119 } 120 121 keys = v.elements(); 123 while (keys.hasMoreElements()) 124 { 125 String n = (String ) keys.nextElement(); 127 Hashtable h = (Hashtable ) keys.nextElement(); 128 129 appendHashToNode(h, n, hashNode, factory); 130 } 131 } 132 catch (Exception e2) 133 { 134 e2.printStackTrace(); 137 } 138 } 139 } 140 | Popular Tags |