From: Jeremias Maerki Date: Wed, 25 Oct 2006 16:05:10 +0000 (+0000) Subject: Style only. X-Git-Tag: fop-0_93~41 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e31971dcdb4ab8208fc543909e3238d7e00f3347;p=xmlgraphics-fop.git Style only. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@467698 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/test/java/org/apache/fop/render/pdf/BasePDFTestCase.java b/test/java/org/apache/fop/render/pdf/BasePDFTestCase.java index 11ee3e75f..54e2ba9d8 100644 --- a/test/java/org/apache/fop/render/pdf/BasePDFTestCase.java +++ b/test/java/org/apache/fop/render/pdf/BasePDFTestCase.java @@ -15,6 +15,8 @@ * limitations under the License. */ +/* $Id$ */ + package org.apache.fop.render.pdf; import java.io.File; @@ -34,51 +36,60 @@ import org.apache.fop.apps.MimeConstants; import junit.framework.TestCase; -/** Base class for automated tests that create PDF files - * $Id$ +/** + * Base class for automated tests that create PDF files */ - public class BasePDFTestCase extends TestCase { - protected final FopFactory fopFactory = FopFactory.newInstance(); - protected final TransformerFactory tFactory = TransformerFactory.newInstance(); - protected BasePDFTestCase(String name) { - super(name); - - final File uc = getUserConfigFile(); - - try { - fopFactory.setUserConfig(uc); - } catch (Exception e) { - throw new RuntimeException("fopFactory.setUserConfig (" + uc.getAbsolutePath() + ") failed: " + e.getMessage()); + /** the FopFactory */ + protected final FopFactory fopFactory = FopFactory.newInstance(); + + /** the JAXP TransformerFactory */ + protected final TransformerFactory tFactory = TransformerFactory.newInstance(); + + /** + * Main constructor + * @param name the name of the test case + */ + protected BasePDFTestCase(String name) { + super(name); + + final File uc = getUserConfigFile(); + + try { + fopFactory.setUserConfig(uc); + } catch (Exception e) { + throw new RuntimeException("fopFactory.setUserConfig (" + + uc.getAbsolutePath() + ") failed: " + e.getMessage()); + } + } + + /** + * Convert a test FO file to PDF + * @param foFile the FO file + * @param ua the preconfigured user agent + * @param dumpPdfFile if true, dumps the generated PDF file to a file name (foFile).pdf + * @return the generated PDF data + * @throws Exception if the conversion fails + */ + protected byte[] convertFO(File foFile, FOUserAgent ua, boolean dumpPdfFile) + 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); + } + return result; + } + + /** get FOP config File */ + protected File getUserConfigFile() { + return new File("test/test.xconf"); } - } - - /** - * Convert a test FO file to PDF - * @param foFile the FO file - * @param ua the preconfigured user agent - * @param dumpPdfFile if true, dumps the generated PDF file to a file name (foFile).pdf - * @return the generated PDF data - * @throws Exception if the conversion fails - */ - protected byte[] convertFO(File foFile, FOUserAgent ua, boolean dumpPdfFile) 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); - } - return result; - } - - /** get FOP config File */ - protected File getUserConfigFile() { - return new File("test/test.xconf"); - } } diff --git a/test/java/org/apache/fop/render/pdf/PDFAConformanceTestCase.java b/test/java/org/apache/fop/render/pdf/PDFAConformanceTestCase.java index 1e5b70056..54ea5b571 100644 --- a/test/java/org/apache/fop/render/pdf/PDFAConformanceTestCase.java +++ b/test/java/org/apache/fop/render/pdf/PDFAConformanceTestCase.java @@ -44,9 +44,9 @@ public class PDFAConformanceTestCase extends BasePDFTestCase { * @return an initialized FOUserAgent * */ protected FOUserAgent getUserAgent() { - final FOUserAgent a = fopFactory.newFOUserAgent(); - a.getRendererOptions().put("pdf-a-mode", "PDF/A-1b"); - return a; + final FOUserAgent a = fopFactory.newFOUserAgent(); + a.getRendererOptions().put("pdf-a-mode", "PDF/A-1b"); + return a; } /**