From cd98d9ad186f7b7ca03effb64b04a702a2c251ca Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Thu, 27 Feb 2003 10:13:07 +0000 Subject: [PATCH] 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 --- src/org/apache/fop/apps/AWTStarter.java | 53 ++++- .../apache/fop/apps/CommandLineOptions.java | 182 +++++++++++++----- .../apache/fop/apps/CommandLineStarter.java | 61 +++++- src/org/apache/fop/apps/Driver.java | 152 ++++++++++++--- src/org/apache/fop/apps/ErrorHandler.java | 14 -- src/org/apache/fop/apps/FOInputHandler.java | 76 ++++++-- src/org/apache/fop/apps/FOPException.java | 56 +++++- src/org/apache/fop/apps/Fop.java | 59 +++++- src/org/apache/fop/apps/InputHandler.java | 70 ++++++- src/org/apache/fop/apps/LayoutHandler.java | 95 ++++++--- src/org/apache/fop/apps/PrintStarter.java | 80 ++++++-- src/org/apache/fop/apps/Starter.java | 82 ++++++-- src/org/apache/fop/apps/StructureHandler.java | 95 +++++++-- src/org/apache/fop/apps/TraxInputHandler.java | 98 +++++++--- src/org/apache/fop/apps/Version.java | 57 +++++- src/org/apache/fop/apps/XSLTInputHandler.java | 103 +++++++--- 16 files changed, 1067 insertions(+), 266 deletions(-) delete mode 100644 src/org/apache/fop/apps/ErrorHandler.java diff --git a/src/org/apache/fop/apps/AWTStarter.java b/src/org/apache/fop/apps/AWTStarter.java index 4394c3c9e..e6d0609b8 100644 --- a/src/org/apache/fop/apps/AWTStarter.java +++ b/src/org/apache/fop/apps/AWTStarter.java @@ -1,10 +1,53 @@ /* * $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 . For more information on the Apache + * Software Foundation, please see . + */ package org.apache.fop.apps; //FOP diff --git a/src/org/apache/fop/apps/CommandLineOptions.java b/src/org/apache/fop/apps/CommandLineOptions.java index 33549034f..d71b5bf86 100644 --- a/src/org/apache/fop/apps/CommandLineOptions.java +++ b/src/org/apache/fop/apps/CommandLineOptions.java @@ -1,10 +1,53 @@ /* * $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 . For more information on the Apache + * Software Foundation, please see . + */ package org.apache.fop.apps; // java @@ -111,7 +154,8 @@ public class CommandLineOptions { /** * 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 */ private boolean parseOptions(String args[]) throws FOPException { @@ -127,7 +171,8 @@ public class CommandLineOptions { } else if (args[i].equals("-c")) { if ((i + 1 == args.length) || (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 { userConfigFile = new File(args[i + 1]); i++; @@ -155,7 +200,8 @@ public class CommandLineOptions { inputmode = XSLT_INPUT; if ((i + 1 == args.length) || (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 { xsltfile = new File(args[i + 1]); i++; @@ -164,7 +210,8 @@ public class CommandLineOptions { inputmode = XSLT_INPUT; if ((i + 1 == args.length) || (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 { xmlfile = new File(args[i + 1]); i++; @@ -238,7 +285,8 @@ public class CommandLineOptions { setOutputMode(SVG_OUTPUT); if ((i + 1 == args.length) || (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]); i++; } @@ -395,6 +443,7 @@ public class CommandLineOptions { /** * Get the starter for the process. * @return the starter. + * @throws FOPException In case of failure while getting the starter */ public Starter getStarter() throws FOPException { Starter starter = null; @@ -424,51 +473,96 @@ public class CommandLineOptions { return starter; } + /** + * Returns the input mode (type of input data, ex. NOT_SET or FO_INPUT) + * @return the input mode + */ public int getInputMode() { return inputmode; } + /** + * Returns the output mode (output format, ex. NOT_SET or PDF_OUTPUT) + * @return the output mode + */ public int getOutputMode() { return outputmode; } + /** + * Returns the XSL-FO file if set. + * @return the XSL-FO file, null if not set + */ public File getFOFile() { return fofile; } + /** + * Returns the input XML file if set. + * @return the input XML file, null if not set + */ public File getXMLFile() { return xmlfile; } + /** + * Returns the stylesheet to be used for transformation to XSL-FO. + * @return stylesheet + */ public File getXSLFile() { return xsltfile; } + /** + * Returns the output file + * @return the output file + */ public File getOutputFile() { return outfile; } + /** + * Returns the user configuration file to be used. + * @return the userconfig.xml file + */ public File getUserConfigFile() { return userConfigFile; } + /** + * Returns the default language + * @return the default language + */ public String getLanguage() { return language; } + /** + * Indicates if FOP should be silent. + * @return true if should be silent + */ public Boolean isQuiet() { return quiet; } + /** + * Indicates if FOP should dump its configuration during runtime. + * @return true if config dump is enabled + */ public Boolean dumpConfiguration() { return dumpConfiguration; } + /** + * Indicates whether the XML renderer should generate course area XML + * @return true if coarse area XML is desired + */ public Boolean isCoarseAreaXml() { return suppressLowLevelAreas; } /** + * Returns the input file. * @return either the fofile or the xmlfile */ public File getInputFile() { @@ -486,39 +580,41 @@ public class CommandLineOptions { * shows the commandline syntax including a summary of all available options and some examples */ public static void printUsage() { - System.err.println("\nUSAGE\nFop [options] [-fo|-xml] infile [-xsl file] [-awt|-pdf|-mif|-rtf|-pcl|-ps|-txt|-at|-print] \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] \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"); } /** diff --git a/src/org/apache/fop/apps/CommandLineStarter.java b/src/org/apache/fop/apps/CommandLineStarter.java index befa7010a..cdda837b3 100644 --- a/src/org/apache/fop/apps/CommandLineStarter.java +++ b/src/org/apache/fop/apps/CommandLineStarter.java @@ -1,10 +1,53 @@ /* * $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 . For more information on the Apache + * Software Foundation, please see . + */ package org.apache.fop.apps; // SAX @@ -22,10 +65,16 @@ import java.io.FileOutputStream; */ public class CommandLineStarter extends Starter { + /** the command-line options associated with this starter */ protected CommandLineOptions commandLineOptions; + /** + * Main constructor + * @param commandLineOptions command-line options to use + * @throws FOPException In case of failure + */ public CommandLineStarter(CommandLineOptions commandLineOptions) - throws FOPException { + throws FOPException { this.commandLineOptions = commandLineOptions; super.setInputHandler(commandLineOptions.getInputHandler()); } diff --git a/src/org/apache/fop/apps/Driver.java b/src/org/apache/fop/apps/Driver.java index fd980ed8a..c8522bc74 100644 --- a/src/org/apache/fop/apps/Driver.java +++ b/src/org/apache/fop/apps/Driver.java @@ -1,10 +1,53 @@ /* * $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 . For more information on the Apache + * Software Foundation, please see . + */ package org.apache.fop.apps; // FOP @@ -39,8 +82,9 @@ import java.io.InputStreamReader; import java.io.OutputStream; import java.io.Reader; 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. @@ -182,6 +226,11 @@ public class Driver implements LogEnabled { private Logger log = 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() { try { return javax.xml.parsers.SAXParserFactory.newInstance() @@ -194,18 +243,26 @@ public class Driver implements LogEnabled { } /** - * create a new Driver + * Main constructor for the Driver class. */ public Driver() { 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) { this(); this.source = source; this.stream = stream; } + /** + * Initializes the Driver object. + */ public void initialize() { stream = null; treeBuilder = new FOTreeBuilder(); @@ -213,6 +270,11 @@ public class Driver implements LogEnabled { 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) { userAgent = agent; } @@ -226,6 +288,14 @@ public class Driver implements LogEnabled { return userAgent; } + /** + * Provide the Driver instance with a logger. More information on Avalon + * logging can be found at the + * Avalon site. + * + * @param log the logger. Must not be null. + * @see org.apache.avalon.framework.logger.LogEnabled#enableLogging(Logger) + */ public void enableLogging(Logger log) { if (this.log == null) { this.log = log; @@ -235,6 +305,11 @@ public class Driver implements LogEnabled { } + /** + * Returns the logger for use by FOP. + * @return the logger + * @see #enableLogging(Logger) + */ protected Logger getLogger() { if (this.log == null) { this.log = new ConsoleLogger(ConsoleLogger.LEVEL_INFO); @@ -256,6 +331,10 @@ public class Driver implements LogEnabled { treeBuilder.reset(); } + /** + * Indicates whether FOP has already received input data. + * @return true, if input data was received + */ public boolean hasData() { return (treeBuilder.hasData()); } @@ -264,7 +343,6 @@ public class Driver implements LogEnabled { * Set the OutputStream to use to output the result of the Renderer * (if applicable) * @param stream the stream to output the result of rendering to - * */ public void setOutputStream(OutputStream stream) { this.stream = stream; @@ -298,14 +376,15 @@ public class Driver implements LogEnabled { addElementMapping("org.apache.fop.extensions.ExtensionElementMapping"); // add mappings from available services - Enumeration providers = + Iterator providers = Service.providers(org.apache.fop.fo.ElementMapping.class); if (providers != null) { - while (providers.hasMoreElements()) { - String str = (String)providers.nextElement(); + while (providers.hasNext()) { + String str = (String)providers.next(); try { addElementMapping(str); } catch (IllegalArgumentException e) { + getLogger().warn("Error while adding element mapping", e); } } @@ -373,12 +452,21 @@ public class Driver implements LogEnabled { this.renderer = renderer; } + /** + * Returns the currently active renderer. + * @return the renderer + */ public Renderer getRenderer() { 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(Renderer) */ @@ -395,7 +483,7 @@ public class Driver implements LogEnabled { * @see #setRenderer(int) */ public void setRenderer(String rendererClassName) - throws IllegalArgumentException { + throws IllegalArgumentException { try { renderer = (Renderer)Class.forName(rendererClassName).newInstance(); @@ -431,11 +519,11 @@ public class Driver implements LogEnabled { /** * 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. */ public void addElementMapping(String mappingClassName) - throws IllegalArgumentException { + throws IllegalArgumentException { try { ElementMapping mapping = (ElementMapping)Class.forName(mappingClassName).newInstance(); @@ -464,7 +552,7 @@ public class Driver implements LogEnabled { * @return a content handler for handling the SAX events. */ 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. if (rendererType == RENDER_MIF) { structHandler = new org.apache.fop.mif.MIFHandler(stream); @@ -472,7 +560,8 @@ public class Driver implements LogEnabled { structHandler = new org.apache.fop.rtf.renderer.RTFHandler(stream); } else { 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); } @@ -492,7 +581,7 @@ public class Driver implements LogEnabled { * @throws FOPException if anything goes wrong. */ public synchronized void render(XMLReader parser, InputSource source) - throws FOPException { + throws FOPException { parser.setContentHandler(getContentHandler()); try { parser.parse(source); @@ -514,7 +603,7 @@ public class Driver implements LogEnabled { * @throws FOPException if anything goes wrong. */ public synchronized void render(Document document) - throws FOPException { + throws FOPException { try { DocumentInputSource source = new DocumentInputSource(document); DocumentReader reader = new DocumentReader(); @@ -542,8 +631,7 @@ public class Driver implements LogEnabled { * @throws IOException in case of IO errors. * @throws FOPException if anything else goes wrong. */ - public synchronized void run() - throws IOException, FOPException { + public synchronized void run() throws IOException, FOPException { if (renderer == null) { setRenderer(RENDER_PDF); } @@ -583,9 +671,9 @@ public class Driver implements LogEnabled { */ 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(); // null if loaded by bootstrap class loader if (cl == null) { @@ -595,19 +683,19 @@ class Service { // 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; try { e = cl.getResources(serviceFile); } catch (IOException ioe) { - return v.elements(); + return lst.iterator(); } while (e.hasMoreElements()) { @@ -641,7 +729,7 @@ class Service { // Try and load the class // Object obj = cl.loadClass(line).newInstance(); // stick it into our vector... - v.add(line); + lst.add(line); } catch (Exception ex) { // Just try the next line } @@ -653,7 +741,7 @@ class Service { } } - return v.elements(); + return lst.iterator(); } } diff --git a/src/org/apache/fop/apps/ErrorHandler.java b/src/org/apache/fop/apps/ErrorHandler.java deleted file mode 100644 index b9428744a..000000000 --- a/src/org/apache/fop/apps/ErrorHandler.java +++ /dev/null @@ -1,14 +0,0 @@ -/* - * $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 { -} diff --git a/src/org/apache/fop/apps/FOInputHandler.java b/src/org/apache/fop/apps/FOInputHandler.java index 4af404ef8..403e96527 100644 --- a/src/org/apache/fop/apps/FOInputHandler.java +++ b/src/org/apache/fop/apps/FOInputHandler.java @@ -1,10 +1,53 @@ /* * $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 . For more information on the Apache + * Software Foundation, please see . + */ package org.apache.fop.apps; // Imported SAX classes @@ -16,31 +59,32 @@ import java.io.File; 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 { + private File fofile = null; private URL foURL = null; - /* + /** * 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; } - /* + /** * 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; } - /* - * Get the input source associated with this input handler. + /** + * @see org.apache.fop.apps.InputHandler#getInputSource() */ public InputSource getInputSource () { if (fofile != null) { @@ -49,8 +93,8 @@ public class FOInputHandler extends InputHandler { 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 { return super.createParser(); diff --git a/src/org/apache/fop/apps/FOPException.java b/src/org/apache/fop/apps/FOPException.java index 0a377d652..cb8c4ca9c 100644 --- a/src/org/apache/fop/apps/FOPException.java +++ b/src/org/apache/fop/apps/FOPException.java @@ -1,17 +1,59 @@ /* * $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 . For more information on the Apache + * Software Foundation, please see . + */ package org.apache.fop.apps; import org.xml.sax.SAXException; - /** - * Exception thrown when FOP has a problem + * Exception thrown when FOP has a problem. */ public class FOPException extends Exception { diff --git a/src/org/apache/fop/apps/Fop.java b/src/org/apache/fop/apps/Fop.java index 2342555f7..a09ef5957 100644 --- a/src/org/apache/fop/apps/Fop.java +++ b/src/org/apache/fop/apps/Fop.java @@ -1,18 +1,61 @@ /* * $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 . For more information on the Apache + * Software Foundation, please see . + */ package org.apache.fop.apps; -/* +/** * The main application class for the FOP command line interface (CLI). */ public class Fop { - /* + /** * The main routine for the command line interface * @param args the command line parameters */ @@ -24,7 +67,7 @@ public class Fop { Starter starter = options.getStarter(); starter.run(); } catch (FOPException e) { - if (e.getMessage()==null) { + if (e.getMessage() == null) { System.err.println("Exception occured with a null error message"); } else { System.err.println("" + e.getMessage()); diff --git a/src/org/apache/fop/apps/InputHandler.java b/src/org/apache/fop/apps/InputHandler.java index ff82b781a..75cd81705 100644 --- a/src/org/apache/fop/apps/InputHandler.java +++ b/src/org/apache/fop/apps/InputHandler.java @@ -1,10 +1,53 @@ /* * $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 . For more information on the Apache + * Software Foundation, please see . + */ package org.apache.fop.apps; // SAX @@ -18,16 +61,31 @@ import javax.xml.parsers.ParserConfigurationException; import java.net.URL; import java.io.File; -/* +/** * Abstract super class for input handlers. * Should be used to abstract the various possibilities on how input * can be provided to FOP (but actually isn't). */ public abstract class InputHandler { + /** + * Get the input source associated with this input handler. + * @return the input source + */ 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; + /** + * Creates an InputSource from a URL. + * @param url URL to use + * @return the newly created InputSource + */ public static InputSource urlInputSource(URL url) { return new InputSource(url.toString()); } diff --git a/src/org/apache/fop/apps/LayoutHandler.java b/src/org/apache/fop/apps/LayoutHandler.java index 3e5e67b00..35def53f6 100644 --- a/src/org/apache/fop/apps/LayoutHandler.java +++ b/src/org/apache/fop/apps/LayoutHandler.java @@ -1,10 +1,53 @@ /* * $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 . For more information on the Apache + * Software Foundation, please see . + */ package org.apache.fop.apps; // Java @@ -35,44 +78,44 @@ public class LayoutHandler extends StructureHandler { // TODO: Collecting of statistics should be configurable 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; /** - Keep track of the number of pages rendered. + * Keep track of the number of pages rendered. */ private int pageCount; /** - Keep track of heap memory allocated, - for statistical purposes. + * Keep track of heap memory allocated, + * for statistical purposes. */ private long initialMemory; /** - Keep track of time used by renderer. + * Keep track of time used by renderer. */ private long startTime; /** - The stream to which this rendering is to be - written to. Note 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. Note that some renderers + * do not render to a stream, and that this + * member can therefore be null. */ private OutputStream outputStream; /** - The renderer being used. + * The renderer being used. */ private Renderer renderer; /** - The FontInfo for this renderer. + * The FontInfo for this renderer. */ private FontInfo fontInfo = new FontInfo(); @@ -83,6 +126,7 @@ public class LayoutHandler extends StructureHandler { private AreaTreeModel atModel; /** + * Main constructor * @param outputStream the stream that the result is rendered to * @param renderer the renderer to call * @param store if true then use the store pages model and keep the @@ -90,8 +134,9 @@ public class LayoutHandler extends StructureHandler { */ public LayoutHandler(OutputStream outputStream, Renderer renderer, boolean store) { - if (collectStatistics) + if (collectStatistics) { runtime = Runtime.getRuntime(); + } this.outputStream = outputStream; this.renderer = renderer; @@ -123,14 +168,16 @@ public class LayoutHandler extends StructureHandler { if (MEM_PROFILE_WITH_GC) { System.gc(); // This takes time but gives better results } + initialMemory = runtime.totalMemory() - runtime.freeMemory(); startTime = System.currentTimeMillis(); } try { renderer.setupFontInfo(fontInfo); // 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); } catch (IOException e) { @@ -186,7 +233,9 @@ public class LayoutHandler extends StructureHandler { * @param seqTitle the title of the page sequence * @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; if (seqTitle != null) { title = seqTitle.getTitleArea(); @@ -203,7 +252,7 @@ public class LayoutHandler extends StructureHandler { * @throws FOPException if there is an error formatting the pages */ public void endPageSequence(PageSequence pageSequence) - throws FOPException { + throws FOPException { //areaTree.setFontInfo(fontInfo); if (collectStatistics) { @@ -245,7 +294,7 @@ public class LayoutHandler extends StructureHandler { count++; } List list = model.getEndExtensions(); - for(count = 0; count < list.size(); count++) { + for (count = 0; count < list.size(); count++) { TreeExt ext = (TreeExt)list.get(count); renderer.renderExtension(ext); } diff --git a/src/org/apache/fop/apps/PrintStarter.java b/src/org/apache/fop/apps/PrintStarter.java index 7af154127..8910aba2d 100644 --- a/src/org/apache/fop/apps/PrintStarter.java +++ b/src/org/apache/fop/apps/PrintStarter.java @@ -1,10 +1,53 @@ /* * $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 . For more information on the Apache + * Software Foundation, please see . + */ package org.apache.fop.apps; /* @@ -20,12 +63,9 @@ package org.apache.fop.apps; 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.IOException; import java.util.Vector; @@ -33,7 +73,7 @@ import java.util.Vector; 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 * options without interaction (30.03.2000). * This class allows to print a set of pages (from-to), even/odd pages and many copies. @@ -41,14 +81,19 @@ import org.apache.fop.render.awt.AWTRenderer; * - Print to page xxx: property name - end, value int * - Print even/odd pages: property name - even, value boolean * - Print xxx copies: property name - copies, value int - * */ public class PrintStarter extends CommandLineStarter { + /** + * @see org.apache.fop.apps.CommandLineStarter#CommandLineStarter(CommandLineOptions) + */ public PrintStarter(CommandLineOptions options) throws FOPException { super(options); } + /** + * @see org.apache.fop.apps.Starter#run() + */ public void run() throws FOPException { Driver driver = new Driver(); @@ -121,10 +166,7 @@ public class PrintStarter extends CommandLineStarter { mode = EVEN_AND_ALL; String str = System.getProperty("even"); if (str != null) { - try { - mode = Boolean.valueOf(str).booleanValue() ? EVEN : ODD; - } catch (Exception e) {} - + mode = Boolean.valueOf(str).booleanValue() ? EVEN : ODD; } } @@ -146,9 +188,9 @@ public class PrintStarter extends CommandLineStarter { printerJob.print(); } catch (PrinterException e) { e.printStackTrace(); - throw new IOException( - "Unable to print: " + e.getClass().getName() + - ": " + e.getMessage()); + throw new IOException("Unable to print: " + + e.getClass().getName() + + ": " + e.getMessage()); } } diff --git a/src/org/apache/fop/apps/Starter.java b/src/org/apache/fop/apps/Starter.java index 21d53d27b..f4a44ad6f 100644 --- a/src/org/apache/fop/apps/Starter.java +++ b/src/org/apache/fop/apps/Starter.java @@ -1,10 +1,53 @@ /* * $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 . For more information on the Apache + * Software Foundation, please see . + */ package org.apache.fop.apps; // Avalon @@ -14,29 +57,42 @@ import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.xml.sax.XMLReader; 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). - * */ 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 { } + /** + * Sets the InputHandler to use. + * @param inputHandler input handler + */ public void setInputHandler(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; - // 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 { try { parser.setFeature("http://xml.org/sax/features/namespace-prefixes", diff --git a/src/org/apache/fop/apps/StructureHandler.java b/src/org/apache/fop/apps/StructureHandler.java index 9ba7da70c..a173f13a5 100644 --- a/src/org/apache/fop/apps/StructureHandler.java +++ b/src/org/apache/fop/apps/StructureHandler.java @@ -1,10 +1,53 @@ /* * $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 . For more information on the Apache + * Software Foundation, please see . + */ package org.apache.fop.apps; // Java @@ -15,9 +58,20 @@ import java.util.HashSet; import org.apache.avalon.framework.logger.AbstractLogEnabled; // 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.xml.sax.SAXException; @@ -29,28 +83,45 @@ import org.xml.sax.SAXException; */ 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(); + /** + * Main constructor + */ public StructureHandler() { } + /** + * Retuns the set of ID references. + * @return the ID references + */ public Set getIDReferences() { return idReferences; } + /** + * Returns the FontInfo object associated with this StructureHandler. + * @return the FontInof object + */ public FontInfo getFontInfo() { 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 { - } + /** + * 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 startPageSequence(PageSequence pageSeq, Title seqTitle, LayoutMasterSet lms) { diff --git a/src/org/apache/fop/apps/TraxInputHandler.java b/src/org/apache/fop/apps/TraxInputHandler.java index 47d5ae008..93441d4d1 100644 --- a/src/org/apache/fop/apps/TraxInputHandler.java +++ b/src/org/apache/fop/apps/TraxInputHandler.java @@ -1,12 +1,57 @@ /* * $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 . For more information on the Apache + * Software Foundation, please see . + */ package org.apache.fop.apps; +// Imported java.io classes +import java.io.File; // Imported TraX classes import javax.xml.transform.TransformerFactory; @@ -15,44 +60,40 @@ import javax.xml.transform.sax.SAXResult; import javax.xml.transform.sax.SAXSource; import javax.xml.transform.sax.SAXTransformerFactory; - // Imported SAX classes import org.xml.sax.InputSource; -import org.xml.sax.SAXException; import org.xml.sax.XMLReader; 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 { - File xmlfile, xsltfile; + private File xmlfile, xsltfile; + /** + * Main constructor + * @param xmlfile XML file + * @param xsltfile XSLT file + */ public TraxInputHandler(File xmlfile, File xsltfile) { this.xmlfile = xmlfile; this.xsltfile = xsltfile; } /** - * overwrites the method of the super class to return the xmlfile + * @see org.apache.fop.apps.InputHandler#getInputSource() */ public InputSource getInputSource() { 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 { return this.getXMLFilter(xmlfile, xsltfile); @@ -65,7 +106,9 @@ public class TraxInputHandler extends InputHandler { * data is fed into Fop. This should help to avoid memory problems * @param xmlfile The xmlfile containing the text data * @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, File xsltfile) throws FOPException { @@ -93,13 +136,14 @@ public class TraxInputHandler extends InputHandler { xmlfilter.setParent(parser); return xmlfilter; } 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) { - if (ex instanceof FOPException) { - throw (FOPException)ex; - } throw new FOPException(ex); } } diff --git a/src/org/apache/fop/apps/Version.java b/src/org/apache/fop/apps/Version.java index 885012c9e..dd38a9b31 100644 --- a/src/org/apache/fop/apps/Version.java +++ b/src/org/apache/fop/apps/Version.java @@ -1,19 +1,62 @@ /* * $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 . For more information on the Apache + * Software Foundation, please see . + */ package org.apache.fop.apps; /** - * class representing the version of FOP. + * Class representing the version of FOP. */ public class Version { /** - * get the version of FOP + * Get the version of FOP * * @return the version string */ diff --git a/src/org/apache/fop/apps/XSLTInputHandler.java b/src/org/apache/fop/apps/XSLTInputHandler.java index cf24a3ea4..147075634 100644 --- a/src/org/apache/fop/apps/XSLTInputHandler.java +++ b/src/org/apache/fop/apps/XSLTInputHandler.java @@ -1,51 +1,95 @@ /* * $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 . For more information on the Apache + * Software Foundation, please see . + */ 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 import org.xml.sax.InputSource; -import org.xml.sax.SAXException; import org.xml.sax.XMLReader; -// Imported java.io classes -import java.io.*; - // FOP 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 { - 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) { this.xmlfile = xmlfile; this.xsltfile = xsltfile; } /** - * overwrites the method of the super class to return the xmlfile + * @see org.apache.fop.apps.InputHandler#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) { try { @@ -58,9 +102,9 @@ public class XSLTInputHandler extends InputHandler { // if xml file size is larger than 500 kb write the fo:file to disk if ((xmlfile.length()) > 500000) { tmpFile = new File(xmlfile.getName() + ".fo.tmp"); - writer = new FileWriter(tmpFile); + writer = new java.io.FileWriter(tmpFile); } else { - writer = new StringWriter(); + writer = new java.io.StringWriter(); } XSLTransform.transform(xmlfile.getCanonicalPath(), @@ -70,14 +114,15 @@ public class XSLTInputHandler extends InputHandler { writer.close(); if (tmpFile != null) { - reader = new FileReader(tmpFile); + reader = new java.io.FileReader(tmpFile); } else { // 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); } catch (Exception ex) { ex.printStackTrace(); + /**@todo do proper logging of exceptions */ return null; } } else { @@ -89,7 +134,9 @@ public class XSLTInputHandler extends InputHandler { /** * 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 - * + * @return the created XMLReader + * @throws FOPException if getting the parser fails + * @see org.apache.fop.apps.InputHandler#getParser() */ public XMLReader getParser() throws FOPException { gotParser = true; -- 2.39.5