From 423de7ff32cbf6292a1362a2884dbf821abdf525 Mon Sep 17 00:00:00 2001 From: pdanner Date: Mon, 7 Mar 2011 15:53:18 +0000 Subject: Added errorhandling for replacePlaceholder git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@776 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c --- .../wag/egov/egiz/pdf/BinarySignature.java | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src/main') diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java index bc399f0..ae1ce12 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/BinarySignature.java @@ -966,15 +966,30 @@ public abstract class BinarySignature } } - private static void replacePlaceholder(PdfStamper stamper, int pageNr, String placeholderName) throws BadElementException, MalformedURLException, IOException, BadPdfFormatException { + private static void replacePlaceholder(PdfStamper stamper, int pageNr, String placeholderName) throws BadElementException, MalformedURLException, IOException, BadPdfFormatException, PresentableException { Image img = Image.getInstance(SignaturePlaceholderData.class.getResource("empty.jpg")); PdfImage pImg = new PdfImage(img, "Imwurscht", null); PdfStamperImp stamperImp = (PdfStamperImp)stamper.getWriter(); PdfIndirectObject ind = stamperImp.addToBody(pImg); PdfDictionary resources = stamper.getReader().getPageN(pageNr).getAsDict(PdfName.RESOURCES); - resources.getAsDict(PdfName.XOBJECT).put(new PdfName(placeholderName), ind.getIndirectReference()); - stamperImp.markUsed(resources); + if (ind != null && resources != null) + { + PdfDictionary xobjDict = resources.getAsDict(PdfName.XOBJECT); + if (xobjDict != null) + { + xobjDict.put(new PdfName(placeholderName), ind.getIndirectReference()); + stamperImp.markUsed(resources); + } + else + { + throw new PresentableException(ErrorCode.CANNOT_WRITE_PDF, new NullPointerException("Image dictionary not found in document structure!")); + } + } + else + { + throw new PresentableException(ErrorCode.CANNOT_WRITE_PDF, new NullPointerException("Resource dictionary not found in document structure!")); + } } -- cgit v1.2.3