00001 package net.threebit.utils.sosc;
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00051
00052
00053
00054
00055
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
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
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
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
00120
00121
00122 Driver driver = new Driver();
00123 driver.setOutputStream( out );
00124 driver.setRenderer(renderMode);
00125
00126
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 }