1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.utgenome.gwt.utgb.client.util.xml;
26
27
28 import com.google.gwt.core.client.GWT;
29 import com.google.gwt.xml.client.Node;
30 import com.google.gwt.xml.client.NodeList;
31
32
33
34
35
36
37 public class DOMUtil {
38
39
40
41
42 private DOMUtil()
43 {}
44
45 public static String getAttributeValue(Node node, String attributeName)
46 {
47 Node attributeValue = node.getAttributes().getNamedItem(attributeName);
48 return attributeValue != null ? attributeValue.getNodeValue() : null;
49 }
50
51 public static String getAttributeValue(Node node, String attributeName, String defaultValue)
52 {
53 String value = getAttributeValue(node, attributeName);
54 return value != null ? value : defaultValue;
55 }
56
57 public static boolean getBooleanAttributeValue(Node node, String attributeName, boolean defaultValue)
58 {
59 String value = getAttributeValue(node, attributeName);
60 return value != null ? (value.equals("true") ? true : false) : defaultValue;
61 }
62
63 public static int getIntAttributeValue(Node node, String attributeName, int defaultValue)
64 {
65 String value = getAttributeValue(node, attributeName);
66 try
67 {
68 return value != null ? Integer.parseInt(value) : defaultValue;
69 }
70 catch(NumberFormatException e)
71 {
72 GWT.log("parseInt: " + value, e);
73 return defaultValue;
74 }
75 }
76
77 public static NodeList getChildNodeList(Node baseNode, String tagName)
78 {
79 NodeList childNodeList = baseNode.getChildNodes();
80 NodeListImpl returnNodeList = new NodeListImpl();
81 for ( int i = 0; i < childNodeList.getLength(); i++ ) {
82 Node childNode = childNodeList.item(i);
83 short nodeType = childNode.getNodeType();
84 if ( nodeType != Node.TEXT_NODE && childNode.getNodeName().equalsIgnoreCase(tagName) ) {
85 returnNodeList.add(childNode);
86 }
87 }
88 return returnNodeList;
89 }
90
91 }
92
93
94
95