/*
* $Id$
- * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
+ * Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
import org.apache.fop.viewer.Translator;
//Java
-import javax.swing.UIManager;
-import java.awt.*;
+import java.awt.Dimension;
+import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Locale;
private Driver driver;
private XMLReader parser;
- public AWTStarter(CommandLineOptions commandLineOptions) throws FOPException {
+ /**
+ * Construct an AWTStarter
+ * @param commandLineOptions the parsed command line options
+ * @throws FOPException if anything goes wrong during initialization.
+ */
+ public AWTStarter(CommandLineOptions commandLineOptions)
+ throws FOPException {
super(commandLineOptions);
init();
}
private void init() throws FOPException {
//Creates Translator according to the language
String language = commandLineOptions.getLanguage();
- if (language == null)
+ if (language == null) {
translator = new Translator(Locale.getDefault());
- else
+ } else {
translator = new Translator(new Locale(language, ""));
+ }
AWTRenderer renderer = new AWTRenderer(translator);
frame = createPreviewDialog(renderer, translator);
renderer.setComponent(frame);
/**
* Runs formatting.
+ * @throws FOPException FIXME should not happen.
*/
public void run() throws FOPException {
driver.reset();
/*
* $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
package org.apache.fop.apps;
// java
-import java.util.Vector;
import java.io.File;
import java.io.FileNotFoundException;
-// FOP
-import org.apache.fop.apps.FOPException;
-
// Avalon
import org.apache.avalon.framework.logger.ConsoleLogger;
import org.apache.avalon.framework.logger.Logger;
-import java.io.*;
-
/**
* Options parses the commandline arguments
*/
private static final int RTF_OUTPUT = 10;
/* show configuration information */
- Boolean dumpConfiguration = Boolean.FALSE;
+ private Boolean dumpConfiguration = Boolean.FALSE;
/* suppress any progress information */
- Boolean quiet = Boolean.FALSE;
+ private Boolean quiet = Boolean.FALSE;
/* for area tree XML output, only down to block area level */
- Boolean suppressLowLevelAreas = Boolean.FALSE;
+ private Boolean suppressLowLevelAreas = Boolean.FALSE;
/* user configuration file */
- File userConfigFile = null;
+ private File userConfigFile = null;
/* input fo file */
- File fofile = null;
+ private File fofile = null;
/* xsltfile (xslt transformation as input) */
- File xsltfile = null;
+ private File xsltfile = null;
/* xml file (xslt transformation as input) */
- File xmlfile = null;
+ private File xmlfile = null;
/* output file */
- File outfile = null;
+ private File outfile = null;
/* input mode */
- int inputmode = NOT_SET;
+ private int inputmode = NOT_SET;
/* output mode */
- int outputmode = NOT_SET;
+ private int outputmode = NOT_SET;
/* language for user information */
- String language = null;
+ private String language = null;
private java.util.HashMap rendererOptions;
private Logger log;
+ /**
+ * Construct a command line option object from command line arguments
+ * @param args command line parameters
+ * @throws FOPException for general errors
+ * @throws FileNotFoundException if an input file wasn't found.
+ */
public CommandLineOptions(String[] args)
throws FOPException, FileNotFoundException {
printUsage();
throw e;
}
-
}
+ /**
+ * Get the logger.
+ * @return the logger
+ */
public Logger getLogger() {
return log;
}
/**
* parses the commandline arguments
- * @return true if parse was successful and procesing can continue, false if processing should stop
+ * @return true if parse was successful and processing can continue, false if processing should stop
* @exception FOPException if there was an error in the format of the options
*/
private boolean parseOptions(String args[]) throws FOPException {
} // end checkSettings
/**
- * returns the chosen renderer, throws FOPException
+ * @return the type chosen renderer
+ * @throws FOPException for invalid output modes
*/
public int getRenderer() throws FOPException {
switch (outputmode) {
}
/**
- *
+ * Get the input handler.
+ * @return the input handler
*/
public InputHandler getInputHandler() {
switch (inputmode) {
}
}
+ /**
+ * Get the renderer specific options.
+ * @return hash map with option/value pairs.
+ */
public java.util.HashMap getRendererOptions() {
return rendererOptions;
}
+ /**
+ * Get the starter for the process.
+ * @return the starter.
+ */
public Starter getStarter() throws FOPException {
Starter starter = null;
switch (outputmode) {
case AWT_OUTPUT:
try {
- starter = ((Starter)Class.forName("org.apache.fop.apps.AWTStarter").getConstructor(new Class[] {
- CommandLineOptions.class
- }).newInstance(new Object[] {
- this
- }));
+ starter = new AWTStarter(this);
+ } catch (FOPException e) {
+ throw e;
} catch (Exception e) {
- if (e instanceof FOPException) {
- throw (FOPException)e;
- }
throw new FOPException("AWTStarter could not be loaded.", e);
}
- break;
+ break;
case PRINT_OUTPUT:
try {
- starter = ((Starter)Class.forName("org.apache.fop.apps.PrintStarter").getConstructor(new Class[] {
- CommandLineOptions.class
- }).newInstance(new Object[] {
- this
- }));
+ starter = new PrintStarter(this);
+ } catch (FOPException e) {
+ throw e;
} catch (Exception e) {
- if (e instanceof FOPException) {
- throw (FOPException)e;
- }
- throw new FOPException("PrintStarter could not be loaded.",
- e);
+ throw new FOPException("PrintStarter could not be loaded.", e);
}
- break;
+ break;
default:
starter = new CommandLineStarter(this);
}
}
/**
- * return either the fofile or the xmlfile
+ * @return either the fofile or the xmlfile
*/
public File getInputFile() {
switch (inputmode) {
*/
public static void printUsage() {
System.err.println("\nUSAGE\nFop [options] [-fo|-xml] infile [-xsl file] [-awt|-pdf|-mif|-rtf|-pcl|-ps|-txt|-at|-print] <outfile>\n"
- + " [OPTIONS] \n"
- + " -d debug mode \n"
- + " -x dump configuration settings \n"
- + " -q quiet mode \n"
- + " -c cfg.xml use additional configuration file cfg.xml\n"
- + " -l lang the language to use for user information \n"
- + " -s for area tree XML, down to block areas only\n\n"
- + " [INPUT] \n"
- + " infile xsl:fo input file (the same as the next) \n"
- + " -fo infile xsl:fo input file \n"
- + " -xml infile xml input file, must be used together with -xsl \n"
- + " -xsl stylesheet xslt stylesheet \n \n"
- + " [OUTPUT] \n"
- + " outfile input will be rendered as pdf file into outfile \n"
- + " -pdf outfile input will be rendered as pdf file (outfile req'd) \n"
- + " -awt input will be displayed on screen \n"
- + " -mif outfile input will be rendered as mif file (outfile req'd)\n"
- + " -rtf outfile input will be rendered as rtf file (outfile req'd)\n"
- + " -pcl outfile input will be rendered as pcl file (outfile req'd) \n"
- + " -ps outfile input will be rendered as PostScript file (outfile req'd) \n"
- + " -txt outfile input will be rendered as text file (outfile req'd) \n"
- + " -svg outfile input will be rendered as an svg slides file (outfile req'd) \n"
- + " -at outfile representation of area tree as XML (outfile req'd) \n"
- + " -print input file will be rendered and sent to the printer \n"
- + " see options with \"-print help\" \n\n"
- + " [Examples]\n" + " Fop foo.fo foo.pdf \n"
- + " Fop -fo foo.fo -pdf foo.pdf (does the same as the previous line)\n"
- + " Fop -xsl foo.xsl -xml foo.xml -pdf foo.pdf\n"
- + " Fop foo.fo -mif foo.mif\n"
- + " Fop foo.fo -rtf foo.rtf\n"
- + " Fop foo.fo -print or Fop -print foo.fo \n"
- + " Fop foo.fo -awt \n");
+ + " [OPTIONS] \n"
+ + " -d debug mode \n"
+ + " -x dump configuration settings \n"
+ + " -q quiet mode \n"
+ + " -c cfg.xml use additional configuration file cfg.xml\n"
+ + " -l lang the language to use for user information \n"
+ + " -s for area tree XML, down to block areas only\n\n"
+ + " [INPUT] \n"
+ + " infile xsl:fo input file (the same as the next) \n"
+ + " -fo infile xsl:fo input file \n"
+ + " -xml infile xml input file, must be used together with -xsl \n"
+ + " -xsl stylesheet xslt stylesheet \n \n"
+ + " [OUTPUT] \n"
+ + " outfile input will be rendered as pdf file into outfile \n"
+ + " -pdf outfile input will be rendered as pdf file (outfile req'd) \n"
+ + " -awt input will be displayed on screen \n"
+ + " -mif outfile input will be rendered as mif file (outfile req'd)\n"
+ + " -rtf outfile input will be rendered as rtf file (outfile req'd)\n"
+ + " -pcl outfile input will be rendered as pcl file (outfile req'd) \n"
+ + " -ps outfile input will be rendered as PostScript file (outfile req'd) \n"
+ + " -txt outfile input will be rendered as text file (outfile req'd) \n"
+ + " -svg outfile input will be rendered as an svg slides file (outfile req'd) \n"
+ + " -at outfile representation of area tree as XML (outfile req'd) \n"
+ + " -print input file will be rendered and sent to the printer \n"
+ + " see options with \"-print help\" \n\n"
+ + " [Examples]\n" + " Fop foo.fo foo.pdf \n"
+ + " Fop -fo foo.fo -pdf foo.pdf (does the same as the previous line)\n"
+ + " Fop -xsl foo.xsl -xml foo.xml -pdf foo.pdf\n"
+ + " Fop foo.fo -mif foo.mif\n"
+ + " Fop foo.fo -rtf foo.rtf\n"
+ + " Fop foo.fo -print or Fop -print foo.fo \n"
+ + " Fop foo.fo -awt \n");
}
-
+
/**
* shows the options for print output
*/
public void printUsagePrintOutput() {
System.err.println("USAGE: -print [-Dstart=i] [-Dend=i] [-Dcopies=i] [-Deven=true|false] "
- + " org.apache.fop.apps.Fop (..) -print \n"
- + "Example:\n"
- + "java -Dstart=1 -Dend=2 org.apache.Fop.apps.Fop infile.fo -print ");
+ + " org.apache.fop.apps.Fop (..) -print \n"
+ + "Example:\n"
+ + "java -Dstart=1 -Dend=2 org.apache.Fop.apps.Fop infile.fo -print ");
}
}
- // debug: create class and output all settings
- public static void main(String args[]) {
- /*
- * for (int i = 0; i < args.length; i++) {
- * log.debug(">"+args[i]+"<");
- * }
- */
- try {
- CommandLineOptions options = new CommandLineOptions(args);
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- // options.debug();
- }
-
}
/*
* $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
// SAX
import org.xml.sax.XMLReader;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXParseException;
// Java
-import java.io.*;
-import java.net.URL;
+import java.io.BufferedOutputStream;
+import java.io.FileOutputStream;
/**
*/
public class CommandLineStarter extends Starter {
- CommandLineOptions commandLineOptions;
+ protected CommandLineOptions commandLineOptions;
public CommandLineStarter(CommandLineOptions commandLineOptions)
throws FOPException {
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(
commandLineOptions.getOutputFile()));
driver.setOutputStream(bos);
- if(driver.getRenderer() != null) {
+ if (driver.getRenderer() != null) {
driver.getRenderer().setOptions(
commandLineOptions.getRendererOptions());
}
/*
* $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
package org.apache.fop.apps;
// FOP
-import org.apache.fop.fo.FOUserAgent;
-import org.apache.fop.fo.FOTreeBuilder;
import org.apache.fop.fo.ElementMapping;
+import org.apache.fop.fo.FOTreeBuilder;
+import org.apache.fop.fo.FOUserAgent;
import org.apache.fop.render.Renderer;
import org.apache.fop.tools.DocumentInputSource;
import org.apache.fop.tools.DocumentReader;
-import org.apache.fop.render.pdf.PDFRenderer;
// Avalon
import org.apache.avalon.framework.logger.ConsoleLogger;
-import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.logger.LogEnabled;
-import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.avalon.framework.logger.Logger;
// DOM
import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Attr;
// SAX
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
-import org.xml.sax.XMLReader;
import org.xml.sax.SAXException;
-import org.xml.sax.helpers.AttributesImpl;
+import org.xml.sax.XMLReader;
+import javax.xml.parsers.ParserConfigurationException;
// Java
-import java.io.*;
-import java.util.*;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Vector;
/**
* Primary class that drives overall FOP process.
/**
* the FO tree builder
*/
- private FOTreeBuilder _treeBuilder;
+ private FOTreeBuilder treeBuilder;
/**
* the renderer type code given by setRenderer
*/
- private int _rendererType;
+ private int rendererType;
/**
* the renderer to use to output the area tree
*/
- private Renderer _renderer;
+ private Renderer renderer;
/**
* the structure handler
/**
* the source of the FO file
*/
- private InputSource _source;
+ private InputSource source;
/**
* the stream to use to output the results of the renderer
*/
- private OutputStream _stream;
+ private OutputStream stream;
/**
* The XML parser to use when building the FO tree
*/
- private XMLReader _reader;
+ private XMLReader reader;
/**
* the system resources that FOP will use
public static final String getParserClassName() {
try {
- return javax.xml.parsers.SAXParserFactory.newInstance().newSAXParser().getXMLReader().getClass().getName();
+ return javax.xml.parsers.SAXParserFactory.newInstance()
+ .newSAXParser().getXMLReader().getClass().getName();
} catch (javax.xml.parsers.ParserConfigurationException e) {
return null;
} catch (org.xml.sax.SAXException e) {
* create a new Driver
*/
public Driver() {
- _stream = null;
+ stream = null;
}
public Driver(InputSource source, OutputStream stream) {
this();
- _source = source;
- _stream = stream;
+ this.source = source;
+ this.stream = stream;
}
public void initialize() {
- _stream = null;
- _treeBuilder = new FOTreeBuilder();
- _treeBuilder.setUserAgent(getUserAgent());
+ stream = null;
+ treeBuilder = new FOTreeBuilder();
+ treeBuilder.setUserAgent(getUserAgent());
setupDefaultMappings();
}
if (userAgent == null) {
userAgent = new FOUserAgent();
userAgent.enableLogging(getLogger());
- userAgent.setBaseURL("file:/.");
+ userAgent.setBaseURL("");
}
return userAgent;
}
* The output stream is cleared. The renderer is cleared.
*/
public synchronized void reset() {
- _source = null;
- _stream = null;
- _reader = null;
- _treeBuilder.reset();
+ source = null;
+ stream = null;
+ reader = null;
+ treeBuilder.reset();
}
public boolean hasData() {
- return (_treeBuilder.hasData());
+ return (treeBuilder.hasData());
}
/**
*
*/
public void setOutputStream(OutputStream stream) {
- _stream = stream;
+ this.stream = stream;
}
/**
* @see DocumentInputSource
*/
public void setInputSource(InputSource source) {
- _source = source;
+ this.source = source;
}
/**
* Sets the reader used when reading in the source. If not set,
* this defaults to a basic SAX parser.
+ * @param reader the reader to use.
*/
public void setXMLReader(XMLReader reader) {
- _reader = reader;
+ this.reader = reader;
}
/**
String str = (String)providers.nextElement();
try {
addElementMapping(str);
- } catch (IllegalArgumentException e) {}
+ } catch (IllegalArgumentException e) {
+ }
}
}
}
/**
- * Set the rendering type to use. Must be one of
+ * Shortcut to set the rendering type to use. Must be one of
* <ul>
- * <li>RENDER_PDF
- * <li>RENDER_AWT
- * <li>RENDER_MIF
- * <li>RENDER_XML
- * <li>RENDER_PCL
- * <li>RENDER_PS
- * <li>RENDER_TXT
- * <li>RENDER_SVG
- * <li>RENDER_RTF
+ * <li>RENDER_PDF</li>
+ * <li>RENDER_AWT</li>
+ * <li>RENDER_MIF</li>
+ * <li>RENDER_XML</li>
+ * <li>RENDER_PCL</li>
+ * <li>RENDER_PS</li>
+ * <li>RENDER_TXT</li>
+ * <li>RENDER_SVG</li>
+ * <li>RENDER_RTF</li>
* </ul>
* @param renderer the type of renderer to use
+ * @throws IllegalArgumentException if an unsupported renderer type was required.
*/
public void setRenderer(int renderer) throws IllegalArgumentException {
- _rendererType = renderer;
+ rendererType = renderer;
switch (renderer) {
case RENDER_PDF:
setRenderer("org.apache.fop.render.pdf.PDFRenderer");
*/
public void setRenderer(Renderer renderer) {
renderer.setUserAgent(getUserAgent());
- _renderer = renderer;
+ this.renderer = renderer;
}
public Renderer getRenderer() {
- return _renderer;
+ return renderer;
}
/**
- * @deprecated use renderer.setProducer(version) + setRenderer(renderer) or just setRenderer(renderer_type) which will use the default producer string.
+ * @deprecated use renderer.setProducer(version) + setRenderer(renderer) or just setRenderer(rendererType) which will use the default producer string.
* @see #setRenderer(int)
* @see #setRenderer(Renderer)
*/
public void setRenderer(String rendererClassName)
throws IllegalArgumentException {
try {
- _renderer =
+ renderer =
(Renderer)Class.forName(rendererClassName).newInstance();
- if (_renderer instanceof LogEnabled) {
- ((LogEnabled)_renderer).enableLogging(getLogger());
+ if (renderer instanceof LogEnabled) {
+ ((LogEnabled)renderer).enableLogging(getLogger());
}
- _renderer.setProducer(Version.getVersion());
- _renderer.setUserAgent(getUserAgent());
+ renderer.setProducer(Version.getVersion());
+ renderer.setUserAgent(getUserAgent());
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Could not find "
+ rendererClassName);
- }
- catch (InstantiationException e) {
+ } catch (InstantiationException e) {
throw new IllegalArgumentException("Could not instantiate "
+ rendererClassName);
- }
- catch (IllegalAccessException e) {
+ } catch (IllegalAccessException e) {
throw new IllegalArgumentException("Could not access "
+ rendererClassName);
- }
- catch (ClassCastException e) {
+ } catch (ClassCastException e) {
throw new IllegalArgumentException(rendererClassName
+ " is not a renderer");
}
* @param mapping the element mappingto add
*/
public void addElementMapping(ElementMapping mapping) {
- mapping.addToBuilder(_treeBuilder);
+ mapping.addToBuilder(treeBuilder);
}
/**
- * add the element mapping with the given class name
+ * Add the element mapping with the given class name.
+ * @param the class name representing the element mapping.
+ * @throws IllegalArgumentException if there was not such element mapping.
*/
public void addElementMapping(String mappingClassName)
- throws IllegalArgumentException {
+ throws IllegalArgumentException {
try {
ElementMapping mapping =
(ElementMapping)Class.forName(mappingClassName).newInstance();
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Could not find "
+ mappingClassName);
- }
- catch (InstantiationException e) {
+ } catch (InstantiationException e) {
throw new IllegalArgumentException("Could not instantiate "
+ mappingClassName);
- }
- catch (IllegalAccessException e) {
+ } catch (IllegalAccessException e) {
throw new IllegalArgumentException("Could not access "
+ mappingClassName);
- }
- catch (ClassCastException e) {
+ } catch (ClassCastException e) {
throw new IllegalArgumentException(mappingClassName
+ " is not an ElementMapping");
}
* Used in situations where SAX is used but not via a FOP-invoked
* SAX parser. A good example is an XSLT engine that fires SAX
* events but isn't a SAX Parser itself.
+ * @return a content handler for handling the SAX events.
*/
public ContentHandler getContentHandler() {
// TODO - do this stuff in a better way
- if(_rendererType == RENDER_MIF) {
- structHandler = new org.apache.fop.mif.MIFHandler(_stream);
- } else if(_rendererType == RENDER_RTF) {
- structHandler = new org.apache.fop.rtf.renderer.RTFHandler(_stream);
+ // PIJ: I guess the structure handler should be created by the renderer.
+ if (rendererType == RENDER_MIF) {
+ structHandler = new org.apache.fop.mif.MIFHandler(stream);
+ } else if (rendererType == RENDER_RTF) {
+ structHandler = new org.apache.fop.rtf.renderer.RTFHandler(stream);
} else {
- if (_renderer == null) throw new Error("_renderer not set when using standard structHandler");
- structHandler = new LayoutHandler(_stream, _renderer, true);
+ if (renderer == null) {
+ throw new Error("Renderer not set when using standard structHandler");
+ }
+ structHandler = new LayoutHandler(stream, renderer, true);
}
structHandler.enableLogging(getLogger());
- _treeBuilder.setUserAgent(getUserAgent());
- _treeBuilder.setStructHandler(structHandler);
+ treeBuilder.setUserAgent(getUserAgent());
+ treeBuilder.setStructHandler(structHandler);
- return _treeBuilder;
+ return treeBuilder;
}
/**
- * Build the formatting object tree using the given SAX Parser and
- * SAX InputSource
+ * Render the FO document read by a SAX Parser from an InputSource.
+ * @param parser the SAX parser.
+ * @param source the input source the parser reads from.
+ * @throws FOPException if anything goes wrong.
*/
public synchronized void render(XMLReader parser, InputSource source)
- throws FOPException {
+ throws FOPException {
parser.setContentHandler(getContentHandler());
try {
parser.parse(source);
} catch (SAXException e) {
if (e.getException() instanceof FOPException) {
+ // Undo exception tunneling.
throw (FOPException)e.getException();
} else {
throw new FOPException(e);
}
- }
- catch (IOException e) {
+ } catch (IOException e) {
throw new FOPException(e);
}
}
/**
- * Build the formatting object tree using the given DOM Document
+ * Render the FO ducument represented by a DOM Document.
+ * @param document the DOM document to read from
+ * @throws FOPException if anything goes wrong.
*/
public synchronized void render(Document document)
- throws FOPException {
-
+ throws FOPException {
try {
DocumentInputSource source = new DocumentInputSource(document);
DocumentReader reader = new DocumentReader();
reader.setContentHandler(getContentHandler());
reader.parse(source);
} catch (SAXException e) {
- throw new FOPException(e);
- }
- catch (IOException e) {
+ if (e.getException() instanceof FOPException) {
+ // Undo exception tunneling.
+ throw (FOPException)e.getException();
+ } else {
+ throw new FOPException(e);
+ }
+ } catch (IOException e) {
throw new FOPException(e);
}
/**
* Runs the formatting and renderering process using the previously set
- * inputsource and outputstream
- */
- public synchronized void run() throws IOException, FOPException {
- if (_renderer == null) {
+ * parser, input source, renderer and output stream.
+ * If the renderer was not set, default to PDF.
+ * If no parser was set, and the input source is not a dom document,
+ * get a default SAX parser.
+ * @throws IOException in case of IO errors.
+ * @throws FOPException if anything else goes wrong.
+ */
+ public synchronized void run()
+ throws IOException, FOPException {
+ if (renderer == null) {
setRenderer(RENDER_PDF);
}
- if (_source == null) {
+ if (source == null) {
throw new FOPException("InputSource is not set.");
}
- if (_reader == null) {
- if (!(_source instanceof DocumentInputSource)) {
+ if (reader == null) {
+ if (!(source instanceof DocumentInputSource)) {
try {
- _reader = javax.xml.parsers.SAXParserFactory.newInstance().newSAXParser().getXMLReader();
- } catch(Exception e) {
+ reader = javax.xml.parsers.SAXParserFactory.newInstance()
+ .newSAXParser().getXMLReader();
+ } catch (SAXException e) {
+ throw new FOPException(e);
+ } catch (ParserConfigurationException e) {
throw new FOPException(e);
}
}
}
- if (_source instanceof DocumentInputSource) {
- render(((DocumentInputSource)_source).getDocument());
+ if (source instanceof DocumentInputSource) {
+ render(((DocumentInputSource)source).getDocument());
} else {
- render(_reader, _source);
+ render(reader, source);
}
}
*/
class Service {
- static Hashtable providerMap = new Hashtable();
+ static private Hashtable providerMap = new Hashtable();
public static synchronized Enumeration providers(Class cls) {
ClassLoader cl = cls.getClassLoader();
/*
* $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
/**
* not implemented yet
*/
-public interface ErrorHandler {}
+public interface ErrorHandler {
+}
/*
* $Id$
- * Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
+ * Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
* Manages input if it is an xsl:fo file
*/
public class FOInputHandler extends InputHandler {
- File fofile = null;
- URL foURL = null;
+ private File fofile = null;
+ private URL foURL = null;
+ /*
+ * Create a FOInputHandler for a file.
+ * @param file the file to read the FO document.
+ */
public FOInputHandler (File fofile) {
this.fofile = fofile;
}
+ /*
+ * Create a FOInputHandler for an URL.
+ * @param file the URL to read the FO document.
+ */
public FOInputHandler (URL url) {
this.foURL = url;
}
+
+ /*
+ * Get the input source associated with this input handler.
+ */
public InputSource getInputSource () {
if (fofile != null) {
return super.fileInputSource(fofile);
return super.urlInputSource(foURL);
}
+ /*
+ * Get the SAX parser associated with this input handler.
+ */
public XMLReader getParser() throws FOPException {
return super.createParser();
}
/*
* $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources."
*/
private static final String EXCEPTION_SEPARATOR = "\n---------\n";
- private Throwable _exception;
+ private Throwable exception;
/**
* create a new FOP Exception
}
protected void setException(Throwable t) {
- _exception = t;
+ exception = t;
}
public Throwable getException() {
- return _exception;
+ return exception;
}
protected Throwable getRootException() {
- Throwable result = _exception;
+ Throwable result = exception;
if (result instanceof SAXException) {
result = ((SAXException)result).getException();
result =
((java.lang.reflect.InvocationTargetException)result).getTargetException();
}
- if (result != _exception) {
+ if (result != exception) {
return result;
}
return null;
public void printStackTrace() {
synchronized (System.err) {
super.printStackTrace();
- if (_exception != null) {
+ if (exception != null) {
System.err.println(EXCEPTION_SEPARATOR);
- _exception.printStackTrace();
+ exception.printStackTrace();
}
if (getRootException() != null) {
System.err.println(EXCEPTION_SEPARATOR);
public void printStackTrace(java.io.PrintStream stream) {
synchronized (stream) {
super.printStackTrace(stream);
- if (_exception != null) {
+ if (exception != null) {
stream.println(EXCEPTION_SEPARATOR);
- _exception.printStackTrace(stream);
+ exception.printStackTrace(stream);
}
if (getRootException() != null) {
stream.println(EXCEPTION_SEPARATOR);
public void printStackTrace(java.io.PrintWriter writer) {
synchronized (writer) {
super.printStackTrace(writer);
- if (_exception != null) {
+ if (exception != null) {
writer.println(EXCEPTION_SEPARATOR);
- _exception.printStackTrace(writer);
+ exception.printStackTrace(writer);
}
if (getRootException() != null) {
writer.println(EXCEPTION_SEPARATOR);
/*
* $Id$
- * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
+ * Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/
package org.apache.fop.apps;
+/*
+ * The main application class for the FOP command line interface (CLI).
+ */
public class Fop {
+
+ /*
+ * The main routine for the command line interface
+ * @param args the command line parameters
+ */
public static void main(String[] args) {
CommandLineOptions options = null;
Starter starter = options.getStarter();
starter.run();
} catch (FOPException e) {
- if("null".equals("" + e.getMessage())) {
+ if (e.getMessage()==null) {
System.err.println("Exception occured with a null error message");
} else {
System.err.println("" + e.getMessage());
import java.net.URL;
import java.io.File;
+/*
+ * Abstract super class for input handlers.
+ * Should be used to abstract the various possibilities on how input
+ * can be provided to FOP (but actually isn't).
+ */
public abstract class InputHandler {
public abstract InputSource getInputSource();
* Creates <code>XMLReader</code> object using default
* <code>SAXParserFactory</code>
* @return the created <code>XMLReader</code>
+ * @throws FOPException if the parser couldn't be created or configured for proper operation.
*/
protected static XMLReader createParser() throws FOPException {
try {
package org.apache.fop.apps;
// Java
-import java.io.OutputStream;
import java.io.IOException;
+import java.io.OutputStream;
import java.util.List;
// SAX
import org.xml.sax.SAXException;
// FOP
+import org.apache.fop.area.AreaTree;
+import org.apache.fop.area.AreaTreeModel;
+import org.apache.fop.area.StorePagesModel;
+import org.apache.fop.area.Title;
+import org.apache.fop.area.TreeExt;
+import org.apache.fop.fo.pagination.LayoutMasterSet;
+import org.apache.fop.fo.pagination.PageSequence;
import org.apache.fop.layout.FontInfo;
-import org.apache.fop.area.*;
import org.apache.fop.render.Renderer;
-import org.apache.fop.fo.pagination.PageSequence;
-import org.apache.fop.fo.pagination.LayoutMasterSet;
/**
* Layout handler that receives the structure events.