Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/server/MapPrintServiceImpl.java @ 2508:4aa70825bde1
map print: generate valid url to access service.
flys-client/trunk@4363 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 09 May 2012 11:18:24 +0000 |
parents | 47d07709ba09 |
children | 4861ab2c28d2 |
comparison
equal
deleted
inserted
replaced
2507:7ef59d7e113d | 2508:4aa70825bde1 |
---|---|
119 } | 119 } |
120 } // class Layer | 120 } // class Layer |
121 | 121 |
122 protected static String generateSpec( | 122 protected static String generateSpec( |
123 Document descDocument, | 123 Document descDocument, |
124 Document outDocument, | 124 MapConfig mapConfig, |
125 double minX, double minY, | 125 Double minX, Double minY, |
126 double maxX, double maxY | 126 Double maxX, Double maxY |
127 ) { | 127 ) { |
128 MapConfig mapConfig = MapHelper.parseConfig(outDocument); | |
129 | |
130 Map<String, Object> spec = new LinkedHashMap<String, Object>(); | 128 Map<String, Object> spec = new LinkedHashMap<String, Object>(); |
131 spec.put("layout", "A4 portrait"); | 129 spec.put("layout", "A4 portrait"); |
132 spec.put("title", "FLYS Druck"); | 130 spec.put("title", "FLYS Druck"); |
133 spec.put("srs", "EPSG:" + mapConfig.getSrid()); | 131 spec.put("srs", "EPSG:" + mapConfig.getSrid()); |
134 spec.put("dpi", Integer.valueOf(254)); | 132 spec.put("dpi", Integer.valueOf(254)); |
135 spec.put("units", "degrees"); | 133 spec.put("units", "m"); |
136 spec.put("outputFormat", "pdf"); | 134 spec.put("outputFormat", "pdf"); |
137 | 135 |
138 | 136 |
139 List<Layer> ls = new ArrayList<Layer>(); | 137 List<Layer> ls = new ArrayList<Layer>(); |
140 Layer l = new Layer(); | 138 Layer l = new Layer(); |
201 String minXS = req.getParameter("minx"); | 199 String minXS = req.getParameter("minx"); |
202 String maxXS = req.getParameter("maxx"); | 200 String maxXS = req.getParameter("maxx"); |
203 String minYS = req.getParameter("miny"); | 201 String minYS = req.getParameter("miny"); |
204 String maxYS = req.getParameter("maxy"); | 202 String maxYS = req.getParameter("maxy"); |
205 | 203 |
206 if (minXS == null || maxXS == null | 204 Double minX = null; |
207 || minYS == null || maxYS == null) { | 205 Double maxX = null; |
208 throw new ServletException("Missing minX, minY, maxX or maxY"); | 206 Double minY = null; |
209 } | 207 Double maxY = null; |
210 | 208 |
211 double minX, maxX, minY, maxY; | 209 if (minXS != null && maxXS != null |
212 | 210 && minYS != null && maxYS == null) { |
213 try { | 211 try { |
214 minX = Double.parseDouble(minXS); | 212 minX = Double.parseDouble(minXS); |
215 minY = Double.parseDouble(minYS); | 213 minY = Double.parseDouble(minYS); |
216 maxX = Double.parseDouble(maxXS); | 214 maxX = Double.parseDouble(maxXS); |
217 maxY = Double.parseDouble(maxYS); | 215 maxY = Double.parseDouble(maxYS); |
218 } | 216 } |
219 catch (NumberFormatException nfe) { | 217 catch (NumberFormatException nfe) { |
220 throw new ServletException("Misspelled minX, minY, maxX or maxY"); | 218 throw new ServletException("Misspelled minX, minY, maxX or maxY"); |
219 } | |
221 } | 220 } |
222 | 221 |
223 String mapType = req.getParameter("maptype"); | 222 String mapType = req.getParameter("maptype"); |
224 | 223 |
225 if (mapType == null || !mapType.equals("map")) { | 224 if (mapType == null || !mapType.equals("floodmap")) { |
226 mapType = "floodmap"; | 225 mapType = "map"; |
227 } | 226 } |
228 | 227 |
229 String url = getURL(); | 228 String url = getURL(); |
230 | 229 |
231 Document requestOut = | 230 Document requestOut = |
238 Document descDocument; | 237 Document descDocument; |
239 | 238 |
240 try { | 239 try { |
241 HttpClient client = new HttpClientImpl(url); | 240 HttpClient client = new HttpClientImpl(url); |
242 | 241 |
242 descDocument = (Document)client.doCollectionAction( | |
243 requestDesc, uuid, new DocumentResponseHandler()); | |
244 | |
243 InputStream is = client.collectionOut( | 245 InputStream is = client.collectionOut( |
244 requestOut, uuid, mapType); | 246 requestOut, uuid, mapType); |
245 | 247 |
246 try { | 248 try { |
247 outDocument = XMLUtils.parseDocument(is); | 249 outDocument = XMLUtils.parseDocument(is); |
249 finally { | 251 finally { |
250 is.close(); | 252 is.close(); |
251 is = null; | 253 is = null; |
252 } | 254 } |
253 | 255 |
254 descDocument = (Document)client.doCollectionAction( | |
255 requestDesc, uuid, new DocumentResponseHandler()); | |
256 } | 256 } |
257 catch (ConnectionException ce) { | 257 catch (ConnectionException ce) { |
258 log.error(ce); | 258 log.error(ce); |
259 throw new ServletException(ce); | 259 throw new ServletException(ce); |
260 } | 260 } |
261 | 261 |
262 MapConfig mapConfig = MapHelper.parseConfig(outDocument); | |
263 | |
264 if (minX == null) { | |
265 String [] parts = mapConfig.getMaxExtent().split("\\s+"); | |
266 if (parts.length < 4) { | |
267 throw new ServletException( | |
268 "Max extent has less than 4 values"); | |
269 } | |
270 try { | |
271 minX = Double.valueOf(parts[0]); | |
272 minY = Double.valueOf(parts[1]); | |
273 maxX = Double.valueOf(parts[2]); | |
274 maxY = Double.valueOf(parts[3]); | |
275 } | |
276 catch (NumberFormatException nfe) { | |
277 throw new ServletException(nfe); | |
278 } | |
279 } | |
280 | |
262 String spec = generateSpec( | 281 String spec = generateSpec( |
263 descDocument, | 282 descDocument, |
264 outDocument, | 283 mapConfig, |
265 minX, minY, | 284 minX, minY, |
266 maxX, maxY); | 285 maxX, maxY); |
267 | 286 |
268 if (log.isDebugEnabled()) { | 287 if (log.isDebugEnabled()) { |
269 log.debug(spec); | 288 log.debug(spec); |