annotate flys-client/src/main/java/de/intevation/flys/client/server/MapPrintServiceImpl.java @ 2511:1aa6aec70b97

map print: Simplified config. flys-client/trunk@4366 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 09 May 2012 16:32:49 +0000
parents 4861ab2c28d2
children 532c590beb3e
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
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.ClientProtocolUtils;
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.JSON;
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.StringUtils;
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
8 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
9
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.exceptions.ConnectionException;
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
11
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
12 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
13 import de.intevation.artifacts.httpclient.http.HttpClientImpl;
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
14
2506
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
15 import de.intevation.artifacts.httpclient.http.response.DocumentResponseHandler;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
16
2504
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
17 import de.intevation.flys.client.shared.model.MapConfig;
2510
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
18 import de.intevation.flys.client.shared.MapUtils;
2504
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
19
2506
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
20 import java.io.BufferedInputStream;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
21 import java.io.BufferedOutputStream;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
22 import java.io.File;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
23 import java.io.FileInputStream;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
24 import java.io.FileOutputStream;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
25 import java.io.IOException;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
26 import java.io.InputStream;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
27 import java.io.OutputStream;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
28
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
29 import java.util.ArrayList;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
30 import java.util.Collections;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
31 import java.util.LinkedHashMap;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
32 import java.util.List;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
33 import java.util.Map;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
34
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
35 import javax.servlet.ServletException;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
36
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
37 import javax.servlet.http.HttpServlet;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
38 import javax.servlet.http.HttpServletRequest;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
39 import javax.servlet.http.HttpServletResponse;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
40
2502
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41 import org.apache.log4j.Logger;
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 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
44
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45 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
46 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
47
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.utils.PJsonObject;
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
50 import org.w3c.dom.Document;
2504
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
51 import org.w3c.dom.Element;
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
52 import org.w3c.dom.NodeList;
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
53
2502
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 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");
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
74 if (!(parentName.equals("map")
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);
2506
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
109 layer.put("baseURL", url);
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
110 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
111
2506
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
112 return layer;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
113 }
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
114
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
115 @Override
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
116 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
117 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
118 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
119 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
120 }
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
121 } // class Layer
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
122
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
123 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
124 Document descDocument,
2508
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
125 MapConfig mapConfig,
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
126 Double minX, Double minY,
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
127 Double maxX, Double maxY
2506
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
128 ) {
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
129 Map<String, Object> spec = new LinkedHashMap<String, Object>();
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
130 spec.put("layout", "A4 portrait");
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
131 spec.put("title", "FLYS Druck");
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
132 spec.put("srs", "EPSG:" + mapConfig.getSrid());
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
133 spec.put("dpi", Integer.valueOf(254));
2508
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
134 spec.put("units", "m");
2510
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
135 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
136 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
137
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
138 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
139
2510
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
140 List<Layer> ls = new ArrayList<Layer>();
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
141 { Layer l = new Layer();
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
142
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
143 NodeList facets = descDocument.getElementsByTagNameNS(ns, "facet");
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
144
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
145 for (int i = 0, N = facets.getLength(); i < N; ++i) {
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
146 Element element = (Element)facets.item(i);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
147 if (l.setup(element)) {
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
148 ls.add(l);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
149 l = new Layer();
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
150 }
2506
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
151 }
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
152 }
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
153
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
154 // Establish Z order.
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
155 Collections.sort(ls);
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
156
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
157 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
158
2510
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
159 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
160 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
161 }
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
162
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
163 spec.put("layers", layers);
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
164 spec.put("name", "Name");
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
165
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
166 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
167
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 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
170
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
171 List<Object> bounds = new ArrayList<Object>(4);
2510
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
172 bounds.add(minX);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
173 bounds.add(minY);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
174 bounds.add(maxX);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
175 bounds.add(maxY);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
176 page.put("bbox", bounds);
2504
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
177
2510
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
178 /*
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
179 bounds.add(Double.valueOf((minX+maxX)*0.5));
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
180 bounds.add(Double.valueOf((minY+maxY)*0.5));
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
181
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
182 page.put("center", bounds);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
183 page.put("scale", Integer.valueOf(50000));
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
184 */
2504
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
185
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
186 page.put("mapTitle", "FLYS Karte");
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
187 page.put("comment", "Eine mit FLYS gedruckte Karte.");
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
188 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
189
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
190 pages.add(page);
2510
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
191 spec.put("pages", pages);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
192
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
193 List<Object> legends = new ArrayList<Object>(layers.size());
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
194
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
195 for (Layer layer: ls) {
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
196 Map<String, Object> legend = new LinkedHashMap<String, Object>();
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
197 List<Object> classes = new ArrayList<Object>(1);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
198 Map<String, Object> clazz = new LinkedHashMap<String, Object>();
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
199 String lgu = MapUtils.getLegendGraphicUrl(layer.url, layer.layers);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
200 clazz.put("icon", lgu);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
201 clazz.put("name", layer.description);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
202 classes.add(clazz);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
203 legend.put("classes", classes);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
204 legend.put("name", layer.description);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
205 legends.add(legend);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
206 }
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
207
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
208 spec.put("legends", legends);
2504
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
209
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
210 return JSON.toJSONString(spec);
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
211 }
2502
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
212
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
213
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
214 @Override
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
215 public void doGet(HttpServletRequest req, HttpServletResponse resp)
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
216 throws ServletException, IOException
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
217 {
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
218 log.info("MapPrintServiceImpl.doGet");
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
219
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
220 String uuid = req.getParameter("uuid");
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
221
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
222 if (uuid == null || !StringUtils.checkUUID(uuid)) {
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
223 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
224 }
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
225
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
226 String minXS = req.getParameter("minx");
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
227 String maxXS = req.getParameter("maxx");
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
228 String minYS = req.getParameter("miny");
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
229 String maxYS = req.getParameter("maxy");
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
230
2508
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
231 Double minX = null;
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
232 Double maxX = null;
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
233 Double minY = null;
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
234 Double maxY = null;
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
235
2508
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
236 if (minXS != null && maxXS != null
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
237 && minYS != null && maxYS == null) {
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
238 try {
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
239 minX = Double.parseDouble(minXS);
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
240 minY = Double.parseDouble(minYS);
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
241 maxX = Double.parseDouble(maxXS);
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
242 maxY = Double.parseDouble(maxYS);
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
243 }
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
244 catch (NumberFormatException nfe) {
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
245 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
246 }
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
247 }
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
248
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
249 String mapType = req.getParameter("maptype");
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
250
2508
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
251 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
252 mapType = "map";
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
253 }
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
254
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
255 String url = getURL();
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
256
2506
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
257 Document requestOut =
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
258 ClientProtocolUtils.newOutCollectionDocument(
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
259 uuid, mapType, mapType);
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
260 Document requestDesc =
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
261 ClientProtocolUtils.newDescribeCollectionDocument(uuid);
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
262
2506
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
263 Document outDocument;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
264 Document descDocument;
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
265
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
266 try {
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
267 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
268
2508
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
269 descDocument = (Document)client.doCollectionAction(
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
270 requestDesc, uuid, new DocumentResponseHandler());
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
271
2506
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
272 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
273 requestOut, uuid, mapType);
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
274
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
275 try {
2506
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
276 outDocument = XMLUtils.parseDocument(is);
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
277 }
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
278 finally {
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
279 is.close();
2506
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
280 is = null;
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
281 }
2506
47d07709ba09 Printing: extract layer order and visibility from collections describe.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2504
diff changeset
282
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
283 }
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
284 catch (ConnectionException ce) {
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
285 log.error(ce);
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
286 throw new ServletException(ce);
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
287 }
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
288
2508
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
289 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
290
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
291 if (minX == null) {
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
292 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
293 if (parts.length < 4) {
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
294 throw new ServletException(
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
295 "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
296 }
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
297 try {
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
298 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
299 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
300 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
301 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
302 }
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
303 catch (NumberFormatException nfe) {
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
304 throw new ServletException(nfe);
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
305 }
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
306 }
2510
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
307 if (log.isDebugEnabled()) {
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
308 log.debug("minX: " + minX);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
309 log.debug("maxX: " + maxX);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
310 log.debug("minY: " + minY);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
311 log.debug("maxY: " + maxY);
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
312 }
2508
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
313
2504
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
314 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
315 descDocument,
2508
4aa70825bde1 map print: generate valid url to access service.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2506
diff changeset
316 mapConfig,
2504
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
317 minX, minY,
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
318 maxX, maxY);
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
319
2504
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
320 if (log.isDebugEnabled()) {
2510
4861ab2c28d2 map print: add legend
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2508
diff changeset
321 log.debug("Generated spec:");
2504
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
322 log.debug(spec);
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
323 //System.err.println(spec);
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
324 }
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
325
2504
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
326 producePDF(spec, resp);
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
327 }
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
328
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
329 protected String getURL() throws ServletException {
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
330 String url = getServletContext().getInitParameter("server-url");
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
331 if (url == null) {
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
332 throw new ServletException("Missing server-url");
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
333 }
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
334 return url;
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
335 }
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 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
338 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
339 if (configPath == null) {
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
340 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
341 }
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
342
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
343 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
344 if (!configFile.isAbsolute()) {
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
345 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
346 }
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
347
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
348 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
349 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
350 }
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
351
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
352 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
353 }
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
354
2503
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
355
e3bd1f412421 Added GET parameters to map printer
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2502
diff changeset
356 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
357 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
358 {
2504
425bc486a40f Generate map print spec dynamically from artifact
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2503
diff changeset
359 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
360
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
361 MapPrinter printer = getMapPrinter();
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
362
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
363 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
364 printer.getConfig(), jsonSpec);
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
365
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
366 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
367 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
368
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
369 // 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
370 // 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
371 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
372
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
373 try {
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
374 OutputStream out =
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
375 new BufferedOutputStream(
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
376 new FileOutputStream(tmpFile));
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
377 try {
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
378 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
379 out.flush();
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
380 }
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
381 catch (Exception e) {
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
382 log.error(e);
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
383 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
384 }
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
385 finally {
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
386 printer.stop();
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
387 out.close();
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
388 }
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
389 InputStream in =
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
390 new BufferedInputStream(
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
391 new FileInputStream(tmpFile));
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
392 out = resp.getOutputStream();
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
393 try {
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
394 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
395 int r;
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
396 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
397 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
398 }
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
399 out.flush();
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
400 }
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
401 finally {
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
402 in.close();
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
403 out.close();
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
404 }
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
405 }
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
406 finally {
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
407 if (tmpFile.exists()) {
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
408 tmpFile.delete();
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
409 }
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
410 }
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
411 }
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
412 }
328aa273ef3b Call MapPrinter directly and not via the MapFish Print servlet.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
413 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org