Mercurial > dive4elements > river
annotate flys-client/src/main/java/de/intevation/flys/client/server/MetaDataServiceImpl.java @ 282:e92f7ef455d6
Show rivers as links instead of a combobox.
flys-client/trunk@1911 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Thu, 12 May 2011 14:59:18 +0000 |
parents | f33af25b7490 |
children | 0fa8bf8a2295 |
rev | line source |
---|---|
262
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.client.server; |
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import java.util.List; |
276
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
4 import java.util.ArrayList; |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
5 |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
6 import org.w3c.dom.Document; |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
7 import org.w3c.dom.Element; |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
8 import org.w3c.dom.Node; |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
9 import org.w3c.dom.NodeList; |
262
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 |
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 import com.google.gwt.user.server.rpc.RemoteServiceServlet; |
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 |
276
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
13 import de.intevation.artifacts.common.ArtifactNamespaceContext; |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
14 |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
15 import de.intevation.artifacts.common.utils.XMLUtils; |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
16 |
262
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 import de.intevation.flys.client.shared.exceptions.ServerException; |
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 |
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 import de.intevation.flys.client.client.services.MetaDataService; |
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 |
276
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
21 import de.intevation.artifacts.httpclient.exceptions.ConnectionException; |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
22 |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
23 import de.intevation.artifacts.httpclient.http.HttpClient; |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
24 import de.intevation.artifacts.httpclient.http.HttpClientImpl; |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
25 |
278
f33af25b7490
Datacage: transport rpc result to ui.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
276
diff
changeset
|
26 import de.intevation.flys.client.shared.model.DataCageTree; |
f33af25b7490
Datacage: transport rpc result to ui.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
276
diff
changeset
|
27 import de.intevation.flys.client.shared.model.DataCageNode; |
f33af25b7490
Datacage: transport rpc result to ui.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
276
diff
changeset
|
28 |
262
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 public class MetaDataServiceImpl |
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 extends RemoteServiceServlet |
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 implements MetaDataService |
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 { |
276
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
33 public static final String ERROR_NO_META_DATA_FOUND = |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
34 "error_no_meta_data_found"; |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
35 |
278
f33af25b7490
Datacage: transport rpc result to ui.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
276
diff
changeset
|
36 public DataCageTree getMetaData(String url, String locale, String river) |
262
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 throws ServerException |
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 { |
276
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
39 System.out.println("MetaDataService.getDistanceInfo"); |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
40 |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
41 Document doc = XMLUtils.newDocument(); |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
42 |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
43 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
44 doc, |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
45 ArtifactNamespaceContext.NAMESPACE_URI, |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
46 ArtifactNamespaceContext.NAMESPACE_PREFIX); |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
47 |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
48 Element riverEl = ec.create("river"); |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
49 |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
50 riverEl.setTextContent(river); |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
51 |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
52 doc.appendChild(riverEl); |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
53 |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
54 HttpClient client = new HttpClientImpl(url, locale); |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
55 |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
56 try { |
278
f33af25b7490
Datacage: transport rpc result to ui.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
276
diff
changeset
|
57 return convert(client.callService(url, "metadata", doc)); |
276
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
58 } |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
59 catch (ConnectionException ce) { |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
60 System.err.println(ce.getLocalizedMessage()); |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
61 } |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
62 |
f4c8ce11df33
UI stub for data cage
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
262
diff
changeset
|
63 throw new ServerException(ERROR_NO_META_DATA_FOUND); |
262
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 } |
278
f33af25b7490
Datacage: transport rpc result to ui.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
276
diff
changeset
|
65 |
f33af25b7490
Datacage: transport rpc result to ui.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
276
diff
changeset
|
66 protected static DataCageNode convert(Node node) { |
f33af25b7490
Datacage: transport rpc result to ui.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
276
diff
changeset
|
67 String name = node.getLocalName(); |
f33af25b7490
Datacage: transport rpc result to ui.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
276
diff
changeset
|
68 DataCageNode dvn = new DataCageNode(name); |
f33af25b7490
Datacage: transport rpc result to ui.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
276
diff
changeset
|
69 NodeList children = node.getChildNodes(); |
f33af25b7490
Datacage: transport rpc result to ui.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
276
diff
changeset
|
70 for (int i = 0, N = children.getLength(); i < N; ++i) { |
f33af25b7490
Datacage: transport rpc result to ui.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
276
diff
changeset
|
71 dvn.addChild(convert(children.item(i))); |
f33af25b7490
Datacage: transport rpc result to ui.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
276
diff
changeset
|
72 } |
f33af25b7490
Datacage: transport rpc result to ui.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
276
diff
changeset
|
73 return dvn; |
f33af25b7490
Datacage: transport rpc result to ui.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
276
diff
changeset
|
74 } |
f33af25b7490
Datacage: transport rpc result to ui.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
276
diff
changeset
|
75 |
f33af25b7490
Datacage: transport rpc result to ui.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
276
diff
changeset
|
76 protected static DataCageTree convert(Document document) { |
f33af25b7490
Datacage: transport rpc result to ui.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
276
diff
changeset
|
77 ArrayList<DataCageNode> roots = new ArrayList<DataCageNode>(); |
f33af25b7490
Datacage: transport rpc result to ui.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
276
diff
changeset
|
78 NodeList nodes = document.getChildNodes(); |
f33af25b7490
Datacage: transport rpc result to ui.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
276
diff
changeset
|
79 for (int i = 0, N = nodes.getLength(); i < N; ++i) { |
f33af25b7490
Datacage: transport rpc result to ui.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
276
diff
changeset
|
80 Node node = nodes.item(i); |
f33af25b7490
Datacage: transport rpc result to ui.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
276
diff
changeset
|
81 if (node.getNodeType() == Node.ELEMENT_NODE) { |
f33af25b7490
Datacage: transport rpc result to ui.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
276
diff
changeset
|
82 roots.add(convert(nodes.item(i))); |
f33af25b7490
Datacage: transport rpc result to ui.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
276
diff
changeset
|
83 } |
f33af25b7490
Datacage: transport rpc result to ui.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
276
diff
changeset
|
84 } |
f33af25b7490
Datacage: transport rpc result to ui.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
276
diff
changeset
|
85 return new DataCageTree(roots.get(0)); |
f33af25b7490
Datacage: transport rpc result to ui.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
276
diff
changeset
|
86 } |
262
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 } |
44a340c9becc
Added stub for meta data service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |