Bladeren bron

Switched to long licence

Some general checkstyle fixing
Removed unused ErrorHandler (readd when we know what to do with it)


git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@196004 13f79535-47bb-0310-9956-ffa450edef68
pull/30/head
Jeremias Maerki 21 jaren geleden
bovenliggende
commit
9a5eae0085

+ 48
- 5
src/org/apache/fop/apps/AWTStarter.java Bestand weergeven

/* /*
* $Id$ * $Id$
* 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.
*/

* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps; package org.apache.fop.apps;


//FOP //FOP

+ 139
- 43
src/org/apache/fop/apps/CommandLineOptions.java Bestand weergeven

/* /*
* $Id$ * $Id$
* 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.
*/

* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps; package org.apache.fop.apps;


// java // java


/** /**
* parses the commandline arguments * parses the commandline arguments
* @return true if parse was successful and processing 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 {
} else if (args[i].equals("-c")) { } else if (args[i].equals("-c")) {
if ((i + 1 == args.length) if ((i + 1 == args.length)
|| (args[i + 1].charAt(0) == '-')) { || (args[i + 1].charAt(0) == '-')) {
throw new FOPException("if you use '-c', you must specify the name of the configuration file");
throw new FOPException("if you use '-c', you must specify "
+ "the name of the configuration file");
} else { } else {
userConfigFile = new File(args[i + 1]); userConfigFile = new File(args[i + 1]);
i++; i++;
inputmode = XSLT_INPUT; inputmode = XSLT_INPUT;
if ((i + 1 == args.length) if ((i + 1 == args.length)
|| (args[i + 1].charAt(0) == '-')) { || (args[i + 1].charAt(0) == '-')) {
throw new FOPException("you must specify the stylesheet file for the '-xsl' option");
throw new FOPException("you must specify the stylesheet "
+ "file for the '-xsl' option");
} else { } else {
xsltfile = new File(args[i + 1]); xsltfile = new File(args[i + 1]);
i++; i++;
inputmode = XSLT_INPUT; inputmode = XSLT_INPUT;
if ((i + 1 == args.length) if ((i + 1 == args.length)
|| (args[i + 1].charAt(0) == '-')) { || (args[i + 1].charAt(0) == '-')) {
throw new FOPException("you must specify the input file for the '-xml' option");
throw new FOPException("you must specify the input file "
+ "for the '-xml' option");
} else { } else {
xmlfile = new File(args[i + 1]); xmlfile = new File(args[i + 1]);
i++; i++;
setOutputMode(SVG_OUTPUT); setOutputMode(SVG_OUTPUT);
if ((i + 1 == args.length) if ((i + 1 == args.length)
|| (args[i + 1].charAt(0) == '-')) { || (args[i + 1].charAt(0) == '-')) {
throw new FOPException("you must specify the svg output file"); } else {
throw new FOPException("you must specify the svg output file");
} else {
outfile = new File(args[i + 1]); outfile = new File(args[i + 1]);
i++; i++;
} }
/** /**
* Get the starter for the process. * Get the starter for the process.
* @return the starter. * @return the starter.
* @throws FOPException In case of failure while getting the starter
*/ */
public Starter getStarter() throws FOPException { public Starter getStarter() throws FOPException {
Starter starter = null; Starter starter = null;
return starter; return starter;
} }


/**
* Returns the input mode (type of input data, ex. NOT_SET or FO_INPUT)
* @return the input mode
*/
public int getInputMode() { public int getInputMode() {
return inputmode; return inputmode;
} }


/**
* Returns the output mode (output format, ex. NOT_SET or PDF_OUTPUT)
* @return the output mode
*/
public int getOutputMode() { public int getOutputMode() {
return outputmode; return outputmode;
} }


/**
* Returns the XSL-FO file if set.
* @return the XSL-FO file, null if not set
*/
public File getFOFile() { public File getFOFile() {
return fofile; return fofile;
} }


/**
* Returns the input XML file if set.
* @return the input XML file, null if not set
*/
public File getXMLFile() { public File getXMLFile() {
return xmlfile; return xmlfile;
} }


/**
* Returns the stylesheet to be used for transformation to XSL-FO.
* @return stylesheet
*/
public File getXSLFile() { public File getXSLFile() {
return xsltfile; return xsltfile;
} }


/**
* Returns the output file
* @return the output file
*/
public File getOutputFile() { public File getOutputFile() {
return outfile; return outfile;
} }


/**
* Returns the user configuration file to be used.
* @return the userconfig.xml file
*/
public File getUserConfigFile() { public File getUserConfigFile() {
return userConfigFile; return userConfigFile;
} }


/**
* Returns the default language
* @return the default language
*/
public String getLanguage() { public String getLanguage() {
return language; return language;
} }


/**
* Indicates if FOP should be silent.
* @return true if should be silent
*/
public Boolean isQuiet() { public Boolean isQuiet() {
return quiet; return quiet;
} }


