Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/server/MapInfoServiceImpl.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/MapInfoServiceImpl.java@821a02bbfb4e |
children | 172338b1407f |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
1 package org.dive4elements.river.client.server; | |
2 | |
3 import com.google.gwt.core.client.GWT; | |
4 import com.google.gwt.user.server.rpc.RemoteServiceServlet; | |
5 | |
6 import org.dive4elements.artifacts.common.utils.XMLUtils; | |
7 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; | |
8 import org.dive4elements.artifacts.httpclient.exceptions.ConnectionException; | |
9 import org.dive4elements.artifacts.httpclient.http.HttpClient; | |
10 import org.dive4elements.artifacts.httpclient.http.HttpClientImpl; | |
11 import org.dive4elements.river.client.client.services.MapInfoService; | |
12 import org.dive4elements.river.client.shared.exceptions.ServerException; | |
13 import org.dive4elements.river.client.shared.model.BBox; | |
14 import org.dive4elements.river.client.shared.model.MapInfo; | |
15 | |
16 import org.apache.log4j.Logger; | |
17 import org.w3c.dom.Document; | |
18 import org.w3c.dom.Element; | |
19 | |
20 | |
21 /** | |
22 * This service fetches a document that contains meta information for a specific | |
23 * chart. | |
24 * | |
25 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
26 */ | |
27 public class MapInfoServiceImpl | |
28 extends RemoteServiceServlet | |
29 implements MapInfoService | |
30 { | |
31 private static final Logger logger = | |
32 Logger.getLogger(MapInfoServiceImpl.class); | |
33 | |
34 | |
35 public static final String XPATH_RIVER = | |
36 "/mapinfo/river/@name"; | |
37 | |
38 public static final String XPATH_SRID = | |
39 "/mapinfo/river/srid/@value"; | |
40 | |
41 public static final String XPATH_BBOX = | |
42 "/mapinfo/river/bbox/@value"; | |
43 | |
44 public static final String XPATH_RIVER_WMS = | |
45 "/mapinfo/river/river-wms/@url"; | |
46 | |
47 public static final String XPATH_RIVER_LAYERS = | |
48 "/mapinfo/river/river-wms/@layers"; | |
49 | |
50 public static final String XPATH_WMS_URL = | |
51 "/mapinfo/river/background-wms/@url"; | |
52 | |
53 public static final String XPATH_WMS_LAYERS = | |
54 "/mapinfo/river/background-wms/@layers"; | |
55 | |
56 public static final String ERROR_NO_MAPINFO_FOUND = | |
57 "mapinfo_service_no_result"; | |
58 | |
59 | |
60 @Override | |
61 public MapInfo getMapInfo(String locale, String river) | |
62 throws ServerException | |
63 { | |
64 logger.info("MapInfoServiceImpl.getMapInfo"); | |
65 | |
66 String url = getServletContext().getInitParameter("server-url"); | |
67 | |
68 Document request = getRequestDocument(river, "rivermap"); | |
69 | |
70 HttpClient client = new HttpClientImpl(url, locale); | |
71 | |
72 try { | |
73 logger.debug("MapInfoServiceImpl.callService"); | |
74 Document result = client.callService(url, "mapinfo", request); | |
75 | |
76 if (result == null) { | |
77 logger.warn("MapInfo service returned no result."); | |
78 throw new ServerException(ERROR_NO_MAPINFO_FOUND); | |
79 } | |
80 | |
81 return getMapInfo(result); | |
82 } | |
83 catch (ConnectionException ce) { | |
84 logger.error(ce, ce); | |
85 } | |
86 | |
87 throw new ServerException(ERROR_NO_MAPINFO_FOUND); | |
88 } | |
89 | |
90 | |
91 public static Document getRequestDocument(String rivername, String maptypeStr) { | |
92 logger.debug("MapInfoServiceImpl.getRequestDocument"); | |
93 | |
94 Document request = XMLUtils.newDocument(); | |
95 ElementCreator cr = new ElementCreator(request, null, null); | |
96 | |
97 Element root = cr.create("mapinfo"); | |
98 Element river = cr.create("river"); | |
99 Element maptype = cr.create("maptype"); | |
100 | |
101 river.setTextContent(rivername); | |
102 maptype.setTextContent(maptypeStr); | |
103 | |
104 request.appendChild(root); | |
105 root.appendChild(river); | |
106 root.appendChild(maptype); | |
107 | |
108 return request; | |
109 } | |
110 | |
111 | |
112 public static MapInfo getMapInfo(Document result) { | |
113 logger.debug("MapInfoServiceImpl.getMapInfo"); | |
114 | |
115 String river = XMLUtils.xpathString(result, XPATH_RIVER, null); | |
116 String sridStr = XMLUtils.xpathString(result, XPATH_SRID, null); | |
117 String bboxS = XMLUtils.xpathString(result, XPATH_BBOX, null); | |
118 BBox bbox = BBox.getBBoxFromString(bboxS); | |
119 | |
120 String riverWMS = XMLUtils.xpathString(result, XPATH_RIVER_WMS, null); | |
121 String riverLayers = XMLUtils.xpathString(result, XPATH_RIVER_LAYERS, null); | |
122 String wmsURL = XMLUtils.xpathString(result, XPATH_WMS_URL, null); | |
123 String wmsLayers = XMLUtils.xpathString(result, XPATH_WMS_LAYERS, null); | |
124 | |
125 int srid = 4326; | |
126 | |
127 try { | |
128 srid = Integer.parseInt(sridStr); | |
129 } | |
130 catch (NumberFormatException nfe) { | |
131 GWT.log("Could not parse SRID String: " + sridStr); | |
132 } | |
133 | |
134 return new MapInfo( | |
135 river, srid, bbox, riverWMS, riverLayers, wmsURL, wmsLayers); | |
136 } | |
137 } | |
138 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |