1 10 package org.mmbase.module.builders; 11 12 import java.io.File ; 13 import java.io.IOException ; 14 import java.util.*; 15 16 import javax.xml.parsers.DocumentBuilder ; 17 18 import org.mmbase.module.core.MMObjectNode; 19 import org.mmbase.util.XMLBasicReader; 20 import org.mmbase.util.logging.*; 21 22 import org.w3c.dom.*; 23 import org.xml.sax.SAXException ; 24 25 31 public class VersionXMLCacheNodeReader { 32 33 private static Logger log = Logging.getLoggerInstance(VersionCacheNode.class.getName()); 34 Document document; 35 Versions parent; 36 37 public VersionXMLCacheNodeReader(String filename) { 38 try { 39 DocumentBuilder db = XMLBasicReader.getDocumentBuilder(false); 40 File file = new File (filename); 41 if (!file.exists()) { 42 log.error("no cache version " + filename + " found)"); 43 } 44 document = db.parse(file); 45 } 46 catch (SAXException e) { 47 log.error("", e); 48 } 49 catch (IOException e) { 50 log.error("", e); 51 } 52 } 53 54 public void setBuilder(Versions parent) { 55 this.parent = parent; 56 } 57 58 60 public Hashtable getCacheVersions(Hashtable handlers) { 61 Node n1 = document.getFirstChild(); 62 if (n1.getNodeType() == Node.DOCUMENT_TYPE_NODE) { 63 n1 = n1.getNextSibling(); 64 } 65 if (n1 != null) { 66 Node n2 = n1.getFirstChild(); 67 while (n2 != null) { 68 if (n2.getNodeName().equals("cacheversion")) { 69 70 NamedNodeMap nm = n2.getAttributes(); 72 if (nm != null) { 73 Node n3 = nm.getNamedItem("name"); 74 if (n3 != null) { 75 String name = n3.getNodeValue(); 76 if (log.isDebugEnabled()) log.debug("name = " + name); 77 MMObjectNode versionnode = null; 79 String query = "name=='" + name + "'+type=='cache'"; 80 Enumeration b = parent.search(query); 81 if (b.hasMoreElements()) { 82 versionnode = (MMObjectNode)b.nextElement(); 83 } 84 if (log.isDebugEnabled()) log.debug("versionnode=" + versionnode); 85 VersionCacheNode cnode = new VersionCacheNode(parent.getMMBase()); 86 cnode.setVersionNode(versionnode); 87 88 n3 = n2.getFirstChild(); 89 while (n3 != null) { 90 91 if (n3.getNodeName().equals("when")) { 92 VersionCacheWhenNode wn = new VersionCacheWhenNode(); 94 nm = n3.getAttributes(); 95 if (nm != null) { 96 Node n5 = nm.getNamedItem("type"); 97 if (n5 != null) { 98 String types = n5.getNodeValue(); 99 StringTokenizer tok = new StringTokenizer(types, ",\n\r"); 100 while (tok.hasMoreTokens()) { 101 String type = tok.nextToken(); 102 wn.addType(type); 103 104 106 Vector subs = (Vector)handlers.get(type); 107 if (subs == null) { 108 subs = new Vector(); 109 subs.addElement(cnode); 110 handlers.put(type, subs); 111 } else { 112 subs.addElement(cnode); 113 } 114 } 115 } 116 n5 = nm.getNamedItem("node"); 117 if (n5 != null) { 118 String nodes = n5.getNodeValue(); 119 StringTokenizer tok = new StringTokenizer(nodes, ",\n\r"); 120 while (tok.hasMoreTokens()) { 121 String type = tok.nextToken(); 122 wn.addNode(type); 123 } 124 } 125 } 126 cnode.addWhen(wn); 127 } 128 n3 = n3.getNextSibling(); 129 } 130 } 131 } 132 } 133 n2 = n2.getNextSibling(); 134 } 135 } 136 return handlers; 137 } 138 139 141 public Vector getDefines() { 142 Vector results = new Vector(); 143 Node n1 = document.getFirstChild(); 144 if (n1 != null) { 145 Node n2 = n1.getFirstChild(); 146 while (n2 != null) { 147 if (n2.getNodeName().equals("define")) { 148 Hashtable rep = new Hashtable(); 149 150 NamedNodeMap nm = n2.getAttributes(); 152 if (nm != null) { 153 Node n3 = nm.getNamedItem("type"); 154 if (n3 != null) { 155 rep.put("type", n3.getNodeValue()); 156 } 157 n3 = nm.getNamedItem("id"); 158 if (n3 != null) { 159 rep.put("id", n3.getNodeValue()); 160 } 161 162 n3 = nm.getNamedItem("width"); 163 if (n3 != null) { 164 rep.put("width", n3.getNodeValue()); 165 } 166 167 n3 = nm.getNamedItem("height"); 168 if (n3 != null) { 169 rep.put("height", n3.getNodeValue()); 170 } 171 172 n3 = nm.getNamedItem("src"); 173 if (n3 != null) { 174 rep.put("src", n3.getNodeValue()); 175 } 176 177 n3 = nm.getNamedItem("value"); 178 if (n3 != null) { 179 rep.put("value", n3.getNodeValue()); 180 } 181 n3 = nm.getNamedItem("file"); 182 if (n3 != null) { 183 rep.put("valuefile", n3.getNodeValue()); 184 } 185 186 } 187 188 results.addElement(rep); 189 } 190 n2 = n2.getNextSibling(); 191 } 192 } 193 return results; 194 } 195 196 } 197 | Popular Tags |