/**
* Indicates if FOP should dump its configuration during runtime.
* @return true if config dump is enabled
*/
public Boolean dumpConfiguration() { public Boolean dumpConfiguration() {
return dumpConfiguration; return dumpConfiguration;
} }


/**
* Indicates whether the XML renderer should generate course area XML
* @return true if coarse area XML is desired
*/
public Boolean isCoarseAreaXml() { public Boolean isCoarseAreaXml() {
return suppressLowLevelAreas; return suppressLowLevelAreas;
} }


/** /**
* Returns the input file.
* @return either the fofile or the xmlfile * @return either the fofile or the xmlfile
*/ */
public File getInputFile() { public File getInputFile() {
* shows the commandline syntax including a summary of all available options and some examples * shows the commandline syntax including a summary of all available options and some examples
*/ */
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"
+ " [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");
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");
} }
/** /**

+ 55
- 6
src/org/apache/fop/apps/CommandLineStarter.java Bestand weergeven

/* /*
* $Id$ * $Id$
* 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.
*/

* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps; package org.apache.fop.apps;


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


/** the command-line options associated with this starter */
protected CommandLineOptions commandLineOptions; protected CommandLineOptions commandLineOptions;


/**
* Main constructor
* @param commandLineOptions command-line options to use
* @throws FOPException In case of failure
*/
public CommandLineStarter(CommandLineOptions commandLineOptions) public CommandLineStarter(CommandLineOptions commandLineOptions)
throws FOPException {
throws FOPException {
this.commandLineOptions = commandLineOptions; this.commandLineOptions = commandLineOptions;
super.setInputHandler(commandLineOptions.getInputHandler()); super.setInputHandler(commandLineOptions.getInputHandler());
} }

+ 120
- 32
src/org/apache/fop/apps/Driver.java Bestand weergeven

/* /*
* $Id$ * $Id$
* 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.
*/

* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps; package org.apache.fop.apps;


// FOP // FOP
import java.io.OutputStream; import java.io.OutputStream;
import java.io.Reader; import java.io.Reader;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Vector;
import java.util.Iterator;
import java.util.List;
import java.util.Map;


/** /**
* Primary class that drives overall FOP process. * Primary class that drives overall FOP process.
private Logger log = null; private Logger log = null;
private FOUserAgent userAgent = null; private FOUserAgent userAgent = null;


/**
* Returns the fully qualified classname of the standard XML parser for FOP
* to use.
* @return the XML parser classname
*/
public static final String getParserClassName() { public static final String getParserClassName() {
try { try {
return javax.xml.parsers.SAXParserFactory.newInstance() return javax.xml.parsers.SAXParserFactory.newInstance()
} }


/** /**
* create a new Driver
* Main constructor for the Driver class.
*/ */
public Driver() { public Driver() {
stream = null; stream = null;
} }


/**
* Convenience constructor for directly setting input and output.
* @param source InputSource to take the XSL-FO input from
* @param stream Target output stream
*/
public Driver(InputSource source, OutputStream stream) { public Driver(InputSource source, OutputStream stream) {
this(); this();
this.source = source; this.source = source;
this.stream = stream; this.stream = stream;
} }


/**
* Initializes the Driver object.
*/
public void initialize() { public void initialize() {
stream = null; stream = null;
treeBuilder = new FOTreeBuilder(); treeBuilder = new FOTreeBuilder();
setupDefaultMappings(); setupDefaultMappings();
} }


/**
* Optionally sets the FOUserAgent instance for FOP to use. The Driver
* class sets up its own FOUserAgent if none is set through this method.
* @param agent FOUserAgent to use
*/
public void setUserAgent(FOUserAgent agent) { public void setUserAgent(FOUserAgent agent) {
userAgent = agent; userAgent = agent;
} }
return userAgent; return userAgent;
} }


