/* * Copyright 1999-2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* $Id$ */ package org.apache.fop.apps; import org.apache.fop.fo.ElementMapping; import org.apache.fop.render.Renderer; // Avalon import org.apache.avalon.framework.logger.ConsoleLogger; import org.apache.avalon.framework.logger.Logger; // DOM import org.w3c.dom.Document; // SAX import org.xml.sax.ContentHandler; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.XMLReader; // Java import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; import java.io.IOException; import java.io.OutputStream; import java.util.Enumeration; import java.util.HashMap; import java.util.Vector; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import javax.xml.transform.Result; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.sax.SAXResult; /** * Primary class that drives overall FOP process. *
This class is deprecated and included only for * some backwards compatibility with older Fop releases.
** The simplest way to use this is to instantiate it with the * InputSource and OutputStream, then set the renderer desired, and * calling run(); *
* Here is an example use of Driver which outputs PDF: * *
* Driver driver = new Driver(new InputSource (args[0]), * new FileOutputStream(args[1])); * driver.setRenderer(RENDER_PDF); * driver.run(); ** If neccessary, calling classes can call into the lower level * methods to setup and render. Methods can be called to set the * Renderer to use, the (possibly multiple) ElementMapping(s) to use * and the OutputStream to use to output the results of the rendering * (where applicable). In the case of the Renderer and * ElementMapping(s), the Driver may be supplied either with the * object itself, or the name of the class, in which case Driver will * instantiate the class itself. The advantage of the latter is it * enables runtime determination of Renderer and ElementMapping(s). *
* Once the Driver is set up, the render method is called. Depending * on whether DOM or SAX is being used, the invocation of the method * is either render(Document) or render(Parser, InputSource) * respectively. *
* A third possibility is to call getContentHandler() and firing * the SAX events yourself. *
* Here is an example use of Driver which outputs to AWT: * *
* Driver driver = new Driver(); * driver.setRenderer(new org.apache.fop.render.awt.AWTRenderer(translator)); * driver.render(parser, fileInputSource(args[0])); **/ public class Driver { /** * Render to PDF. OutputStream must be set */ public static final int RENDER_PDF = 1; /** * Render to a GUI window. No OutputStream neccessary */ public static final int RENDER_AWT = 2; /** * Render to MIF. OutputStream must be set */ public static final int RENDER_MIF = 3; /** * Render to XML. OutputStream must be set */ public static final int RENDER_XML = 4; /** * Render to PRINT. No OutputStream neccessary */ public static final int RENDER_PRINT = 5; /** * Render to PCL. OutputStream must be set */ public static final int RENDER_PCL = 6; /** * Render to Postscript. OutputStream must be set */ public static final int RENDER_PS = 7; /** * Render to Text. OutputStream must be set */ public static final int RENDER_TXT = 8; /** * Render to SVG. OutputStream must be set */ public static final int RENDER_SVG = 9; /** * the FOP object we are encapsulating */ private Fop _fop; /** * the source of the FO file */ private InputSource _source; /** * the stream to use to output the results of the renderer */ private OutputStream _stream; /** * The XML parser to use when building the FO tree */ private XMLReader _reader; /** * If true, full error stacks are reported */ private boolean _errorDump = false; /** * the system resources that FOP will use */ private Logger log; /** * @deprecated * @return the class name of the SAX parser */ public static final String getParserClassName() { try { return javax.xml.parsers.SAXParserFactory.newInstance().newSAXParser().getXMLReader().getClass().getName(); } catch (javax.xml.parsers.ParserConfigurationException e) { return null; } catch (org.xml.sax.SAXException e) { return null; } } /** * @deprecated * create a new Driver */ public Driver() { _stream = null; setupDefaultMappings(); } /** * @deprecated * create a new Driver * @param the input source, @see #setInputSource(InputSource) * @param the output stream, @see #setOutputStream(OutputStream) */ public Driver(InputSource source, OutputStream stream) { this(); _source = source; _stream = stream; } /** * @deprecated * Set the logger * @param the logger */ public void setLogger(Logger logger) { log = logger; } private Logger getLogger() { if(log == null) { log = new ConsoleLogger(ConsoleLogger.LEVEL_INFO); log.error("Logger not set"); } return log; } /** * @deprecated * Resets the Driver so it can be reused. Property and element * mappings are reset to defaults. * The output stream is cleared. The renderer is cleared. */ public synchronized void reset() { _source = null; _stream = null; _reader = null; } /** * @deprecated * Returns the results of the last rendering process. Information includes * the total number of pages generated and the number of pages per * page-sequence. */ public FormattingResults getResults() { try { return _fop.getResults(); } catch (NullPointerException e) { return null; } } /** * @deprecated always returns false * @return always false */ public boolean hasData() { return (false); } /** * @deprecated * Set the error dump option * @param dump if true, full stacks will be reported to the error log */ public void setErrorDump(boolean dump) { _errorDump = dump; } /** * @deprecated * Set the OutputStream to use to output the result of the Renderer * (if applicable) * @param stream the stream to output the result of rendering to * */ public void setOutputStream(OutputStream stream) { _stream = stream; } /** * @deprecated DocumentInputSource is not supported * Set the source for the FO document. This can be a normal SAX * InputSource, or an DocumentInputSource containing a DOM document. */ public void setInputSource(InputSource source) { _source = source; } /** * @deprecated * Sets the reader used when reading in the source. If not set, * this defaults to a basic SAX parser. */ public void setXMLReader(XMLReader reader) { _reader = reader; } /** * @deprecated not supported any more * Sets all the element and property list mappings to their default values. */ public void setupDefaultMappings() { } /** * @deprecated * Set the rendering type to use. Must be one of *