annotate flys-client/src/main/java/de/intevation/flys/client/server/MapInfoServiceImpl.java @ 1260:3a4c14b4a8f1

DemDatacagePanel now returns the database ID of the selected DEM. flys-client/trunk@2788 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 19 Sep 2011 15:04:08 +0000
parents 910b03de6857
children ab8eb2f544f2
rev   line source
828
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.client.server;
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
3 import org.w3c.dom.Document;
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
4 import org.w3c.dom.Element;
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
5
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
6 import com.google.gwt.user.server.rpc.RemoteServiceServlet;
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
7
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
8 import de.intevation.artifacts.common.utils.XMLUtils;
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 import de.intevation.artifacts.httpclient.exceptions.ConnectionException;
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12 import de.intevation.artifacts.httpclient.http.HttpClient;
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
13 import de.intevation.artifacts.httpclient.http.HttpClientImpl;
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15 import de.intevation.flys.client.shared.exceptions.ServerException;
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 import de.intevation.flys.client.shared.model.BBox;
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17 import de.intevation.flys.client.shared.model.MapInfo;
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19 import de.intevation.flys.client.client.services.MapInfoService;
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 /**
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23 * This service fetches a document that contains meta information for a specific
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24 * chart.
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 *
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27 */
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28 public class MapInfoServiceImpl
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29 extends RemoteServiceServlet
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30 implements MapInfoService
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31 {
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 public static final String XPATH_RIVER =
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33 "/mapinfo/river/@name";
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 public static final String XPATH_SRID =
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36 "/mapinfo/river/srid/@value";
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38 public static final String XPATH_BBOX =
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39 "/mapinfo/river/bbox/@value";
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41 public static final String XPATH_RIVER_WMS =
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42 "/mapinfo/river/river-wms/@url";
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
43
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44 public static final String XPATH_WMS_URL =
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45 "/mapinfo/river/background-wms/@url";
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47 public static final String XPATH_WMS_LAYERS =
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48 "/mapinfo/river/background-wms/@layers";
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 public static final String ERROR_NO_MAPINFO_FOUND =
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 "mapinfo_service_no_result";
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
54 public MapInfo getMapInfo(String url, String locale, String river)
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
55 throws ServerException
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
56 {
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
57 System.out.println("MapInfoServiceImpl.getMapInfo");
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
58
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
59 Document request = getRequestDocument(river);;
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
60
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
61 HttpClient client = new HttpClientImpl(url, locale);
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
62
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
63 try {
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
64 System.out.println("MapInfoServiceImpl.callService");
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
65 Document result = client.callService(url, "mapinfo", request);
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
66
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
67 if (result == null) {
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
68 System.err.println("MapInfo service returned no result.");
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
69 throw new ServerException(ERROR_NO_MAPINFO_FOUND);
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
70 }
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
71
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
72 return getMapInfo(result);
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
73 }
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
74 catch (ConnectionException ce) {
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
75 System.err.println(ce.getLocalizedMessage());
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
76 }
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
77
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
78 throw new ServerException(ERROR_NO_MAPINFO_FOUND);
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
79 }
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
80
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
81
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
82 public static Document getRequestDocument(String rivername) {
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
83 System.out.println("MapInfoServiceImpl.getRequestDocument");
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
84
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
85 Document request = XMLUtils.newDocument();
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
86 ElementCreator cr = new ElementCreator(request, null, null);
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
87
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
88 Element root = cr.create("mapinfo");
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
89 Element river = cr.create("river");
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
90
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91 river.setTextContent(rivername);
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
93 request.appendChild(root);
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
94 root.appendChild(river);
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
95
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
96 return request;
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
97 }
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
98
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
99
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100 public static MapInfo getMapInfo(Document result) {
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
101 System.out.println("MapInfoServiceImpl.getMapInfo");
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
102
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
103 String river = XMLUtils.xpathString(result, XPATH_RIVER, null);
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
104 String sridStr = XMLUtils.xpathString(result, XPATH_SRID, null);
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
105 String bboxS = XMLUtils.xpathString(result, XPATH_BBOX, null);
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
106 BBox bbox = BBox.getBBoxFromString(bboxS);
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
107
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
108 String riverWMS = XMLUtils.xpathString(result, XPATH_RIVER_WMS, null);
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
109 String wmsURL = XMLUtils.xpathString(result, XPATH_WMS_URL, null);
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
110 String wmsLayers = XMLUtils.xpathString(result, XPATH_WMS_LAYERS, null);
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
111
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
112 int srid = 4326;
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
113
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
114 try {
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
115 srid = Integer.parseInt(sridStr);
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
116 }
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
117 catch (NumberFormatException nfe) {
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
118 // do nothing
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
119 }
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
120
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
121 return new MapInfo(river, srid, bbox, riverWMS, wmsURL, wmsLayers);
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
122 }
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
123 }
910b03de6857 Added a service to get some basic spatial information used for map creation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
124 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org