1 17 18 19 20 package org.apache.fop; 21 22 import java.io.File ; 23 24 import javax.xml.transform.Result ; 25 import javax.xml.transform.Source ; 26 import javax.xml.transform.Transformer ; 27 import javax.xml.transform.TransformerFactory ; 28 import javax.xml.transform.sax.SAXResult ; 29 import javax.xml.transform.stream.StreamSource ; 30 31 import org.apache.commons.io.output.ByteArrayOutputStream; 32 import org.apache.fop.apps.FOUserAgent; 33 import org.apache.fop.apps.Fop; 34 import org.apache.fop.apps.FopFactory; 35 import org.apache.fop.apps.MimeConstants; 36 import org.apache.fop.cli.InputHandler; 37 38 42 public class BasicDriverTestCase extends AbstractFOPTestCase { 43 44 private FopFactory fopFactory = FopFactory.newInstance(); 45 46 49 public BasicDriverTestCase(String name) { 50 super(name); 51 } 52 53 57 public void testFO2PDFWithJAXP() throws Exception { 58 FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); 59 File foFile = new File (getBaseDir(), "test/xml/bugtests/block.fo"); 60 ByteArrayOutputStream baout = new ByteArrayOutputStream(); 61 Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, baout); 62 63 TransformerFactory factory = TransformerFactory.newInstance(); 64 Transformer transformer = factory.newTransformer(); Source src = new StreamSource (foFile); 66 Result res = new SAXResult (fop.getDefaultHandler()); 67 transformer.transform(src, res); 68 69 assertTrue("Generated PDF has zero length", baout.size() > 0); 70 } 71 72 76 public void testFO2PSWithJAXP() throws Exception { 77 FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); 78 File foFile = new File (getBaseDir(), "test/xml/bugtests/block.fo"); 79 ByteArrayOutputStream baout = new ByteArrayOutputStream(); 80 Fop fop = fopFactory.newFop(MimeConstants.MIME_POSTSCRIPT, foUserAgent, baout); 81 82 TransformerFactory factory = TransformerFactory.newInstance(); 83 Transformer transformer = factory.newTransformer(); Source src = new StreamSource (foFile); 85 Result res = new SAXResult (fop.getDefaultHandler()); 86 transformer.transform(src, res); 87 88 assertTrue("Generated PostScript has zero length", baout.size() > 0); 89 } 90 91 95 public void testFO2RTFWithJAXP() throws Exception { 96 FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); 97 File foFile = new File (getBaseDir(), "test/xml/bugtests/block.fo"); 98 ByteArrayOutputStream baout = new ByteArrayOutputStream(); 99 Fop fop = fopFactory.newFop(MimeConstants.MIME_RTF, foUserAgent, baout); 100 101 TransformerFactory factory = TransformerFactory.newInstance(); 102 Transformer transformer = factory.newTransformer(); Source src = new StreamSource (foFile); 104 Result res = new SAXResult (fop.getDefaultHandler()); 105 transformer.transform(src, res); 106 107 assertTrue("Generated RTF has zero length", baout.size() > 0); 108 } 109 110 114 public void testFO2PDFWithXSLTInputHandler() throws Exception { 115 FOUserAgent foUserAgent = fopFactory.newFOUserAgent(); 116 File xmlFile = new File (getBaseDir(), "test/xml/1.xml"); 117 File xsltFile = new File (getBaseDir(), "test/xsl/doc.xsl"); 118 ByteArrayOutputStream baout = new ByteArrayOutputStream(); 119 120 InputHandler handler = new InputHandler(xmlFile, xsltFile, null); 121 handler.renderTo(foUserAgent, MimeConstants.MIME_PDF, baout); 122 123 assertTrue("Generated PDF has zero length", baout.size() > 0); 124 } 125 126 } 127 | Popular Tags |