From 62a3115ce4d55a7a3b3fbf202bac0fff85dc412b Mon Sep 17 00:00:00 2001 From: Jakob Heher Date: Tue, 2 Aug 2022 14:18:37 +0200 Subject: YAGNI: PDF signer factory pattern --- .../composites/configuration/AboutComposite.java | 4 -- .../AdvancedConfigurationComposite.java | 11 ------ .../configuration/ConfigurationCompositeBase.java | 26 ------------- .../KeystoreConfigurationComposite.java | 11 ------ .../SimpleConfigurationComposite.java | 45 +++++++--------------- 5 files changed, 14 insertions(+), 83 deletions(-) (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration') diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AboutComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AboutComposite.java index fe3442a0..1f1cc1ba 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AboutComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AboutComposite.java @@ -132,10 +132,6 @@ public class AboutComposite extends ConfigurationCompositeBase { this.btnOpenLogDirectory.setText(Messages.getString("config.ShowLogDirectory")); } - - @Override - protected void signerChanged() {} - @Override public void initConfiguration(ConfigurationManager provider) {} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AdvancedConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AdvancedConfigurationComposite.java index 31a10b01..e9776846 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AdvancedConfigurationComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/AdvancedConfigurationComposite.java @@ -455,17 +455,6 @@ public class AdvancedConfigurationComposite extends ConfigurationCompositeBase { AdvancedConfigurationComposite.this.txtSaveFilePostFix.setText(postfix); } - /* - * (non-Javadoc) - * - * @see - * at.asit.pdfover.gui.composites.BaseConfigurationComposite#signerChanged() - */ - @Override - protected void signerChanged() { - // Nothing to do here (yet) - } - void performOutputFolderChanged(String foldername) { log.debug("Selected Output folder: {}", foldername); this.configurationContainer.outputFolder = foldername; diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/ConfigurationCompositeBase.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/ConfigurationCompositeBase.java index 16dcd366..54207292 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/ConfigurationCompositeBase.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/ConfigurationCompositeBase.java @@ -19,7 +19,6 @@ package at.asit.pdfover.gui.composites.configuration; import org.eclipse.swt.widgets.Composite; import at.asit.pdfover.gui.composites.StateComposite; -import at.asit.pdfover.gui.workflow.PDFSigner; import at.asit.pdfover.gui.workflow.config.ConfigurationManager; import at.asit.pdfover.gui.workflow.config.ConfigurationDataInMemory; import at.asit.pdfover.gui.workflow.states.State; @@ -34,31 +33,6 @@ public abstract class ConfigurationCompositeBase extends StateComposite { */ protected ConfigurationDataInMemory configurationContainer; - /** - * The PDF Signer used to produce signature block preview - */ - protected PDFSigner signer; - - /** - * @return the signer - */ - public PDFSigner getSigner() { - return this.signer; - } - - /** - * @param signer the signer to set - */ - public void setSigner(PDFSigner signer) { - this.signer = signer; - this.signerChanged(); - } - - /** - * Called when the signer is changed! - */ - protected abstract void signerChanged(); - /** * @param parent * @param style diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/KeystoreConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/KeystoreConfigurationComposite.java index 74d3d62b..14100128 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/KeystoreConfigurationComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/KeystoreConfigurationComposite.java @@ -427,17 +427,6 @@ public class KeystoreConfigurationComposite extends ConfigurationCompositeBase { this.txtKeystoreKeyPass.setText(keypass); } - /* - * (non-Javadoc) - * - * @see - * at.asit.pdfover.gui.composites.BaseConfigurationComposite#signerChanged() - */ - @Override - protected void signerChanged() { - // Nothing to do here (yet) - } - /* * (non-Javadoc) * 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 2de930bf..c5ad6f5a 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 @@ -68,6 +68,7 @@ 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.PdfAs4Signer; /** * @@ -440,22 +441,20 @@ public class SimpleConfigurationComposite extends ConfigurationCompositeBase { ImageData logo = null; try { - if (this.signer != null) { - SignatureParameter param = this.signer.getPDFSigner().newParameter(); - if(this.configurationContainer.signatureNote != null && !this.configurationContainer.signatureNote.isEmpty()) { - param.setProperty("SIG_NOTE", this.configurationContainer.signatureNote); - } + SignatureParameter param = PdfAs4Signer.newParameter(); + if(this.configurationContainer.signatureNote != null && !this.configurationContainer.signatureNote.isEmpty()) { + param.setProperty("SIG_NOTE", this.configurationContainer.signatureNote); + } - param.setSignatureLanguage(this.configurationContainer.signatureLocale.getLanguage()); - param.setSignaturePdfACompat(this.configurationContainer.signaturePDFACompat); - if (image != null && !image.trim().isEmpty()) { - logo = new ImageData(image); - param.setEmblem(new CachedFileNameEmblem(image)); - } - //TODO deactivated the placeholder preview - //TODO display accurate placeholder preview -> now its only standard placeholder shown - //img = SignaturePlaceholderCache.getSWTPlaceholder(param); + param.setSignatureLanguage(this.configurationContainer.signatureLocale.getLanguage()); + param.setSignaturePdfACompat(this.configurationContainer.signaturePDFACompat); + if (image != null && !image.trim().isEmpty()) { + logo = new ImageData(image); + param.setEmblem(new CachedFileNameEmblem(image)); } + //TODO deactivated the placeholder preview + //TODO display accurate placeholder preview -> now its only standard placeholder shown + //img = SignaturePlaceholderCache.getSWTPlaceholder(param); } catch (Exception e) { log.error("Failed to load image for display...", e); } @@ -555,12 +554,8 @@ public class SimpleConfigurationComposite extends ConfigurationCompositeBase { } void setSignatureProfileSetting(){ - if (this.signer == null){ - log.debug("In setSignatureProfileSettings: Signer was null"); - return; - } try { - SignatureParameter param = this.signer.getPDFSigner().newParameter(); + SignatureParameter param = PdfAs4Signer.newParameter(); param.setSignatureProfile(this.configurationContainer.getSignatureProfile().name()); } catch (Exception e){ @@ -568,18 +563,6 @@ public class SimpleConfigurationComposite extends ConfigurationCompositeBase { } } - /* - * (non-Javadoc) - * - * @see - * at.asit.pdfover.gui.composites.BaseConfigurationComposite#signerChanged() - */ - @Override - protected void signerChanged() { - this.setVisibleImage(); - this.setSignatureProfileSetting(); - } - private void plainMobileNumberSetter() { String number = this.txtMobileNumber.getText(); this.configurationContainer.setMobileNumber(number); -- cgit v1.2.3