summaryrefslogtreecommitdiff
path: root/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments
diff options
context:
space:
mode:
Diffstat (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments')
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/ArgumentHandler.java115
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/BKUArgument.java67
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/CLIArgument.java102
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/ConfigFileArgument.java72
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/HelpArgument.java71
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/PhoneNumberArgument.java77
6 files changed, 504 insertions, 0 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
new file mode 100644
index 00000000..f43b636c
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/ArgumentHandler.java
@@ -0,0 +1,115 @@
+/*
+ * 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.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.asit.pdfover.gui.exceptions.InitializationException;
+import at.asit.pdfover.gui.workflow.StateMachine;
+
+/**
+ *
+ */
+public class ArgumentHandler {
+ /**
+ * SLF4J Logger instance
+ **/
+ @SuppressWarnings("unused")
+ private static final Logger log = LoggerFactory
+ .getLogger(ArgumentHandler.class);
+
+ private Map<String, CLIArgument> cliArguments = new HashMap<String, CLIArgument>();
+
+ private StateMachine stateMachine = null;
+
+ private boolean requiredExit = false;
+
+ /**
+ * Constructor
+ * @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) {
+ return;
+ }
+
+ String[] commandOptions = arg.getCommandOptions();
+
+ if(commandOptions == null) {
+ return;
+ }
+
+ for(int i = 0; i < commandOptions.length; i++)
+ {
+ this.cliArguments.put(commandOptions[i], arg);
+ }
+ }
+
+ /**
+ * Handle CLI Arguments
+ *
+ * @param args
+ * @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);
+ }
+ }
+ }
+
+ /**
+ * 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
+ *
+ * @return true or false
+ */
+ public boolean IsRequireExit() {
+ return this.requiredExit;
+ }
+}
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
new file mode 100644
index 00000000..e8d721ca
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/BKUArgument.java
@@ -0,0 +1,67 @@
+/*
+ * 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.ConfigManipulator;
+import at.asit.pdfover.gui.workflow.StateMachine;
+import at.asit.pdfover.signator.BKUs;
+
+/**
+ *
+ */
+public class BKUArgument extends CLIArgument {
+ /**
+ * Constructor
+ */
+ public BKUArgument() {
+ super(
+ new String[] { "-b" }, "Select the BKU to use values are: LOCAL, MOBILE (example: -b <option>"); //$NON-NLS-1$
+ }
+
+ /*
+ * (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) {
+
+ BKUs argumentValue = BKUs.valueOf(args[argOffset + 1]);
+
+ ConfigManipulator configManipulator = stateMachine.getConfigManipulator();
+
+ configManipulator.setDefaultBKU(argumentValue);
+
+ return argOffset + 1;
+ }
+ } catch (Exception ex) {
+ throw new InitializationException(
+ "BKU Argument invalid! Use: " + this.getHelpText(), ex); //$NON-NLS-1$
+ }
+
+ throw new InitializationException(
+ "BKU Argument invalid! Use: " + this.getHelpText(), null); //$NON-NLS-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
new file mode 100644
index 00000000..7f8d4366
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/CLIArgument.java
@@ -0,0 +1,102 @@
+/*
+ * 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.StateMachine;
+
+/**
+ *
+ */
+public abstract class CLIArgument {
+
+ private String helpText = null;
+
+ private String[] commandOptions = null;
+
+ /**
+ * @param commandOptions
+ * @param helpText
+ */
+ protected CLIArgument(String[] commandOptions, String helpText) {
+ this.helpText = helpText;
+ this.commandOptions = commandOptions;
+ }
+
+ /**
+ * 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 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;
+}
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
new file mode 100644
index 00000000..9ddeaf6c
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/ConfigFileArgument.java
@@ -0,0 +1,72 @@
+/*
+ * 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 org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+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;
+
+/**
+ *
+ */
+public class ConfigFileArgument extends CLIArgument {
+ /**
+ * SLF4J Logger instance
+ **/
+ private static final Logger log = LoggerFactory
+ .getLogger(ConfigFileArgument.class);
+
+ /**
+ * Constructor
+ */
+ public ConfigFileArgument() {
+ super(new String[] {"-c"}, "Defines which configuration file to use. Example: -c <config file>"); //$NON-NLS-1$
+ }
+
+ /* (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 configFile = args[argOffset + 1];
+
+ ConfigManipulator configManipulator = stateMachine.getConfigManipulator();
+
+ configManipulator.setConfigurationFile(configFile);
+
+ return argOffset + 1;
+ }
+ } catch (Exception ex) {
+ log.error("Configuration File Argument invalid!", ex); //$NON-NLS-1$
+ throw new InitializationException(
+ "Configuration File Argument invalid! Use: " + this.getHelpText(), ex); //$NON-NLS-1$
+ }
+
+ throw new InitializationException(
+ "Configuration File invalid! Use: " + 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
new file mode 100644
index 00000000..8087807c
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/HelpArgument.java
@@ -0,0 +1,71 @@
+/*
+ * 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.util.Iterator;
+import java.util.Set;
+
+import at.asit.pdfover.gui.exceptions.InitializationException;
+import at.asit.pdfover.gui.workflow.StateMachine;
+
+/**
+ *
+ */
+public class HelpArgument extends CLIArgument {
+
+ /**
+ * Constructor
+ */
+ public HelpArgument() {
+ super(new String[] {"-h", "-?" }, "shows this help message"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /* (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 {
+ Set<CLIArgument> arguments = handler.getArguments();
+
+ Iterator<CLIArgument> argumentIterator = arguments.iterator();
+
+ System.out.println("The following options are available"); //$NON-NLS-1$
+
+ while(argumentIterator.hasNext()) {
+ CLIArgument agrument = argumentIterator.next();
+ StringBuilder sb = new StringBuilder();
+
+ for(int i = 0; i < agrument.getCommandOptions().length; i++) {
+ sb.append(agrument.getCommandOptions()[i]);
+
+ if(i < agrument.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$
+ }
+
+ handler.setRequireExit(true);
+
+ return argOffset;
+ }
+
+}
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
new file mode 100644
index 00000000..255b4f91
--- /dev/null
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/cliarguments/PhoneNumberArgument.java
@@ -0,0 +1,77 @@
+/*
+ * 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 org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+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;
+
+/**
+ *
+ */
+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$
+ }
+
+
+ /**
+ * SLF4J Logger instance
+ **/
+ private static final Logger log = LoggerFactory
+ .getLogger(PhoneNumberArgument.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 number = args[argOffset + 1];
+
+ number = ATrustHelper.normalizeMobileNumber(number);
+
+ ConfigManipulator configManipulator = stateMachine.getConfigManipulator();
+
+ configManipulator.setDefaultMobileNumber(number);
+
+ return argOffset + 1;
+ }
+ } catch (Exception ex) {
+ log.error("Phone Number Argument invalid!", ex); //$NON-NLS-1$
+ throw new InitializationException(
+ "Phone Number Argument invalid! Use: " + this.getHelpText(), ex); //$NON-NLS-1$
+ }
+
+ throw new InitializationException(
+ "Phone Number invalid! Use: " + this.getHelpText(), null); //$NON-NLS-1$
+ }
+
+}