1 10 package org.mmbase.util; 11 12 import java.io.File ; 13 14 import org.mmbase.util.logging.*; 15 import org.w3c.dom.*; 16 17 31 public class XMLContextDepthReader { 32 33 private static final Logger log = Logging.getLoggerInstance(XMLContextDepthReader.class); 35 36 Document document; 37 38 41 public XMLContextDepthReader(String filename) { 42 try { 43 document = XMLBasicReader.getDocumentBuilder(false, null, null).parse(new File (filename)); 44 } catch (Exception e) { 45 log.error(e.getMessage()); 46 log.error(Logging.stackTrace(e)); 47 } 48 } 49 50 53 public int getDepth() { 54 Node n1 = document.getFirstChild(); 55 if (n1 != null) { 56 Node n2 = n1.getFirstChild(); 57 while (n2 != null) { 58 if (n2.getNodeName().equals("depth")) { 59 Node n3 = n2.getFirstChild(); 60 String tmp = n3.getNodeValue(); 61 try { 62 return Integer.parseInt(tmp); 63 } catch (Exception e) { 64 return -1; 65 } 66 67 } 68 n2 = n2.getNextSibling(); 69 } 70 } 71 return -1; 72 } 73 74 77 public String getStartBuilder() { 78 Node n1 = document.getFirstChild(); 79 if (n1 != null) { 80 Node n2 = n1.getFirstChild(); 81 while (n2 != null) { 82 if (n2.getNodeName().equals("startnode")) { 83 Node n3 = n2.getFirstChild(); 84 while (n3 != null) { 85 if (n3.getNodeName().equals("builder")) { 86 Node n4 = n3.getFirstChild(); 87 return n4.getNodeValue(); 88 } 89 n3 = n3.getNextSibling(); 90 } 91 } 92 n2 = n2.getNextSibling(); 93 } 94 } 95 return null; 96 } 97 98 101 public String getStartAlias() { 102 Node n1 = document.getFirstChild(); 103 if (n1 != null) { 104 Node n2 = n1.getFirstChild(); 105 while (n2 != null) { 106 if (n2.getNodeName().equals("startnode")) { 107 NamedNodeMap nm = n2.getAttributes(); 108 if (nm != null) { 109 Node n4 = nm.getNamedItem("alias"); 110 if (n4 != null) 111 return n4.getNodeValue(); 112 } 113 114 } 115 n2 = n2.getNextSibling(); 116 } 117 } 118 return null; 119 } 120 121 124 public String getStartWhere() { 125 Node n1 = document.getFirstChild(); 126 if (n1 != null) { 127 Node n2 = n1.getFirstChild(); 128 while (n2 != null) { 129 if (n2.getNodeName().equals("startnode")) { 130 Node n3 = n2.getFirstChild(); 131 while (n3 != null) { 132 if (n3.getNodeName().equals("where")) { 133 Node n4 = n3.getFirstChild(); 134 return n4.getNodeValue(); 135 } 136 n3 = n3.getNextSibling(); 137 } 138 } 139 n2 = n2.getNextSibling(); 140 } 141 } 142 return null; 143 } 144 } 145 | Popular Tags |