1 32 33 package it.businesslogic.ireport.connection; 34 35 39 public class FieldNode { 40 41 42 private java.util.Properties attributes; 43 44 private java.util.Vector children; 45 46 47 private String name = ""; 48 49 50 private String value = null; 51 52 private int childIndex = 0; 53 54 private boolean consumed = false; 55 56 60 public FieldNode(String name) { 61 attributes = new java.util.Properties (); 62 children = new java.util.Vector (); 63 this.name = name; 64 } 65 66 70 public java.util.Properties getAttributes() { 71 return attributes; 72 } 73 74 78 public void setAttributes(java.util.Properties attributes) { 79 this.attributes = attributes; 80 } 81 82 86 public java.lang.String getName() { 87 return name; 88 } 89 90 94 public void setName(java.lang.String name) { 95 this.name = name; 96 } 97 98 102 public java.lang.String getValue() { 103 return value; 104 } 105 106 107 111 public java.lang.String getValue(String def) { 112 if (value == null || value.length() == 0) return def; 113 return value; 114 } 115 116 120 public boolean getValueAsBoolean() { 121 if (value !=null && value.trim().equalsIgnoreCase("true")) return true; 122 return false; 123 } 124 125 126 130 public int getValueAsInteger() { 131 try { 132 return Integer.parseInt( value + "" ); 133 } catch (Exception ex) { 134 return 0; 135 } 136 } 137 138 142 public void setValue(java.lang.String value) { 143 this.value = value; 144 } 145 146 152 public FieldNode getChild(java.lang.String childName, boolean noNull) { 153 154 java.util.Enumeration enum_children = children.elements(); 155 while (enum_children.hasMoreElements()) 156 { 157 FieldNode cn = (FieldNode)enum_children.nextElement(); 158 if (cn.getName().equals(childName) ) return cn; 159 } 160 161 if (noNull) 162 { 163 FieldNode cn = new FieldNode(childName); 164 this.children.add(cn); 165 return cn; 166 } 167 return null; 168 } 169 170 171 176 public java.util.Vector getChilddren(java.lang.String childName) { 177 178 java.util.Vector result = new java.util.Vector (); 179 java.util.Enumeration enum_children = children.elements(); 180 while (enum_children.hasMoreElements()) 181 { 182 FieldNode cn = (FieldNode)enum_children.nextElement(); 183 if (cn.getName().equals(childName) ) 184 { 185 result.add(cn); 186 } 187 } 188 return result; 189 } 190 191 196 public FieldNode getChild(java.lang.String childName) { 197 return getChild(childName, true); 198 } 199 200 201 206 public FieldNode getNextChild() { 207 208 209 if (this.getChildren().size() == 0) 210 { 211 return new FieldNode("Unnamed"); 212 } 213 if (childIndex < 0) 214 { 215 childIndex = 0; 216 } 217 return (FieldNode)this.getChildren().elementAt( childIndex ); 218 } 219 220 221 226 public java.lang.String getAttribute(String attrName) { 227 return attributes.getProperty(attrName); 228 } 229 230 236 public java.lang.String getAttribute(String attrName, String def) { 237 return attributes.getProperty(attrName,def); 238 } 239 240 245 public boolean getAttributeAsBoolean(String attrName) { 246 String val = attributes.getProperty(attrName); 247 if (val !=null && val.trim().equalsIgnoreCase("true")) return true; 248 return false; 249 } 250 251 252 257 public int getAttributeAsInteger(String attrName) { 258 try { 259 String val = attributes.getProperty(attrName); 260 return Integer.parseInt( val + "" ); 261 } catch (Exception ex) { 262 return 0; 263 } 264 } 265 266 270 public java.util.Vector getChildren() { 271 return children; 272 } 273 274 278 public void setChildren(java.util.Vector children) { 279 this.children = children; 280 } 281 282 public boolean next(String xmlPath) { 283 285 if (xmlPath.startsWith("/")) 287 { 288 xmlPath = xmlPath.substring(1); 289 } 290 291 if (xmlPath.indexOf("/") < 0) 292 { 293 if (!consumed) { return consumed = true; } 295 else return false; 296 } 297 298 xmlPath = xmlPath.substring( xmlPath.indexOf("/")); 300 301 if (childIndex == 0 && getChildren().size() == 0) 303 { 304 if (!consumed) { return consumed = true; } 305 else return false; 306 } 307 308 if (!getNextChild().next(xmlPath)) 310 { 311 childIndex++; 312 if (childIndex < getChildren().size()) return getNextChild().next(xmlPath); 314 } 315 else 316 { 317 return true; 318 } 319 321 return false; 322 } 323 324 public String getChildsPath(String xmlPath) 325 { 326 if (xmlPath.indexOf("/") == xmlPath.lastIndexOf("/")) 327 { 328 return ""; 330 } 331 332 xmlPath = xmlPath.substring(xmlPath.indexOf("/")+1); 333 return this.getNextChild().getName() +"(" + childIndex +")::" + this.getNextChild().getChildsPath(xmlPath); 334 335 } 336 } 337 | Popular Tags |