From 0f63732ed31a3b5189e46f8b49c32a79ef2b6534 Mon Sep 17 00:00:00 2001 From: Jakob Heher Date: Thu, 7 Jul 2022 15:08:09 +0200 Subject: config cleanup --- .../asit/pdfover/gui/bku/mobile/ATrustStatus.java | 4 +- .../at/asit/pdfover/gui/bku/mobile/IAIKStatus.java | 4 +- .../at/asit/pdfover/gui/cliarguments/Argument.java | 4 +- .../gui/composites/ConfigurationComposite.java | 10 +- .../composites/configuration/AboutComposite.java | 6 +- .../AdvancedConfigurationComposite.java | 10 +- .../configuration/ConfigurationCompositeBase.java | 12 +- .../KeystoreConfigurationComposite.java | 20 +- .../SimpleConfigurationComposite.java | 10 +- .../at/asit/pdfover/gui/workflow/StateMachine.java | 6 +- .../gui/workflow/config/ConfigProviderImpl.java | 1027 ------------------- .../workflow/config/ConfigurationContainer.java | 194 ---- .../workflow/config/ConfigurationDataInMemory.java | 194 ++++ .../gui/workflow/config/ConfigurationManager.java | 1030 ++++++++++++++++++++ .../asit/pdfover/gui/workflow/states/KSState.java | 4 +- .../gui/workflow/states/MobileBKUState.java | 4 +- .../pdfover/gui/workflow/states/OpenState.java | 4 +- .../pdfover/gui/workflow/states/OutputState.java | 4 +- .../gui/workflow/states/PositioningState.java | 4 +- .../workflow/states/PrepareConfigurationState.java | 4 +- .../gui/workflow/states/PrepareSigningState.java | 4 +- 21 files changed, 1281 insertions(+), 1278 deletions(-) delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigProviderImpl.java delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationContainer.java create mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationDataInMemory.java create mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationManager.java (limited to 'pdf-over-gui/src') diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustStatus.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustStatus.java index 7a51a961..5bc0c745 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustStatus.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/ATrustStatus.java @@ -19,7 +19,7 @@ package at.asit.pdfover.gui.bku.mobile; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import at.asit.pdfover.gui.workflow.config.ConfigProviderImpl; +import at.asit.pdfover.gui.workflow.config.ConfigurationManager; /** * A-Trust MobileBKUStatus implementation @@ -52,7 +52,7 @@ public class ATrustStatus extends MobileBKUStatus { * Constructor * @param provider the ConfigProvider */ - public ATrustStatus(ConfigProviderImpl provider) { + public ATrustStatus(ConfigurationManager provider) { this.phoneNumber = provider.getDefaultMobileNumber(); this.mobilePassword = provider.getDefaultMobilePassword(); } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/IAIKStatus.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/IAIKStatus.java index cb150327..c855c99a 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/IAIKStatus.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/IAIKStatus.java @@ -15,7 +15,7 @@ */ package at.asit.pdfover.gui.bku.mobile; -import at.asit.pdfover.gui.workflow.config.ConfigProviderImpl; +import at.asit.pdfover.gui.workflow.config.ConfigurationManager; /** * IAIK MobileBKUStatus implementation @@ -31,7 +31,7 @@ public class IAIKStatus extends MobileBKUStatus { * Constructor * @param provider the ConfigProvider */ - public IAIKStatus(ConfigProviderImpl provider) { + public IAIKStatus(ConfigurationManager provider) { this.phoneNumber = provider.getDefaultMobileNumber(); this.mobilePassword = provider.getDefaultMobilePassword(); } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/Argument.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/Argument.java index bf82177e..16a47a42 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/Argument.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/Argument.java @@ -19,7 +19,7 @@ import at.asit.pdfover.gui.exceptions.InitializationException; import at.asit.pdfover.commons.Messages; import at.asit.pdfover.gui.workflow.StateMachine; import at.asit.pdfover.gui.workflow.Status; -import at.asit.pdfover.gui.workflow.config.ConfigProviderImpl; +import at.asit.pdfover.gui.workflow.config.ConfigurationManager; /** * CLI Argument base class @@ -52,7 +52,7 @@ public abstract class Argument { this.stateMachine = stateMachine; } - protected ConfigProviderImpl getConfiguration() { + protected ConfigurationManager getConfiguration() { return this.stateMachine.configProvider; } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationComposite.java index d977e665..013d084f 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/ConfigurationComposite.java @@ -42,8 +42,8 @@ import at.asit.pdfover.gui.controls.ErrorDialog; import at.asit.pdfover.gui.exceptions.ResumableException; import at.asit.pdfover.commons.Messages; import at.asit.pdfover.gui.workflow.PDFSigner; -import at.asit.pdfover.gui.workflow.config.ConfigProviderImpl; -import at.asit.pdfover.gui.workflow.config.ConfigurationContainer; +import at.asit.pdfover.gui.workflow.config.ConfigurationManager; +import at.asit.pdfover.gui.workflow.config.ConfigurationDataInMemory; import at.asit.pdfover.gui.workflow.states.State; /** @@ -64,7 +64,7 @@ public class ConfigurationComposite extends StateComposite { /** * configuration provider */ - ConfigProviderImpl configProvider = null; + ConfigurationManager configProvider = null; /** * simple configuration composite @@ -89,7 +89,7 @@ public class ConfigurationComposite extends StateComposite { /** * configuration container Keeps state for current configuration changes */ - ConfigurationContainer configurationContainer = new ConfigurationContainer(); + ConfigurationDataInMemory configurationContainer = new ConfigurationDataInMemory(); /** * The stack layout @@ -308,7 +308,7 @@ public class ConfigurationComposite extends StateComposite { * * @param provider */ - public void setConfigProvider(ConfigProviderImpl provider) { + public void setConfigProvider(ConfigurationManager provider) { this.configProvider = provider; if (this.configProvider != null) { // Initialize Configuration Container 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 7eac256a..fe3442a0 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 @@ -21,7 +21,7 @@ import org.slf4j.LoggerFactory; import at.asit.pdfover.commons.Constants; import at.asit.pdfover.commons.Messages; import at.asit.pdfover.gui.composites.StateComposite; -import at.asit.pdfover.gui.workflow.config.ConfigProviderImpl; +import at.asit.pdfover.gui.workflow.config.ConfigurationManager; public class AboutComposite extends ConfigurationCompositeBase { static final Logger log = LoggerFactory.getLogger(AboutComposite.class); @@ -137,13 +137,13 @@ public class AboutComposite extends ConfigurationCompositeBase { protected void signerChanged() {} @Override - public void initConfiguration(ConfigProviderImpl provider) {} + public void initConfiguration(ConfigurationManager provider) {} @Override public void loadConfiguration() {} @Override - public void storeConfiguration(ConfigProviderImpl store) {} + public void storeConfiguration(ConfigurationManager store) {} @Override public void validateSettings(int resumeFrom) throws Exception {} 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 baba386a..be872c1e 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 @@ -53,8 +53,8 @@ import at.asit.pdfover.gui.controls.ErrorMarker; import at.asit.pdfover.gui.exceptions.InvalidPortException; import at.asit.pdfover.gui.exceptions.OutputfolderDoesntExistException; import at.asit.pdfover.gui.exceptions.OutputfolderNotADirectoryException; -import at.asit.pdfover.gui.workflow.config.ConfigProviderImpl; -import at.asit.pdfover.gui.workflow.config.ConfigurationContainer; +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.BKUs; import at.asit.pdfover.signator.SignaturePosition; @@ -120,7 +120,7 @@ public class AdvancedConfigurationComposite extends ConfigurationCompositeBase { * @param container * @param config */ - public AdvancedConfigurationComposite(Composite parent, int style, State state, ConfigurationContainer container, + public AdvancedConfigurationComposite(Composite parent, int style, State state, ConfigurationDataInMemory container, ConfigurationComposite config) { super(parent, style, state, container); this.configurationComposite = config; @@ -647,7 +647,7 @@ public class AdvancedConfigurationComposite extends ConfigurationCompositeBase { } @Override - public void initConfiguration(ConfigProviderImpl provider) { + public void initConfiguration(ConfigurationManager provider) { this.configurationContainer.defaultSignaturePosition = provider.getDefaultSignaturePositionPersistent(); this.configurationContainer.setUseMarker(provider.getUseMarker()); this.configurationContainer.setUseSignatureFields(provider.getUseSignatureFields()); @@ -739,7 +739,7 @@ public class AdvancedConfigurationComposite extends ConfigurationCompositeBase { } @Override - public void storeConfiguration(ConfigProviderImpl store) { + public void storeConfiguration(ConfigurationManager store) { store.setDefaultSignaturePosition(this.configurationContainer.defaultSignaturePosition); store.setUseMarker(this.configurationContainer.getUseMarker()); store.setUseSignatureFields(this.configurationContainer.getUseSignatureFields()); 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 d3e458db..16dcd366 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 @@ -20,8 +20,8 @@ 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.ConfigProviderImpl; -import at.asit.pdfover.gui.workflow.config.ConfigurationContainer; +import at.asit.pdfover.gui.workflow.config.ConfigurationManager; +import at.asit.pdfover.gui.workflow.config.ConfigurationDataInMemory; import at.asit.pdfover.gui.workflow.states.State; /** @@ -32,7 +32,7 @@ public abstract class ConfigurationCompositeBase extends StateComposite { /** * the configuration container */ - protected ConfigurationContainer configurationContainer; + protected ConfigurationDataInMemory configurationContainer; /** * The PDF Signer used to produce signature block preview @@ -65,7 +65,7 @@ public abstract class ConfigurationCompositeBase extends StateComposite { * @param state * @param configuration */ - public ConfigurationCompositeBase(Composite parent, int style, State state, ConfigurationContainer configuration) { + public ConfigurationCompositeBase(Composite parent, int style, State state, ConfigurationDataInMemory configuration) { super(parent, style, state); this.configurationContainer = configuration; } @@ -74,7 +74,7 @@ public abstract class ConfigurationCompositeBase extends StateComposite { * Initialize ConfigurationContainer from ConfigProviderImpl * @param provider the ConfigProviderImpl to load config from */ - public abstract void initConfiguration(ConfigProviderImpl provider); + public abstract void initConfiguration(ConfigurationManager provider); /** * Load configuration from ConfigurationContainer @@ -85,7 +85,7 @@ public abstract class ConfigurationCompositeBase extends StateComposite { * Store configuration from ConfigurationContainer to ConfigProvider * @param store the ConfigProviderImpl to store config to */ - public abstract void storeConfiguration(ConfigProviderImpl store); + public abstract void storeConfiguration(ConfigurationManager store); /** * Called before exit. 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 597112df..7ea2a642 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 @@ -55,8 +55,8 @@ import at.asit.pdfover.gui.exceptions.KeystoreAliasNoKeyException; import at.asit.pdfover.gui.exceptions.KeystoreDoesntExistException; import at.asit.pdfover.gui.exceptions.KeystoreKeyPasswordException; import at.asit.pdfover.commons.Messages; -import at.asit.pdfover.gui.workflow.config.ConfigProviderImpl; -import at.asit.pdfover.gui.workflow.config.ConfigurationContainer; +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 iaik.security.provider.IAIK; @@ -97,7 +97,7 @@ public class KeystoreConfigurationComposite extends ConfigurationCompositeBase { */ public KeystoreConfigurationComposite( org.eclipse.swt.widgets.Composite parent, int style, State state, - ConfigurationContainer container) { + ConfigurationDataInMemory container) { super(parent, style, state, container); setLayout(new FormLayout()); @@ -277,7 +277,7 @@ public class KeystoreConfigurationComposite extends ConfigurationCompositeBase { } void loadKeystore() throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException { - ConfigurationContainer config = + ConfigurationDataInMemory config = KeystoreConfigurationComposite.this.configurationContainer; File f = new File(config.keystoreFile); this.ks = KeyStore.getInstance(config.keystoreType); @@ -380,8 +380,8 @@ public class KeystoreConfigurationComposite extends ConfigurationCompositeBase { } @Override - public void initConfiguration(ConfigProviderImpl provider) { - ConfigurationContainer config = this.configurationContainer; + public void initConfiguration(ConfigurationManager provider) { + ConfigurationDataInMemory config = this.configurationContainer; config.keystoreFile = provider.getKeyStoreFilePersistent(); config.keystoreType = provider.getKeyStoreTypePersistent(); config.keystoreAlias = provider.getKeyStoreAliasPersistent(); @@ -397,7 +397,7 @@ public class KeystoreConfigurationComposite extends ConfigurationCompositeBase { @Override public void loadConfiguration() { // Initialize form fields from configuration Container - ConfigurationContainer config = this.configurationContainer; + ConfigurationDataInMemory config = this.configurationContainer; String ks = config.keystoreFile; performKeystoreFileChanged(ks); performKeystoreTypeChanged(config.keystoreType); @@ -414,8 +414,8 @@ public class KeystoreConfigurationComposite extends ConfigurationCompositeBase { } @Override - public void storeConfiguration(ConfigProviderImpl store) { - ConfigurationContainer config = this.configurationContainer; + public void storeConfiguration(ConfigurationManager store) { + ConfigurationDataInMemory config = this.configurationContainer; store.setKeyStoreFile(config.keystoreFile); store.setKeyStoreType(config.keystoreType); store.setKeyStoreAlias(config.keystoreAlias); @@ -432,7 +432,7 @@ public class KeystoreConfigurationComposite extends ConfigurationCompositeBase { */ @Override public void validateSettings(int resumeFrom) throws Exception { - ConfigurationContainer config = this.configurationContainer; + ConfigurationDataInMemory config = this.configurationContainer; switch (resumeFrom) { case 0: String fname = config.keystoreFile; 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 257f9cc6..c8d9c208 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 @@ -63,8 +63,8 @@ import at.asit.pdfover.gui.controls.ErrorDialog; import at.asit.pdfover.gui.controls.ErrorMarker; import at.asit.pdfover.gui.exceptions.InvalidEmblemFile; import at.asit.pdfover.gui.utils.ImageConverter; -import at.asit.pdfover.gui.workflow.config.ConfigProviderImpl; -import at.asit.pdfover.gui.workflow.config.ConfigurationContainer; +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; @@ -119,7 +119,7 @@ public class SimpleConfigurationComposite extends ConfigurationCompositeBase { */ public SimpleConfigurationComposite( org.eclipse.swt.widgets.Composite parent, int style, State state, - ConfigurationContainer container) { + ConfigurationDataInMemory container) { super(parent, style, state, container); setLayout(new FormLayout()); @@ -607,7 +607,7 @@ public class SimpleConfigurationComposite extends ConfigurationCompositeBase { } @Override - public void initConfiguration(ConfigProviderImpl provider) { + public void initConfiguration(ConfigurationManager provider) { this.configurationContainer.setMobileNumber(provider.getDefaultMobileNumberPersistent()); try { @@ -663,7 +663,7 @@ public class SimpleConfigurationComposite extends ConfigurationCompositeBase { } @Override - public void storeConfiguration(ConfigProviderImpl store) { + public void storeConfiguration(ConfigurationManager store) { store.setDefaultMobileNumber(this.configurationContainer.getMobileNumber()); store.setDefaultEmblem(this.configurationContainer.getEmblem()); store.setSignatureLocale(this.configurationContainer.signatureLocale); diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachine.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachine.java index cbb30b51..17a8d56f 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachine.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachine.java @@ -28,7 +28,7 @@ import at.asit.pdfover.gui.MainWindow; import at.asit.pdfover.gui.controls.Dialog.BUTTONS; import at.asit.pdfover.gui.controls.ErrorDialog; import at.asit.pdfover.commons.Messages; -import at.asit.pdfover.gui.workflow.config.ConfigProviderImpl; +import at.asit.pdfover.gui.workflow.config.ConfigurationManager; import at.asit.pdfover.gui.workflow.states.PrepareConfigurationState; import at.asit.pdfover.gui.workflow.states.State; @@ -42,7 +42,7 @@ public class StateMachine implements GUIProvider { public final Status status; public final PDFSigner pdfSigner; - public final ConfigProviderImpl configProvider; + public final ConfigurationManager configProvider; public final String[] cmdLineArgs; /** @@ -54,7 +54,7 @@ public class StateMachine implements GUIProvider { this.status = new Status(); this.status.setCurrentState(new PrepareConfigurationState(this)); this.pdfSigner = new PDFSigner(); - this.configProvider = new ConfigProviderImpl(); + this.configProvider = new ConfigurationManager(); this.cmdLineArgs = cmdLineArgs; } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigProviderImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigProviderImpl.java deleted file mode 100644 index 7fc3c832..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigProviderImpl.java +++ /dev/null @@ -1,1027 +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.gui.workflow.config; - -// Imports -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.util.Locale; -import java.util.Properties; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import at.asit.pdfover.commons.Profile; -import org.eclipse.swt.graphics.Point; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.commons.Constants; -import at.asit.pdfover.gui.bku.mobile.MobileBKUs; -import at.asit.pdfover.gui.exceptions.InvalidEmblemFile; -import at.asit.pdfover.gui.exceptions.InvalidPortException; -import at.asit.pdfover.gui.utils.LocaleSerializer; -import at.asit.pdfover.commons.Messages; -import at.asit.pdfover.signator.BKUs; -import at.asit.pdfover.signator.SignaturePosition; - -// TODO: review which properties use the overlay in this file (also: remove unneeded setters/getters, maybe template impl for overlays?) - -/** - * Implementation of the configuration provider and manipulator - */ -public class ConfigProviderImpl { - - - /** Default Mobile BKU type */ - public static final MobileBKUs DEFAULT_MOBILE_BKU_TYPE = MobileBKUs.A_TRUST; - - - /** - * SLF4J Logger instance - **/ - private static final Logger log = LoggerFactory - .getLogger(ConfigProviderImpl.class); - - /** - * An empty property entry - */ - private static final String STRING_EMPTY = ""; - - private String configurationFile = Constants.DEFAULT_CONFIG_FILENAME; - - // The persistent configuration read from the config file - private ConfigurationContainer configuration; - - // The configuration overlay built from the cmd line args - private ConfigurationContainer configurationOverlay; - - /** - * Constructor - */ - public ConfigProviderImpl() { - this.configuration = new ConfigurationContainer(); - this.configurationOverlay = new ConfigurationContainer(); - } - - /* load from disk */ - public void loadFromDisk() throws IOException { - - Properties config = new Properties(); - - config.load(new FileInputStream(Constants.CONFIG_DIRECTORY + File.separator + getConfigurationFileName())); - - setDefaultEmblem(config.getProperty(Constants.CFG_EMBLEM)); - - setDefaultMobileNumber(config.getProperty(Constants.CFG_MOBILE_NUMBER)); - - setProxyHost(config.getProperty(Constants.CFG_PROXY_HOST)); - setProxyUser(config.getProperty(Constants.CFG_PROXY_USER)); - setProxyPass(config.getProperty(Constants.CFG_PROXY_PASS)); - - setDefaultOutputFolder(config.getProperty(Constants.CFG_OUTPUT_FOLDER)); - - String postFix = config.getProperty(Constants.CFG_POSTFIX); - if (postFix == null) - setSaveFilePostFix(Constants.DEFAULT_POSTFIX); - else - setSaveFilePostFix(postFix); - - String localeString = config.getProperty(Constants.CFG_LOCALE); - - Locale targetLocale = LocaleSerializer.parseFromString(localeString); - if (targetLocale != null) - setLocale(targetLocale); - - String signatureLocaleString = config.getProperty(Constants.CFG_SIGNATURE_LOCALE); - - Locale signatureTargetLocale = LocaleSerializer.parseFromString(signatureLocaleString); - if (signatureTargetLocale != null) - setSignatureLocale(signatureTargetLocale); - - String useMarker = config.getProperty(Constants.CFG_USE_MARKER); - if (useMarker != null) - setUseMarker(useMarker.equalsIgnoreCase(Constants.TRUE)); - - String useSignatureFields = config.getProperty(Constants.CFG_USE_SIGNATURE_FIELDS); - if (useSignatureFields != null) - setUseSignatureFields(useSignatureFields.equalsIgnoreCase(Constants.TRUE)); - - String enablePlaceholder = config.getProperty(Constants.CFG_ENABLE_PLACEHOLDER); - if (enablePlaceholder != null) - setEnablePlaceholderUsage(enablePlaceholder.equalsIgnoreCase(Constants.TRUE)); - - String signatureProfile = config.getProperty(Constants.SIGNATURE_PROFILE); - if (signatureProfile != null) - { - Profile profile = Profile.getProfile(signatureProfile); - if (profile != null) - { - this.configuration.setSignatureProfile(profile); - this.configurationOverlay.setSignatureProfile(profile); - } - } - - if (config.containsKey(Constants.CFG_SIGNATURE_NOTE)) - setSignatureNote(config.getProperty(Constants.CFG_SIGNATURE_NOTE)); - else - setSignatureNote(Profile.getProfile(getSignatureProfile()).getDefaultSignatureBlockNote(getSignatureLocale())); - - String compat = config.getProperty(Constants.CFG_SIGNATURE_PDFA_COMPAT); - if (compat != null) - setSignaturePdfACompat(compat.equalsIgnoreCase(Constants.TRUE)); - - String bkuUrl = config.getProperty(Constants.CFG_MOBILE_BKU_URL); - if (bkuUrl != null && !bkuUrl.isEmpty()) - this.configuration.mobileBKUURL = bkuUrl; - - String bkuType = config - .getProperty(Constants.CFG_MOBILE_BKU_TYPE); - - if (bkuType != null && !bkuType.isEmpty()) - { - try - { - this.configuration.mobileBKUType = MobileBKUs.valueOf(bkuType.trim().toUpperCase()); - } catch (IllegalArgumentException e) { - log.error("Invalid BKU type: " + bkuType); - this.configuration.mobileBKUType = DEFAULT_MOBILE_BKU_TYPE; - } - } - - String useBase64 = config.getProperty(Constants.CFG_MOBILE_BKU_BASE64); - if (useBase64 != null) - this.configuration.mobileBKUBase64 = useBase64.equalsIgnoreCase(Constants.TRUE); - - String proxyPortString = config.getProperty(Constants.CFG_PROXY_PORT); - if (proxyPortString != null && !proxyPortString.trim().isEmpty()) - { - int port = Integer.parseInt(proxyPortString); - - if (port > 0 && port <= 0xFFFF) - setProxyPort(port); - else - log.warn("Proxy port is out of range!: " + port); - } - - // Set Default BKU - String bkuString = config.getProperty(Constants.CFG_BKU); - BKUs defaultBKU = BKUs.NONE; - if (bkuString != null) { - try { - defaultBKU = BKUs.valueOf(bkuString); - } catch (IllegalArgumentException ex) { - log.error("Invalid BKU config value " + bkuString + " using none!"); - defaultBKU = BKUs.NONE; - } catch (NullPointerException ex) { - log.error("Invalid BKU config value " + bkuString + " using none!"); - defaultBKU = BKUs.NONE; - } - } - setDefaultBKU(defaultBKU); - - // Set Signature placeholder transparency - int transparency = Constants.DEFAULT_SIGNATURE_PLACEHOLDER_TRANSPARENCY; - String trans = config.getProperty(Constants.CFG_SIGNATURE_PLACEHOLDER_TRANSPARENCY); - if (trans != null) { - try { - transparency = Integer.parseInt(trans); - } catch (NumberFormatException e) { - log.debug("Couldn't parse placeholder transparency", e); - // ignore parsing exception - } - } - setPlaceholderTransparency(transparency); - - // Set MainWindow size - int width = Constants.DEFAULT_MAINWINDOW_WIDTH; - int height = Constants.DEFAULT_MAINWINDOW_HEIGHT; - String size = config.getProperty(Constants.CFG_MAINWINDOW_SIZE); - parse: { - if (size == null) - break parse; - int pos = size.indexOf(','); - if (pos <= 0) - break parse; - - try { - width = Integer.parseInt(size.substring(0, pos).trim()); - height = Integer.parseInt(size.substring(pos + 1).trim()); - } catch (NumberFormatException e) { - log.debug("Couldn't parse main window size", e); - // ignore parsing exception - } - } - this.configuration.mainWindowSize = new Point(width, height); - - // Set Signature Position - String signaturePosition = config.getProperty(Constants.CFG_SIGNATURE_POSITION); - SignaturePosition position = null; - if (signaturePosition != null && !signaturePosition.trim().isEmpty()) { - signaturePosition = signaturePosition.trim().toLowerCase(); - - Pattern pattern = Pattern.compile("(x=(\\d\\.?\\d?);y=(\\d\\.?\\d?);p=(\\d))|(auto)|(x=(\\d\\.?\\d?);y=(\\d\\.?\\d?))"); - Matcher matcher = pattern.matcher(signaturePosition); - if (matcher.matches()) { - if (matcher.groupCount() == 8) { - if (matcher.group(1) != null) { - // we have format: x=..;y=..;p=... - try { - // group 2 = x value - float x = Float.parseFloat(matcher.group(2)); - - // group 3 = y value - float y = Float.parseFloat(matcher.group(3)); - - // group 4 = p value - int p = Integer.parseInt(matcher.group(3)); - - position = new SignaturePosition(x, y, p); - } catch (NumberFormatException ex) { - log.error( - "Signature Position read from config failed: Not a valid number", ex); - } - } else if (matcher.group(5) != null) { - // we have format auto - position = new SignaturePosition(); - } else if (matcher.group(6) != null) { - // we have format x=...;y=...; - // group 7 = x value - float x = Float.parseFloat(matcher.group(7)); - - // group 8 = y value - float y = Float.parseFloat(matcher.group(8)); - - position = new SignaturePosition(x, y); - } - } else { - log.error("Signature Position read from config failed: wrong group Count!"); - } - } else { - log.error("Signature Position read from config failed: not matching string"); - } - } - setDefaultSignaturePosition(position); - - //Set keystore stuff - String keystoreEnabled = config.getProperty(Constants.CFG_KEYSTORE_ENABLED); - if (keystoreEnabled != null) - setKeyStoreEnabled(keystoreEnabled.equalsIgnoreCase(Constants.TRUE)); - setKeyStoreFile(config.getProperty(Constants.CFG_KEYSTORE_FILE)); - setKeyStoreType(config.getProperty(Constants.CFG_KEYSTORE_TYPE)); - setKeyStoreAlias(config.getProperty(Constants.CFG_KEYSTORE_ALIAS)); - setKeyStoreStorePass(config.getProperty(Constants.CFG_KEYSTORE_STOREPASS)); - String keystoreKeyPass = config.getProperty(Constants.CFG_KEYSTORE_KEYPASS); - setKeyStoreKeyPass(keystoreKeyPass); - - // Set update check - String updateCheck = config.getProperty(Constants.CFG_UPDATE_CHECK); - if (updateCheck != null) - setUpdateCheck(!updateCheck.equalsIgnoreCase(Constants.FALSE)); - - log.info("Successfully loaded config from: " + getConfigurationFileName()); - } - - /* save to file */ - public void saveToDisk() throws IOException { - String filename = this.getConfigurationFileName(); - File configFile = new File(Constants.CONFIG_DIRECTORY + File.separator + filename); - - Properties props = new Properties(); - props.clear(); - - props.setProperty(Constants.CFG_BKU, getDefaultBKUPersistent().toString()); - - String proxyHost = getProxyHostPersistent(); - if (proxyHost != STRING_EMPTY) - props.setProperty(Constants.CFG_PROXY_HOST, proxyHost); - int proxyPort = getProxyPortPersistent(); - if (proxyPort != -1) - props.setProperty(Constants.CFG_PROXY_PORT,Integer.toString(proxyPort)); - String proxyUser = getProxyUserPersistent(); - if (proxyUser != STRING_EMPTY) - props.setProperty(Constants.CFG_PROXY_USER, proxyUser); - String proxyPass = getProxyPassPersistent(); - if (proxyPass != STRING_EMPTY) - props.setProperty(Constants.CFG_PROXY_PASS, proxyPass); - - props.setProperty(Constants.CFG_EMBLEM, getDefaultEmblemPersistent()); - props.setProperty(Constants.CFG_SIGNATURE_NOTE, getSignatureNote()); - props.setProperty(Constants.CFG_MOBILE_NUMBER, getDefaultMobileNumberPersistent()); - props.setProperty(Constants.CFG_OUTPUT_FOLDER, getDefaultOutputFolderPersistent()); - props.setProperty(Constants.CFG_POSTFIX, getSaveFilePostFix()); - props.setProperty(Constants.CFG_SIGNATURE_PLACEHOLDER_TRANSPARENCY, - Integer.toString(getPlaceholderTransparency())); - - Point size = this.configuration.mainWindowSize; - props.setProperty(Constants.CFG_MAINWINDOW_SIZE, size.x + "," + size.y); - - Locale configLocale = getLocale(); - if(configLocale != null) { - props.setProperty(Constants.CFG_LOCALE, LocaleSerializer.getParsableString(configLocale)); - } - - Locale signatureLocale = this.getSignatureLocale(); - if(signatureLocale != null) { - props.setProperty(Constants.CFG_SIGNATURE_LOCALE, LocaleSerializer.getParsableString(signatureLocale)); - } - - if (getUseMarker()) - props.setProperty(Constants.CFG_USE_MARKER, Constants.TRUE); - - if (getUseSignatureFields()) { - props.setProperty(Constants.CFG_USE_SIGNATURE_FIELDS, Constants.TRUE); - } - - if (getEnablePlaceholderUsage()) { - props.setProperty(Constants.CFG_ENABLE_PLACEHOLDER, Constants.TRUE); - } - - if (getSignaturePdfACompat()) - props.setProperty(Constants.CFG_SIGNATURE_PDFA_COMPAT, Constants.TRUE); - - SignaturePosition pos = getDefaultSignaturePositionPersistent(); - if (pos == null) { - props.setProperty(Constants.CFG_SIGNATURE_POSITION, ""); - } else if (pos.useAutoPositioning()) { - props.setProperty(Constants.CFG_SIGNATURE_POSITION, "auto"); - } else { - props.setProperty(Constants.CFG_SIGNATURE_POSITION, - String.format((Locale) null, "x=%f;y=%f;p=%d", - pos.getX(), pos.getY(), pos.getPage())); - } - - String mobileBKUURL = getMobileBKUURL(); - if (!mobileBKUURL.equals(Constants.DEFAULT_MOBILE_BKU_URL)) - props.setProperty(Constants.CFG_MOBILE_BKU_URL, mobileBKUURL); - - MobileBKUs mobileBKUType = getMobileBKUType(); - if (mobileBKUType != DEFAULT_MOBILE_BKU_TYPE) - props.setProperty(Constants.CFG_MOBILE_BKU_TYPE, mobileBKUType.toString()); - - if (getMobileBKUBase64()) - props.setProperty(Constants.CFG_MOBILE_BKU_BASE64, Constants.TRUE); - - if (Constants.THEME != Constants.Themes.DEFAULT) - props.setProperty(Constants.CFG_THEME, Constants.THEME.name()); - - if (getKeyStoreEnabledPersistent()) - props.setProperty(Constants.CFG_KEYSTORE_ENABLED, Constants.TRUE); - String keystoreFile = getKeyStoreFilePersistent(); - if (keystoreFile != STRING_EMPTY) - props.setProperty(Constants.CFG_KEYSTORE_FILE, keystoreFile); - String keystoreType = getKeyStoreTypePersistent(); - if (keystoreType != STRING_EMPTY) - props.setProperty(Constants.CFG_KEYSTORE_TYPE, keystoreType); - String keystoreAlias = getKeyStoreAliasPersistent(); - if (keystoreAlias != STRING_EMPTY) - props.setProperty(Constants.CFG_KEYSTORE_ALIAS, keystoreAlias); - String keystoreStorePass = getKeyStoreStorePassPersistent(); - if (keystoreStorePass != STRING_EMPTY) - props.setProperty(Constants.CFG_KEYSTORE_STOREPASS, keystoreStorePass); - String keystoreKeyPass = getKeyStoreKeyPassPersistent(); - if (keystoreKeyPass != STRING_EMPTY) - props.setProperty(Constants.CFG_KEYSTORE_KEYPASS, keystoreKeyPass); - - if (!getUpdateCheck()) - props.setProperty(Constants.CFG_UPDATE_CHECK, Constants.FALSE); - - props.setProperty(Constants.SIGNATURE_PROFILE, getSignatureProfile()); - - - FileOutputStream outputstream = new FileOutputStream(configFile, false); - - props.store(outputstream, "Configuration file was generated!"); - - log.info("Configuration file saved to " + configFile.getAbsolutePath()); - } - - // TODO review this - public void setConfigurationFileName(String configurationFile) { this.configurationFile = configurationFile; } - public String getConfigurationFileName() { return this.configurationFile; } - - public void setDefaultBKU(BKUs bku) { - this.configuration.defaultBKU = bku; - } - - public void setDefaultBKUOverlay(BKUs bku) { - this.configurationOverlay.defaultBKU = bku; - } - - public BKUs getDefaultBKU() { - BKUs bku = this.configurationOverlay.defaultBKU; - if (bku == BKUs.NONE) - bku = getDefaultBKUPersistent(); - return bku; - } - - public BKUs getDefaultBKUPersistent() { - return this.configuration.defaultBKU; - } - - public void setDefaultSignaturePosition(SignaturePosition signaturePosition) { - this.configuration.defaultSignaturePosition = signaturePosition; - } - - public void setDefaultSignaturePositionOverlay(SignaturePosition signaturePosition) { - this.configurationOverlay.defaultSignaturePosition = signaturePosition; - } - - public SignaturePosition getDefaultSignaturePosition() { - SignaturePosition position = this.configurationOverlay.defaultSignaturePosition; - if (position == null) - position = getDefaultSignaturePositionPersistent(); - return position; - } - - public SignaturePosition getDefaultSignaturePositionPersistent() { - return this.configuration.defaultSignaturePosition; - } - - public void setPlaceholderTransparency(int transparency) { - this.configuration.placeholderTransparency = transparency; - } - - public int getPlaceholderTransparency() { - return this.configuration.placeholderTransparency; - } - - public void setDefaultMobileNumber(String number) { - if (number == null || number.trim().isEmpty()) { - this.configuration.setMobileNumber(STRING_EMPTY); - } else { - this.configuration.setMobileNumber(number); - } - } - - public void setDefaultMobileNumberOverlay(String number) { - if (number == null || number.trim().isEmpty()) { - this.configurationOverlay.setMobileNumber(STRING_EMPTY); - } else { - this.configurationOverlay.setMobileNumber(number); - } - } - - public String getDefaultMobileNumber() { - String number = this.configurationOverlay.getMobileNumber(); - if (number == null) - number = getDefaultMobileNumberPersistent(); - return number; - } - - public String getDefaultMobileNumberPersistent() { - String number = this.configuration.getMobileNumber(); - if (number == null) - number = STRING_EMPTY; - return number; - } - - public void setDefaultMobilePassword(String password) { - if (password == null || password.trim().isEmpty()) { - this.configuration.mobilePassword = STRING_EMPTY; - } else { - this.configuration.mobilePassword = password; - } - } - - public void setDefaultMobilePasswordOverlay(String password) { - if (password == null || password.trim().isEmpty()) { - this.configurationOverlay.mobilePassword = STRING_EMPTY; - } else { - this.configurationOverlay.mobilePassword = password; - } - } - - public String getDefaultMobilePassword() { - String password = this.configurationOverlay.mobilePassword; - if (password == null) - password = getDefaultMobilePasswordPersistent(); - return password; - } - - public String getDefaultMobilePasswordPersistent() { - String password = this.configuration.mobilePassword; - if (password == null) - password = STRING_EMPTY; - return password; - } - - public void setDefaultEmblem(String emblem) { - try { - if (emblem == null || emblem.trim().isEmpty()) { - this.configuration.setEmblem(STRING_EMPTY); - } else { - this.configuration.setEmblem(emblem); - } - } catch (InvalidEmblemFile e) { - log.error("Error setting emblem file", e); - try { - this.configuration.setEmblem(STRING_EMPTY); - } catch (InvalidEmblemFile e1) { - // Ignore - } - } - } - - public void setDefaultEmblemOverlay(String emblem) { - try { - if (emblem == null || emblem.trim().isEmpty()) { - this.configurationOverlay.setEmblem(STRING_EMPTY); - } else { - this.configurationOverlay.setEmblem(emblem); - } - } catch (InvalidEmblemFile e) { - log.error("Error setting emblem file", e); - try { - this.configurationOverlay.setEmblem(STRING_EMPTY); - } catch (InvalidEmblemFile e1) { - // Ignore - } - } - } - - public String getDefaultEmblem() { - String emblem = this.configurationOverlay.getEmblem(); - if (emblem == null) - emblem = getDefaultEmblemPersistent(); - return emblem; - } - - public String getDefaultEmblemPersistent() { - String emblem = this.configuration.getEmblem(); - if (emblem == null) - emblem = STRING_EMPTY; - return emblem; - } - - public void setProxyHost(String host) { - if (host == null || host.trim().isEmpty()) { - this.configuration.proxyHost = STRING_EMPTY; - } else { - this.configuration.proxyHost = host; - } - } - - public void setProxyHostOverlay(String host) { - if (host == null || host.trim().isEmpty()) { - this.configurationOverlay.proxyHost = STRING_EMPTY; - } else { - this.configurationOverlay.proxyHost = host; - } - } - - public String getProxyHost() { - String host = this.configurationOverlay.proxyHost; - if (host == null) - host = getProxyHostPersistent(); - return host; - } - - public String getProxyHostPersistent() { - String host = this.configuration.proxyHost; - if (host == null) - host = STRING_EMPTY; - return host; - } - - public void setProxyPort(int port) { - try { - this.configuration.setProxyPort(port); - } catch (InvalidPortException e) { - log.error("Error setting proxy port" , e); - // ignore - } - } - - public void setProxyPortOverlay(int port) { - try { - this.configurationOverlay.setProxyPort(port); - } catch (InvalidPortException e) { - log.error("Error setting proxy port" , e); - // ignore - } - } - - public int getProxyPort() { - int port = this.configurationOverlay.getProxyPort(); - if (port == -1) - port = getProxyPortPersistent(); - return port; - } - - public int getProxyPortPersistent() { - return this.configuration.getProxyPort(); - } - - public void setProxyUser(String user) { - if (user == null || user.trim().isEmpty()) { - this.configuration.proxyUser = STRING_EMPTY; - } else { - this.configuration.proxyUser = user; - } - } - - public void setProxyUserOverlay(String user) { - if (user == null || user.trim().isEmpty()) { - this.configurationOverlay.proxyUser = STRING_EMPTY; - } else { - this.configurationOverlay.proxyUser = user; - } - } - - public String getProxyUser() { - String user = this.configurationOverlay.proxyUser; - if (user == null) - user = getProxyUserPersistent(); - return user; - } - - public String getProxyUserPersistent() { - String user = this.configuration.proxyUser; - if (user == null) - user = STRING_EMPTY; - return user; - } - - public void setProxyPass(String pass) { - if (pass == null || pass.trim().isEmpty()) { - this.configuration.proxyPass = STRING_EMPTY; - } else { - this.configuration.proxyPass = pass; - } - } - - public void setProxyPassOverlay(String pass) { - if (pass == null || pass.trim().isEmpty()) { - this.configurationOverlay.proxyPass = STRING_EMPTY; - } else { - this.configurationOverlay.proxyPass = pass; - } - } - - public String getProxyPass() { - String pass = this.configurationOverlay.proxyPass; - if (pass == null) - pass = getProxyPassPersistent(); - return pass; - } - - public String getProxyPassPersistent() { - String pass = this.configuration.proxyPass; - if (pass == null) - pass = STRING_EMPTY; - return pass; - } - - public void setDefaultOutputFolder(String outputFolder) { - if (outputFolder == null || outputFolder.trim().isEmpty()) { - this.configuration.outputFolder = STRING_EMPTY; - } else { - this.configuration.outputFolder = outputFolder; - } - } - - public void setDefaultOutputFolderOverlay(String outputFolder) { - if (outputFolder == null || outputFolder.trim().isEmpty()) { - this.configurationOverlay.outputFolder = STRING_EMPTY; - } else { - this.configurationOverlay.outputFolder = outputFolder; - } - } - - public String getDefaultOutputFolder() { - String outputFolder = this.configurationOverlay.outputFolder; - if (outputFolder == null) - outputFolder = getDefaultOutputFolderPersistent(); - return outputFolder; - } - - public String getDefaultOutputFolderPersistent() { - String outputFolder = this.configuration.outputFolder; - if (outputFolder == null) - outputFolder = STRING_EMPTY; - return outputFolder; - } - - public String getMobileBKUURL() { - return this.configuration.mobileBKUURL; - } - - public MobileBKUs getMobileBKUType() { - return this.configuration.mobileBKUType; - } - - public boolean getMobileBKUBase64() { - return this.configuration.mobileBKUBase64; - } - - public void setSignatureNote(String note) { - if (note == null || note.trim().isEmpty()) { - this.configuration.signatureNote = STRING_EMPTY; - } else { - this.configuration.signatureNote = note; - } - } - - public String getSignatureNote() { - String note = this.configuration.signatureNote; - if (note == null) - note = STRING_EMPTY; - return note; - } - - public void setLocale(Locale locale) { - if(locale == null) { - this.configuration.locale = Messages.getDefaultLocale(); - } else { - this.configuration.locale = locale; - Locale.setDefault(locale); - Messages.setLocale(locale); - } - } - - public Locale getLocale() { - Locale locale = this.configuration.locale; - if (locale == null) - locale = Messages.getDefaultLocale(); - return locale; - } - - public void setSignatureLocale(Locale locale) { - if(locale == null) { - this.configuration.signatureLocale = Messages.getDefaultLocale(); - } else { - this.configuration.signatureLocale = locale; - } - } - - public Locale getSignatureLocale() { - Locale locale = this.configuration.signatureLocale; - if (locale == null) - locale = Messages.getDefaultLocale(); - return locale; - } - - public void setSignaturePdfACompat(boolean compat) { - this.configuration.signaturePDFACompat = compat; - } - - public boolean getSignaturePdfACompat() { - return this.configuration.signaturePDFACompat; - } - - public void setKeyStoreEnabled(Boolean enabled) { - this.configuration.keystoreEnabled = enabled; - } - - public void setKeyStoreEnabledOverlay(Boolean enabled) { - this.configurationOverlay.keystoreEnabled = enabled; - } - - public Boolean getKeyStoreEnabled() { - Boolean enabled = this.configurationOverlay.keystoreEnabled; - if (enabled == null) - enabled = getKeyStoreEnabledPersistent(); - return enabled; - } - - public Boolean getKeyStoreEnabledPersistent() { - Boolean enabled = this.configuration.keystoreEnabled; - if (enabled == null) - enabled = false; - return enabled; - } - - public void setKeyStoreFile(String file) { - if (file == null || file.trim().isEmpty()) { - this.configuration.keystoreFile = STRING_EMPTY; - } else { - this.configuration.keystoreFile = file; - } - } - - public void setKeyStoreFileOverlay(String file) { - if (file == null || file.trim().isEmpty()) { - this.configurationOverlay.keystoreFile = STRING_EMPTY; - } else { - this.configurationOverlay.keystoreFile = file; - } - } - - public String getKeyStoreFile() { - String file = this.configurationOverlay.keystoreFile; - if (file == null) - file = getKeyStoreFilePersistent(); - return file; - } - - public String getKeyStoreFilePersistent() { - String file = this.configuration.keystoreFile; - if (file == null) - file = STRING_EMPTY; - return file; - } - - public void setKeyStoreType(String type) { - if (type == null || type.trim().isEmpty()) { - this.configuration.keystoreType = STRING_EMPTY; - } else { - this.configuration.keystoreType = type; - } - } - - public void setKeyStoreTypeOverlay(String type) { - if (type == null || type.trim().isEmpty()) { - this.configurationOverlay.keystoreType = STRING_EMPTY; - } else { - this.configurationOverlay.keystoreType = type; - } - } - - public String getKeyStoreType() { - String type = this.configurationOverlay.keystoreType; - if (type == null) - type = getKeyStoreTypePersistent(); - return type; - } - - public String getKeyStoreTypePersistent() { - String type = this.configuration.keystoreType; - if (type == null) - type = STRING_EMPTY; - return type; - } - - public void setKeyStoreAlias(String alias) { - if (alias == null || alias.trim().isEmpty()) { - this.configuration.keystoreAlias = STRING_EMPTY; - } else { - this.configuration.keystoreAlias = alias; - } - } - - public void setKeyStoreAliasOverlay(String alias) { - if (alias == null || alias.trim().isEmpty()) { - this.configurationOverlay.keystoreAlias = STRING_EMPTY; - } else { - this.configurationOverlay.keystoreAlias = alias; - } - } - - public String getKeyStoreAlias() { - String alias = this.configurationOverlay.keystoreAlias; - if (alias == null) - alias = getKeyStoreAliasPersistent(); - return alias; - } - - public String getKeyStoreAliasPersistent() { - String alias = this.configuration.keystoreAlias; - if (alias == null) - alias = STRING_EMPTY; - return alias; - } - - public void setKeyStoreStorePass(String storePass) { - if (storePass == null || storePass.trim().isEmpty()) { - this.configuration.keystoreStorePass = STRING_EMPTY; - } else { - this.configuration.keystoreStorePass = storePass; - } - } - - public void setKeyStoreStorePassOverlay(String storePass) { - if (storePass == null || storePass.trim().isEmpty()) { - this.configurationOverlay.keystoreStorePass = STRING_EMPTY; - } else { - this.configurationOverlay.keystoreStorePass = storePass; - } - } - - public String getKeyStoreStorePass() { - String storePass = this.configurationOverlay.keystoreStorePass; - if (storePass != null) - return storePass; - return getKeyStoreStorePassPersistent(); - } - - public String getKeyStoreStorePassPersistent() { - String storePass = this.configuration.keystoreStorePass; - if (storePass == null) - storePass = STRING_EMPTY; - return storePass; - } - - public void setKeyStoreKeyPass(String keyPass) { - if (keyPass == null || keyPass.trim().isEmpty()) { - this.configuration.keystoreKeyPass = STRING_EMPTY; - } else { - this.configuration.keystoreKeyPass = keyPass; - } - } - - public void setKeyStoreKeyPassOverlay(String keyPass) { - if (keyPass == null || keyPass.trim().isEmpty()) { - this.configurationOverlay.keystoreKeyPass = STRING_EMPTY; - } else { - this.configurationOverlay.keystoreKeyPass = keyPass; - } - } - - public String getKeyStoreKeyPass() { - String keyPass = this.configurationOverlay.keystoreKeyPass; - if (keyPass != null) - return keyPass; - return getKeyStoreKeyPassPersistent(); - } - - public String getKeyStoreKeyPassPersistent() { - String keyPass = this.configuration.keystoreKeyPass; - if (keyPass == null) - keyPass = STRING_EMPTY; - return keyPass; - } - - public void setUpdateCheck(boolean checkUpdate) { - this.configuration.updateCheck = checkUpdate; - } - - public boolean getUpdateCheck() { - return this.configuration.updateCheck; - } - - public void setMainWindowSize(Point size) { - this.configuration.mainWindowSize = size; - } - - public Point getMainWindowSize() { - return this.configuration.mainWindowSize; - } - - public boolean getSkipFinish() { - return this.configurationOverlay.skipFinish; - } - - public void setSkipFinishOverlay(boolean skipFinish) { - this.configurationOverlay.skipFinish = skipFinish; - } - - public boolean getUseMarker() { - return this.configurationOverlay.getUseMarker(); - } - - public boolean getUseSignatureFields() { - return this.configurationOverlay.getUseSignatureFields(); - } - - public void setUseMarker(boolean useMarker) { - this.configurationOverlay.setUseMarker(useMarker); - if (useMarker) setUseSignatureFields(false); - } - - public void setUseSignatureFields(boolean useFields) { - this.configurationOverlay.setUseSignatureFields(useFields); - if (useFields) setUseMarker(false); - } - - public void setSignatureProfile(String profile) { - this.configurationOverlay.setSignatureProfile(Profile.getProfile(profile)); - } - - public void setSaveFilePostFix(String postFix) { - this.configurationOverlay.saveFilePostFix = postFix; - } - - public String getSaveFilePostFix(){ - return this.configurationOverlay.saveFilePostFix; - } - - public String getSignatureProfile() { - return this.configurationOverlay.getSignatureProfile().name(); - } - - public void setEnablePlaceholderUsage(boolean bool) { - this.configurationOverlay.enabledPlaceholderUsage = bool; - } - - public boolean getEnablePlaceholderUsage() { - return this.configurationOverlay.enabledPlaceholderUsage; - } - - - -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationContainer.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationContainer.java deleted file mode 100644 index b238da01..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationContainer.java +++ /dev/null @@ -1,194 +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.gui.workflow.config; - -// Imports -import java.io.File; -import java.io.FileNotFoundException; -import java.util.Locale; - -import at.asit.pdfover.commons.Profile; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.graphics.ImageData; -import org.eclipse.swt.graphics.Point; -import org.eclipse.swt.widgets.Display; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.asit.pdfover.commons.Constants; -import at.asit.pdfover.gui.bku.mobile.MobileBKUHelper; -import at.asit.pdfover.gui.bku.mobile.MobileBKUs; -import at.asit.pdfover.gui.exceptions.InvalidEmblemFile; -import at.asit.pdfover.gui.exceptions.InvalidPortException; -import at.asit.pdfover.signator.BKUs; -import at.asit.pdfover.signator.SignaturePosition; - -/** - * Implementation of the configuration container - */ -public class ConfigurationContainer { - /** - * SLF4J Logger instance - **/ - @SuppressWarnings("unused") - private static final Logger log = LoggerFactory.getLogger(ConfigurationContainer.class); - - /** the emblem File */ - protected String emblemFile = null; - public String getEmblem() { return this.emblemFile; } - public void setEmblem(String emblemFile) throws InvalidEmblemFile { - if (emblemFile == null || emblemFile.trim().isEmpty()) { - // Ok to set no file ... - } else { - File imageFile = new File(emblemFile); - if (!imageFile.exists()) { - throw new InvalidEmblemFile(imageFile, - new FileNotFoundException(emblemFile)); - } - - try { - Image img = new Image(Display.getDefault(), new ImageData( - emblemFile)); - - img.dispose(); - } catch (Exception ex) { - throw new InvalidEmblemFile(imageFile, ex); - } - } - - this.emblemFile = emblemFile; - } - - /** The mobile phone number */ - protected String mobileNumber = null; - public String getMobileNumber() { return this.mobileNumber; } - public void setMobileNumber(String number) { - if(number == null || number.trim().isEmpty()) { - this.mobileNumber = null; - return; - } - this.mobileNumber = MobileBKUHelper.normalizeMobileNumber(number); - } - - /** The mobile phone password */ - public String mobilePassword = null; - - /** Holds the proxy host */ - public String proxyHost = null; - - /** Holds the proxy port number */ - protected int proxyPort = -1; - public int getProxyPort() { return this.proxyPort; } - public void setProxyPort(int port) throws InvalidPortException { - if(port > 0 && port <= 0xFFFF) { - this.proxyPort = port; - return; - } - if(port == -1) { - this.proxyPort = -1; - return; - } - throw new InvalidPortException(port); - } - - /** Holds the proxy username */ - public String proxyUser = null; - - /** Holds the proxy password */ - public String proxyPass = null; - - /** Holds the transparency of the signature placeholder */ - public int placeholderTransparency = Constants.DEFAULT_SIGNATURE_PLACEHOLDER_TRANSPARENCY; - - /** Holds the default BKU to use */ - public BKUs defaultBKU = BKUs.NONE; - - /** Holds the output folder */ - public String outputFolder = null; - - /** Holds the signatureNote */ - public String signatureNote = null; - - /** Holds the locale */ - public Locale locale = null; - - /** Holds the signature locale */ - public Locale signatureLocale = null; - - /** Holds the PDF/A compatibility setting */ - public boolean signaturePDFACompat = false; - - /** Holds the mobile BKU URL */ - public String mobileBKUURL = Constants.DEFAULT_MOBILE_BKU_URL; - - /** Holds the mobile BKU type */ - public MobileBKUs mobileBKUType = ConfigProviderImpl.DEFAULT_MOBILE_BKU_TYPE; - - /** Holds the mobile BKU BASE64 setting */ - protected boolean mobileBKUBase64 = false; - - /** Holds the default signature position */ - public SignaturePosition defaultSignaturePosition = null; - - /** Keystore signing options */ - public Boolean keystoreEnabled = null; - public String keystoreFile = null; - public String keystoreType = null; - public String keystoreAlias = null; - public String keystoreStorePass = null; - public String keystoreKeyPass = null; - - /** Whether to automatically check for updates */ - public boolean updateCheck = true; - - /** Holds the main window size */ - public Point mainWindowSize = null; - - /** Whether to skip the output state */ - public boolean skipFinish = false; - - /** Whether to use an existing signature marker. */ - protected boolean useMarker = false; - public boolean getUseMarker() { return this.useMarker; } - public void setUseMarker(boolean useMarker) { - this.useMarker = useMarker; - if (useMarker) setUseSignatureFields(false); - } - - /** Either QR-Code or signature fields as marker */ - protected boolean useSignatureFields = false; - public boolean getUseSignatureFields() { return this.useSignatureFields; } - public void setUseSignatureFields(boolean useFields) { - this.useSignatureFields = useFields; - if (useFields) setUseMarker(false); - } - - /** describes if the placeholder search is enabled */ - public boolean enabledPlaceholderUsage = false; - - /** The Signature Profile */ - protected Profile signatureProfile = null; - public Profile getSignatureProfile() { - if (this.signatureProfile == null) { - this.signatureProfile = Profile.SIGNATURBLOCK_SMALL; - } - return this.signatureProfile; - } - public void setSignatureProfile(Profile profile) { this.signatureProfile = profile; } - - public String saveFilePostFix = "_signed"; - -} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationDataInMemory.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationDataInMemory.java new file mode 100644 index 00000000..c59da748 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationDataInMemory.java @@ -0,0 +1,194 @@ +/* + * 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.gui.workflow.config; + +// Imports +import java.io.File; +import java.io.FileNotFoundException; +import java.util.Locale; + +import at.asit.pdfover.commons.Profile; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.widgets.Display; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.asit.pdfover.commons.Constants; +import at.asit.pdfover.gui.bku.mobile.MobileBKUHelper; +import at.asit.pdfover.gui.bku.mobile.MobileBKUs; +import at.asit.pdfover.gui.exceptions.InvalidEmblemFile; +import at.asit.pdfover.gui.exceptions.InvalidPortException; +import at.asit.pdfover.signator.BKUs; +import at.asit.pdfover.signator.SignaturePosition; + +/** + * Implementation of the configuration container + */ +public class ConfigurationDataInMemory { + /** + * SLF4J Logger instance + **/ + @SuppressWarnings("unused") + private static final Logger log = LoggerFactory.getLogger(ConfigurationDataInMemory.class); + + /** the emblem File */ + protected String emblemFile = null; + public String getEmblem() { return this.emblemFile; } + public void setEmblem(String emblemFile) throws InvalidEmblemFile { + if (emblemFile == null || emblemFile.trim().isEmpty()) { + // Ok to set no file ... + } else { + File imageFile = new File(emblemFile); + if (!imageFile.exists()) { + throw new InvalidEmblemFile(imageFile, + new FileNotFoundException(emblemFile)); + } + + try { + Image img = new Image(Display.getDefault(), new ImageData( + emblemFile)); + + img.dispose(); + } catch (Exception ex) { + throw new InvalidEmblemFile(imageFile, ex); + } + } + + this.emblemFile = emblemFile; + } + + /** The mobile phone number */ + protected String mobileNumber = null; + public String getMobileNumber() { return this.mobileNumber; } + public void setMobileNumber(String number) { + if(number == null || number.trim().isEmpty()) { + this.mobileNumber = null; + return; + } + this.mobileNumber = MobileBKUHelper.normalizeMobileNumber(number); + } + + /** The mobile phone password */ + public String mobilePassword = null; + + /** Holds the proxy host */ + public String proxyHost = null; + + /** Holds the proxy port number */ + protected int proxyPort = -1; + public int getProxyPort() { return this.proxyPort; } + public void setProxyPort(int port) throws InvalidPortException { + if(port > 0 && port <= 0xFFFF) { + this.proxyPort = port; + return; + } + if(port == -1) { + this.proxyPort = -1; + return; + } + throw new InvalidPortException(port); + } + + /** Holds the proxy username */ + public String proxyUser = null; + + /** Holds the proxy password */ + public String proxyPass = null; + + /** Holds the transparency of the signature placeholder */ + public int placeholderTransparency = Constants.DEFAULT_SIGNATURE_PLACEHOLDER_TRANSPARENCY; + + /** Holds the default BKU to use */ + public BKUs defaultBKU = BKUs.NONE; + + /** Holds the output folder */ + public String outputFolder = null; + + /** Holds the signatureNote */ + public String signatureNote = null; + + /** Holds the locale */ + public Locale locale = null; + + /** Holds the signature locale */ + public Locale signatureLocale = null; + + /** Holds the PDF/A compatibility setting */ + public boolean signaturePDFACompat = false; + + /** Holds the mobile BKU URL */ + public String mobileBKUURL = Constants.DEFAULT_MOBILE_BKU_URL; + + /** Holds the mobile BKU type */ + public MobileBKUs mobileBKUType = ConfigurationManager.DEFAULT_MOBILE_BKU_TYPE; + + /** Holds the mobile BKU BASE64 setting */ + protected boolean mobileBKUBase64 = false; + + /** Holds the default signature position */ + public SignaturePosition defaultSignaturePosition = null; + + /** Keystore signing options */ + public Boolean keystoreEnabled = null; + public String keystoreFile = null; + public String keystoreType = null; + public String keystoreAlias = null; + public String keystoreStorePass = null; + public String keystoreKeyPass = null; + + /** Whether to automatically check for updates */ + public boolean updateCheck = true; + + /** Holds the main window size */ + public Point mainWindowSize = null; + + /** Whether to skip the output state */ + public boolean skipFinish = false; + + /** Whether to use an existing signature marker. */ + protected boolean useMarker = false; + public boolean getUseMarker() { return this.useMarker; } + public void setUseMarker(boolean useMarker) { + this.useMarker = useMarker; + if (useMarker) setUseSignatureFields(false); + } + + /** Either QR-Code or signature fields as marker */ + protected boolean useSignatureFields = false; + public boolean getUseSignatureFields() { return this.useSignatureFields; } + public void setUseSignatureFields(boolean useFields) { + this.useSignatureFields = useFields; + if (useFields) setUseMarker(false); + } + + /** describes if the placeholder search is enabled */ + public boolean enabledPlaceholderUsage = false; + + /** The Signature Profile */ + protected Profile signatureProfile = null; + public Profile getSignatureProfile() { + if (this.signatureProfile == null) { + this.signatureProfile = Profile.SIGNATURBLOCK_SMALL; + } + return this.signatureProfile; + } + public void setSignatureProfile(Profile profile) { this.signatureProfile = profile; } + + public String saveFilePostFix = "_signed"; + +} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationManager.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationManager.java new file mode 100644 index 00000000..7823ca41 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationManager.java @@ -0,0 +1,1030 @@ +/* + * 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.gui.workflow.config; + +// Imports +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Locale; +import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import at.asit.pdfover.commons.Profile; +import org.eclipse.swt.graphics.Point; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.asit.pdfover.commons.Constants; +import at.asit.pdfover.gui.bku.mobile.MobileBKUs; +import at.asit.pdfover.gui.exceptions.InvalidEmblemFile; +import at.asit.pdfover.gui.exceptions.InvalidPortException; +import at.asit.pdfover.gui.utils.LocaleSerializer; +import at.asit.pdfover.commons.Messages; +import at.asit.pdfover.signator.BKUs; +import at.asit.pdfover.signator.SignaturePosition; + +// TODO: review which properties use the overlay in this file (also: remove unneeded setters/getters, maybe template impl for overlays?) + +/** + * Implementation of the configuration provider and manipulator + */ +public class ConfigurationManager { + + + /** Default Mobile BKU type */ + public static final MobileBKUs DEFAULT_MOBILE_BKU_TYPE = MobileBKUs.A_TRUST; + + + /** + * SLF4J Logger instance + **/ + private static final Logger log = LoggerFactory.getLogger(ConfigurationManager.class); + + /** + * An empty property entry + */ + private static final String STRING_EMPTY = ""; + + private String configurationFile = Constants.DEFAULT_CONFIG_FILENAME; + + private boolean loaded = false; + + // The persistent configuration read from the config file + private ConfigurationDataInMemory configuration; + + // The configuration overlay built from the cmd line args + private ConfigurationDataInMemory configurationOverlay; + + /** + * Constructor + */ + public ConfigurationManager() { + this.configuration = new ConfigurationDataInMemory(); + this.configurationOverlay = new ConfigurationDataInMemory(); + } + + /* load from disk */ + public void loadFromDisk() throws IOException { + if (loaded) + throw new RuntimeException("ConfigProvider double load?"); + + Properties diskConfig = new Properties(); + + diskConfig.load(new FileInputStream(Constants.CONFIG_DIRECTORY + File.separator + getConfigurationFileName())); + + setDefaultEmblem(diskConfig.getProperty(Constants.CFG_EMBLEM)); + + setDefaultMobileNumber(diskConfig.getProperty(Constants.CFG_MOBILE_NUMBER)); + + setProxyHost(diskConfig.getProperty(Constants.CFG_PROXY_HOST)); + setProxyUser(diskConfig.getProperty(Constants.CFG_PROXY_USER)); + setProxyPass(diskConfig.getProperty(Constants.CFG_PROXY_PASS)); + + setDefaultOutputFolder(diskConfig.getProperty(Constants.CFG_OUTPUT_FOLDER)); + + String postFix = diskConfig.getProperty(Constants.CFG_POSTFIX); + if (postFix == null) + setSaveFilePostFix(Constants.DEFAULT_POSTFIX); + else + setSaveFilePostFix(postFix); + + String localeString = diskConfig.getProperty(Constants.CFG_LOCALE); + + Locale targetLocale = LocaleSerializer.parseFromString(localeString); + if (targetLocale != null) + setLocale(targetLocale); + + String signatureLocaleString = diskConfig.getProperty(Constants.CFG_SIGNATURE_LOCALE); + + Locale signatureTargetLocale = LocaleSerializer.parseFromString(signatureLocaleString); + if (signatureTargetLocale != null) + setSignatureLocale(signatureTargetLocale); + + String useMarker = diskConfig.getProperty(Constants.CFG_USE_MARKER); + if (useMarker != null) + setUseMarker(useMarker.equalsIgnoreCase(Constants.TRUE)); + + String useSignatureFields = diskConfig.getProperty(Constants.CFG_USE_SIGNATURE_FIELDS); + if (useSignatureFields != null) + setUseSignatureFields(useSignatureFields.equalsIgnoreCase(Constants.TRUE)); + + String enablePlaceholder = diskConfig.getProperty(Constants.CFG_ENABLE_PLACEHOLDER); + if (enablePlaceholder != null) + setEnablePlaceholderUsage(enablePlaceholder.equalsIgnoreCase(Constants.TRUE)); + + String signatureProfileName = diskConfig.getProperty(Constants.SIGNATURE_PROFILE); + if (signatureProfileName != null) + setSignatureProfile(signatureProfileName); + + if (diskConfig.containsKey(Constants.CFG_SIGNATURE_NOTE)) + setSignatureNote(diskConfig.getProperty(Constants.CFG_SIGNATURE_NOTE)); + else + setSignatureNote(Profile.getProfile(getSignatureProfile()).getDefaultSignatureBlockNote(getSignatureLocale())); + + String compat = diskConfig.getProperty(Constants.CFG_SIGNATURE_PDFA_COMPAT); + if (compat != null) + setSignaturePdfACompat(compat.equalsIgnoreCase(Constants.TRUE)); + + String bkuUrl = diskConfig.getProperty(Constants.CFG_MOBILE_BKU_URL); + if (bkuUrl != null && !bkuUrl.isEmpty()) + this.configuration.mobileBKUURL = bkuUrl; + + String bkuType = diskConfig.getProperty(Constants.CFG_MOBILE_BKU_TYPE); + + if (bkuType != null && !bkuType.isEmpty()) + { + try + { + this.configuration.mobileBKUType = MobileBKUs.valueOf(bkuType.trim().toUpperCase()); + } catch (IllegalArgumentException e) { + log.error("Invalid BKU type: " + bkuType); + this.configuration.mobileBKUType = DEFAULT_MOBILE_BKU_TYPE; + } + } + + String useBase64 = diskConfig.getProperty(Constants.CFG_MOBILE_BKU_BASE64); + if (useBase64 != null) + this.configuration.mobileBKUBase64 = useBase64.equalsIgnoreCase(Constants.TRUE); + + String proxyPortString = diskConfig.getProperty(Constants.CFG_PROXY_PORT); + if (proxyPortString != null && !proxyPortString.trim().isEmpty()) + { + int port = Integer.parseInt(proxyPortString); + + if (port > 0 && port <= 0xFFFF) + setProxyPort(port); + else + log.warn("Proxy port is out of range!: " + port); + } + + // Set Default BKU + String bkuString = diskConfig.getProperty(Constants.CFG_BKU); + BKUs defaultBKU = BKUs.NONE; + if (bkuString != null) { + try { + defaultBKU = BKUs.valueOf(bkuString); + } catch (IllegalArgumentException ex) { + log.error("Invalid BKU config value " + bkuString + " using none!"); + defaultBKU = BKUs.NONE; + } catch (NullPointerException ex) { + log.error("Invalid BKU config value " + bkuString + " using none!"); + defaultBKU = BKUs.NONE; + } + } + setDefaultBKU(defaultBKU); + + // Set Signature placeholder transparency + int transparency = Constants.DEFAULT_SIGNATURE_PLACEHOLDER_TRANSPARENCY; + String trans = diskConfig.getProperty(Constants.CFG_SIGNATURE_PLACEHOLDER_TRANSPARENCY); + if (trans != null) { + try { + transparency = Integer.parseInt(trans); + } catch (NumberFormatException e) { + log.debug("Couldn't parse placeholder transparency", e); + // ignore parsing exception + } + } + setPlaceholderTransparency(transparency); + + // Set MainWindow size + int width = Constants.DEFAULT_MAINWINDOW_WIDTH; + int height = Constants.DEFAULT_MAINWINDOW_HEIGHT; + String size = diskConfig.getProperty(Constants.CFG_MAINWINDOW_SIZE); + parse: { + if (size == null) + break parse; + int pos = size.indexOf(','); + if (pos <= 0) + break parse; + + try { + width = Integer.parseInt(size.substring(0, pos).trim()); + height = Integer.parseInt(size.substring(pos + 1).trim()); + } catch (NumberFormatException e) { + log.debug("Couldn't parse main window size", e); + // ignore parsing exception + } + } + this.configuration.mainWindowSize = new Point(width, height); + + // Set Signature Position + String signaturePosition = diskConfig.getProperty(Constants.CFG_SIGNATURE_POSITION); + SignaturePosition position = null; + if (signaturePosition != null && !signaturePosition.trim().isEmpty()) { + signaturePosition = signaturePosition.trim().toLowerCase(); + + Pattern pattern = Pattern.compile("(x=(\\d\\.?\\d?);y=(\\d\\.?\\d?);p=(\\d))|(auto)|(x=(\\d\\.?\\d?);y=(\\d\\.?\\d?))"); + Matcher matcher = pattern.matcher(signaturePosition); + if (matcher.matches()) { + if (matcher.groupCount() == 8) { + if (matcher.group(1) != null) { + // we have format: x=..;y=..;p=... + try { + // group 2 = x value + float x = Float.parseFloat(matcher.group(2)); + + // group 3 = y value + float y = Float.parseFloat(matcher.group(3)); + + // group 4 = p value + int p = Integer.parseInt(matcher.group(3)); + + position = new SignaturePosition(x, y, p); + } catch (NumberFormatException ex) { + log.error( + "Signature Position read from config failed: Not a valid number", ex); + } + } else if (matcher.group(5) != null) { + // we have format auto + position = new SignaturePosition(); + } else if (matcher.group(6) != null) { + // we have format x=...;y=...; + // group 7 = x value + float x = Float.parseFloat(matcher.group(7)); + + // group 8 = y value + float y = Float.parseFloat(matcher.group(8)); + + position = new SignaturePosition(x, y); + } + } else { + log.error("Signature Position read from config failed: wrong group Count!"); + } + } else { + log.error("Signature Position read from config failed: not matching string"); + } + } + setDefaultSignaturePosition(position); + + //Set keystore stuff + String keystoreEnabled = diskConfig.getProperty(Constants.CFG_KEYSTORE_ENABLED); + if (keystoreEnabled != null) + setKeyStoreEnabled(keystoreEnabled.equalsIgnoreCase(Constants.TRUE)); + setKeyStoreFile(diskConfig.getProperty(Constants.CFG_KEYSTORE_FILE)); + setKeyStoreType(diskConfig.getProperty(Constants.CFG_KEYSTORE_TYPE)); + setKeyStoreAlias(diskConfig.getProperty(Constants.CFG_KEYSTORE_ALIAS)); + setKeyStoreStorePass(diskConfig.getProperty(Constants.CFG_KEYSTORE_STOREPASS)); + String keystoreKeyPass = diskConfig.getProperty(Constants.CFG_KEYSTORE_KEYPASS); + setKeyStoreKeyPass(keystoreKeyPass); + + // Set update check + String updateCheck = diskConfig.getProperty(Constants.CFG_UPDATE_CHECK); + if (updateCheck != null) + setUpdateCheck(!updateCheck.equalsIgnoreCase(Constants.FALSE)); + + log.info("Successfully loaded config from: " + getConfigurationFileName()); + loaded = true; + } + + /* save to file */ + public void saveToDisk() throws IOException { + String filename = this.getConfigurationFileName(); + File configFile = new File(Constants.CONFIG_DIRECTORY + File.separator + filename); + + Properties props = new Properties(); + props.clear(); + + props.setProperty(Constants.CFG_BKU, getDefaultBKUPersistent().toString()); + + String proxyHost = getProxyHostPersistent(); + if (proxyHost != STRING_EMPTY) + props.setProperty(Constants.CFG_PROXY_HOST, proxyHost); + int proxyPort = getProxyPortPersistent(); + if (proxyPort != -1) + props.setProperty(Constants.CFG_PROXY_PORT,Integer.toString(proxyPort)); + String proxyUser = getProxyUserPersistent(); + if (proxyUser != STRING_EMPTY) + props.setProperty(Constants.CFG_PROXY_USER, proxyUser); + String proxyPass = getProxyPassPersistent(); + if (proxyPass != STRING_EMPTY) + props.setProperty(Constants.CFG_PROXY_PASS, proxyPass); + + props.setProperty(Constants.CFG_EMBLEM, getDefaultEmblemPersistent()); + props.setProperty(Constants.CFG_SIGNATURE_NOTE, getSignatureNote()); + props.setProperty(Constants.CFG_MOBILE_NUMBER, getDefaultMobileNumberPersistent()); + props.setProperty(Constants.CFG_OUTPUT_FOLDER, getDefaultOutputFolderPersistent()); + props.setProperty(Constants.CFG_POSTFIX, getSaveFilePostFix()); + props.setProperty(Constants.CFG_SIGNATURE_PLACEHOLDER_TRANSPARENCY, + Integer.toString(getPlaceholderTransparency())); + + Point size = this.configuration.mainWindowSize; + props.setProperty(Constants.CFG_MAINWINDOW_SIZE, size.x + "," + size.y); + + Locale configLocale = getLocale(); + if(configLocale != null) { + props.setProperty(Constants.CFG_LOCALE, LocaleSerializer.getParsableString(configLocale)); + } + + Locale signatureLocale = this.getSignatureLocale(); + if(signatureLocale != null) { + props.setProperty(Constants.CFG_SIGNATURE_LOCALE, LocaleSerializer.getParsableString(signatureLocale)); + } + + if (getUseMarker()) + props.setProperty(Constants.CFG_USE_MARKER, Constants.TRUE); + + if (getUseSignatureFields()) { + props.setProperty(Constants.CFG_USE_SIGNATURE_FIELDS, Constants.TRUE); + } + + if (getEnablePlaceholderUsage()) { + props.setProperty(Constants.CFG_ENABLE_PLACEHOLDER, Constants.TRUE); + } + + if (getSignaturePdfACompat()) + props.setProperty(Constants.CFG_SIGNATURE_PDFA_COMPAT, Constants.TRUE); + + SignaturePosition pos = getDefaultSignaturePositionPersistent(); + if (pos == null) { + props.setProperty(Constants.CFG_SIGNATURE_POSITION, ""); + } else if (pos.useAutoPositioning()) { + props.setProperty(Constants.CFG_SIGNATURE_POSITION, "auto"); + } else { + props.setProperty(Constants.CFG_SIGNATURE_POSITION, + String.format((Locale) null, "x=%f;y=%f;p=%d", + pos.getX(), pos.getY(), pos.getPage())); + } + + String mobileBKUURL = getMobileBKUURL(); + if (!mobileBKUURL.equals(Constants.DEFAULT_MOBILE_BKU_URL)) + props.setProperty(Constants.CFG_MOBILE_BKU_URL, mobileBKUURL); + + MobileBKUs mobileBKUType = getMobileBKUType(); + if (mobileBKUType != DEFAULT_MOBILE_BKU_TYPE) + props.setProperty(Constants.CFG_MOBILE_BKU_TYPE, mobileBKUType.toString()); + + if (getMobileBKUBase64()) + props.setProperty(Constants.CFG_MOBILE_BKU_BASE64, Constants.TRUE); + + if (Constants.THEME != Constants.Themes.DEFAULT) + props.setProperty(Constants.CFG_THEME, Constants.THEME.name()); + + if (getKeyStoreEnabledPersistent()) + props.setProperty(Constants.CFG_KEYSTORE_ENABLED, Constants.TRUE); + String keystoreFile = getKeyStoreFilePersistent(); + if (keystoreFile != STRING_EMPTY) + props.setProperty(Constants.CFG_KEYSTORE_FILE, keystoreFile); + String keystoreType = getKeyStoreTypePersistent(); + if (keystoreType != STRING_EMPTY) + props.setProperty(Constants.CFG_KEYSTORE_TYPE, keystoreType); + String keystoreAlias = getKeyStoreAliasPersistent(); + if (keystoreAlias != STRING_EMPTY) + props.setProperty(Constants.CFG_KEYSTORE_ALIAS, keystoreAlias); + String keystoreStorePass = getKeyStoreStorePassPersistent(); + if (keystoreStorePass != STRING_EMPTY) + props.setProperty(Constants.CFG_KEYSTORE_STOREPASS, keystoreStorePass); + String keystoreKeyPass = getKeyStoreKeyPassPersistent(); + if (keystoreKeyPass != STRING_EMPTY) + props.setProperty(Constants.CFG_KEYSTORE_KEYPASS, keystoreKeyPass); + + if (!getUpdateCheck()) + props.setProperty(Constants.CFG_UPDATE_CHECK, Constants.FALSE); + + props.setProperty(Constants.SIGNATURE_PROFILE, getSignatureProfile()); + + + FileOutputStream outputstream = new FileOutputStream(configFile, false); + + props.store(outputstream, "Configuration file was generated!"); + + log.info("Configuration file saved to " + configFile.getAbsolutePath()); + } + + // TODO review this + public void setConfigurationFileName(String configurationFile) + { + if (this.configurationFile.equals(configurationFile)) + return; + if (this.loaded) + throw new RuntimeException("Cannot change configuration file path after it has been loaded"); + this.configurationFile = configurationFile; + } + public String getConfigurationFileName() { return this.configurationFile; } + + public void setDefaultBKU(BKUs bku) { + this.configuration.defaultBKU = bku; + } + + public void setDefaultBKUOverlay(BKUs bku) { + this.configurationOverlay.defaultBKU = bku; + } + + public BKUs getDefaultBKU() { + BKUs bku = this.configurationOverlay.defaultBKU; + if (bku == BKUs.NONE) + bku = getDefaultBKUPersistent(); + return bku; + } + + public BKUs getDefaultBKUPersistent() { + return this.configuration.defaultBKU; + } + + public void setDefaultSignaturePosition(SignaturePosition signaturePosition) { + this.configuration.defaultSignaturePosition = signaturePosition; + } + + public void setDefaultSignaturePositionOverlay(SignaturePosition signaturePosition) { + this.configurationOverlay.defaultSignaturePosition = signaturePosition; + } + + public SignaturePosition getDefaultSignaturePosition() { + SignaturePosition position = this.configurationOverlay.defaultSignaturePosition; + if (position == null) + position = getDefaultSignaturePositionPersistent(); + return position; + } + + public SignaturePosition getDefaultSignaturePositionPersistent() { + return this.configuration.defaultSignaturePosition; + } + + public void setPlaceholderTransparency(int transparency) { + this.configuration.placeholderTransparency = transparency; + } + + public int getPlaceholderTransparency() { + return this.configuration.placeholderTransparency; + } + + public void setDefaultMobileNumber(String number) { + if (number == null || number.trim().isEmpty()) { + this.configuration.setMobileNumber(STRING_EMPTY); + } else { + this.configuration.setMobileNumber(number); + } + } + + public void setDefaultMobileNumberOverlay(String number) { + if (number == null || number.trim().isEmpty()) { + this.configurationOverlay.setMobileNumber(STRING_EMPTY); + } else { + this.configurationOverlay.setMobileNumber(number); + } + } + + public String getDefaultMobileNumber() { + String number = this.configurationOverlay.getMobileNumber(); + if (number == null) + number = getDefaultMobileNumberPersistent(); + return number; + } + + public String getDefaultMobileNumberPersistent() { + String number = this.configuration.getMobileNumber(); + if (number == null) + number = STRING_EMPTY; + return number; + } + + public void setDefaultMobilePassword(String password) { + if (password == null || password.trim().isEmpty()) { + this.configuration.mobilePassword = STRING_EMPTY; + } else { + this.configuration.mobilePassword = password; + } + } + + public void setDefaultMobilePasswordOverlay(String password) { + if (password == null || password.trim().isEmpty()) { + this.configurationOverlay.mobilePassword = STRING_EMPTY; + } else { + this.configurationOverlay.mobilePassword = password; + } + } + + public String getDefaultMobilePassword() { + String password = this.configurationOverlay.mobilePassword; + if (password == null) + password = getDefaultMobilePasswordPersistent(); + return password; + } + + public String getDefaultMobilePasswordPersistent() { + String password = this.configuration.mobilePassword; + if (password == null) + password = STRING_EMPTY; + return password; + } + + public void setDefaultEmblem(String emblem) { + try { + if (emblem == null || emblem.trim().isEmpty()) { + this.configuration.setEmblem(STRING_EMPTY); + } else { + this.configuration.setEmblem(emblem); + } + } catch (InvalidEmblemFile e) { + log.error("Error setting emblem file", e); + try { + this.configuration.setEmblem(STRING_EMPTY); + } catch (InvalidEmblemFile e1) { + // Ignore + } + } + } + + public void setDefaultEmblemOverlay(String emblem) { + try { + if (emblem == null || emblem.trim().isEmpty()) { + this.configurationOverlay.setEmblem(STRING_EMPTY); + } else { + this.configurationOverlay.setEmblem(emblem); + } + } catch (InvalidEmblemFile e) { + log.error("Error setting emblem file", e); + try { + this.configurationOverlay.setEmblem(STRING_EMPTY); + } catch (InvalidEmblemFile e1) { + // Ignore + } + } + } + + public String getDefaultEmblem() { + String emblem = this.configurationOverlay.getEmblem(); + if (emblem == null) + emblem = getDefaultEmblemPersistent(); + return emblem; + } + + public String getDefaultEmblemPersistent() { + String emblem = this.configuration.getEmblem(); + if (emblem == null) + emblem = STRING_EMPTY; + return emblem; + } + + public void setProxyHost(String host) { + if (host == null || host.trim().isEmpty()) { + this.configuration.proxyHost = STRING_EMPTY; + } else { + this.configuration.proxyHost = host; + } + } + + public void setProxyHostOverlay(String host) { + if (host == null || host.trim().isEmpty()) { + this.configurationOverlay.proxyHost = STRING_EMPTY; + } else { + this.configurationOverlay.proxyHost = host; + } + } + + public String getProxyHost() { + String host = this.configurationOverlay.proxyHost; + if (host == null) + host = getProxyHostPersistent(); + return host; + } + + public String getProxyHostPersistent() { + String host = this.configuration.proxyHost; + if (host == null) + host = STRING_EMPTY; + return host; + } + + public void setProxyPort(int port) { + try { + this.configuration.setProxyPort(port); + } catch (InvalidPortException e) { + log.error("Error setting proxy port" , e); + // ignore + } + } + + public void setProxyPortOverlay(int port) { + try { + this.configurationOverlay.setProxyPort(port); + } catch (InvalidPortException e) { + log.error("Error setting proxy port" , e); + // ignore + } + } + + public int getProxyPort() { + int port = this.configurationOverlay.getProxyPort(); + if (port == -1) + port = getProxyPortPersistent(); + return port; + } + + public int getProxyPortPersistent() { + return this.configuration.getProxyPort(); + } + + public void setProxyUser(String user) { + if (user == null || user.trim().isEmpty()) { + this.configuration.proxyUser = STRING_EMPTY; + } else { + this.configuration.proxyUser = user; + } + } + + public void setProxyUserOverlay(String user) { + if (user == null || user.trim().isEmpty()) { + this.configurationOverlay.proxyUser = STRING_EMPTY; + } else { + this.configurationOverlay.proxyUser = user; + } + } + + public String getProxyUser() { + String user = this.configurationOverlay.proxyUser; + if (user == null) + user = getProxyUserPersistent(); + return user; + } + + public String getProxyUserPersistent() { + String user = this.configuration.proxyUser; + if (user == null) + user = STRING_EMPTY; + return user; + } + + public void setProxyPass(String pass) { + if (pass == null || pass.trim().isEmpty()) { + this.configuration.proxyPass = STRING_EMPTY; + } else { + this.configuration.proxyPass = pass; + } + } + + public void setProxyPassOverlay(String pass) { + if (pass == null || pass.trim().isEmpty()) { + this.configurationOverlay.proxyPass = STRING_EMPTY; + } else { + this.configurationOverlay.proxyPass = pass; + } + } + + public String getProxyPass() { + String pass = this.configurationOverlay.proxyPass; + if (pass == null) + pass = getProxyPassPersistent(); + return pass; + } + + public String getProxyPassPersistent() { + String pass = this.configuration.proxyPass; + if (pass == null) + pass = STRING_EMPTY; + return pass; + } + + public void setDefaultOutputFolder(String outputFolder) { + if (outputFolder == null || outputFolder.trim().isEmpty()) { + this.configuration.outputFolder = STRING_EMPTY; + } else { + this.configuration.outputFolder = outputFolder; + } + } + + public void setDefaultOutputFolderOverlay(String outputFolder) { + if (outputFolder == null || outputFolder.trim().isEmpty()) { + this.configurationOverlay.outputFolder = STRING_EMPTY; + } else { + this.configurationOverlay.outputFolder = outputFolder; + } + } + + public String getDefaultOutputFolder() { + String outputFolder = this.configurationOverlay.outputFolder; + if (outputFolder == null) + outputFolder = getDefaultOutputFolderPersistent(); + return outputFolder; + } + + public String getDefaultOutputFolderPersistent() { + String outputFolder = this.configuration.outputFolder; + if (outputFolder == null) + outputFolder = STRING_EMPTY; + return outputFolder; + } + + public String getMobileBKUURL() { + return this.configuration.mobileBKUURL; + } + + public MobileBKUs getMobileBKUType() { + return this.configuration.mobileBKUType; + } + + public boolean getMobileBKUBase64() { + return this.configuration.mobileBKUBase64; + } + + public void setSignatureNote(String note) { + if (note == null || note.trim().isEmpty()) { + this.configuration.signatureNote = STRING_EMPTY; + } else { + this.configuration.signatureNote = note; + } + } + + public String getSignatureNote() { + String note = this.configuration.signatureNote; + if (note == null) + note = STRING_EMPTY; + return note; + } + + public void setLocale(Locale locale) { + if(locale == null) { + this.configuration.locale = Messages.getDefaultLocale(); + } else { + this.configuration.locale = locale; + Locale.setDefault(locale); + Messages.setLocale(locale); + } + } + + public Locale getLocale() { + Locale locale = this.configuration.locale; + if (locale == null) + locale = Messages.getDefaultLocale(); + return locale; + } + + public void setSignatureLocale(Locale locale) { + if(locale == null) { + this.configuration.signatureLocale = Messages.getDefaultLocale(); + } else { + this.configuration.signatureLocale = locale; + } + } + + public Locale getSignatureLocale() { + Locale locale = this.configuration.signatureLocale; + if (locale == null) + locale = Messages.getDefaultLocale(); + return locale; + } + + public void setSignaturePdfACompat(boolean compat) { + this.configuration.signaturePDFACompat = compat; + } + + public boolean getSignaturePdfACompat() { + return this.configuration.signaturePDFACompat; + } + + public void setKeyStoreEnabled(Boolean enabled) { + this.configuration.keystoreEnabled = enabled; + } + + public void setKeyStoreEnabledOverlay(Boolean enabled) { + this.configurationOverlay.keystoreEnabled = enabled; + } + + public Boolean getKeyStoreEnabled() { + Boolean enabled = this.configurationOverlay.keystoreEnabled; + if (enabled == null) + enabled = getKeyStoreEnabledPersistent(); + return enabled; + } + + public Boolean getKeyStoreEnabledPersistent() { + Boolean enabled = this.configuration.keystoreEnabled; + if (enabled == null) + enabled = false; + return enabled; + } + + public void setKeyStoreFile(String file) { + if (file == null || file.trim().isEmpty()) { + this.configuration.keystoreFile = STRING_EMPTY; + } else { + this.configuration.keystoreFile = file; + } + } + + public void setKeyStoreFileOverlay(String file) { + if (file == null || file.trim().isEmpty()) { + this.configurationOverlay.keystoreFile = STRING_EMPTY; + } else { + this.configurationOverlay.keystoreFile = file; + } + } + + public String getKeyStoreFile() { + String file = this.configurationOverlay.keystoreFile; + if (file == null) + file = getKeyStoreFilePersistent(); + return file; + } + + public String getKeyStoreFilePersistent() { + String file = this.configuration.keystoreFile; + if (file == null) + file = STRING_EMPTY; + return file; + } + + public void setKeyStoreType(String type) { + if (type == null || type.trim().isEmpty()) { + this.configuration.keystoreType = STRING_EMPTY; + } else { + this.configuration.keystoreType = type; + } + } + + public void setKeyStoreTypeOverlay(String type) { + if (type == null || type.trim().isEmpty()) { + this.configurationOverlay.keystoreType = STRING_EMPTY; + } else { + this.configurationOverlay.keystoreType = type; + } + } + + public String getKeyStoreType() { + String type = this.configurationOverlay.keystoreType; + if (type == null) + type = getKeyStoreTypePersistent(); + return type; + } + + public String getKeyStoreTypePersistent() { + String type = this.configuration.keystoreType; + if (type == null) + type = STRING_EMPTY; + return type; + } + + public void setKeyStoreAlias(String alias) { + if (alias == null || alias.trim().isEmpty()) { + this.configuration.keystoreAlias = STRING_EMPTY; + } else { + this.configuration.keystoreAlias = alias; + } + } + + public void setKeyStoreAliasOverlay(String alias) { + if (alias == null || alias.trim().isEmpty()) { + this.configurationOverlay.keystoreAlias = STRING_EMPTY; + } else { + this.configurationOverlay.keystoreAlias = alias; + } + } + + public String getKeyStoreAlias() { + String alias = this.configurationOverlay.keystoreAlias; + if (alias == null) + alias = getKeyStoreAliasPersistent(); + return alias; + } + + public String getKeyStoreAliasPersistent() { + String alias = this.configuration.keystoreAlias; + if (alias == null) + alias = STRING_EMPTY; + return alias; + } + + public void setKeyStoreStorePass(String storePass) { + if (storePass == null || storePass.trim().isEmpty()) { + this.configuration.keystoreStorePass = STRING_EMPTY; + } else { + this.configuration.keystoreStorePass = storePass; + } + } + + public void setKeyStoreStorePassOverlay(String storePass) { + if (storePass == null || storePass.trim().isEmpty()) { + this.configurationOverlay.keystoreStorePass = STRING_EMPTY; + } else { + this.configurationOverlay.keystoreStorePass = storePass; + } + } + + public String getKeyStoreStorePass() { + String storePass = this.configurationOverlay.keystoreStorePass; + if (storePass != null) + return storePass; + return getKeyStoreStorePassPersistent(); + } + + public String getKeyStoreStorePassPersistent() { + String storePass = this.configuration.keystoreStorePass; + if (storePass == null) + storePass = STRING_EMPTY; + return storePass; + } + + public void setKeyStoreKeyPass(String keyPass) { + if (keyPass == null || keyPass.trim().isEmpty()) { + this.configuration.keystoreKeyPass = STRING_EMPTY; + } else { + this.configuration.keystoreKeyPass = keyPass; + } + } + + public void setKeyStoreKeyPassOverlay(String keyPass) { + if (keyPass == null || keyPass.trim().isEmpty()) { + this.configurationOverlay.keystoreKeyPass = STRING_EMPTY; + } else { + this.configurationOverlay.keystoreKeyPass = keyPass; + } + } + + public String getKeyStoreKeyPass() { + String keyPass = this.configurationOverlay.keystoreKeyPass; + if (keyPass != null) + return keyPass; + return getKeyStoreKeyPassPersistent(); + } + + public String getKeyStoreKeyPassPersistent() { + String keyPass = this.configuration.keystoreKeyPass; + if (keyPass == null) + keyPass = STRING_EMPTY; + return keyPass; + } + + public void setUpdateCheck(boolean checkUpdate) { + this.configuration.updateCheck = checkUpdate; + } + + public boolean getUpdateCheck() { + return this.configuration.updateCheck; + } + + public void setMainWindowSize(Point size) { + this.configuration.mainWindowSize = size; + } + + public Point getMainWindowSize() { + return this.configuration.mainWindowSize; + } + + public boolean getSkipFinish() { + return this.configurationOverlay.skipFinish; + } + + public void setSkipFinishOverlay(boolean skipFinish) { + this.configurationOverlay.skipFinish = skipFinish; + } + + public boolean getUseSignatureFields() { + return this.configuration.getUseSignatureFields(); + } + + public void setUseSignatureFields(boolean useFields) { + this.configuration.setUseSignatureFields(useFields); + if (useFields) setUseMarker(false); + } + + public boolean getUseMarker() { + return this.configuration.getUseMarker(); + } + + public void setUseMarker(boolean useMarker) { + this.configuration.setUseMarker(useMarker); + if (useMarker) setUseSignatureFields(false); + } + + public void setSignatureProfile(String profile) { + this.configuration.setSignatureProfile(Profile.getProfile(profile)); + } + + public void setSaveFilePostFix(String postFix) { + this.configuration.saveFilePostFix = postFix; + } + + public String getSaveFilePostFix(){ + return this.configuration.saveFilePostFix; + } + + public String getSignatureProfile() { + return this.configuration.getSignatureProfile().name(); + } + + public void setEnablePlaceholderUsage(boolean bool) { + this.configuration.enabledPlaceholderUsage = bool; + } + + public boolean getEnablePlaceholderUsage() { + return this.configuration.enabledPlaceholderUsage; + } + + + +} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/KSState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/KSState.java index 3e74f9ec..2d64d160 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/KSState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/KSState.java @@ -30,7 +30,7 @@ import at.asit.pdfover.gui.controls.PasswordInputDialog; import at.asit.pdfover.commons.Messages; import at.asit.pdfover.gui.workflow.StateMachine; import at.asit.pdfover.gui.workflow.Status; -import at.asit.pdfover.gui.workflow.config.ConfigProviderImpl; +import at.asit.pdfover.gui.workflow.config.ConfigurationManager; import at.asit.pdfover.signator.SignatureException; import at.asit.pdfover.signator.SigningState; @@ -64,7 +64,7 @@ public class KSState extends State { Status status = getStateMachine().status; SigningState signingState = status.signingState; - ConfigProviderImpl config = getStateMachine().configProvider; + ConfigurationManager config = getStateMachine().configProvider; try { String file = config.getKeyStoreFile(); diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java index 3595e003..0d0018dd 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java @@ -46,7 +46,7 @@ import at.asit.pdfover.gui.controls.Dialog.BUTTONS; import at.asit.pdfover.gui.controls.ErrorDialog; import at.asit.pdfover.commons.Messages; import at.asit.pdfover.gui.workflow.StateMachine; -import at.asit.pdfover.gui.workflow.config.ConfigProviderImpl; +import at.asit.pdfover.gui.workflow.config.ConfigurationManager; import at.asit.pdfover.signator.SigningState; /** @@ -64,7 +64,7 @@ public class MobileBKUState extends State { public MobileBKUState(StateMachine stateMachine) { super(stateMachine); - ConfigProviderImpl provider = stateMachine.configProvider; + ConfigurationManager provider = stateMachine.configProvider; switch(provider.getMobileBKUType()) { case A_TRUST: this.status = new ATrustStatus(provider); diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OpenState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OpenState.java index 77e1edf4..e7fcb98d 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OpenState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OpenState.java @@ -40,7 +40,7 @@ import at.asit.pdfover.gui.composites.DataSourceSelectComposite; import at.asit.pdfover.commons.Messages; import at.asit.pdfover.gui.workflow.StateMachine; import at.asit.pdfover.gui.workflow.Status; -import at.asit.pdfover.gui.workflow.config.ConfigProviderImpl; +import at.asit.pdfover.gui.workflow.config.ConfigurationManager; import at.asit.pdfover.signator.SignaturePosition; import at.gv.egiz.pdfas.lib.impl.placeholder.SignaturePlaceholderData; @@ -81,7 +81,7 @@ public class OpenState extends State { @Override public void run() { - ConfigProviderImpl config = getStateMachine().configProvider; + ConfigurationManager config = getStateMachine().configProvider; Status status = getStateMachine().status; if (!(status.getPreviousState() instanceof PrepareConfigurationState) && !(status.getPreviousState() instanceof OpenState)) { diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OutputState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OutputState.java index d47b0f84..308b7d5a 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OutputState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OutputState.java @@ -29,7 +29,7 @@ import at.asit.pdfover.commons.Constants; import at.asit.pdfover.commons.Messages; import at.asit.pdfover.gui.workflow.StateMachine; import at.asit.pdfover.gui.workflow.Status; -import at.asit.pdfover.gui.workflow.config.ConfigProviderImpl; +import at.asit.pdfover.gui.workflow.config.ConfigurationManager; /** * Produces the output of the signature process. (save file, open file) @@ -50,7 +50,7 @@ public class OutputState extends State { this.outputComposite = getStateMachine() .createComposite(OutputComposite.class, SWT.RESIZE, this); - ConfigProviderImpl config = getStateMachine().configProvider; + ConfigurationManager config = getStateMachine().configProvider; Status status = getStateMachine().status; File tmpDir = new File(Constants.CONFIG_DIRECTORY + File.separator + "tmp"); 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 84d61cb0..b09728c9 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 @@ -35,7 +35,7 @@ import at.asit.pdfover.commons.Messages; import at.asit.pdfover.gui.utils.SignaturePlaceholderCache; import at.asit.pdfover.gui.workflow.StateMachine; import at.asit.pdfover.gui.workflow.Status; -import at.asit.pdfover.gui.workflow.config.ConfigProviderImpl; +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; @@ -119,7 +119,7 @@ public class PositioningState extends State { this.positionComposite.displayDocument(document); } // Update possibly changed values - ConfigProviderImpl config = stateMachine.configProvider; + ConfigurationManager config = stateMachine.configProvider; SignatureParameter param = stateMachine.pdfSigner.getPDFSigner().newParameter(); Emblem emblem = new CachedFileNameEmblem(config.getDefaultEmblem()); param.setEmblem(emblem); diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java index 8480554e..01f7a19c 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java @@ -52,7 +52,7 @@ import at.asit.pdfover.gui.utils.Zipper; import at.asit.pdfover.gui.workflow.GUIProvider; import at.asit.pdfover.gui.workflow.StateMachine; import at.asit.pdfover.gui.workflow.Status; -import at.asit.pdfover.gui.workflow.config.ConfigProviderImpl; +import at.asit.pdfover.gui.workflow.config.ConfigurationManager; import at.asit.pdfover.signator.Signator; /** @@ -246,7 +246,7 @@ public class PrepareConfigurationState extends State { // Read config file try { StateMachine stateMachine = getStateMachine(); - ConfigProviderImpl config = stateMachine.configProvider; + ConfigurationManager config = stateMachine.configProvider; final GUIProvider gui = stateMachine; File configDir = new File(Constants.CONFIG_DIRECTORY); File configFile = new File(configDir, Constants.DEFAULT_CONFIG_FILENAME); 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 364da8c7..c07f7282 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 @@ -31,7 +31,7 @@ import at.asit.pdfover.gui.controls.ErrorDialog; import at.asit.pdfover.commons.Messages; import at.asit.pdfover.gui.workflow.StateMachine; import at.asit.pdfover.gui.workflow.Status; -import at.asit.pdfover.gui.workflow.config.ConfigProviderImpl; +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; @@ -69,7 +69,7 @@ public class PrepareSigningState extends State { Status status = this.state.getStateMachine().status; - ConfigProviderImpl configuration = this.state.getStateMachine().configProvider; + ConfigurationManager configuration = this.state.getStateMachine().configProvider; // SET PROXY HOST and PORT settings final String proxyHost = configuration.getProxyHost(); -- cgit v1.2.3