aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets
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 /pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets
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
Diffstat (limited to 'pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets')
-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
2 files changed, 28 insertions, 22 deletions
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();