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/helper/PdfAsHelper.java | 12 +++++++++
.../at/gv/egiz/pdfas/web/servlets/ErrorPage.java | 31 ++++++++++++----------
.../egiz/pdfas/web/servlets/ProvidePDFServlet.java | 19 +++++++------
pdf-as-web/src/main/resources/template_error.html | 11 ++++++++
.../src/main/resources/template_provide.html | 9 +++++++
.../webapp/WEB-INF/decorators/default_layout.jsp | 6 +----
6 files changed, 61 insertions(+), 27 deletions(-)
create mode 100644 pdf-as-web/src/main/resources/template_error.html
create mode 100644 pdf-as-web/src/main/resources/template_provide.html
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("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();
diff --git a/pdf-as-web/src/main/resources/template_error.html b/pdf-as-web/src/main/resources/template_error.html
new file mode 100644
index 00000000..0371c568
--- /dev/null
+++ b/pdf-as-web/src/main/resources/template_error.html
@@ -0,0 +1,11 @@
+
+
+
+Error Page
+
+
+Error Page:
+##ERROR_MESSAGE##
+##ERROR_STACK##
+
+
diff --git a/pdf-as-web/src/main/resources/template_provide.html b/pdf-as-web/src/main/resources/template_provide.html
new file mode 100644
index 00000000..d0bb41ac
--- /dev/null
+++ b/pdf-as-web/src/main/resources/template_provide.html
@@ -0,0 +1,9 @@
+
+
+
+Provide PDF
+
+
+PDF ready @: here
+
+
diff --git a/pdf-as-web/src/main/webapp/WEB-INF/decorators/default_layout.jsp b/pdf-as-web/src/main/webapp/WEB-INF/decorators/default_layout.jsp
index 045fd2b9..9ed40e30 100644
--- a/pdf-as-web/src/main/webapp/WEB-INF/decorators/default_layout.jsp
+++ b/pdf-as-web/src/main/webapp/WEB-INF/decorators/default_layout.jsp
@@ -16,7 +16,7 @@
-
+">
PDF-Signatur
@@ -24,9 +24,5 @@
-
-
-
© EGIZ 2014
-
\ No newline at end of file
--
cgit v1.2.3