pbwest      2003/07/05 12:04:51

  Added:       src/java/org/apache/fop/apps Tag: FOP_0-20-0_Alt-Design
                        Fop.java FOPException.java CommandLineStarter.java
                        package.html InputHandler.java ErrorHandler.java
                        Options.java FOInputHandler.java Driver.java
  Log:
  Moved from src to src/java.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.1   +81 -45    xml-fop/src/java/org/apache/fop/apps/Fop.java
  
  Index: Fop.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/Fop.java,v
  retrieving revision 1.1
  retrieving revision 1.1.2.1
  diff -u -r1.1 -r1.1.2.1
  --- Fop.java  11 Mar 2003 13:05:28 -0000      1.1
  +++ Fop.java  5 Jul 2003 19:04:50 -0000       1.1.2.1
  @@ -1,7 +1,8 @@
   /*
    * $Id$
  + * 
    * ============================================================================
  - *                    The Apache Software License, Version 1.1
  + *                   The Apache Software License, Version 1.1
    * ============================================================================
    * 
    * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  @@ -9,7 +10,7 @@
    * 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,
  + * 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,
  @@ -17,72 +18,107 @@
    *    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
  + *    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
  + * 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
    *    [EMAIL PROTECTED]
    * 
  - * 5. Products derived from this software may not be called "Apache", nor may
  - *    "Apache" appear in their name, without prior written permission of the
  + * 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
  + * 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 <[EMAIL PROTECTED]>. For more information on the Apache
  + * This software  consists of voluntary contributions made  by many individuals
  + * on  behalf of the Apache Software  Foundation and was  originally created by
  + * James Tauber <[EMAIL PROTECTED]>. For more  information on the Apache 
    * Software Foundation, please see <http://www.apache.org/>.
  - */ 
  + *  
  + */
  +
   package org.apache.fop.apps;
   
  -/**
  - * The main application class for the FOP command line interface (CLI).
  - */
  +import org.apache.fop.messaging.MessageHandler;
  +
   public class Fop {
   
  -    /**
  -     * The main routine for the command line interface
  -     * @param args the command line parameters
  -     */
  +    public static Runtime runtime;
  +    public static long startTotal;
  +    public static long startFree;
  +    public static long startTime;
  +    public static long startPCi;
  +    public static long endPCi;
  +
       public static void main(String[] args) {
  -        CommandLineOptions options = null;
  +
  +     long endtotal, endfree, gctotal, gcfree;
  +        Driver driver;
  +        Boolean bool = null;
  +
  +     runtime = Runtime.getRuntime();
  +     startTotal = runtime.totalMemory();
  +     startFree = runtime.freeMemory();
  +     startTime = System.currentTimeMillis();
   
           try {
  -            options = new CommandLineOptions(args);
  -            Starter starter = options.getStarter();
  -            starter.run();
  +            Options.configure(args);
  +            driver = new Driver();
  +            driver.run();
  +            System.out.println("Back from driver.run()");
  +         System.out.println("Elapsed time: " +
  +                             (System.currentTimeMillis() - startTime));
  +         endtotal = runtime.totalMemory();
  +         endfree = runtime.freeMemory();
  +         System.gc();
  +         gctotal = runtime.totalMemory();
  +         gcfree = runtime.freeMemory();
  +         System.out.println("Total memory before run : " + startTotal);
  +         System.out.println("Total memory after run  : " + endtotal);
  +         System.out.println("Total memory after GC   : " + gctotal);
  +         System.out.println("Diff before/after total : "
  +                                                   + (endtotal - startTotal));
  +         System.out.println("Diff before/GC total    : "
  +                                                   + (gctotal - startTotal));
  +         System.out.println("Diff after/GC total     : "
  +                                                   + (gctotal - endtotal));
  +         System.out.println("Free memory before run  : " + startFree);
  +         System.out.println("Free memory after run   : " + endfree);
  +         System.out.println("Free memory after GC    : " + gcfree);
  +         System.out.println("Diff before/after free  : "
  +                                                   + (endfree - startFree));
  +         System.out.println("Diff before/GC free     : "
  +                                                   + (gcfree - startFree));
  +         System.out.println("Diff after/GC free      : "
  +                                                   + (gcfree - endfree));
  +         System.out.println("cg() freed              : "
  +                                                    + (gcfree - endfree));
  +         //System.out.println("PC time     : " + (endPCi - startPCi));
  +            
           } catch (FOPException e) {
  -            if (e.getMessage() == null) {
  -                System.err.println("Exception occured with a null error message");
  -            } else {
  -                System.err.println("" + e.getMessage());
  -            }
  -            if (options != null && options.getLogger().isDebugEnabled()) {
  +            MessageHandler.errorln("ERROR: " + e.getMessage());
  +            if ((bool = Options.isDebugMode()) != null
  +                    && bool.booleanValue()) {
                   e.printStackTrace();
  -            } else {
  -                System.err.println("Turn on debugging for more information");
               }
           } catch (java.io.FileNotFoundException e) {
  -            System.err.println("" + e.getMessage());
  -            if (options != null && options.getLogger().isDebugEnabled()) {
  +            MessageHandler.errorln("ERROR: " + e.getMessage());
  +            if ((bool = Options.isDebugMode()) != null
  +                    && bool.booleanValue()) {
                   e.printStackTrace();
  -            } else {
  -                System.err.println("Turn on debugging for more information");
               }
           }
       }
  
  
  
  1.2.2.1   +50 -72    xml-fop/src/java/org/apache/fop/apps/FOPException.java
  
  Index: FOPException.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/FOPException.java,v
  retrieving revision 1.2
  retrieving revision 1.2.2.1
  diff -u -r1.2 -r1.2.2.1
  --- FOPException.java 5 Jul 2003 09:28:34 -0000       1.2
  +++ FOPException.java 5 Jul 2003 19:04:50 -0000       1.2.2.1
  @@ -1,65 +1,70 @@
   /*
    * $Id$
  + * 
    * ============================================================================
  - *                    The Apache Software License, Version 1.1
  + *                   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,
  + * 
  + * 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
  + *    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
  + * 
  + * 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
    *    [EMAIL PROTECTED]
  - *
  - * 5. Products derived from this software may not be called "Apache", nor may
  - *    "Apache" appear in their name, without prior written permission of the
  + * 
  + * 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
  + * 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 <[EMAIL PROTECTED]>. For more information on the Apache
  + * 
  + * This software  consists of voluntary contributions made  by many individuals
  + * on  behalf of the Apache Software  Foundation and was  originally created by
  + * James Tauber <[EMAIL PROTECTED]>. For more  information on the Apache 
    * Software Foundation, please see <http://www.apache.org/>.
  + *  
    */
  +
   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 {
  +    private static final String tag = "$Name$";
  +    private static final String revision = "$Revision$";
   
       private static final String EXCEPTION_SEPARATOR = "\n---------\n";
   
  -    private Throwable exception;
  +    private Throwable _exception;
   
       /**
        * create a new FOP Exception
  @@ -70,43 +75,26 @@
           super(message);
       }
   
  -    /**
  -     *
  -     * @param e Throwable object
  -     */
       public FOPException(Throwable e) {
           super(e.getMessage());
           setException(e);
       }
   
  -    /**
  -     *
  -     * @param message descriptive message
  -     * @param e Throwable object
  -     */
       public FOPException(String message, Throwable e) {
           super(message);
           setException(e);
       }
   
  -    /**
  -     * Sets exception
  -     * @param t Throwable object
  -     */
       protected void setException(Throwable t) {
  -        exception = t;
  +        _exception = t;
       }
   
  -    /**
  -     * Accessor for exception
  -     * @return exception
  -     */
       public Throwable getException() {
  -        return exception;
  +        return _exception;
       }
   
       protected Throwable getRootException() {
  -        Throwable result = exception;
  +        Throwable result = _exception;
   
           if (result instanceof SAXException) {
               result = ((SAXException)result).getException();
  @@ -115,21 +103,19 @@
               result =
                   
((java.lang.reflect.InvocationTargetException)result).getTargetException();
           }
  -        if (result != exception) {
  +        if (result != _exception) {
               return result;
           }
           return null;
       }
   
  -    /**
  -     * Write stack trace to stderr
  -     */
  +
       public void printStackTrace() {
           synchronized (System.err) {
               super.printStackTrace();
  -            if (exception != null) {
  +            if (_exception != null) {
                   System.err.println(EXCEPTION_SEPARATOR);
  -                exception.printStackTrace();
  +                _exception.printStackTrace();
               }
               if (getRootException() != null) {
                   System.err.println(EXCEPTION_SEPARATOR);
  @@ -138,37 +124,29 @@
           }
       }
   
  -    /**
  -     * write stack trace on a PrintStream
  -     * @param stream PrintStream on which to write stack trace
  -     */
       public void printStackTrace(java.io.PrintStream stream) {
           synchronized (stream) {
               super.printStackTrace(stream);
  -            if (exception != null) {
  +            if (_exception != null) {
                   stream.println(EXCEPTION_SEPARATOR);
  -                exception.printStackTrace(stream);
  +                _exception.printStackTrace(stream);
               }
               if (getRootException() != null) {
  -                stream.println(EXCEPTION_SEPARATOR);
  +                System.err.println(EXCEPTION_SEPARATOR);
                   getRootException().printStackTrace(stream);
               }
           }
       }
   
  -    /**
  -     * Write stack trace on a PrintWriter
  -     * @param writer PrintWriter on which to write stack trace
  -     */
       public void printStackTrace(java.io.PrintWriter writer) {
           synchronized (writer) {
               super.printStackTrace(writer);
  -            if (exception != null) {
  +            if (_exception != null) {
                   writer.println(EXCEPTION_SEPARATOR);
  -                exception.printStackTrace(writer);
  +                _exception.printStackTrace(writer);
               }
               if (getRootException() != null) {
  -                writer.println(EXCEPTION_SEPARATOR);
  +                System.err.println(EXCEPTION_SEPARATOR);
                   getRootException().printStackTrace(writer);
               }
           }
  
  
  
  1.3.2.1   +25 -86    xml-fop/src/java/org/apache/fop/apps/CommandLineStarter.java
  
  Index: CommandLineStarter.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/CommandLineStarter.java,v
  retrieving revision 1.3
  retrieving revision 1.3.2.1
  diff -u -r1.3 -r1.3.2.1
  --- CommandLineStarter.java   17 Jun 2003 16:35:57 -0000      1.3
  +++ CommandLineStarter.java   5 Jul 2003 19:04:50 -0000       1.3.2.1
  @@ -1,7 +1,8 @@
   /*
    * $Id$
  + * 
    * ============================================================================
  - *                    The Apache Software License, Version 1.1
  + *                   The Apache Software License, Version 1.1
    * ============================================================================
    * 
    * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  @@ -9,7 +10,7 @@
    * 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,
  + * 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,
  @@ -17,105 +18,43 @@
    *    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
  + *    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
  + * 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
    *    [EMAIL PROTECTED]
    * 
  - * 5. Products derived from this software may not be called "Apache", nor may
  - *    "Apache" appear in their name, without prior written permission of the
  + * 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
  + * 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 <[EMAIL PROTECTED]>. For more information on the Apache
  + * This software  consists of voluntary contributions made  by many individuals
  + * on  behalf of the Apache Software  Foundation and was  originally created by
  + * James Tauber <[EMAIL PROTECTED]>. For more  information on the Apache 
    * Software Foundation, please see <http://www.apache.org/>.
  - */ 
  -package org.apache.fop.apps;
  -
  -// SAX
  -import org.xml.sax.XMLReader;
  -
  -// Java
  -import java.io.BufferedOutputStream;
  -import java.io.FileOutputStream;
  -
  -
  -/**
  - * super class for all classes which start Fop from the commandline
  - *
  - * Modified to use new streaming API by Mark Lillywhite, [EMAIL PROTECTED]
  + *  
    */
  -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 {
  -        this.commandLineOptions = commandLineOptions;
  -        super.setInputHandler(commandLineOptions.getInputHandler());
  -    }
   
  -    /**
  -     * Run the format.
  -     * @exception FOPException if there is an error during processing
  -     */
  -    public void run() throws FOPException {
  -        String version = Version.getVersion();
  -
  -        getLogger().info(version);
  -
  -        XMLReader parser = inputHandler.getParser();
  -        setParserFeatures(parser);
  +package org.apache.fop.apps;
   
  -        Driver driver = new Driver();
  -        setupLogger(driver);
  -        driver.initialize();
  +public class CommandLineStarter {
   
  -        try {
  -            driver.setRenderer(commandLineOptions.getRenderer());
  -            BufferedOutputStream bos = new BufferedOutputStream(new 
FileOutputStream(
  -                                      commandLineOptions.getOutputFile()));
  -            try {
  -                driver.setOutputStream(bos);
  -                if (driver.getRenderer() != null) {
  -                    driver.getRenderer().setOptions(
  -                  commandLineOptions.getRendererOptions());
  -                }
  -                driver.render(parser, inputHandler.getInputSource());
  -            } finally {
  -                bos.close();
  -            }
  -            System.exit(0);
  -        } catch (Exception e) {
  -            if (e instanceof FOPException) {
  -                throw (FOPException) e;
  -            }
  -            throw new FOPException(e);
  -        }
  +    public CommandLineStarter() throws FOPException {
       }
   
   }
  
  
  
  1.1.2.1   +1 -1      xml-fop/src/java/org/apache/fop/apps/package.html
  
  Index: package.html
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/package.html,v
  retrieving revision 1.1
  retrieving revision 1.1.2.1
  diff -u -r1.1 -r1.1.2.1
  --- package.html      11 Mar 2003 13:05:28 -0000      1.1
  +++ package.html      5 Jul 2003 19:04:50 -0000       1.1.2.1
  @@ -4,4 +4,4 @@
   <P>Application classes used for running FOP both on the command line and
   embedded in other applications.</P>
   </BODY>
  -</HTML>
  \ No newline at end of file
  +</HTML>
  
  
  
  1.4.2.1   +61 -80    xml-fop/src/java/org/apache/fop/apps/InputHandler.java
  
  Index: InputHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/InputHandler.java,v
  retrieving revision 1.4
  retrieving revision 1.4.2.1
  diff -u -r1.4 -r1.4.2.1
  --- InputHandler.java 17 Jun 2003 16:35:57 -0000      1.4
  +++ InputHandler.java 5 Jul 2003 19:04:50 -0000       1.4.2.1
  @@ -1,7 +1,8 @@
   /*
    * $Id$
  + * 
    * ============================================================================
  - *                    The Apache Software License, Version 1.1
  + *                   The Apache Software License, Version 1.1
    * ============================================================================
    * 
    * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  @@ -9,7 +10,7 @@
    * 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,
  + * 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,
  @@ -17,94 +18,71 @@
    *    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
  + *    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
  + * 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
    *    [EMAIL PROTECTED]
    * 
  - * 5. Products derived from this software may not be called "Apache", nor may
  - *    "Apache" appear in their name, without prior written permission of the
  + * 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
  + * 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 <[EMAIL PROTECTED]>. For more information on the Apache
  + * This software  consists of voluntary contributions made  by many individuals
  + * on  behalf of the Apache Software  Foundation and was  originally created by
  + * James Tauber <[EMAIL PROTECTED]>. For more  information on the Apache 
    * Software Foundation, please see <http://www.apache.org/>.
  - */ 
  + *  
  + */
  +
   package org.apache.fop.apps;
   
   // SAX
  +import java.io.File;
  +import java.net.URL;
  +
   import org.xml.sax.InputSource;
   import org.xml.sax.XMLReader;
  -import org.xml.sax.SAXException;
   
  -// Java
  -import javax.xml.parsers.SAXParserFactory;
  -import javax.xml.parsers.ParserConfigurationException;
  -import java.net.URL;
  -import java.io.File;
  +import org.apache.fop.messaging.MessageHandler;
   
  -/**
  - * 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();
  +abstract public class InputHandler {
   
  -    /**
  -     * 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());
  -    }
  +    abstract public InputSource getInputSource();
  +    abstract public XMLReader getParser() throws FOPException;
  +
   
       /**
  -     * Creates an <code>InputSource</code> from a <code>File</code>
  -     * @param file the <code>File</code>
  -     * @return the <code>InputSource</code> created
  +     * create an InputSource from a File
  +     *
  +     * @param file the File
  +     * @return the InputSource created
        */
  -    public static InputSource fileInputSource(File file) {
  +    static public InputSource fileInputSource(File file) {
           /* this code adapted from James Clark's in XT */
           String path = file.getAbsolutePath();
           String fSep = System.getProperty("file.separator");
  -        if (fSep != null && fSep.length() == 1) {
  +        if (fSep != null && fSep.length() == 1)
               path = path.replace(fSep.charAt(0), '/');
  -        }
  -        if (path.length() > 0 && path.charAt(0) != '/') {
  +        if (path.length() > 0 && path.charAt(0) != '/')
               path = '/' + path;
  -        }
           try {
               return new InputSource(new URL("file", null, path).toString());
           } catch (java.net.MalformedURLException e) {
  @@ -113,29 +91,32 @@
       }
   
       /**
  -     * Creates <code>XMLReader</code> object using default
  -     * <code>SAXParserFactory</code>
  -     * @return the created <code>XMLReader</code>
  -     * @throws FOPException if the parser couldn't be created or configured for 
proper operation.
  +     * creates a SAX parser, using the value of org.xml.sax.parser
  +     * defaulting to org.apache.xerces.parsers.SAXParser
  +     *
  +     * @return the created SAX parser
        */
       protected static XMLReader createParser() throws FOPException {
  +        String parserClassName = System.getProperty("org.xml.sax.parser");
  +        if (parserClassName == null) {
  +            parserClassName = "org.apache.xerces.parsers.SAXParser";
  +        }
  +        MessageHandler.logln("using SAX parser " + parserClassName);
  +
           try {
  -            SAXParserFactory factory = SAXParserFactory.newInstance();
  -            factory.setNamespaceAware(true);
  -            return factory.newSAXParser().getXMLReader();
  -        } catch (SAXException se) {
  -            throw new FOPException("Coudn't create XMLReader", se);
  -        } catch (ParserConfigurationException pce) {
  -            throw new FOPException("Coudn't create XMLReader", pce);
  +            return (XMLReader)Class.forName(parserClassName).newInstance();
  +        } catch (ClassNotFoundException e) {
  +            throw new FOPException(e);
  +        } catch (InstantiationException e) {
  +            throw new FOPException("Could not instantiate "
  +                                   + parserClassName, e);
  +        } catch (IllegalAccessException e) {
  +            throw new FOPException("Could not access " + parserClassName, e);
  +        } catch (ClassCastException e) {
  +            throw new FOPException(parserClassName + " is not a SAX driver",
  +                                   e);
           }
       }
  -    
  -    /**
  -     * Runs this InputHandler through the Driver.
  -     * @param driver Driver instance to use
  -     * @throws FOPException if processing this InputHandler fails
  -     */
  -    public abstract void run(Driver driver) throws FOPException;
  -    
  +
   }
   
  
  
  
  1.1.2.1   +58 -0     xml-fop/src/java/org/apache/fop/apps/Attic/ErrorHandler.java
  
  
  
  
  1.1.2.1   +918 -0    xml-fop/src/java/org/apache/fop/apps/Attic/Options.java
  
  
  
  
  1.4.2.1   +31 -63    xml-fop/src/java/org/apache/fop/apps/FOInputHandler.java
  
  Index: FOInputHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/FOInputHandler.java,v
  retrieving revision 1.4
  retrieving revision 1.4.2.1
  diff -u -r1.4 -r1.4.2.1
  --- FOInputHandler.java       17 Jun 2003 16:35:57 -0000      1.4
  +++ FOInputHandler.java       5 Jul 2003 19:04:50 -0000       1.4.2.1
  @@ -1,7 +1,8 @@
   /*
    * $Id$
  + * 
    * ============================================================================
  - *                    The Apache Software License, Version 1.1
  + *                   The Apache Software License, Version 1.1
    * ============================================================================
    * 
    * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  @@ -9,7 +10,7 @@
    * 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,
  + * 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,
  @@ -17,96 +18,63 @@
    *    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
  + *    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
  + * 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
    *    [EMAIL PROTECTED]
    * 
  - * 5. Products derived from this software may not be called "Apache", nor may
  - *    "Apache" appear in their name, without prior written permission of the
  + * 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
  + * 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 <[EMAIL PROTECTED]>. For more information on the Apache
  + * This software  consists of voluntary contributions made  by many individuals
  + * on  behalf of the Apache Software  Foundation and was  originally created by
  + * James Tauber <[EMAIL PROTECTED]>. For more  information on the Apache 
    * Software Foundation, please see <http://www.apache.org/>.
  - */ 
  + *  
  + */
  +
   package org.apache.fop.apps;
   
   // Imported SAX classes
  +import java.io.File;
  +
   import org.xml.sax.InputSource;
   import org.xml.sax.XMLReader;
   
  -// java
  -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 fofile the file to read the FO document.
  -     */
  +
  +    File fofile;
       public FOInputHandler(File fofile) {
           this.fofile = fofile;
       }
   
  -    /**
  -     * Create a FOInputHandler for an URL.
  -     * @param url the URL to read the FO document.
  -     */
  -    public FOInputHandler(URL url) {
  -        this.foURL = url;
  -    }
  -
  -    
  -    /**
  -     * @see org.apache.fop.apps.InputHandler#getInputSource()
  -     */
  -    public InputSource getInputSource () {
  -        if (fofile != null) {
  -            return super.fileInputSource(fofile);
  -        }
  -        return super.urlInputSource(foURL);
  +    public InputSource getInputSource() {
  +        return super.fileInputSource(fofile);
       }
   
  -    /**
  -     * @see org.apache.fop.apps.InputHandler#getParser()
  -     */
       public XMLReader getParser() throws FOPException {
           return super.createParser();
       }
  -
  -    /**
  -     * @see org.apache.fop.apps.InputHandler#run(Driver)
  -     */
  -    public void run(Driver driver) throws FOPException {
  -        throw new FOPException("not implemented: FOInputHandler.run(Driver)");
  -    }
  -
   
   }
   
  
  
  
  1.9.2.1   +126 -591  xml-fop/src/java/org/apache/fop/apps/Driver.java
  
  Index: Driver.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/Driver.java,v
  retrieving revision 1.9
  retrieving revision 1.9.2.1
  diff -u -r1.9 -r1.9.2.1
  --- Driver.java       5 Jul 2003 09:28:34 -0000       1.9
  +++ Driver.java       5 Jul 2003 19:04:50 -0000       1.9.2.1
  @@ -1,650 +1,185 @@
   /*
    * $Id$
  + * 
    * ============================================================================
  - *                    The Apache Software License, Version 1.1
  + *                   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,
  + * 
  + * 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
  + *    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
  + * 
  + * 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
    *    [EMAIL PROTECTED]
  - *
  - * 5. Products derived from this software may not be called "Apache", nor may
  - *    "Apache" appear in their name, without prior written permission of the
  + * 
  + * 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
  + * 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 <[EMAIL PROTECTED]>. For more information on the Apache
  + * 
  + * This software  consists of voluntary contributions made  by many individuals
  + * on  behalf of the Apache Software  Foundation and was  originally created by
  + * James Tauber <[EMAIL PROTECTED]>. 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.fo.StructureHandler;
  -import org.apache.fop.layoutmgr.LayoutHandler;
  -import org.apache.fop.mif.MIFHandler;
  -import org.apache.fop.render.Renderer;
  -import org.apache.fop.rtf.renderer.RTFHandler;
  -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.IOException;
  -import java.io.OutputStream;
  -
  -/**
  - * 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 Driver which outputs PDF:
  - *
  - * <PRE>
  - * Driver driver = new Driver(new InputSource (args[0]),
  - * new FileOutputStream(args[1]));
  - * driver.enableLogging(myLogger); //optional
  - * driver.setRenderer(RENDER_PDF);
  - * driver.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 Driver may be supplied either with the
  - * object itself, or the name of the class, in which case Driver will
  - * instantiate the class itself. The advantage of the latter is it
  - * enables runtime determination of Renderer and ElementMapping(s).
  - * <P>
  - * Once the Driver 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 Driver which outputs to AWT:
  - *
  - * <PRE>
  - * Driver driver = new Driver();
  - * driver.enableLogging(myLogger); //optional
  - * driver.setRenderer(new org.apache.fop.render.awt.AWTRenderer(translator));
  - * driver.render(parser, fileInputSource(args[0]));
  - * </PRE>
  - */
  -public class Driver 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;
  +import org.apache.fop.configuration.Configuration;
  +import org.apache.fop.fo.FOTree;
  +import org.apache.fop.layout.AreaTree;
  +import org.apache.fop.messaging.MessageHandler;
  +import org.apache.fop.version.Version;
  +import org.apache.fop.xml.FoXMLSerialHandler;
  +import org.apache.fop.xml.SyncedFoXmlEventsBuffer;
   
  +public class Driver {
       /**
  -     * Render to Postscript. OutputStream must be set
  +     * If true, full error stacks are reported
        */
  -    public static final int RENDER_PS = 7;
  +    private static boolean _errorDump = false;
   
  -    /**
  -     * 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 InputHandler inputHandler;
  +    private XMLReader parser;
       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;
  +    private FoXMLSerialHandler xmlhandler;
  +    private SyncedFoXmlEventsBuffer xmlevents;
  +    private FOTree foTree;
  +    private AreaTree areaTree = new AreaTree();
  +
  +    private Thread driverThread;
  +    private Thread parserThread;
  +    private Thread foThread;
  +    private Thread areaThread;
  +    private Thread renderThread;
   
  -    /**
  -     * 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() {
  +     * What does the Driver do?
  +     * When it has all of the ancillary requirements, it sets up the
  +     * serialized components:
  +     * XMLEventSource <=> FOTree <=> AreaTree ...
  +     */
  +    public Driver() throws FOPException {
  +        _errorDump =
  +                Configuration.getBooleanValue("debugMode").booleanValue();
  +        String version = Version.getVersion();
  +        MessageHandler.logln(version);
  +    }
  +
  +    public void run () throws FOPException {
  +        setInputHandler(Options.getInputHandler());
  +        parser = inputHandler.getParser();
  +        source = inputHandler.getInputSource();
  +        setParserFeatures(parser);
  +
  +        xmlevents = new SyncedFoXmlEventsBuffer();
  +        xmlhandler = new FoXMLSerialHandler(xmlevents, parser, source);
  +        foTree = new FOTree(xmlevents);
  +
  +        driverThread = Thread.currentThread();
  +        foThread = new Thread(foTree, "FOTreeBuilder");
  +        foThread.setDaemon(true);
  +        parserThread = new Thread(xmlhandler, "XMLSerialHandler");
  +        parserThread.setDaemon(true);
  +
  +        xmlhandler.setFoThread(foThread);
  +        foTree.setParserThread(parserThread);
  +
  +        System.out.println("Starting parserThread");
  +        parserThread.start();
  +        System.out.println("parserThread started");
  +        foThread.start();
  +        System.out.println("foThread started");
           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 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;
  -    }
  -
  -    private boolean isInitialized() {
  -        return (treeBuilder != null);
  -    }
  -
  -    /**
  -     * Initializes the Driver object.
  -     */
  -    public void initialize() {
  -        if (isInitialized()) {
  -            throw new IllegalStateException("Driver already initialized");
  -        }
  -        treeBuilder = new FOTreeBuilder();
  -        treeBuilder.setUserAgent(getUserAgent());
  -    }
  -
  -    /**
  -     * 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;
  -    }
  -
  -    private FOUserAgent getUserAgent() {
  -        if (userAgent == null) {
  -            userAgent = new FOUserAgent();
  -            userAgent.enableLogging(getLogger());
  -            userAgent.setBaseURL("");
  -        }
  -        return userAgent;
  -    }
  -
  -    /**
  -     * Provide the Driver instance with a logger. More information on Avalon
  -     * logging can be found at the
  -     * <a href="http://avalon.apache.org";>Avalon site</a>.
  -     *
  -     * @param log the logger. Must not be <code>null</code>.
  -     * @see org.apache.avalon.framework.logger.LogEnabled#enableLogging(Logger)
  -     */
  -    public void enableLogging(Logger log) {
  -        if (this.log == null) {
  -            this.log = log;
  -        } else {
  -            getLogger().warn("Logger is already set! Won't use the new logger.");
  -        }
  -    }
  -
  -    /**
  -     * Provide the Driver 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 Driver 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;
  -    }
  -
  -    /**
  -     * 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 {
  +            parserThread.join();
  +        } catch (InterruptedException e) {}
  +        //System.out.println("Joined to parser.");
           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");
  -        }
  -    }
  +            foThread.join();
  +        } catch (InterruptedException e) {}
   
  -    /**
  -     * 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) {
  -        treeBuilder.addElementMapping(mapping);
  -    }
  -
  -    /**
  -     * Add the element mapping with the given class name.
  -     * @param mappingClassName the class name representing the element mapping.
  -     */
  -    public void addElementMapping(String mappingClassName) {
  -        treeBuilder.addElementMapping(mappingClassName);
       }
   
  -    /**
  -     * 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();
  +    public static final String getParserClassName() {
  +        String parserClassName = null;
  +        try {
  +            parserClassName = System.getProperty("org.xml.sax.parser");
  +        } catch (SecurityException se) {}
   
  -        // 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 MIFHandler(stream);
  -        } else if (rendererType == RENDER_RTF) {
  -            structHandler = new RTFHandler(stream);
  -        } else {
  -            if (renderer == null) {
  -                throw new IllegalStateException(
  -                        "Renderer not set when using standard structHandler");
  -            }
  -            structHandler = new LayoutHandler(stream, renderer, true);
  +        if (parserClassName == null) {
  +            parserClassName = "org.apache.xerces.parsers.SAXParser";
           }
  -
  -        structHandler.enableLogging(getLogger());
  -
  -        treeBuilder.setUserAgent(getUserAgent());
  -        treeBuilder.setStructHandler(structHandler);
  -
  -        return treeBuilder;
  +        return parserClassName;
       }
   
  -    /**
  -     * 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);
  -        }
  +    public void setInputHandler(InputHandler inputHandler) {
  +        this.inputHandler = inputHandler;
       }
   
  -    /**
  -     * 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();
  -        }
  +     // setting the parser features
  +    public void setParserFeatures(XMLReader parser) throws FOPException {
           try {
  -            DocumentInputSource source = new DocumentInputSource(document);
  -            DocumentReader reader = new DocumentReader();
  -            reader.setContentHandler(getContentHandler());
  -            reader.parse(source);
  +            parser.setFeature("http://xml.org/sax/features/namespace-prefixes";,
  +                              true);
           } 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);
  +            throw new FOPException(
  +                "Error in setting up parser feature namespace-prefixes\n"
  +                       + "You need a parser which supports SAX version 2", 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.
  +     * Dumps an error
        */
  -    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);
  +    public static void dumpError(Exception e) {
  +        if (_errorDump) {
  +            if (e instanceof SAXException) {
  +                e.printStackTrace();
  +                if (((SAXException)e).getException() != null) {
  +                    ((SAXException)e).getException().printStackTrace();
  +                }
  +            } else if (e instanceof FOPException) {
  +                e.printStackTrace();
  +                if (((FOPException)e).getException() != null) {
  +                    ((FOPException)e).getException().printStackTrace();
                   }
  +            } else {
  +                e.printStackTrace();
               }
  -        }
  -
  -        if (source instanceof DocumentInputSource) {
  -            render(((DocumentInputSource)source).getDocument());
  -        } else {
  -            render(reader, source);
           }
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to