Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/server/ExportServiceImpl.java @ 5838:5aa05a7a34b7
Rename modules to more fitting names.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 15:23:37 +0200 |
parents | flys-client/src/main/java/org/dive4elements/river/client/server/ExportServiceImpl.java@821a02bbfb4e |
children | 172338b1407f |
comparison
equal
deleted
inserted
replaced
5837:d9901a08d0a6 | 5838:5aa05a7a34b7 |
---|---|
1 package org.dive4elements.river.client.server; | |
2 | |
3 import java.io.OutputStream; | |
4 import java.io.IOException; | |
5 | |
6 import org.w3c.dom.Document; | |
7 import org.w3c.dom.Element; | |
8 | |
9 import org.apache.log4j.Logger; | |
10 | |
11 import javax.servlet.http.HttpServlet; | |
12 import javax.servlet.http.HttpServletRequest; | |
13 import javax.servlet.http.HttpServletResponse; | |
14 | |
15 import org.dive4elements.artifacts.common.utils.ClientProtocolUtils; | |
16 import org.dive4elements.artifacts.common.utils.XMLUtils; | |
17 | |
18 import org.dive4elements.artifacts.httpclient.http.HttpClient; | |
19 import org.dive4elements.artifacts.httpclient.http.HttpClientImpl; | |
20 | |
21 | |
22 /** | |
23 * This service is used to request a data export from the artifact server. The | |
24 * response is directed directly to the output stream, so that a file dialog is | |
25 * opened. | |
26 * | |
27 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
28 */ | |
29 public class ExportServiceImpl | |
30 extends HttpServlet | |
31 { | |
32 private static final Logger logger = | |
33 Logger.getLogger(ExportServiceImpl.class); | |
34 | |
35 | |
36 public void doGet(HttpServletRequest req, HttpServletResponse resp) { | |
37 logger.info("ExportServiceImpl.doGet"); | |
38 | |
39 try { | |
40 OutputStream out = resp.getOutputStream(); | |
41 | |
42 String url = getServletContext().getInitParameter("server-url"); | |
43 String uuid = req.getParameter("uuid"); | |
44 String name = req.getParameter("name"); | |
45 String mode = req.getParameter("mode"); | |
46 String type = req.getParameter("type"); | |
47 String locale = req.getParameter("locale"); | |
48 String km = req.getParameter("km"); | |
49 String fn = name + "." + type; | |
50 | |
51 resp.setHeader("Content-Disposition", "attachment;filename=" + fn); | |
52 | |
53 if (logger.isDebugEnabled()) { | |
54 logger.debug("Request " + type + " export."); | |
55 } | |
56 | |
57 Document attr = null; | |
58 if (km != null && km.length() > 0) { | |
59 attr = XMLUtils.newDocument(); | |
60 XMLUtils.ElementCreator ec = | |
61 new XMLUtils.ElementCreator(attr, null, null); | |
62 Element e = ec.create("km"); | |
63 e.setTextContent(km); | |
64 attr.appendChild(e); | |
65 } | |
66 Document request = ClientProtocolUtils.newOutCollectionDocument( | |
67 uuid, mode, type, attr); | |
68 HttpClient client = new HttpClientImpl(url, locale); | |
69 client.collectionOut(request, uuid, mode, out); | |
70 | |
71 out.close(); | |
72 out.flush(); | |
73 } | |
74 catch (IOException ioe) { | |
75 logger.error(ioe, ioe); | |
76 } | |
77 } | |
78 } | |
79 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |