Browse Source

Fixed more style problems.


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@195855 13f79535-47bb-0310-9956-ffa450edef68
pull/30/head
Joerg Pietschmann 21 years ago
parent
commit
1837587dc1

+ 14
- 6
src/org/apache/fop/apps/AWTStarter.java View File

/* /*
* $Id$ * $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 * For details on use and redistribution please refer to the
* LICENSE file included with these sources. * LICENSE file included with these sources.
*/ */
import org.apache.fop.viewer.Translator; import org.apache.fop.viewer.Translator;


//Java //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.WindowAdapter;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.util.Locale; import java.util.Locale;
private Driver driver; private Driver driver;
private XMLReader parser; 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); super(commandLineOptions);
init(); init();
} }
private void init() throws FOPException { private void init() throws FOPException {
//Creates Translator according to the language //Creates Translator according to the language
String language = commandLineOptions.getLanguage(); String language = commandLineOptions.getLanguage();
if (language == null)
if (language == null) {
translator = new Translator(Locale.getDefault()); translator = new Translator(Locale.getDefault());
else
} else {
translator = new Translator(new Locale(language, "")); translator = new Translator(new Locale(language, ""));
}
AWTRenderer renderer = new AWTRenderer(translator); AWTRenderer renderer = new AWTRenderer(translator);
frame = createPreviewDialog(renderer, translator); frame = createPreviewDialog(renderer, translator);
renderer.setComponent(frame); renderer.setComponent(frame);


/** /**
* Runs formatting. * Runs formatting.
* @throws FOPException FIXME should not happen.
*/ */
public void run() throws FOPException { public void run() throws FOPException {
driver.reset(); driver.reset();

+ 81
- 95
src/org/apache/fop/apps/CommandLineOptions.java View File

/* /*
* $Id$ * $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 * For details on use and redistribution please refer to the
* LICENSE file included with these sources. * LICENSE file included with these sources.
*/ */
package org.apache.fop.apps; package org.apache.fop.apps;


// java // java
import java.util.Vector;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;


// FOP
import org.apache.fop.apps.FOPException;

// Avalon // Avalon
import org.apache.avalon.framework.logger.ConsoleLogger; import org.apache.avalon.framework.logger.ConsoleLogger;
import org.apache.avalon.framework.logger.Logger; import org.apache.avalon.framework.logger.Logger;


import java.io.*;

/** /**
* Options parses the commandline arguments * Options parses the commandline arguments
*/ */
private static final int RTF_OUTPUT = 10; private static final int RTF_OUTPUT = 10;


/* show configuration information */ /* show configuration information */
Boolean dumpConfiguration = Boolean.FALSE;
private Boolean dumpConfiguration = Boolean.FALSE;
/* suppress any progress information */ /* suppress any progress information */
Boolean quiet = Boolean.FALSE;
private Boolean quiet = Boolean.FALSE;
/* for area tree XML output, only down to block area level */ /* for area tree XML output, only down to block area level */
Boolean suppressLowLevelAreas = Boolean.FALSE;
private Boolean suppressLowLevelAreas = Boolean.FALSE;
/* user configuration file */ /* user configuration file */
File userConfigFile = null;
private File userConfigFile = null;
/* input fo file */ /* input fo file */
File fofile = null;
private File fofile = null;
/* xsltfile (xslt transformation as input) */ /* xsltfile (xslt transformation as input) */
File xsltfile = null;
private File xsltfile = null;
/* xml file (xslt transformation as input) */ /* xml file (xslt transformation as input) */
File xmlfile = null;
private File xmlfile = null;
/* output file */ /* output file */
File outfile = null;
private File outfile = null;
/* input mode */ /* input mode */
int inputmode = NOT_SET;
private int inputmode = NOT_SET;
/* output mode */ /* output mode */
int outputmode = NOT_SET;
private int outputmode = NOT_SET;
/* language for user information */ /* language for user information */
String language = null;
private String language = null;


private java.util.HashMap rendererOptions; private java.util.HashMap rendererOptions;


private Logger log; 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) public CommandLineOptions(String[] args)
throws FOPException, FileNotFoundException { throws FOPException, FileNotFoundException {


printUsage(); printUsage();
throw e; throw e;
} }

} }


/**
* Get the logger.
* @return the logger
*/
public Logger getLogger() { public Logger getLogger() {
return log; return log;
} }


/** /**
* parses the commandline arguments * 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 * @exception FOPException if there was an error in the format of the options
*/ */
private boolean parseOptions(String args[]) throws FOPException { private boolean parseOptions(String args[]) throws FOPException {
} // end checkSettings } // end checkSettings


/** /**
* returns the chosen renderer, throws FOPException
* @return the type chosen renderer
* @throws FOPException for invalid output modes
*/ */
public int getRenderer() throws FOPException { public int getRenderer() throws FOPException {
switch (outputmode) { switch (outputmode) {
} }


/** /**
*
* Get the input handler.
* @return the input handler
*/ */
public InputHandler getInputHandler() { public InputHandler getInputHandler() {
switch (inputmode) { switch (inputmode) {
} }
} }


/**
* Get the renderer specific options.
* @return hash map with option/value pairs.
*/
public java.util.HashMap getRendererOptions() { public java.util.HashMap getRendererOptions() {
return rendererOptions; return rendererOptions;
} }


/**
* Get the starter for the process.
* @return the starter.
*/
public Starter getStarter() throws FOPException { public Starter getStarter() throws FOPException {
Starter starter = null; Starter starter = null;
switch (outputmode) { switch (outputmode) {
case AWT_OUTPUT: case AWT_OUTPUT:
try { 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) { } catch (Exception e) {
if (e instanceof FOPException) {
throw (FOPException)e;
}
throw new FOPException("AWTStarter could not be loaded.", e); throw new FOPException("AWTStarter could not be loaded.", e);
} }
break;
break;
case PRINT_OUTPUT: case PRINT_OUTPUT:
try { 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) { } 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: default:
starter = new CommandLineStarter(this); starter = new CommandLineStarter(this);
} }
} }


/** /**
* return either the fofile or the xmlfile
* @return either the fofile or the xmlfile
*/ */
public File getInputFile() { public File getInputFile() {
switch (inputmode) { switch (inputmode) {
*/ */
public static void printUsage() { 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" 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 * shows the options for print output
*/ */
public void printUsagePrintOutput() { public void printUsagePrintOutput() {
System.err.println("USAGE: -print [-Dstart=i] [-Dend=i] [-Dcopies=i] [-Deven=true|false] " 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();
}

} }



+ 5
- 8
src/org/apache/fop/apps/CommandLineStarter.java View File

/* /*
* $Id$ * $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 * For details on use and redistribution please refer to the
* LICENSE file included with these sources. * LICENSE file included with these sources.
*/ */


// SAX // SAX
import org.xml.sax.XMLReader; import org.xml.sax.XMLReader;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;


// Java // Java
import java.io.*;
import java.net.URL;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;




/** /**
*/ */
public class CommandLineStarter extends Starter { public class CommandLineStarter extends Starter {


CommandLineOptions commandLineOptions;
protected CommandLineOptions commandLineOptions;


public CommandLineStarter(CommandLineOptions commandLineOptions) public CommandLineStarter(CommandLineOptions commandLineOptions)
throws FOPException { throws FOPException {
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream( BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(
commandLineOptions.getOutputFile())); commandLineOptions.getOutputFile()));
driver.setOutputStream(bos); driver.setOutputStream(bos);
if(driver.getRenderer() != null) {
if (driver.getRenderer() != null) {
driver.getRenderer().setOptions( driver.getRenderer().setOptions(
commandLineOptions.getRendererOptions()); commandLineOptions.getRendererOptions());
} }

+ 125
- 103
src/org/apache/fop/apps/Driver.java View File

/* /*
* $Id$ * $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 * For details on use and redistribution please refer to the
* LICENSE file included with these sources. * LICENSE file included with these sources.
*/ */
package org.apache.fop.apps; package org.apache.fop.apps;


// FOP // FOP
import org.apache.fop.fo.FOUserAgent;
import org.apache.fop.fo.FOTreeBuilder;
import org.apache.fop.fo.ElementMapping; 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.render.Renderer;
import org.apache.fop.tools.DocumentInputSource; import org.apache.fop.tools.DocumentInputSource;
import org.apache.fop.tools.DocumentReader; import org.apache.fop.tools.DocumentReader;


import org.apache.fop.render.pdf.PDFRenderer;


// Avalon // Avalon
import org.apache.avalon.framework.logger.ConsoleLogger; 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.LogEnabled;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.logger.Logger;


// DOM // DOM
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Attr;


// SAX // SAX
import org.xml.sax.ContentHandler; import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.AttributesImpl;
import org.xml.sax.XMLReader;
import javax.xml.parsers.ParserConfigurationException;


// Java // 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. * Primary class that drives overall FOP process.
/** /**
* the FO tree builder * the FO tree builder
*/ */
private FOTreeBuilder _treeBuilder;
private FOTreeBuilder treeBuilder;


/** /**
* the renderer type code given by setRenderer * the renderer type code given by setRenderer
*/ */
private int _rendererType;
private int rendererType;


/** /**
* the renderer to use to output the area tree * the renderer to use to output the area tree
*/ */
private Renderer _renderer;
private Renderer renderer;


/** /**
* the structure handler * the structure handler
/** /**
* the source of the FO file * the source of the FO file
*/ */
private InputSource _source;
private InputSource source;


/** /**
* the stream to use to output the results of the renderer * 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 * The XML parser to use when building the FO tree
*/ */
private XMLReader _reader;
private XMLReader reader;


/** /**
* the system resources that FOP will use * the system resources that FOP will use


public static final String getParserClassName() { public static final String getParserClassName() {
try { 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) { } catch (javax.xml.parsers.ParserConfigurationException e) {
return null; return null;
} catch (org.xml.sax.SAXException e) { } catch (org.xml.sax.SAXException e) {
* create a new Driver * create a new Driver
*/ */
public Driver() { public Driver() {
_stream = null;
stream = null;
} }


public Driver(InputSource source, OutputStream stream) { public Driver(InputSource source, OutputStream stream) {
this(); this();
_source = source;
_stream = stream;
this.source = source;
this.stream = stream;
} }


public void initialize() { public void initialize() {
_stream = null;
_treeBuilder = new FOTreeBuilder();
_treeBuilder.setUserAgent(getUserAgent());
stream = null;
treeBuilder = new FOTreeBuilder();
treeBuilder.setUserAgent(getUserAgent());
setupDefaultMappings(); setupDefaultMappings();
} }


if (userAgent == null) { if (userAgent == null) {
userAgent = new FOUserAgent(); userAgent = new FOUserAgent();
userAgent.enableLogging(getLogger()); userAgent.enableLogging(getLogger());
userAgent.setBaseURL("file:/.");
userAgent.setBaseURL("");
} }
return userAgent; return userAgent;
} }
* The output stream is cleared. The renderer is cleared. * The output stream is cleared. The renderer is cleared.
*/ */
public synchronized void reset() { public synchronized void reset() {
_source = null;
_stream = null;
_reader = null;
_treeBuilder.reset();
source = null;
stream = null;
reader = null;
treeBuilder.reset();
} }


public boolean hasData() { public boolean hasData() {
return (_treeBuilder.hasData());
return (treeBuilder.hasData());
} }


/** /**
* *
*/ */
public void setOutputStream(OutputStream stream) { public void setOutputStream(OutputStream stream) {
_stream = stream;
this.stream = stream;
} }


/** /**
* @see DocumentInputSource * @see DocumentInputSource
*/ */
public void setInputSource(InputSource source) { public void setInputSource(InputSource source) {
_source = source;
this.source = source;
} }


/** /**
* Sets the reader used when reading in the source. If not set, * Sets the reader used when reading in the source. If not set,
* this defaults to a basic SAX parser. * this defaults to a basic SAX parser.
* @param reader the reader to use.
*/ */
public void setXMLReader(XMLReader reader) { public void setXMLReader(XMLReader reader) {
_reader = reader;
this.reader = reader;
} }


/** /**
String str = (String)providers.nextElement(); String str = (String)providers.nextElement();
try { try {
addElementMapping(str); 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> * <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> * </ul>
* @param renderer the type of renderer to use * @param renderer the type of renderer to use
* @throws IllegalArgumentException if an unsupported renderer type was required.
*/ */
public void setRenderer(int renderer) throws IllegalArgumentException { public void setRenderer(int renderer) throws IllegalArgumentException {
_rendererType = renderer;
rendererType = renderer;
switch (renderer) { switch (renderer) {
case RENDER_PDF: case RENDER_PDF:
setRenderer("org.apache.fop.render.pdf.PDFRenderer"); setRenderer("org.apache.fop.render.pdf.PDFRenderer");
*/ */
public void setRenderer(Renderer renderer) { public void setRenderer(Renderer renderer) {
renderer.setUserAgent(getUserAgent()); renderer.setUserAgent(getUserAgent());
_renderer = renderer;
this.renderer = renderer;
} }


public Renderer getRenderer() { 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(int)
* @see #setRenderer(Renderer) * @see #setRenderer(Renderer)
*/ */
public void setRenderer(String rendererClassName) public void setRenderer(String rendererClassName)
throws IllegalArgumentException { throws IllegalArgumentException {
try { try {
_renderer =
renderer =
(Renderer)Class.forName(rendererClassName).newInstance(); (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) { } catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Could not find " throw new IllegalArgumentException("Could not find "
+ rendererClassName); + rendererClassName);
}
catch (InstantiationException e) {
} catch (InstantiationException e) {
throw new IllegalArgumentException("Could not instantiate " throw new IllegalArgumentException("Could not instantiate "
+ rendererClassName); + rendererClassName);
}
catch (IllegalAccessException e) {
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("Could not access " throw new IllegalArgumentException("Could not access "
+ rendererClassName); + rendererClassName);
}
catch (ClassCastException e) {
} catch (ClassCastException e) {
throw new IllegalArgumentException(rendererClassName throw new IllegalArgumentException(rendererClassName
+ " is not a renderer"); + " is not a renderer");
} }
* @param mapping the element mappingto add * @param mapping the element mappingto add
*/ */
public void addElementMapping(ElementMapping mapping) { 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) public void addElementMapping(String mappingClassName)
throws IllegalArgumentException {
throws IllegalArgumentException {
try { try {
ElementMapping mapping = ElementMapping mapping =
(ElementMapping)Class.forName(mappingClassName).newInstance(); (ElementMapping)Class.forName(mappingClassName).newInstance();
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
throw new IllegalArgumentException("Could not find " throw new IllegalArgumentException("Could not find "
+ mappingClassName); + mappingClassName);
}
catch (InstantiationException e) {
} catch (InstantiationException e) {
throw new IllegalArgumentException("Could not instantiate " throw new IllegalArgumentException("Could not instantiate "
+ mappingClassName); + mappingClassName);
}
catch (IllegalAccessException e) {
} catch (IllegalAccessException e) {
throw new IllegalArgumentException("Could not access " throw new IllegalArgumentException("Could not access "
+ mappingClassName); + mappingClassName);
}
catch (ClassCastException e) {
} catch (ClassCastException e) {
throw new IllegalArgumentException(mappingClassName throw new IllegalArgumentException(mappingClassName
+ " is not an ElementMapping"); + " is not an ElementMapping");
} }
* Used in situations where SAX is used but not via a FOP-invoked * 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 * SAX parser. A good example is an XSLT engine that fires SAX
* events but isn't a SAX Parser itself. * events but isn't a SAX Parser itself.
* @return a content handler for handling the SAX events.
*/ */
public ContentHandler getContentHandler() { public ContentHandler getContentHandler() {
// TODO - do this stuff in a better way // 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 { } 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()); 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) public synchronized void render(XMLReader parser, InputSource source)
throws FOPException {
throws FOPException {
parser.setContentHandler(getContentHandler()); parser.setContentHandler(getContentHandler());
try { try {
parser.parse(source); parser.parse(source);
} catch (SAXException e) { } catch (SAXException e) {
if (e.getException() instanceof FOPException) { if (e.getException() instanceof FOPException) {
// Undo exception tunneling.
throw (FOPException)e.getException(); throw (FOPException)e.getException();
} else { } else {
throw new FOPException(e); throw new FOPException(e);
} }
}
catch (IOException e) {
} catch (IOException e) {
throw new FOPException(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) public synchronized void render(Document document)
throws FOPException {

throws FOPException {
try { try {
DocumentInputSource source = new DocumentInputSource(document); DocumentInputSource source = new DocumentInputSource(document);
DocumentReader reader = new DocumentReader(); DocumentReader reader = new DocumentReader();
reader.setContentHandler(getContentHandler()); reader.setContentHandler(getContentHandler());
reader.parse(source); reader.parse(source);
} catch (SAXException e) { } 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); throw new FOPException(e);
} }




/** /**
* Runs the formatting and renderering process using the previously set * 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); setRenderer(RENDER_PDF);
} }


if (_source == null) {
if (source == null) {
throw new FOPException("InputSource is not set."); throw new FOPException("InputSource is not set.");
} }


if (_reader == null) {
if (!(_source instanceof DocumentInputSource)) {
if (reader == null) {
if (!(source instanceof DocumentInputSource)) {
try { 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); throw new FOPException(e);
} }
} }
} }


if (_source instanceof DocumentInputSource) {
render(((DocumentInputSource)_source).getDocument());
if (source instanceof DocumentInputSource) {
render(((DocumentInputSource)source).getDocument());
} else { } else {
render(_reader, _source);
render(reader, source);
} }
} }


*/ */
class Service { class Service {


static Hashtable providerMap = new Hashtable();
static private Hashtable providerMap = new Hashtable();


public static synchronized Enumeration providers(Class cls) { public static synchronized Enumeration providers(Class cls) {
ClassLoader cl = cls.getClassLoader(); ClassLoader cl = cls.getClassLoader();

+ 3
- 2
src/org/apache/fop/apps/ErrorHandler.java View File

/* /*
* $Id$ * $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 * For details on use and redistribution please refer to the
* LICENSE file included with these sources. * LICENSE file included with these sources.
*/ */
/** /**
* not implemented yet * not implemented yet
*/ */
public interface ErrorHandler {}
public interface ErrorHandler {
}

+ 18
- 3
src/org/apache/fop/apps/FOInputHandler.java View File

/* /*
* $Id$ * $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 * For details on use and redistribution please refer to the
* LICENSE file included with these sources. * LICENSE file included with these sources.
*/ */
* Manages input if it is an xsl:fo file * Manages input if it is an xsl:fo file
*/ */
public class FOInputHandler extends InputHandler { 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) { public FOInputHandler (File fofile) {
this.fofile = fofile; this.fofile = fofile;
} }


/*
* Create a FOInputHandler for an URL.
* @param file the URL to read the FO document.
*/
public FOInputHandler (URL url) { public FOInputHandler (URL url) {
this.foURL = url; this.foURL = url;
} }


/*
* Get the input source associated with this input handler.
*/
public InputSource getInputSource () { public InputSource getInputSource () {
if (fofile != null) { if (fofile != null) {
return super.fileInputSource(fofile); return super.fileInputSource(fofile);
return super.urlInputSource(foURL); return super.urlInputSource(foURL);
} }


/*
* Get the SAX parser associated with this input handler.
*/
public XMLReader getParser() throws FOPException { public XMLReader getParser() throws FOPException {
return super.createParser(); return super.createParser();
} }

+ 12
- 12
src/org/apache/fop/apps/FOPException.java View File

/* /*
* $Id$ * $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 * For details on use and redistribution please refer to the
* LICENSE file included with these sources." * LICENSE file included with these sources."
*/ */


private static final String EXCEPTION_SEPARATOR = "\n---------\n"; private static final String EXCEPTION_SEPARATOR = "\n---------\n";


private Throwable _exception;
private Throwable exception;


/** /**
* create a new FOP Exception * create a new FOP Exception
} }


protected void setException(Throwable t) { protected void setException(Throwable t) {
_exception = t;
exception = t;
} }


public Throwable getException() { public Throwable getException() {
return _exception;
return exception;
} }


protected Throwable getRootException() { protected Throwable getRootException() {
Throwable result = _exception;
Throwable result = exception;


if (result instanceof SAXException) { if (result instanceof SAXException) {
result = ((SAXException)result).getException(); result = ((SAXException)result).getException();
result = result =
((java.lang.reflect.InvocationTargetException)result).getTargetException(); ((java.lang.reflect.InvocationTargetException)result).getTargetException();
} }
if (result != _exception) {
if (result != exception) {
return result; return result;
} }
return null; return null;
public void printStackTrace() { public void printStackTrace() {
synchronized (System.err) { synchronized (System.err) {
super.printStackTrace(); super.printStackTrace();
if (_exception != null) {
if (exception != null) {
System.err.println(EXCEPTION_SEPARATOR); System.err.println(EXCEPTION_SEPARATOR);
_exception.printStackTrace();
exception.printStackTrace();
} }
if (getRootException() != null) { if (getRootException() != null) {
System.err.println(EXCEPTION_SEPARATOR); System.err.println(EXCEPTION_SEPARATOR);
public void printStackTrace(java.io.PrintStream stream) { public void printStackTrace(java.io.PrintStream stream) {
synchronized (stream) { synchronized (stream) {
super.printStackTrace(stream); super.printStackTrace(stream);
if (_exception != null) {
if (exception != null) {
stream.println(EXCEPTION_SEPARATOR); stream.println(EXCEPTION_SEPARATOR);
_exception.printStackTrace(stream);
exception.printStackTrace(stream);
} }
if (getRootException() != null) { if (getRootException() != null) {
stream.println(EXCEPTION_SEPARATOR); stream.println(EXCEPTION_SEPARATOR);
public void printStackTrace(java.io.PrintWriter writer) { public void printStackTrace(java.io.PrintWriter writer) {
synchronized (writer) { synchronized (writer) {
super.printStackTrace(writer); super.printStackTrace(writer);
if (_exception != null) {
if (exception != null) {
writer.println(EXCEPTION_SEPARATOR); writer.println(EXCEPTION_SEPARATOR);
_exception.printStackTrace(writer);
exception.printStackTrace(writer);
} }
if (getRootException() != null) { if (getRootException() != null) {
writer.println(EXCEPTION_SEPARATOR); writer.println(EXCEPTION_SEPARATOR);

+ 10
- 2
src/org/apache/fop/apps/Fop.java View File

/* /*
* $Id$ * $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 * For details on use and redistribution please refer to the
* LICENSE file included with these sources. * LICENSE file included with these sources.
*/ */


package org.apache.fop.apps; package org.apache.fop.apps;


/*
* The main application class for the FOP command line interface (CLI).
*/
public class Fop { public class Fop {

/*
* The main routine for the command line interface
* @param args the command line parameters
*/
public static void main(String[] args) { public static void main(String[] args) {
CommandLineOptions options = null; CommandLineOptions options = null;


Starter starter = options.getStarter(); Starter starter = options.getStarter();
starter.run(); starter.run();
} catch (FOPException e) { } catch (FOPException e) {
if("null".equals("" + e.getMessage())) {
if (e.getMessage()==null) {
System.err.println("Exception occured with a null error message"); System.err.println("Exception occured with a null error message");
} else { } else {
System.err.println("" + e.getMessage()); System.err.println("" + e.getMessage());

+ 6
- 0
src/org/apache/fop/apps/InputHandler.java View File

import java.net.URL; import java.net.URL;
import java.io.File; 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 class InputHandler {


public abstract InputSource getInputSource(); public abstract InputSource getInputSource();
* Creates <code>XMLReader</code> object using default * Creates <code>XMLReader</code> object using default
* <code>SAXParserFactory</code> * <code>SAXParserFactory</code>
* @return the created <code>XMLReader</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 { protected static XMLReader createParser() throws FOPException {
try { try {

+ 8
- 4
src/org/apache/fop/apps/LayoutHandler.java View File

package org.apache.fop.apps; package org.apache.fop.apps;


// Java // Java
import java.io.OutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream;
import java.util.List; import java.util.List;


// SAX // SAX
import org.xml.sax.SAXException; import org.xml.sax.SAXException;


// FOP // 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.layout.FontInfo;
import org.apache.fop.area.*;
import org.apache.fop.render.Renderer; 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. * Layout handler that receives the structure events.

Loading…
Cancel
Save