aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePositioning.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePositioning.java')
-rw-r--r--src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePositioning.java80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePositioning.java b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePositioning.java
index b9e2c8a..42b02eb 100644
--- a/src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePositioning.java
+++ b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePositioning.java
@@ -3,6 +3,8 @@
*/
package at.gv.egiz.pdfas.api.sign.pos;
+import java.util.StringTokenizer;
+
import at.gv.egiz.pdfas.api.sign.pos.axis.AbsoluteAxisAlgorithm;
import at.gv.egiz.pdfas.api.sign.pos.axis.AutoAxisAlgorithm;
import at.gv.egiz.pdfas.api.sign.pos.axis.AxisAlgorithm;
@@ -10,6 +12,8 @@ import at.gv.egiz.pdfas.api.sign.pos.page.AbsolutePageAlgorithm;
import at.gv.egiz.pdfas.api.sign.pos.page.AutoPageAlgorithm;
import at.gv.egiz.pdfas.api.sign.pos.page.NewPageAlgorithm;
import at.gv.egiz.pdfas.api.sign.pos.page.PageAlgorithm;
+import at.gv.egiz.pdfas.exceptions.ErrorCode;
+import at.knowcenter.wag.egov.egiz.exceptions.PDFDocumentException;
/**
* Defines how the signature positioning is to be performed.
@@ -186,4 +190,80 @@ public class SignaturePositioning
this.footerLine = footerLine;
}
+ public SignaturePositioning() {
+ }
+
+ public SignaturePositioning(String position) throws PDFDocumentException {
+ if (position != null) {
+ StringTokenizer tokenizer = new StringTokenizer(position, ";");
+ while (tokenizer.hasMoreTokens()) {
+ String token = tokenizer.nextToken().replaceAll(" ", "");
+ String[] sToken = token.split(":");
+ if (sToken == null || sToken.length != 2 || sToken[0].length() != 1) {
+ throw new PDFDocumentException(ErrorCode.INVALID_SIGNATURE_POSITION, "Invalid signature position element: " + token);
+ }
+ char cmd = sToken[0].toLowerCase().charAt(0);
+ String value = sToken[1];
+ switch (cmd) {
+ case 'x':
+ if ("auto".equalsIgnoreCase(value)) {
+ this.setXAlgorithm(new AutoAxisAlgorithm());
+ } else {
+ try {
+ this.setXAlgorithm(new AbsoluteAxisAlgorithm(Float.parseFloat(value)));
+ } catch (NumberFormatException e) {
+ throw new PDFDocumentException(ErrorCode.INVALID_SIGNATURE_POSITION, "Invalid signature position element: " + token);
+ }
+ }
+ break;
+ case 'y':
+ if ("auto".equalsIgnoreCase(value)) {
+ this.setYAlgorithm(new AutoAxisAlgorithm());
+ } else {
+ try {
+ this.setYAlgorithm(new AbsoluteAxisAlgorithm(Float.parseFloat(value)));
+ } catch (NumberFormatException e) {
+ throw new PDFDocumentException(ErrorCode.INVALID_SIGNATURE_POSITION, "Invalid signature position element: " + token);
+ }
+ }
+ break;
+ case 'w':
+ if ("auto".equalsIgnoreCase(value)) {
+ this.setWidthAlgorithm(new AutoAxisAlgorithm());
+ } else {
+ try {
+ this.setWidthAlgorithm(new AbsoluteAxisAlgorithm(Float.parseFloat(value)));
+ } catch (NumberFormatException e) {
+ throw new PDFDocumentException(ErrorCode.INVALID_SIGNATURE_POSITION, "Invalid signature position element: " + token);
+ }
+ }
+ break;
+ case 'p':
+ if ("auto".equalsIgnoreCase(value)) {
+ this.setPageAlgorithm(new AutoPageAlgorithm());
+ } else if ("new".equalsIgnoreCase(value)) {
+ this.setPageAlgorithm(new NewPageAlgorithm());
+ } else {
+ try {
+ this.setPageAlgorithm(new AbsolutePageAlgorithm(Integer.parseInt(value)));
+ } catch (NumberFormatException e) {
+ throw new PDFDocumentException(ErrorCode.INVALID_SIGNATURE_POSITION, "Invalid signature position element: " + token);
+ }
+ }
+ break;
+ case 'f':
+ try {
+ this.setFooterLine(Float.parseFloat(value));
+ } catch (NumberFormatException e) {
+ throw new PDFDocumentException(ErrorCode.INVALID_SIGNATURE_POSITION, "Invalid signature position element: " + token);
+ }
+ break;
+ default:
+ throw new PDFDocumentException(ErrorCode.INVALID_SIGNATURE_POSITION, "Invalid signature position element: " + token);
+ }
+ }
+ }
+ }
+
+
}