Mercurial > dive4elements > river
comparison flys-client/src/main/java/de/intevation/flys/client/server/MapPrintServiceImpl.java @ 2503:e3bd1f412421
Added GET parameters to map printer
flys-client/trunk@4348 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 04 May 2012 17:03:04 +0000 |
parents | 328aa273ef3b |
children | 425bc486a40f |
comparison
equal
deleted
inserted
replaced
2502:328aa273ef3b | 2503:e3bd1f412421 |
---|---|
21 | 21 |
22 import org.mapfish.print.output.OutputFactory; | 22 import org.mapfish.print.output.OutputFactory; |
23 import org.mapfish.print.output.OutputFormat; | 23 import org.mapfish.print.output.OutputFormat; |
24 | 24 |
25 import org.mapfish.print.utils.PJsonObject; | 25 import org.mapfish.print.utils.PJsonObject; |
26 | |
27 import de.intevation.artifacts.common.utils.StringUtils; | |
28 import de.intevation.artifacts.common.utils.XMLUtils; | |
29 import de.intevation.artifacts.common.utils.ClientProtocolUtils; | |
30 | |
31 import de.intevation.artifacts.httpclient.http.HttpClient; | |
32 import de.intevation.artifacts.httpclient.http.HttpClientImpl; | |
33 import de.intevation.artifacts.httpclient.exceptions.ConnectionException; | |
34 | |
35 import org.w3c.dom.Document; | |
36 | |
37 import de.intevation.flys.client.shared.model.MapConfig; | |
26 | 38 |
27 public class MapPrintServiceImpl | 39 public class MapPrintServiceImpl |
28 extends HttpServlet | 40 extends HttpServlet |
29 { | 41 { |
30 private static final Logger log = | 42 private static final Logger log = |
125 " }" + | 137 " }" + |
126 "]" + | 138 "]" + |
127 "}"; | 139 "}"; |
128 | 140 |
129 | 141 |
130 private MapPrinter getMapPrinter() throws ServletException, IOException { | |
131 String configPath = getInitParameter("config"); | |
132 if (configPath == null) { | |
133 throw new ServletException("Missing configuration in web.xml"); | |
134 } | |
135 | |
136 File configFile = new File(configPath); | |
137 if (!configFile.isAbsolute()) { | |
138 configFile = new File(getServletContext().getRealPath(configPath)); | |
139 } | |
140 | |
141 if (!configFile.isFile() || !configFile.canRead()) { | |
142 throw new ServletException("Cannot read '" + configFile + "'"); | |
143 } | |
144 | |
145 return new MapPrinter(configFile); | |
146 } | |
147 | |
148 @Override | 142 @Override |
149 public void doGet(HttpServletRequest req, HttpServletResponse resp) | 143 public void doGet(HttpServletRequest req, HttpServletResponse resp) |
150 throws ServletException, IOException | 144 throws ServletException, IOException |
151 { | 145 { |
152 log.info("MapPrintServiceImpl.doGet"); | 146 log.info("MapPrintServiceImpl.doGet"); |
153 | 147 |
148 String uuid = req.getParameter("uuid"); | |
149 | |
150 if (uuid == null || !StringUtils.checkUUID(uuid)) { | |
151 throw new ServletException("Missing or misspelled UUID"); | |
152 } | |
153 | |
154 String minXS = req.getParameter("minx"); | |
155 String maxXS = req.getParameter("maxx"); | |
156 String minYS = req.getParameter("miny"); | |
157 String maxYS = req.getParameter("maxy"); | |
158 | |
159 if (minXS == null || maxXS == null | |
160 || minYS == null || maxYS == null) { | |
161 throw new ServletException("Missing minX, minY, maxX or maxY"); | |
162 } | |
163 | |
164 double minX, maxX, minY, maxY; | |
165 | |
166 try { | |
167 minX = Double.parseDouble(minXS); | |
168 minY = Double.parseDouble(minYS); | |
169 maxX = Double.parseDouble(maxXS); | |
170 maxY = Double.parseDouble(maxYS); | |
171 } | |
172 catch (NumberFormatException nfe) { | |
173 throw new ServletException("Misspelled minX, minY, maxX or maxY"); | |
174 } | |
175 | |
176 String mapType = req.getParameter("maptype"); | |
177 | |
178 if (mapType == null || !mapType.equals("map")) { | |
179 mapType = "floodmap"; | |
180 } | |
181 | |
182 String url = getURL(); | |
183 | |
184 Document request = ClientProtocolUtils.newOutCollectionDocument( | |
185 uuid, mapType, mapType); | |
186 | |
187 Document result; | |
188 try { | |
189 HttpClient client = new HttpClientImpl(url); | |
190 InputStream is = client.collectionOut(request, uuid, mapType); | |
191 try { | |
192 result = XMLUtils.parseDocument(is); | |
193 } | |
194 finally { | |
195 is.close(); | |
196 } | |
197 } | |
198 catch (ConnectionException ce) { | |
199 log.error(ce); | |
200 throw new ServletException(ce); | |
201 } | |
202 | |
203 MapConfig mapConfig = MapHelper.parseConfig(result); | |
204 | |
205 System.err.println(XMLUtils.toString(result)); | |
206 | |
207 producePDF(DEMO_JSON, resp); | |
208 } | |
209 | |
210 protected String getURL() throws ServletException { | |
211 String url = getServletContext().getInitParameter("server-url"); | |
212 if (url == null) { | |
213 throw new ServletException("Missing server-url"); | |
214 } | |
215 return url; | |
216 } | |
217 | |
218 protected MapPrinter getMapPrinter() throws ServletException, IOException { | |
219 String configPath = getInitParameter("config"); | |
220 if (configPath == null) { | |
221 throw new ServletException("Missing configuration in web.xml"); | |
222 } | |
223 | |
224 File configFile = new File(configPath); | |
225 if (!configFile.isAbsolute()) { | |
226 configFile = new File(getServletContext().getRealPath(configPath)); | |
227 } | |
228 | |
229 if (!configFile.isFile() || !configFile.canRead()) { | |
230 throw new ServletException("Cannot read '" + configFile + "'"); | |
231 } | |
232 | |
233 return new MapPrinter(configFile); | |
234 } | |
235 | |
236 | |
237 protected void producePDF(String json, HttpServletResponse resp) | |
238 throws ServletException, IOException | |
239 { | |
154 PJsonObject jsonSpec = MapPrinter.parseSpec(DEMO_JSON); | 240 PJsonObject jsonSpec = MapPrinter.parseSpec(DEMO_JSON); |
155 | 241 |
156 MapPrinter printer = getMapPrinter(); | 242 MapPrinter printer = getMapPrinter(); |
157 | 243 |
158 OutputFormat outputFormat = OutputFactory.create( | 244 OutputFormat outputFormat = OutputFactory.create( |