From 09dfbe9ba1b1f4469044b4bf1004df3740a8ae9d Mon Sep 17 00:00:00 2001 From: Andreas Fitzek Date: Wed, 29 Jan 2014 10:52:20 +0100 Subject: Added resource templates for default pages --- .../at/gv/egiz/pdfas/web/servlets/ErrorPage.java | 31 ++++++++++++---------- .../egiz/pdfas/web/servlets/ProvidePDFServlet.java | 19 +++++++------ 2 files changed, 28 insertions(+), 22 deletions(-) (limited to 'pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets') 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("Error Page:"); + + String template = PdfAsHelper.getErrorTemplate(); if (message != null) { - pw.write("

" + message + "

"); + template = template.replace(ERROR_MESSAGE, message); + } else { + template = template.replace(ERROR_MESSAGE, "Unbekannter Fehler"); } - + if (e != null && WebConfiguration.isShowErrorDetails()) { - pw.write("

" - + HTMLFormater.formatStackTrace(e.getStackTrace()) - + "

"); + template = template.replace(ERROR_STACK, HTMLFormater.formatStackTrace(e.getStackTrace())); + } else { + template = template.replace(ERROR_STACK, ""); } - pw.write(""); - 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("PDF ready @: here"); - 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(); -- cgit v1.2.3