summaryrefslogtreecommitdiff
path: root/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OpenState.java
diff options
context:
space:
mode:
authorBianca Schnalzer <bianca.schnalzer@egiz.gv.at>2017-08-07 08:13:09 +0200
committerBianca Schnalzer <bianca.schnalzer@egiz.gv.at>2017-08-07 08:13:09 +0200
commitc1d04c110f717521d0f6bed3e57fdcd39b5d0498 (patch)
tree4e37dc1fda02f8c78961527d418f262e8442a4cf /pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OpenState.java
parent59fe25941355ef5cf58ea1c1436e276f604cfab7 (diff)
downloadpdf-over-c1d04c110f717521d0f6bed3e57fdcd39b5d0498.tar.gz
pdf-over-c1d04c110f717521d0f6bed3e57fdcd39b5d0498.tar.bz2
pdf-over-c1d04c110f717521d0f6bed3e57fdcd39b5d0498.zip
Certificate Download Server + Searching for Placeholder
Diffstat (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OpenState.java')
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/OpenState.java56
1 files changed, 56 insertions, 0 deletions
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 b77809ed..b2a7cb50 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
@@ -15,17 +15,26 @@
*/
package at.asit.pdfover.gui.workflow.states;
+import java.io.IOException;
+
+import org.apache.pdfbox.pdmodel.PDDocument;
//Imports
import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.MessageBox;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import at.asit.pdfover.gui.MainWindow.Buttons;
import at.asit.pdfover.gui.MainWindowBehavior;
import at.asit.pdfover.gui.composites.DataSourceSelectComposite;
+import at.asit.pdfover.gui.utils.Messages;
import at.asit.pdfover.gui.workflow.StateMachine;
import at.asit.pdfover.gui.workflow.Status;
import at.asit.pdfover.gui.workflow.config.ConfigProvider;
+import at.asit.pdfover.signator.SignaturePosition;
+import at.gv.egiz.pdfas.common.exceptions.PdfAsException;
+import at.gv.egiz.pdfas.lib.impl.pdfbox.placeholder.SignaturePlaceholderExtractor;
+import at.gv.egiz.pdfas.lib.impl.placeholder.SignaturePlaceholderData;
/**
* Selects the data source for the signature process.
@@ -82,6 +91,53 @@ public class OpenState extends State {
}
}
log.debug("Got Datasource: " + getStateMachine().getStatus().getDocument().getAbsolutePath()); //$NON-NLS-1$
+
+ // scan for signature placeholders
+ // - see if we want to scan for placeholders in the settings
+ if (getStateMachine().getConfigProvider().getUseMarker()) {
+ try {
+ // - scan for placeholders
+ PDDocument pddocument = PDDocument.load(getStateMachine().getStatus().getDocument());
+ SignaturePlaceholderData signaturePlaceholderData = SignaturePlaceholderExtractor.extract(pddocument,
+ "1", 3);
+
+ if (null != signaturePlaceholderData) {
+ log.debug("we got a position", signaturePlaceholderData.getId()); //$NON-NLS-1$
+ // create a dialog with ok and cancel buttons and a question
+ // icon
+ MessageBox dialog = new MessageBox(getStateMachine().getGUIProvider().getMainShell(),
+ SWT.ICON_QUESTION | SWT.YES | SWT.NO);
+ dialog.setText(Messages.getString("dataSourceSelection.usePlaceholderTitle")); //$NON-NLS-1$
+ dialog.setMessage(Messages.getString("dataSourceSelection.usePlaceholderText")); //$NON-NLS-1$
+
+ // open dialog and await user selection
+ if (SWT.YES == dialog.open()) {
+ // if the user chooses to use the signature placeholder
+ // - fill the position information so that we skip to
+ // the
+ // next stages without breaking stuff
+ SignaturePosition position = new SignaturePosition(
+ signaturePlaceholderData.getTablePos().getPosX(),
+ signaturePlaceholderData.getTablePos().getPosY(),
+ signaturePlaceholderData.getTablePos().getPage());
+ status.setSignaturePosition(position);
+
+ getStateMachine().getStatus().setSearchForPlaceholderSignature(true);
+ } else {
+ getStateMachine().getStatus().setSearchForPlaceholderSignature(false);
+ }
+ }
+ } catch (PdfAsException e) {
+ // fail silently. In case we got here no dialog has been shown.
+ // Just
+ // proceed with the usual process.
+ } catch (IOException e) {
+ // fail silently. In case we got here no dialog has been shown.
+ // Just
+ // proceed with the usual process.
+ }
+ }
+
this.setNextState(new PositioningState(getStateMachine()));
}