diff options
Diffstat (limited to 'pdf-as-web/src/main/java/at/gv')
3 files changed, 40 insertions, 22 deletions
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java index 1059738e..77c31c9a 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java @@ -437,6 +437,18 @@ public class PdfAsHelper { return xml; } + public static String getProvideTemplate() throws IOException { + String xml = FileUtils.readFileToString(FileUtils + .toFile(PdfAsHelper.class.getResource("/template_provide.html"))); + return xml; + } + + public static String getErrorTemplate() throws IOException { + String xml = FileUtils.readFileToString(FileUtils + .toFile(PdfAsHelper.class.getResource("/template_error.html"))); + return xml; + } + public static String getInvokeRedirectTemplateSL() throws IOException { String xml = FileUtils.readFileToString(FileUtils .toFile(PdfAsHelper.class.getResource("/template_invoke_redirect.html"))); diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ErrorPage.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ErrorPage.java index ef8e058f..68e143a3 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ErrorPage.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ErrorPage.java @@ -1,7 +1,6 @@ package at.gv.egiz.pdfas.web.servlets; import java.io.IOException; -import java.io.PrintWriter; import java.net.URLEncoder; import javax.servlet.ServletException; @@ -25,12 +24,14 @@ public class ErrorPage extends HttpServlet { private static final Logger logger = LoggerFactory .getLogger(ErrorPage.class); + private static final String ERROR_STACK = "##ERROR_STACK##"; + private static final String ERROR_MESSAGE = "##ERROR_MESSAGE##"; + /** * @see HttpServlet#HttpServlet() */ public ErrorPage() { super(); - // TODO Auto-generated constructor stub } /** @@ -84,24 +85,26 @@ public class ErrorPage extends HttpServlet { response.getWriter().write(template); response.getWriter().close(); } else { - if(!WebConfiguration.isProvidePdfURLinWhitelist(errorURL)) { + if(errorURL != null) { logger.warn(errorURL + " is not allowed by whitelist"); } - response.setContentType("text/html"); - PrintWriter pw = response.getWriter(); - - pw.write("<html><body>Error Page:"); + + String template = PdfAsHelper.getErrorTemplate(); if (message != null) { - pw.write("<p>" + message + "</p>"); + template = template.replace(ERROR_MESSAGE, message); + } else { + template = template.replace(ERROR_MESSAGE, "Unbekannter Fehler"); } - + if (e != null && WebConfiguration.isShowErrorDetails()) { - pw.write("<p>" - + HTMLFormater.formatStackTrace(e.getStackTrace()) - + "</p>"); + template = template.replace(ERROR_STACK, HTMLFormater.formatStackTrace(e.getStackTrace())); + } else { + template = template.replace(ERROR_STACK, ""); } - pw.write("</body></html>"); - pw.close(); + + response.setContentType("text/html"); + response.getWriter().write(template); + response.getWriter().close(); } } } diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ProvidePDFServlet.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ProvidePDFServlet.java index 194a9a63..0f949d1d 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ProvidePDFServlet.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ProvidePDFServlet.java @@ -2,12 +2,14 @@ package at.gv.egiz.pdfas.web.servlets; import java.io.IOException; import java.io.PrintWriter; +import java.net.URLEncoder; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.apache.http.client.utils.URLEncodedUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -24,6 +26,8 @@ public class ProvidePDFServlet extends HttpServlet { private static final Logger logger = LoggerFactory .getLogger(ProvidePDFServlet.class); + private static final String PDF_DATA_URL = "##PDFDATAURL##"; + /** * @see HttpServlet#HttpServlet() */ @@ -56,18 +60,16 @@ public class ProvidePDFServlet extends HttpServlet { if (invokeURL == null || WebConfiguration.isProvidePdfURLinWhitelist(invokeURL)) { - if(!WebConfiguration.isProvidePdfURLinWhitelist(invokeURL)) { + if(invokeURL != null) { logger.warn(invokeURL + " is not allowed by whitelist"); } + String template = PdfAsHelper.getProvideTemplate(); + template = template.replace(PDF_DATA_URL, PdfAsHelper.generatePdfURL(request, response)); // Deliver to Browser directly! response.setContentType("text/html"); - PrintWriter pw = response.getWriter(); - pw.write("<html><body>PDF ready @: <a href='" - + PdfAsHelper.generatePdfURL(request, response) - + "' download>here</a></body></html>"); - pw.close(); - + response.getWriter().write(template); + response.getWriter().close(); } else { // Redirect Browser String template = PdfAsHelper.getInvokeRedirectTemplateSL(); @@ -82,7 +84,8 @@ public class ProvidePDFServlet extends HttpServlet { } template = template.replace("##PDFURL##", - PdfAsHelper.generatePdfURL(request, response)); + URLEncoder.encode(PdfAsHelper.generatePdfURL(request, response), + "UTF-8")); response.setContentType("text/html"); response.getWriter().write(template); response.getWriter().close(); |