summaryrefslogtreecommitdiff
path: root/pdf-over-gui/src/main/java
diff options
context:
space:
mode:
authorAndreas Abraham <andreas.abraham@egiz.gv.at>2019-12-02 12:54:22 +0100
committerAndreas Abraham <andreas.abraham@egiz.gv.at>2019-12-02 12:54:22 +0100
commit44256e68fc579cb804d56d1fb5525c6c29d8c38b (patch)
treecbb173b3db8b2c1c3b8fb46f9aef3f7360c92742 /pdf-over-gui/src/main/java
parenteb8993049ab6341152daa0f2e6a0650be38e8843 (diff)
downloadpdf-over-44256e68fc579cb804d56d1fb5525c6c29d8c38b.tar.gz
pdf-over-44256e68fc579cb804d56d1fb5525c6c29d8c38b.tar.bz2
pdf-over-44256e68fc579cb804d56d1fb5525c6c29d8c38b.zip
signature placeholder (pdf signature annotation) implemented
Diffstat (limited to 'pdf-over-gui/src/main/java')
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/Constants.java5
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OpenState.java64
2 files changed, 49 insertions, 20 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Constants.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Constants.java
index f1ee6165..162fbd15 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Constants.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/Constants.java
@@ -44,6 +44,11 @@ public class Constants {
// Has to be set before (implicitly) initializing Display
Display.setAppName(APP_NAME);
}
+
+ /**
+ *
+ */
+ public static final String SIGNATURE_FIELD_NAME_CONF = "signature_field_name";
/** Current display - used for Colors */
private static Display display = Display.getCurrent();
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OpenState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OpenState.java
index 9e9d0700..c3681dd8 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OpenState.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OpenState.java
@@ -18,7 +18,9 @@ package at.asit.pdfover.gui.workflow.states;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
+import java.io.FileWriter;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.util.List;
import java.util.Properties;
@@ -46,6 +48,10 @@ import at.gv.egiz.pdfas.lib.impl.pdfbox2.placeholder.SignatureFieldsExtractor;
import at.gv.egiz.pdfas.lib.impl.pdfbox2.placeholder.SignaturePlaceholderExtractor;
//import at.gv.egiz.pdfas.lib.impl.pdfbox2.placeholder.
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.commons.configuration.PropertiesConfigurationLayout;
+
/**
* Selects the data source for the signature process.
@@ -64,7 +70,8 @@ public class OpenState extends State {
**/
private static final Logger log = LoggerFactory
.getLogger(OpenState.class);
-
+ private static final String advancedConfig = Constants.CONFIG_DIRECTORY + File.separator + "/cfg/advancedconfig.properties"; //$NON-NLS-1$
+
private DataSourceSelectComposite selectionComposite = null;
private DataSourceSelectComposite getSelectionComposite() {
@@ -140,25 +147,8 @@ public class OpenState extends State {
System.out.println("ok pressed"); //$NON-NLS-1$
getStateMachine().getStatus().setSearchForPlaceholderSignature(true);
- //TODO configure and skip placing
- //TODO fix this
- try {
- String cfgPath = Constants.CONFIG_DIRECTORY + File.separator + "/cfg/advancedconfig.properties"; //$NON-NLS-1$
- FileInputStream in = new FileInputStream(cfgPath);
- Properties props = new Properties();
- props.load(in);
- in.close();
-
- FileOutputStream out = new FileOutputStream(cfgPath); //$NON-NLS-1$
- props.setProperty("signature_field_name", fields.get(res)); //$NON-NLS-1$ //$NON-NLS-2$
- props.store(out, null);
- out.close();
-
- } catch (Exception e) {
- System.err.println(e.getMessage());
- System.err.println(e.getStackTrace());
- }
-
+
+ addPlaceholderSelectionToConfig(fields.get(res));
this.setNextState(new BKUSelectionState(getStateMachine()));
return;
@@ -196,6 +186,40 @@ public class OpenState extends State {
this.setNextState(new PositioningState(getStateMachine()));
}
+
+ /**
+ * The selected placeholder is added to the configuration file
+ * @param selection
+ */
+ @SuppressWarnings("static-method")
+ private void addPlaceholderSelectionToConfig(String selection) {
+ try {
+ FileInputStream in = new FileInputStream(advancedConfig);
+// Properties props = new Properties();
+// props.load(in);
+// in.close();
+//
+//
+//
+// FileOutputStream out = new FileOutputStream(advancedConfig);
+// props.setProperty(Constants.SIGNATURE_FIELD_NAME_CONF, selection); //$NON-NLS-1$
+//
+// props.store(out, null);
+// out.close();
+
+
+ PropertiesConfiguration config = new PropertiesConfiguration();
+ PropertiesConfigurationLayout layout = new PropertiesConfigurationLayout(config);
+ layout.load(new InputStreamReader(new FileInputStream(advancedConfig)));
+
+ config.setProperty(Constants.SIGNATURE_FIELD_NAME_CONF, selection);
+ layout.save(new FileWriter(advancedConfig, false));
+
+ } catch (Exception e) {
+ log.error(e.getMessage(), e.getStackTrace());
+ }
+
+ }
/**
* Open the input document selection dialog