From 135c54f61da53a5f6342d9a4fc947b3d64498625 Mon Sep 17 00:00:00 2001 From: Jakob Heher Date: Tue, 2 Aug 2022 14:29:11 +0200 Subject: YAGNI: SignatureParameter abstract class --- .../signer/pdfas/PdfAs4SignatureParameter.java | 190 +++++++++++++++++++-- .../at/asit/pdfover/signer/pdfas/PdfAs4Signer.java | 21 +-- 2 files changed, 184 insertions(+), 27 deletions(-) (limited to 'pdf-over-signer') diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignatureParameter.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignatureParameter.java index 99b6e238..34eabb11 100644 --- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignatureParameter.java +++ b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignatureParameter.java @@ -27,9 +27,10 @@ import java.util.Locale; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - +import at.asit.pdfover.signator.BKUs; +import at.asit.pdfover.signator.DocumentSource; +import at.asit.pdfover.signator.Emblem; import at.asit.pdfover.signator.SignatureDimension; -import at.asit.pdfover.signator.SignatureParameter; import at.asit.pdfover.signator.SignaturePosition; import at.gv.egiz.pdfas.lib.api.Configuration; import at.gv.egiz.pdfas.lib.api.PdfAs; @@ -40,14 +41,187 @@ import at.asit.pdfover.commons.Profile; /** * Implementation of SignatureParameter for PDF-AS 4 Library */ -public class PdfAs4SignatureParameter extends SignatureParameter { +public class PdfAs4SignatureParameter { + /** + * SLF4J Logger instance + **/ + static final Logger log = LoggerFactory.getLogger(PdfAs4SignatureParameter.class); + /** * this is set by CliArguments.InvisibleProfile * TODO: this is a no good, very bad, hack */ public static boolean PROFILE_VISIBILITY = true; + /** The Signature Position */ + protected SignaturePosition signaturePosition = null; + + /** The Signature language */ + protected String signatureLanguage = null; + + /** The key identifier */ + protected String keyIdentifier = null; + + /** The input document */ + protected DocumentSource documentSource = null; + + /** Holds the emblem */ + protected Emblem emblem; + + /** Whether to use PDF/A compatibility */ + protected boolean pdfACompat; + + /** The signature device */ + protected BKUs signatureDevice; + + /** Whether so look for placeholder signatures or not. */ + protected boolean searchForPlaceholderSignatures = false; + + /** + * @return the searchForPlaceholderSignatures + */ + public boolean isSearchForPlaceholderSignatures() { + return this.searchForPlaceholderSignatures; + } + + /** + * @param value + * the searchForPlaceholderSignatures to set + */ + public void setSearchForPlaceholderSignatures(boolean value) { + this.searchForPlaceholderSignatures = value; + } + + /** + * @return the signatureDevice + */ + public BKUs getSignatureDevice() { + return this.signatureDevice; + } + + /** + * @param signatureDevice + * the signatureDevice to set + */ + public void setSignatureDevice(BKUs signatureDevice) { + this.signatureDevice = signatureDevice; + } + + /** + * Getter of the property signaturePosition + * + * @return Returns the signaturePosition. + */ + public SignaturePosition getSignaturePosition() { + return this.signaturePosition; + } + + /** + * Setter of the property signaturePosition + * + * @param signaturePosition + * The signaturePosition to set. + */ + public void setSignaturePosition(SignaturePosition signaturePosition) { + this.signaturePosition = signaturePosition; + } + + /** + * Getter of the property signatureLanguage + * + * @return Returns the signatureLanguage. + */ + public String getSignatureLanguage() { + return this.signatureLanguage; + } + + /** + * Setter of the property signatureLanguage + * + * @param signatureLanguage + * The signatureLanguage to set. + */ + public void setSignatureLanguage(String signatureLanguage) { + this.signatureLanguage = signatureLanguage; + } + + /** + * Getter of the property signaturePdfACompat + * + * @return Returns the PDF/A compatibility setting. + */ + public boolean getSignaturePdfACompat() { + return this.pdfACompat; + } + + /** + * Setter of the property signaturePdfACompat + * + * @param compat + * The the PDF/A compatibility setting to set. + */ + public void setSignaturePdfACompat(boolean compat) { + this.pdfACompat = compat; + } + + /** + * Getter of the property keyIdentifier + * + * @return Returns the keyIdentifier. + */ + public String getKeyIdentifier() { + return this.keyIdentifier; + } + + /** + * Setter of the property keyIdentifier + * + * @param keyIdentifier + * The keyIdentifier to set. + */ + public void setKeyIdentifier(String keyIdentifier) { + this.keyIdentifier = keyIdentifier; + } + + /** + * Getter of the property documentSource + * + * @return Returns the documentSource. + */ + public DocumentSource getInputDocument() { + return this.documentSource; + } + + /** + * Setter of the property documentSource + * + * @param inputDocument + * The documentSource to set. + */ + public void setInputDocument(DocumentSource inputDocument) { + this.documentSource = inputDocument; + } + + /** + * Gets the Emblem + * + * @return the Emblem + */ + public Emblem getEmblem() { + return this.emblem; + } + + /** + * Sets the Emblem + * + * @param emblem + * The new Emblem + */ + public void setEmblem(Emblem emblem) { + this.emblem = emblem; + } + private HashMap genericProperties = new HashMap(); /** @@ -56,16 +230,11 @@ public class PdfAs4SignatureParameter extends SignatureParameter { private int sig_w = 229; private int sig_h = 77; - /** - * SLF4J Logger instance - **/ - static final Logger log = LoggerFactory.getLogger(PdfAs4SignatureParameter.class); private String profile = Profile.getDefaultProfile(); /* (non-Javadoc) * @see at.asit.pdfover.signator.SignatureParameter#getPlaceholderDimension() */ - @Override public SignatureDimension getPlaceholderDimension() { return new SignatureDimension(this.sig_w, this.sig_h); } @@ -73,7 +242,6 @@ public class PdfAs4SignatureParameter extends SignatureParameter { /* (non-Javadoc) * @see at.asit.pdfover.signator.SignatureParameter#getPlaceholder() */ - @Override public Image getPlaceholder() { String sigProfile = getPdfAsSignatureProfileId(); @@ -109,7 +277,6 @@ public class PdfAs4SignatureParameter extends SignatureParameter { /* (non-Javadoc) * @see at.asit.pdfover.signator.SignatureParameter#setProperty(java.lang.String, java.lang.String) */ - @Override public void setProperty(String key, String value) { this.genericProperties.put(key, value); } @@ -117,7 +284,6 @@ public class PdfAs4SignatureParameter extends SignatureParameter { /* (non-Javadoc) * @see at.asit.pdfover.signator.SignatureParameter#getProperty(java.lang.String) */ - @Override public String getProperty(String key) { return this.genericProperties.get(key); } @@ -196,12 +362,10 @@ public class PdfAs4SignatureParameter extends SignatureParameter { return ("en".equals(lang)) ? "_EN" : "_DE"; } - @Override public void setSignatureProfile(String profile) { this.profile = profile; } - @Override public String getSignatureProfile() { return this.profile; } diff --git a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java index 5d3e2b64..9959dcdf 100644 --- a/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java +++ b/pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java @@ -10,7 +10,6 @@ import at.asit.pdfover.signator.ByteArrayDocumentSource; import at.asit.pdfover.signator.SignResult; import at.asit.pdfover.signator.SignResultImpl; import at.asit.pdfover.signator.SignatureException; -import at.asit.pdfover.signator.SignatureParameter; import at.asit.pdfover.signator.SignaturePosition; import at.asit.pdfover.signator.SigningState; import at.gv.egiz.pdfas.common.exceptions.PDFASError; @@ -42,24 +41,18 @@ public class PdfAs4Signer { protected static final String LOC_REF = "" + URL_TEMPLATE + ""; - public static SigningState prepare(SignatureParameter parameter) - throws SignatureException { - PdfAs4SignatureParameter sign_para = null; + public static SigningState prepare(PdfAs4SignatureParameter parameter) throws SignatureException { - if (PdfAs4SignatureParameter.class.isInstance(parameter)) { - sign_para = PdfAs4SignatureParameter.class.cast(parameter); - } - - if (sign_para == null) { + if (parameter == null) { throw new SignatureException("Incorrect SignatureParameter!"); } - String sigProfile = sign_para.getPdfAsSignatureProfileId(); - String sigEmblem = (sign_para.getEmblem() == null ? null : sign_para.getEmblem().getFileName()); - String sigNote = sign_para.getProperty("SIG_NOTE"); + String sigProfile = parameter.getPdfAsSignatureProfileId(); + String sigEmblem = (parameter.getEmblem() == null ? null : parameter.getEmblem().getFileName()); + String sigNote = parameter.getProperty("SIG_NOTE"); String sigPos = null; - if (sign_para.getSignaturePosition() != null) { - sigPos = sign_para.getPdfAsSignaturePosition(); + if (parameter.getSignaturePosition() != null) { + sigPos = parameter.getPdfAsSignaturePosition(); } PdfAs pdfas = PdfAs4Helper.getPdfAs(); Configuration config = pdfas.getConfiguration(); -- cgit v1.2.3