]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Extract original exception in BasePDFTestCase.java. They are normally embedded in...
authorJeremias Maerki <jeremias@apache.org>
Mon, 18 Feb 2008 09:41:03 +0000 (09:41 +0000)
committerJeremias Maerki <jeremias@apache.org>
Mon, 18 Feb 2008 09:41:03 +0000 (09:41 +0000)
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
test/java/org/apache/fop/render/pdf/BasePDFTestCase.java

index 497565e9c095c12976d26a01880bb1196d848402..14f1a657c902a1be034f81404df058c81dc26b20 100644 (file)
@@ -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);
+    }
     
 }
index 3b4e0311889bfde4cb68402abe0584a90873edba..7c66a0cebbf2caf145c393253e8c5cd5f58c340b 100644 (file)
@@ -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