diff options
4 files changed, 66 insertions, 18 deletions
diff --git a/pdf-over-gui/.classpath b/pdf-over-gui/.classpath index 8308daea..a6e09d11 100644 --- a/pdf-over-gui/.classpath +++ b/pdf-over-gui/.classpath @@ -28,5 +28,6 @@ </attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
+ <classpathentry kind="lib" path="swing2swt.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
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 769e772e..9e9d0700 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,8 +15,12 @@ */ package at.asit.pdfover.gui.workflow.states; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; import java.util.List; +import java.util.Properties; import org.apache.pdfbox.pdmodel.PDDocument; @@ -26,8 +30,10 @@ import org.eclipse.swt.widgets.MessageBox; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import at.asit.pdfover.gui.Constants; import at.asit.pdfover.gui.MainWindow.Buttons; import at.asit.pdfover.gui.MainWindowBehavior; +import at.asit.pdfover.gui.PlaceholderSelectionGui; import at.asit.pdfover.gui.composites.DataSourceSelectComposite; import at.asit.pdfover.gui.utils.Messages; import at.asit.pdfover.gui.workflow.StateMachine; @@ -112,7 +118,7 @@ public class OpenState extends State { } SignaturePlaceholderData signaturePlaceholderData = SignaturePlaceholderExtractor.extract(pddocument, - "1", 3); + "1", 3); //$NON-NLS-1$ if (null != signaturePlaceholderData || fields.size() > 0) { // create a dialog with ok and cancel buttons and a question @@ -125,7 +131,41 @@ public class OpenState extends State { // open dialog and await user selection if (SWT.YES == dialog.open()) { - //TODO if yes handle the two differnet cases + if (fields.size() > 0) { + + PlaceholderSelectionGui gui = new PlaceholderSelectionGui(getStateMachine().getGUIProvider().getMainShell(), + 65570, "text","select the fields", fields); //$NON-NLS-1$ //$NON-NLS-2$ + int res = gui.open(); + if (res != -1) { + + 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()); + } + + this.setNextState(new BKUSelectionState(getStateMachine())); + return; + + } + getStateMachine().getStatus().setSearchForPlaceholderSignature(false); + + } else { // if the user chooses to use the signature placeholder // - fill the position information so that we skip to @@ -138,7 +178,8 @@ public class OpenState extends State { status.setSignaturePosition(position); getStateMachine().getStatus().setSearchForPlaceholderSignature(true); - } else { + } + } else { getStateMachine().getStatus().setSearchForPlaceholderSignature(false); } } diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java index 4a914046..f9827ba4 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java @@ -139,8 +139,10 @@ public class PrepareSigningState extends State { .getDocument())); this.state.signatureParameter.setSignatureDevice(status .getBKU()); - this.state.signatureParameter.setSignaturePosition(status + if (status.getSignaturePosition() != null ) { + this.state.signatureParameter.setSignaturePosition(status .getSignaturePosition()); + } if (configuration.getDefaultEmblem() != null && !configuration.getDefaultEmblem().isEmpty()) { diff --git a/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java b/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java index e516d63f..e04022e8 100644 --- a/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java +++ b/pdf-over-signer/pdf-over-sigpdfas4/src/main/java/at/asit/pdfover/signer/pdfas/PdfAs4Signer.java @@ -61,7 +61,7 @@ public class PdfAs4Signer implements Signer { String sigProfile = sign_para.getPdfAsSignatureProfileId(); String sigEmblem = (sign_para.getEmblem() == null ? null : sign_para.getEmblem().getFileName()); String sigNote = sign_para.getProperty("SIG_NOTE"); - String sigPos = sign_para.getPdfAsSignaturePosition(); + //String sigPos = sign_para.getPdfAsSignaturePosition(); //TODO just for testing PdfAs pdfas = PdfAs4Helper.getPdfAs(); Configuration config = pdfas.getConfiguration(); @@ -77,7 +77,7 @@ public class PdfAs4Signer implements Signer { ByteArrayOutputStream output = new ByteArrayOutputStream(); DataSource input = new ByteArrayDataSource(parameter.getInputDocument().getByteArray()); SignParameter param = PdfAsFactory.createSignParameter(config, input, output); - param.setSignaturePosition(sigPos); +// param.setSignaturePosition(sigPos); //TODO just for testing param.setSignatureProfileId(sigProfile); String id = UUID.randomUUID().toString(); param.setTransactionId(id); @@ -137,22 +137,26 @@ public class PdfAs4Signer implements Signer { // result.setSignerCertificate(..); // Set Signature position - TablePos tp = new TablePos(param.getSignaturePosition()); - SignaturePosition sp; - if (tp.isXauto() && tp.isYauto()) - sp = new SignaturePosition(); - else if (tp.isPauto()) - sp = new SignaturePosition(tp.getPosX(), tp.getPosY()); - else - sp = new SignaturePosition(tp.getPosX(), tp.getPosY(), tp.getPage()); - result.setSignaturePosition(sp); + + //TODO just for testing +// TablePos tp = new TablePos(param.getSignaturePosition()); +// SignaturePosition sp; +// if (tp.isXauto() && tp.isYauto()) +// sp = new SignaturePosition(); +// else if (tp.isPauto()) +// sp = new SignaturePosition(tp.getPosX(), tp.getPosY()); +// else +// sp = new SignaturePosition(tp.getPosX(), tp.getPosY(), tp.getPage()); +// result.setSignaturePosition(sp); // Set signed Document result.setSignedDocument(new ByteArrayDocumentSource(sstate.getOutput().toByteArray())); return result; - } catch (PdfAsException e) { - throw new SignatureException(e); - } catch (PDFASError e) { + } +// catch (PdfAsException e) { //TODO just for testing +// throw new SignatureException(e); +// } + catch (PDFASError e) { throw new SignatureException(e); } } |