Mercurial > dive4elements > river
comparison flys-client/src/main/java/org/dive4elements/river/client/server/ThemeListingServiceImpl.java @ 5834:f507086aa94b
Repaired internal references.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:31:32 +0200 |
parents | flys-client/src/main/java/de/intevation/flys/client/server/ThemeListingServiceImpl.java@37dce0f2f63b |
children | 821a02bbfb4e |
comparison
equal
deleted
inserted
replaced
5833:a2bdc0f524e8 | 5834:f507086aa94b |
---|---|
1 package de.intevation.flys.client.server; | |
2 | |
3 import com.google.gwt.user.server.rpc.RemoteServiceServlet; | |
4 | |
5 import de.intevation.artifacts.common.utils.XMLUtils; | |
6 | |
7 import de.intevation.artifacts.httpclient.exceptions.ConnectionException; | |
8 | |
9 import de.intevation.artifacts.httpclient.http.HttpClient; | |
10 import de.intevation.artifacts.httpclient.http.HttpClientImpl; | |
11 | |
12 import de.intevation.flys.client.client.services.ThemeListingService; | |
13 | |
14 import de.intevation.flys.client.shared.exceptions.ServerException; | |
15 | |
16 import de.intevation.flys.client.shared.model.Style; | |
17 | |
18 import java.util.HashMap; | |
19 import java.util.Map; | |
20 | |
21 import javax.xml.xpath.XPathConstants; | |
22 | |
23 import org.apache.log4j.Logger; | |
24 | |
25 import org.w3c.dom.Document; | |
26 import org.w3c.dom.Element; | |
27 import org.w3c.dom.NodeList; | |
28 | |
29 /** | |
30 * This interface provides a method to list themes filtered by name. | |
31 * | |
32 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | |
33 */ | |
34 public class ThemeListingServiceImpl | |
35 extends RemoteServiceServlet | |
36 implements ThemeListingService | |
37 { | |
38 private static final Logger logger = | |
39 Logger.getLogger(ThemeListingServiceImpl.class); | |
40 | |
41 | |
42 private static final String XPATH_THEME_GROUPS = "/themes/themegroup"; | |
43 /** The error message key that is thrown if an error occured while reading | |
44 * the supported rivers from server.*/ | |
45 public static final String ERROR_NO_GROUPS_FOUND = "error_no_groups_found"; | |
46 | |
47 | |
48 public Map<String, Style> list(String locale, String name) | |
49 throws ServerException | |
50 { | |
51 String url = getServletContext().getInitParameter("server-url"); | |
52 | |
53 Document doc = XMLUtils.newDocument(); | |
54 | |
55 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( | |
56 doc, | |
57 null, | |
58 null); | |
59 | |
60 Element e = ec.create("theme"); | |
61 ec.addAttr(e, "name", name); | |
62 doc.appendChild(e); | |
63 HttpClient client = new HttpClientImpl(url, locale); | |
64 | |
65 try { | |
66 Document res = client.callService(url, "themelisting", doc); | |
67 | |
68 NodeList themeGroups = (NodeList) XMLUtils.xpath( | |
69 res, | |
70 XPATH_THEME_GROUPS, | |
71 XPathConstants.NODESET, | |
72 null); | |
73 | |
74 if (themeGroups == null || themeGroups.getLength() == 0) { | |
75 throw new ServerException(ERROR_NO_GROUPS_FOUND); | |
76 } | |
77 | |
78 int count = themeGroups.getLength(); | |
79 | |
80 Map<String, Style> theStyles = new HashMap<String, Style>(count); | |
81 | |
82 for (int i = 0; i < count; i++) { | |
83 Element tmp = (Element)themeGroups.item(i); | |
84 | |
85 String groupName = tmp.getAttribute("name"); | |
86 NodeList theTheme = (NodeList) XMLUtils.xpath( | |
87 tmp, | |
88 "theme", | |
89 XPathConstants.NODESET, | |
90 null); | |
91 | |
92 for (int j = 0; j < theTheme.getLength(); j++) { | |
93 Element elem = (Element) theTheme.item(j); | |
94 theStyles.put(groupName, StyleHelper.getStyle(elem)); | |
95 } | |
96 } | |
97 | |
98 return theStyles; | |
99 } | |
100 catch (ConnectionException ce) { | |
101 logger.error(ce, ce); | |
102 } | |
103 | |
104 throw new ServerException(ERROR_NO_GROUPS_FOUND); | |
105 } | |
106 } | |
107 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |