From d6de3b8d165b29ba6f6a0a629dc83ca01b60dde1 Mon Sep 17 00:00:00 2001 From: tkellner Date: Wed, 10 Apr 2013 19:36:13 +0000 Subject: Handle argument help localization correctly git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@406 174cde9d-5d70-4d2a-aa98-46368bc2aaf7 --- .../at/asit/pdfover/gui/cliarguments/Argument.java | 129 ++++++++++++++++++++ .../pdfover/gui/cliarguments/ArgumentHandler.java | 10 +- .../asit/pdfover/gui/cliarguments/BKUArgument.java | 4 +- .../asit/pdfover/gui/cliarguments/CLIArgument.java | 131 --------------------- .../gui/cliarguments/ConfigFileArgument.java | 4 +- .../pdfover/gui/cliarguments/EmblemArgument.java | 4 +- .../pdfover/gui/cliarguments/HelpArgument.java | 18 +-- .../gui/cliarguments/InputDocumentArgument.java | 6 +- .../gui/cliarguments/OutputFolderArgument.java | 4 +- .../pdfover/gui/cliarguments/PasswordArgument.java | 4 +- .../gui/cliarguments/PhoneNumberArgument.java | 4 +- .../gui/cliarguments/ProxyHostArgument.java | 4 +- .../gui/cliarguments/ProxyPortArgument.java | 4 +- .../pdfover/gui/workflow/ConfigProviderImpl.java | 8 +- 14 files changed, 166 insertions(+), 168 deletions(-) create mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/Argument.java delete mode 100644 pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/CLIArgument.java (limited to 'pdf-over-gui/src/main/java') 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 new file mode 100644 index 00000000..761e5dc3 --- /dev/null +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/Argument.java @@ -0,0 +1,129 @@ +/* + * 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; + +import at.asit.pdfover.gui.exceptions.InitializationException; +import at.asit.pdfover.gui.utils.Messages; +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 Argument { + + private String helpTextKey = null; + + private String[] commandOptions = null; + + private StateMachine stateMachine; + + /** + * @param commandOptions + * @param helpTextKey + */ + protected Argument(String[] commandOptions, String helpTextKey) { + this.helpTextKey = helpTextKey; + 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 key + * @param key + */ + protected void setHelpTextKey(String key) { + this.helpTextKey = key; + } + + /** + * Gets help text + * @return help text + */ + public String getHelpText() { + return Messages.getString(this.helpTextKey); + } + + /** + * Set the command option in format: -... + * + * Examples: -h + * + * @param value + */ + protected void setCommandOptions(String[] value) { + this.commandOptions = value; + } + + /** + * Get the command option + * + * Examples: -h + * @return the command option + */ + public String[] getCommandOptions() { + return this.commandOptions; + } + + /** + * Invokes the argument to set stuff within the stateMachine + * + * It should return the offset within the args array where the last used argument of this Argument was used. + * + * Example: + * args[] = { "-h", "-b", "LOCAL" } + * + * Help Argument call: + * offset = 0 + * returns 0 + * + * BKU Argument call: + * offset = 1 + * returns 2 + * + * @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, ArgumentHandler handler) throws InitializationException; +} 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 378588eb..9fb6f7ab 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 @@ -37,7 +37,7 @@ public class ArgumentHandler { private static final Logger log = LoggerFactory .getLogger(ArgumentHandler.class); - private Map cliArguments = new HashMap(); + private Map cliArguments = new HashMap(); private StateMachine stateMachine = null; @@ -57,8 +57,8 @@ public class ArgumentHandler { * * @return the list of available arguments */ - public Set getArguments() { - return new HashSet(this.cliArguments.values()); + public Set getArguments() { + return new HashSet(this.cliArguments.values()); } /** @@ -66,9 +66,9 @@ public class ArgumentHandler { * * @param cliArgument the CLIArgument subclass to add */ - public void addCLIArgument(Class cliArgument) { + public void addCLIArgument(Class cliArgument) { - CLIArgument arg; + Argument arg; try { arg = cliArgument.newInstance(); 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 b1902cb1..058d84cf 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 @@ -22,13 +22,13 @@ import at.asit.pdfover.signator.BKUs; /** * CLI Argument to set the BKU to use */ -public class BKUArgument extends CLIArgument { +public class BKUArgument extends Argument { /** * Constructor */ public BKUArgument() { super( - new String[] { "-b" }, Messages.getString("argument.help.bku")); //$NON-NLS-1$ //$NON-NLS-2$ + new String[] { "-b" }, "argument.help.bku"); //$NON-NLS-1$ //$NON-NLS-2$ } /* 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 deleted file mode 100644 index 4c471118..00000000 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/CLIArgument.java +++ /dev/null @@ -1,131 +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.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 - */ - protected CLIArgument(String[] commandOptions, String helpText) { - 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 - * - * @param value - */ - protected void setHelpText(String value) { - this.helpText = value; - } - - /** - * Gets help text - * - * @return help text - */ - public String getHelpText() { - return this.helpText; - } - - /** - * Set the command option in format: -... - * - * Examples: -h - * - * @param value - */ - protected void setCommandOptions(String[] value) { - this.commandOptions = value; - } - - /** - * Get the command option - * - * Examples: -h - * @return the command option - */ - public String[] getCommandOptions() { - return this.commandOptions; - } - - /** - * Invokes the argument to set stuff within the stateMachine - * - * It should return the offset within the args array where the last used argument of this CLIArgument was used. - * - * Example: - * args[] = { "-h", "-b", "LOCAL" } - * - * Help Argument call: - * offset = 0 - * returns 0 - * - * BKU Argument call: - * offset = 1 - * returns 2 - * - * @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, 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 7fd3acef..0f73143d 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 @@ -25,7 +25,7 @@ import at.asit.pdfover.gui.utils.Messages; /** * CLI Argument to set the configuration file */ -public class ConfigFileArgument extends CLIArgument { +public class ConfigFileArgument extends Argument { /** * SLF4J Logger instance **/ @@ -36,7 +36,7 @@ public class ConfigFileArgument extends CLIArgument { * Constructor */ public ConfigFileArgument() { - super(new String[] {"-c"}, Messages.getString("argument.help.config")); //$NON-NLS-1$ //$NON-NLS-2$ + super(new String[] {"-c"}, "argument.help.config"); //$NON-NLS-1$ //$NON-NLS-2$ } /* (non-Javadoc) 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 98401b16..96b3690b 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 @@ -28,12 +28,12 @@ import at.asit.pdfover.gui.utils.Messages; /** * CLI Argument to set the emblem file to use for signature */ -public class EmblemArgument extends CLIArgument { +public class EmblemArgument extends Argument { /** * Constructor */ public EmblemArgument() { - super(new String[] {"-e"}, Messages.getString("argument.help.emblem")); //$NON-NLS-1$ //$NON-NLS-2$ + super(new String[] {"-e"}, "argument.help.emblem"); //$NON-NLS-1$ //$NON-NLS-2$ } /** 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 3160b4e4..77d95ae9 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 @@ -25,14 +25,14 @@ import at.asit.pdfover.gui.utils.Messages; /** * CLI Argument to show the useage message */ -public class HelpArgument extends CLIArgument { +public class HelpArgument extends Argument { /** * Constructor */ public HelpArgument() { super(new String[] {"-h", "-?", "--help" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - Messages.getString("argument.help.help")); //$NON-NLS-1$ + "argument.help.help"); //$NON-NLS-1$ } /* (non-Javadoc) @@ -42,26 +42,26 @@ public class HelpArgument extends CLIArgument { public int handleArgument(String[] args, int argOffset, ArgumentHandler handler) throws InitializationException { - Set arguments = handler.getArguments(); + Set arguments = handler.getArguments(); - Iterator argumentIterator = arguments.iterator(); + Iterator argumentIterator = arguments.iterator(); System.out.println(Messages.getString("argument.info.help")); //$NON-NLS-1$ while(argumentIterator.hasNext()) { - CLIArgument agrument = argumentIterator.next(); + Argument argument = argumentIterator.next(); StringBuilder sb = new StringBuilder(); - for(int i = 0; i < agrument.getCommandOptions().length; i++) { - sb.append(agrument.getCommandOptions()[i]); + for(int i = 0; i < argument.getCommandOptions().length; i++) { + sb.append(argument.getCommandOptions()[i]); - if(i < agrument.getCommandOptions().length -1) { + if(i < argument.getCommandOptions().length -1) { sb.append(", "); //$NON-NLS-1$ } } System.out.println(sb.toString() + ":"); //$NON-NLS-1$ - System.out.println("\t" + agrument.getHelpText()); //$NON-NLS-1$ + System.out.println("\t" + argument.getHelpText()); //$NON-NLS-1$ } handler.setRequireExit(true); 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 efb2c3aa..37c0c81c 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 @@ -28,12 +28,12 @@ import at.asit.pdfover.gui.utils.Messages; /** * CLI Argument to set the input document to sign */ -public class InputDocumentArgument extends CLIArgument { +public class InputDocumentArgument extends Argument { /** * Constructor */ public InputDocumentArgument() { - super(new String[] {"-i"}, Messages.getString("argument.help.input")); //$NON-NLS-1$ //$NON-NLS-2$ + super(new String[] {"-i"}, "argument.help.input"); //$NON-NLS-1$ //$NON-NLS-2$ } /** @@ -43,7 +43,7 @@ public class InputDocumentArgument extends CLIArgument { .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) + * @see at.asit.pdfovewr.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, 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 037a4226..7bce81c1 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,12 +25,12 @@ import at.asit.pdfover.gui.utils.Messages; /** * CLI Argument to show the usage message */ -public class OutputFolderArgument extends CLIArgument { +public class OutputFolderArgument extends Argument { /** * Constructor */ public OutputFolderArgument() { - super(new String[] {"-o"}, Messages.getString("argument.help.output")); //$NON-NLS-1$ //$NON-NLS-2$ + super(new String[] {"-o"}, "argument.help.output"); //$NON-NLS-1$ //$NON-NLS-2$ } /** 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 1f90cda2..268468d9 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 @@ -26,12 +26,12 @@ import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHelper; /** * CLI Argument to provide Mobile BKU password */ -public class PasswordArgument extends CLIArgument { +public class PasswordArgument extends Argument { /** * Constructor */ public PasswordArgument() { - super(new String[] {"-p"}, Messages.getString("argument.help.password")); //$NON-NLS-1$ //$NON-NLS-2$ + super(new String[] {"-p"}, "argument.help.password"); //$NON-NLS-1$ //$NON-NLS-2$ } /** 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 a6a1cb79..afaa01c7 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 @@ -26,12 +26,12 @@ import at.asit.pdfover.gui.workflow.states.mobilebku.MobileBKUHelper; /** * CLI Argument to provide Mobile BKU phone number to use */ -public class PhoneNumberArgument extends CLIArgument { +public class PhoneNumberArgument extends Argument { /** * Constructor */ public PhoneNumberArgument() { - super(new String[] {"-n" }, Messages.getString("argument.help.number")); //$NON-NLS-1$ //$NON-NLS-2$ + super(new String[] {"-n" }, "argument.help.number"); //$NON-NLS-1$ //$NON-NLS-2$ } 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 cc50705e..779d6cee 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 @@ -25,12 +25,12 @@ import at.asit.pdfover.gui.utils.Messages; /** * CLI Argument to provide the proxy host */ -public class ProxyHostArgument extends CLIArgument { +public class ProxyHostArgument extends Argument { /** * Constructor */ public ProxyHostArgument() { - super(new String[] {"-proxy"}, Messages.getString("argument.help.proxyhost")); //$NON-NLS-1$ //$NON-NLS-2$ + super(new String[] {"-proxy"}, "argument.help.proxyhost"); //$NON-NLS-1$ //$NON-NLS-2$ } /** 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 a9bceead..5f5db33a 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 @@ -26,12 +26,12 @@ import at.asit.pdfover.gui.utils.Messages; /** * CLI Argument to provide the proxy port */ -public class ProxyPortArgument extends CLIArgument { +public class ProxyPortArgument extends Argument { /** * Constructor */ public ProxyPortArgument() { - super(new String[] {"-proxyport"}, Messages.getString("argument.help.proxyport")); //$NON-NLS-1$ //$NON-NLS-2$ + super(new String[] {"-proxyport"}, "argument.help.proxyport"); //$NON-NLS-1$ //$NON-NLS-2$ } /** 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 e9fbe1c2..ec0be92d 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 @@ -103,17 +103,17 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator, this.setDefaultOutputFolder(config .getProperty(Constants.CFG_OUTPUT_FOLDER)); - String localString = config.getProperty(Constants.CFG_LOCALE); + String localeString = config.getProperty(Constants.CFG_LOCALE); - Locale targetLocale = LocaleSerializer.parseFromString(localString); - if(targetLocale != null) { + Locale targetLocale = LocaleSerializer.parseFromString(localeString); + if (targetLocale != null) { this.setLocale(targetLocale); } String signlocalString = config.getProperty(Constants.CFG_SIGN_LOCALE); Locale signtargetLocale = LocaleSerializer.parseFromString(signlocalString); - if(signtargetLocale != null) { + if (signtargetLocale != null) { this.setSignLocale(signtargetLocale); } -- cgit v1.2.3