Mercurial > dive4elements > river
annotate flys-client/src/main/java/de/intevation/flys/client/server/MapPrintServiceImpl.java @ 5622:b28a6d05e969
Add a new mechanism in mapfish print call to add arbitary data maps
Data properties are identified by starting with mapfish-data
and they are then split in info value pairs where info
can be the description of the information and value the value
of the information to be transported in the data map.
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Tue, 09 Apr 2013 19:04:32 +0200 |
parents | 6602be8ca685 |
children | f8409fbe3b88 |
rev | line source |
---|---|
2502
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.client.server; |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
2504
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
3 import de.intevation.artifacts.common.ArtifactNamespaceContext; |
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
4 import de.intevation.artifacts.common.utils.ClientProtocolUtils; |
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
5 import de.intevation.artifacts.common.utils.JSON; |
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
6 import de.intevation.artifacts.common.utils.StringUtils; |
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
7 import de.intevation.artifacts.common.utils.XMLUtils; |
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
8 import de.intevation.artifacts.httpclient.exceptions.ConnectionException; |
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
9 import de.intevation.artifacts.httpclient.http.HttpClient; |
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
10 import de.intevation.artifacts.httpclient.http.HttpClientImpl; |
2506
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
11 import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler; |
4436
9fca4d60fb7c
Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4433
diff
changeset
|
12 import de.intevation.flys.client.shared.MapUtils; |
9fca4d60fb7c
Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4433
diff
changeset
|
13 import de.intevation.flys.client.shared.model.MapConfig; |
5606
0d8564196d73
Break printing to rework the parametrization of the print job
Andre Heinecke <aheinecke@intevation.de>
parents:
5600
diff
changeset
|
14 import de.intevation.flys.client.client.FLYSConstants; |
4433
5b8919ef601d
Backed out changeset e8a4d2fd25cc
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4424
diff
changeset
|
15 |
4436
9fca4d60fb7c
Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4433
diff
changeset
|
16 import java.io.IOException; |
9fca4d60fb7c
Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4433
diff
changeset
|
17 import java.io.InputStream; |
9fca4d60fb7c
Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4433
diff
changeset
|
18 import java.io.OutputStream; |
9fca4d60fb7c
Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4433
diff
changeset
|
19 import java.io.UnsupportedEncodingException; |
9fca4d60fb7c
Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4433
diff
changeset
|
20 import java.net.URLEncoder; |
9fca4d60fb7c
Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4433
diff
changeset
|
21 import java.util.ArrayList; |
9fca4d60fb7c
Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4433
diff
changeset
|
22 import java.util.Collections; |
4474
bd78d2b0e309
Map print settings can now be configured via settings window.
Christian Lins <christian.lins@intevation.de>
parents:
4473
diff
changeset
|
23 import java.util.Enumeration; |
4473
6db783627137
Map print does now submit additional parameters to MapPrintServiceImpl.
Christian Lins <christian.lins@intevation.de>
parents:
4472
diff
changeset
|
24 import java.util.HashMap; |
4436
9fca4d60fb7c
Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4433
diff
changeset
|
25 import java.util.LinkedHashMap; |
9fca4d60fb7c
Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4433
diff
changeset
|
26 import java.util.List; |
9fca4d60fb7c
Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4433
diff
changeset
|
27 import java.util.Map; |
2506
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
28 |
4436
9fca4d60fb7c
Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4433
diff
changeset
|
29 import javax.servlet.ServletException; |
9fca4d60fb7c
Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4433
diff
changeset
|
30 import javax.servlet.http.HttpServlet; |
9fca4d60fb7c
Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4433
diff
changeset
|
31 import javax.servlet.http.HttpServletRequest; |
9fca4d60fb7c
Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4433
diff
changeset
|
32 import javax.servlet.http.HttpServletResponse; |
9fca4d60fb7c
Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4433
diff
changeset
|
33 |
9fca4d60fb7c
Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4433
diff
changeset
|
34 import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; |
9fca4d60fb7c
Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4433
diff
changeset
|
35 import org.apache.commons.httpclient.methods.GetMethod; |
9fca4d60fb7c
Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4433
diff
changeset
|
36 import org.apache.log4j.Logger; |
9fca4d60fb7c
Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4433
diff
changeset
|
37 import org.w3c.dom.Document; |
9fca4d60fb7c
Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4433
diff
changeset
|
38 import org.w3c.dom.Element; |
9fca4d60fb7c
Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4433
diff
changeset
|
39 import org.w3c.dom.NodeList; |
4433
5b8919ef601d
Backed out changeset e8a4d2fd25cc
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4424
diff
changeset
|
40 /* |
5b8919ef601d
Backed out changeset e8a4d2fd25cc
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4424
diff
changeset
|
41 import java.io.BufferedInputStream; |
5b8919ef601d
Backed out changeset e8a4d2fd25cc
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4424
diff
changeset
|
42 import java.io.BufferedOutputStream; |
5b8919ef601d
Backed out changeset e8a4d2fd25cc
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4424
diff
changeset
|
43 import java.io.File; |
5b8919ef601d
Backed out changeset e8a4d2fd25cc
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4424
diff
changeset
|
44 import java.io.FileInputStream; |
5b8919ef601d
Backed out changeset e8a4d2fd25cc
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4424
diff
changeset
|
45 import java.io.FileOutputStream; |
5b8919ef601d
Backed out changeset e8a4d2fd25cc
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4424
diff
changeset
|
46 */ |
2519
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
47 /* Used by direct API call. -> Enforce GPLv3 |
2502
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 import org.mapfish.print.MapPrinter; |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 import org.mapfish.print.output.OutputFactory; |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 import org.mapfish.print.output.OutputFormat; |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 import org.mapfish.print.utils.PJsonObject; |
2905
51ed89b754ae
FLYS client: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2519
diff
changeset
|
53 */ |
2502
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 public class MapPrintServiceImpl |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 extends HttpServlet |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 { |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 private static final Logger log = |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 Logger.getLogger(MapPrintServiceImpl.class); |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 |
2506
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
61 protected static class Layer implements Comparable<Layer> { |
2504
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
62 |
2506
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
63 protected int pos; |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
64 protected String url; |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
65 protected String layers; |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
66 protected String description; |
2504
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
67 |
2506
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
68 public Layer() { |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
69 } |
2504
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
70 |
2506
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
71 public boolean setup(Element element) { |
2504
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
72 |
2506
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
73 Element parent = (Element)element.getParentNode(); |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
74 String parentName = parent.getAttribute("name"); |
2905
51ed89b754ae
FLYS client: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2519
diff
changeset
|
75 if (!(parentName.equals("map") |
2506
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
76 || parentName.equals("floodmap"))) { |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
77 return false; |
2504
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
78 } |
2506
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
79 |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
80 String ns = ArtifactNamespaceContext.NAMESPACE_URI; |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
81 |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
82 String visible = element.getAttributeNS(ns, "visible"); |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
83 String active = element.getAttributeNS(ns, "active"); |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
84 |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
85 if (visible.equals("0") || active.equals("0")) { |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
86 return false; |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
87 } |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
88 |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
89 url = element.getAttributeNS(ns, "url"); |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
90 layers = element.getAttributeNS(ns, "layers"); |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
91 description = element.getAttributeNS(ns, "description"); |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
92 |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
93 try { |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
94 pos = Integer.parseInt(element.getAttributeNS(ns, "pos")); |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
95 } |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
96 catch (NumberFormatException nfe) { |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
97 return false; |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
98 } |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
99 |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
100 return true; |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
101 } |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
102 |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
103 public Map<String, Object> toMap() { |
2504
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
104 Map<String, Object> layer = new LinkedHashMap<String, Object>(); |
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
105 |
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
106 layer.put("type", "WMS"); |
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
107 List<Object> subLayers = new ArrayList<Object>(1); |
2506
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
108 subLayers.add(layers); |
2504
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
109 layer.put("layers", subLayers); |
2506
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
110 layer.put("baseURL", url); |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
111 layer.put("format", "image/png"); // TODO: Make configurable. |
2504
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
112 |
2506
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
113 return layer; |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
114 } |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
115 |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
116 @Override |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
117 public int compareTo(Layer other) { |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
118 int d = pos - other.pos; |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
119 if (d < 0) return -1; |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
120 return d > 0 ? +1 : 0; |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
121 } |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
122 } // class Layer |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
123 |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
124 protected static String generateSpec( |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
125 Document descDocument, |
2508
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
126 MapConfig mapConfig, |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
127 Double minX, Double minY, |
4473
6db783627137
Map print does now submit additional parameters to MapPrintServiceImpl.
Christian Lins <christian.lins@intevation.de>
parents:
4472
diff
changeset
|
128 Double maxX, Double maxY, |
4474
bd78d2b0e309
Map print settings can now be configured via settings window.
Christian Lins <christian.lins@intevation.de>
parents:
4473
diff
changeset
|
129 Map<String, Object> pageSpecs |
2506
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
130 ) { |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
131 Map<String, Object> spec = new LinkedHashMap<String, Object>(); |
4969
555fa2774d3c
Map printing in landscape mode. Layout still buggy.
Christian Lins <christian.lins@intevation.de>
parents:
4525
diff
changeset
|
132 spec.put("layout", "A4 landscape"); |
4474
bd78d2b0e309
Map print settings can now be configured via settings window.
Christian Lins <christian.lins@intevation.de>
parents:
4473
diff
changeset
|
133 spec.put("pageSize", "A4"); |
bd78d2b0e309
Map print settings can now be configured via settings window.
Christian Lins <christian.lins@intevation.de>
parents:
4473
diff
changeset
|
134 spec.put("landscape", "false"); |
2506
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
135 spec.put("title", "FLYS Druck"); |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
136 spec.put("srs", "EPSG:" + mapConfig.getSrid()); |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
137 spec.put("dpi", Integer.valueOf(254)); |
2508
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
138 spec.put("units", "m"); |
2510
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
139 spec.put("geodaetic", "true"); |
2506
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
140 spec.put("outputFormat", "pdf"); |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
141 |
4474
bd78d2b0e309
Map print settings can now be configured via settings window.
Christian Lins <christian.lins@intevation.de>
parents:
4473
diff
changeset
|
142 spec.putAll(pageSpecs); |
bd78d2b0e309
Map print settings can now be configured via settings window.
Christian Lins <christian.lins@intevation.de>
parents:
4473
diff
changeset
|
143 |
2506
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
144 String ns = ArtifactNamespaceContext.NAMESPACE_URI; |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
145 |
2510
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
146 List<Layer> ls = new ArrayList<Layer>(); |
4472
dc7e41efd5ba
Work (in progress) on a print settings dialog.
Christian Lins <christian.lins@intevation.de>
parents:
4436
diff
changeset
|
147 Layer l = new Layer(); |
2510
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
148 |
4472
dc7e41efd5ba
Work (in progress) on a print settings dialog.
Christian Lins <christian.lins@intevation.de>
parents:
4436
diff
changeset
|
149 NodeList facets = descDocument.getElementsByTagNameNS(ns, "facet"); |
dc7e41efd5ba
Work (in progress) on a print settings dialog.
Christian Lins <christian.lins@intevation.de>
parents:
4436
diff
changeset
|
150 |
dc7e41efd5ba
Work (in progress) on a print settings dialog.
Christian Lins <christian.lins@intevation.de>
parents:
4436
diff
changeset
|
151 for (int i = 0, N = facets.getLength(); i < N; ++i) { |
dc7e41efd5ba
Work (in progress) on a print settings dialog.
Christian Lins <christian.lins@intevation.de>
parents:
4436
diff
changeset
|
152 Element element = (Element)facets.item(i); |
dc7e41efd5ba
Work (in progress) on a print settings dialog.
Christian Lins <christian.lins@intevation.de>
parents:
4436
diff
changeset
|
153 if (l.setup(element)) { |
dc7e41efd5ba
Work (in progress) on a print settings dialog.
Christian Lins <christian.lins@intevation.de>
parents:
4436
diff
changeset
|
154 ls.add(l); |
dc7e41efd5ba
Work (in progress) on a print settings dialog.
Christian Lins <christian.lins@intevation.de>
parents:
4436
diff
changeset
|
155 l = new Layer(); |
2506
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
156 } |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
157 } |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
158 |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
159 // Establish Z order. |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
160 Collections.sort(ls); |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
161 |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
162 List<Object> layers = new ArrayList<Object>(ls.size()); |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
163 |
2510
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
164 for (int i = ls.size()-1; i >= 0; --i) { |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
165 layers.add(ls.get(i).toMap()); |
2504
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
166 } |
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
167 |
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
168 spec.put("layers", layers); |
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
169 spec.put("name", "Name"); |
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
170 |
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
171 List<Object> pages = new ArrayList<Object>(1); |
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
172 |
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
173 |
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
174 Map<String, Object> page = new LinkedHashMap<String, Object>(); |
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
175 |
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
176 List<Object> bounds = new ArrayList<Object>(4); |
2510
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
177 bounds.add(minX); |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
178 bounds.add(minY); |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
179 bounds.add(maxX); |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
180 bounds.add(maxY); |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
181 page.put("bbox", bounds); |
2504
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
182 |
2510
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
183 /* |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
184 bounds.add(Double.valueOf((minX+maxX)*0.5)); |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
185 bounds.add(Double.valueOf((minY+maxY)*0.5)); |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
186 |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
187 page.put("center", bounds); |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
188 page.put("scale", Integer.valueOf(50000)); |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
189 */ |
2504
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
190 |
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
191 page.put("rotation", Integer.valueOf(0)); |
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
192 |
4473
6db783627137
Map print does now submit additional parameters to MapPrintServiceImpl.
Christian Lins <christian.lins@intevation.de>
parents:
4472
diff
changeset
|
193 // This may overwrite default settings above |
4474
bd78d2b0e309
Map print settings can now be configured via settings window.
Christian Lins <christian.lins@intevation.de>
parents:
4473
diff
changeset
|
194 page.putAll(pageSpecs); |
4473
6db783627137
Map print does now submit additional parameters to MapPrintServiceImpl.
Christian Lins <christian.lins@intevation.de>
parents:
4472
diff
changeset
|
195 |
2504
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
196 pages.add(page); |
2510
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
197 spec.put("pages", pages); |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
198 |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
199 List<Object> legends = new ArrayList<Object>(layers.size()); |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
200 |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
201 for (Layer layer: ls) { |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
202 Map<String, Object> legend = new LinkedHashMap<String, Object>(); |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
203 List<Object> classes = new ArrayList<Object>(1); |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
204 Map<String, Object> clazz = new LinkedHashMap<String, Object>(); |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
205 String lgu = MapUtils.getLegendGraphicUrl(layer.url, layer.layers); |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
206 clazz.put("icon", lgu); |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
207 clazz.put("name", layer.description); |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
208 classes.add(clazz); |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
209 legend.put("classes", classes); |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
210 legend.put("name", layer.description); |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
211 legends.add(legend); |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
212 } |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
213 |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
214 spec.put("legends", legends); |
2504
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
215 |
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
216 return JSON.toJSONString(spec); |
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
217 } |
2502
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
218 |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
219 |
2503
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
220 @Override |
2905
51ed89b754ae
FLYS client: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2519
diff
changeset
|
221 public void doGet(HttpServletRequest req, HttpServletResponse resp) |
2503
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
222 throws ServletException, IOException |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
223 { |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
224 log.info("MapPrintServiceImpl.doGet"); |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
225 |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
226 String uuid = req.getParameter("uuid"); |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
227 |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
228 if (uuid == null || !StringUtils.checkUUID(uuid)) { |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
229 throw new ServletException("Missing or misspelled UUID"); |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
230 } |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
231 |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
232 String minXS = req.getParameter("minx"); |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
233 String maxXS = req.getParameter("maxx"); |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
234 String minYS = req.getParameter("miny"); |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
235 String maxYS = req.getParameter("maxy"); |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
236 |
2508
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
237 Double minX = null; |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
238 Double maxX = null; |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
239 Double minY = null; |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
240 Double maxY = null; |
2503
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
241 |
2508
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
242 if (minXS != null && maxXS != null |
2515
532c590beb3e
Fixed problem with selecting the wrong map scale for printing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2510
diff
changeset
|
243 && minYS != null && maxYS != null) { |
532c590beb3e
Fixed problem with selecting the wrong map scale for printing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2510
diff
changeset
|
244 log.debug("all parameters found -> parsing"); |
2508
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
245 try { |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
246 minX = Double.parseDouble(minXS); |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
247 minY = Double.parseDouble(minYS); |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
248 maxX = Double.parseDouble(maxXS); |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
249 maxY = Double.parseDouble(maxYS); |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
250 } |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
251 catch (NumberFormatException nfe) { |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
252 throw new ServletException("Misspelled minX, minY, maxX or maxY"); |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
253 } |
2503
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
254 } |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
255 |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
256 String mapType = req.getParameter("maptype"); |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
257 |
2508
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
258 if (mapType == null || !mapType.equals("floodmap")) { |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
259 mapType = "map"; |
2503
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
260 } |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
261 |
4473
6db783627137
Map print does now submit additional parameters to MapPrintServiceImpl.
Christian Lins <christian.lins@intevation.de>
parents:
4472
diff
changeset
|
262 // Retrieve print settings from request |
4474
bd78d2b0e309
Map print settings can now be configured via settings window.
Christian Lins <christian.lins@intevation.de>
parents:
4473
diff
changeset
|
263 Map<String, Object> pageSpecs = new HashMap<String, Object>(); |
5622
b28a6d05e969
Add a new mechanism in mapfish print call to add arbitary data maps
Andre Heinecke <aheinecke@intevation.de>
parents:
5620
diff
changeset
|
264 Map<String, Object> data = new HashMap<String, Object>(); |
b28a6d05e969
Add a new mechanism in mapfish print call to add arbitary data maps
Andre Heinecke <aheinecke@intevation.de>
parents:
5620
diff
changeset
|
265 List<Object> payload = new ArrayList<Object>(); |
b28a6d05e969
Add a new mechanism in mapfish print call to add arbitary data maps
Andre Heinecke <aheinecke@intevation.de>
parents:
5620
diff
changeset
|
266 data.put("data", payload); |
4474
bd78d2b0e309
Map print settings can now be configured via settings window.
Christian Lins <christian.lins@intevation.de>
parents:
4473
diff
changeset
|
267 Enumeration<String> paramNames = req.getParameterNames(); |
bd78d2b0e309
Map print settings can now be configured via settings window.
Christian Lins <christian.lins@intevation.de>
parents:
4473
diff
changeset
|
268 while (paramNames.hasMoreElements()) { |
bd78d2b0e309
Map print settings can now be configured via settings window.
Christian Lins <christian.lins@intevation.de>
parents:
4473
diff
changeset
|
269 String paramName = paramNames.nextElement(); |
5622
b28a6d05e969
Add a new mechanism in mapfish print call to add arbitary data maps
Andre Heinecke <aheinecke@intevation.de>
parents:
5620
diff
changeset
|
270 if (paramName.startsWith("mapfish-data-")) { |
b28a6d05e969
Add a new mechanism in mapfish print call to add arbitary data maps
Andre Heinecke <aheinecke@intevation.de>
parents:
5620
diff
changeset
|
271 // You can add mapfish-data variables that will be mapped |
b28a6d05e969
Add a new mechanism in mapfish print call to add arbitary data maps
Andre Heinecke <aheinecke@intevation.de>
parents:
5620
diff
changeset
|
272 // to a info value pairs to provide meta data for the map |
b28a6d05e969
Add a new mechanism in mapfish print call to add arbitary data maps
Andre Heinecke <aheinecke@intevation.de>
parents:
5620
diff
changeset
|
273 String paramValue = req.getParameter(paramName); |
b28a6d05e969
Add a new mechanism in mapfish print call to add arbitary data maps
Andre Heinecke <aheinecke@intevation.de>
parents:
5620
diff
changeset
|
274 if (paramValue != null && !paramValue.isEmpty()) { |
b28a6d05e969
Add a new mechanism in mapfish print call to add arbitary data maps
Andre Heinecke <aheinecke@intevation.de>
parents:
5620
diff
changeset
|
275 Map<String, Object> data3 = new HashMap<String, Object>(); |
b28a6d05e969
Add a new mechanism in mapfish print call to add arbitary data maps
Andre Heinecke <aheinecke@intevation.de>
parents:
5620
diff
changeset
|
276 data3.put("info", paramName.substring(13)); |
b28a6d05e969
Add a new mechanism in mapfish print call to add arbitary data maps
Andre Heinecke <aheinecke@intevation.de>
parents:
5620
diff
changeset
|
277 data3.put("value", paramValue); |
b28a6d05e969
Add a new mechanism in mapfish print call to add arbitary data maps
Andre Heinecke <aheinecke@intevation.de>
parents:
5620
diff
changeset
|
278 payload.add(data3); |
b28a6d05e969
Add a new mechanism in mapfish print call to add arbitary data maps
Andre Heinecke <aheinecke@intevation.de>
parents:
5620
diff
changeset
|
279 } |
b28a6d05e969
Add a new mechanism in mapfish print call to add arbitary data maps
Andre Heinecke <aheinecke@intevation.de>
parents:
5620
diff
changeset
|
280 } else if (paramName.startsWith("mapfish-")) { |
4474
bd78d2b0e309
Map print settings can now be configured via settings window.
Christian Lins <christian.lins@intevation.de>
parents:
4473
diff
changeset
|
281 String paramValue = req.getParameter(paramName); |
bd78d2b0e309
Map print settings can now be configured via settings window.
Christian Lins <christian.lins@intevation.de>
parents:
4473
diff
changeset
|
282 pageSpecs.put(paramName.substring(8), paramValue); |
bd78d2b0e309
Map print settings can now be configured via settings window.
Christian Lins <christian.lins@intevation.de>
parents:
4473
diff
changeset
|
283 } |
bd78d2b0e309
Map print settings can now be configured via settings window.
Christian Lins <christian.lins@intevation.de>
parents:
4473
diff
changeset
|
284 } |
5622
b28a6d05e969
Add a new mechanism in mapfish print call to add arbitary data maps
Andre Heinecke <aheinecke@intevation.de>
parents:
5620
diff
changeset
|
285 if (!payload.isEmpty()) { |
b28a6d05e969
Add a new mechanism in mapfish print call to add arbitary data maps
Andre Heinecke <aheinecke@intevation.de>
parents:
5620
diff
changeset
|
286 pageSpecs.put("data", data); |
b28a6d05e969
Add a new mechanism in mapfish print call to add arbitary data maps
Andre Heinecke <aheinecke@intevation.de>
parents:
5620
diff
changeset
|
287 List<Object> columns = new ArrayList<Object>(); |
b28a6d05e969
Add a new mechanism in mapfish print call to add arbitary data maps
Andre Heinecke <aheinecke@intevation.de>
parents:
5620
diff
changeset
|
288 columns.add("info"); |
b28a6d05e969
Add a new mechanism in mapfish print call to add arbitary data maps
Andre Heinecke <aheinecke@intevation.de>
parents:
5620
diff
changeset
|
289 columns.add("value"); |
b28a6d05e969
Add a new mechanism in mapfish print call to add arbitary data maps
Andre Heinecke <aheinecke@intevation.de>
parents:
5620
diff
changeset
|
290 data.put("columns", columns); |
b28a6d05e969
Add a new mechanism in mapfish print call to add arbitary data maps
Andre Heinecke <aheinecke@intevation.de>
parents:
5620
diff
changeset
|
291 } |
4473
6db783627137
Map print does now submit additional parameters to MapPrintServiceImpl.
Christian Lins <christian.lins@intevation.de>
parents:
4472
diff
changeset
|
292 |
2503
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
293 String url = getURL(); |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
294 |
2506
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
295 Document requestOut = |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
296 ClientProtocolUtils.newOutCollectionDocument( |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
297 uuid, mapType, mapType); |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
298 Document requestDesc = |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
299 ClientProtocolUtils.newDescribeCollectionDocument(uuid); |
2503
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
300 |
2506
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
301 Document outDocument; |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
302 Document descDocument; |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
303 |
2503
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
304 try { |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
305 HttpClient client = new HttpClientImpl(url); |
2506
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
306 |
2508
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
307 descDocument = (Document)client.doCollectionAction( |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
308 requestDesc, uuid, new DocumentResponseHandler()); |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
309 |
2506
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
310 InputStream is = client.collectionOut( |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
311 requestOut, uuid, mapType); |
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
312 |
2503
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
313 try { |
2506
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
314 outDocument = XMLUtils.parseDocument(is); |
2503
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
315 } |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
316 finally { |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
317 is.close(); |
2506
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
318 is = null; |
2503
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
319 } |
2506
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
320 |
2503
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
321 } |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
322 catch (ConnectionException ce) { |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
323 log.error(ce); |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
324 throw new ServletException(ce); |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
325 } |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
326 |
2508
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
327 MapConfig mapConfig = MapHelper.parseConfig(outDocument); |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
328 |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
329 if (minX == null) { |
2515
532c590beb3e
Fixed problem with selecting the wrong map scale for printing.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2510
diff
changeset
|
330 log.debug("parameters missing -> fallback to max extent"); |
2508
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
331 String [] parts = mapConfig.getMaxExtent().split("\\s+"); |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
332 if (parts.length < 4) { |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
333 throw new ServletException( |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
334 "Max extent has less than 4 values"); |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
335 } |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
336 try { |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
337 minX = Double.valueOf(parts[0]); |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
338 minY = Double.valueOf(parts[1]); |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
339 maxX = Double.valueOf(parts[2]); |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
340 maxY = Double.valueOf(parts[3]); |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
341 } |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
342 catch (NumberFormatException nfe) { |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
343 throw new ServletException(nfe); |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
344 } |
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
345 } |
2510
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
346 if (log.isDebugEnabled()) { |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
347 log.debug("minX: " + minX); |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
348 log.debug("maxX: " + maxX); |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
349 log.debug("minY: " + minY); |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
350 log.debug("maxY: " + maxY); |
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
351 } |
2508
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
352 |
2504
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
353 String spec = generateSpec( |
2506
47d07709ba09
Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2504
diff
changeset
|
354 descDocument, |
2508
4aa70825bde1
map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2506
diff
changeset
|
355 mapConfig, |
2504
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
356 minX, minY, |
4473
6db783627137
Map print does now submit additional parameters to MapPrintServiceImpl.
Christian Lins <christian.lins@intevation.de>
parents:
4472
diff
changeset
|
357 maxX, maxY, |
4474
bd78d2b0e309
Map print settings can now be configured via settings window.
Christian Lins <christian.lins@intevation.de>
parents:
4473
diff
changeset
|
358 pageSpecs); |
2503
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
359 |
2504
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
360 if (log.isDebugEnabled()) { |
2510
4861ab2c28d2
map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2508
diff
changeset
|
361 log.debug("Generated spec:"); |
2504
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
362 log.debug(spec); |
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
363 //System.err.println(spec); |
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
364 } |
2503
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
365 |
2504
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
366 producePDF(spec, resp); |
2503
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
367 } |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
368 |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
369 protected String getURL() throws ServletException { |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
370 String url = getServletContext().getInitParameter("server-url"); |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
371 if (url == null) { |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
372 throw new ServletException("Missing server-url"); |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
373 } |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
374 return url; |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
375 } |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
376 |
2519
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
377 private static final String encode(String s) { |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
378 try { |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
379 return URLEncoder.encode(s, "UTF-8"); |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
380 } |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
381 catch (UnsupportedEncodingException usee) { |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
382 // Should not happen. |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
383 return s; |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
384 } |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
385 } |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
386 |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
387 protected void producePDF(String json, HttpServletResponse resp) |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
388 throws ServletException, IOException |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
389 { |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
390 String printUrl = getInitParameter("print-url"); |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
391 |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
392 if (printUrl == null) { |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
393 throw new ServletException("Missing 'print-url' in web.xml"); |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
394 } |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
395 |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
396 String url = printUrl + "/print.pdf?spec=" + encode(json); |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
397 |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
398 org.apache.commons.httpclient.HttpClient client = |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
399 new org.apache.commons.httpclient.HttpClient( |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
400 new MultiThreadedHttpConnectionManager()); |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
401 |
4436
9fca4d60fb7c
Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4433
diff
changeset
|
402 // FIXME: The request is not authenticated. |
9fca4d60fb7c
Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4433
diff
changeset
|
403 // Currently this is not a problem because /flys/map-print |
9fca4d60fb7c
Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4433
diff
changeset
|
404 // is whitelisted in GGInAFilter. |
2519
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
405 GetMethod get = new GetMethod(url); |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
406 int result = client.executeMethod(get); |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
407 InputStream in = get.getResponseBodyAsStream(); |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
408 |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
409 if (in != null) { |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
410 try { |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
411 OutputStream out = resp.getOutputStream(); |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
412 try { |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
413 byte [] buf = new byte[4096]; |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
414 int r; |
5600
8128622e4b28
Set filename for the response
Andre Heinecke <aheinecke@intevation.de>
parents:
4969
diff
changeset
|
415 resp.setHeader("Content-Disposition", |
8128622e4b28
Set filename for the response
Andre Heinecke <aheinecke@intevation.de>
parents:
4969
diff
changeset
|
416 "attachment;filename=flys-karte.pdf"); |
5607
6e0d122904f9
Explicitly set the content type for the pdf download.
Andre Heinecke <aheinecke@intevation.de>
parents:
5606
diff
changeset
|
417 resp.setContentType("application/pdf"); |
2519
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
418 while ((r = in.read(buf)) >= 0) { |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
419 out.write(buf, 0, r); |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
420 } |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
421 out.flush(); |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
422 } |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
423 finally { |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
424 out.close(); |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
425 } |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
426 } |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
427 finally { |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
428 in.close(); |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
429 } |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
430 } |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
431 } |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
432 |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
433 /* Use this if you want directly call the MapPrinter. Enforces GPLv3! |
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
434 |
2503
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
435 protected MapPrinter getMapPrinter() throws ServletException, IOException { |
2502
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
436 String configPath = getInitParameter("config"); |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
437 if (configPath == null) { |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
438 throw new ServletException("Missing configuration in web.xml"); |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
439 } |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
440 |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
441 File configFile = new File(configPath); |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
442 if (!configFile.isAbsolute()) { |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
443 configFile = new File(getServletContext().getRealPath(configPath)); |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
444 } |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
445 |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
446 if (!configFile.isFile() || !configFile.canRead()) { |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
447 throw new ServletException("Cannot read '" + configFile + "'"); |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
448 } |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
449 |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
450 return new MapPrinter(configFile); |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
451 } |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
452 |
2503
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
453 protected void producePDF(String json, HttpServletResponse resp) |
e3bd1f412421
Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2502
diff
changeset
|
454 throws ServletException, IOException |
2502
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
455 { |
2504
425bc486a40f
Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2503
diff
changeset
|
456 PJsonObject jsonSpec = MapPrinter.parseSpec(json); |
2502
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
457 |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
458 MapPrinter printer = getMapPrinter(); |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
459 |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
460 OutputFormat outputFormat = OutputFactory.create( |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
461 printer.getConfig(), jsonSpec); |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
462 |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
463 resp.setHeader("Content-Disposition", "attachment;filename=print.pdf"); |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
464 resp.setHeader("Content-Type", "application/pdf"); |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
465 |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
466 // XXX: Streaming the generated PDF directly |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
467 // to the request out does not work. :-/ |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
468 File tmpFile = File.createTempFile("map-printing", null); |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
469 |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
470 try { |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
471 OutputStream out = |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
472 new BufferedOutputStream( |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
473 new FileOutputStream(tmpFile)); |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
474 try { |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
475 outputFormat.print(printer, jsonSpec, out, ""); |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
476 out.flush(); |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
477 } |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
478 catch (Exception e) { |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
479 log.error(e); |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
480 throw new ServletException(e); |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
481 } |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
482 finally { |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
483 printer.stop(); |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
484 out.close(); |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
485 } |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
486 InputStream in = |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
487 new BufferedInputStream( |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
488 new FileInputStream(tmpFile)); |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
489 out = resp.getOutputStream(); |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
490 try { |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
491 byte [] buf = new byte[4096]; |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
492 int r; |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
493 while ((r = in.read(buf)) >= 0) { |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
494 out.write(buf, 0, r); |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
495 } |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
496 out.flush(); |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
497 } |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
498 finally { |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
499 in.close(); |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
500 out.close(); |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
501 } |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
502 } |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
503 finally { |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
504 if (tmpFile.exists()) { |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
505 tmpFile.delete(); |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
506 } |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
507 } |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
508 } |
2519
427df4e81af0
Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2515
diff
changeset
|
509 */ |
2502
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
510 } |
328aa273ef3b
Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
511 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |