summaryrefslogtreecommitdiff
path: root/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow
diff options
context:
space:
mode:
Diffstat (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow')
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/ConfigProviderImpl.java6
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java58
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java116
3 files changed, 143 insertions, 37 deletions
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 ea4088c6..a95423e3 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
@@ -309,7 +309,11 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator {
*/
@Override
public void setDefaultOutputFolder(String outputFolder) {
- this.outputFolder = outputFolder;
+ if (outputFolder == null || outputFolder.trim().equals("")) { //$NON-NLS-1$
+ this.outputFolder = STRING_EMPTY;
+ } else {
+ this.outputFolder = outputFolder;
+ }
}
/*
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java
index f04805a7..18f913ef 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/MobileBKUState.java
@@ -150,11 +150,12 @@ public class MobileBKUState extends State {
MobileBKUStatus mobileStatus = this.getStatus();
if (this.threadException != null) {
- ErrorDialog error = new ErrorDialog(this.stateMachine.getGUIProvider().getMainShell(),
+ ErrorDialog error = new ErrorDialog(
+ this.stateMachine.getGUIProvider().getMainShell(),
SWT.NONE,
Messages.getString("error.Unexpected"), this.threadException, false); //$NON-NLS-1$
- //error.setException(this.threadException);
- //this.setNextState(error);
+ // error.setException(this.threadException);
+ // this.setNextState(error);
error.open();
this.stateMachine.exit();
return;
@@ -165,7 +166,8 @@ public class MobileBKUState extends State {
this.stateMachine.getGUIProvider().display(
this.getWaitingComposite());
Thread postSLRequestThread = new Thread(new PostSLRequestThread(
- this, this.stateMachine.getConfigProvider().getMobileBKUURL()));
+ this, this.stateMachine.getConfigProvider()
+ .getMobileBKUURL()));
postSLRequestThread.start();
break;
case POST_NUMBER:
@@ -208,16 +210,26 @@ public class MobileBKUState extends State {
} else {
// We need number and password => show UI!
+
+ if (mobileStatus.getErrorMessage() != null
+ && !mobileStatus.getErrorMessage().equals("")) { //$NON-NLS-1$
+ // set possible error message
+ ui.setErrorMessage(mobileStatus.getErrorMessage());
+ mobileStatus.setErrorMessage(null);
+ }
- // set possible error message
- ui.setErrorMessage(mobileStatus.getErrorMessage());
-
- // set possible phone number
- ui.setMobileNumber(mobileStatus.getPhoneNumber());
-
- // set possible password
- ui.setMobilePassword(mobileStatus.getMobilePassword());
-
+
+ if (ui.getMobileNumber() == null
+ || ui.getMobileNumber().equals("")) { //$NON-NLS-1$
+ // set possible phone number
+ ui.setMobileNumber(mobileStatus.getPhoneNumber());
+ }
+
+ if (ui.getMobilePassword() == null
+ || ui.getMobilePassword().equals("")) { //$NON-NLS-1$
+ // set possible password
+ ui.setMobilePassword(mobileStatus.getMobilePassword());
+ }
this.stateMachine.getGUIProvider().display(ui);
}
}
@@ -231,23 +243,23 @@ public class MobileBKUState extends State {
if (tan.isUserAck()) {
// user hit ok!
tan.setUserAck(false);
-
+
mobileStatus.setTan(tan.getTan());
-
+
// post to BKU!
Thread postTanThread = new Thread(new PostTanThread(this));
postTanThread.start();
} else {
tan.setVergleichswert(mobileStatus.getVergleichswert());
-
- if(mobileStatus.getTanTries() < MobileBKUStatus.MOBILE_MAX_TAN_TRIES
+
+ if (mobileStatus.getTanTries() < MobileBKUStatus.MOBILE_MAX_TAN_TRIES
&& mobileStatus.getTanTries() > 0) {
// show warning message x tries left!
-
+
tan.setTries(mobileStatus.getTanTries());
-
- }
+
+ }
this.stateMachine.getGUIProvider().display(tan);
}
@@ -265,11 +277,11 @@ public class MobileBKUState extends State {
*/
@Override
public void cleanUp() {
- if(this.mobileBKUEnterNumberComposite != null)
+ if (this.mobileBKUEnterNumberComposite != null)
this.mobileBKUEnterNumberComposite.dispose();
- if(this.mobileBKUEnterTANComposite != null)
+ if (this.mobileBKUEnterTANComposite != null)
this.mobileBKUEnterTANComposite.dispose();
- if(this.waitingComposite != null)
+ if (this.waitingComposite != null)
this.waitingComposite.dispose();
}
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 6957f85c..237dffa9 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
@@ -16,16 +16,21 @@
package at.asit.pdfover.gui.workflow.states;
//Imports
+import java.io.BufferedInputStream;
+import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
import org.eclipse.swt.SWT;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import at.asit.pdfover.gui.Messages;
+import at.asit.pdfover.gui.Unzipper;
import at.asit.pdfover.gui.cliarguments.ArgumentHandler;
import at.asit.pdfover.gui.cliarguments.BKUArgument;
import at.asit.pdfover.gui.cliarguments.ConfigFileArgument;
@@ -50,7 +55,11 @@ import at.asit.pdfover.signator.Signator;
*/
public class PrepareConfigurationState extends State {
-
+ /**
+ * PDFOver config directory
+ */
+ public static String CONFIG_DIRECTORY = System.getProperty("user.home") + "/.pdfover"; //$NON-NLS-1$ //$NON-NLS-2$
+
/**
* @param stateMachine
*/
@@ -68,8 +77,7 @@ public class PrepareConfigurationState extends State {
this.handler.addCLIArgument(new InputDocumentArgument());
// adding config file argument to this handler so it appears in help
this.handler.addCLIArgument(new ConfigFileArgument());
-
-
+
this.configFilehandler = new ArgumentHandler(this.stateMachine);
this.configFilehandler.addCLIArgument(new ConfigFileArgument());
}
@@ -89,10 +97,11 @@ public class PrepareConfigurationState extends State {
try {
try {
- this.stateMachine.getConfigProvider().loadConfiguration(new FileInputStream(filename));
-
+ this.stateMachine.getConfigProvider().loadConfiguration(
+ new FileInputStream(CONFIG_DIRECTORY + "/" + filename)); //$NON-NLS-1$
+
log.info("Loaded config from file : " + filename); //$NON-NLS-1$
-
+
} catch (FileNotFoundException ex) {
if (filename.equals(ConfigManipulator.DEFAULT_CONFIG_FILE)) {
// we only check for resource config file if it is the
@@ -100,8 +109,9 @@ public class PrepareConfigurationState extends State {
try {
InputStream is = this.getClass().getResourceAsStream(
"/" + filename); //$NON-NLS-1$
- this.stateMachine.getConfigProvider().loadConfiguration(is);
-
+ this.stateMachine.getConfigProvider()
+ .loadConfiguration(is);
+
log.info("Loaded config from resource : " + filename); //$NON-NLS-1$
} catch (Exception eex) {
throw ex;
@@ -110,7 +120,7 @@ public class PrepareConfigurationState extends State {
throw ex;
}
}
-
+
} catch (IOException ex) {
throw new InitializationException(
"Failed to read configuration from config file", ex); //$NON-NLS-1$
@@ -130,6 +140,85 @@ public class PrepareConfigurationState extends State {
public void run() {
// Read config file
try {
+
+ File configDir = new File(CONFIG_DIRECTORY);
+ File configFile = new File(CONFIG_DIRECTORY + "/" //$NON-NLS-1$
+ + ConfigManipulator.DEFAULT_CONFIG_FILE);
+ if (!configDir.exists() || !configFile.exists()) {
+ boolean allOK = false;
+
+ log.info("Creating configuration directory"); //$NON-NLS-1$
+
+ try {
+ if (!configDir.exists()) {
+ configDir.mkdir();
+ }
+ // Copy PDFOver config to config Dir
+
+ // 1Kb buffer
+ byte[] buffer = new byte[1024];
+ int byteCount = 0;
+
+ InputStream inputStream = null;
+ FileOutputStream pdfOverConfig = null;
+ try {
+ inputStream = this.getClass().getResourceAsStream(
+ "/" + ConfigManipulator.DEFAULT_CONFIG_FILE); //$NON-NLS-1$
+ pdfOverConfig = new FileOutputStream(CONFIG_DIRECTORY
+ + "/" //$NON-NLS-1$
+ + ConfigManipulator.DEFAULT_CONFIG_FILE);
+
+ while ((byteCount = inputStream.read(buffer)) >= 0) {
+ pdfOverConfig.write(buffer, 0, byteCount);
+ }
+ } catch (Exception e) {
+ log.error(
+ "Failed to write PDF Over config file to config directory", e); //$NON-NLS-1$
+ throw new InitializationException(
+ "Failed to write PDF Over config file to config directory",
+ e);
+ } finally {
+ if (pdfOverConfig != null) {
+ try {
+ pdfOverConfig.close();
+ } catch (IOException e) {
+ log.warn(
+ "Failed to close File stream for PDFOver config", e); //$NON-NLS-1$
+ }
+ }
+
+ if (inputStream != null) {
+ try {
+ inputStream.close();
+ } catch (IOException e) {
+ log.warn(
+ "Failed to close Resource stream for PDFOver config", e); //$NON-NLS-1$
+ }
+ }
+ }
+
+ InputStream is = this.getClass().getResourceAsStream(
+ "/cfg/PDFASConfig.zip"); //$NON-NLS-1$
+
+ try {
+ Unzipper.unzip(is, configDir.getAbsolutePath());
+ } catch (IOException e) {
+ log.error(
+ "Failed to create local configuration directory!", e); //$NON-NLS-1$
+ throw new InitializationException(
+ "Failed to create local configuration directory!",
+ e);
+ }
+ allOK = true;
+ } finally {
+ if (!allOK) {
+ configDir.delete();
+ }
+ }
+ } else {
+ log.debug("Configuration directory exists!");
+ }
+
// Read cli arguments with for config file!
this.initializeFromArguments(this.stateMachine.getCmdArgs(),
this.configFilehandler);
@@ -158,11 +247,12 @@ public class PrepareConfigurationState extends State {
} catch (InitializationException e) {
log.error("Failed to initialize: ", e); //$NON-NLS-1$
- ErrorDialog error = new ErrorDialog(this.stateMachine.getGUIProvider().getMainShell(),
- SWT.NONE, Messages.getString("error.Initialization"), //$NON-NLS-1$
+ ErrorDialog error = new ErrorDialog(this.stateMachine
+ .getGUIProvider().getMainShell(), SWT.NONE,
+ Messages.getString("error.Initialization"), //$NON-NLS-1$
e, false);
- //error.setException(e);
- //this.setNextState(error);
+ // error.setException(e);
+ // this.setNextState(error);
error.open();
this.stateMachine.exit();
}