Mercurial > dive4elements > river
comparison flys-client/src/main/java/org/dive4elements/river/client/server/ModuleServiceImpl.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/ModuleServiceImpl.java@fed914a42a10 |
children | 821a02bbfb4e |
comparison
equal
deleted
inserted
replaced
5833:a2bdc0f524e8 | 5834:f507086aa94b |
---|---|
1 package de.intevation.flys.client.server; | |
2 | |
3 import de.intevation.artifacts.common.ArtifactNamespaceContext; | |
4 import de.intevation.artifacts.common.utils.XMLUtils; | |
5 import de.intevation.artifacts.httpclient.exceptions.ConnectionException; | |
6 import de.intevation.artifacts.httpclient.http.HttpClient; | |
7 import de.intevation.artifacts.httpclient.http.HttpClientImpl; | |
8 import de.intevation.flys.client.client.services.ModuleService; | |
9 import de.intevation.flys.client.server.auth.User; | |
10 import de.intevation.flys.client.shared.exceptions.ServerException; | |
11 import de.intevation.flys.client.shared.model.DefaultModule; | |
12 import de.intevation.flys.client.shared.model.Module; | |
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 public class ModuleServiceImpl | |
25 extends RemoteServiceServlet | |
26 implements ModuleService | |
27 { | |
28 private static final Logger logger = | |
29 Logger.getLogger(ModuleServiceImpl.class); | |
30 | |
31 public static final String XPATH_MODULES = "/art:modules/art:module"; | |
32 | |
33 public static final String ERROR_NO_MODULES_FOUND = | |
34 "error_no_module_found"; | |
35 | |
36 @Override | |
37 public Module[] list(String locale) throws ServerException { | |
38 User user = this.getUser(); | |
39 | |
40 logger.info("ModuleService.list"); | |
41 | |
42 String url = getServletContext().getInitParameter("server-url"); | |
43 | |
44 // create dummy xml | |
45 Document doc = XMLUtils.newDocument(); | |
46 | |
47 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( | |
48 doc, | |
49 ArtifactNamespaceContext.NAMESPACE_URI, | |
50 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
51 | |
52 Element dummy = ec.create("modules"); | |
53 doc.appendChild(dummy); | |
54 | |
55 HttpClient client = new HttpClientImpl(url, locale); | |
56 try { | |
57 Document result = client.callService(url, "modules", doc); | |
58 | |
59 NodeList list = (NodeList) XMLUtils.xpath( | |
60 result, | |
61 XPATH_MODULES, | |
62 XPathConstants.NODESET, | |
63 ArtifactNamespaceContext.INSTANCE); | |
64 | |
65 if (list == null) { | |
66 logger.warn("No modules found."); | |
67 | |
68 throw new ServerException(ERROR_NO_MODULES_FOUND); | |
69 } | |
70 | |
71 int num = list.getLength(); | |
72 | |
73 List<Module> modules = new ArrayList<Module>(list.getLength()); | |
74 for(int i =0; i < num; i++) { | |
75 Element em = (Element)list.item(i); | |
76 String name = em.getAttributeNS( | |
77 ArtifactNamespaceContext.NAMESPACE_URI, "name"); | |
78 String localname = em.getAttributeNS( | |
79 ArtifactNamespaceContext.NAMESPACE_URI, "localname"); | |
80 String strselected = em.getAttributeNS( | |
81 ArtifactNamespaceContext.NAMESPACE_URI, "selected"); | |
82 boolean selected = strselected == null ? false : | |
83 strselected.equalsIgnoreCase("true"); | |
84 logger.debug("Found module " + name + " " + localname); | |
85 if (user == null || user.canUseFeature("module:" + name)) { | |
86 modules.add(new DefaultModule(name, localname, selected)); | |
87 } | |
88 } | |
89 return modules.toArray(new Module[modules.size()]); | |
90 } | |
91 catch (ConnectionException ce) { | |
92 logger.error(ce, ce); | |
93 } | |
94 | |
95 throw new ServerException(ERROR_NO_MODULES_FOUND); | |
96 } | |
97 } | |
98 | |
99 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 tw=80 : |