diff options
author | Jakob Heher <jakob.heher@iaik.tugraz.at> | 2022-08-02 14:29:11 +0200 |
---|---|---|
committer | Jakob Heher <jakob.heher@iaik.tugraz.at> | 2022-08-02 14:29:11 +0200 |
commit | 135c54f61da53a5f6342d9a4fc947b3d64498625 (patch) | |
tree | 08d4d52d93693d443d2e4ac85f3cb6383c40698b | |
parent | 9db67a0963f01d5c893d76c8e746272a53703d91 (diff) | |
download | pdf-over-135c54f61da53a5f6342d9a4fc947b3d64498625.tar.gz pdf-over-135c54f61da53a5f6342d9a4fc947b3d64498625.tar.bz2 pdf-over-135c54f61da53a5f6342d9a4fc947b3d64498625.zip |
YAGNI: SignatureParameter abstract class
7 files changed, 191 insertions, 269 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/SimpleConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/SimpleConfigurationComposite.java index b00dc00a..c3392a46 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/SimpleConfigurationComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/SimpleConfigurationComposite.java @@ -67,9 +67,7 @@ import at.asit.pdfover.gui.workflow.config.ConfigurationManager; import at.asit.pdfover.gui.workflow.config.ConfigurationDataInMemory; import at.asit.pdfover.gui.workflow.states.State; import at.asit.pdfover.signator.CachedFileNameEmblem; -import at.asit.pdfover.signator.SignatureParameter; import at.asit.pdfover.signer.pdfas.PdfAs4SignatureParameter; -import at.asit.pdfover.signer.pdfas.PdfAs4Signer; /** * @@ -442,7 +440,7 @@ public class SimpleConfigurationComposite extends ConfigurationCompositeBase { ImageData logo = null; try { - SignatureParameter param = new PdfAs4SignatureParameter(); + PdfAs4SignatureParameter param = new PdfAs4SignatureParameter(); if(this.configurationContainer.signatureNote != null && !this.configurationContainer.signatureNote.isEmpty()) { param.setProperty("SIG_NOTE", this.configurationContainer.signatureNote); } @@ -556,7 +554,7 @@ public class SimpleConfigurationComposite extends ConfigurationCompositeBase { void setSignatureProfileSetting(){ try { - SignatureParameter param = new PdfAs4SignatureParameter(); + PdfAs4SignatureParameter param = new PdfAs4SignatureParameter(); param.setSignatureProfile(this.configurationContainer.getSignatureProfile().name()); } catch (Exception e){ diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SignaturePlaceholderCache.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SignaturePlaceholderCache.java index 2d9a190b..7d2d444f 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SignaturePlaceholderCache.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SignaturePlaceholderCache.java @@ -36,7 +36,7 @@ import org.slf4j.LoggerFactory; import at.asit.pdfover.commons.Constants; import at.asit.pdfover.signator.CachedFileNameEmblem; import at.asit.pdfover.signator.Emblem; -import at.asit.pdfover.signator.SignatureParameter; +import at.asit.pdfover.signer.pdfas.PdfAs4SignatureParameter; /** * @@ -61,7 +61,7 @@ public class SignaturePlaceholderCache { * @param param SignatureParameter * @return the placeholder AWT Image */ - public static Image getPlaceholder(SignatureParameter param) { + public static Image getPlaceholder(PdfAs4SignatureParameter param) { final String fileDir = Constants.CONFIG_DIRECTORY; final String imgFileName = Constants.PLACEHOLDER_CACHE_FILENAME; final String imgFileExt = "png"; @@ -144,7 +144,7 @@ public class SignaturePlaceholderCache { * @param param SignatureParameter * @return the placeholder SWT ImageData */ - public static ImageData getSWTPlaceholder(SignatureParameter param) { + public static ImageData getSWTPlaceholder(PdfAs4SignatureParameter param) { return ImageConverter.convertToSWT((BufferedImage) getPlaceholder(param)); } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java index 1b1a978c..ea6f3003 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java @@ -37,10 +37,8 @@ import at.asit.pdfover.gui.workflow.Status; import at.asit.pdfover.gui.workflow.config.ConfigurationManager; import at.asit.pdfover.signator.CachedFileNameEmblem; import at.asit.pdfover.signator.Emblem; -import at.asit.pdfover.signator.SignatureParameter; import at.asit.pdfover.signator.SignaturePosition; import at.asit.pdfover.signer.pdfas.PdfAs4SignatureParameter; -import at.asit.pdfover.signer.pdfas.PdfAs4Signer; /** * Decides where to position the signature block @@ -109,7 +107,7 @@ public class PositioningState extends State { } // Update possibly changed values ConfigurationManager config = stateMachine.configProvider; - SignatureParameter param = new PdfAs4SignatureParameter(); + PdfAs4SignatureParameter param = new PdfAs4SignatureParameter(); Emblem emblem = new CachedFileNameEmblem(config.getDefaultEmblem()); param.setEmblem(emblem); if(config.getSignatureNote() != null && !config.getSignatureNote().isEmpty()) { diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java index 57a91da5..e6a10aa6 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java @@ -34,7 +34,6 @@ import at.asit.pdfover.gui.workflow.Status; import at.asit.pdfover.gui.workflow.config.ConfigurationManager; import at.asit.pdfover.signator.CachedFileNameEmblem; import at.asit.pdfover.signator.PDFFileDocumentSource; -import at.asit.pdfover.signator.SignatureParameter; import at.asit.pdfover.signer.pdfas.PdfAs4SignatureParameter; import at.asit.pdfover.signer.pdfas.PdfAs4Signer; @@ -168,7 +167,7 @@ public class PrepareSigningState extends State { **/ static final Logger log = LoggerFactory.getLogger(PrepareSigningState.class); - SignatureParameter signatureParameter; + PdfAs4SignatureParameter signatureParameter; private WaitingComposite waitingComposite = null; diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignatureParameter.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignatureParameter.java deleted file mode 100644 index 14ae6314..00000000 --- a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/SignatureParameter.java +++ /dev/null @@ -1,230 +0,0 @@ -/* - * Copyright 2012 by A-SIT, Secure Information Technology Center Austria - * - * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by - * the European Commission - subsequent versions of the EUPL (the "Licence"); - * You may not use this work except in compliance with the Licence. - * You may obtain a copy of the Licence at: - * http://joinup.ec.europa.eu/software/page/eupl - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the Licence is distributed on an "AS IS" basis, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the Licence for the specific language governing permissions and - * limitations under the Licence. - */ -package at.asit.pdfover.signator; - -import java.awt.Image; - -//Imports - -/** - * The Signature Parameter - */ -public abstract class SignatureParameter { - - /** 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 <tt>signaturePosition</tt> - * - * @return Returns the signaturePosition. - */ - public SignaturePosition getSignaturePosition() { - return this.signaturePosition; - } - - /** - * Setter of the property <tt>signaturePosition</tt> - * - * @param signaturePosition - * The signaturePosition to set. - */ - public void setSignaturePosition(SignaturePosition signaturePosition) { - this.signaturePosition = signaturePosition; - } - - /** - * Getter of the property <tt>signatureLanguage</tt> - * - * @return Returns the signatureLanguage. - */ - public String getSignatureLanguage() { - return this.signatureLanguage; - } - - /** - * Setter of the property <tt>signatureLanguage</tt> - * - * @param signatureLanguage - * The signatureLanguage to set. - */ - public void setSignatureLanguage(String signatureLanguage) { - this.signatureLanguage = signatureLanguage; - } - - /** - * Getter of the property <tt>signaturePdfACompat</tt> - * - * @return Returns the PDF/A compatibility setting. - */ - public boolean getSignaturePdfACompat() { - return this.pdfACompat; - } - - /** - * Setter of the property <tt>signaturePdfACompat</tt> - * - * @param compat - * The the PDF/A compatibility setting to set. - */ - public void setSignaturePdfACompat(boolean compat) { - this.pdfACompat = compat; - } - - /** - * Getter of the property <tt>keyIdentifier</tt> - * - * @return Returns the keyIdentifier. - */ - public String getKeyIdentifier() { - return this.keyIdentifier; - } - - /** - * Setter of the property <tt>keyIdentifier</tt> - * - * @param keyIdentifier - * The keyIdentifier to set. - */ - public void setKeyIdentifier(String keyIdentifier) { - this.keyIdentifier = keyIdentifier; - } - - /** - * Getter of the property <tt>documentSource</tt> - * - * @return Returns the documentSource. - */ - public DocumentSource getInputDocument() { - return this.documentSource; - } - - /** - * Setter of the property <tt>documentSource</tt> - * - * @param inputDocument - * The documentSource to set. - */ - public void setInputDocument(DocumentSource inputDocument) { - this.documentSource = inputDocument; - } - - /** - * Gets the Dimension to display the Placeholder - * - * @return the placeholder dimensions - */ - public abstract SignatureDimension getPlaceholderDimension(); - - /** - * Gets the Placeholder image - * - * @return the placeholder image - */ - public abstract Image getPlaceholder(); - - /** - * 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; - } - - /** - * Sets generic properties - * - * @param key - * @param value - */ - public abstract void setProperty(String key, String value); - - /** - * Gets generic properties - * - * @param key - * @return associated value - */ - public abstract String getProperty(String key); - - - public abstract void setSignatureProfile(String profile); - - public abstract String getSignatureProfile(); - -} 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 <tt>signaturePosition</tt> + * + * @return Returns the signaturePosition. + */ + public SignaturePosition getSignaturePosition() { + return this.signaturePosition; + } + + /** + * Setter of the property <tt>signaturePosition</tt> + * + * @param signaturePosition + * The signaturePosition to set. + */ + public void setSignaturePosition(SignaturePosition signaturePosition) { + this.signaturePosition = signaturePosition; + } + + /** + * Getter of the property <tt>signatureLanguage</tt> + * + * @return Returns the signatureLanguage. + */ + public String getSignatureLanguage() { + return this.signatureLanguage; + } + + /** + * Setter of the property <tt>signatureLanguage</tt> + * + * @param signatureLanguage + * The signatureLanguage to set. + */ + public void setSignatureLanguage(String signatureLanguage) { + this.signatureLanguage = signatureLanguage; + } + + /** + * Getter of the property <tt>signaturePdfACompat</tt> + * + * @return Returns the PDF/A compatibility setting. + */ + public boolean getSignaturePdfACompat() { + return this.pdfACompat; + } + + /** + * Setter of the property <tt>signaturePdfACompat</tt> + * + * @param compat + * The the PDF/A compatibility setting to set. + */ + public void setSignaturePdfACompat(boolean compat) { + this.pdfACompat = compat; + } + + /** + * Getter of the property <tt>keyIdentifier</tt> + * + * @return Returns the keyIdentifier. + */ + public String getKeyIdentifier() { + return this.keyIdentifier; + } + + /** + * Setter of the property <tt>keyIdentifier</tt> + * + * @param keyIdentifier + * The keyIdentifier to set. + */ + public void setKeyIdentifier(String keyIdentifier) { + this.keyIdentifier = keyIdentifier; + } + + /** + * Getter of the property <tt>documentSource</tt> + * + * @return Returns the documentSource. + */ + public DocumentSource getInputDocument() { + return this.documentSource; + } + + /** + * Setter of the property <tt>documentSource</tt> + * + * @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<String, String> genericProperties = new HashMap<String, String>(); /** @@ -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 = "<sl:LocRefContent>" + URL_TEMPLATE + "</sl:LocRefContent>"; - 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(); |