summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Heher <jakob.heher@iaik.tugraz.at>2022-08-02 15:32:12 +0200
committerJakob Heher <jakob.heher@iaik.tugraz.at>2022-08-02 15:32:12 +0200
commit8522b8b8cb0043883b8801e619384f94efe981e8 (patch)
tree9edaddee3f786d5a14635d912cbfcb425d426c22
parent464e7b1df6a0ff5d1450e5ff0f67101640edbc5e (diff)
downloadpdf-over-8522b8b8cb0043883b8801e619384f94efe981e8.tar.gz
pdf-over-8522b8b8cb0043883b8801e619384f94efe981e8.tar.bz2
pdf-over-8522b8b8cb0043883b8801e619384f94efe981e8.zip
YAGNI SignatureParameter setters/getters
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/configuration/SimpleConfigurationComposite.java9
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/utils/SignaturePlaceholderCache.java10
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PositioningState.java6
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java16
-rw-r--r--pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4SignatureParameter.java241
-rw-r--r--pdf-over-signer/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java8
6 files changed, 60 insertions, 230 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 c3392a46..a737bdfe 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
@@ -445,11 +445,11 @@ public class SimpleConfigurationComposite extends ConfigurationCompositeBase {
param.setProperty("SIG_NOTE", this.configurationContainer.signatureNote);
}
- param.setSignatureLanguage(this.configurationContainer.signatureLocale.getLanguage());
- param.setSignaturePdfACompat(this.configurationContainer.signaturePDFACompat);
+ param.signatureLanguage = this.configurationContainer.signatureLocale.getLanguage();
+ param.enablePDFACompat = this.configurationContainer.signaturePDFACompat;
if (image != null && !image.trim().isEmpty()) {
logo = new ImageData(image);
- param.setEmblem(new CachedFileNameEmblem(image));
+ param.emblem = new CachedFileNameEmblem(image);
}
//TODO deactivated the placeholder preview
//TODO display accurate placeholder preview -> now its only standard placeholder shown
@@ -554,8 +554,9 @@ public class SimpleConfigurationComposite extends ConfigurationCompositeBase {
void setSignatureProfileSetting(){
try {
+ // TODO this doesn't do anything...?
PdfAs4SignatureParameter param = new PdfAs4SignatureParameter();
- param.setSignatureProfile(this.configurationContainer.getSignatureProfile().name());
+ param.signatureProfileName = this.configurationContainer.getSignatureProfile().name();
} catch (Exception e){
log.warn("Cannot save signature profile {}", e.getMessage());
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 7d2d444f..80b27183 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
@@ -74,11 +74,11 @@ public class SignaturePlaceholderCache {
final String sigNoteProp = "NOTE";
final String sigProfProp = "PROF";
- String sigLang = param.getSignatureLanguage();
+ String sigLang = param.signatureLanguage;
String sigEmbl = "";
String sigEHsh = "";
- if (param.getEmblem() != null) {
- Emblem embl = param.getEmblem();
+ if (param.emblem != null) {
+ Emblem embl = param.emblem;
if (embl instanceof CachedFileNameEmblem) {
sigEmbl = ((CachedFileNameEmblem) embl).getOriginalFileName();
sigEHsh = ((CachedFileNameEmblem) embl).getOriginalFileHash();
@@ -86,11 +86,11 @@ public class SignaturePlaceholderCache {
sigEmbl = embl.getFileName();
}
}
- String sigPdfA = param.getSignaturePdfACompat() ? Constants.TRUE : Constants.FALSE;
+ String sigPdfA = param.enablePDFACompat ? Constants.TRUE : Constants.FALSE;
String sigNote = param.getProperty("SIG_NOTE");
if (sigNote == null)
sigNote = "";
- String profile = param.getSignatureProfile();
+ String profile = param.signatureProfileName;
if (profile == null){
// set default value
profile = Profile.getDefaultProfile();
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 ea6f3003..5ed63e0b 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
@@ -109,13 +109,13 @@ public class PositioningState extends State {
ConfigurationManager config = stateMachine.configProvider;
PdfAs4SignatureParameter param = new PdfAs4SignatureParameter();
Emblem emblem = new CachedFileNameEmblem(config.getDefaultEmblem());
- param.setEmblem(emblem);
+ param.emblem = emblem;
if(config.getSignatureNote() != null && !config.getSignatureNote().isEmpty()) {
param.setProperty("SIG_NOTE", config.getSignatureNote());
}
- param.setSignatureLanguage(config.getSignatureLocale().getLanguage());
- param.setSignaturePdfACompat(config.getSignaturePdfACompat());
+ param.signatureLanguage = config.getSignatureLocale().getLanguage();
+ param.enablePDFACompat = config.getSignaturePdfACompat();
this.positionComposite.setPlaceholder(
SignaturePlaceholderCache.getPlaceholder(param),
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 26fd0cab..786ed920 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
@@ -128,14 +128,14 @@ public class PrepareSigningState extends State {
this.state.signatureParameter = new PdfAs4SignatureParameter();
}
- this.state.signatureParameter.setInputDocument(new PDFFileDocumentSource(status.document));
- this.state.signatureParameter.setSignatureDevice(status.bku);
+ this.state.signatureParameter.inputDocument = new PDFFileDocumentSource(status.document);
+ this.state.signatureParameter.signatureDevice = status.bku;
if (status.signaturePosition != null) {
- this.state.signatureParameter.setSignaturePosition(status.signaturePosition);
+ this.state.signatureParameter.signaturePosition = status.signaturePosition;
}
if (configuration.getDefaultEmblem() != null && !configuration.getDefaultEmblem().isEmpty()) {
- this.state.signatureParameter.setEmblem(new CachedFileNameEmblem(configuration.getDefaultEmblem()));
+ this.state.signatureParameter.emblem = new CachedFileNameEmblem(configuration.getDefaultEmblem());
}
if (configuration.getSignatureNote() != null
@@ -144,13 +144,13 @@ public class PrepareSigningState extends State {
"SIG_NOTE", configuration.getSignatureNote());
}
- this.state.signatureParameter.setSearchForPlaceholderSignatures(getStateMachine().status.searchForPlacehoderSignature);
+ this.state.signatureParameter.searchForPlaceholderSignatures = getStateMachine().status.searchForPlacehoderSignature;
- this.state.signatureParameter.setSignatureLanguage(configuration.getSignatureLocale().getLanguage());
+ this.state.signatureParameter.signatureLanguage = configuration.getSignatureLocale().getLanguage();
- this.state.signatureParameter.setSignaturePdfACompat(configuration.getSignaturePdfACompat());
+ this.state.signatureParameter.enablePDFACompat = configuration.getSignaturePdfACompat();
- this.state.signatureParameter.setSignatureProfile(configuration.getSignatureProfile());
+ this.state.signatureParameter.signatureProfileName = configuration.getSignatureProfile();
this.state.signingState = PdfAs4Signer.prepare(this.state.signatureParameter);
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 3a14cb1a..359af17a 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
@@ -42,8 +42,6 @@ import at.asit.pdfover.commons.Profile;
* Implementation of SignatureParameter for PDF-AS 4 Library
*/
public class PdfAs4SignatureParameter {
-
- // TODO nuke getters/setters from this class
/**
* SLF4J Logger instance
**/
@@ -56,172 +54,28 @@ public class PdfAs4SignatureParameter {
public static boolean PROFILE_VISIBILITY = true;
/** The Signature Position */
- protected SignaturePosition signaturePosition = null;
+ public SignaturePosition signaturePosition = null;
/** The Signature language */
- protected String signatureLanguage = null;
+ public String signatureLanguage = null;
/** The key identifier */
- protected String keyIdentifier = null;
+ public String keyIdentifier = null;
/** The input document */
- protected DocumentSource documentSource = null;
+ public DocumentSource inputDocument = null;
/** Holds the emblem */
- protected Emblem emblem;
+ public Emblem emblem;
/** Whether to use PDF/A compatibility */
- protected boolean pdfACompat;
+ public boolean enablePDFACompat;
/** The signature device */
- protected BKUs signatureDevice;
+ public 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;
- }
+ public boolean searchForPlaceholderSignatures = false;
private HashMap<String, String> genericProperties = new HashMap<String, String>();
@@ -231,22 +85,17 @@ public class PdfAs4SignatureParameter {
private int sig_w = 229;
private int sig_h = 77;
- private String profile = Profile.getDefaultProfile();
+ public String signatureProfileName = Profile.getDefaultProfile();
- /* (non-Javadoc)
- * @see at.asit.pdfover.signator.SignatureParameter#getPlaceholderDimension()
- */
+ // TODO why is this stored separately?
public SignatureDimension getPlaceholderDimension() {
return new SignatureDimension(this.sig_w, this.sig_h);
}
- /* (non-Javadoc)
- * @see at.asit.pdfover.signator.SignatureParameter#getPlaceholder()
- */
public Image getPlaceholder() {
String sigProfile = getPdfAsSignatureProfileId();
- String sigEmblem = (getEmblem() == null ? null : getEmblem().getFileName());
+ String sigEmblem = (this.emblem == null ? null : this.emblem.getFileName());
String sigNote = getProperty("SIG_NOTE");
try {
@@ -275,16 +124,11 @@ public class PdfAs4SignatureParameter {
}
}
- /* (non-Javadoc)
- * @see at.asit.pdfover.signator.SignatureParameter#setProperty(java.lang.String, java.lang.String)
- */
+ // TODO review this
public void setProperty(String key, String value) {
this.genericProperties.put(key, value);
}
- /* (non-Javadoc)
- * @see at.asit.pdfover.signator.SignatureParameter#getProperty(java.lang.String)
- */
public String getProperty(String key) {
return this.genericProperties.get(key);
}
@@ -295,24 +139,21 @@ public class PdfAs4SignatureParameter {
* @return Signature Position String
*/
public String getPdfAsSignaturePosition() {
- SignaturePosition in_pos = getSignaturePosition();
- String out_pos;
-
- if (!in_pos.useAutoPositioning()) {
- if (in_pos.getPage() < 1) {
- out_pos = String.format(
- (Locale) null,
- "p:new;x:%f;y:%f", in_pos.getX(), in_pos.getY());
- } else {
- out_pos = String.format(
- (Locale) null,
- "p:%d;x:%f;y:%f", in_pos.getPage(), in_pos.getX(), in_pos.getY());
- }
- } else {
- out_pos = "p:auto;x:auto;y:auto";
- }
-
- return out_pos;
+ SignaturePosition in_pos = this.signaturePosition;
+
+ if (in_pos.useAutoPositioning())
+ return "p:auto;x:auto;y:auto";
+
+ if (in_pos.getPage() < 1)
+ {
+ return String.format(
+ (Locale) null,
+ "p:new;x:%f;y:%f", in_pos.getX(), in_pos.getY());
+ } else {
+ return String.format(
+ (Locale) null,
+ "p:%d;x:%f;y:%f", in_pos.getPage(), in_pos.getX(), in_pos.getY());
+ }
}
/**
@@ -321,9 +162,6 @@ public class PdfAs4SignatureParameter {
* @return the Signature Profile ID
*/
public String getPdfAsSignatureProfileId() {
- String lang = getSignatureLanguage();
- boolean useNote = (getProperty("SIG_NOTE") != null);
- boolean usePdfACompat = (getSignaturePdfACompat());
//Add Signature Param here//
String profileId;
@@ -333,26 +171,26 @@ public class PdfAs4SignatureParameter {
return Profile.INVISIBLE.name();
}
- Profile profile = Profile.getProfile(this.profile);
+ Profile profile = Profile.getProfile(this.signatureProfileName);
switch (profile) {
case BASE_LOGO:
case INVISIBLE:
- return this.profile;
+ return this.signatureProfileName;
case AMTSSIGNATURBLOCK:
- profileId = this.profile;
- profileId += getLangProfilePart(lang);
+ profileId = this.signatureProfileName;
+ profileId += getLangProfilePart(this.signatureLanguage);
profileId += "_RECOMMENDED";
return profileId;
default:
- profileId = this.profile;
- profileId += getLangProfilePart(lang);
+ profileId = this.signatureProfileName;
+ profileId += getLangProfilePart(this.signatureLanguage);
break;
}
- if (useNote)
+ if (getProperty("SIG_NOTE") != null)
profileId += "_NOTE";
- if (usePdfACompat)
+ if (this.enablePDFACompat)
profileId += "_PDFA";
log.debug("Profile ID: {}", profileId);
@@ -362,15 +200,6 @@ public class PdfAs4SignatureParameter {
private static String getLangProfilePart(String lang) {
return ("en".equals(lang)) ? "_EN" : "_DE";
}
-
- public void setSignatureProfile(String profile) {
- this.profile = profile;
- }
-
- 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 8a31f101..e4d07b5d 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
@@ -46,10 +46,10 @@ public class PdfAs4Signer {
}
String sigProfile = parameter.getPdfAsSignatureProfileId();
- String sigEmblem = (parameter.getEmblem() == null ? null : parameter.getEmblem().getFileName());
+ String sigEmblem = (parameter.emblem == null ? null : parameter.emblem.getFileName());
String sigNote = parameter.getProperty("SIG_NOTE");
String sigPos = null;
- if (parameter.getSignaturePosition() != null) {
+ if (parameter.signaturePosition != null) {
sigPos = parameter.getPdfAsSignaturePosition();
}
PdfAs pdfas = PdfAs4Helper.getPdfAs();
@@ -64,7 +64,7 @@ public class PdfAs4Signer {
PdfAs4SigningState state = new PdfAs4SigningState();
ByteArrayOutputStream output = new ByteArrayOutputStream();
- DataSource input = new ByteArrayDataSource(parameter.getInputDocument().getByteArray());
+ DataSource input = new ByteArrayDataSource(parameter.inputDocument.getByteArray());
SignParameter param = PdfAsFactory.createSignParameter(config, input, output);
if (sigPos != null) {
param.setSignaturePosition(sigPos);
@@ -73,7 +73,7 @@ public class PdfAs4Signer {
String id = UUID.randomUUID().toString();
param.setTransactionId(id);
- if (parameter.isSearchForPlaceholderSignatures()) {
+ if (parameter.searchForPlaceholderSignatures) {
param.getConfiguration().setValue(IConfigurationConstants.PLACEHOLDER_MODE, "1");
param.getConfiguration().setValue(IConfigurationConstants.PLACEHOLDER_SEARCH_ENABLED, IConfigurationConstants.TRUE);
}