/**
* Provide the Driver instance with a logger. More information on Avalon
* logging can be found at the
* <a href="http://avalon.apache.org">Avalon site</a>.
*
* @param log the logger. Must not be <code>null</code>.
* @see org.apache.avalon.framework.logger.LogEnabled#enableLogging(Logger)
*/
public void enableLogging(Logger log) { public void enableLogging(Logger log) {
if (this.log == null) { if (this.log == null) {
this.log = log; this.log = log;
} }




/**
* Returns the logger for use by FOP.
* @return the logger
* @see #enableLogging(Logger)
*/
protected Logger getLogger() { protected Logger getLogger() {
if (this.log == null) { if (this.log == null) {
this.log = new ConsoleLogger(ConsoleLogger.LEVEL_INFO); this.log = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
treeBuilder.reset(); treeBuilder.reset();
} }


/**
* Indicates whether FOP has already received input data.
* @return true, if input data was received
*/
public boolean hasData() { public boolean hasData() {
return (treeBuilder.hasData()); return (treeBuilder.hasData());
} }
* Set the OutputStream to use to output the result of the Renderer * Set the OutputStream to use to output the result of the Renderer
* (if applicable) * (if applicable)
* @param stream the stream to output the result of rendering to * @param stream the stream to output the result of rendering to
*
*/ */
public void setOutputStream(OutputStream stream) { public void setOutputStream(OutputStream stream) {
this.stream = stream; this.stream = stream;
addElementMapping("org.apache.fop.extensions.ExtensionElementMapping"); addElementMapping("org.apache.fop.extensions.ExtensionElementMapping");


// add mappings from available services // add mappings from available services
Enumeration providers =
Iterator providers =
Service.providers(org.apache.fop.fo.ElementMapping.class); Service.providers(org.apache.fop.fo.ElementMapping.class);
if (providers != null) { if (providers != null) {
while (providers.hasMoreElements()) {
String str = (String)providers.nextElement();
while (providers.hasNext()) {
String str = (String)providers.next();
try { try {
addElementMapping(str); addElementMapping(str);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
getLogger().warn("Error while adding element mapping", e);
} }


} }
this.renderer = renderer; this.renderer = renderer;
} }


/**
* Returns the currently active renderer.
* @return the renderer
*/
public Renderer getRenderer() { public Renderer getRenderer() {
return renderer; return renderer;
} }


/** /**
* @deprecated use renderer.setProducer(version) + setRenderer(renderer) or just setRenderer(rendererType) which will use the default producer string.
* Sets the renderer.
* @param rendererClassName the fully qualified classname of the renderer
* class to use.
* @param version version number
* @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)
*/ */
* @see #setRenderer(int) * @see #setRenderer(int)
*/ */
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();


/** /**
* 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.
* @param mappingClassName the class name representing the element mapping.
* @throws IllegalArgumentException if there was not such 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();
* @return a content handler for handling the SAX events. * @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
// PIJ: I guess the structure handler should be created by the renderer. // PIJ: I guess the structure handler should be created by the renderer.
if (rendererType == RENDER_MIF) { if (rendererType == RENDER_MIF) {
structHandler = new org.apache.fop.mif.MIFHandler(stream); structHandler = new org.apache.fop.mif.MIFHandler(stream);
structHandler = new org.apache.fop.rtf.renderer.RTFHandler(stream); structHandler = new org.apache.fop.rtf.renderer.RTFHandler(stream);
} else { } else {
if (renderer == null) { if (renderer == null) {
throw new Error("Renderer not set when using standard structHandler");
throw new IllegalStateException(
"Renderer not set when using standard structHandler");
} }
structHandler = new LayoutHandler(stream, renderer, true); structHandler = new LayoutHandler(stream, renderer, true);
} }
* @throws FOPException if anything goes wrong. * @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);
* @throws FOPException if anything goes wrong. * @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();
* @throws IOException in case of IO errors. * @throws IOException in case of IO errors.
* @throws FOPException if anything else goes wrong. * @throws FOPException if anything else goes wrong.
*/ */
public synchronized void run()
throws IOException, FOPException {
public synchronized void run() throws IOException, FOPException {
if (renderer == null) { if (renderer == null) {
setRenderer(RENDER_PDF); setRenderer(RENDER_PDF);
} }
*/ */
class Service { class Service {


static private Hashtable providerMap = new Hashtable();
private static Map providerMap = new java.util.Hashtable();


public static synchronized Enumeration providers(Class cls) {
public static synchronized Iterator providers(Class cls) {
ClassLoader cl = cls.getClassLoader(); ClassLoader cl = cls.getClassLoader();
// null if loaded by bootstrap class loader // null if loaded by bootstrap class loader
if (cl == null) { if (cl == null) {


// getLogger().debug("File: " + serviceFile); // getLogger().debug("File: " + serviceFile);


Vector v = (Vector)providerMap.get(serviceFile);
if (v != null) {
return v.elements();
List lst = (List)providerMap.get(serviceFile);
if (lst != null) {
return lst.iterator();
} }


v = new Vector();
providerMap.put(serviceFile, v);
lst = new java.util.Vector();
providerMap.put(serviceFile, lst);


Enumeration e; Enumeration e;
try { try {
e = cl.getResources(serviceFile); e = cl.getResources(serviceFile);
} catch (IOException ioe) { } catch (IOException ioe) {
return v.elements();
return lst.iterator();
} }


while (e.hasMoreElements()) { while (e.hasMoreElements()) {
// Try and load the class // Try and load the class
// Object obj = cl.loadClass(line).newInstance(); // Object obj = cl.loadClass(line).newInstance();
// stick it into our vector... // stick it into our vector...
v.add(line);
lst.add(line);
} catch (Exception ex) { } catch (Exception ex) {
// Just try the next line // Just try the next line
} }
} }


} }
return v.elements();
return lst.iterator();
} }


} }

+ 0
- 14
src/org/apache/fop/apps/ErrorHandler.java Bestand weergeven

/*
* $Id$
* 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;

/**
* not implemented yet
*/
public interface ErrorHandler {
}

+ 60
- 16
src/org/apache/fop/apps/FOInputHandler.java Bestand weergeven

/* /*
* $Id$ * $Id$
* 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.
*/

* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps; package org.apache.fop.apps;


// Imported SAX classes // Imported SAX classes
import java.net.URL; import java.net.URL;


/** /**
* 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 {
private File fofile = null; private File fofile = null;
private URL foURL = null; private URL foURL = null;


/*
/**
* Create a FOInputHandler for a file. * Create a FOInputHandler for a file.
* @param file the file to read the FO document.
* @param fofile 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. * Create a FOInputHandler for an URL.
* @param file the URL to read the FO document.
* @param url 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.
/**
* @see org.apache.fop.apps.InputHandler#getInputSource()
*/ */
public InputSource getInputSource () { public InputSource getInputSource () {
if (fofile != null) { if (fofile != null) {
return super.urlInputSource(foURL); return super.urlInputSource(foURL);
} }


/*
* Get the SAX parser associated with this input handler.
/**
* @see org.apache.fop.apps.InputHandler#getParser()
*/ */
public XMLReader getParser() throws FOPException { public XMLReader getParser() throws FOPException {
return super.createParser(); return super.createParser();

+ 49
- 7
src/org/apache/fop/apps/FOPException.java Bestand weergeven

/* /*
* $Id$ * $Id$
* 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."
*/

* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps; package org.apache.fop.apps;


import org.xml.sax.SAXException; import org.xml.sax.SAXException;



/** /**
* Exception thrown when FOP has a problem
* Exception thrown when FOP has a problem.
*/ */
public class FOPException extends Exception { public class FOPException extends Exception {



+ 51
- 8
src/org/apache/fop/apps/Fop.java Bestand weergeven

/* /*
* $Id$ * $Id$
* 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.
*/

* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps; package org.apache.fop.apps;


/*
/**
* The main application class for the FOP command line interface (CLI). * 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 * The main routine for the command line interface
* @param args the command line parameters * @param args the command line parameters
*/ */
Starter starter = options.getStarter(); Starter starter = options.getStarter();
starter.run(); starter.run();
} catch (FOPException e) { } catch (FOPException e) {
if (e.getMessage()==null) {
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());

+ 64
- 6
src/org/apache/fop/apps/InputHandler.java Bestand weergeven

/* /*
* $Id$ * $Id$
* Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/

* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps; package org.apache.fop.apps;


// SAX // SAX
import java.net.URL; import java.net.URL;
import java.io.File; import java.io.File;


/*
/**
* Abstract super class for input handlers. * Abstract super class for input handlers.
* Should be used to abstract the various possibilities on how input * Should be used to abstract the various possibilities on how input
* can be provided to FOP (but actually isn't). * can be provided to FOP (but actually isn't).
*/ */
public abstract class InputHandler { public abstract class InputHandler {


/**
* Get the input source associated with this input handler.
* @return the input source
*/
public abstract InputSource getInputSource(); public abstract InputSource getInputSource();

/**
* Get the SAX parser associated with this input handler.
* @return the SAX parser
* @throws FOPException in case of an error determining the SAX parser
*/
public abstract XMLReader getParser() throws FOPException; public abstract XMLReader getParser() throws FOPException;


/**
* Creates an InputSource from a URL.
* @param url URL to use
* @return the newly created InputSource
*/
public static InputSource urlInputSource(URL url) { public static InputSource urlInputSource(URL url) {
return new InputSource(url.toString()); return new InputSource(url.toString());
} }

+ 72
- 23
src/org/apache/fop/apps/LayoutHandler.java Bestand weergeven

/* /*
* $Id$ * $Id$
* Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/

* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps; package org.apache.fop.apps;


// Java // Java


// TODO: Collecting of statistics should be configurable // TODO: Collecting of statistics should be configurable
private final boolean collectStatistics = true; private final boolean collectStatistics = true;
private final boolean MEM_PROFILE_WITH_GC = false;
private static final boolean MEM_PROFILE_WITH_GC = false;


/** /**
Somewhere to get our stats from.
* Somewhere to get our stats from.
*/ */
private Runtime runtime; private Runtime runtime;


/** /**
Keep track of the number of pages rendered.
* Keep track of the number of pages rendered.
*/ */
private int pageCount; private int pageCount;


/** /**
Keep track of heap memory allocated,
for statistical purposes.
* Keep track of heap memory allocated,
* for statistical purposes.
*/ */
private long initialMemory; private long initialMemory;


/** /**
Keep track of time used by renderer.
* Keep track of time used by renderer.
*/ */
private long startTime; private long startTime;


/** /**
The stream to which this rendering is to be
written to. <B>Note</B> that some renderers
do not render to a stream, and that this
member can therefore be null.
* The stream to which this rendering is to be
* written to. <B>Note</B> that some renderers
* do not render to a stream, and that this
* member can therefore be null.
*/ */
private OutputStream outputStream; private OutputStream outputStream;


/** /**
The renderer being used.
* The renderer being used.
*/ */
private Renderer renderer; private Renderer renderer;


/** /**
The FontInfo for this renderer.
* The FontInfo for this renderer.
*/ */
private FontInfo fontInfo = new FontInfo(); private FontInfo fontInfo = new FontInfo();


private AreaTreeModel atModel; private AreaTreeModel atModel;


/** /**
* Main constructor
* @param outputStream the stream that the result is rendered to * @param outputStream the stream that the result is rendered to
* @param renderer the renderer to call * @param renderer the renderer to call
* @param store if true then use the store pages model and keep the * @param store if true then use the store pages model and keep the
*/ */
public LayoutHandler(OutputStream outputStream, Renderer renderer, public LayoutHandler(OutputStream outputStream, Renderer renderer,
boolean store) { boolean store) {
if (collectStatistics)
if (collectStatistics) {
runtime = Runtime.getRuntime(); runtime = Runtime.getRuntime();
}
this.outputStream = outputStream; this.outputStream = outputStream;
this.renderer = renderer; this.renderer = renderer;


if (MEM_PROFILE_WITH_GC) { if (MEM_PROFILE_WITH_GC) {
System.gc(); // This takes time but gives better results System.gc(); // This takes time but gives better results
} }
initialMemory = runtime.totalMemory() - runtime.freeMemory(); initialMemory = runtime.totalMemory() - runtime.freeMemory();
startTime = System.currentTimeMillis(); startTime = System.currentTimeMillis();
} }
try { try {
renderer.setupFontInfo(fontInfo); renderer.setupFontInfo(fontInfo);
// check that the "any,normal,400" font exists // check that the "any,normal,400" font exists
if(!fontInfo.isSetupValid()) {
throw new SAXException(new FOPException("no default font defined by OutputConverter"));
if (!fontInfo.isSetupValid()) {
throw new SAXException(new FOPException(
"No default font defined by OutputConverter"));
} }
renderer.startRenderer(outputStream); renderer.startRenderer(outputStream);
} catch (IOException e) { } catch (IOException e) {
* @param seqTitle the title of the page sequence * @param seqTitle the title of the page sequence
* @param lms the layout master set * @param lms the layout master set
*/ */
public void startPageSequence(PageSequence pageSeq, org.apache.fop.fo.Title seqTitle, LayoutMasterSet lms) {
public void startPageSequence(PageSequence pageSeq,
org.apache.fop.fo.Title seqTitle,
LayoutMasterSet lms) {
Title title = null; Title title = null;
if (seqTitle != null) { if (seqTitle != null) {
title = seqTitle.getTitleArea(); title = seqTitle.getTitleArea();
* @throws FOPException if there is an error formatting the pages * @throws FOPException if there is an error formatting the pages
*/ */
public void endPageSequence(PageSequence pageSequence) public void endPageSequence(PageSequence pageSequence)
throws FOPException {
throws FOPException {
//areaTree.setFontInfo(fontInfo); //areaTree.setFontInfo(fontInfo);


if (collectStatistics) { if (collectStatistics) {
count++; count++;
} }
List list = model.getEndExtensions(); List list = model.getEndExtensions();
for(count = 0; count < list.size(); count++) {
for (count = 0; count < list.size(); count++) {
TreeExt ext = (TreeExt)list.get(count); TreeExt ext = (TreeExt)list.get(count);
renderer.renderExtension(ext); renderer.renderExtension(ext);
} }

+ 61
- 19
src/org/apache/fop/apps/PrintStarter.java Bestand weergeven

/* /*
* $Id$ * $Id$
* Copyright (C) 2001-2002 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/

* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps; package org.apache.fop.apps;


/* /*




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;


import java.awt.Graphics;
import java.awt.print.*;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.Vector; import java.util.Vector;
import org.apache.fop.render.awt.AWTRenderer; import org.apache.fop.render.awt.AWTRenderer;


/** /**
* This class prints a xsl-fo dokument without interaction.
* This class prints a XSL-FO dokument without interaction.
* At the moment java has not the possibility to configure the printer and it's * At the moment java has not the possibility to configure the printer and it's
* options without interaction (30.03.2000). * options without interaction (30.03.2000).
* This class allows to print a set of pages (from-to), even/odd pages and many copies. * This class allows to print a set of pages (from-to), even/odd pages and many copies.
* - Print to page xxx: property name - end, value int * - Print to page xxx: property name - end, value int
* - Print even/odd pages: property name - even, value boolean * - Print even/odd pages: property name - even, value boolean
* - Print xxx copies: property name - copies, value int * - Print xxx copies: property name - copies, value int
*
*/ */
public class PrintStarter extends CommandLineStarter { public class PrintStarter extends CommandLineStarter {


/**
* @see org.apache.fop.apps.CommandLineStarter#CommandLineStarter(CommandLineOptions)
*/
public PrintStarter(CommandLineOptions options) throws FOPException { public PrintStarter(CommandLineOptions options) throws FOPException {
super(options); super(options);
} }


/**
* @see org.apache.fop.apps.Starter#run()
*/
public void run() throws FOPException { public void run() throws FOPException {
Driver driver = new Driver(); Driver driver = new Driver();


mode = EVEN_AND_ALL; mode = EVEN_AND_ALL;
String str = System.getProperty("even"); String str = System.getProperty("even");
if (str != null) { if (str != null) {
try {
mode = Boolean.valueOf(str).booleanValue() ? EVEN : ODD;
} catch (Exception e) {}

mode = Boolean.valueOf(str).booleanValue() ? EVEN : ODD;
} }


} }
printerJob.print(); printerJob.print();
} catch (PrinterException e) { } catch (PrinterException e) {
e.printStackTrace(); e.printStackTrace();
throw new IOException(
"Unable to print: " + e.getClass().getName() +
": " + e.getMessage());
throw new IOException("Unable to print: "
+ e.getClass().getName()
+ ": " + e.getMessage());
} }
} }



+ 69
- 13
src/org/apache/fop/apps/Starter.java Bestand weergeven

/* /*
* $Id$ * $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/

* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps; package org.apache.fop.apps;


// Avalon // Avalon
import org.xml.sax.XMLReader; import org.xml.sax.XMLReader;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;


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

/** /**
* abstract super class
* Abstract super class.
* Creates a SAX Parser (defaulting to Xerces). * Creates a SAX Parser (defaulting to Xerces).
*
*/ */
public abstract class Starter extends AbstractLogEnabled { public abstract class Starter extends AbstractLogEnabled {


InputHandler inputHandler;
/** InputHandler associated with this Starter */
protected InputHandler inputHandler;


/**
* Main constructor
* @throws FOPException In case of a problem constructing the Starter
*/
public Starter() throws FOPException { public Starter() throws FOPException {
} }


/**
* Sets the InputHandler to use.
* @param inputHandler input handler
*/
public void setInputHandler(InputHandler inputHandler) { public void setInputHandler(InputHandler inputHandler) {
this.inputHandler = inputHandler; this.inputHandler = inputHandler;
} }


/**
* Runs the current setup.
* @throws FOPException In case of a problem during the FOP run
*/
public abstract void run() throws FOPException; public abstract void run() throws FOPException;


// setting the parser features
/**
* Sets the parser features on an XMLReader
* @param parser XMLReader to set features on
* @throws FOPException if the XMLReader doesn't support the feature that
* need to be set
*/
public void setParserFeatures(XMLReader parser) throws FOPException { public void setParserFeatures(XMLReader parser) throws FOPException {
try { try {
parser.setFeature("http://xml.org/sax/features/namespace-prefixes", parser.setFeature("http://xml.org/sax/features/namespace-prefixes",

+ 83
- 12
src/org/apache/fop/apps/StructureHandler.java Bestand weergeven

/* /*
* $Id$ * $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/

* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps; package org.apache.fop.apps;


// Java // Java
import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.logger.AbstractLogEnabled;


// FOP // FOP
import org.apache.fop.fo.pagination.*;
import org.apache.fop.fo.flow.*;
import org.apache.fop.fo.*;
import org.apache.fop.fo.Title;
import org.apache.fop.fo.flow.Block;
import org.apache.fop.fo.flow.ExternalGraphic;
import org.apache.fop.fo.flow.Flow;
import org.apache.fop.fo.flow.InstreamForeignObject;
import org.apache.fop.fo.flow.Leader;
import org.apache.fop.fo.flow.ListBlock;
import org.apache.fop.fo.flow.ListItem;
import org.apache.fop.fo.flow.Table;
import org.apache.fop.fo.flow.TableBody;
import org.apache.fop.fo.flow.TableCell;
import org.apache.fop.fo.flow.TableRow;
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.xml.sax.SAXException; import org.xml.sax.SAXException;
*/ */
public class StructureHandler extends AbstractLogEnabled { public class StructureHandler extends AbstractLogEnabled {
/** /**
The current set of id's in the FO tree
This is used so we know if the FO tree contains duplicates
* The current set of id's in the FO tree.
* This is used so we know if the FO tree contains duplicates.
*/ */
private Set idReferences = new HashSet(); private Set idReferences = new HashSet();


/**
* Main constructor
*/
public StructureHandler() { public StructureHandler() {
} }


/**
* Retuns the set of ID references.
* @return the ID references
*/
public Set getIDReferences() { public Set getIDReferences() {
return idReferences; return idReferences;
} }


/**
* Returns the FontInfo object associated with this StructureHandler.
* @return the FontInof object
*/
public FontInfo getFontInfo() { public FontInfo getFontInfo() {
return null; return null;
} }


/**
* This method is called to indicate the start of a new document run.
* @throws SAXException In case of a problem
*/
public void startDocument() throws SAXException { public void startDocument() throws SAXException {

} }


/**
* This method is called to indicate the end of a document run.
* @throws SAXException In case of a problem
*/
public void endDocument() throws SAXException { public void endDocument() throws SAXException {

} }


public void startPageSequence(PageSequence pageSeq, Title seqTitle, LayoutMasterSet lms) { public void startPageSequence(PageSequence pageSeq, Title seqTitle, LayoutMasterSet lms) {

+ 71
- 27
src/org/apache/fop/apps/TraxInputHandler.java Bestand weergeven

/* /*
* $Id$ * $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/

* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps; package org.apache.fop.apps;


// Imported java.io classes
import java.io.File;


// Imported TraX classes // Imported TraX classes
import javax.xml.transform.TransformerFactory; import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXSource; import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.sax.SAXTransformerFactory; import javax.xml.transform.sax.SAXTransformerFactory;



// Imported SAX classes // Imported SAX classes
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader; import org.xml.sax.XMLReader;
import org.xml.sax.XMLFilter; import org.xml.sax.XMLFilter;




// Imported java.io classes
import java.io.InputStream;
import java.io.IOException;
import java.io.File;

/** /**
* XSLTInputHandler basically takes an xmlfile and transforms it with an xsltfile
* and the resulting xsl:fo document is input for Fop.
* XSLTInputHandler basically takes an XML file and transforms it with an
* XSLT file and the resulting XSL-FO document is input for FOP.
*/ */
public class TraxInputHandler extends InputHandler { public class TraxInputHandler extends InputHandler {


File xmlfile, xsltfile;
private File xmlfile, xsltfile;


/**
* Main constructor
* @param xmlfile XML file
* @param xsltfile XSLT file
*/
public TraxInputHandler(File xmlfile, File xsltfile) { public TraxInputHandler(File xmlfile, File xsltfile) {
this.xmlfile = xmlfile; this.xmlfile = xmlfile;
this.xsltfile = xsltfile; this.xsltfile = xsltfile;
} }


/** /**
* overwrites the method of the super class to return the xmlfile
* @see org.apache.fop.apps.InputHandler#getInputSource()
*/ */
public InputSource getInputSource() { public InputSource getInputSource() {
return fileInputSource(xmlfile); return fileInputSource(xmlfile);
} }


/** /**
* overwrites this method of the super class and returns an XMLFilter instead of a
* simple XMLReader which allows chaining of transformations
*
* Overwrites this method of the super class and returns an XMLFilter
* instead of a simple XMLReader which allows chaining of transformations.
* @see org.apache.fop.apps.InputHandler#getParser()
*/ */
public XMLReader getParser() throws FOPException { public XMLReader getParser() throws FOPException {
return this.getXMLFilter(xmlfile, xsltfile); return this.getXMLFilter(xmlfile, xsltfile);
* data is fed into Fop. This should help to avoid memory problems * data is fed into Fop. This should help to avoid memory problems
* @param xmlfile The xmlfile containing the text data * @param xmlfile The xmlfile containing the text data
* @param xsltfile An xslt stylesheet * @param xsltfile An xslt stylesheet
* @return XMLFilter an XMLFilter which can be chained together with other XMLReaders or XMLFilters
* @return an XMLFilter which can be chained together with other
* XMLReaders or XMLFilters
* @throws FOPException if setting up the XMLFilter fails
*/ */
public static XMLFilter getXMLFilter(File xmlfile, public static XMLFilter getXMLFilter(File xmlfile,
File xsltfile) throws FOPException { File xsltfile) throws FOPException {
xmlfilter.setParent(parser); xmlfilter.setParent(parser);
return xmlfilter; return xmlfilter;
} else { } else {
throw new FOPException("Your parser doesn't support the features SAXSource and SAXResult."
+ "\nMake sure you are using a xsl parser which supports TrAX");
throw new FOPException("Your parser doesn't support the "
+ "features SAXSource and SAXResult."
+ "\nMake sure you are using an XSLT engine which "
+ "supports TrAX");
} }
} catch (FOPException fe) {
throw fe;
} catch (Exception ex) { } catch (Exception ex) {
if (ex instanceof FOPException) {
throw (FOPException)ex;
}
throw new FOPException(ex); throw new FOPException(ex);
} }
} }

+ 50
- 7
src/org/apache/fop/apps/Version.java Bestand weergeven

/* /*
* $Id$ * $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources."
*/

* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps; package org.apache.fop.apps;


/** /**
* class representing the version of FOP.
* Class representing the version of FOP.
*/ */
public class Version { public class Version {


/** /**
* get the version of FOP
* Get the version of FOP
* *
* @return the version string * @return the version string
*/ */

+ 75
- 28
src/org/apache/fop/apps/XSLTInputHandler.java Bestand weergeven

/* /*
* $Id$ * $Id$
* Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
* For details on use and redistribution please refer to the
* LICENSE file included with these sources.
*/

* ============================================================================
* The Apache Software License, Version 1.1
* ============================================================================
*
* Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modifica-
* tion, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The end-user documentation included with the redistribution, if any, must
* include the following acknowledgment: "This product includes software
* developed by the Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself, if
* and wherever such third-party acknowledgments normally appear.
*
* 4. The names "FOP" and "Apache Software Foundation" must not be used to
* endorse or promote products derived from this software without prior
* written permission. For written permission, please contact
* apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache", nor may
* "Apache" appear in their name, without prior written permission of the
* Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
* DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* ============================================================================
*
* This software consists of voluntary contributions made by many individuals
* on behalf of the Apache Software Foundation and was originally created by
* James Tauber <jtauber@jtauber.com>. For more information on the Apache
* Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.fop.apps; package org.apache.fop.apps;


import java.lang.reflect.*;

// Imported java.io classes
import java.io.File;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;


// Imported SAX classes // Imported SAX classes
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader; import org.xml.sax.XMLReader;


// Imported java.io classes
import java.io.*;

// FOP // FOP
import org.apache.fop.tools.xslt.XSLTransform; import org.apache.fop.tools.xslt.XSLTransform;


/*
add url constructer
*/

/** /**
* XSLTInputHandler basically takes an xmlfile and transforms it with an xsltfile
* and the resulting xsl:fo document is input for Fop.
* XSLTInputHandler basically takes an XML file and transforms it with an XSLT
* file and the resulting XSL-FO document is input for FOP.
* @todo add URL constructor
*/ */
public class XSLTInputHandler extends InputHandler { public class XSLTInputHandler extends InputHandler {


File xmlfile, xsltfile;
boolean useOldTransform = false;
boolean gotParser = false;
private File xmlfile, xsltfile;
private boolean useOldTransform = false;
private boolean gotParser = false;


/**
* Main constructor
* @param xmlfile XML file
* @param xsltfile XSLT file
*/
public XSLTInputHandler(File xmlfile, File xsltfile) { public XSLTInputHandler(File xmlfile, File xsltfile) {
this.xmlfile = xmlfile; this.xmlfile = xmlfile;
this.xsltfile = xsltfile; this.xsltfile = xsltfile;
} }


/** /**
* overwrites the method of the super class to return the xmlfile
* @see org.apache.fop.apps.InputHandler#getInputSource()
*/ */
public InputSource getInputSource() { public InputSource getInputSource() {
if(!gotParser) {
throw new IllegalStateException("The method getParser() must be called and the parser used when using XSLTInputHandler");
if (!gotParser) {
throw new IllegalStateException("The method getParser() must be "
+ "called and the parser used when using XSLTInputHandler");
} }
if (useOldTransform) { if (useOldTransform) {
try { try {
// if xml file size is larger than 500 kb write the fo:file to disk // if xml file size is larger than 500 kb write the fo:file to disk
if ((xmlfile.length()) > 500000) { if ((xmlfile.length()) > 500000) {
tmpFile = new File(xmlfile.getName() + ".fo.tmp"); tmpFile = new File(xmlfile.getName() + ".fo.tmp");
writer = new FileWriter(tmpFile);
writer = new java.io.FileWriter(tmpFile);
} else { } else {
writer = new StringWriter();
writer = new java.io.StringWriter();
} }


XSLTransform.transform(xmlfile.getCanonicalPath(), XSLTransform.transform(xmlfile.getCanonicalPath(),
writer.close(); writer.close();


if (tmpFile != null) { if (tmpFile != null) {
reader = new FileReader(tmpFile);
reader = new java.io.FileReader(tmpFile);
} else { } else {
// create a input source containing the xsl:fo file which can be fed to Fop // create a input source containing the xsl:fo file which can be fed to Fop
reader = new StringReader(writer.toString());
reader = new java.io.StringReader(writer.toString());
} }
return new InputSource(reader); return new InputSource(reader);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
/**@todo do proper logging of exceptions */
return null; return null;
} }
} else { } else {
/** /**
* This looks to see if the Trax api is supported and uses that to * This looks to see if the Trax api is supported and uses that to
* get an XMLFilter. Otherwise, it falls back to using DOM documents * get an XMLFilter. Otherwise, it falls back to using DOM documents
*
* @return the created <code>XMLReader</code>
* @throws FOPException if getting the parser fails
* @see org.apache.fop.apps.InputHandler#getParser()
*/ */
public XMLReader getParser() throws FOPException { public XMLReader getParser() throws FOPException {
gotParser = true; gotParser = true;

Laden…
Annuleren
Opslaan