annotate flys-client/src/main/java/de/intevation/flys/client/server/MapPrintServiceImpl.java @ 5769:eef5484e5846

Added i18n strings for morhologic width in datacage.
author Raimund Renkert <rrenkert@intevation.de>
date Thu, 18 Apr 2013 14:19:23 +0200
parents b6f8fd50269b
children
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;
4433
5b8919ef601d Backed out changeset e8a4d2fd25cc
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4424
diff changeset
14
4436
9fca4d60fb7c Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4433
diff changeset
15 import java.io.IOException;
9fca4d60fb7c Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4433
diff changeset
16 import java.io.InputStream;
9fca4d60fb7c Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4433
diff changeset
17 import java.io.OutputStream;
9fca4d60fb7c Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4433
diff changeset
18 import java.io.UnsupportedEncodingException;
9fca4d60fb7c Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4433
diff changeset
19 import java.net.URLEncoder;
9fca4d60fb7c Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4433
diff changeset
20 import java.util.ArrayList;
9fca4d60fb7c Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4433
diff changeset
21 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
22 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
23 import java.util.HashMap;
4436
9fca4d60fb7c Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4433
diff changeset
24 import java.util.LinkedHashMap;
9fca4d60fb7c Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4433
diff changeset
25 import java.util.List;
9fca4d60fb7c Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4433
diff changeset
26 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
27
4436
9fca4d60fb7c Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4433
diff changeset
28 import javax.servlet.ServletException;
9fca4d60fb7c Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4433
diff changeset
29 import javax.servlet.http.HttpServlet;
9fca4d60fb7c Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4433
diff changeset
30 import javax.servlet.http.HttpServletRequest;
9fca4d60fb7c Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4433
diff changeset
31 import javax.servlet.http.HttpServletResponse;
9fca4d60fb7c Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4433
diff changeset
32
9fca4d60fb7c Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4433
diff changeset
33 import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
9fca4d60fb7c Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4433
diff changeset
34 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
35 import org.apache.log4j.Logger;
9fca4d60fb7c Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4433
diff changeset
36 import org.w3c.dom.Document;
9fca4d60fb7c Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4433
diff changeset
37 import org.w3c.dom.Element;
9fca4d60fb7c Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4433
diff changeset
38 import org.w3c.dom.NodeList;
4433
5b8919ef601d Backed out changeset e8a4d2fd25cc
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4424
diff changeset
39 /*
5b8919ef601d Backed out changeset e8a4d2fd25cc
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4424
diff changeset
40 import java.io.BufferedInputStream;
5b8919ef601d Backed out changeset e8a4d2fd25cc
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4424
diff changeset
41 import java.io.BufferedOutputStream;
5b8919ef601d Backed out changeset e8a4d2fd25cc
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4424
diff changeset
42 import java.io.File;
5b8919ef601d Backed out changeset e8a4d2fd25cc
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4424
diff changeset
43 import java.io.FileInputStream;
5b8919ef601d Backed out changeset e8a4d2fd25cc
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4424
diff changeset
44 import java.io.FileOutputStream;
5b8919ef601d Backed out changeset e8a4d2fd25cc
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4424
diff changeset
45 */
2519
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
46 /* 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
47 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
48 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
49 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
50
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 import org.mapfish.print.utils.PJsonObject;
2905
51ed89b754ae FLYS client: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2519
diff changeset
52 */
2502
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
53
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 public class MapPrintServiceImpl
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
55 extends HttpServlet
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
56 {
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
57 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
58 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
59
2506
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
60 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
61
2506
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
62 protected int pos;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
63 protected String url;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
64 protected String layers;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
65 protected String description;
2504
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
66
2506
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
67 public Layer() {
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
68 }
2504
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
69
2506
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
70 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
71
2506
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
72 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
73 String parentName = parent.getAttribute("name");
2905
51ed89b754ae FLYS client: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2519
diff changeset
74 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
75 || parentName.equals("floodmap"))) {
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
76 return false;
2504
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
77 }
2506
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
78
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
79 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
80
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
81 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
82 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
83
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
84 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
85 return false;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
86 }
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 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
89 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
90 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
91
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
92 try {
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
93 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
94 }
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
95 catch (NumberFormatException nfe) {
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
96 return false;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
97 }
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 return true;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
100 }
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 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
103 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
104
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
105 layer.put("type", "WMS");
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
106 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
107 subLayers.add(layers);
2504
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
108 layer.put("layers", subLayers);
5676
f8409fbe3b88 Request maps from osm.intevation.de by another url and fix dpi handling
Andre Heinecke <aheinecke@intevation.de>
parents: 5622
diff changeset
109 // XXX: osm.intevation.de mapache only offers low dpi maps
f8409fbe3b88 Request maps from osm.intevation.de by another url and fix dpi handling
Andre Heinecke <aheinecke@intevation.de>
parents: 5622
diff changeset
110 // so we need to use the uncached service
f8409fbe3b88 Request maps from osm.intevation.de by another url and fix dpi handling
Andre Heinecke <aheinecke@intevation.de>
parents: 5622
diff changeset
111 layer.put("baseURL", url.replace("http://osm.intevation.de/mapcache/?",
f8409fbe3b88 Request maps from osm.intevation.de by another url and fix dpi handling
Andre Heinecke <aheinecke@intevation.de>
parents: 5622
diff changeset
112 "http://osm.intevation.de/cgi-bin/germany.fcgi?"));
2506
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
113 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
114
2506
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
115 return layer;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
116 }
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
117
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
118 @Override
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
119 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
120 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
121 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
122 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
123 }
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
124 } // class Layer
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
125
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
126 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
127 Document descDocument,
2508
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
128 MapConfig mapConfig,
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
129 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
130 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
131 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
132 ) {
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
133 Map<String, Object> spec = new LinkedHashMap<String, Object>();
5676
f8409fbe3b88 Request maps from osm.intevation.de by another url and fix dpi handling
Andre Heinecke <aheinecke@intevation.de>
parents: 5622
diff changeset
134 int dpi = 254;
4969
555fa2774d3c Map printing in landscape mode. Layout still buggy.
Christian Lins <christian.lins@intevation.de>
parents: 4525
diff changeset
135 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
136 spec.put("pageSize", "A4");
5676
f8409fbe3b88 Request maps from osm.intevation.de by another url and fix dpi handling
Andre Heinecke <aheinecke@intevation.de>
parents: 5622
diff changeset
137 spec.put("landscape", "true");
2506
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
138 spec.put("srs", "EPSG:" + mapConfig.getSrid());
5676
f8409fbe3b88 Request maps from osm.intevation.de by another url and fix dpi handling
Andre Heinecke <aheinecke@intevation.de>
parents: 5622
diff changeset
139 spec.put("dpi", dpi);
2508
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
140 spec.put("units", "m");
2510
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
141 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
142 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
143
4474
bd78d2b0e309 Map print settings can now be configured via settings window.
Christian Lins <christian.lins@intevation.de>
parents: 4473
diff changeset
144 spec.putAll(pageSpecs);
bd78d2b0e309 Map print settings can now be configured via settings window.
Christian Lins <christian.lins@intevation.de>
parents: 4473
diff changeset
145
2506
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
146 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
147
2510
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
148 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
149 Layer l = new Layer();
2510
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
150
4472
dc7e41efd5ba Work (in progress) on a print settings dialog.
Christian Lins <christian.lins@intevation.de>
parents: 4436
diff changeset
151 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
152
dc7e41efd5ba Work (in progress) on a print settings dialog.
Christian Lins <christian.lins@intevation.de>
parents: 4436
diff changeset
153 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
154 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
155 if (l.setup(element)) {
dc7e41efd5ba Work (in progress) on a print settings dialog.
Christian Lins <christian.lins@intevation.de>
parents: 4436
diff changeset
156 ls.add(l);
dc7e41efd5ba Work (in progress) on a print settings dialog.
Christian Lins <christian.lins@intevation.de>
parents: 4436
diff changeset
157 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
158 }
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
159 }
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
160
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
161 // Establish Z order.
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
162 Collections.sort(ls);
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
163
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
164 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
165
2510
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
166 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
167 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
168 }
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
169
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
170 spec.put("layers", layers);
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
171 spec.put("name", "Name");
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 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
174
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 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
177
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
178 List<Object> bounds = new ArrayList<Object>(4);
2510
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
179 bounds.add(minX);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
180 bounds.add(minY);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
181 bounds.add(maxX);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
182 bounds.add(maxY);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
183 page.put("bbox", bounds);
2504
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
184
2510
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
185 /*
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
186 bounds.add(Double.valueOf((minX+maxX)*0.5));
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
187 bounds.add(Double.valueOf((minY+maxY)*0.5));
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
188
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
189 page.put("center", bounds);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
190 page.put("scale", Integer.valueOf(50000));
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
191 */
2504
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
192
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
193 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
194
4473
6db783627137 Map print does now submit additional parameters to MapPrintServiceImpl.
Christian Lins <christian.lins@intevation.de>
parents: 4472
diff changeset
195 // 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
196 page.putAll(pageSpecs);
4473
6db783627137 Map print does now submit additional parameters to MapPrintServiceImpl.
Christian Lins <christian.lins@intevation.de>
parents: 4472
diff changeset
197
2504
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
198 pages.add(page);
2510
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
199 spec.put("pages", pages);
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 List<Object> legends = new ArrayList<Object>(layers.size());
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
202
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
203 for (Layer layer: ls) {
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
204 Map<String, Object> legend = new LinkedHashMap<String, Object>();
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
205 List<Object> classes = new ArrayList<Object>(1);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
206 Map<String, Object> clazz = new LinkedHashMap<String, Object>();
5676
f8409fbe3b88 Request maps from osm.intevation.de by another url and fix dpi handling
Andre Heinecke <aheinecke@intevation.de>
parents: 5622
diff changeset
207 String lgu = MapUtils.getLegendGraphicUrl(layer.url, layer.layers, dpi);
2510
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
208 clazz.put("icon", lgu);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
209 clazz.put("name", layer.description);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
210 classes.add(clazz);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
211 legend.put("classes", classes);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
212 legend.put("name", layer.description);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
213 legends.add(legend);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
214 }
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
215
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
216 spec.put("legends", legends);
2504
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
217
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
218 return JSON.toJSONString(spec);
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
219 }
2502
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
220
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
221
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
222 @Override
2905
51ed89b754ae FLYS client: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2519
diff changeset
223 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
224 throws ServletException, IOException
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 log.info("MapPrintServiceImpl.doGet");
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 String uuid = req.getParameter("uuid");
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
229
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
230 if (uuid == null || !StringUtils.checkUUID(uuid)) {
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
231 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
232 }
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
233
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
234 String minXS = req.getParameter("minx");
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
235 String maxXS = req.getParameter("maxx");
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
236 String minYS = req.getParameter("miny");
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
237 String maxYS = req.getParameter("maxy");
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
238
2508
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
239 Double minX = null;
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
240 Double maxX = null;
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
241 Double minY = null;
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
242 Double maxY = null;
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
243
2508
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
244 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
245 && 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
246 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
247 try {
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
248 minX = Double.parseDouble(minXS);
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
249 minY = Double.parseDouble(minYS);
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
250 maxX = Double.parseDouble(maxXS);
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
251 maxY = Double.parseDouble(maxYS);
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
252 }
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
253 catch (NumberFormatException nfe) {
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
254 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
255 }
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
256 }
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
257
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
258 String mapType = req.getParameter("maptype");
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
259
2508
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
260 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
261 mapType = "map";
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
262 }
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
263
4473
6db783627137 Map print does now submit additional parameters to MapPrintServiceImpl.
Christian Lins <christian.lins@intevation.de>
parents: 4472
diff changeset
264 // 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
265 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
266 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
267 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
268 data.put("data", payload);
5677
413798463dfe Do ordering in the data dictionary and replace "null" strings with empty strings
Andre Heinecke <aheinecke@intevation.de>
parents: 5676
diff changeset
269 Enumeration paramNames = req.getParameterNames();
413798463dfe Do ordering in the data dictionary and replace "null" strings with empty strings
Andre Heinecke <aheinecke@intevation.de>
parents: 5676
diff changeset
270 List<String> params = Collections.list(paramNames);
413798463dfe Do ordering in the data dictionary and replace "null" strings with empty strings
Andre Heinecke <aheinecke@intevation.de>
parents: 5676
diff changeset
271 Collections.sort(params);
413798463dfe Do ordering in the data dictionary and replace "null" strings with empty strings
Andre Heinecke <aheinecke@intevation.de>
parents: 5676
diff changeset
272 for (String paramName : params) {
413798463dfe Do ordering in the data dictionary and replace "null" strings with empty strings
Andre Heinecke <aheinecke@intevation.de>
parents: 5676
diff changeset
273 if (paramName.startsWith("mapfish_data_")) {
413798463dfe Do ordering in the data dictionary and replace "null" strings with empty strings
Andre Heinecke <aheinecke@intevation.de>
parents: 5676
diff changeset
274 // You can add mapfish_data variables that will be mapped
5622
b28a6d05e969 Add a new mechanism in mapfish print call to add arbitary data maps
Andre Heinecke <aheinecke@intevation.de>
parents: 5620
diff changeset
275 // to a info value pairs to provide meta data for the map
5677
413798463dfe Do ordering in the data dictionary and replace "null" strings with empty strings
Andre Heinecke <aheinecke@intevation.de>
parents: 5676
diff changeset
276 // The the info part starts with a number for sorting that
413798463dfe Do ordering in the data dictionary and replace "null" strings with empty strings
Andre Heinecke <aheinecke@intevation.de>
parents: 5676
diff changeset
277 // number will be stripped
5622
b28a6d05e969 Add a new mechanism in mapfish print call to add arbitary data maps
Andre Heinecke <aheinecke@intevation.de>
parents: 5620
diff changeset
278 String paramValue = req.getParameter(paramName);
5677
413798463dfe Do ordering in the data dictionary and replace "null" strings with empty strings
Andre Heinecke <aheinecke@intevation.de>
parents: 5676
diff changeset
279 Map<String, Object> data3 = new HashMap<String, Object>();
413798463dfe Do ordering in the data dictionary and replace "null" strings with empty strings
Andre Heinecke <aheinecke@intevation.de>
parents: 5676
diff changeset
280 int order = 0;
413798463dfe Do ordering in the data dictionary and replace "null" strings with empty strings
Andre Heinecke <aheinecke@intevation.de>
parents: 5676
diff changeset
281 try {
413798463dfe Do ordering in the data dictionary and replace "null" strings with empty strings
Andre Heinecke <aheinecke@intevation.de>
parents: 5676
diff changeset
282 order = Integer.parseInt(paramName.substring(13, 14));
413798463dfe Do ordering in the data dictionary and replace "null" strings with empty strings
Andre Heinecke <aheinecke@intevation.de>
parents: 5676
diff changeset
283 data3.put("info", paramName.substring(14));
413798463dfe Do ordering in the data dictionary and replace "null" strings with empty strings
Andre Heinecke <aheinecke@intevation.de>
parents: 5676
diff changeset
284 } catch (NumberFormatException nfe) {
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 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
286 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
287 }
5677
413798463dfe Do ordering in the data dictionary and replace "null" strings with empty strings
Andre Heinecke <aheinecke@intevation.de>
parents: 5676
diff changeset
288 if (paramValue.equals("null"))
413798463dfe Do ordering in the data dictionary and replace "null" strings with empty strings
Andre Heinecke <aheinecke@intevation.de>
parents: 5676
diff changeset
289 data3.put("value", "");
413798463dfe Do ordering in the data dictionary and replace "null" strings with empty strings
Andre Heinecke <aheinecke@intevation.de>
parents: 5676
diff changeset
290 else
413798463dfe Do ordering in the data dictionary and replace "null" strings with empty strings
Andre Heinecke <aheinecke@intevation.de>
parents: 5676
diff changeset
291 data3.put("value", paramValue);
413798463dfe Do ordering in the data dictionary and replace "null" strings with empty strings
Andre Heinecke <aheinecke@intevation.de>
parents: 5676
diff changeset
292 payload.add(data3);
413798463dfe Do ordering in the data dictionary and replace "null" strings with empty strings
Andre Heinecke <aheinecke@intevation.de>
parents: 5676
diff changeset
293 } 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
294 String paramValue = req.getParameter(paramName);
5687
c4162d8378a1 Fix syntax error
Andre Heinecke <aheinecke@intevation.de>
parents: 5677
diff changeset
295 if (paramValue.equals("null"))
5677
413798463dfe Do ordering in the data dictionary and replace "null" strings with empty strings
Andre Heinecke <aheinecke@intevation.de>
parents: 5676
diff changeset
296 paramValue = "";
4474
bd78d2b0e309 Map print settings can now be configured via settings window.
Christian Lins <christian.lins@intevation.de>
parents: 4473
diff changeset
297 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
298 }
bd78d2b0e309 Map print settings can now be configured via settings window.
Christian Lins <christian.lins@intevation.de>
parents: 4473
diff changeset
299 }
5622
b28a6d05e969 Add a new mechanism in mapfish print call to add arbitary data maps
Andre Heinecke <aheinecke@intevation.de>
parents: 5620
diff changeset
300 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
301 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
302 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
303 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
304 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
305 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
306 }
4473
6db783627137 Map print does now submit additional parameters to MapPrintServiceImpl.
Christian Lins <christian.lins@intevation.de>
parents: 4472
diff changeset
307
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
308 String url = getURL();
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
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 Document requestOut =
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
311 ClientProtocolUtils.newOutCollectionDocument(
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
312 uuid, mapType, mapType);
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
313 Document requestDesc =
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
314 ClientProtocolUtils.newDescribeCollectionDocument(uuid);
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
315
2506
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
316 Document outDocument;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
317 Document descDocument;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
318
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
319 try {
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
320 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
321
2508
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
322 descDocument = (Document)client.doCollectionAction(
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
323 requestDesc, uuid, new DocumentResponseHandler());
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
324
2506
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
325 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
326 requestOut, uuid, mapType);
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
327
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
328 try {
2506
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
329 outDocument = XMLUtils.parseDocument(is);
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
330 }
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
331 finally {
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
332 is.close();
2506
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
333 is = null;
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
334 }
2506
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
335
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
336 }
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
337 catch (ConnectionException ce) {
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
338 log.error(ce);
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
339 throw new ServletException(ce);
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
340 }
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
341
2508
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
342 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
343
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
344 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
345 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
346 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
347 if (parts.length < 4) {
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
348 throw new ServletException(
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
349 "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
350 }
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
351 try {
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
352 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
353 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
354 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
355 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
356 }
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
357 catch (NumberFormatException nfe) {
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
358 throw new ServletException(nfe);
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
359 }
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
360 }
2510
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
361 if (log.isDebugEnabled()) {
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
362 log.debug("minX: " + minX);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
363 log.debug("maxX: " + maxX);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
364 log.debug("minY: " + minY);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
365 log.debug("maxY: " + maxY);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
366 }
2508
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
367
2504
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
368 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
369 descDocument,
2508
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
370 mapConfig,
2504
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
371 minX, minY,
4473
6db783627137 Map print does now submit additional parameters to MapPrintServiceImpl.
Christian Lins <christian.lins@intevation.de>
parents: 4472
diff changeset
372 maxX, maxY,
4474
bd78d2b0e309 Map print settings can now be configured via settings window.
Christian Lins <christian.lins@intevation.de>
parents: 4473
diff changeset
373 pageSpecs);
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
374
2504
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
375 if (log.isDebugEnabled()) {
2510
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
376 log.debug("Generated spec:");
2504
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
377 log.debug(spec);
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
378 //System.err.println(spec);
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
379 }
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
380
2504
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
381 producePDF(spec, resp);
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
382 }
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
383
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
384 protected String getURL() throws ServletException {
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
385 String url = getServletContext().getInitParameter("server-url");
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
386 if (url == null) {
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
387 throw new ServletException("Missing server-url");
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
388 }
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
389 return url;
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
390 }
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
391
2519
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
392 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
393 try {
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
394 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
395 }
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
396 catch (UnsupportedEncodingException usee) {
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
397 // Should not happen.
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
398 return s;
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
399 }
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
400 }
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
401
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
402 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
403 throws ServletException, IOException
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
404 {
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
405 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
406
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
407 if (printUrl == null) {
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
408 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
409 }
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
410
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
411 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
412
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
413 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
414 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
415 new MultiThreadedHttpConnectionManager());
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
416
4436
9fca4d60fb7c Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4433
diff changeset
417 // FIXME: The request is not authenticated.
9fca4d60fb7c Reintroduce wrongly outbacked changes (rev 4418-4425).
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 4433
diff changeset
418 // 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
419 // 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
420 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
421 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
422 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
423
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
424 if (in != null) {
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
425 try {
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
426 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
427 try {
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
428 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
429 int r;
5752
b6f8fd50269b Check for errors based on the return code instead of hackish parsing
Andre Heinecke <aheinecke@intevation.de>
parents: 5720
diff changeset
430 if (result < 200 || result >= 300) {
b6f8fd50269b Check for errors based on the return code instead of hackish parsing
Andre Heinecke <aheinecke@intevation.de>
parents: 5720
diff changeset
431 resp.setContentType("text/plain");
b6f8fd50269b Check for errors based on the return code instead of hackish parsing
Andre Heinecke <aheinecke@intevation.de>
parents: 5720
diff changeset
432 } else {
b6f8fd50269b Check for errors based on the return code instead of hackish parsing
Andre Heinecke <aheinecke@intevation.de>
parents: 5720
diff changeset
433 // Only send content disposition and filename content
b6f8fd50269b Check for errors based on the return code instead of hackish parsing
Andre Heinecke <aheinecke@intevation.de>
parents: 5720
diff changeset
434 // type when we have a pdf
b6f8fd50269b Check for errors based on the return code instead of hackish parsing
Andre Heinecke <aheinecke@intevation.de>
parents: 5720
diff changeset
435 resp.setHeader("Content-Disposition",
b6f8fd50269b Check for errors based on the return code instead of hackish parsing
Andre Heinecke <aheinecke@intevation.de>
parents: 5720
diff changeset
436 "attachment;filename=flys-karte.pdf");
b6f8fd50269b Check for errors based on the return code instead of hackish parsing
Andre Heinecke <aheinecke@intevation.de>
parents: 5720
diff changeset
437 resp.setContentType("application/pdf");
b6f8fd50269b Check for errors based on the return code instead of hackish parsing
Andre Heinecke <aheinecke@intevation.de>
parents: 5720
diff changeset
438 }
2519
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
439 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
440 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
441 }
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
442 out.flush();
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
443 }
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
444 finally {
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
445 out.close();
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
446 }
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
447 }
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
448 finally {
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
449 in.close();
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
450 }
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
451 }
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
452 }
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
453
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
454 /* 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
455
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
456 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
457 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
458 if (configPath == null) {
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
459 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
460 }
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
461
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
462 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
463 if (!configFile.isAbsolute()) {
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
464 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
465 }
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
466
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
467 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
468 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
469 }
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
470
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
471 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
472 }
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
473
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
474 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
475 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
476 {
2504
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
477 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
478
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
479 MapPrinter printer = getMapPrinter();
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
480
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
481 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
482 printer.getConfig(), jsonSpec);
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
483
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
484 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
485 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
486
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
487 // 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
488 // 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
489 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
490
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
491 try {
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
492 OutputStream out =
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
493 new BufferedOutputStream(
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
494 new FileOutputStream(tmpFile));
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
495 try {
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
496 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
497 out.flush();
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
498 }
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
499 catch (Exception e) {
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
500 log.error(e);
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
501 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
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 printer.stop();
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
505 out.close();
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 InputStream in =
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
508 new BufferedInputStream(
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
509 new FileInputStream(tmpFile));
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
510 out = resp.getOutputStream();
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
511 try {
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
512 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
513 int r;
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
514 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
515 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
516 }
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
517 out.flush();
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
518 }
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
519 finally {
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
520 in.close();
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
521 out.close();
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
522 }
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
523 }
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
524 finally {
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
525 if (tmpFile.exists()) {
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
526 tmpFile.delete();
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
527 }
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
528 }
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
529 }
2519
427df4e81af0 Call MapFish Printer via servlet to evade viral GPLv3.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2515
diff changeset
530 */
2502
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
531 }
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
532 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org