From 5ffe3db4b8a1171ae9620afe1d64395d6b71109b Mon Sep 17 00:00:00 2001 From: tkellner Date: Wed, 10 Apr 2013 19:39:42 +0000 Subject: Move PDFFile creation to PositioningState This ensures PDF encryption is also checked if autopositioning is used git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@438 174cde9d-5d70-4d2a-aa98-46368bc2aaf7 --- .../gui/composites/PositioningComposite.java | 37 +++------------------- 1 file changed, 4 insertions(+), 33 deletions(-) (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java') diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java index 8eb31752..327c8386 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/PositioningComposite.java @@ -22,11 +22,6 @@ import java.awt.Frame; import java.awt.Image; import java.awt.event.MouseWheelEvent; import java.awt.event.MouseWheelListener; -import java.io.File; -import java.io.IOException; -import java.io.RandomAccessFile; -import java.nio.ByteBuffer; -import java.nio.channels.FileChannel; import org.eclipse.swt.SWT; import org.eclipse.swt.awt.SWT_AWT; @@ -52,7 +47,6 @@ import at.asit.pdfover.gui.workflow.states.State; import at.asit.pdfover.signator.SignaturePosition; import com.sun.pdfview.PDFFile; -import com.sun.pdfview.decrypt.PDFAuthenticationFailureException; /** * Composite which allows to position the signature on a preview of the document @@ -66,8 +60,6 @@ public class PositioningComposite extends StateComposite { private SignaturePanel viewer = null; - private PDFFile pdf = null; - private Frame frame = null; private Composite mainArea = null; @@ -167,39 +159,18 @@ public class PositioningComposite extends StateComposite { * * @param document * document to display - * @throws IOException - * I/O Error */ - public void displayDocument(File document) throws IOException { - RandomAccessFile rafile = new RandomAccessFile(document, "r"); //$NON-NLS-1$ - FileChannel chan = rafile.getChannel(); - ByteBuffer buf = chan - .map(FileChannel.MapMode.READ_ONLY, 0, chan.size()); - chan.close(); - rafile.close(); - try - { - this.pdf = new PDFFile(buf); - } - catch (PDFAuthenticationFailureException e) { - throw new IOException(Messages.getString("error.PDFPwdProtected"), e); //$NON-NLS-1$ - } - catch (IOException e) { - throw new IOException(Messages.getString("error.MayNotBeAPDF"), e); //$NON-NLS-1$ - } - if (this.pdf.getDefaultDecrypter().isEncryptionPresent()) - throw new IOException(Messages.getString("error.PDFProtected")); //$NON-NLS-1$ - + public void displayDocument(PDFFile document) { if (this.viewer == null) { - this.viewer = new SignaturePanel(this.pdf); + this.viewer = new SignaturePanel(document); this.frame.add(this.viewer, BorderLayout.CENTER); this.viewer.setSignaturePlaceholderBorderColor(new Color( Constants.MAINBAR_ACTIVE_BACK_DARK.getRed(), Constants.MAINBAR_ACTIVE_BACK_DARK.getGreen(), Constants.MAINBAR_ACTIVE_BACK_DARK.getBlue())); } else - this.viewer.setDocument(this.pdf); - this.numPages = this.pdf.getNumPages(); + this.viewer.setDocument(document); + this.numPages = document.getNumPages(); this.scrollbar.setValues(1, 1, this.numPages + 1, 1, 1, 1); showPage(this.numPages); } -- cgit v1.2.3