diff options
Diffstat (limited to 'src')
17 files changed, 1015 insertions, 310 deletions
diff --git a/src/java/org/apache/fop/apps/AWTStarter.java b/src/java/org/apache/fop/apps/AWTStarter.java index 57515a6cb..3a93e44fb 100644 --- a/src/java/org/apache/fop/apps/AWTStarter.java +++ b/src/java/org/apache/fop/apps/AWTStarter.java @@ -3,34 +3,34 @@ * ============================================================================ * 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 @@ -42,12 +42,12 @@ * (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; //FOP @@ -76,7 +76,7 @@ import org.xml.sax.XMLReader; public class AWTStarter extends CommandLineStarter { private PreviewDialog frame; private Translator translator; - private Driver driver; + private Session session; private XMLReader parser; /** @@ -101,8 +101,8 @@ public class AWTStarter extends CommandLineStarter { AWTRenderer renderer = new AWTRenderer(translator); frame = createPreviewDialog(renderer, translator); renderer.setComponent(frame); - driver = new Driver(); - driver.setRenderer(renderer); + session = new Session(); + session.setRenderer(renderer); parser = inputHandler.getParser(); if (parser == null) { throw new FOPException("Unable to create SAX parser"); @@ -115,10 +115,10 @@ public class AWTStarter extends CommandLineStarter { * @throws FOPException FIXME should not happen. */ public void run() throws FOPException { - driver.reset(); + session.reset(); try { frame.setStatus(translator.getString("Status.Build.FO.tree")); - driver.render(parser, inputHandler.getInputSource()); + session.render(parser, inputHandler.getInputSource()); frame.setStatus(translator.getString("Status.Show")); frame.showPage(); } catch (Exception e) { diff --git a/src/java/org/apache/fop/apps/CommandLineOptions.java b/src/java/org/apache/fop/apps/CommandLineOptions.java index f72472d9f..026fc4e49 100644 --- a/src/java/org/apache/fop/apps/CommandLineOptions.java +++ b/src/java/org/apache/fop/apps/CommandLineOptions.java @@ -3,34 +3,34 @@ * ============================================================================ * 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 @@ -42,12 +42,12 @@ * (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; // java @@ -154,7 +154,7 @@ public class CommandLineOptions { /** * parses the commandline arguments - * @return true if parse was successful and processing can continue, false + * @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 */ @@ -392,26 +392,26 @@ public class CommandLineOptions { case NOT_SET: throw new FOPException("Renderer has not been set!"); case PDF_OUTPUT: - return Driver.RENDER_PDF; + return Session.RENDER_PDF; case AWT_OUTPUT: - return Driver.RENDER_AWT; + return Session.RENDER_AWT; case MIF_OUTPUT: - return Driver.RENDER_MIF; + return Session.RENDER_MIF; case PRINT_OUTPUT: - return Driver.RENDER_PRINT; + return Session.RENDER_PRINT; case PCL_OUTPUT: - return Driver.RENDER_PCL; + return Session.RENDER_PCL; case PS_OUTPUT: - return Driver.RENDER_PS; + return Session.RENDER_PS; case TXT_OUTPUT: - return Driver.RENDER_TXT; + return Session.RENDER_TXT; case SVG_OUTPUT: - return Driver.RENDER_SVG; + return Session.RENDER_SVG; case AREA_OUTPUT: rendererOptions.put("fineDetail", isCoarseAreaXml()); - return Driver.RENDER_XML; + return Session.RENDER_XML; case RTF_OUTPUT: - return Driver.RENDER_RTF; + return Session.RENDER_RTF; default: throw new FOPException("Invalid Renderer setting!"); } @@ -617,7 +617,7 @@ public class CommandLineOptions { + " Fop foo.fo -print or Fop -print foo.fo \n" + " Fop foo.fo -awt \n"); } - + /** * shows the options for print output */ diff --git a/src/java/org/apache/fop/apps/CommandLineStarter.java b/src/java/org/apache/fop/apps/CommandLineStarter.java index cdda837b3..0ed3838dd 100644 --- a/src/java/org/apache/fop/apps/CommandLineStarter.java +++ b/src/java/org/apache/fop/apps/CommandLineStarter.java @@ -3,34 +3,34 @@ * ============================================================================ * 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 @@ -42,12 +42,12 @@ * (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; // SAX @@ -91,21 +91,21 @@ public class CommandLineStarter extends Starter { XMLReader parser = inputHandler.getParser(); setParserFeatures(parser); - Driver driver = new Driver(); - setupLogger(driver); - driver.initialize(); + Session session = new Session(); + setupLogger(session); + session.initialize(); try { - driver.setRenderer(commandLineOptions.getRenderer()); + session.setRenderer(commandLineOptions.getRenderer()); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream( commandLineOptions.getOutputFile())); try { - driver.setOutputStream(bos); - if (driver.getRenderer() != null) { - driver.getRenderer().setOptions( + session.setOutputStream(bos); + if (session.getRenderer() != null) { + session.getRenderer().setOptions( commandLineOptions.getRendererOptions()); } - driver.render(parser, inputHandler.getInputSource()); + session.render(parser, inputHandler.getInputSource()); } finally { bos.close(); } diff --git a/src/java/org/apache/fop/apps/Driver.java b/src/java/org/apache/fop/apps/Driver.java index 7f97f0d97..915dd9280 100644 --- a/src/java/org/apache/fop/apps/Driver.java +++ b/src/java/org/apache/fop/apps/Driver.java @@ -3,34 +3,34 @@ * ============================================================================ * 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 @@ -42,12 +42,12 @@ * (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; // FOP @@ -133,6 +133,9 @@ import java.util.Map; * driver.setRenderer(new org.apache.fop.render.awt.AWTRenderer(translator)); * driver.render(parser, fileInputSource(args[0])); * </PRE> + * + * @deprecated This class is replaced by {@link Session}. See {@link + * CommandLineStarter#run for a usage example. */ public class Driver implements LogEnabled { @@ -296,8 +299,8 @@ public class Driver implements LogEnabled { } /** - * Provide the Driver instance with a logger. More information on Avalon - * logging can be found at the + * 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>. @@ -312,7 +315,7 @@ public class Driver implements LogEnabled { } /** - * Provide the Driver instance with a logger. + * Provide the Driver instance with a logger. * @param log the logger. Must not be <code>null</code>. * @deprecated Use #enableLogging(Logger) instead. */ @@ -399,7 +402,7 @@ public class Driver implements LogEnabled { // add mappings from available services Iterator providers = - Service.providers(org.apache.fop.fo.ElementMapping.class); + Session.providers(org.apache.fop.fo.ElementMapping.class); if (providers != null) { while (providers.hasNext()) { String str = (String)providers.next(); @@ -487,7 +490,7 @@ public class Driver implements LogEnabled { * @param rendererClassName the fully qualified classname of the renderer * class to use. * @param version version number - * @deprecated use renderer.setProducer(version) + setRenderer(renderer) or + * @deprecated use renderer.setProducer(version) + setRenderer(renderer) or * just setRenderer(rendererType) which will use the default producer string. * @see #setRenderer(int) * @see #setRenderer(Renderer) @@ -578,7 +581,7 @@ public class Driver implements LogEnabled { initialize(); } validateOutputStream(); - + // TODO: - do this stuff in a better way // PIJ: I guess the structure handler should be created by the renderer. if (rendererType == RENDER_MIF) { @@ -698,88 +701,3 @@ public class Driver implements LogEnabled { } } - -// code stolen from org.apache.batik.util and modified slightly -// does what sun.misc.Service probably does, but it cannot be relied on. -// hopefully will be part of standard jdk sometime. - -/** - * This class loads services present in the class path. - */ -class Service { - - private static Map providerMap = new java.util.Hashtable(); - - public static synchronized Iterator providers(Class cls) { - ClassLoader cl = cls.getClassLoader(); - // null if loaded by bootstrap class loader - if (cl == null) { - cl = ClassLoader.getSystemClassLoader(); - } - String serviceFile = "META-INF/services/" + cls.getName(); - - // getLogger().debug("File: " + serviceFile); - - List lst = (List)providerMap.get(serviceFile); - if (lst != null) { - return lst.iterator(); - } - - lst = new java.util.Vector(); - providerMap.put(serviceFile, lst); - - Enumeration e; - try { - e = cl.getResources(serviceFile); - } catch (IOException ioe) { - return lst.iterator(); - } - - while (e.hasMoreElements()) { - try { - java.net.URL u = (java.net.URL)e.nextElement(); - //getLogger().debug("URL: " + u); - - InputStream is = u.openStream(); - Reader r = new InputStreamReader(is, "UTF-8"); - BufferedReader br = new BufferedReader(r); - - String line = br.readLine(); - while (line != null) { - try { - // First strip any comment... - int idx = line.indexOf('#'); - if (idx != -1) { - line = line.substring(0, idx); - } - - // Trim whitespace. - line = line.trim(); - - // If nothing left then loop around... - if (line.length() == 0) { - line = br.readLine(); - continue; - } - // getLogger().debug("Line: " + line); - - // Try and load the class - // Object obj = cl.loadClass(line).newInstance(); - // stick it into our vector... - lst.add(line); - } catch (Exception ex) { - // Just try the next line - } - - line = br.readLine(); - } - } catch (Exception ex) { - // Just try the next file... - } - - } - return lst.iterator(); - } - -} - diff --git a/src/java/org/apache/fop/apps/FOInputHandler.java b/src/java/org/apache/fop/apps/FOInputHandler.java index 9f23c7dd5..e896a1986 100644 --- a/src/java/org/apache/fop/apps/FOInputHandler.java +++ b/src/java/org/apache/fop/apps/FOInputHandler.java @@ -3,34 +3,34 @@ * ============================================================================ * 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 @@ -42,12 +42,12 @@ * (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; // Imported SAX classes @@ -62,7 +62,7 @@ import java.net.URL; * Manages input if it is an XSL-FO file. */ public class FOInputHandler extends InputHandler { - + private File fofile = null; private URL foURL = null; @@ -82,7 +82,7 @@ public class FOInputHandler extends InputHandler { this.foURL = url; } - + /** * @see org.apache.fop.apps.InputHandler#getInputSource() */ @@ -101,9 +101,9 @@ public class FOInputHandler extends InputHandler { } /** - * @see org.apache.fop.apps.InputHandler#run(Driver) + * @see org.apache.fop.apps.InputHandler#run(Session) */ - public void run(Driver driver) throws FOPException { + public void run(Session session) throws FOPException { throw new FOPException("not implemented: FOInputHandler.run(Driver)"); } diff --git a/src/java/org/apache/fop/apps/InputHandler.java b/src/java/org/apache/fop/apps/InputHandler.java index 7f7fe40a0..06fec221a 100644 --- a/src/java/org/apache/fop/apps/InputHandler.java +++ b/src/java/org/apache/fop/apps/InputHandler.java @@ -3,34 +3,34 @@ * ============================================================================ * 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 @@ -42,12 +42,12 @@ * (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; // SAX @@ -129,13 +129,13 @@ public abstract class InputHandler { throw new FOPException("Coudn't create XMLReader", pce); } } - + /** - * Runs this InputHandler through the Driver. - * @param driver Driver instance to use + * Runs this InputHandler through the Session. + * @param session Session instance to use * @throws FOPException if processing this InputHandler fails */ - public abstract void run(Driver driver) throws FOPException; - + public abstract void run(Session session) throws FOPException; + } diff --git a/src/java/org/apache/fop/apps/PrintStarter.java b/src/java/org/apache/fop/apps/PrintStarter.java index f1c3660cd..8b9e177e4 100644 --- a/src/java/org/apache/fop/apps/PrintStarter.java +++ b/src/java/org/apache/fop/apps/PrintStarter.java @@ -3,34 +3,34 @@ * ============================================================================ * 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 @@ -42,12 +42,12 @@ * (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; /* @@ -95,7 +95,7 @@ public class PrintStarter extends CommandLineStarter { * @see org.apache.fop.apps.Starter#run() */ public void run() throws FOPException { - Driver driver = new Driver(); + Session session = new Session(); String version = Version.getVersion(); //log.debug(version); @@ -118,8 +118,8 @@ public class PrintStarter extends CommandLineStarter { //renderer.setCopies(copies); try { - driver.setRenderer(renderer); - driver.render(parser, inputHandler.getInputSource()); + session.setRenderer(renderer); + session.render(parser, inputHandler.getInputSource()); } catch (Exception e) { if (e instanceof FOPException) { throw (FOPException)e; @@ -188,7 +188,7 @@ public class PrintStarter extends CommandLineStarter { printerJob.print(); } catch (PrinterException e) { e.printStackTrace(); - throw new IOException("Unable to print: " + throw new IOException("Unable to print: " + e.getClass().getName() + ": " + e.getMessage()); } diff --git a/src/java/org/apache/fop/apps/Session.java b/src/java/org/apache/fop/apps/Session.java new file mode 100644 index 000000000..199626b37 --- /dev/null +++ b/src/java/org/apache/fop/apps/Session.java @@ -0,0 +1,787 @@ +/* + * $Id$ + * ============================================================================ + * 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; + +// FOP +import org.apache.fop.fo.ElementMapping; +import org.apache.fop.fo.FOTreeBuilder; +import org.apache.fop.fo.FOUserAgent; +import org.apache.fop.render.Renderer; +import org.apache.fop.tools.DocumentInputSource; +import org.apache.fop.tools.DocumentReader; + + +// Avalon +import org.apache.avalon.framework.logger.ConsoleLogger; +import org.apache.avalon.framework.logger.LogEnabled; +import org.apache.avalon.framework.logger.Logger; + +// DOM +import org.w3c.dom.Document; + +// SAX +import org.xml.sax.ContentHandler; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParserFactory; + +// Java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.Reader; +import java.util.Enumeration; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +/** + * Primary class that drives overall FOP process. + * <P> + * The simplest way to use this is to instantiate it with the + * InputSource and OutputStream, then set the renderer desired, and + * calling run(); + * <P> + * Here is an example use of Session which outputs PDF: + * + * <PRE> + * Session session = new Session(new InputSource (args[0]), + * new FileOutputStream(args[1])); + * session.enableLogging(myLogger); //optional + * session.setRenderer(RENDER_PDF); + * session.run(); + * </PRE> + * If neccessary, calling classes can call into the lower level + * methods to setup and + * render. Methods can be called to set the + * Renderer to use, the (possibly multiple) ElementMapping(s) to + * use and the OutputStream to use to output the results of the + * rendering (where applicable). In the case of the Renderer and + * ElementMapping(s), the Session may be supplied either with the + * object itself, or the name of the class, in which case Session will + * instantiate the class itself. The advantage of the latter is it + * enables runtime determination of Renderer and ElementMapping(s). + * <P> + * Once the Session is set up, the render method + * is called. Depending on whether DOM or SAX is being used, the + * invocation of the method is either render(Document) or + * buildFOTree(Parser, InputSource) respectively. + * <P> + * A third possibility may be used to build the FO Tree, namely + * calling getContentHandler() and firing the SAX events yourself. + * <P> + * Once the FO Tree is built, the format() and render() methods may be + * called in that order. + * <P> + * Here is an example use of Session which outputs to AWT: + * + * <PRE> + * Session session = new Session(); + * session.enableLogging(myLogger); //optional + * session.setRenderer(new org.apache.fop.render.awt.AWTRenderer(translator)); + * session.render(parser, fileInputSource(args[0])); + * </PRE> + */ +public class Session implements LogEnabled { + + /** + * Render to PDF. OutputStream must be set + */ + public static final int RENDER_PDF = 1; + + /** + * Render to a GUI window. No OutputStream neccessary + */ + public static final int RENDER_AWT = 2; + + /** + * Render to MIF. OutputStream must be set + */ + public static final int RENDER_MIF = 3; + + /** + * Render to XML. OutputStream must be set + */ + public static final int RENDER_XML = 4; + + /** + * Render to PRINT. No OutputStream neccessary + */ + public static final int RENDER_PRINT = 5; + + /** + * Render to PCL. OutputStream must be set + */ + public static final int RENDER_PCL = 6; + + /** + * Render to Postscript. OutputStream must be set + */ + public static final int RENDER_PS = 7; + + /** + * Render to Text. OutputStream must be set + */ + public static final int RENDER_TXT = 8; + + /** + * Render to SVG. OutputStream must be set + */ + public static final int RENDER_SVG = 9; + + /** + * Render to RTF. OutputStream must be set + */ + public static final int RENDER_RTF = 10; + + /** + * the FO tree builder + */ + private FOTreeBuilder treeBuilder; + + /** + * the renderer type code given by setRenderer + */ + private int rendererType; + + /** + * the renderer to use to output the area tree + */ + private Renderer renderer; + + /** + * the structure handler + */ + private StructureHandler structHandler; + + /** + * the source of the FO file + */ + private InputSource source; + + /** + * the stream to use to output the results of the renderer + */ + private OutputStream stream; + + /** + * The XML parser to use when building the FO tree + */ + private XMLReader reader; + + /** + * the system resources that FOP will use + */ + 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() + .newSAXParser().getXMLReader().getClass().getName(); + } catch (javax.xml.parsers.ParserConfigurationException e) { + return null; + } catch (org.xml.sax.SAXException e) { + return null; + } + } + + /** + * Main constructor for the Session class. + */ + public Session() { + 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 Session(InputSource source, OutputStream stream) { + this(); + this.source = source; + this.stream = stream; + } + + private boolean isInitialized() { + return (treeBuilder != null); + } + + /** + * Initializes the Session object. + */ + public void initialize() { + if (isInitialized()) { + throw new IllegalStateException("Session already initialized"); + } + treeBuilder = new FOTreeBuilder(); + treeBuilder.setUserAgent(getUserAgent()); + setupDefaultMappings(); + } + + /** + * Optionally sets the FOUserAgent instance for FOP to use. The Session + * 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; + } + + private FOUserAgent getUserAgent() { + if (userAgent == null) { + userAgent = new FOUserAgent(); + userAgent.enableLogging(getLogger()); + userAgent.setBaseURL(""); + } + return userAgent; + } + + /** + * Provide the Session 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) { + if (this.log == null) { + this.log = log; + } else { + getLogger().warn("Logger is already set! Won't use the new logger."); + } + } + + /** + * Provide the Session instance with a logger. + * @param log the logger. Must not be <code>null</code>. + * @deprecated Use #enableLogging(Logger) instead. + */ + public void setLogger(Logger log) { + enableLogging(log); + } + + + /** + * 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); + this.log.error("Logger not set. Using ConsoleLogger as default."); + } + + return this.log; + } + + /** + * Resets the Session so it can be reused. Property and element + * mappings are reset to defaults. + * The output stream is cleared. The renderer is cleared. + */ + public synchronized void reset() { + source = null; + stream = null; + reader = null; + treeBuilder.reset(); + } + + /** + * Indicates whether FOP has already received input data. + * @return true, if input data was received + */ + public boolean hasData() { + return (treeBuilder.hasData()); + } + + /** + * 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; + } + + private void validateOutputStream() { + if (this.stream == null) { + throw new IllegalStateException("OutputStream has not been set"); + } + } + + /** + * Set the source for the FO document. This can be a normal SAX + * InputSource, or an DocumentInputSource containing a DOM document. + * @see DocumentInputSource + */ + public void setInputSource(InputSource source) { + this.source = source; + } + + /** + * Sets the reader used when reading in the source. If not set, + * this defaults to a basic SAX parser. + * @param reader the reader to use. + */ + public void setXMLReader(XMLReader reader) { + this.reader = reader; + } + + /** + * Sets all the element and property list mappings to their default values. + * + */ + public void setupDefaultMappings() { + addElementMapping("org.apache.fop.fo.FOElementMapping"); + addElementMapping("org.apache.fop.svg.SVGElementMapping"); + addElementMapping("org.apache.fop.extensions.ExtensionElementMapping"); + + // add mappings from available services + Iterator providers = + providers(org.apache.fop.fo.ElementMapping.class); + if (providers != null) { + while (providers.hasNext()) { + String str = (String)providers.next(); + try { + addElementMapping(str); + } catch (IllegalArgumentException e) { + getLogger().warn("Error while adding element mapping", e); + } + + } + } + } + + /** + * Shortcut to set the rendering type to use. Must be one of + * <ul> + * <li>RENDER_PDF</li> + * <li>RENDER_AWT</li> + * <li>RENDER_MIF</li> + * <li>RENDER_XML</li> + * <li>RENDER_PCL</li> + * <li>RENDER_PS</li> + * <li>RENDER_TXT</li> + * <li>RENDER_SVG</li> + * <li>RENDER_RTF</li> + * </ul> + * @param renderer the type of renderer to use + * @throws IllegalArgumentException if an unsupported renderer type was required. + */ + public void setRenderer(int renderer) throws IllegalArgumentException { + rendererType = renderer; + switch (renderer) { + case RENDER_PDF: + setRenderer("org.apache.fop.render.pdf.PDFRenderer"); + break; + case RENDER_AWT: + throw new IllegalArgumentException("Use renderer form of setRenderer() for AWT"); + case RENDER_PRINT: + throw new IllegalArgumentException("Use renderer form of setRenderer() for PRINT"); + case RENDER_PCL: + setRenderer("org.apache.fop.render.pcl.PCLRenderer"); + break; + case RENDER_PS: + setRenderer("org.apache.fop.render.ps.PSRenderer"); + break; + case RENDER_TXT: + setRenderer("org.apache.fop.render.txt.TXTRenderer()"); + break; + case RENDER_MIF: + //structHandler will be set later + break; + case RENDER_XML: + setRenderer("org.apache.fop.render.xml.XMLRenderer"); + break; + case RENDER_SVG: + setRenderer("org.apache.fop.render.svg.SVGRenderer"); + break; + case RENDER_RTF: + //structHandler will be set later + break; + default: + throw new IllegalArgumentException("Unknown renderer type"); + } + } + + /** + * Set the Renderer to use. + * @param renderer the renderer instance to use (Note: Logger must be set at this point) + */ + public void setRenderer(Renderer renderer) { + renderer.setUserAgent(getUserAgent()); + this.renderer = renderer; + } + + /** + * Returns the currently active renderer. + * @return the renderer + */ + public Renderer getRenderer() { + return renderer; + } + + /** + * 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) + */ + public void setRenderer(String rendererClassName, String version) { + setRenderer(rendererClassName); + } + + /** + * Set the class name of the Renderer to use as well as the + * producer string for those renderers that can make use of it. + * @param rendererClassName classname of the renderer to use such as + * "org.apache.fop.render.pdf.PDFRenderer" + * @exception IllegalArgumentException if the classname was invalid. + * @see #setRenderer(int) + */ + public void setRenderer(String rendererClassName) + throws IllegalArgumentException { + try { + renderer = + (Renderer)Class.forName(rendererClassName).newInstance(); + if (renderer instanceof LogEnabled) { + ((LogEnabled)renderer).enableLogging(getLogger()); + } + renderer.setProducer(Version.getVersion()); + renderer.setUserAgent(getUserAgent()); + } catch (ClassNotFoundException e) { + throw new IllegalArgumentException("Could not find " + + rendererClassName); + } catch (InstantiationException e) { + throw new IllegalArgumentException("Could not instantiate " + + rendererClassName); + } catch (IllegalAccessException e) { + throw new IllegalArgumentException("Could not access " + + rendererClassName); + } catch (ClassCastException e) { + throw new IllegalArgumentException(rendererClassName + + " is not a renderer"); + } + } + + /** + * Add the given element mapping. + * An element mapping maps element names to Java classes. + * + * @param mapping the element mappingto add + */ + public void addElementMapping(ElementMapping mapping) { + mapping.addToBuilder(treeBuilder); + } + + /** + * Add the element mapping with the given class name. + * @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 { + try { + ElementMapping mapping = + (ElementMapping)Class.forName(mappingClassName).newInstance(); + addElementMapping(mapping); + } catch (ClassNotFoundException e) { + throw new IllegalArgumentException("Could not find " + + mappingClassName); + } catch (InstantiationException e) { + throw new IllegalArgumentException("Could not instantiate " + + mappingClassName); + } catch (IllegalAccessException e) { + throw new IllegalArgumentException("Could not access " + + mappingClassName); + } catch (ClassCastException e) { + throw new IllegalArgumentException(mappingClassName + + " is not an ElementMapping"); + } + } + + /** + * Returns the tree builder (a SAX ContentHandler). + * + * Used in situations where SAX is used but not via a FOP-invoked + * SAX parser. A good example is an XSLT engine that fires SAX + * events but isn't a SAX Parser itself. + * @return a content handler for handling the SAX events. + */ + public ContentHandler getContentHandler() { + if (!isInitialized()) { + initialize(); + } + validateOutputStream(); + + // 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); + } else if (rendererType == RENDER_RTF) { + structHandler = new org.apache.fop.rtf.renderer.RTFHandler(stream); + } else { + if (renderer == null) { + throw new IllegalStateException( + "Renderer not set when using standard structHandler"); + } + structHandler = new LayoutHandler(stream, renderer, true); + } + + structHandler.enableLogging(getLogger()); + + treeBuilder.setUserAgent(getUserAgent()); + treeBuilder.setStructHandler(structHandler); + + return treeBuilder; + } + + /** + * Render the FO document read by a SAX Parser from an InputSource. + * @param parser the SAX parser. + * @param source the input source the parser reads from. + * @throws FOPException if anything goes wrong. + */ + public synchronized void render(XMLReader parser, InputSource source) + throws FOPException { + if (!isInitialized()) { + initialize(); + } + parser.setContentHandler(getContentHandler()); + try { + parser.parse(source); + } catch (SAXException e) { + if (e.getException() instanceof FOPException) { + // Undo exception tunneling. + throw (FOPException)e.getException(); + } else { + throw new FOPException(e); + } + } catch (IOException e) { + throw new FOPException(e); + } + } + + /** + * Render the FO ducument represented by a DOM Document. + * @param document the DOM document to read from + * @throws FOPException if anything goes wrong. + */ + public synchronized void render(Document document) + throws FOPException { + if (!isInitialized()) { + initialize(); + } + try { + DocumentInputSource source = new DocumentInputSource(document); + DocumentReader reader = new DocumentReader(); + reader.setContentHandler(getContentHandler()); + reader.parse(source); + } catch (SAXException e) { + if (e.getException() instanceof FOPException) { + // Undo exception tunneling. + throw (FOPException)e.getException(); + } else { + throw new FOPException(e); + } + } catch (IOException e) { + throw new FOPException(e); + } + + } + + /** + * Runs the formatting and renderering process using the previously set + * parser, input source, renderer and output stream. + * If the renderer was not set, default to PDF. + * If no parser was set, and the input source is not a dom document, + * get a default SAX parser. + * @throws IOException in case of IO errors. + * @throws FOPException if anything else goes wrong. + */ + public synchronized void run() throws IOException, FOPException { + if (!isInitialized()) { + initialize(); + } + if (renderer == null) { + setRenderer(RENDER_PDF); + } + + if (source == null) { + throw new FOPException("InputSource is not set."); + } + + if (reader == null) { + if (!(source instanceof DocumentInputSource)) { + try { + SAXParserFactory spf = javax.xml.parsers.SAXParserFactory.newInstance(); + spf.setNamespaceAware(true); + reader = spf.newSAXParser().getXMLReader(); + } catch (SAXException e) { + throw new FOPException(e); + } catch (ParserConfigurationException e) { + throw new FOPException(e); + } + } + } + + if (source instanceof DocumentInputSource) { + render(((DocumentInputSource)source).getDocument()); + } else { + render(reader, source); + } + } + +/* Following code was stolen from org.apache.batik.util and modified slightly. + It does what sun.misc.Service probably does, but it cannot be relied on. + Hopefully, it will be part of standard jdk sometime. + This code was formerly part of a "Service" class, the contents of which have + been extracted here so that they can be used by both Session and the now- + deprecated Driver class. +*/ + + /** + * Map of services in the classpath + */ + private static Map providerMap = new java.util.Hashtable(); + + /** + * Loads services present in the class path. + */ + public static synchronized Iterator providers(Class cls) { + ClassLoader cl = cls.getClassLoader(); + // null if loaded by bootstrap class loader + if (cl == null) { + cl = ClassLoader.getSystemClassLoader(); + } + String serviceFile = "META-INF/services/" + cls.getName(); + + // getLogger().debug("File: " + serviceFile); + + List lst = (List)providerMap.get(serviceFile); + if (lst != null) { + return lst.iterator(); + } + + lst = new java.util.Vector(); + providerMap.put(serviceFile, lst); + + Enumeration e; + try { + e = cl.getResources(serviceFile); + } catch (IOException ioe) { + return lst.iterator(); + } + + while (e.hasMoreElements()) { + try { + java.net.URL u = (java.net.URL)e.nextElement(); + //getLogger().debug("URL: " + u); + + InputStream is = u.openStream(); + Reader r = new InputStreamReader(is, "UTF-8"); + BufferedReader br = new BufferedReader(r); + + String line = br.readLine(); + while (line != null) { + try { + // First strip any comment... + int idx = line.indexOf('#'); + if (idx != -1) { + line = line.substring(0, idx); + } + + // Trim whitespace. + line = line.trim(); + + // If nothing left then loop around... + if (line.length() == 0) { + line = br.readLine(); + continue; + } + // getLogger().debug("Line: " + line); + + // Try and load the class + // Object obj = cl.loadClass(line).newInstance(); + // stick it into our vector... + lst.add(line); + } catch (Exception ex) { + // Just try the next line + } + + line = br.readLine(); + } + } catch (Exception ex) { + // Just try the next file... + } + + } + return lst.iterator(); + } + +} diff --git a/src/java/org/apache/fop/apps/TraxInputHandler.java b/src/java/org/apache/fop/apps/TraxInputHandler.java index d5ae20240..84db9e129 100644 --- a/src/java/org/apache/fop/apps/TraxInputHandler.java +++ b/src/java/org/apache/fop/apps/TraxInputHandler.java @@ -3,34 +3,34 @@ * ============================================================================ * 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 @@ -42,12 +42,12 @@ * (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; // Imported java.io classes @@ -68,7 +68,7 @@ import org.xml.sax.XMLReader; import org.xml.sax.XMLFilter; /** - * XSLTInputHandler basically takes an XML file and transforms it with an + * 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 { @@ -79,7 +79,7 @@ public class TraxInputHandler extends InputHandler { /** * Constructor with files as input. - * @param xmlfile XML file + * @param xmlfile XML file * @param xsltfile XSLT file * @throws FOPException if initializing the Transformer fails */ @@ -107,7 +107,7 @@ public class TraxInputHandler extends InputHandler { * @param xsltSource XSLT InputSource * @throws FOPException if initializing the Transformer fails */ - public TraxInputHandler(InputSource xmlSource, InputSource xsltSource) + public TraxInputHandler(InputSource xmlSource, InputSource xsltSource) throws FOPException { this.xmlSource = new StreamSource(xmlSource.getByteStream(), xmlSource.getSystemId()); @@ -115,10 +115,10 @@ public class TraxInputHandler extends InputHandler { xsltSource.getSystemId()); initTransformer(); } - + private void initTransformer() throws FOPException { try { - this.transformer = + this.transformer = TransformerFactory.newInstance().newTransformer(xsltSource); } catch (Exception ex) { throw new FOPException(ex); @@ -136,7 +136,7 @@ public class TraxInputHandler extends InputHandler { } /** - * Overwrites this method of the super class and returns an XMLFilter + * 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() */ @@ -150,7 +150,7 @@ public class TraxInputHandler extends InputHandler { * during the conversion of the xml file + xslt stylesheet the resulting * data is fed into Fop. This should help to avoid memory problems * @param xsltSource An xslt stylesheet - * @return an XMLFilter which can be chained together with other + * @return an XMLFilter which can be chained together with other * XMLReaders or XMLFilters * @throws FOPException if setting up the XMLFilter fails */ @@ -192,12 +192,12 @@ public class TraxInputHandler extends InputHandler { } /** - * @see org.apache.fop.apps.InputHandler#run(Driver) + * @see org.apache.fop.apps.InputHandler#run(Session) */ - public void run(Driver driver) throws FOPException { + public void run(Session session) throws FOPException { try { transformer.transform(xmlSource, - new SAXResult(driver.getContentHandler())); + new SAXResult(session.getContentHandler())); } catch (Exception ex) { throw new FOPException(ex); } diff --git a/src/java/org/apache/fop/apps/XSLTInputHandler.java b/src/java/org/apache/fop/apps/XSLTInputHandler.java index 0770717e6..3876bfae5 100644 --- a/src/java/org/apache/fop/apps/XSLTInputHandler.java +++ b/src/java/org/apache/fop/apps/XSLTInputHandler.java @@ -115,10 +115,10 @@ public class XSLTInputHandler extends InputHandler { } /** - * @see org.apache.fop.apps.InputHandler#run(Driver) + * @see org.apache.fop.apps.InputHandler#run(Session) */ - public void run(Driver driver) throws FOPException { - traxInputHandler.run(driver); + public void run(Session session) throws FOPException { + traxInputHandler.run(session); } /** diff --git a/src/java/org/apache/fop/image/XMLImage.java b/src/java/org/apache/fop/image/XMLImage.java index a1a7b8b92..ddfdf799b 100644 --- a/src/java/org/apache/fop/image/XMLImage.java +++ b/src/java/org/apache/fop/image/XMLImage.java @@ -54,7 +54,7 @@ package org.apache.fop.image; import org.w3c.dom.Document; // FOP -import org.apache.fop.apps.Driver; +import org.apache.fop.apps.Session; /** * This is an implementation for XML-based images such as SVG. @@ -86,7 +86,7 @@ public class XMLImage extends AbstractFopImage { * @return the created SAX parser */ public static String getParserName() { - String parserClassName = Driver.getParserClassName(); + String parserClassName = Session.getParserClassName(); return parserClassName; } diff --git a/src/java/org/apache/fop/servlet/FopPrintServlet.java b/src/java/org/apache/fop/servlet/FopPrintServlet.java index c184eb184..14ab5f287 100644 --- a/src/java/org/apache/fop/servlet/FopPrintServlet.java +++ b/src/java/org/apache/fop/servlet/FopPrintServlet.java @@ -72,7 +72,7 @@ import org.apache.avalon.framework.logger.ConsoleLogger; import org.apache.avalon.framework.logger.Logger; // FOP -import org.apache.fop.apps.Driver; +import org.apache.fop.apps.Session; import org.apache.fop.apps.FOPException; import org.apache.fop.area.PageViewport; import org.apache.fop.apps.XSLTInputHandler; @@ -171,13 +171,13 @@ public class FopPrintServlet extends HttpServlet { public void renderFO(InputSource foFile, HttpServletResponse response) throws ServletException { try { - Driver driver = new Driver(foFile, null); + Session session = new Session(foFile, null); PrinterJob pj = PrinterJob.getPrinterJob(); PrintRenderer renderer = new PrintRenderer(pj); - driver.enableLogging(log); - driver.setRenderer(renderer); - driver.run(); + session.enableLogging(log); + session.setRenderer(renderer); + session.run(); reportOK (response); } catch (Exception ex) { @@ -194,15 +194,15 @@ public class FopPrintServlet extends HttpServlet { public void renderXML(XSLTInputHandler input, HttpServletResponse response) throws ServletException { try { - Driver driver = new Driver(); + Session session = new Session(); PrinterJob pj = PrinterJob.getPrinterJob(); PrintRenderer renderer = new PrintRenderer(pj); pj.setCopies(1); - driver.enableLogging(log); - driver.setRenderer(renderer); - driver.render(input.getParser(), input.getInputSource()); + session.enableLogging(log); + session.setRenderer(renderer); + session.render(input.getParser(), input.getInputSource()); reportOK (response); } catch (Exception ex) { diff --git a/src/java/org/apache/fop/servlet/FopServlet.java b/src/java/org/apache/fop/servlet/FopServlet.java index 59f3f8fda..8263e4084 100644 --- a/src/java/org/apache/fop/servlet/FopServlet.java +++ b/src/java/org/apache/fop/servlet/FopServlet.java @@ -71,7 +71,7 @@ import org.apache.avalon.framework.logger.ConsoleLogger; import org.apache.avalon.framework.logger.Logger; //FOP -import org.apache.fop.apps.Driver; +import org.apache.fop.apps.Session; import org.apache.fop.apps.FOPException; /** @@ -233,17 +233,17 @@ public class FopServlet extends HttpServlet { throws FOPException, TransformerException { //Setup FOP - Driver driver = new Driver(); - driver.enableLogging(this.log); - driver.setRenderer(Driver.RENDER_PDF); - driver.initialize(); + Session session = new Session(); + session.enableLogging(this.log); + session.setRenderer(Session.RENDER_PDF); + session.initialize(); //Setup output ByteArrayOutputStream out = new ByteArrayOutputStream(); - driver.setOutputStream(out); + session.setOutputStream(out); //Make sure the XSL transformation's result is piped through to FOP - Result res = new SAXResult(driver.getContentHandler()); + Result res = new SAXResult(session.getContentHandler()); //Start the transformation and rendering process transformer.transform(src, res); diff --git a/src/java/org/apache/fop/svg/SVGElementMapping.java b/src/java/org/apache/fop/svg/SVGElementMapping.java index dd6296cd5..bf8c0309b 100644 --- a/src/java/org/apache/fop/svg/SVGElementMapping.java +++ b/src/java/org/apache/fop/svg/SVGElementMapping.java @@ -3,34 +3,34 @@ * ============================================================================ * 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 @@ -42,12 +42,12 @@ * (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.svg; import java.util.HashMap; @@ -55,7 +55,7 @@ import java.util.HashMap; import org.apache.fop.fo.FONode; import org.apache.fop.fo.FOTreeBuilder; import org.apache.fop.fo.ElementMapping; -import org.apache.fop.apps.Driver; +import org.apache.fop.apps.Session; import org.apache.batik.util.XMLResourceDescriptor; import org.apache.batik.dom.svg.SVGDOMImplementation; @@ -75,7 +75,7 @@ public class SVGElementMapping implements ElementMapping { // by default (SVGBrokenLinkProvider) // normally the user agent value is used XMLResourceDescriptor.setXMLParserClassName( - Driver.getParserClassName()); + Session.getParserClassName()); foObjs = new HashMap(); foObjs.put("svg", new SE()); diff --git a/src/java/org/apache/fop/svg/SVGUserAgent.java b/src/java/org/apache/fop/svg/SVGUserAgent.java index 6a63ee4d1..ec6a75166 100644 --- a/src/java/org/apache/fop/svg/SVGUserAgent.java +++ b/src/java/org/apache/fop/svg/SVGUserAgent.java @@ -3,34 +3,34 @@ * ============================================================================ * 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 @@ -42,12 +42,12 @@ * (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.svg; import org.apache.fop.fo.FOUserAgent; @@ -158,7 +158,7 @@ public class SVGUserAgent extends UserAgentAdapter { * @return the XML parser class name */ public String getXMLParserClassName() { - return org.apache.fop.apps.Driver.getParserClassName(); + return org.apache.fop.apps.Session.getParserClassName(); } /** diff --git a/src/java/org/apache/fop/tools/TestConverter.java b/src/java/org/apache/fop/tools/TestConverter.java index 1f8449043..c4fd4f6da 100644 --- a/src/java/org/apache/fop/tools/TestConverter.java +++ b/src/java/org/apache/fop/tools/TestConverter.java @@ -3,34 +3,34 @@ * ============================================================================ * 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 @@ -42,15 +42,15 @@ * (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.tools; -import org.apache.fop.apps.Driver; +import org.apache.fop.apps.Session; import org.apache.fop.apps.FOInputHandler; import org.apache.fop.apps.FOPException; import org.apache.fop.apps.InputHandler; @@ -84,10 +84,10 @@ import org.xml.sax.SAXException; * pdf rendering. * * Modified by Mark Lillywhite mark-fop@inomial.com to use the new Driver - * interface. + * (now Session) interface. */ public class TestConverter extends AbstractLogEnabled { - + private boolean failOnly = false; private boolean outputPDF = false; private File destdir; @@ -141,7 +141,7 @@ public class TestConverter extends AbstractLogEnabled { } /** - * Controls whether to process only the tests which are specified as fail + * Controls whether to process only the tests which are specified as fail * in the test results. * @param fail True if only fail tests should be processed */ @@ -266,7 +266,7 @@ public class TestConverter extends AbstractLogEnabled { if (xslNode != null) { xsl = xslNode.getNodeValue(); } - getLogger().debug("converting xml:" + xml + " and xsl:" + getLogger().debug("converting xml:" + xml + " and xsl:" + xsl + " to area tree"); try { @@ -290,33 +290,33 @@ public class TestConverter extends AbstractLogEnabled { XMLReader parser = inputHandler.getParser(); setParserFeatures(parser); - Driver driver = new Driver(); - setupLogger(driver, "fop"); - driver.initialize(); + Session session = new Session(); + setupLogger(session, "fop"); + session.initialize(); FOUserAgent userAgent = new FOUserAgent(); userAgent.setBaseURL(baseURL); - driver.setUserAgent(userAgent); + session.setUserAgent(userAgent); if (outputPDF) { - driver.setRenderer(Driver.RENDER_PDF); + session.setRenderer(Session.RENDER_PDF); } else { - driver.setRenderer(Driver.RENDER_XML); + session.setRenderer(Session.RENDER_XML); } Map rendererOptions = new java.util.HashMap(); rendererOptions.put("fineDetail", new Boolean(false)); rendererOptions.put("consistentOutput", new Boolean(true)); - driver.getRenderer().setOptions(rendererOptions); - driver.getRenderer().setProducer("Testsuite Converter"); + session.getRenderer().setOptions(rendererOptions); + session.getRenderer().setProducer("Testsuite Converter"); String outname = xmlFile.getName(); if (outname.endsWith(".xml")) { outname = outname.substring(0, outname.length() - 4); } - driver.setOutputStream(new java.io.BufferedOutputStream( + session.setOutputStream(new java.io.BufferedOutputStream( new java.io.FileOutputStream(new File(destdir, outname + (outputPDF ? ".pdf" : ".at.xml"))))); getLogger().debug("ddir:" + destdir + " on:" + outname + ".pdf"); - driver.render(parser, inputHandler.getInputSource()); + session.render(parser, inputHandler.getInputSource()); // check difference if (compare != null) { diff --git a/src/java/org/apache/fop/tools/anttasks/Fop.java b/src/java/org/apache/fop/tools/anttasks/Fop.java index a4104de92..5fcb89222 100644 --- a/src/java/org/apache/fop/tools/anttasks/Fop.java +++ b/src/java/org/apache/fop/tools/anttasks/Fop.java @@ -72,7 +72,7 @@ import java.util.List; import org.apache.fop.apps.Starter; import org.apache.fop.apps.InputHandler; import org.apache.fop.apps.FOInputHandler; -import org.apache.fop.apps.Driver; +import org.apache.fop.apps.Session; import org.apache.fop.apps.FOPException; import org.apache.fop.fo.FOUserAgent; @@ -307,27 +307,27 @@ class FOPTaskStarter extends Starter { if ((format == null) || format.equalsIgnoreCase("application/pdf") || format.equalsIgnoreCase("pdf")) { - return Driver.RENDER_PDF; + return Session.RENDER_PDF; } else if (format.equalsIgnoreCase("application/postscript") || format.equalsIgnoreCase("ps")) { - return Driver.RENDER_PS; + return Session.RENDER_PS; } else if (format.equalsIgnoreCase("application/vnd.mif") || format.equalsIgnoreCase("mif")) { - return Driver.RENDER_MIF; + return Session.RENDER_MIF; } else if (format.equalsIgnoreCase("application/msword") || format.equalsIgnoreCase("application/rtf") || format.equalsIgnoreCase("rtf")) { - return Driver.RENDER_RTF; + return Session.RENDER_RTF; } else if (format.equalsIgnoreCase("application/vnd.hp-PCL") || format.equalsIgnoreCase("pcl")) { - return Driver.RENDER_PCL; + return Session.RENDER_PCL; } else if (format.equalsIgnoreCase("text/plain") || format.equalsIgnoreCase("txt")) { - return Driver.RENDER_TXT; + return Session.RENDER_TXT; } else if (format.equalsIgnoreCase("text/xml") || format.equalsIgnoreCase("at") || format.equalsIgnoreCase("xml")) { - return Driver.RENDER_XML; + return Session.RENDER_XML; } else { String err = "Couldn't determine renderer to use: " + format; throw new BuildException(err); @@ -336,19 +336,19 @@ class FOPTaskStarter extends Starter { private String determineExtension(int renderer) { switch (renderer) { - case Driver.RENDER_PDF: + case Session.RENDER_PDF: return ".pdf"; - case Driver.RENDER_PS: + case Session.RENDER_PS: return ".ps"; - case Driver.RENDER_MIF: + case Session.RENDER_MIF: return ".mif"; - case Driver.RENDER_RTF: + case Session.RENDER_RTF: return ".rtf"; - case Driver.RENDER_PCL: + case Session.RENDER_PCL: return ".pcl"; - case Driver.RENDER_TXT: + case Session.RENDER_TXT: return ".txt"; - case Driver.RENDER_XML: + case Session.RENDER_XML: return ".xml"; default: String err = "Unknown renderer: " + renderer; @@ -478,16 +478,16 @@ class FOPTaskStarter extends Starter { } try { - Driver driver = new Driver(); - setupLogger(driver); - driver.initialize(); + Session session = new Session(); + setupLogger(session); + session.initialize(); FOUserAgent userAgent = new FOUserAgent(); userAgent.setBaseURL(this.baseURL); userAgent.enableLogging(getLogger()); - driver.setUserAgent(userAgent); - driver.setRenderer(renderer); - driver.setOutputStream(out); - driver.render(parser, inputHandler.getInputSource()); + session.setUserAgent(userAgent); + session.setRenderer(renderer); + session.setOutputStream(out); + session.render(parser, inputHandler.getInputSource()); } catch (Exception ex) { throw new BuildException(ex); } finally { |