1616import javax .xml .transform .Source ;
1717import javax .xml .transform .Transformer ;
1818import javax .xml .transform .TransformerFactory ;
19+ import javax .xml .transform .dom .DOMResult ;
20+ import javax .xml .transform .dom .DOMSource ;
1921import javax .xml .transform .sax .SAXResult ;
20- import javax .xml .transform .stream .StreamResult ;
2122import javax .xml .transform .stream .StreamSource ;
2223
2324import org .apache .fop .apps .Fop ;
2728import org .dbdoclet .trafo .html .docbook .DocBookTransformer ;
2829import org .dbdoclet .trafo .script .Script ;
2930import org .junit .Test ;
31+ import org .w3c .dom .Document ;
3032
3133public class ApacheFOPHeroldTest {
3234 private String [] inputUrls = {// @formatter:off
@@ -49,7 +51,6 @@ public class ApacheFOPHeroldTest {
4951
5052 private String style_file = "src/test/resources/docbook-xsl/fo/docbook.xsl" ;
5153 private String output_file = "src/test/resources/final_output.pdf" ;
52- private String fo_file = "src/test/resources/fofile.fo" ;
5354 private String xmlInput = "src/test/resources/input.xml" ;
5455 private String xmlOutput = "src/test/resources/output.xml" ;
5556
@@ -61,8 +62,8 @@ public void whenTransformFromHeroldToPDF_thenCorrect() throws Exception {
6162 fromHTMLTOXMLUsingHerold (inputUrls [i ], true );
6263 }
6364 fixXML (xmlInput , xmlOutput );
64- fromXMLFileToFO ();
65- fromFODocumentToPDF (output_file );
65+ final Document fo = fromXMLFileToFO ();
66+ fromFODocumentToPDF (fo , output_file );
6667 }
6768
6869 // UTIL
@@ -78,22 +79,22 @@ private void fromHTMLTOXMLUsingHerold(final String input, boolean append) throws
7879 transformer .convert (getInputStream (input ), new FileOutputStream (xmlInput ,append ));
7980 }
8081
81- private void fromXMLFileToFO () throws Exception {
82+ private Document fromXMLFileToFO () throws Exception {
8283 final Source source = new StreamSource (new FileInputStream (xmlOutput ));
83- final StreamResult result = new StreamResult ( new FileOutputStream ( fo_file ) );
84+ final DOMResult result = new DOMResult ( );
8485 final Transformer transformer = createTransformer (style_file );
8586 transformer .transform (source , result );
86- // return (Document) result.getNode();
87+ return (Document ) result .getNode ();
8788 }
8889
89- private void fromFODocumentToPDF (final String outputFile ) throws Exception {
90+ private void fromFODocumentToPDF (Document fo , final String outputFile ) throws Exception {
9091 final FopFactory fopFactory = FopFactory .newInstance ();
9192 final OutputStream outStream = new BufferedOutputStream (new FileOutputStream (new File (outputFile )));
9293
9394 final Fop fop = fopFactory .newFop (MimeConstants .MIME_PDF , outStream );
9495 final TransformerFactory factory = TransformerFactory .newInstance ();
9596 final Transformer transformer = factory .newTransformer ();
96- final StreamSource src = new StreamSource ( new File ( fo_file ) );
97+ final DOMSource src = new DOMSource ( fo );
9798 final Result res = new SAXResult (fop .getDefaultHandler ());
9899 transformer .transform (src , res );
99100
0 commit comments