aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-01-29 10:52:20 +0100
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2014-01-29 10:52:20 +0100
commit09dfbe9ba1b1f4469044b4bf1004df3740a8ae9d (patch)
tree0d37508fc6589573f899545b73c75c51c01dddab
parent13d3597a1455ce5df41ee3ea3285f22768d4bc44 (diff)
downloadpdf-as-4-09dfbe9ba1b1f4469044b4bf1004df3740a8ae9d.tar.gz
pdf-as-4-09dfbe9ba1b1f4469044b4bf1004df3740a8ae9d.tar.bz2
pdf-as-4-09dfbe9ba1b1f4469044b4bf1004df3740a8ae9d.zip
Added resource templates for default pages
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/helper/PdfAsHelper.java12
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ErrorPage.java31
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/ProvidePDFServlet.java19
-rw-r--r--pdf-as-web/src/main/resources/template_error.html11
-rw-r--r--pdf-as-web/src/main/resources/template_provide.html9
-rw-r--r--pdf-as-web/src/main/webapp/WEB-INF/decorators/default_layout.jsp6
6 files changed, 61 insertions, 27 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();
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 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html lang="de">
+<head>
+<title>Error Page</title>
+</head>
+<body>
+Error Page:
+<p>##ERROR_MESSAGE##</p>
+<p>##ERROR_STACK##</p>
+</body>
+</html>
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 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html lang="de">
+<head>
+<title>Provide PDF</title>
+</head>
+<body>
+PDF ready @: <a href="##PDFDATAURL##">here</a>
+</body>
+</html>
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 @@
<decorator:head></decorator:head>
</head>
-<body>
+<body onload="<decorator:getProperty property="body.onload" />">
<p>
<h3>PDF-Signatur</h3>
</p>
@@ -24,9 +24,5 @@
<p>
<decorator:body></decorator:body>
</p>
-
- <p>
- <p>&copy; EGIZ 2014</p>
- </p>
</body>
</html> \ No newline at end of file