From 263b70846b06d2a119d5d253633e5678a9f908bb Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Mon, 18 Feb 2008 09:41:03 +0000 Subject: 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 --- .../org/apache/fop/render/pdf/BasePDFTestCase.java | 34 +++++++++++++++++----- 1 file changed, 27 insertions(+), 7 deletions(-) (limited to 'test/java/org/apache') 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 -- cgit v1.2.3