Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/server/ArtifactDescriptionFactory.java @ 34:bf84bcd4e11b
Parse static data from DESCRIBE.
flys-client/trunk@1454 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 10 Mar 2011 13:40:29 +0000 |
parents | 88c530c25968 |
children | b6b89ff1adee |
comparison
equal
deleted
inserted
replaced
33:e29658e2623a | 34:bf84bcd4e11b |
---|---|
35 | 35 |
36 public static final String XPATH_UIPROVIDER = "@art:uiprovider"; | 36 public static final String XPATH_UIPROVIDER = "@art:uiprovider"; |
37 | 37 |
38 public static final String XPATH_REACHABLE_STATE = "art:state"; | 38 public static final String XPATH_REACHABLE_STATE = "art:state"; |
39 | 39 |
40 public static final String XPATH_STATIC_DATA_NODE = "art:data"; | |
41 | |
42 public static final String XPATH_STATIC_ITEM_NODE = "art:item"; | |
43 | |
40 /** | 44 /** |
41 * This method creates the {@link ArtifactDescription} of the DESCRIBE | 45 * This method creates the {@link ArtifactDescription} of the DESCRIBE |
42 * document <i>doc</i>. | 46 * document <i>doc</i>. |
43 * | 47 * |
44 * @param doc A DESCRIBE document. | 48 * @param doc A DESCRIBE document. |
58 XPATH_STATE_NAME, | 62 XPATH_STATE_NAME, |
59 XPathConstants.STRING, | 63 XPathConstants.STRING, |
60 ArtifactNamespaceContext.INSTANCE); | 64 ArtifactNamespaceContext.INSTANCE); |
61 System.out.println("Current state name: " + state); | 65 System.out.println("Current state name: " + state); |
62 | 66 |
63 Data currentData = extractCurrentData(dynamicNode); | 67 Data currentData = extractCurrentData(dynamicNode); |
64 String[] states = extractReachableStates(reachable); | 68 Data[] old = extractOldData(staticNode); |
65 | 69 String[] states = extractReachableStates(reachable); |
66 // TODO parse the static ui part | 70 |
67 return new DefaultArtifactDescription(null, currentData, state, states); | 71 return new DefaultArtifactDescription(old, currentData, state, states); |
68 } | 72 } |
69 | 73 |
70 | 74 |
71 /** | 75 /** |
72 * This method extracts the data that the user is able to enter in the | 76 * This method extracts the data that the user is able to enter in the |
119 | 123 |
120 dataItems.add(new DefaultDataItem(label, null, value)); | 124 dataItems.add(new DefaultDataItem(label, null, value)); |
121 } | 125 } |
122 | 126 |
123 return (DataItem[]) dataItems.toArray(new DataItem[count]); | 127 return (DataItem[]) dataItems.toArray(new DataItem[count]); |
128 } | |
129 | |
130 | |
131 /** | |
132 * This method extracts the data objects from the data node of the static ui | |
133 * part of the DESCRIBE document. | |
134 * | |
135 * @param staticNode The static ui node of the DESCRIBE. | |
136 * | |
137 * @return the Data objects. | |
138 */ | |
139 protected static Data[] extractOldData(Node staticNode) { | |
140 System.out.println("ArtifactDescriptionFactory - extractOldData()"); | |
141 | |
142 NodeList dataNodes = (NodeList) XMLUtils.xpath( | |
143 staticNode, | |
144 XPATH_STATIC_DATA_NODE, | |
145 XPathConstants.NODESET, | |
146 ArtifactNamespaceContext.INSTANCE); | |
147 | |
148 if (dataNodes == null || dataNodes.getLength() == 0) { | |
149 System.out.println("No old items found."); | |
150 return null; | |
151 } | |
152 | |
153 int count = dataNodes.getLength(); | |
154 | |
155 Data[] data = new Data[count]; | |
156 | |
157 for (int i = 0; i < count; i++) { | |
158 Node tmp = dataNodes.item(i); | |
159 | |
160 String name = XMLUtils.xpathString( | |
161 tmp, "@art:name", ArtifactNamespaceContext.INSTANCE); | |
162 String type = XMLUtils.xpathString( | |
163 tmp, "@art:type", ArtifactNamespaceContext.INSTANCE); | |
164 | |
165 DataItem[] items = extractOldDataItems(tmp); | |
166 | |
167 data[i] = new DefaultData(name, name, type, items, null); | |
168 } | |
169 | |
170 return data; | |
171 } | |
172 | |
173 | |
174 /** | |
175 * This method extracts the data items from the data nodes that are placed | |
176 * in the static ui part of the DESCRIBE document. | |
177 * | |
178 * @param dataNode A data node that contains items. | |
179 * | |
180 * @return a list of DataItems. | |
181 */ | |
182 protected static DataItem[] extractOldDataItems(Node dataNode) { | |
183 NodeList itemList = (NodeList) XMLUtils.xpath( | |
184 dataNode, | |
185 XPATH_STATIC_ITEM_NODE, | |
186 XPathConstants.NODESET, | |
187 ArtifactNamespaceContext.INSTANCE); | |
188 | |
189 if (itemList == null || itemList.getLength() == 0) { | |
190 System.out.println("No old data items found."); | |
191 return null; | |
192 } | |
193 | |
194 int count = itemList.getLength(); | |
195 | |
196 DataItem[] items = new DataItem[count]; | |
197 | |
198 for (int i = 0; i < count; i++) { | |
199 Node tmp = itemList.item(i); | |
200 | |
201 String value = XMLUtils.xpathString( | |
202 tmp, "@art:value", ArtifactNamespaceContext.INSTANCE); | |
203 | |
204 // TODO extract the human readable value (description) from node | |
205 items[i] = new DefaultDataItem(value, value, value); | |
206 } | |
207 | |
208 return items; | |
124 } | 209 } |
125 | 210 |
126 | 211 |
127 /** | 212 /** |
128 * This method extracts the UIProvider specified by the data node. | 213 * This method extracts the UIProvider specified by the data node. |