Mercurial > dive4elements > river
diff flys-client/src/main/java/de/intevation/flys/client/server/ChartOutputServiceImpl.java @ 1344:51d4b51a51ed
Added icons to export chart as PNG, PDF and SVG to the ChartToolbar.
flys-client/trunk@2998 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 17 Oct 2011 17:33:27 +0000 |
parents | e74bf6bfeeb6 |
children | ab8eb2f544f2 |
line wrap: on
line diff
--- a/flys-client/src/main/java/de/intevation/flys/client/server/ChartOutputServiceImpl.java Mon Oct 17 17:28:24 2011 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/server/ChartOutputServiceImpl.java Mon Oct 17 17:33:27 2011 +0000 @@ -38,6 +38,8 @@ String type = req.getParameter("type"); String locale = req.getParameter("locale"); + prepareHeader(req, resp); + Document request = ClientProtocolUtils.newOutCollectionDocument( uuid, type, type, ChartServiceHelper.getChartAttributes(prepareChartAttributes(req))); @@ -70,8 +72,60 @@ attr.put("maxx", req.getParameter("maxx")); attr.put("miny", req.getParameter("miny")); attr.put("maxy", req.getParameter("maxy")); + attr.put("format", req.getParameter("format")); return attr; } + + + protected void prepareHeader( + HttpServletRequest req, + HttpServletResponse resp + ) { + String export = req.getParameter("export"); + + if (export != null && export.equals("true")) { + String format = req.getParameter("format"); + + if (format == null || format.length() == 0) { + format = "png"; + } + + String fn = "chart_export" + getFileExtension(format); + + resp.setHeader("Content-Disposition", "attachment;filename=" + fn); + resp.setHeader("Content-Type", getMimeType(format)); + } + } + + + protected String getFileExtension(String format) { + if (format.equals("png")) { + return ".png"; + } + else if (format.equals("pdf")) { + return ".pdf"; + } + else if (format.equals("svg")) { + return ".svg"; + } + + return ".png"; + } + + + protected String getMimeType(String format) { + if (format.equals("png")) { + return "image/png"; + } + else if (format.equals("pdf")) { + return "application/pdf"; + } + else if (format.equals("svg")) { + return "svg+xml"; + } + + return "image/png"; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :