Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/server/DescribeCollectionServiceImpl.java @ 524:ba238f917b94
The theme list information stored in the attribute of a collection is read and added in form of Themes and ThemeLists to the Collection.
flys-client/trunk@2003 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 25 May 2011 13:42:04 +0000 |
parents | d01b0d81b92a |
children | 5277f46a63c2 |
comparison
equal
deleted
inserted
replaced
523:0785a8ba5e6d | 524:ba238f917b94 |
---|---|
1 package de.intevation.flys.client.server; | 1 package de.intevation.flys.client.server; |
2 | 2 |
3 import java.util.ArrayList; | 3 import java.util.ArrayList; |
4 import java.util.HashMap; | |
4 import java.util.List; | 5 import java.util.List; |
6 import java.util.Map; | |
5 | 7 |
6 import javax.xml.xpath.XPathConstants; | 8 import javax.xml.xpath.XPathConstants; |
7 | 9 |
8 import org.w3c.dom.Document; | 10 import org.w3c.dom.Document; |
9 import org.w3c.dom.Node; | 11 import org.w3c.dom.Node; |
25 import de.intevation.flys.client.shared.model.CollectionItem; | 27 import de.intevation.flys.client.shared.model.CollectionItem; |
26 import de.intevation.flys.client.shared.model.DefaultCollection; | 28 import de.intevation.flys.client.shared.model.DefaultCollection; |
27 import de.intevation.flys.client.shared.model.DefaultCollectionItem; | 29 import de.intevation.flys.client.shared.model.DefaultCollectionItem; |
28 import de.intevation.flys.client.shared.model.DefaultFacet; | 30 import de.intevation.flys.client.shared.model.DefaultFacet; |
29 import de.intevation.flys.client.shared.model.DefaultOutputMode; | 31 import de.intevation.flys.client.shared.model.DefaultOutputMode; |
32 import de.intevation.flys.client.shared.model.DefaultTheme; | |
30 import de.intevation.flys.client.shared.model.ExportMode; | 33 import de.intevation.flys.client.shared.model.ExportMode; |
31 import de.intevation.flys.client.shared.model.Facet; | 34 import de.intevation.flys.client.shared.model.Facet; |
32 import de.intevation.flys.client.shared.model.OutputMode; | 35 import de.intevation.flys.client.shared.model.OutputMode; |
36 import de.intevation.flys.client.shared.model.Theme; | |
37 import de.intevation.flys.client.shared.model.ThemeList; | |
33 import de.intevation.flys.client.client.services.DescribeCollectionService; | 38 import de.intevation.flys.client.client.services.DescribeCollectionService; |
34 | 39 |
35 | 40 |
36 /** | 41 /** |
37 * This service implements a method that queries the DESCRIBE document of a | 42 * This service implements a method that queries the DESCRIBE document of a |
70 | 75 |
71 if (c == null) { | 76 if (c == null) { |
72 throw new ServerException(ERROR_DESCRIBE_COLLECTION); | 77 throw new ServerException(ERROR_DESCRIBE_COLLECTION); |
73 } | 78 } |
74 | 79 |
80 System.out.println("Collection successfully parsed."); | |
81 | |
75 return c; | 82 return c; |
76 } | 83 } |
77 catch (ConnectionException ce) { | 84 catch (ConnectionException ce) { |
78 System.err.println(ce.getLocalizedMessage()); | 85 System.err.println(ce.getLocalizedMessage()); |
79 } | 86 } |
108 if (uuid == null || uuid.equals("")) { | 115 if (uuid == null || uuid.equals("")) { |
109 System.err.println("Found an invalid Collection!"); | 116 System.err.println("Found an invalid Collection!"); |
110 return null; | 117 return null; |
111 } | 118 } |
112 | 119 |
113 Collection c = new DefaultCollection(uuid); | 120 Map<String, ThemeList> themeList = parseThemeLists(description); |
121 | |
122 Collection c = null; | |
123 | |
124 if (themeList != null) { | |
125 c = new DefaultCollection(uuid, themeList); | |
126 //c = new DefaultCollection(uuid); | |
127 } | |
128 else { | |
129 c = new DefaultCollection(uuid); | |
130 } | |
114 | 131 |
115 NodeList items = (NodeList) XMLUtils.xpath( | 132 NodeList items = (NodeList) XMLUtils.xpath( |
116 description, | 133 description, |
117 "art:artifact-collection/art:artifacts/art:artifact", | 134 "art:artifact-collection/art:artifacts/art:artifact", |
118 XPathConstants.NODESET, | 135 XPathConstants.NODESET, |
137 System.out.println( | 154 System.out.println( |
138 "Found " + c.getItemLength() + " collection items " + | 155 "Found " + c.getItemLength() + " collection items " + |
139 "for the Collection '" + c.identifier() + "'."); | 156 "for the Collection '" + c.identifier() + "'."); |
140 | 157 |
141 return c; | 158 return c; |
159 } | |
160 | |
161 | |
162 protected Map<String, ThemeList> parseThemeLists(Document description) { | |
163 System.out.println("DescribeCollectionServiceImpl.parseThemeLists"); | |
164 | |
165 NodeList lists = (NodeList) XMLUtils.xpath( | |
166 description, | |
167 "/art:artifact-collection/art:attribute/art:outputs/art:output", | |
168 XPathConstants.NODESET, | |
169 ArtifactNamespaceContext.INSTANCE); | |
170 | |
171 int num = lists != null ? lists.getLength() : 0; | |
172 | |
173 Map<String, ThemeList> themeList = new HashMap<String, ThemeList>(num); | |
174 | |
175 for (int i = 0; i < num; i++) { | |
176 Node node = lists.item(i); | |
177 | |
178 String outName = XMLUtils.xpathString( | |
179 node, "@name", ArtifactNamespaceContext.INSTANCE); | |
180 | |
181 ThemeList list = parseThemeList(node); | |
182 | |
183 if (list != null) { | |
184 themeList.put(outName, list); | |
185 } | |
186 } | |
187 | |
188 return themeList; | |
189 } | |
190 | |
191 | |
192 protected ThemeList parseThemeList(Node node) { | |
193 System.out.println("DescribeCollectionServiceImpl.parseThemeList"); | |
194 | |
195 NodeList themes = (NodeList) XMLUtils.xpath( | |
196 node, | |
197 "art:theme", | |
198 XPathConstants.NODESET, | |
199 ArtifactNamespaceContext.INSTANCE); | |
200 | |
201 int num = themes != null ? themes.getLength() : 0; | |
202 | |
203 List<Theme> themeList = new ArrayList<Theme>(num); | |
204 | |
205 for (int i = 0; i < num; i++) { | |
206 Theme theme = parseTheme(themes.item(i)); | |
207 | |
208 if (theme != null) { | |
209 themeList.add(theme); | |
210 } | |
211 } | |
212 | |
213 return new ThemeList(themeList); | |
214 } | |
215 | |
216 | |
217 protected Theme parseTheme(Node node) { | |
218 System.out.println("DescribeCollectionServiceImpl.parseTheme"); | |
219 | |
220 String strAct = XMLUtils.xpathString( | |
221 node, "@art:active", ArtifactNamespaceContext.INSTANCE); | |
222 | |
223 String art = XMLUtils.xpathString( | |
224 node, "@art:artifact", ArtifactNamespaceContext.INSTANCE); | |
225 | |
226 String fac = XMLUtils.xpathString( | |
227 node, "@art:facet", ArtifactNamespaceContext.INSTANCE); | |
228 | |
229 String strPos = XMLUtils.xpathString( | |
230 node, "@art:pos", ArtifactNamespaceContext.INSTANCE); | |
231 | |
232 if (strAct != null && art != null && fac != null && strPos != null) { | |
233 try { | |
234 int pos = Integer.valueOf(strPos); | |
235 int active = Integer.valueOf(strAct); | |
236 | |
237 return new DefaultTheme(pos, active > 0, art, fac); | |
238 } | |
239 catch (NumberFormatException nfe) { | |
240 nfe.printStackTrace(); | |
241 } | |
242 } | |
243 | |
244 return null; | |
142 } | 245 } |
143 | 246 |
144 | 247 |
145 /** | 248 /** |
146 * This method extracts the CollectionItem from <i>node</i> with its output | 249 * This method extracts the CollectionItem from <i>node</i> with its output |