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 /pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments | |
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
Diffstat (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments')
12 files changed, 77 insertions, 81 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; } |