From d298630f92308c462a5b7ae37942f92dcc4d4d21 Mon Sep 17 00:00:00 2001 From: Christian Maierhofer Date: Tue, 29 Mar 2016 14:44:12 +0200 Subject: added signature block positioning --- simpleSigning/build.gradle | 2 +- .../at/gv/egiz/simpleSigning/StartSignature.java | 102 ++++++++++++++++++++- .../egiz/simpleSigning/helper/SessionHelper.java | 63 +++++++++++++ simpleSigning/src/main/resources/js/pdfas.js | 15 ++- simpleSigning/src/main/webapp/index.jsp | 36 +++++++- 5 files changed, 207 insertions(+), 11 deletions(-) diff --git a/simpleSigning/build.gradle b/simpleSigning/build.gradle index 573b09f..91f99fb 100644 --- a/simpleSigning/build.gradle +++ b/simpleSigning/build.gradle @@ -4,7 +4,7 @@ apply plugin: 'eclipse-wtp' apply plugin: 'war' sourceCompatibility = 1.7 -version = '1.2' +version = '1.3' war { manifest { diff --git a/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/StartSignature.java b/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/StartSignature.java index 70741ed..69f60d5 100644 --- a/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/StartSignature.java +++ b/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/StartSignature.java @@ -45,6 +45,12 @@ public class StartSignature extends HttpServlet { private static final String PARAM_QRCODE = "QRCODE"; private static final String PARAM_NEW = "NEW"; private static final String PARAM_NEW_V = "1"; + + private static final String PARAM_SIG_POS_X = "SIG_POS_X"; + private static final String PARAM_SIG_POS_Y = "SIG_POS_Y"; + private static final String PARAM_SIG_POS_P = "SIG_POS_P"; + private static final String PARAM_SIG_POS_W = "SIG_POS_W"; + private static final String PARAM_SIG_POS_F = "SIG_POS_F"; public StartSignature() { super(); @@ -138,6 +144,12 @@ public class StartSignature extends HttpServlet { String targetUrl = req.getParameter(PARAM_TARGETURL); String qrCodeData = req.getParameter(PARAM_QRCODE); String localeData = req.getParameter(PARAM_LOCALE); + + String sigPosX = req.getParameter(PARAM_SIG_POS_X); + String sigPosY = req.getParameter(PARAM_SIG_POS_Y); + String sigPosP = req.getParameter(PARAM_SIG_POS_P); + String sigPosW = req.getParameter(PARAM_SIG_POS_W); + String sigPosF = req.getParameter(PARAM_SIG_POS_F); // Step 1. Setup Parameters if (type != null) { @@ -200,6 +212,53 @@ public class StartSignature extends HttpServlet { } } + + //Position Params + if (sigPosX != null && !sigPosX.isEmpty()) { + if(isNumeric(sigPosX, req, resp)==false) + return; + // If we have a type set it + SessionHelper.setSigPosX(req, sigPosX); + + logger.trace("[" + req.getSession().getId() + + "]: setting SigPosX to: " + sigPosX); + } + if (sigPosY != null && !sigPosY.isEmpty()) { + if(isNumeric(sigPosY, req, resp)==false) + return; + // If we have a type set it + SessionHelper.setSigPosY(req, sigPosY); + + logger.trace("[" + req.getSession().getId() + + "]: setting SigPosY to: " + sigPosY); + } + if (sigPosP != null && !sigPosP.isEmpty()) { + if(isNumeric(sigPosP, req, resp)==false) + return; + // If we have a type set it + SessionHelper.setSigPosP(req, sigPosP); + + logger.trace("[" + req.getSession().getId() + + "]: setting SigPosP to: " + sigPosP); + } + if (sigPosW != null && !sigPosW.isEmpty()) { + if(isNumeric(sigPosW, req, resp)==false) + return; + // If we have a type set it + SessionHelper.setSigPosW(req, sigPosW); + + logger.trace("[" + req.getSession().getId() + + "]: setting SigPosW to: " + sigPosW); + } + if (sigPosF != null && !sigPosF.isEmpty()) { + if(isNumeric(sigPosF, req, resp)==false) + return; + // If we have a type set it + SessionHelper.setSigPosF(req, sigPosF); + + logger.trace("[" + req.getSession().getId() + + "]: setting SigPosF to: " + sigPosF); + } if ((SessionHelper.getContent(req) == null && SessionHelper .getDocument(req) == null) @@ -386,7 +445,27 @@ public class StartSignature extends HttpServlet { if (SessionHelper.getLocale(req) != null) { entry += ""; - } + } + if (SessionHelper.getSigPosX(req) != null){ + entry += ""; + } + if (SessionHelper.getSigPosY(req) != null){ + entry += ""; + } + if (SessionHelper.getSigPosP(req) != null){ + entry += ""; + } + if (SessionHelper.getSigPosW(req) != null){ + entry += ""; + } + if (SessionHelper.getSigPosF(req) != null){ + entry += ""; + } template = template.replace("##ADDITIONAL##", entry); @@ -415,4 +494,25 @@ public class StartSignature extends HttpServlet { .toError(req, resp, "Something went wrong", e.getMessage()); } } + + private static boolean isNumeric(String nr, HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException + { + try + { + Double.parseDouble(nr); + } + catch(NumberFormatException e) + { + logger.error("[" + + req.getSession().getId() + + "]: Failed to generate signature Data!: Position Parameter is not numeric"); + PDFHelper.toError(req, resp, + "Failed to get signature Data", + "Position Parameter is not numeric"); + return false; + + } + return true; + + } } diff --git a/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/helper/SessionHelper.java b/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/helper/SessionHelper.java index bc86da6..0d06a36 100644 --- a/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/helper/SessionHelper.java +++ b/simpleSigning/src/main/java/at/gv/egiz/simpleSigning/helper/SessionHelper.java @@ -22,6 +22,12 @@ public class SessionHelper { private static final String SESSION_TYPE_PDF = "PDF"; private static final String SESSION_TYPE_BASE64 = "B64"; + private static final String SESSION_SIG_POS_X = "SESSION_SIG_POS_X"; + private static final String SESSION_SIG_POS_Y = "SESSION_SIG_POS_Y"; + private static final String SESSION_SIG_POS_P = "SESSION_SIG_POS_P"; + private static final String SESSION_SIG_POS_W = "SESSION_SIG_POS_W"; + private static final String SESSION_SIG_POS_F = "SESSION_SIG_POS_F"; + private static final Logger logger = LoggerFactory .getLogger(SessionHelper.class); @@ -171,4 +177,61 @@ public class SessionHelper { logger.info("Killing Session: " + request.getSession().getId()); request.getSession().invalidate(); } + + public static void setSigPosX(HttpServletRequest request, String value) { + request.getSession().setAttribute(SESSION_SIG_POS_X, value); + } + public static void setSigPosY(HttpServletRequest request, String value) { + request.getSession().setAttribute(SESSION_SIG_POS_Y, value); + } + public static void setSigPosP(HttpServletRequest request, String value) { + request.getSession().setAttribute(SESSION_SIG_POS_P, value); + } + public static void setSigPosW(HttpServletRequest request, String value) { + request.getSession().setAttribute(SESSION_SIG_POS_W, value); + } + public static void setSigPosF(HttpServletRequest request, String value) { + request.getSession().setAttribute(SESSION_SIG_POS_F, value); + } + + public static String getSigPosX(HttpServletRequest request) { + Object s = request.getSession().getAttribute(SESSION_SIG_POS_X); + if (s != null) { + return s.toString(); + } else { + return null; + } + } + public static String getSigPosY(HttpServletRequest request) { + Object s = request.getSession().getAttribute(SESSION_SIG_POS_Y); + if (s != null) { + return s.toString(); + } else { + return null; + } + } + public static String getSigPosP(HttpServletRequest request) { + Object s = request.getSession().getAttribute(SESSION_SIG_POS_P); + if (s != null) { + return s.toString(); + } else { + return null; + } + } + public static String getSigPosW(HttpServletRequest request) { + Object s = request.getSession().getAttribute(SESSION_SIG_POS_W); + if (s != null) { + return s.toString(); + } else { + return null; + } + } + public static String getSigPosF(HttpServletRequest request) { + Object s = request.getSession().getAttribute(SESSION_SIG_POS_F); + if (s != null) { + return s.toString(); + } else { + return null; + } + } } diff --git a/simpleSigning/src/main/resources/js/pdfas.js b/simpleSigning/src/main/resources/js/pdfas.js index 2fd3f83..daae998 100644 --- a/simpleSigning/src/main/resources/js/pdfas.js +++ b/simpleSigning/src/main/resources/js/pdfas.js @@ -38,15 +38,15 @@ var pdfAs = {}; * @returns */ pdfAs.signText = function(content, error, success) { - this.createAsyncSignature(content.content, content.connector, content.uiId, pdfAsUrl, content.qrdata, content.locale, "TEXT", success, error); + this.createAsyncSignature(content.content, content.connector, content.uiId, pdfAsUrl, content.qrdata, content.locale, content.sig_pos_x, content.sig_pos_y, content.sig_pos_p, content.sig_pos_w, content.sig_pos_f, "TEXT", success, error); }; pdfAs.signPdf = function(content, error, success) { - this.createAsyncSignature(content.content, content.connector, content.uiId, pdfAsUrl, content.qrdata, content.locale, "PDF", success, error); + this.createAsyncSignature(content.content, content.connector, content.uiId, pdfAsUrl, content.qrdata, content.locale, content.sig_pos_x, content.sig_pos_y, content.sig_pos_p, content.sig_pos_w, content.sig_pos_f, "PDF", success, error); }; pdfAs.signPdfBase64 = function(content, error, success) { - this.createAsyncSignature(content.content, content.connector, content.uiId, pdfAsUrl, content.qrdata, content.locale, "B64", success, error); + this.createAsyncSignature(content.content, content.connector, content.uiId, pdfAsUrl, content.qrdata, content.locale, content.sig_pos_x, content.sig_pos_y, content.sig_pos_p, content.sig_pos_w, content.sig_pos_f, "B64", success, error); }; pdfAs.getVersion = function(cb, err) { @@ -139,7 +139,7 @@ pdfAs.autoResize = function(eventId, height, width){ } }; -pdfAs.createAsyncSignature = function(pdfUrl, connector, divID, pdfAsURL, qrcode, locale, type, success, error) { +pdfAs.createAsyncSignature = function(pdfUrl, connector, divID, pdfAsURL, qrcode, locale, sigPosX, sigPosY, sigPosP, sigPosW, sigPosF, type, success, error) { // generate EventID var eventId = guid(); @@ -151,7 +151,12 @@ pdfAs.createAsyncSignature = function(pdfUrl, connector, divID, pdfAsURL, qrcode TARGETURL: document.URL, NEW: "1", QRCODE: qrcode, - LOCALE: locale + LOCALE: locale, + SIG_POS_X: sigPosX, + SIG_POS_Y: sigPosY, + SIG_POS_P: sigPosP, + SIG_POS_W: sigPosW, + SIG_POS_F: sigPosF }; /*var querystring = encodeQueryData(parameters); diff --git a/simpleSigning/src/main/webapp/index.jsp b/simpleSigning/src/main/webapp/index.jsp index f1da513..1cb85cd 100644 --- a/simpleSigning/src/main/webapp/index.jsp +++ b/simpleSigning/src/main/webapp/index.jsp @@ -155,6 +155,13 @@ var op = { content : valueContent }; + + op.sig_pos_x = document.getElementById("sig-pos-x").value; + op.sig_pos_y = document.getElementById("sig-pos-y").value; + op.sig_pos_p = document.getElementById("sig-pos-p").value; + op.sig_pos_w = document.getElementById("sig-pos-w").value; + op.sig_pos_f = document.getElementById("sig-pos-f").value; + var dispOption = document.getElementById("disp"); @@ -268,6 +275,13 @@ +
+
+
+
+
+ +
@@ -313,10 +327,18 @@ der lokalen BKU, "onlinebku" -> Signatur mit der online BKU, "mobilebku" -> Signatur mit der Handy Signatur
-     uiId: "exampleDiv" // Diese Eigenschaft +     uiId: "exampleDiv", // Diese Eigenschaft ist optional, wenn ausgelassen wird ein Overlay erzeugt. Dies ist die id eines div elements in das das iframe zur Benutzerinteraktion - eingefuegt werden soll.
   };
  pdfAs.signText(op, + eingefuegt werden soll.
+     sig_pos_x: 100, // Die X-Koordinate der links-unten Signaturblockecke.
+     sig_pos_y: 100, // Die X-Koordinate der links-unten Signaturblockecke.
+     sig_pos_p: 2, // Die Seite auf der der Signaturblock platziert werden soll.
+     sig_pos_w: 250, //Die Breite des Signaturblocks
+     sig_pos_f: 40 // Die Hoehe der Fuszzeile ueber der der Signaturblock + platziert werden soll.
+ };
   + pdfAs.signText(op, function(error, cause) {
    //fehler error aufgetreten wegen cause
  }, function(pdfurl) {
    //signiertes Dokument liegt bei pdfurl
  });
</script> @@ -338,10 +360,16 @@ der lokalen BKU, "onlinebku" -> Signatur mit der online BKU, "mobilebku" -> Signatur mit der Handy Signatur
-     uiId: "exampleDiv" // Diese Eigenschaft +     uiId: "exampleDiv", // Diese Eigenschaft ist optional, wenn ausgelassen wird ein Overlay erzeugt. Dies ist die id eines div elements in das das iframe zur Benutzerinteraktion - eingefuegt werden soll.
+ eingefuegt werden soll.
+     sig_pos_x: 100, // Die X-Koordinate der links-unten Signaturblockecke.
+     sig_pos_y: 100, // Die X-Koordinate der links-unten Signaturblockecke.
+     sig_pos_p: 2, // Die Seite auf der der Signaturblock platziert werden soll.
+     sig_pos_w: 250, //Die Breite des Signaturblocks
+     sig_pos_f: 40 // Die Hoehe der Fuszzeile ueber der der Signaturblock + platziert werden soll.
  };
  pdfAs.signPdf(op, function(error, cause) {
-- cgit v1.2.3