You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ke...@apache.org on 2001/06/22 11:18:24 UTC

cvs commit: xml-fop/src/org/apache/fop/apps CommandLineOptions.java Driver.java

keiron      01/06/22 02:18:24

  Modified:    src/org/apache/fop/apps CommandLineOptions.java Driver.java
  Log:
  command line support for new ps renderer
  also cleaned up code
  Submitted by:  Jeremias Maerki <je...@outline.ch>
  
  Revision  Changes    Path
  1.9       +146 -149  xml-fop/src/org/apache/fop/apps/CommandLineOptions.java
  
  Index: CommandLineOptions.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/apps/CommandLineOptions.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- CommandLineOptions.java	2001/05/20 23:53:40	1.8
  +++ CommandLineOptions.java	2001/06/22 09:18:24	1.9
  @@ -1,10 +1,9 @@
  -/*
  +/* $Id: CommandLineOptions.java,v 1.9 2001/06/22 09:18:24 keiron Exp $
    * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
    * For details on use and redistribution please refer to the
  - * LICENSE file included with these sources."
  + * LICENSE file included with these sources.
    */
   
  -
   package org.apache.fop.apps;
   
   //java
  @@ -20,7 +19,6 @@
   /**
    *	Options parses the commandline arguments
    */
  -
   public class CommandLineOptions {
   
       /* input / output not set */
  @@ -39,23 +37,25 @@
       private static final int PRINT_OUTPUT = 4;
       /* output: pcl file  */
       private static final int PCL_OUTPUT = 5;
  +    /* output: postscript file  */
  +    private static final int PS_OUTPUT = 6;
       /* output: text file  */
  -    private static final int TXT_OUTPUT = 6;
  +    private static final int TXT_OUTPUT = 7;
  +
  +    /* System buffers */
  +    private static final int BUFFER_FILE = 8;
   
  -	/* System buffers */
  -	private static final int BUFFER_FILE = 7;
  -	
  -	/* System buffers */
  -	private static final int AREA_OUTPUT = 8;
  -	
  +    /* System buffers */
  +    private static final int AREA_OUTPUT = 9;
  +
       /* use debug mode*/
       Boolean errorDump = new Boolean(false);
       /* show configuration information */
       Boolean dumpConfiguration = new Boolean(false);
       /*suppress any progress information */
       Boolean quiet = new Boolean(false);
  -	/* for area tree XML output, only down to block area level */
  -	Boolean suppressLowLevelAreas = new Boolean(false);
  +    /* for area tree XML output, only down to block area level */
  +    Boolean suppressLowLevelAreas = new Boolean(false);
       /* name of user configuration file*/
       File userConfigFile = null;
       /* name of input fo file  */
  @@ -76,43 +76,38 @@
       int buffermode = NOT_SET;
       /* language for user information */
       String language = null;
  +
  +    private java.util.Hashtable rendererOptions;
  +
  +    public CommandLineOptions (String [] args) throws FOPException,
  +    FileNotFoundException {
  +        boolean optionsParsed = true;
  +        rendererOptions = new java.util.Hashtable();
  +        try {
  +            optionsParsed = parseOptions(args);
  +            if (optionsParsed) {
  +                checkSettings ();
  +                if (errorDump != null && errorDump.booleanValue()) {
  +                    debug();
  +                }
  +            }
  +        } catch (FOPException e) {
  +            printUsage();
  +            throw e;
  +        }
  +        catch (java.io.FileNotFoundException e) {
  +            printUsage();
  +            throw e;
  +        }
   
  -	private java.util.Hashtable rendererOptions;
  -	
  -    public CommandLineOptions (String [] args) 
  -	throws FOPException, FileNotFoundException
  -    {
  -	boolean optionsParsed = true;
  -	rendererOptions = new java.util.Hashtable();
  -	try {
  -	    optionsParsed = parseOptions(args);
  -	    if (optionsParsed) {
  -		checkSettings ();
  -		if (errorDump != null && errorDump.booleanValue()) {
  -		    debug();
  -		}
  -	    }
  -	}
  -	catch (FOPException e) {
  -	    printUsage();
  -	    throw e;
  -	}
  -	catch (java.io.FileNotFoundException e) {
  -	    printUsage();
  -	    throw e;
  -	}
  -       
       }
  -    
   
       /**
        *  parses the commandline arguments
        * @return true if parse was successful and procesing can continue, false if processing should stop
        * @exception FOPException if there was an error in the format of the options
        */
  -    private boolean parseOptions (String args[]) 
  -	throws FOPException
  -    {
  +    private boolean parseOptions (String args[]) throws FOPException {
           for (int i = 0; i < args.length; i++) {
               if (args[i].equals("-d") || args[i].equals("--full-error-dump")) {
                   errorDump = new Boolean(true);
  @@ -123,7 +118,7 @@
               } else if (args[i].equals("-c")) {
                   if ((i + 1 == args.length) ||
                           (args[i + 1].charAt(0) == '-')) {
  -		    throw new FOPException("if you use '-c', you must specify the name of the configuration file");
  +                    throw new FOPException("if you use '-c', you must specify the name of the configuration file");
                   } else {
                       userConfigFile = new File (args[i + 1]);
                       i++;
  @@ -138,7 +133,7 @@
                   }
               } else if (args[i].equals("-s")) {
                   suppressLowLevelAreas = new Boolean(true);
  -            }  else if (args[i].equals("-fo")) {
  +            } else if (args[i].equals("-fo")) {
                   inputmode = FO_INPUT;
                   if ((i + 1 == args.length) ||
                           (args[i + 1].charAt(0) == '-')) {
  @@ -166,36 +161,36 @@
                       i++;
                   }
               } else if (args[i].equals("-awt")) {
  -		setOutputMode(AWT_OUTPUT);
  -	    } else if (args[i].equals("-pdf")) {
  -		setOutputMode(PDF_OUTPUT);
  -		if ((i + 1 == args.length) ||
  -		    (args[i + 1].charAt(0) == '-')) {
  +                setOutputMode(AWT_OUTPUT);
  +            } else if (args[i].equals("-pdf")) {
  +                setOutputMode(PDF_OUTPUT);
  +                if ((i + 1 == args.length) ||
  +                        (args[i + 1].charAt(0) == '-')) {
                       throw new FOPException("you must specify the pdf output file");
                   } else {
                       outfile = new File (args[i + 1]);
                       i++;
                   }
               } else if (args[i].equals("-mif")) {
  -		setOutputMode(MIF_OUTPUT);
  +                setOutputMode(MIF_OUTPUT);
                   if ((i + 1 == args.length) ||
                           (args[i + 1].charAt(0) == '-')) {
  -                     throw new FOPException("you must specify the mif output file");
  +                    throw new FOPException("you must specify the mif output file");
                   } else {
                       outfile = new File(args[i + 1]);
                       i++;
                   }
               } else if (args[i].equals("-print")) {
  -		setOutputMode(PRINT_OUTPUT);
  +                setOutputMode(PRINT_OUTPUT);
                   //show print help
                   if (i + 1 < args.length) {
                       if (args[i + 1].equals("help")) {
                           printUsagePrintOutput();
  -			return false;
  -		    }
  +                        return false;
  +                    }
                   }
               } else if (args[i].equals("-pcl")) {
  -		setOutputMode(PCL_OUTPUT);
  +                setOutputMode(PCL_OUTPUT);
                   if ((i + 1 == args.length) ||
                           (args[i + 1].charAt(0) == '-')) {
                       throw new FOPException("you must specify the pdf output file");
  @@ -203,8 +198,17 @@
                       outfile = new File (args[i + 1]);
                       i++;
                   }
  +            } else if (args[i].equals("-ps")) {
  +                setOutputMode(PS_OUTPUT);
  +                if ((i + 1 == args.length) ||
  +                        (args[i + 1].charAt(0) == '-')) {
  +                    throw new FOPException("you must specify the PostScript output file");
  +                } else {
  +                    outfile = new File (args[i + 1]);
  +                    i++;
  +                }
               } else if (args[i].equals("-txt")) {
  -		setOutputMode(TXT_OUTPUT);
  +                setOutputMode(TXT_OUTPUT);
                   if ((i + 1 == args.length) ||
                           (args[i + 1].charAt(0) == '-')) {
                       throw new FOPException("you must specify the text output file");
  @@ -220,9 +224,10 @@
                       outputmode = PDF_OUTPUT;
                       outfile = new File(args[i]);
                   } else {
  -                    throw new FOPException("Don't know what to do with " + args[i]);
  +                    throw new FOPException(
  +                      "Don't know what to do with " + args[i]);
                   }
  -            }	else if (args[i].equals("-buf")) {
  +            } else if (args[i].equals("-buf")) {
                   if (buffermode == NOT_SET) {
                       buffermode = BUFFER_FILE;
                   } else {
  @@ -238,7 +243,7 @@
                       i++;
                   }
               } else if (args[i].equals("-at")) {
  -		setOutputMode(AREA_OUTPUT);
  +                setOutputMode(AREA_OUTPUT);
                   if ((i + 1 == args.length) ||
                           (args[i + 1].charAt(0) == '-')) {
                       throw new FOPException("you must specify the area-tree output file");
  @@ -248,62 +253,58 @@
                   }
               } else {
                   printUsage();
  -		return false;
  -	    }
  +                return false;
  +            }
           }
  -	return true;
  +        return true;
       } //end parseOptions
   
  -    private void setOutputMode(int mode) 
  -	throws FOPException
  -    {
  -	if (outputmode == NOT_SET) {
  -	    outputmode = mode;
  -	} else {
  -	    throw new FOPException("you can only set one output method");
  -	}
  +    private void setOutputMode(int mode) throws FOPException {
  +        if (outputmode == NOT_SET) {
  +            outputmode = mode;
  +        } else {
  +            throw new FOPException("you can only set one output method");
  +        }
       }
  -    
   
       /**
        * checks whether all necessary information has been given in a consistent way
        */
  -    private void checkSettings ()
  -	throws FOPException, FileNotFoundException
  -    {
  +    private void checkSettings () throws FOPException,
  +    FileNotFoundException {
           if (inputmode == NOT_SET) {
  -	    throw new FOPException("No input file specified");
  -	}
  +            throw new FOPException("No input file specified");
  +        }
   
           if (outputmode == NOT_SET) {
  -	    throw new FOPException("No output file specified");
  -	}
  +            throw new FOPException("No output file specified");
  +        }
   
           if (inputmode == XSLT_INPUT) {
               //check whether xml *and* xslt file have been set
  -	    if (xmlfile == null) {
  -		throw new FOPException("XML file must be specified for the tranform mode");
  -	    }
  -	    if (xsltfile == null) {
  -		throw new FOPException("XSLT file must be specified for the tranform mode");
  -	    }
  +            if (xmlfile == null) {
  +                throw new FOPException("XML file must be specified for the tranform mode");
  +            }
  +            if (xsltfile == null) {
  +                throw new FOPException("XSLT file must be specified for the tranform mode");
  +            }
   
               //warning if fofile has been set in xslt mode
               if (fofile != null) {
                   MessageHandler.errorln(
                     "WARNING: Can't use fo file with transform mode! Ignoring.\n" +
  -                  "Your input is "+
  -		  "\n xmlfile: " + xmlfile.getAbsolutePath() + 
  -		  "\nxsltfile: " + xsltfile.getAbsolutePath() + 
  -		  "\n  fofile: " + fofile.getAbsolutePath());
  +                  "Your input is "+ "\n xmlfile: " +
  +                  xmlfile.getAbsolutePath() + "\nxsltfile: " +
  +                  xsltfile.getAbsolutePath() + "\n  fofile: " +
  +                  fofile.getAbsolutePath());
               }
               if (!xmlfile.exists()) {
  -		throw new FileNotFoundException("xml file " +
  -						xmlfile.getAbsolutePath() + " not found ");
  +                throw new FileNotFoundException("xml file " +
  +                                                xmlfile.getAbsolutePath() + " not found ");
               }
               if (!xsltfile.exists()) {
                   throw new FileNotFoundException("xsl file " +
  -                                       xsltfile.getAbsolutePath() + " not found ");
  +                                                xsltfile.getAbsolutePath() + " not found ");
               }
   
           } else if (inputmode == FO_INPUT) {
  @@ -313,14 +314,13 @@
                   MessageHandler.errorln("xslt file: " + xsltfile.toString());
               }
               if (!fofile.exists()) {
  -                 throw new FileNotFoundException("fo file " +
  -                                       fofile.getAbsolutePath() + " not found ");
  +                throw new FileNotFoundException("fo file " +
  +                                                fofile.getAbsolutePath() + " not found ");
               }
   
           }
       }// end checkSettings
   
  -
       /**
        *  returns the chosen renderer, throws FOPException
        */
  @@ -338,19 +338,21 @@
                   return Driver.RENDER_PRINT;
               case PCL_OUTPUT:
                   return Driver.RENDER_PCL;
  +            case PS_OUTPUT:
  +                return Driver.RENDER_PS;
               case TXT_OUTPUT:
                   return Driver.RENDER_TXT;
  -			case AREA_OUTPUT:
  -				rendererOptions.put("fineDetail", isCoarseAreaXml());
  -				return Driver.RENDER_XML;
  +            case AREA_OUTPUT:
  +                rendererOptions.put("fineDetail", isCoarseAreaXml());
  +                return Driver.RENDER_XML;
               default:
                   throw new FOPException("Invalid Renderer setting!");
           }
       }
   
       /**
  -       *
  -       **/
  +     *
  +     **/
       public InputHandler getInputHandler () {
           switch (inputmode) {
               case FO_INPUT:
  @@ -362,16 +364,12 @@
           }
       }
   
  -	public java.util.Hashtable getRendererOptions() {
  -		return rendererOptions;
  -	}
  -	
  -    public Starter getStarter() 
  -	throws FOPException
  -    {
  +    public java.util.Hashtable getRendererOptions() {
  +        return rendererOptions;
  +    }
  +
  +    public Starter getStarter() throws FOPException {
           switch (outputmode) {
  -            case PDF_OUTPUT:
  -                return new CommandLineStarter(this);
               case AWT_OUTPUT:
                   try {
                       return((Starter) Class.forName(
  @@ -380,13 +378,11 @@
                                new Class[]{CommandLineOptions.class}).
                              newInstance(new Object[]{this}));
                   } catch (Exception e) {
  -		    if (e instanceof FOPException) {
  -			throw (FOPException)e;
  -		    }
  -		    throw new FOPException("AWTStarter could not be loaded.",e);
  +                    if (e instanceof FOPException) {
  +                        throw (FOPException) e;
  +                    }
  +                    throw new FOPException("AWTStarter could not be loaded.",e);
                   }
  -            case MIF_OUTPUT:
  -                return new CommandLineStarter(this);
               case PRINT_OUTPUT:
                   try {
                       return((Starter) Class.forName(
  @@ -395,14 +391,12 @@
                                new Class[]{CommandLineOptions.class}).
                              newInstance(new Object[]{this}));
                   } catch (Exception e) {
  -		    if (e instanceof FOPException) {
  -			throw (FOPException)e;
  -		    }
  -		    throw new FOPException("PrintStarter could not be loaded.",e);
  +                    if (e instanceof FOPException) {
  +                        throw (FOPException) e;
  +                    }
  +                    throw new FOPException("PrintStarter could not be loaded.",e);
                   }
   
  -            case AREA_OUTPUT:
  -                return new CommandLineStarter(this);
               default:
                   return new CommandLineStarter(this);
           }
  @@ -439,11 +433,11 @@
       public String getLanguage() {
           return language;
       }
  +
  +    public File getBufferFile() {
  +        return bufferFile;
  +    }
   
  -     public File getBufferFile() {
  -        		return bufferFile;
  -     }
  -     
       public Boolean isQuiet() {
           return quiet;
       }
  @@ -455,14 +449,14 @@
       public Boolean isDebugMode() {
           return errorDump;
       }
  +
  +    public Boolean isCoarseAreaXml() {
  +        return suppressLowLevelAreas;
  +    }
   
  -	public Boolean isCoarseAreaXml() {
  -		return suppressLowLevelAreas;
  -	}
  -	
       /**
  -       * return either the fofile or the xmlfile
  -       */
  +     * return either the fofile or the xmlfile
  +     */
       public File getInputFile() {
           switch (inputmode) {
               case FO_INPUT:
  @@ -474,19 +468,18 @@
           }
       }
   
  -
       /**
  -       *	 shows the commandline syntax including a summary of all available options and some examples
  -       */
  +     *	 shows the commandline syntax including a summary of all available options and some examples
  +     */
       public static void printUsage() {
           MessageHandler.errorln(
  -          "\nUSAGE\nFop [options] [-fo|-xml] infile [-xsl file] [-awt|-pdf|-mif|-pcl|-txt|-at|-print] <outfile>\n" +
  +          "\nUSAGE\nFop [options] [-fo|-xml] infile [-xsl file] [-awt|-pdf|-mif|-pcl|-ps|-txt|-at|-print] <outfile>\n" +
             " [OPTIONS]  \n" + "  -d          debug mode   \n" +
             "  -x          dump configuration settings  \n" +
             "  -q          quiet mode  \n" +
             "  -c cfg.xml  use additional configuration file cfg.xml\n" +
             "  -l lang     the language to use for user information \n" +
  -		  "  -s          for area tree XML, down to block areas only\n\n" +
  +          "  -s          for area tree XML, down to block areas only\n\n" +
             " [INPUT]  \n" +
             "  infile            xsl:fo input file (the same as the next) \n" +
             "  -fo  infile       xsl:fo input file  \n" +
  @@ -498,6 +491,7 @@
             "  -awt              input will be displayed on screen \n" +
             "  -mif outfile      input will be rendered as mif file (outfile req'd)\n" +
             "  -pcl outfile      input will be rendered as pcl file (outfile req'd) \n" +
  +          "  -ps outfile       input will be rendered as PostScript file (outfile req'd) \n" +
             "  -txt outfile      input will be rendered as text file (outfile req'd) \n" +
             "  -at outfile       representation of area tree as XML (outfile req'd) \n" +
             "  -print            input file will be rendered and sent to the printer \n" +
  @@ -510,8 +504,8 @@
       }
   
       /**
  -       *	shows the options for print output
  -       */
  +     *	shows the options for print output
  +     */
       public void printUsagePrintOutput() {
           MessageHandler.errorln(
             "USAGE: -print [-Dstart=i] [-Dend=i] [-Dcopies=i] [-Deven=true|false] " +
  @@ -521,8 +515,8 @@
   
   
       /**
  -       * debug mode. outputs all commandline settings
  -       */
  +     * debug mode. outputs all commandline settings
  +     */
       private void debug () {
           System.out.print("Input mode: ");
           switch (inputmode) {
  @@ -574,6 +568,10 @@
                   MessageHandler.logln("pcl");
                   MessageHandler.logln("output file: " + outfile.toString());
                   break;
  +            case PS_OUTPUT:
  +                MessageHandler.logln("PostScript");
  +                MessageHandler.logln("output file: " + outfile.toString());
  +                break;
               case TXT_OUTPUT:
                   MessageHandler.logln("txt");
                   MessageHandler.logln("output file: " + outfile.toString());
  @@ -611,16 +609,15 @@
       //debug: create class and output all settings
       public static void main (String args[]) {
           /*
  -          for (int i = 0; i < args.length; i++) {
  -          	MessageHandler.logln(">"+args[i]+"<");
  -          }*/
  -	try {
  -	    CommandLineOptions options = new CommandLineOptions (args);
  -	}
  -	catch (Exception e) {
  -	    e.printStackTrace();
  -	}
  -	
  +           for (int i = 0; i < args.length; i++) {
  +             MessageHandler.logln(">"+args[i]+"<");
  +           }*/
  +        try {
  +            CommandLineOptions options = new CommandLineOptions (args);
  +        } catch (Exception e) {
  +            e.printStackTrace();
  +        }
  +
           //options.debug();
       }
   }
  
  
  
  1.26      +514 -518  xml-fop/src/org/apache/fop/apps/Driver.java
  
  Index: Driver.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/apps/Driver.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- Driver.java	2001/05/20 23:54:33	1.25
  +++ Driver.java	2001/06/22 09:18:24	1.26
  @@ -1,518 +1,514 @@
  -/* $Id: Driver.java,v 1.25 2001/05/20 23:54:33 arved Exp $
  - * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  - * For details on use and redistribution please refer to the 
  - * LICENSE file included with these sources."
  - */
  -
  -
  -package org.apache.fop.apps;
  -
  -// FOP
  -import org.apache.fop.fo.FOTreeBuilder;
  -import org.apache.fop.fo.ElementMapping;
  -import org.apache.fop.fo.PropertyListMapping;
  -import org.apache.fop.layout.AreaTree;
  -import org.apache.fop.layout.FontInfo;
  -import org.apache.fop.render.Renderer;
  -import org.apache.fop.messaging.MessageHandler;
  -import org.apache.fop.configuration.ConfigurationReader;
  -import org.apache.fop.configuration.Configuration;
  -import org.apache.fop.tools.DocumentInputSource;
  -import org.apache.fop.tools.DocumentReader;
  -
  -import org.apache.fop.system.BufferManager;
  -
  -// DOM
  -import org.w3c.dom.Document;
  -import org.w3c.dom.Node;
  -import org.w3c.dom.NamedNodeMap;
  -import org.w3c.dom.Attr;
  -
  -// SAX
  -import org.xml.sax.ContentHandler;
  -import org.xml.sax.InputSource;
  -import org.xml.sax.XMLReader;
  -import org.xml.sax.SAXException;
  -import org.xml.sax.helpers.AttributesImpl;
  -
  -// Java
  -import java.io.*;
  -
  -
  -/**
  - * 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.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 buildFOTree method
  - * is called. Depending on whether DOM or SAX is being used, the
  - * invocation of the method is either buildFOTree(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.setRenderer(new org.apache.fop.render.awt.AWTRenderer(translator));
  - *   driver.buildFOTree(parser, fileInputSource(args[0]));
  - *   driver.format();
  - *   driver.render();
  - * </PRE>
  - */
  -public class Driver {
  -    
  -    /** 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 Text. OutputStream must be set */
  -    public static final int RENDER_TXT = 7;
  -
  -    /** the FO tree builder */
  -    private FOTreeBuilder _treeBuilder;
  -
  -    /** the area tree that is the result of formatting the FO tree */
  -    private AreaTree _areaTree;
  -
  -    /** the renderer to use to output the area tree */
  -    private Renderer _renderer;
  -
  -    /** 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;
  -    
  -    /** If true, full error stacks are reported */
  -    private boolean _errorDump = false;
  -
  -    /** the system resources that FOP will use    */
  -    private BufferManager _bufferManager;
  -
  -    /** create a new Driver */
  -    public Driver() {
  - 	_stream = null;
  -  	_bufferManager = new BufferManager();
  - 	_treeBuilder = new FOTreeBuilder();
  -  	_treeBuilder.setBufferManager(_bufferManager);
  -	setupDefaultMappings();
  -    }
  -
  -    public Driver(InputSource source, OutputStream stream) {
  -	this();
  -	_source = source;
  -	_stream = stream;
  -    }
  -
  -    /**
  -     * 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() 
  -    {
  -	_areaTree = null;
  -	_treeBuilder.reset();
  -    }
  -    
  -    public boolean hasData()
  -    {
  -	return(_treeBuilder.hasData());
  -    }
  -    
  -    /** 
  -     * Set the error dump option
  -     * @param dump if true, full stacks will be reported to the error log
  -     */
  -    public void setErrorDump(boolean dump) {
  -        _errorDump = dump;
  -    }
  -
  -    /**
  -     * 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) {
  -        _stream = stream;
  -    }
  -
  -    /**
  -     * 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) 
  -    {
  -	_source = source;
  -    }
  -    
  -    /**
  -     * Sets the reader used when reading in the source. If not set,
  -     * this defaults to a basic SAX parser.
  -     */
  -    public void setXMLReader(XMLReader reader) 
  -    {
  -	_reader = reader;
  -    }
  -    
  -
  -    /**
  -     * Sets all the element and property list mappings to their default values.
  -     *
  -     */
  -    public void setupDefaultMappings() 
  -    {
  -	addElementMapping("org.apache.fop.fo.StandardElementMapping");
  -	addPropertyList  ("org.apache.fop.fo.StandardPropertyListMapping");
  -
  -	addElementMapping("org.apache.fop.svg.SVGElementMapping");
  -	addPropertyList  ("org.apache.fop.svg.SVGPropertyListMapping");
  -
  -        addElementMapping("org.apache.fop.extensions.ExtensionElementMapping");
  -	addPropertyList  ("org.apache.fop.extensions.ExtensionPropertyListMapping");
  -    }
  -
  -    /**
  -     * Set the rendering type to use. Must be one of 
  -     * <ul>
  -     *   <li>RENDER_PDF
  -     *   <li>RENDER_AWT
  -     *   <li>RENDER_MIF
  -     *   <li>RENDER_XML
  -     *   <li>RENDER_PCL
  -     *   <li>RENDER_TXT
  -     * </ul>
  -     * @param renderer the type of renderer to use
  -     */
  -    public void setRenderer(int renderer) 
  -	throws IllegalArgumentException
  -    {
  -	switch (renderer) {
  -	case RENDER_PDF:
  -	    setRenderer(new 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(new org.apache.fop.render.pcl.PCLRenderer());
  -        break;
  -    case RENDER_TXT:
  -        setRenderer(new org.apache.fop.render.txt.TXTRenderer());
  -		break;
  -	case RENDER_MIF:
  -	    setRenderer(new org.apache.fop.render.mif.MIFRenderer());
  -	    break;
  -	case RENDER_XML:
  -	    setRenderer(new org.apache.fop.render.xml.XMLRenderer());
  -	    break;
  -	default:
  -	    throw new IllegalArgumentException("Unknown renderer type");
  -	}
  -	
  -    }
  -    
  -
  -    /** 
  -     * Set the Renderer to use 
  -     * @param renderer the renderer instance to use
  -     */
  -    public void setRenderer(Renderer renderer) {
  -        _renderer = renderer;
  -    }
  -
  -    public Renderer getRenderer() {
  -        return _renderer;
  -    }
  -
  -    /**
  -     * @deprecated use renderer.setProducer(version) + setRenderer(renderer) or just setRenderer(renderer_type) 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();
  -	    _renderer.setProducer(Version.getVersion());
  -	}
  -	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
  -     */
  -    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");
  -	}
  -    }
  -
  -    /**
  -     * Add the PropertyListMapping.
  -     */
  -    public void addPropertyList(PropertyListMapping mapping) 
  -    {
  -	mapping.addToBuilder(_treeBuilder);
  -    }
  -    
  -
  -    /**
  -     * Add the PropertyListMapping with the given class name.
  -     */
  -    public void addPropertyList(String listClassName) 
  -	throws IllegalArgumentException
  -    {
  -	try {
  -            PropertyListMapping mapping = (PropertyListMapping) Class.forName(
  -                     listClassName).newInstance();
  -	    addPropertyList(mapping);
  -	    
  -	} catch (ClassNotFoundException e) {
  -            throw new IllegalArgumentException("Could not find " + listClassName);
  -	}
  -        catch (InstantiationException e) {
  -            throw new IllegalArgumentException("Could not instantiate " +
  -					       listClassName);
  -	}
  -        catch (IllegalAccessException e) {
  -            throw new IllegalArgumentException("Could not access " + listClassName);
  -	}
  -        catch (ClassCastException e) {
  -            throw new IllegalArgumentException(listClassName + " 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.
  -     */
  -    public ContentHandler getContentHandler() {
  -        return _treeBuilder;
  -    }
  -
  -    /**
  -     * Build the formatting object tree using the given SAX Parser and
  -     * SAX InputSource
  -     */
  -    public synchronized void buildFOTree(XMLReader parser,
  -                            InputSource source)
  -	throws FOPException 
  -    {
  -
  -        parser.setContentHandler(_treeBuilder);
  -        try {
  -            parser.parse(source);
  -        } catch (SAXException e) {
  -            if (e.getException() instanceof FOPException) {
  -                throw (FOPException) e.getException();
  -            } else {
  -                throw new FOPException(e);
  -            }
  -        }
  -        catch (IOException e) {
  -            throw new FOPException(e);
  -        }
  -    }
  -
  -    /**
  -     * Build the formatting object tree using the given DOM Document
  -     */
  -    public synchronized void buildFOTree(Document document) 
  -	throws FOPException 
  -    {
  -	try {
  -	    DocumentInputSource source = new DocumentInputSource(document);
  -	    DocumentReader reader = new DocumentReader();
  -	    reader.setContentHandler(_treeBuilder);
  -	    reader.parse(source);
  -	} catch (SAXException e) {
  -            throw new FOPException(e);
  -	} catch (IOException e) {
  -            throw new FOPException(e);
  -	}
  -	
  -    } 
  -
  -    /**
  -     * Dumps an error
  -     */
  -    public 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();
  -            }
  -        }
  -    }
  -
  -    /* Set up the system buffers */
  -   
  -    public void setBufferFile(File bufferFile) {
  -    	this._bufferManager.addBufferFile(bufferFile);
  -    }
  -    
  -    /**
  -     * format the formatting object tree into an area tree
  -     */
  -    public synchronized void format() throws FOPException {
  -        FontInfo fontInfo = new FontInfo();
  -        _renderer.setupFontInfo(fontInfo);
  -
  -        _areaTree = new AreaTree();
  -        _areaTree.setFontInfo(fontInfo);
  -
  -        _treeBuilder.format(_areaTree);
  -    }
  -
  -    /**
  -     * render the area tree to the output form
  -     */
  -    public synchronized void render() throws IOException, FOPException {
  -        _renderer.render(_areaTree, _stream);
  -    }
  -
  -    /**
  -     * Runs the formatting and renderering process using the previously set
  -     * inputsource and outputstream
  -     */
  -    public synchronized void run()
  -	throws IOException, FOPException 
  -    {
  -	if (_renderer == null) {
  -	    setRenderer(RENDER_PDF);
  -	}
  -	if (_source == null) {
  -	    throw new FOPException("InputSource is not set.");
  -	}
  -	if (_reader == null) {
  -	    if (!(_source instanceof DocumentInputSource)) {
  -		_reader = ConfigurationReader.createParser();
  -	    }
  -	}
  -	if (_source instanceof DocumentInputSource) {
  -	    buildFOTree(((DocumentInputSource)_source).getDocument());
  -	}
  -	else {
  -	    buildFOTree(_reader, _source);
  -	}
  -	format();
  -	render();
  -    }
  -    
  -}
  +/* $Id: Driver.java,v 1.26 2001/06/22 09:18:24 keiron Exp $
  + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  + * For details on use and redistribution please refer to the
  + * LICENSE file included with these sources.
  + */
  +
  +package org.apache.fop.apps;
  +
  +// FOP
  +import org.apache.fop.fo.FOTreeBuilder;
  +import org.apache.fop.fo.ElementMapping;
  +import org.apache.fop.fo.PropertyListMapping;
  +import org.apache.fop.layout.AreaTree;
  +import org.apache.fop.layout.FontInfo;
  +import org.apache.fop.render.Renderer;
  +import org.apache.fop.messaging.MessageHandler;
  +import org.apache.fop.configuration.ConfigurationReader;
  +import org.apache.fop.configuration.Configuration;
  +import org.apache.fop.tools.DocumentInputSource;
  +import org.apache.fop.tools.DocumentReader;
  +
  +import org.apache.fop.system.BufferManager;
  +
  +// DOM
  +import org.w3c.dom.Document;
  +import org.w3c.dom.Node;
  +import org.w3c.dom.NamedNodeMap;
  +import org.w3c.dom.Attr;
  +
  +// SAX
  +import org.xml.sax.ContentHandler;
  +import org.xml.sax.InputSource;
  +import org.xml.sax.XMLReader;
  +import org.xml.sax.SAXException;
  +import org.xml.sax.helpers.AttributesImpl;
  +
  +// Java
  +import java.io.*;
  +
  +
  +/**
  + * 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.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 buildFOTree method
  + * is called. Depending on whether DOM or SAX is being used, the
  + * invocation of the method is either buildFOTree(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.setRenderer(new org.apache.fop.render.awt.AWTRenderer(translator));
  + *   driver.buildFOTree(parser, fileInputSource(args[0]));
  + *   driver.format();
  + *   driver.render();
  + * </PRE>
  + */
  +public class Driver {
  +
  +    /** 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;
  +
  +    /** the FO tree builder */
  +    private FOTreeBuilder _treeBuilder;
  +
  +    /** the area tree that is the result of formatting the FO tree */
  +    private AreaTree _areaTree;
  +
  +    /** the renderer to use to output the area tree */
  +    private Renderer _renderer;
  +
  +    /** 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;
  +
  +    /** If true, full error stacks are reported */
  +    private boolean _errorDump = false;
  +
  +    /** the system resources that FOP will use    */
  +    private BufferManager _bufferManager;
  +
  +    /** create a new Driver */
  +    public Driver() {
  +        _stream = null;
  +        _bufferManager = new BufferManager();
  +        _treeBuilder = new FOTreeBuilder();
  +        _treeBuilder.setBufferManager(_bufferManager);
  +        setupDefaultMappings();
  +    }
  +
  +    public Driver(InputSource source, OutputStream stream) {
  +        this();
  +        _source = source;
  +        _stream = stream;
  +    }
  +
  +    /**
  +     * 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() {
  +        _areaTree = null;
  +        _treeBuilder.reset();
  +    }
  +
  +    public boolean hasData() {
  +        return(_treeBuilder.hasData());
  +    }
  +
  +    /**
  +     * Set the error dump option
  +     * @param dump if true, full stacks will be reported to the error log
  +     */
  +    public void setErrorDump(boolean dump) {
  +        _errorDump = dump;
  +    }
  +
  +    /**
  +     * 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) {
  +        _stream = stream;
  +    }
  +
  +    /**
  +     * 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) {
  +        _source = source;
  +    }
  +
  +    /**
  +     * Sets the reader used when reading in the source. If not set,
  +     * this defaults to a basic SAX parser.
  +     */
  +    public void setXMLReader(XMLReader reader) {
  +        _reader = reader;
  +    }
  +
  +
  +    /**
  +     * Sets all the element and property list mappings to their default values.
  +     *
  +     */
  +    public void setupDefaultMappings() {
  +        addElementMapping("org.apache.fop.fo.StandardElementMapping");
  +        addPropertyList ("org.apache.fop.fo.StandardPropertyListMapping");
  +
  +        addElementMapping("org.apache.fop.svg.SVGElementMapping");
  +        addPropertyList ("org.apache.fop.svg.SVGPropertyListMapping");
  +
  +        addElementMapping("org.apache.fop.extensions.ExtensionElementMapping");
  +        addPropertyList ("org.apache.fop.extensions.ExtensionPropertyListMapping");
  +    }
  +
  +    /**
  +     * Set the rendering type to use. Must be one of
  +     * <ul>
  +     *   <li>RENDER_PDF
  +     *   <li>RENDER_AWT
  +     *   <li>RENDER_MIF
  +     *   <li>RENDER_XML
  +     *   <li>RENDER_PCL
  +     *   <li>RENDER_PS
  +     *   <li>RENDER_TXT
  +     * </ul>
  +     * @param renderer the type of renderer to use
  +     */
  +    public void setRenderer(int renderer) throws IllegalArgumentException {
  +        switch (renderer) {
  +            case RENDER_PDF:
  +                setRenderer(new 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(new org.apache.fop.render.pcl.PCLRenderer());
  +                break;
  +            case RENDER_PS:
  +                setRenderer(new org.apache.fop.render.ps.PSRenderer());
  +                break;
  +            case RENDER_TXT:
  +                setRenderer(new org.apache.fop.render.txt.TXTRenderer());
  +                break;
  +            case RENDER_MIF:
  +                setRenderer(new org.apache.fop.render.mif.MIFRenderer());
  +                break;
  +            case RENDER_XML:
  +                setRenderer(new org.apache.fop.render.xml.XMLRenderer());
  +                break;
  +            default:
  +                throw new IllegalArgumentException("Unknown renderer type");
  +        }
  +
  +    }
  +
  +
  +    /**
  +     * Set the Renderer to use
  +     * @param renderer the renderer instance to use
  +     */
  +    public void setRenderer(Renderer renderer) {
  +        _renderer = renderer;
  +    }
  +
  +    public Renderer getRenderer() {
  +        return _renderer;
  +    }
  +
  +    /**
  +     * @deprecated use renderer.setProducer(version) + setRenderer(renderer) or just setRenderer(renderer_type) 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();
  +            _renderer.setProducer(Version.getVersion());
  +        } 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
  +     */
  +    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");
  +        }
  +    }
  +
  +    /**
  +     * Add the PropertyListMapping.
  +     */
  +    public void addPropertyList(PropertyListMapping mapping) {
  +        mapping.addToBuilder(_treeBuilder);
  +    }
  +
  +    /**
  +     * Add the PropertyListMapping with the given class name.
  +     */
  +    public void addPropertyList(String listClassName)
  +    throws IllegalArgumentException {
  +        try {
  +            PropertyListMapping mapping =
  +              (PropertyListMapping) Class.forName(
  +                listClassName).newInstance();
  +            addPropertyList(mapping);
  +
  +        } catch (ClassNotFoundException e) {
  +            throw new IllegalArgumentException("Could not find " +
  +                                               listClassName);
  +        }
  +        catch (InstantiationException e) {
  +            throw new IllegalArgumentException(
  +              "Could not instantiate " + listClassName);
  +        }
  +        catch (IllegalAccessException e) {
  +            throw new IllegalArgumentException("Could not access " +
  +                                               listClassName);
  +        }
  +        catch (ClassCastException e) {
  +            throw new IllegalArgumentException(listClassName + " 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.
  +     */
  +    public ContentHandler getContentHandler() {
  +        return _treeBuilder;
  +    }
  +
  +    /**
  +     * Build the formatting object tree using the given SAX Parser and
  +     * SAX InputSource
  +     */
  +    public synchronized void buildFOTree(XMLReader parser,
  +                                         InputSource source)
  +        throws FOPException {
  +
  +        parser.setContentHandler(_treeBuilder);
  +        try {
  +            parser.parse(source);
  +        } catch (SAXException e) {
  +            if (e.getException() instanceof FOPException) {
  +                throw (FOPException) e.getException();
  +            } else {
  +                throw new FOPException(e);
  +            }
  +        }
  +        catch (IOException e) {
  +            throw new FOPException(e);
  +        }
  +    }
  +
  +    /**
  +     * Build the formatting object tree using the given DOM Document
  +     */
  +    public synchronized void buildFOTree(Document document)
  +        throws FOPException {
  +        try {
  +            DocumentInputSource source = new DocumentInputSource(document);
  +            DocumentReader reader = new DocumentReader();
  +            reader.setContentHandler(_treeBuilder);
  +            reader.parse(source);
  +        } catch (SAXException e) {
  +            throw new FOPException(e);
  +        }
  +        catch (IOException e) {
  +            throw new FOPException(e);
  +        }
  +
  +    }
  +
  +    /**
  +     * Dumps an error
  +     */
  +    public 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();
  +            }
  +        }
  +    }
  +
  +    /* Set up the system buffers */
  +
  +    public void setBufferFile(File bufferFile) {
  +        this._bufferManager.addBufferFile(bufferFile);
  +    }
  +
  +    /**
  +     * format the formatting object tree into an area tree
  +     */
  +    public synchronized void format()
  +        throws FOPException {
  +        FontInfo fontInfo = new FontInfo();
  +        _renderer.setupFontInfo(fontInfo);
  +
  +        _areaTree = new AreaTree();
  +        _areaTree.setFontInfo(fontInfo);
  +
  +        _treeBuilder.format(_areaTree);
  +    }
  +
  +    /**
  +     * render the area tree to the output form
  +     */
  +    public synchronized void render()
  +        throws IOException, FOPException {
  +        _renderer.render(_areaTree, _stream);
  +    }
  +
  +    /**
  +     * Runs the formatting and renderering process using the previously set
  +     * inputsource and outputstream
  +     */
  +    public synchronized void run()
  +        throws IOException, FOPException {
  +        if (_renderer == null) {
  +            setRenderer(RENDER_PDF);
  +        }
  +        if (_source == null) {
  +            throw new FOPException("InputSource is not set.");
  +        }
  +        if (_reader == null) {
  +            if (!(_source instanceof DocumentInputSource)) {
  +                _reader = ConfigurationReader.createParser();
  +            }
  +        }
  +        if (_source instanceof DocumentInputSource) {
  +            buildFOTree(((DocumentInputSource)_source).getDocument());
  +        } else {
  +            buildFOTree(_reader, _source);
  +        }
  +        format();
  +        render();
  +    }
  +
  +}
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-cvs-help@xml.apache.org