From 263b70846b06d2a119d5d253633e5678a9f908bb Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Mon, 18 Feb 2008 09:41:03 +0000 Subject: [PATCH] Extract original exception in BasePDFTestCase.java. They are normally embedded in a TransformerException and sometimes additionally in a SAXException (depending on the JAXP implementation). Restore validation for Base14 font check when PDF/A is active. Got lost when I refactored to generic structures in the PDF library. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@628668 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/fop/pdf/PDFFont.java | 9 +++++ .../fop/render/pdf/BasePDFTestCase.java | 34 +++++++++++++++---- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/src/java/org/apache/fop/pdf/PDFFont.java b/src/java/org/apache/fop/pdf/PDFFont.java index 497565e9c..14f1a657c 100644 --- a/src/java/org/apache/fop/pdf/PDFFont.java +++ b/src/java/org/apache/fop/pdf/PDFFont.java @@ -19,6 +19,9 @@ package org.apache.fop.pdf; +import java.io.IOException; +import java.io.OutputStream; + import org.apache.fop.fonts.FontType; /** @@ -163,5 +166,11 @@ public class PDFFont extends PDFDictionary { } } } + + /** {@inheritDoc} */ + protected int output(OutputStream stream) throws IOException { + validate(); + return super.output(stream); + } } diff --git a/test/java/org/apache/fop/render/pdf/BasePDFTestCase.java b/test/java/org/apache/fop/render/pdf/BasePDFTestCase.java index 3b4e03118..7c66a0ceb 100644 --- a/test/java/org/apache/fop/render/pdf/BasePDFTestCase.java +++ b/test/java/org/apache/fop/render/pdf/BasePDFTestCase.java @@ -23,12 +23,16 @@ import java.io.File; import javax.xml.transform.Source; import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.sax.SAXResult; import javax.xml.transform.stream.StreamSource; +import org.xml.sax.SAXException; + import org.apache.commons.io.FileUtils; import org.apache.commons.io.output.ByteArrayOutputStream; + import org.apache.fop.AbstractFOPTestCase; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.apps.Fop; @@ -78,21 +82,37 @@ public class BasePDFTestCase extends AbstractFOPTestCase { * @throws Exception if the conversion fails */ protected byte[] convertFO(File foFile, FOUserAgent ua, boolean dumpPdfFile) - throws Exception { + throws Exception { ByteArrayOutputStream baout = new ByteArrayOutputStream(); Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, ua, baout); Transformer transformer = tFactory.newTransformer(); Source src = new StreamSource(foFile); SAXResult res = new SAXResult(fop.getDefaultHandler()); - transformer.transform(src, res); - final byte[] result = baout.toByteArray(); - if (dumpPdfFile) { - final File outFile = new File(foFile.getParentFile(), foFile.getName() + ".pdf"); - FileUtils.writeByteArrayToFile(outFile, result); + try { + transformer.transform(src, res); + final byte[] result = baout.toByteArray(); + if (dumpPdfFile) { + final File outFile = new File(foFile.getParentFile(), foFile.getName() + ".pdf"); + FileUtils.writeByteArrayToFile(outFile, result); + } + return result; + } catch (TransformerException e) { + throw extractOriginalException(e); } - return result; } + private static Exception extractOriginalException(Exception e) { + if (e.getCause() != null) { + return extractOriginalException((Exception)e.getCause()); + } else if (e instanceof SAXException) { + SAXException se = (SAXException)e; + if (se.getException() != null) { + return extractOriginalException(se.getException()); + } + } + return e; + } + /** * get FOP config File * @return user config file to be used for testing -- 2.39.5