From 61a2d23ef72630934c603fe9ffb96ebebff6ee09 Mon Sep 17 00:00:00 2001 From: netconomy Date: Thu, 29 Nov 2007 12:00:22 +0000 Subject: PDF-AS API git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@233 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../at/gv/egiz/pdfas/api/sign/SignParameters.java | 173 +++++++++++++++++++ .../java/at/gv/egiz/pdfas/api/sign/SignResult.java | 49 ++++++ .../egiz/pdfas/api/sign/pos/SignaturePosition.java | 52 ++++++ .../pdfas/api/sign/pos/SignaturePositioning.java | 189 +++++++++++++++++++++ .../api/sign/pos/axis/AbsoluteAxisAlgorithm.java | 35 ++++ .../pdfas/api/sign/pos/axis/AutoAxisAlgorithm.java | 14 ++ .../pdfas/api/sign/pos/axis/AxisAlgorithm.java | 14 ++ .../api/sign/pos/page/AbsolutePageAlgorithm.java | 37 ++++ .../pdfas/api/sign/pos/page/AutoPageAlgorithm.java | 20 +++ .../pdfas/api/sign/pos/page/NewPageAlgorithm.java | 14 ++ .../pdfas/api/sign/pos/page/PageAlgorithm.java | 14 ++ 11 files changed, 611 insertions(+) create mode 100644 src/main/java/at/gv/egiz/pdfas/api/sign/SignParameters.java create mode 100644 src/main/java/at/gv/egiz/pdfas/api/sign/SignResult.java create mode 100644 src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePosition.java create mode 100644 src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePositioning.java create mode 100644 src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AbsoluteAxisAlgorithm.java create mode 100644 src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AutoAxisAlgorithm.java create mode 100644 src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AxisAlgorithm.java create mode 100644 src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/AbsolutePageAlgorithm.java create mode 100644 src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/AutoPageAlgorithm.java create mode 100644 src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/NewPageAlgorithm.java create mode 100644 src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/PageAlgorithm.java (limited to 'src/main/java/at/gv/egiz/pdfas/api/sign') diff --git a/src/main/java/at/gv/egiz/pdfas/api/sign/SignParameters.java b/src/main/java/at/gv/egiz/pdfas/api/sign/SignParameters.java new file mode 100644 index 0000000..cc59cbd --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/api/sign/SignParameters.java @@ -0,0 +1,173 @@ +/** + * + */ +package at.gv.egiz.pdfas.api.sign; + +import at.gv.egiz.pdfas.api.commons.Constants; +import at.gv.egiz.pdfas.api.io.DataSink; +import at.gv.egiz.pdfas.api.io.DataSource; +import at.gv.egiz.pdfas.api.sign.pos.SignaturePositioning; + +/** + * Parameter object that holds the sign parameters. + * + * @author wprinz + */ +public class SignParameters +{ + /** + * The document to be signed. + * + *

+ * The DataSource implementation encapsulates the actual representaion of the + * data. E.g. the DataSource may be File based or byte array based. See + * package at.gv.egiz.pdfas.framework.input and at.gv.pdfas.impl.input + *

+ */ + protected DataSource document = null; + + /** + * The type of the signature. + * + *

+ * May be {@link Constants#SIGNATURE_TYPE_BINARY} or + * {@link Constants#SIGNATURE_TYPE_TEXTUAL}. + *

+ */ + protected String signatureType = Constants.SIGNATURE_TYPE_BINARY; + + /** + * The signature device to perform the actual signature. + * + *

+ * May be {@link Constants#SIGNATURE_DEVICE_MOA} or + * {@link Constants#SIGNATURE_DEVICE_BKU}. + *

+ */ + protected String signatureDevice = Constants.SIGNATURE_DEVICE_MOA; + + /** + * The signature profile identifier identifying the profile to be used in the + * config file. + * + *

+ * Note: In near future it will be possible to provide a full specified + * profile here instead of the profile id. + *

+ */ + protected String signatureProfileId = null;; + + /** + * The signature position. Consult the PDF-AS documentation section + * Commandline. + */ + protected SignaturePositioning signaturePositioning = null; + + /** + * The output DataSink that will receive the signed document. + */ + protected DataSink output = null; + + /** + * @return the document + */ + public DataSource getDocument() + { + return document; + } + + /** + * @param document + * the document to set + */ + public void setDocument(DataSource document) + { + this.document = document; + } + + /** + * @return the signatureType + */ + public String getSignatureType() + { + return signatureType; + } + + /** + * @param signatureType + * the signatureType to set + */ + public void setSignatureType(String signatureType) + { + this.signatureType = signatureType; + } + + /** + * @return the signatureDevice + */ + public String getSignatureDevice() + { + return signatureDevice; + } + + /** + * @param signatureDevice + * the signatureDevice to set + */ + public void setSignatureDevice(String signatureDevice) + { + this.signatureDevice = signatureDevice; + } + + /** + * @return the signatureProfileId + */ + public String getSignatureProfileId() + { + return signatureProfileId; + } + + /** + * @param signatureProfileId + * the signatureProfileId to set + */ + public void setSignatureProfileId(String signatureProfileId) + { + this.signatureProfileId = signatureProfileId; + } + + /** + * @return the signaturePositioning + */ + public SignaturePositioning getSignaturePositioning() + { + return this.signaturePositioning; + } + + /** + * @param signaturePositioning + * the signaturePositioning to set + */ + public void setSignaturePositioning(SignaturePositioning signaturePositioning) + { + this.signaturePositioning = signaturePositioning; + } + + /** + * @return the output + */ + public DataSink getOutput() + { + return output; + } + + /** + * @param output + * the output to set + */ + public void setOutput(DataSink output) + { + this.output = output; + } + +} diff --git a/src/main/java/at/gv/egiz/pdfas/api/sign/SignResult.java b/src/main/java/at/gv/egiz/pdfas/api/sign/SignResult.java new file mode 100644 index 0000000..519a9e1 --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/api/sign/SignResult.java @@ -0,0 +1,49 @@ +/** + * + */ +package at.gv.egiz.pdfas.api.sign; + +import java.security.cert.X509Certificate; + +import at.gv.egiz.pdfas.api.io.DataSink; +import at.gv.egiz.pdfas.api.sign.pos.SignaturePosition; + +/** + * The result of a sign operation. + * + * @author wprinz + */ +public interface SignResult +{ + + /** + * Returns the filled output data sink. + * + * @return Returns the filled output data sink. + */ + public DataSink getOutputDocument(); + + /** + * Returns the certificate of the signer. + * + * @return Returns the certificate of the signer. + */ + public X509Certificate getSignerCertificate(); + + /** + * Returns the position where the signature is finally placed. + * + *

+ * This information can be useful for post-processing the document. + *

+ * + *

+ * Consult the PDF-AS documentation section Commandline for further + * information about positioning. + *

+ * + * @return Returns the position where the signature is finally placed. May + * return null if no position information is available. + */ + public SignaturePosition getSignaturePosition(); +} diff --git a/src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePosition.java b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePosition.java new file mode 100644 index 0000000..8dc6b6c --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePosition.java @@ -0,0 +1,52 @@ +/** + * + */ +package at.gv.egiz.pdfas.api.sign.pos; + +/** + * Holds the actual, absolute signature position where a signature was placed. + * + *

+ * This is usually returned after signing. + *

+ * + * @author wprinz + */ +public interface SignaturePosition +{ + /** + * Returns the page on which the signature was placed. + * + * @return Returns the page on which the signature was placed. + */ + public int getPage(); + + /** + * Returns the x position. + * + * @return Returns the x position. + */ + public float getX(); + + /** + * Returns the y position. + * + * @return Returns the y position. + */ + public float getY(); + + /** + * Returns the width of the signature. + * + * @return Returns the width of the signature. + */ + public float getWidth(); + + /** + * Returns the height of the signature. + * + * @return Returns the height of the signature. + */ + public float getHeight(); + +} 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 new file mode 100644 index 0000000..b9e2c8a --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/SignaturePositioning.java @@ -0,0 +1,189 @@ +/** + * + */ +package at.gv.egiz.pdfas.api.sign.pos; + +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; +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; + +/** + * Defines how the signature positioning is to be performed. + * + *

+ * This positioning allows to select the location where the signature block is + * placed in the document. + *

+ * + * @author wprinz + */ +public class SignaturePositioning +{ + /** + * The x axis algorithm. + * + *

+ * May be {@link AutoAxisAlgorithm} or {@link AbsoluteAxisAlgorithm} + *

+ */ + protected AxisAlgorithm xAlgorithm = new AutoAxisAlgorithm(); + + /** + * The y axis algorithm. + * + *

+ * May be {@link AutoAxisAlgorithm} or {@link AbsoluteAxisAlgorithm} + *

+ */ + protected AxisAlgorithm yAlgorithm = new AutoAxisAlgorithm(); + + /** + * The width algorithm. + * + *

+ * May be {@link AutoAxisAlgorithm} or {@link AbsoluteAxisAlgorithm} + *

+ */ + protected AxisAlgorithm widthAlgorithm = new AutoAxisAlgorithm(); + + /** + * The page algorithm. + * + *

+ * May be {@link AutoPageAlgorithm}, {@link AbsolutePageAlgorithm} or + * {@link NewPageAlgorithm} + *

+ */ + protected PageAlgorithm pageAlgorithm = new AutoPageAlgorithm(); + + /** + * Provides the position of the footline. + * + *

+ * Only used if the pageAlgorithm is {@link AutoPageAlgorithm} and the + * yAlgorithm is {@link AutoAxisAlgorithm} + *

+ */ + protected float footerLine = 0.0f; + + protected void checkAxisAlgorithm(AxisAlgorithm algorithm) + { + if (algorithm == null) + { + throw new IllegalArgumentException("The algorithm must not be null."); + } + if (!(algorithm instanceof AutoAxisAlgorithm) && !(algorithm instanceof AbsoluteAxisAlgorithm)) + { + throw new IllegalArgumentException("The algorithm must be either Auto or Absolute."); + } + } + + protected void checkPageAlgorithm(PageAlgorithm algorithm) + { + if (algorithm == null) + { + throw new IllegalArgumentException("The algorithm must not be null."); + } + if (!(algorithm instanceof AutoPageAlgorithm) && !(algorithm instanceof AbsolutePageAlgorithm) && !(algorithm instanceof NewPageAlgorithm)) + { + throw new IllegalArgumentException("The algorithm must be either Auto or Absolute."); + } + + } + + /** + * @return the xAlgorithm + */ + public AxisAlgorithm getXAlgorithm() + { + return this.xAlgorithm; + } + + /** + * @param algorithm + * the xAlgorithm to set + */ + public void setXAlgorithm(AxisAlgorithm algorithm) + { + checkAxisAlgorithm(algorithm); + xAlgorithm = algorithm; + } + + /** + * @return the yAlgorithm + */ + public AxisAlgorithm getYAlgorithm() + { + return this.yAlgorithm; + } + + /** + * @param algorithm + * the yAlgorithm to set + */ + public void setYAlgorithm(AxisAlgorithm algorithm) + { + checkAxisAlgorithm(algorithm); + + yAlgorithm = algorithm; + } + + /** + * @return the widthAlgorithm + */ + public AxisAlgorithm getWidthAlgorithm() + { + return this.widthAlgorithm; + } + + /** + * @param widthAlgorithm + * the widthAlgorithm to set + */ + public void setWidthAlgorithm(AxisAlgorithm widthAlgorithm) + { + checkAxisAlgorithm(widthAlgorithm); + + this.widthAlgorithm = widthAlgorithm; + } + + /** + * @return the pageAlgorithm + */ + public PageAlgorithm getPageAlgorithm() + { + return this.pageAlgorithm; + } + + /** + * @param pageAlgorithm + * the pageAlgorithm to set + */ + public void setPageAlgorithm(PageAlgorithm pageAlgorithm) + { + checkPageAlgorithm(pageAlgorithm); + this.pageAlgorithm = pageAlgorithm; + } + + /** + * @return the footerLine + */ + public float getFooterLine() + { + return this.footerLine; + } + + /** + * @param footerLine + * the footerLine to set + */ + public void setFooterLine(float footerLine) + { + this.footerLine = footerLine; + } + +} diff --git a/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AbsoluteAxisAlgorithm.java b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AbsoluteAxisAlgorithm.java new file mode 100644 index 0000000..234484c --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AbsoluteAxisAlgorithm.java @@ -0,0 +1,35 @@ +/** + * + */ +package at.gv.egiz.pdfas.api.sign.pos.axis; + +/** + * An absolute positioned element. + * @author wprinz + */ +public class AbsoluteAxisAlgorithm extends AxisAlgorithm +{ + + /** + * The absolute positioning value on the axis. + */ + protected float absoluteValue = 0.0f; + + /** + * Constructor. + * @param absoluteValue The absolute positioning value on the axis. + */ + public AbsoluteAxisAlgorithm (float absoluteValue) + { + this.absoluteValue = absoluteValue; + } + + /** + * Returns absolute positioning value on the axis. + * @return the absoluteValue Returns absolute positioning value on the axis. + */ + public float getAbsoluteValue() + { + return this.absoluteValue; + } +} diff --git a/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AutoAxisAlgorithm.java b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AutoAxisAlgorithm.java new file mode 100644 index 0000000..4c5459f --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AutoAxisAlgorithm.java @@ -0,0 +1,14 @@ +/** + * + */ +package at.gv.egiz.pdfas.api.sign.pos.axis; + +/** + * Auto positioning for this element. + * + * @author wprinz + */ +public class AutoAxisAlgorithm extends AxisAlgorithm +{ +// empty +} diff --git a/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AxisAlgorithm.java b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AxisAlgorithm.java new file mode 100644 index 0000000..a4baac6 --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/axis/AxisAlgorithm.java @@ -0,0 +1,14 @@ +/** + * + */ +package at.gv.egiz.pdfas.api.sign.pos.axis; + +/** + * Determines how a certain position is chosen on the axis (x, y, width). + * + * @author wprinz + */ +public abstract class AxisAlgorithm +{ +// base class +} diff --git a/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/AbsolutePageAlgorithm.java b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/AbsolutePageAlgorithm.java new file mode 100644 index 0000000..206aa19 --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/AbsolutePageAlgorithm.java @@ -0,0 +1,37 @@ +/** + * + */ +package at.gv.egiz.pdfas.api.sign.pos.page; + +/** + * The page is selected absolutely by giving the page number directly. + * + * @author wprinz + */ +public class AbsolutePageAlgorithm extends PageAlgorithm +{ + /** + * The page. + */ + protected int page = -1; + + /** + * Constructor. + * + * @param page + * The page. + */ + public AbsolutePageAlgorithm(int page) + { + this.page = page; + } + + /** + * @return the page + */ + public int getPage() + { + return this.page; + } + +} diff --git a/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/AutoPageAlgorithm.java b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/AutoPageAlgorithm.java new file mode 100644 index 0000000..0070d5e --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/AutoPageAlgorithm.java @@ -0,0 +1,20 @@ +/** + * + */ +package at.gv.egiz.pdfas.api.sign.pos.page; + +/** + * The page for placing the signature is selected automatically. + * + *

+ * The algorithm first tries to place the signature on the free space of the + * last page (considering the footer). If there is not enough space on the last + * page, a new page is appended and the signature is placed there. + *

+ * + * @author wprinz + */ +public class AutoPageAlgorithm extends PageAlgorithm +{ +// empty +} diff --git a/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/NewPageAlgorithm.java b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/NewPageAlgorithm.java new file mode 100644 index 0000000..2a8f67c --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/NewPageAlgorithm.java @@ -0,0 +1,14 @@ +/** + * + */ +package at.gv.egiz.pdfas.api.sign.pos.page; + +/** + * Places the signature on a new Page. + * + * @author wprinz + */ +public class NewPageAlgorithm extends PageAlgorithm +{ + // empty block +} diff --git a/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/PageAlgorithm.java b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/PageAlgorithm.java new file mode 100644 index 0000000..9b0fe8a --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/api/sign/pos/page/PageAlgorithm.java @@ -0,0 +1,14 @@ +/** + * + */ +package at.gv.egiz.pdfas.api.sign.pos.page; + +/** + * Determines how the page on which the signature is to be placed is selected. + * + * @author wprinz + */ +public abstract class PageAlgorithm +{ + // empty +} -- cgit v1.2.3