Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

FopTool.java

Go to the documentation of this file.
00001 package net.threebit.utils.sosc;
00002 
00003 /*
00004         Copyright 2003 Shawn Deleurme
00005         Copyright 2003 Kevin O'Donnell
00006 
00007         This program is free software; you can redistribute it and/or modify
00008         it under the terms of the GNU General Public License as published by
00009         the Free Software Foundation; either version 2 of the License, or
00010         (at your option) any later version.
00011 
00012         This program is distributed in the hope that it will be useful,
00013         but WITHOUT ANY WARRANTY; without even the implied warranty of
00014         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015         GNU General Public License for more details.
00016 
00017         You should have received a copy of the GNU General Public License
00018         along with this program; if not, write to the Free Software
00019         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 */
00021 
00022 import java.io.*;
00023 import java.sql.*;
00024 import java.util.*;
00025 import javax.xml.transform.stream.*;
00026 import javax.xml.transform.*;
00027 import java.text.*;
00028 import org.apache.fop.apps.Driver;
00029 import org.apache.fop.apps.Version;
00030 import org.apache.fop.apps.XSLTInputHandler;
00031 import org.apache.fop.messaging.MessageHandler;
00032 
00037 public class FopTool {
00038 
00040         public static final int RENDER_PDF = Driver.RENDER_PDF;
00042         public static final int RENDER_PS = Driver.RENDER_PS;
00043 
00047         public static void toPDF (String xmlData, String xslPath, OutputStream out) throws Exception {
00048                 render(xmlData, xslPath, out, RENDER_PDF);
00049                 /*
00050                 if (destination == null) { throw new Exception("destination is null."); }
00051                 if (xmlData == null) { throw new Exception("xmlData is null"); }
00052                 if (xslPath == null) { throw new Exception("xslPath is null"); }
00053                 Source xmlSource = new StreamSource(new StringReader(xmlData));
00054                 Source xslSource = new StreamSource( new File(xslPath));
00055                 toPDF(xmlSource,xslSource,destination);
00056                 */
00057         }
00058 
00062         public static void toPDF (Source xmlSource, Source xslSource, OutputStream out) throws Exception {
00063                 render(xmlSource, xslSource, out, RENDER_PDF);
00064                 /*
00065                 // Assert
00066                 if (destination == null) { throw new Exception("destination is null."); }
00067                 if (xmlSource == null) { throw new Exception("xmlSource is null"); }
00068                 if (xslSource == null) { throw new Exception("xslSource is null"); }
00069 
00070                 // Render with FOP
00071                 Driver driver = new Driver();
00072                 driver.setOutputStream( destination );
00073                 driver.setRenderer(Driver.RENDER_PDF);
00074         
00075                 // Do the transform and PDF rendering directly to the destination output stream.
00076                 Result result = new StreamResult( destination );
00077                 TransformerFactory tf = TransformerFactory.newInstance();
00078                 Transformer transformer = tf.newTransformer( xslSource );
00079                 transformer.transform(xmlSource, new javax.xml.transform.sax.SAXResult(driver.getContentHandler()));
00080                 */
00081         }
00082 
00094         public static void render (String xmlData, String xslPath, OutputStream out, int renderMode) throws Exception {
00095                 if (xmlData == null) { throw new Exception("xmlData is null"); }
00096                 if (xslPath == null) { throw new Exception("xslPath is null"); }
00097                 Source xmlSource = new StreamSource(new StringReader(xmlData));
00098                 Source xslSource = new StreamSource( new File(xslPath));
00099                 render(xmlSource, xslSource, out, renderMode);
00100         }
00101 
00113         public static void render (Source xmlSource, Source xslSource, OutputStream out, int renderMode) throws Exception {
00114 
00115                 // Assert
00116                 if (xmlSource == null) { throw new Exception("xmlSource is null"); }
00117                 if (xslSource == null) { throw new Exception("xslSource is null"); }
00118                 if (out == null) { throw new Exception("out is null."); }
00119                 // renderMode is not checked
00120 
00121                 // Render with FOP
00122                 Driver driver = new Driver();
00123                 driver.setOutputStream( out );
00124                 driver.setRenderer(renderMode);
00125         
00126                 // Do the transform and PDF rendering directly to the destination output stream.
00127                 Result result = new StreamResult( out );
00128                 TransformerFactory tf = TransformerFactory.newInstance();
00129                 Transformer transformer = tf.newTransformer( xslSource );
00130                 transformer.transform(xmlSource, new javax.xml.transform.sax.SAXResult(driver.getContentHandler()));
00131 
00132         }
00133 
00134 }

Generated on Mon Jul 14 17:19:20 2003 for SOSC by doxygen1.2.15