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.track.lib.old;
26
27 import java.util.Iterator;
28 import java.util.Set;
29
30 import org.utgenome.gwt.utgb.client.track.TrackGroupProperty;
31 import org.utgenome.gwt.utgb.client.util.xml.NodeListImpl;
32
33 import com.google.gwt.xml.client.NamedNodeMap;
34 import com.google.gwt.xml.client.Node;
35 import com.google.gwt.xml.client.NodeList;
36
37
38
39
40
41
42
43
44 public final class Utilities {
45
46
47
48
49 private Utilities() {
50 throw new AssertionError();
51 }
52
53
54
55
56
57
58
59
60
61
62
63 public static final String getKeyAndValueString(final String key, final String connector, final String value) {
64 return key + connector + value;
65 }
66
67
68
69
70
71
72
73
74
75
76
77 public static final String getKeyAndValueString(final String key, final String value) {
78 return getKeyAndValueString(key, "=", value);
79 }
80
81 public static final String getAttributeValue(final Node node, final String attributeName) {
82 final NamedNodeMap attributeMap = node.getAttributes();
83 final Node attributeNode = attributeMap.getNamedItem(attributeName);
84 if (attributeNode == null)
85 return null;
86 else
87 return attributeNode.getNodeValue();
88 }
89
90 public static final String getAttributeValue(final Node node, final String attributeName, final String defaultValue) {
91 String value = getAttributeValue(node, attributeName);
92 return value != null ? value : defaultValue;
93 }
94
95 public static final NodeList getTagChildNodes(final Node parent) {
96 final NodeList originalNodeList = parent.getChildNodes();
97
98 final NodeListImpl tagNodeList = new NodeListImpl();
99
100 final int SIZE = originalNodeList.getLength();
101 for (int i = 0; i < SIZE; i++) {
102 final Node originalNode = originalNodeList.item(i);
103
104 final short nodeType = originalNode.getNodeType();
105 if (nodeType != Node.TEXT_NODE) {
106 tagNodeList.add(originalNode);
107 }
108 }
109
110 return tagNodeList;
111 }
112
113 public static final String getPropertyXMLTag(final String key, final String value) {
114 return "<property key=\"" + key + "\">" + value + "</property>";
115 }
116
117 public static final String convertTrackGroupPropertyToXML(final TrackGroupProperty trackGroupProperty) {
118 final Set<String> keySet = trackGroupProperty.keySet();
119 if (keySet.size() == 0)
120 return null;
121
122 final StringBuffer buf = new StringBuffer();
123
124 final Iterator<String> keyIterator = keySet.iterator();
125 while (keyIterator.hasNext()) {
126 final String key = (keyIterator.next());
127
128 final String value = (trackGroupProperty.getProperty(key));
129
130 if (buf.length() > 0)
131 buf.append('\n');
132 buf.append(getPropertyXMLTag(key, value));
133 }
134
135 return buf.toString();
136 }
137
138 public static final String convertTrackGroupPropertyToXML(final TrackGroupProperty trackGroupProperty, final Set<String> outputKeySet) {
139 final Set<String> keySet = trackGroupProperty.keySet();
140 if (keySet.size() == 0)
141 return null;
142
143 final StringBuffer buf = new StringBuffer();
144
145 final Iterator<String> keyIterator = keySet.iterator();
146 while (keyIterator.hasNext()) {
147 final String key = (keyIterator.next());
148
149 if (outputKeySet.contains(key)) {
150 final String value = (trackGroupProperty.getProperty(key));
151
152 if (buf.length() > 0)
153 buf.append('\n');
154 buf.append(getPropertyXMLTag(key, value));
155 }
156 }
157
158 if (buf.length() == 0)
159 return null;
160 else
161 return buf.toString();
162 }
163 }