diff options
author | tkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7> | 2013-04-10 18:58:27 +0000 |
---|---|---|
committer | tkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7> | 2013-04-10 18:58:27 +0000 |
commit | 96a1a5c9d04238c63247794ad9c76e5a2001b8d0 (patch) | |
tree | c0b05f0378e84e53a73cdfb62612a7d3e6ecb40a /pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments | |
parent | b8b015d3fa3b58cb5e70b4cd2ad1b8fe2a424af9 (diff) | |
download | mocca-96a1a5c9d04238c63247794ad9c76e5a2001b8d0.tar.gz mocca-96a1a5c9d04238c63247794ad9c76e5a2001b8d0.tar.bz2 mocca-96a1a5c9d04238c63247794ad9c76e5a2001b8d0.zip |
Moved Mobile BKU URL to configuration file
Extracted localizable Strings
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@61 174cde9d-5d70-4d2a-aa98-46368bc2aaf7
Diffstat (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments')
11 files changed, 146 insertions, 52 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 f43b636c..badf37da 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 @@ -39,71 +39,81 @@ public class ArgumentHandler { .getLogger(ArgumentHandler.class); private Map<String, CLIArgument> cliArguments = new HashMap<String, CLIArgument>(); - + private StateMachine stateMachine = null; - + private boolean requiredExit = false; - + /** * Constructor - * @param stateMachine + * + * @param stateMachine */ public ArgumentHandler(StateMachine stateMachine) { this.stateMachine = stateMachine; } - + /** * Gets available Arguments + * * @return the list of available arguments */ public Set<CLIArgument> getArguments() { return new HashSet<CLIArgument>(this.cliArguments.values()); } - + /** * Adds a CLIArgument to the handler * * @param arg */ public void addCLIArgument(CLIArgument arg) { - if(arg == null) { + if (arg == null) { return; } - + String[] commandOptions = arg.getCommandOptions(); - - if(commandOptions == null) { + + if (commandOptions == null) { return; } - - for(int i = 0; i < commandOptions.length; i++) - { + + for (int i = 0; i < commandOptions.length; i++) { this.cliArguments.put(commandOptions[i], arg); } } - + /** * Handle CLI Arguments * * @param args - * @throws InitializationException + * @throws InitializationException */ public void handleArguments(String[] args) throws InitializationException { - for(int i = 0; i < args.length; i++) { - if(this.cliArguments.containsKey(args[i])) { - this.cliArguments.get(args[i]).handleArgument(args, i, this.stateMachine, this); + + 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); + } 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); + } } } } - + /** * Set by an cli argument if it wants the program to exit + * * @param requireExit */ public void setRequireExit(boolean requireExit) { this.requiredExit = requireExit; } - + /** * Checks if one argument required the program to exit again * 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 5c039c83..3117780e 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 @@ -15,6 +15,7 @@ */ package at.asit.pdfover.gui.cliarguments; +import at.asit.pdfover.gui.Messages; import at.asit.pdfover.gui.exceptions.InitializationException; import at.asit.pdfover.gui.workflow.ConfigManipulator; import at.asit.pdfover.gui.workflow.StateMachine; @@ -29,7 +30,7 @@ public class BKUArgument extends CLIArgument { */ public BKUArgument() { super( - new String[] { "-b" }, "Select the BKU to use values are: LOCAL, MOBILE (example: -b <option>"); //$NON-NLS-1$ + new String[] { "-b" }, Messages.getString("argument.help.bku")); //$NON-NLS-1$ //$NON-NLS-2$ } /* @@ -57,11 +58,11 @@ public class BKUArgument extends CLIArgument { } } catch (Exception ex) { throw new InitializationException( - "BKU Argument invalid! Use: " + this.getHelpText(), ex); + Messages.getString("argument.invalid.bku") + this.getHelpText(), ex); //$NON-NLS-1$ } throw new InitializationException( - "BKU Argument invalid! Use: " + this.getHelpText(), null); + Messages.getString("argument.invalid.bku") + this.getHelpText(), null); //$NON-NLS-1$ } } 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 d08ce7c6..417b85cb 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 @@ -19,10 +19,10 @@ package at.asit.pdfover.gui.cliarguments; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.asit.pdfover.gui.Messages; import at.asit.pdfover.gui.exceptions.InitializationException; import at.asit.pdfover.gui.workflow.ConfigManipulator; import at.asit.pdfover.gui.workflow.StateMachine; -import at.asit.pdfover.gui.workflow.states.mobilebku.ATrustHelper; /** * @@ -38,7 +38,7 @@ public class ConfigFileArgument extends CLIArgument { * Constructor */ public ConfigFileArgument() { - super(new String[] {"-c"}, "Defines which configuration file to use. Example: -c <config file>"); //$NON-NLS-1$ + super(new String[] {"-c"}, Messages.getString("argument.help.config")); //$NON-NLS-1$ //$NON-NLS-2$ } /* (non-Javadoc) @@ -62,11 +62,11 @@ public class ConfigFileArgument extends CLIArgument { } catch (Exception ex) { log.error("Configuration File Argument invalid!", ex); //$NON-NLS-1$ throw new InitializationException( - "Configuration File Argument invalid! Use: " + this.getHelpText(), ex); + Messages.getString("argument.invalid.config") + this.getHelpText(), ex); //$NON-NLS-1$ } throw new InitializationException( - "Configuration File invalid! Use: " + this.getHelpText(), null); + Messages.getString("argument.invalid.config") + this.getHelpText(), null); //$NON-NLS-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 1b7260c1..a89bef78 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 @@ -22,6 +22,7 @@ import java.io.FileNotFoundException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.asit.pdfover.gui.Messages; import at.asit.pdfover.gui.exceptions.InitializationException; import at.asit.pdfover.gui.workflow.ConfigManipulator; import at.asit.pdfover.gui.workflow.StateMachine; @@ -34,7 +35,7 @@ public class EmblemArgument extends CLIArgument { * Constructor */ public EmblemArgument() { - super(new String[] {"-e"}, "Sets the emblem file to use for the signature. Example: -e <emblem file>"); //$NON-NLS-1$ + super(new String[] {"-e"}, Messages.getString("argument.help.emblem")); //$NON-NLS-1$ //$NON-NLS-2$ } /** @@ -70,11 +71,11 @@ public class EmblemArgument extends CLIArgument { } catch (Exception ex) { log.error("Emblem argument invalid!", ex); //$NON-NLS-1$ throw new InitializationException( - "Emblem invalid! Use: " + this.getHelpText(), ex); + Messages.getString("argument.invalid.emblem") + this.getHelpText(), ex); //$NON-NLS-1$ } throw new InitializationException( - "Emblem argument invalid! Use: " + this.getHelpText(), null); + Messages.getString("argument.invalid.emblem") + this.getHelpText(), null); //$NON-NLS-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 8087807c..bd015984 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 @@ -19,6 +19,7 @@ package at.asit.pdfover.gui.cliarguments; import java.util.Iterator; import java.util.Set; +import at.asit.pdfover.gui.Messages; import at.asit.pdfover.gui.exceptions.InitializationException; import at.asit.pdfover.gui.workflow.StateMachine; @@ -31,7 +32,7 @@ public class HelpArgument extends CLIArgument { * Constructor */ public HelpArgument() { - super(new String[] {"-h", "-?" }, "shows this help message"); //$NON-NLS-1$ //$NON-NLS-2$ + super(new String[] {"-h", "-?" }, Messages.getString("argument.help.help")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } /* (non-Javadoc) @@ -45,7 +46,7 @@ public class HelpArgument extends CLIArgument { Iterator<CLIArgument> argumentIterator = arguments.iterator(); - System.out.println("The following options are available"); //$NON-NLS-1$ + System.out.println(Messages.getString("argument.info.help")); //$NON-NLS-1$ while(argumentIterator.hasNext()) { CLIArgument agrument = argumentIterator.next(); 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 new file mode 100644 index 00000000..9152a6fd --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/InputDocumentArgument.java @@ -0,0 +1,80 @@ +/* + * 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.cliarguments; + +// Imports +import java.io.File; +import java.io.FileNotFoundException; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.asit.pdfover.gui.Messages; +import at.asit.pdfover.gui.exceptions.InitializationException; +import at.asit.pdfover.gui.workflow.StateMachine; +import at.asit.pdfover.gui.workflow.Status; + +/** + * + */ +public class InputDocumentArgument extends CLIArgument { + /** + * Constructor + */ + public InputDocumentArgument() { + super(new String[] {"-i"}, Messages.getString("argument.help.input")); //$NON-NLS-1$ //$NON-NLS-2$ + } + + /** + * SLF4J Logger instance + **/ + private static final Logger log = LoggerFactory + .getLogger(InputDocumentArgument.class); + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.cliarguments.CLIArgument#handleArgument(java.lang.String[], int, at.asit.pdfover.gui.workflow.StateMachine, at.asit.pdfover.gui.cliarguments.ArgumentHandler) + */ + @Override + public int handleArgument(String[] args, int argOffset, + StateMachine stateMachine, ArgumentHandler handler) + throws InitializationException { + try { + if (args.length > argOffset + 1) { + + String signatureDocument = args[argOffset + 1]; + + File signatureDocumentFile = new File(signatureDocument); + + if(!signatureDocumentFile.exists()) { + throw new FileNotFoundException(signatureDocument); + } + + Status status = stateMachine.getStatus(); + status.setDocument(signatureDocumentFile); + + return argOffset + 1; + } + } catch (Exception ex) { + log.error("Document to sign argument invalid!", ex); //$NON-NLS-1$ + throw new InitializationException( + Messages.getString("argument.invalid.input") + this.getHelpText(), ex); //$NON-NLS-1$ + } + + throw new InitializationException( + Messages.getString("argument.invalid.input") + this.getHelpText(), null); //$NON-NLS-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 5aea45bf..60ef8c59 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 @@ -23,8 +23,8 @@ import java.io.IOException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.asit.pdfover.gui.Messages; import at.asit.pdfover.gui.exceptions.InitializationException; -import at.asit.pdfover.gui.exceptions.InvalidPortException; import at.asit.pdfover.gui.workflow.ConfigManipulator; import at.asit.pdfover.gui.workflow.StateMachine; @@ -36,7 +36,7 @@ public class OutputFolderArgument extends CLIArgument { * Constructor */ public OutputFolderArgument() { - super(new String[] {"-o"}, "Sets the output folder to use. Example: -o <folder>"); //$NON-NLS-1$ + super(new String[] {"-o"}, Messages.getString("argument.help.output")); //$NON-NLS-1$ //$NON-NLS-2$ } /** @@ -64,7 +64,7 @@ public class OutputFolderArgument extends CLIArgument { } if(!outputFolderDir.isDirectory()) { - throw new IOException(outputFolderDir + " is not a directory"); + throw new IOException(outputFolderDir + Messages.getString("argument.error.output")); //$NON-NLS-1$ } ConfigManipulator configManipulator = stateMachine.getConfigManipulator(); @@ -76,11 +76,11 @@ public class OutputFolderArgument extends CLIArgument { } catch (Exception ex) { log.error("Output folder argument invalid!", ex); //$NON-NLS-1$ throw new InitializationException( - "Output folder argument invalid! Use: " + this.getHelpText(), ex); + Messages.getString("argument.invalid.output") + this.getHelpText(), ex); //$NON-NLS-1$ } throw new InitializationException( - "Output folder argument invalid! Use: " + this.getHelpText(), null); + Messages.getString("argument.invalid.output") + this.getHelpText(), null); //$NON-NLS-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 ab239c88..c30e6748 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 @@ -19,6 +19,7 @@ package at.asit.pdfover.gui.cliarguments; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.asit.pdfover.gui.Messages; import at.asit.pdfover.gui.exceptions.InitializationException; import at.asit.pdfover.gui.workflow.ConfigManipulator; import at.asit.pdfover.gui.workflow.StateMachine; @@ -32,7 +33,7 @@ public class PasswordArgument extends CLIArgument { * Constructor */ public PasswordArgument() { - super(new String[] {"-p"}, "Sets the password to use for mobile bku. Example: -p <password>"); //$NON-NLS-1$ + super(new String[] {"-p"}, Messages.getString("argument.help.password")); //$NON-NLS-1$ //$NON-NLS-2$ } /** @@ -64,11 +65,11 @@ public class PasswordArgument extends CLIArgument { } catch (Exception ex) { log.error("Mobile BKU password argument invalid!", ex); //$NON-NLS-1$ throw new InitializationException( - "Mobile BKU password invalid! Use: " + this.getHelpText(), ex); + Messages.getString("argument.invalid.password") + this.getHelpText(), ex); //$NON-NLS-1$ } throw new InitializationException( - "Mobile BKU password argument invalid! Use: " + this.getHelpText(), null); + Messages.getString("argument.invalid.password") + this.getHelpText(), null); //$NON-NLS-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 6d344c42..a9c14d18 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 @@ -19,6 +19,7 @@ package at.asit.pdfover.gui.cliarguments; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.asit.pdfover.gui.Messages; import at.asit.pdfover.gui.exceptions.InitializationException; import at.asit.pdfover.gui.workflow.ConfigManipulator; import at.asit.pdfover.gui.workflow.StateMachine; @@ -32,7 +33,7 @@ public class PhoneNumberArgument extends CLIArgument { * Constructor */ public PhoneNumberArgument() { - super(new String[] {"-n" }, "Sets the telephone number to use for mobile bku. Example: -n <number>"); //$NON-NLS-1$ + super(new String[] {"-n" }, Messages.getString("argument.help.number")); //$NON-NLS-1$ //$NON-NLS-2$ } @@ -67,11 +68,11 @@ public class PhoneNumberArgument extends CLIArgument { } catch (Exception ex) { log.error("Phone Number Argument invalid!", ex); //$NON-NLS-1$ throw new InitializationException( - "Phone Number Argument invalid! Use: " + this.getHelpText(), ex); + Messages.getString("argument.invalid.number") + this.getHelpText(), ex); //$NON-NLS-1$ } throw new InitializationException( - "Phone Number invalid! Use: " + this.getHelpText(), null); + Messages.getString("argument.invalid.number") + this.getHelpText(), null); //$NON-NLS-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 cb6ce596..da7945a6 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 @@ -16,12 +16,10 @@ package at.asit.pdfover.gui.cliarguments; // Imports -import java.io.File; -import java.io.FileNotFoundException; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.asit.pdfover.gui.Messages; import at.asit.pdfover.gui.exceptions.InitializationException; import at.asit.pdfover.gui.workflow.ConfigManipulator; import at.asit.pdfover.gui.workflow.StateMachine; @@ -34,7 +32,7 @@ public class ProxyHostArgument extends CLIArgument { * Constructor */ public ProxyHostArgument() { - super(new String[] {"-proxy"}, "Sets the proxy host to use. Example: -proxy <hostname/IP>"); //$NON-NLS-1$ + super(new String[] {"-proxy"}, Messages.getString("argument.help.proxyhost")); //$NON-NLS-1$ //$NON-NLS-2$ } /** @@ -64,11 +62,11 @@ public class ProxyHostArgument extends CLIArgument { } catch (Exception ex) { log.error("Proxy host argument invalid!", ex); //$NON-NLS-1$ throw new InitializationException( - "Proxy host invalid! Use: " + this.getHelpText(), ex); + Messages.getString("argument.invalid.proxyhost") + this.getHelpText(), ex); //$NON-NLS-1$ } throw new InitializationException( - "Proxy host argument invalid! Use: " + this.getHelpText(), null); + Messages.getString("argument.invalid.proxyhost") + this.getHelpText(), null); //$NON-NLS-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 aa0d5d81..51ef7554 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 @@ -19,6 +19,7 @@ package at.asit.pdfover.gui.cliarguments; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.asit.pdfover.gui.Messages; import at.asit.pdfover.gui.exceptions.InitializationException; import at.asit.pdfover.gui.exceptions.InvalidPortException; import at.asit.pdfover.gui.workflow.ConfigManipulator; @@ -32,7 +33,7 @@ public class ProxyPortArgument extends CLIArgument { * Constructor */ public ProxyPortArgument() { - super(new String[] {"-proxyport"}, "Sets the proxy port to use. Example: -proxyport <port>"); //$NON-NLS-1$ + super(new String[] {"-proxyport"}, Messages.getString("argument.help.proxyport")); //$NON-NLS-1$ //$NON-NLS-2$ } /** @@ -68,11 +69,11 @@ public class ProxyPortArgument extends CLIArgument { } catch (Exception ex) { log.error("Proxy port argument invalid!", ex); //$NON-NLS-1$ throw new InitializationException( - "Proxy port argument invalid! Use: " + this.getHelpText(), ex); + Messages.getString("argument.invalid.proxyport") + this.getHelpText(), ex); //$NON-NLS-1$ } throw new InitializationException( - "Proxy port argument invalid! Use: " + this.getHelpText(), null); + Messages.getString("argument.invalid.proxyport") + this.getHelpText(), null); //$NON-NLS-1$ } } |