Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/server/RiverServiceImpl.java @ 5838:5aa05a7a34b7
Rename modules to more fitting names.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 15:23:37 +0200 |
parents | flys-client/src/main/java/org/dive4elements/river/client/server/RiverServiceImpl.java@821a02bbfb4e |
children | 172338b1407f |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
1 package org.dive4elements.river.client.server; | |
2 | |
3 import org.dive4elements.artifacts.common.ArtifactNamespaceContext; | |
4 import org.dive4elements.artifacts.common.utils.XMLUtils; | |
5 import org.dive4elements.artifacts.httpclient.exceptions.ConnectionException; | |
6 import org.dive4elements.artifacts.httpclient.http.HttpClient; | |
7 import org.dive4elements.artifacts.httpclient.http.HttpClientImpl; | |
8 import org.dive4elements.river.client.client.services.RiverService; | |
9 import org.dive4elements.river.client.server.auth.User; | |
10 import org.dive4elements.river.client.shared.exceptions.ServerException; | |
11 import org.dive4elements.river.client.shared.model.DefaultRiver; | |
12 import org.dive4elements.river.client.shared.model.River; | |
13 | |
14 import java.util.ArrayList; | |
15 import java.util.List; | |
16 | |
17 import javax.xml.xpath.XPathConstants; | |
18 | |
19 import org.apache.log4j.Logger; | |
20 import org.w3c.dom.Document; | |
21 import org.w3c.dom.Element; | |
22 import org.w3c.dom.NodeList; | |
23 | |
24 | |
25 /** | |
26 * This interface provides a method to list the supported rivers of the artifact | |
27 * server. | |
28 * | |
29 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
30 */ | |
31 public class RiverServiceImpl | |
32 extends RemoteServiceServlet | |
33 implements RiverService | |
34 { | |
35 /** Private logger. */ | |
36 private static final Logger logger = | |
37 Logger.getLogger(RiverServiceImpl.class); | |
38 | |
39 /** The XPath string that points to the rivers in the resulting document.*/ | |
40 public static final String XPATH_RIVERS = "/art:rivers/art:river"; | |
41 | |
42 /** The error message key that is thrown if an error occured while reading | |
43 * the supported rivers from server.*/ | |
44 public static final String ERROR_NO_RIVERS_FOUND = "error_no_rivers_found"; | |
45 | |
46 | |
47 /** Get river list. */ | |
48 @Override | |
49 public River[] list(String locale) | |
50 throws ServerException | |
51 { | |
52 String url = getServletContext().getInitParameter("server-url"); | |
53 | |
54 Document doc = XMLUtils.newDocument(); | |
55 | |
56 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( | |
57 doc, | |
58 ArtifactNamespaceContext.NAMESPACE_URI, | |
59 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
60 | |
61 doc.appendChild(ec.create("action")); | |
62 | |
63 HttpClient client = new HttpClientImpl(url, locale); | |
64 | |
65 try { | |
66 Document res = client.callService(url, "rivers", doc); | |
67 | |
68 NodeList rivers = (NodeList) XMLUtils.xpath( | |
69 res, | |
70 XPATH_RIVERS, | |
71 XPathConstants.NODESET, | |
72 ArtifactNamespaceContext.INSTANCE); | |
73 | |
74 if (rivers == null || rivers.getLength() == 0) { | |
75 throw new ServerException(ERROR_NO_RIVERS_FOUND); | |
76 } | |
77 | |
78 int count = rivers.getLength(); | |
79 | |
80 List<River> theRivers = new ArrayList<River>(count); | |
81 User user = this.getUser(); | |
82 | |
83 for (int i = 0; i < count; i++) { | |
84 Element tmp = (Element)rivers.item(i); | |
85 | |
86 String name = tmp.getAttributeNS( | |
87 ArtifactNamespaceContext.NAMESPACE_URI, "name"); | |
88 | |
89 if (name.length() > 0 | |
90 && (user == null || user.canUseFeature("river:" + name))) { | |
91 theRivers.add(new DefaultRiver(name)); | |
92 } | |
93 } | |
94 | |
95 return theRivers.toArray(new River[theRivers.size()]); | |
96 } | |
97 catch (ConnectionException ce) { | |
98 logger.error(ce, ce); | |
99 } | |
100 | |
101 throw new ServerException(ERROR_NO_RIVERS_FOUND); | |
102 } | |
103 } | |
104 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |