diff options
author | tkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7> | 2013-04-10 19:28:04 +0000 |
---|---|---|
committer | tkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7> | 2013-04-10 19:28:04 +0000 |
commit | c2602f46edd68e81cf66fffca3d0dccfdfab4ddc (patch) | |
tree | eaf399ea3fa1844c13f707a70f8950570ddd81f7 | |
parent | 07c7efdfe42ccde13d777df7a6ba0a5c3e335b4f (diff) | |
download | mocca-c2602f46edd68e81cf66fffca3d0dccfdfab4ddc.tar.gz mocca-c2602f46edd68e81cf66fffca3d0dccfdfab4ddc.tar.bz2 mocca-c2602f46edd68e81cf66fffca3d0dccfdfab4ddc.zip |
Configuration overlay added
* Commandline configuration will be stored in an overlay
* This overlay won't be shown on the configuration page
* This overlay won't be saved
* Also slightly reworked CLI Argument creation
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@336 174cde9d-5d70-4d2a-aa98-46368bc2aaf7
21 files changed, 519 insertions, 135 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/ArgumentHandler.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/ArgumentHandler.java index dbc61e24..378588eb 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/ArgumentHandler.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/ArgumentHandler.java @@ -34,7 +34,6 @@ public class ArgumentHandler { /** * SLF4J Logger instance **/ - @SuppressWarnings("unused") private static final Logger log = LoggerFactory .getLogger(ArgumentHandler.class); @@ -65,21 +64,27 @@ public class ArgumentHandler { /** * Adds a CLIArgument to the handler * - * @param arg + * @param cliArgument the CLIArgument subclass to add */ - public void addCLIArgument(CLIArgument arg) { - if (arg == null) { - return; - } + public void addCLIArgument(Class<? extends CLIArgument> cliArgument) { - String[] commandOptions = arg.getCommandOptions(); + CLIArgument arg; + try { + arg = cliArgument.newInstance(); - if (commandOptions == null) { - return; - } + arg.setStateMachine(this.stateMachine); + + String[] commandOptions = arg.getCommandOptions(); - for (int i = 0; i < commandOptions.length; i++) { - this.cliArguments.put(commandOptions[i], arg); + if (commandOptions == null) { + return; + } + + for (int i = 0; i < commandOptions.length; i++) { + this.cliArguments.put(commandOptions[i], arg); + } + } catch (Exception e) { + log.error("Error instantiating CLI argument" , e); //$NON-NLS-1$ } } @@ -93,13 +98,11 @@ public class ArgumentHandler { for (int i = 0; i < args.length; i++) { if (this.cliArguments.containsKey(args[i])) { - i = this.cliArguments.get(args[i]).handleArgument(args, i, - this.stateMachine, this); + i = this.cliArguments.get(args[i]).handleArgument(args, i, this); } else { // Assume we got the document we want to sign if (this.cliArguments.containsKey("-i")) { //$NON-NLS-1$ - i = this.cliArguments.get("-i").handleArgument(args, i-1, //$NON-NLS-1$ - this.stateMachine, this); + i = this.cliArguments.get("-i").handleArgument(args, i-1, this); //$NON-NLS-1$ } } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/BKUArgument.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/BKUArgument.java index 9d1f51be..b1902cb1 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/BKUArgument.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/BKUArgument.java @@ -17,8 +17,6 @@ package at.asit.pdfover.gui.cliarguments; import at.asit.pdfover.gui.exceptions.InitializationException; import at.asit.pdfover.gui.utils.Messages; -import at.asit.pdfover.gui.workflow.ConfigManipulator; -import at.asit.pdfover.gui.workflow.StateMachine; import at.asit.pdfover.signator.BKUs; /** @@ -43,16 +41,14 @@ public class BKUArgument extends CLIArgument { */ @Override public int handleArgument(String[] args, int argOffset, - StateMachine stateMachine, ArgumentHandler handler) + ArgumentHandler handler) throws InitializationException { try { if (args.length > argOffset + 1) { BKUs argumentValue = BKUs.valueOf(args[argOffset + 1]); - ConfigManipulator configManipulator = stateMachine.getConfigManipulator(); - - configManipulator.setDefaultBKU(argumentValue); + getConfiguration().setDefaultBKUOverlay(argumentValue); return argOffset + 1; } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/CLIArgument.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/CLIArgument.java index 26c3d12f..4c471118 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/CLIArgument.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/CLIArgument.java @@ -16,17 +16,21 @@ package at.asit.pdfover.gui.cliarguments; import at.asit.pdfover.gui.exceptions.InitializationException; +import at.asit.pdfover.gui.workflow.ConfigOverlayManipulator; import at.asit.pdfover.gui.workflow.StateMachine; +import at.asit.pdfover.gui.workflow.Status; /** * CLI Argument base class */ public abstract class CLIArgument { - + private String helpText = null; - + private String[] commandOptions = null; - + + private StateMachine stateMachine; + /** * @param commandOptions * @param helpText @@ -35,7 +39,33 @@ public abstract class CLIArgument { this.helpText = helpText; this.commandOptions = commandOptions; } - + + /** + * Set the state machine + * Used for configuration overlay manipulator and status + * @param stateMachine the state machine + */ + protected void setStateMachine(StateMachine stateMachine) { + this.stateMachine = stateMachine; + } + + /** + * Get the configuration overlay manipulator + * @return the configuration overlay manipulator + */ + protected ConfigOverlayManipulator getConfiguration() { + return this.stateMachine.getConfigOverlayManipulator(); + } + + /** + * Get the status + * @return the status + */ + protected Status getStatus() { + return this.stateMachine.getStatus(); + } + + /** * Set help text * @@ -44,7 +74,7 @@ public abstract class CLIArgument { protected void setHelpText(String value) { this.helpText = value; } - + /** * Gets help text * @@ -53,7 +83,7 @@ public abstract class CLIArgument { public String getHelpText() { return this.helpText; } - + /** * Set the command option in format: -... * @@ -64,7 +94,7 @@ public abstract class CLIArgument { protected void setCommandOptions(String[] value) { this.commandOptions = value; } - + /** * Get the command option * @@ -74,7 +104,7 @@ public abstract class CLIArgument { public String[] getCommandOptions() { return this.commandOptions; } - + /** * Invokes the argument to set stuff within the stateMachine * @@ -91,12 +121,11 @@ public abstract class CLIArgument { * offset = 1 * returns 2 * - * @param stateMachine * @param args * @param argOffset * @param handler * @return returns the argumentOffset ending the section of this Argument * @throws InitializationException */ - public abstract int handleArgument(String[] args, int argOffset, StateMachine stateMachine, ArgumentHandler handler) throws InitializationException; + public abstract int handleArgument(String[] args, int argOffset, ArgumentHandler handler) throws InitializationException; } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/ConfigFileArgument.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/ConfigFileArgument.java index 72d6e629..7fd3acef 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/ConfigFileArgument.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/ConfigFileArgument.java @@ -21,8 +21,6 @@ import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.exceptions.InitializationException; import at.asit.pdfover.gui.utils.Messages; -import at.asit.pdfover.gui.workflow.ConfigManipulator; -import at.asit.pdfover.gui.workflow.StateMachine; /** * CLI Argument to set the configuration file @@ -46,16 +44,14 @@ public class ConfigFileArgument extends CLIArgument { */ @Override public int handleArgument(String[] args, int argOffset, - StateMachine stateMachine, ArgumentHandler handler) + ArgumentHandler handler) throws InitializationException { try { if (args.length > argOffset + 1) { String configFile = args[argOffset + 1]; - ConfigManipulator configManipulator = stateMachine.getConfigManipulator(); - - configManipulator.setConfigurationFile(configFile); + getConfiguration().setConfigurationFile(configFile); return argOffset + 1; } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/EmblemArgument.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/EmblemArgument.java index 106f62dc..98401b16 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/EmblemArgument.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/EmblemArgument.java @@ -24,8 +24,6 @@ import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.exceptions.InitializationException; import at.asit.pdfover.gui.utils.Messages; -import at.asit.pdfover.gui.workflow.ConfigManipulator; -import at.asit.pdfover.gui.workflow.StateMachine; /** * CLI Argument to set the emblem file to use for signature @@ -49,7 +47,7 @@ public class EmblemArgument extends CLIArgument { */ @Override public int handleArgument(String[] args, int argOffset, - StateMachine stateMachine, ArgumentHandler handler) + ArgumentHandler handler) throws InitializationException { try { if (args.length > argOffset + 1) { @@ -62,9 +60,7 @@ public class EmblemArgument extends CLIArgument { throw new FileNotFoundException(emblem); } - ConfigManipulator configManipulator = stateMachine.getConfigManipulator(); - - configManipulator.setDefaultEmblem(emblem); + getConfiguration().setDefaultEmblemOverlay(emblem); return argOffset + 1; } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/HelpArgument.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/HelpArgument.java index 21b1124f..1dd0110e 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/HelpArgument.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/HelpArgument.java @@ -21,7 +21,6 @@ import java.util.Set; import at.asit.pdfover.gui.exceptions.InitializationException; import at.asit.pdfover.gui.utils.Messages; -import at.asit.pdfover.gui.workflow.StateMachine; /** * CLI Argument to show the useage message @@ -40,7 +39,7 @@ public class HelpArgument extends CLIArgument { */ @Override public int handleArgument(String[] args, int argOffset, - StateMachine stateMachine, ArgumentHandler handler) + ArgumentHandler handler) throws InitializationException { Set<CLIArgument> arguments = handler.getArguments(); diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/InputDocumentArgument.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/InputDocumentArgument.java index cc37c9b5..efb2c3aa 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/InputDocumentArgument.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/InputDocumentArgument.java @@ -24,8 +24,6 @@ import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.exceptions.InitializationException; import at.asit.pdfover.gui.utils.Messages; -import at.asit.pdfover.gui.workflow.StateMachine; -import at.asit.pdfover.gui.workflow.Status; /** * CLI Argument to set the input document to sign @@ -49,7 +47,7 @@ public class InputDocumentArgument extends CLIArgument { */ @Override public int handleArgument(String[] args, int argOffset, - StateMachine stateMachine, ArgumentHandler handler) + ArgumentHandler handler) throws InitializationException { try { if (args.length > argOffset + 1) { @@ -62,8 +60,7 @@ public class InputDocumentArgument extends CLIArgument { throw new FileNotFoundException(signatureDocument); } - Status status = stateMachine.getStatus(); - status.setDocument(signatureDocumentFile); + getStatus().setDocument(signatureDocumentFile); return argOffset + 1; } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/OutputFolderArgument.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/OutputFolderArgument.java index 0c1c7fc4..9e06be17 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/OutputFolderArgument.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/OutputFolderArgument.java @@ -25,8 +25,6 @@ import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.exceptions.InitializationException; import at.asit.pdfover.gui.utils.Messages; -import at.asit.pdfover.gui.workflow.ConfigManipulator; -import at.asit.pdfover.gui.workflow.StateMachine; /** * CLI Argument to show the usage message @@ -50,7 +48,7 @@ public class OutputFolderArgument extends CLIArgument { */ @Override public int handleArgument(String[] args, int argOffset, - StateMachine stateMachine, ArgumentHandler handler) + ArgumentHandler handler) throws InitializationException { try { if (args.length > argOffset + 1) { @@ -67,9 +65,7 @@ public class OutputFolderArgument extends CLIArgument { throw new IOException(outputFolderDir + Messages.getString("argument.error.output")); //$NON-NLS-1$ } - ConfigManipulator configManipulator = stateMachine.getConfigManipulator(); - - configManipulator.setDefaultOutputFolder(outputFolder); + getConfiguration().setDefaultOutputFolderOverlay(outputFolder); return argOffset + 1; } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/PasswordArgument.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/PasswordArgument.java index b522df45..b32a4edd 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/PasswordArgument.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/PasswordArgument.java @@ -21,8 +21,6 @@ import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.exceptions.InitializationException; import at.asit.pdfover.gui.utils.Messages; -import at.asit.pdfover.gui.workflow.ConfigManipulator; -import at.asit.pdfover.gui.workflow.StateMachine; import at.asit.pdfover.gui.workflow.states.mobilebku.ATrustHelper; /** @@ -47,7 +45,7 @@ public class PasswordArgument extends CLIArgument { */ @Override public int handleArgument(String[] args, int argOffset, - StateMachine stateMachine, ArgumentHandler handler) + ArgumentHandler handler) throws InitializationException { try { if (args.length > argOffset + 1) { @@ -56,9 +54,7 @@ public class PasswordArgument extends CLIArgument { ATrustHelper.validatePassword(password); - ConfigManipulator configManipulator = stateMachine.getConfigManipulator(); - - configManipulator.setDefaultMobilePassword(password); + getConfiguration().setDefaultMobilePasswordOverlay(password); return argOffset + 1; } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/PhoneNumberArgument.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/PhoneNumberArgument.java index 6e24c1b7..eccebb21 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/PhoneNumberArgument.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/PhoneNumberArgument.java @@ -21,8 +21,6 @@ import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.exceptions.InitializationException; import at.asit.pdfover.gui.utils.Messages; -import at.asit.pdfover.gui.workflow.ConfigManipulator; -import at.asit.pdfover.gui.workflow.StateMachine; import at.asit.pdfover.gui.workflow.states.mobilebku.ATrustHelper; /** @@ -49,7 +47,7 @@ public class PhoneNumberArgument extends CLIArgument { */ @Override public int handleArgument(String[] args, int argOffset, - StateMachine stateMachine, ArgumentHandler handler) + ArgumentHandler handler) throws InitializationException { try { @@ -59,9 +57,7 @@ public class PhoneNumberArgument extends CLIArgument { number = ATrustHelper.normalizeMobileNumber(number); - ConfigManipulator configManipulator = stateMachine.getConfigManipulator(); - - configManipulator.setDefaultMobileNumber(number); + getConfiguration().setDefaultMobileNumberOverlay(number); return argOffset + 1; } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/ProxyHostArgument.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/ProxyHostArgument.java index 58ece2c6..cc50705e 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/ProxyHostArgument.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/ProxyHostArgument.java @@ -21,8 +21,6 @@ import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.exceptions.InitializationException; import at.asit.pdfover.gui.utils.Messages; -import at.asit.pdfover.gui.workflow.ConfigManipulator; -import at.asit.pdfover.gui.workflow.StateMachine; /** * CLI Argument to provide the proxy host @@ -46,16 +44,14 @@ public class ProxyHostArgument extends CLIArgument { */ @Override public int handleArgument(String[] args, int argOffset, - StateMachine stateMachine, ArgumentHandler handler) + ArgumentHandler handler) throws InitializationException { try { if (args.length > argOffset + 1) { String proxyHost = args[argOffset + 1]; - ConfigManipulator configManipulator = stateMachine.getConfigManipulator(); - - configManipulator.setProxyHost(proxyHost); + getConfiguration().setProxyHostOverlay(proxyHost); return argOffset + 1; } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/ProxyPortArgument.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/ProxyPortArgument.java index 34ba0f48..a9bceead 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/ProxyPortArgument.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/ProxyPortArgument.java @@ -22,8 +22,6 @@ import org.slf4j.LoggerFactory; import at.asit.pdfover.gui.exceptions.InitializationException; import at.asit.pdfover.gui.exceptions.InvalidPortException; import at.asit.pdfover.gui.utils.Messages; -import at.asit.pdfover.gui.workflow.ConfigManipulator; -import at.asit.pdfover.gui.workflow.StateMachine; /** * CLI Argument to provide the proxy port @@ -47,7 +45,7 @@ public class ProxyPortArgument extends CLIArgument { */ @Override public int handleArgument(String[] args, int argOffset, - StateMachine stateMachine, ArgumentHandler handler) + ArgumentHandler handler) throws InitializationException { try { if (args.length > argOffset + 1) { @@ -60,9 +58,7 @@ public class ProxyPortArgument extends CLIArgument { throw new InvalidPortException(port); } - ConfigManipulator configManipulator = stateMachine.getConfigManipulator(); - - configManipulator.setProxyPort(port); + getConfiguration().setProxyPortOverlay(port); return argOffset + 1; } 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 706ac1f6..88fcfc0d 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 @@ -35,10 +35,10 @@ import at.asit.pdfover.gui.exceptions.InvalidPortException; import at.asit.pdfover.gui.exceptions.ResumableException; import at.asit.pdfover.gui.utils.Messages; import at.asit.pdfover.gui.workflow.ConfigManipulator; -import at.asit.pdfover.gui.workflow.ConfigProvider; import at.asit.pdfover.gui.workflow.ConfigurationContainer; import at.asit.pdfover.gui.workflow.ConfigurationContainerImpl; import at.asit.pdfover.gui.workflow.PDFSigner; +import at.asit.pdfover.gui.workflow.PersistentConfigProvider; import at.asit.pdfover.gui.workflow.states.State; import at.asit.pdfover.signator.SignaturePosition; @@ -212,7 +212,7 @@ public class ConfigurationComposite extends StateComposite { /** * configuration provider */ - ConfigProvider configProvider = null; + PersistentConfigProvider configProvider = null; /** * simple configuration composite @@ -271,7 +271,7 @@ public class ConfigurationComposite extends StateComposite { * * @param provider */ - public void setConfigProvider(ConfigProvider provider) { + public void setConfigProvider(PersistentConfigProvider provider) { this.configProvider = provider; if (this.configProvider != null) { @@ -295,28 +295,28 @@ public class ConfigurationComposite extends StateComposite { this.configurationContainer.setSignLocale(this.configProvider.getSignLocale()); this.configurationContainer.setDefaultBKU(this.configProvider - .getDefaultBKU()); + .getDefaultBKUPersistent()); try { this.configurationContainer.setEmblem(this.configProvider - .getDefaultEmblem()); + .getDefaultEmblemPersistent()); } catch (InvalidEmblemFile e) { log.error("Failed to set emblem!", e); //$NON-NLS-1$ } try { this.configurationContainer.setMobileNumber(this.configProvider - .getDefaultMobileNumber()); + .getDefaultMobileNumberPersistent()); } catch (InvalidNumberException e) { log.error("Failed to set mobile phone number!", e); //$NON-NLS-1$ } this.configurationContainer.setOutputFolder(this.configProvider - .getDefaultOutputFolder()); + .getDefaultOutputFolderPersistent()); this.configurationContainer.setProxyHost(this.configProvider - .getProxyHost()); + .getProxyHostPersistent()); try { this.configurationContainer.setProxyPort(this.configProvider - .getProxyPort()); + .getProxyPortPersistent()); } catch (InvalidPortException e) { log.error("Failed to set proxy port!", e); //$NON-NLS-1$ } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigManipulator.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigManipulator.java index b5cda279..80754f4b 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigManipulator.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigManipulator.java @@ -76,12 +76,6 @@ public interface ConfigManipulator { public void setProxyPort(int port); /** - * Sets the configuration file - * @param configurationFile - */ - public void setConfigurationFile(String configurationFile); - - /** * Sets the default output folder * @param outputFolder the default output folder */ @@ -94,12 +88,6 @@ public interface ConfigManipulator { public void setSignatureNote(String note); /** - * Saves the current configuration to the current configuration file - * @throws IOException - */ - public void saveCurrentConfiguration() throws IOException; - - /** * Sets the locale to be used * @param locale the locale */ @@ -116,4 +104,10 @@ public interface ConfigManipulator { * @param size a Point describing the size */ public void setMainWindowSize(Point size); + + /** + * Saves the current configuration to the current configuration file + * @throws IOException + */ + public void saveCurrentConfiguration() throws IOException; } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigOverlayManipulator.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigOverlayManipulator.java new file mode 100644 index 00000000..a31309f3 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigOverlayManipulator.java @@ -0,0 +1,73 @@ +/* + * 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; + +import at.asit.pdfover.signator.BKUs; + +/** + * An interface for setting the configuration overlay + * + * This overlay overrides the actual configuration but will not be saved + */ +public interface ConfigOverlayManipulator { + /** + * Sets the default bku type + * @param bku the bku type + */ + public void setDefaultBKUOverlay(BKUs bku); + + /** + * Sets the default mobile number + * @param number the default mobile number + */ + public void setDefaultMobileNumberOverlay(String number); + + /** + * Sets the default password + * @param password the default password + */ + public void setDefaultMobilePasswordOverlay(String password); + + /** + * Sets the default emblem + * @param emblem the default emblem + */ + public void setDefaultEmblemOverlay(String emblem); + + /** + * Sets the proxy host + * @param host the proxy host + */ + public void setProxyHostOverlay(String host); + + /** + * Sets the proxy port + * @param port the proxy port + */ + public void setProxyPortOverlay(int port); + + /** + * Sets the default output folder + * @param outputFolder the default output folder + */ + public void setDefaultOutputFolderOverlay(String outputFolder); + + /** + * Sets the configuration file + * @param configurationFile + */ + public void setConfigurationFile(String configurationFile); +} diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java index 81749886..ea5e2629 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java @@ -41,7 +41,8 @@ import at.asit.pdfover.signator.SignaturePosition; /** * Implementation of the configuration provider and manipulator */ -public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { +public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator, + ConfigOverlayManipulator, PersistentConfigProvider { /** * SLF4J Logger instance **/ @@ -57,11 +58,14 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { private ConfigurationContainer configuration; + private ConfigurationContainer configurationOverlay; + /** * Constructor */ public ConfigProviderImpl() { this.configuration = new ConfigurationContainerImpl(); + this.configurationOverlay = new ConfigurationContainerImpl(); } /* @@ -257,14 +261,14 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { Properties props = new Properties(); props.clear(); - props.setProperty(Constants.CFG_BKU, this.getDefaultBKU().toString()); - props.setProperty(Constants.CFG_PROXY_HOST, this.getProxyHost()); + props.setProperty(Constants.CFG_BKU, this.getDefaultBKUPersistent().toString()); + props.setProperty(Constants.CFG_PROXY_HOST, this.getProxyHostPersistent()); props.setProperty(Constants.CFG_PROXY_PORT, - Integer.toString(this.getProxyPort())); - props.setProperty(Constants.CFG_EMBLEM, this.getDefaultEmblem()); + Integer.toString(this.getProxyPortPersistent())); + props.setProperty(Constants.CFG_EMBLEM, this.getDefaultEmblemPersistent()); props.setProperty(Constants.CFG_SIGNATURE_NOTE, this.getSignatureNote()); - props.setProperty(Constants.CFG_MOBILE_NUMBER, this.getDefaultMobileNumber()); - props.setProperty(Constants.CFG_OUTPUT_FOLDER, this.getDefaultOutputFolder()); + props.setProperty(Constants.CFG_MOBILE_NUMBER, this.getDefaultMobileNumberPersistent()); + props.setProperty(Constants.CFG_OUTPUT_FOLDER, this.getDefaultOutputFolderPersistent()); props.setProperty(Constants.CFG_SIGNATURE_PLACEHOLDER_TRANSPARENCY, Integer.toString(this.getPlaceholderTransparency())); @@ -345,6 +349,15 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { this.configuration.setDefaultBKU(bku); } + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.ConfigOverlayManipulator#setDefaultBKUOverlay(at.asit.pdfover.signator.BKUs) + */ + @Override + public void setDefaultBKUOverlay(BKUs bku) { + this.configurationOverlay.setDefaultBKU(bku); + + } + /* * (non-Javadoc) * @@ -352,6 +365,17 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { */ @Override public BKUs getDefaultBKU() { + BKUs bku = this.configurationOverlay.getDefaultBKU(); + if (bku == BKUs.NONE) + bku = this.configuration.getDefaultBKU(); + return bku; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.PersistentConfigProvider#getDefaultBKUPersistent() + */ + @Override + public BKUs getDefaultBKUPersistent() { return this.configuration.getDefaultBKU(); } @@ -423,6 +447,27 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { } } + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.ConfigOverlayManipulator#setDefaultMobileNumberOverlay(java.lang.String) + */ + @Override + public void setDefaultMobileNumberOverlay(String number) { + try { + if (number == null || number.trim().isEmpty()) { + this.configurationOverlay.setMobileNumber(STRING_EMPTY); + } else { + this.configurationOverlay.setMobileNumber(number); + } + } catch (InvalidNumberException e) { + log.error("Error setting mobile number", e); //$NON-NLS-1$ + try { + this.configurationOverlay.setMobileNumber(STRING_EMPTY); + } catch (InvalidNumberException e1) { + // Ignore + } + } + } + /* * (non-Javadoc) * @@ -430,6 +475,17 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { */ @Override public String getDefaultMobileNumber() { + String number = this.configurationOverlay.getMobileNumber(); + if (number == null) + number = this.configuration.getMobileNumber(); + return number; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.PersistentConfigProvider#getDefaultMobileNumberPersistent() + */ + @Override + public String getDefaultMobileNumberPersistent() { return this.configuration.getMobileNumber(); } @@ -448,6 +504,18 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { } } + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.ConfigOverlayManipulator#setDefaultMobilePasswordOverlay(java.lang.String) + */ + @Override + public void setDefaultMobilePasswordOverlay(String password) { + if (password == null || password.trim().isEmpty()) { + this.configurationOverlay.setMobilePassword(STRING_EMPTY); + } else { + this.configurationOverlay.setMobilePassword(password); + } + } + /* * (non-Javadoc) * @@ -455,6 +523,17 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { */ @Override public String getDefaultMobilePassword() { + String password = this.configurationOverlay.getMobilePassword(); + if (password == null) + password = this.configuration.getMobilePassword(); + return password; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.PersistentConfigProvider#getDefaultMobilePasswordPersistent() + */ + @Override + public String getDefaultMobilePasswordPersistent() { return this.configuration.getMobilePassword(); } @@ -482,6 +561,27 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { } } + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.ConfigOverlayManipulator#setDefaultEmblemOverlay(java.lang.String) + */ + @Override + 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); //$NON-NLS-1$ + try { + this.configurationOverlay.setEmblem(STRING_EMPTY); + } catch (InvalidEmblemFile e1) { + // Ignore + } + } + } + /* * (non-Javadoc) * @@ -489,6 +589,17 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { */ @Override public String getDefaultEmblem() { + String emblem = this.configurationOverlay.getEmblem(); + if (emblem == null) + emblem = this.configuration.getEmblem(); + return emblem; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.PersistentConfigProvider#getDefaultEmblemPersistent() + */ + @Override + public String getDefaultEmblemPersistent() { return this.configuration.getEmblem(); } @@ -507,6 +618,18 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { } } + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.ConfigOverlayManipulator#setProxyHostOverlay(java.lang.String) + */ + @Override + public void setProxyHostOverlay(String host) { + if (host == null || host.trim().isEmpty()) { + this.configurationOverlay.setProxyHost(STRING_EMPTY); + } else { + this.configurationOverlay.setProxyHost(host); + } + } + /* * (non-Javadoc) * @@ -514,6 +637,17 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { */ @Override public String getProxyHost() { + String host = this.configurationOverlay.getProxyHost(); + if (host == null) + host = this.configuration.getProxyHost(); + return host; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.PersistentConfigProvider#getProxyHostPersistent() + */ + @Override + public String getProxyHostPersistent() { return this.configuration.getProxyHost(); } @@ -533,6 +667,19 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { } } + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.ConfigOverlayManipulator#setProxyPortOverlay(int) + */ + @Override + public void setProxyPortOverlay(int port) { + try { + this.configurationOverlay.setProxyPort(port); + } catch (InvalidPortException e) { + log.error("Error setting proxy port" , e); //$NON-NLS-1$ + // ignore + } + } + /* * (non-Javadoc) * @@ -540,6 +687,17 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { */ @Override public int getProxyPort() { + int port = this.configurationOverlay.getProxyPort(); + if (port == -1) + port = this.configuration.getProxyPort(); + return this.configuration.getProxyPort(); + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.PersistentConfigProvider#getProxyPortPersistent() + */ + @Override + public int getProxyPortPersistent() { return this.configuration.getProxyPort(); } @@ -559,6 +717,18 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { } } + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.ConfigOverlayManipulator#setDefaultOutputFolderOverlay(java.lang.String) + */ + @Override + public void setDefaultOutputFolderOverlay(String outputFolder) { + if (outputFolder == null || outputFolder.trim().isEmpty()) { + this.configurationOverlay.setOutputFolder(STRING_EMPTY); + } else { + this.configurationOverlay.setOutputFolder(outputFolder); + } + } + /* * (non-Javadoc) * @@ -566,6 +736,17 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { */ @Override public String getDefaultOutputFolder() { + String outputFolder = this.configurationOverlay.getOutputFolder(); + if (outputFolder == null) + outputFolder = this.configuration.getOutputFolder(); + return outputFolder; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.PersistentConfigProvider#getDefaultOutputFolderPersistent() + */ + @Override + public String getDefaultOutputFolderPersistent() { return this.configuration.getOutputFolder(); } @@ -662,5 +843,4 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator { public Point getMainWindowSize() { return this.configuration.getMainWindowSize(); } - } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/PersistentConfigProvider.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/PersistentConfigProvider.java new file mode 100644 index 00000000..c9c02b63 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/PersistentConfigProvider.java @@ -0,0 +1,116 @@ +/* + * 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; + +import java.util.Locale; + +import org.eclipse.swt.graphics.Point; + +import at.asit.pdfover.signator.BKUs; +import at.asit.pdfover.signator.SignaturePosition; + +/** + * An interface for reading the persistent configuration + * + * This reads the configuration that will be saved + */ +public interface PersistentConfigProvider { + /** + * Get the default configured BKU + * @return the default configured BKU + */ + public BKUs getDefaultBKUPersistent(); + + /** + * Gets the default Mobile number + * @return the default mobile number + */ + public String getDefaultMobileNumberPersistent(); + + /** + * Gets the password to use for Mobile BKU + * @return the password + */ + public String getDefaultMobilePasswordPersistent(); + + /** + * Gets the filename of the default emblem + * @return the emblem + */ + public String getDefaultEmblemPersistent(); + + /** + * Gets the proxy host + * @return the proxy hostname or ip address + */ + public String getProxyHostPersistent(); + + /** + * Gets the proxy port + * @return the proxy port + */ + public int getProxyPortPersistent(); + + /** + * Gets the default output folder for signed documents + * @return the default output folder + */ + public String getDefaultOutputFolderPersistent(); + + // Declare the other configuration getters for convenience + + /** + * Get the default configured SignaturePosition + * @return the default configured SignaturePosition or null if not configured + */ + public SignaturePosition getDefaultSignaturePosition(); + + /** + * Get the transparency of the signature placeholder + * @return the transparency of the signature placeholder + */ + public int getPlaceholderTransparency(); + + /** + * Gets the mobile BKU URL + * @return the mobile BKU URL + */ + public String getMobileBKUURL(); + + /** + * Get the signature note text to use + * @return the signature note text + */ + public String getSignatureNote(); + + /** + * Gets the configured locale + * @return the configured locale + */ + public Locale getConfigLocale(); + + /** + * Gets the configured locale + * @return the configured locale + */ + public Locale getSignLocale(); + + /** + * Gets the configured MainWindow size + * @return the configured MainWindow size + */ + public Point getMainWindowSize(); +} 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 9bcc757e..a054daaf 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,11 +28,23 @@ public interface StateMachine { public ConfigProvider getConfigProvider(); /** + * Get the PersistentConfigProvider + * @return the PersistentConfigProvider + */ + public PersistentConfigProvider getPersistentConfigProvider(); + + /** * Gets the Config Manipulator * @return the config manipulator */ public ConfigManipulator getConfigManipulator(); - + + /** + * Gets the Config Overlay Manipulator + * @return the config overlay manipulator + */ + public ConfigOverlayManipulator getConfigOverlayManipulator(); + /** * Get the PDF Signer * @return the PDF Signer diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachineImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachineImpl.java index 18943cbe..1da947f9 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachineImpl.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/StateMachineImpl.java @@ -268,7 +268,6 @@ public class StateMachineImpl implements StateMachine, GUIProvider { /* * (non-Javadoc) - * * @see at.asit.pdfover.gui.workflow.StateMachine#getConfigProvider() */ @Override @@ -278,7 +277,31 @@ public class StateMachineImpl implements StateMachine, GUIProvider { /* * (non-Javadoc) - * + * @see at.asit.pdfover.gui.workflow.StateMachine#getConfigProvider() + */ + @Override + public PersistentConfigProvider getPersistentConfigProvider() { + return this.configProvider; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.StateMachine#getConfigManipulator() + */ + @Override + public ConfigManipulator getConfigManipulator() { + return this.configProvider; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.StateMachine#getConfigOverlayManipulator() + */ + @Override + public ConfigOverlayManipulator getConfigOverlayManipulator() { + return this.configProvider; + } + + /* + * (non-Javadoc) * @see at.asit.pdfover.gui.workflow.StateMachine#getStatus() */ @Override @@ -288,7 +311,6 @@ public class StateMachineImpl implements StateMachine, GUIProvider { /* * (non-Javadoc) - * * @see at.asit.pdfover.gui.workflow.StateMachine#getPDFSigner() */ @Override @@ -298,7 +320,6 @@ public class StateMachineImpl implements StateMachine, GUIProvider { /* * (non-Javadoc) - * * @see at.asit.pdfover.gui.workflow.StateMachine#getGUIProvider() */ @Override @@ -333,14 +354,6 @@ public class StateMachineImpl implements StateMachine, GUIProvider { } /* (non-Javadoc) - * @see at.asit.pdfover.gui.workflow.StateMachine#getConfigManipulator() - */ - @Override - public ConfigManipulator getConfigManipulator() { - return this.configProvider; - } - - /* (non-Javadoc) * @see at.asit.pdfover.gui.workflow.GUIProvider#getMainShell() */ @Override diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ConfigurationUIState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ConfigurationUIState.java index 57a7aa9b..47c21063 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ConfigurationUIState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ConfigurationUIState.java @@ -45,7 +45,7 @@ public class ConfigurationUIState extends State { this.configurationComposite = this.stateMachine.getGUIProvider().createComposite(ConfigurationComposite.class, SWT.RESIZE, this); this.configurationComposite.setConfigManipulator(this.stateMachine.getConfigManipulator()); - this.configurationComposite.setConfigProvider(this.stateMachine.getConfigProvider()); + this.configurationComposite.setConfigProvider(this.stateMachine.getPersistentConfigProvider()); this.configurationComposite.setSigner(this.stateMachine.getPDFSigner()); } 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 e726d7b4..955d125a 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 @@ -71,20 +71,20 @@ public class PrepareConfigurationState extends State { public PrepareConfigurationState(StateMachine stateMachine) { super(stateMachine); this.handler = new ArgumentHandler(this.stateMachine); - this.handler.addCLIArgument(new HelpArgument()); - this.handler.addCLIArgument(new BKUArgument()); - this.handler.addCLIArgument(new PhoneNumberArgument()); - this.handler.addCLIArgument(new EmblemArgument()); - this.handler.addCLIArgument(new PasswordArgument()); - this.handler.addCLIArgument(new ProxyHostArgument()); - this.handler.addCLIArgument(new ProxyPortArgument()); - this.handler.addCLIArgument(new OutputFolderArgument()); - this.handler.addCLIArgument(new InputDocumentArgument()); + this.handler.addCLIArgument(HelpArgument.class); + this.handler.addCLIArgument(BKUArgument.class); + this.handler.addCLIArgument(PhoneNumberArgument.class); + this.handler.addCLIArgument(EmblemArgument.class); + this.handler.addCLIArgument(PasswordArgument.class); + this.handler.addCLIArgument(ProxyHostArgument.class); + this.handler.addCLIArgument(ProxyPortArgument.class); + this.handler.addCLIArgument(OutputFolderArgument.class); + this.handler.addCLIArgument(InputDocumentArgument.class); // adding config file argument to this handler so it appears in help - this.handler.addCLIArgument(new ConfigFileArgument()); + this.handler.addCLIArgument(ConfigFileArgument.class); this.configFileHandler = new ArgumentHandler(this.stateMachine); - this.configFileHandler.addCLIArgument(new ConfigFileArgument()); + this.configFileHandler.addCLIArgument(ConfigFileArgument.class); } private void initializeFromConfigurationFile(String filename) |