1 package de.webman.template.jsp; 2 import org.w3c.dom.*; 3 import org.w3c.dom.traversal.*; 4 5 6 13 public class WSP { 14 15 16 protected Node root; 17 18 19 public WSP(Node root) 20 { 21 this.root = root; 22 } 23 24 25 public WSP(WSP obj) 26 { 27 this.root = obj.root; 28 } 29 30 32 public Node getNode() 33 { 34 return(root); 35 } 36 37 44 public String getAttribute(String attrname) 45 { 46 try 47 { 48 return(root.getAttributes().getNamedItem(attrname).getNodeValue()); 49 } 50 catch(NullPointerException e) 51 { 52 return(null); 53 } 54 } 55 56 64 public String getAttribute(String attrname, String value) 65 { 66 try 67 { 68 String v = root.getAttributes().getNamedItem(attrname).getNodeValue(); 69 if (v == null) 70 return value; 71 return v; 72 } 73 catch(NullPointerException e) 74 { 75 return(value); 76 } 77 } 78 79 84 public String getUploadPath() 85 { 86 if (root.hasChildNodes()) 87 return(root.getChildNodes().item(0).getNodeValue()); 88 return(null); 89 } 90 91 98 public String getItem() 99 { 100 if (root.hasChildNodes()) 101 { 102 if (root.getChildNodes().item(0).hasChildNodes()) 103 return(root.getChildNodes().item(0).getChildNodes().item(0).getNodeValue()); 104 } 105 return(null); 106 } 107 108 114 public String getItem(int number) 115 { 116 if (root.hasChildNodes()) 117 { 118 if (root.getChildNodes().getLength() > number) 119 { 120 if (root.getChildNodes().item(number).hasChildNodes()) 121 return(root.getChildNodes().item(number).getChildNodes().item(0).getNodeValue()); 122 } 123 } 124 return(null); 125 } 126 127 131 public WSP getChild(int number) 132 { 133 if (root.getChildNodes().getLength() > number) 134 { 135 WSP help = new WSP(root.getChildNodes().item(number)); 136 return(help); 137 } 138 return(null); 139 140 } 141 142 147 public WSP getNodeByAttr(String attrname,String attrvalue) { 148 149 if (this == null) return(this); 151 152 if (this.getAttribute(attrname) != null) 153 { 154 if (this.getAttribute(attrname).equals(attrvalue)) 155 return(this); 156 } 157 158 for (int i = 0;this.getChild(i) != null;i++) 160 { 161 WSP help = this.getChild(i).getNodeByAttr(attrname,attrvalue); 162 if (help != null) 163 return(help); 164 } 165 166 return(null); 167 } 168 169 173 public WSP getNodeByName(String name) 174 { 175 return(this.getNodeByAttr("NAME",name)); 176 } 177 178 private static String getNextNode(String path) 180 { 181 if (path == null) 182 return(null); 183 184 int index = path.indexOf('.'); 185 186 if (index == -1) 187 return(path); 188 return(path.substring(0,index)); 189 } 190 191 private static String getNextPath(String path) 193 { 194 String Node = getNextNode(path); 195 196 if (Node == null) return (null); 197 198 if (Node.length()+1 <= path.length()) 199 return(path.substring(Node.length()+1,path.length())); 200 201 return(null); 202 } 203 204 210 public WSP getNodeByPath(String path) 211 { 212 String node = null; 213 WSP back = new WSP(this); 214 int i; 215 216 while ((back != null) && (path != null)) 217 { 218 node = getNextNode(path); 219 path = getNextPath(path); 220 221 if (node == null) break; 222 223 for (i = 0;(back.getChild(i) != null);i++) 224 { 225 if (back.getChild(i).getAttribute("NAME") != null) 226 { 227 if (back.getChild(i).getAttribute("NAME").equals(node)) 228 break; 229 } 230 } 231 back = back.getChild(i); 232 } 233 return(back); 234 } 235 236 242 public WSP getNodeByNodePath(String path) 243 { 244 return(getNodeByNodePath(path,0)); 245 } 246 247 252 public WSP getNodeByNodePath(String path,int index) 253 { 254 String node = null; 255 WSP back = new WSP(this); 256 int i,treffer; 257 treffer = 0; 258 while ((back != null) && (path != null)) 259 { 260 node = getNextNode(path); 261 path = getNextPath(path); 262 263 if (node == null) break; 264 265 for (i = 0;(back.getChild(i) != null);i++) 266 { 267 268 if (back.getChild(i).getNode().getNodeName() != null) 269 { 270 if (back.getChild(i).getNode().getNodeName().equals(node)) 271 { 272 273 if (path == null) 274 { 275 if (treffer == index) 276 break; 277 treffer++; 278 } 279 else 280 break; 281 } 282 } 283 } 284 back = back.getChild(i); 285 } 286 return(back); 287 } 288 289 293 public WSP getElement_FEW_BEL_EL_IN_F(String name,int Element) 294 { 295 296 if (root != null) 297 { 298 int z = 0; 299 300 for (int i=0;this.getNodeByNodePath("FEW-BEL_ELE_IN_F",i) != null;i++) 301 { 302 303 WSP help = this.getNodeByNodePath("FEW-BEL_ELE_IN_F",i); 304 305 if (help.getAttribute("NAME") != null) 306 { 307 if (help.getAttribute("NAME").equals(name)) 308 { 309 if (z == Element) 310 return(help); 311 z++; 312 } 313 } 314 } 315 } 316 317 return(null); 318 } 319 320 324 public String getLength_FEW_BEL_EL_IN_F(String name) 325 { 326 327 WSP help = this.getElement_FEW_BEL_EL_IN_F(name,0); 328 329 if ( help != null) 330 return(help.getAttribute("LENGTH")); 331 332 return(null); 333 } 334 335 339 public WSP getTableCell(String pfad,int row,int col) 340 { 341 WSP table = this.getNodeByPath(pfad); 342 if (table == null) 343 return(null); 344 WSP row1 = table.getChild(row); 345 if (row1 == null) 346 return(null); 347 return(row1.getChild(col)); 348 } 349 350 } 351 | Popular Tags |