/** To get (in JSON) the information about the available formats and CO. */ protected void getInfo(HttpServletRequest req, HttpServletResponse resp, String basePath) throws ServletException, IOException { app = req.getParameter("app"); // System.out.println("app = "+app); MapPrinter printer = getMapPrinter(app); resp.setContentType("application/json; charset=utf-8"); final PrintWriter writer = resp.getWriter(); try { final String var = req.getParameter("var"); if (var != null) { writer.print(var + "="); } JSONWriter json = new JSONWriter(writer); try { json.object(); { printer.printClientConfig(json); String urlToUseInSpec = basePath; String proxyUrl = printer.getConfig().getProxyBaseUrl(); if (proxyUrl != null) { urlToUseInSpec = proxyUrl; } json.key("printURL").value(urlToUseInSpec + PRINT_URL); json.key("createURL").value(urlToUseInSpec + CREATE_URL); if (app != null) { json.key("app").value(app); } } json.endObject(); } catch (JSONException e) { throw new ServletException(e); } if (var != null) { writer.print(";"); } } finally { writer.close(); if (app == null && printer != null) { printer.stop(); } } }
/** copy the PDF into the output stream */ protected void sendPdfFile( HttpServletResponse httpServletResponse, TempFile tempFile, boolean inline) throws IOException, ServletException { FileInputStream pdf = new FileInputStream(tempFile); final OutputStream response = httpServletResponse.getOutputStream(); MapPrinter mapPrinter = getMapPrinter(app); try { httpServletResponse.setContentType(tempFile.contentType()); if (!inline) { final String fileName = tempFile.getOutputFileName(mapPrinter); httpServletResponse.setHeader("Content-disposition", "attachment; filename=" + fileName); } FileUtilities.copyStream(pdf, response); } finally { try { pdf.close(); } finally { response.close(); } if (app == null && mapPrinter != null) { mapPrinter.stop(); } } }