diff options
author | Tore Engvig <tore@apache.org> | 2001-07-30 20:29:35 +0000 |
---|---|---|
committer | Tore Engvig <tore@apache.org> | 2001-07-30 20:29:35 +0000 |
commit | e0edd215721150e6c04ac49706622d6189cb0b42 (patch) | |
tree | 6b59b872d9c0e93f99316ea2f421209b71a97755 /src/org/apache/fop/apps | |
parent | eb57915dec9bcd907e495595efac60dbf3579ad8 (diff) | |
download | xmlgraphics-fop-e0edd215721150e6c04ac49706622d6189cb0b42.tar.gz xmlgraphics-fop-e0edd215721150e6c04ac49706622d6189cb0b42.zip |
Formatted code according to code standards.
Changed license to use short license.
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194380 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache/fop/apps')
-rw-r--r-- | src/org/apache/fop/apps/AWTStarter.java | 47 | ||||
-rw-r--r-- | src/org/apache/fop/apps/CommandLineOptions.java | 498 | ||||
-rw-r--r-- | src/org/apache/fop/apps/CommandLineStarter.java | 54 | ||||
-rw-r--r-- | src/org/apache/fop/apps/Driver.java | 270 | ||||
-rw-r--r-- | src/org/apache/fop/apps/ErrorHandler.java | 59 | ||||
-rw-r--r-- | src/org/apache/fop/apps/FOInputHandler.java | 12 | ||||
-rw-r--r-- | src/org/apache/fop/apps/FOPException.java | 143 | ||||
-rw-r--r-- | src/org/apache/fop/apps/Fop.java | 14 | ||||
-rw-r--r-- | src/org/apache/fop/apps/InputHandler.java | 26 | ||||
-rw-r--r-- | src/org/apache/fop/apps/Options.java | 94 | ||||
-rw-r--r-- | src/org/apache/fop/apps/PDFOutputHandler.java | 354 | ||||
-rw-r--r-- | src/org/apache/fop/apps/PrintStarter.java | 29 | ||||
-rw-r--r-- | src/org/apache/fop/apps/Starter.java | 15 | ||||
-rw-r--r-- | src/org/apache/fop/apps/TraxInputHandler.java | 38 | ||||
-rw-r--r-- | src/org/apache/fop/apps/Version.java | 7 | ||||
-rw-r--r-- | src/org/apache/fop/apps/XSLTInputHandler.java | 39 | ||||
-rw-r--r-- | src/org/apache/fop/apps/XTDriver.java | 436 |
17 files changed, 1061 insertions, 1074 deletions
diff --git a/src/org/apache/fop/apps/AWTStarter.java b/src/org/apache/fop/apps/AWTStarter.java index a38edf207..96dc271aa 100644 --- a/src/org/apache/fop/apps/AWTStarter.java +++ b/src/org/apache/fop/apps/AWTStarter.java @@ -1,4 +1,5 @@ -/* $Id$ +/* + * $Id$ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -6,11 +7,10 @@ package org.apache.fop.apps; /* - originally contributed by - Juergen Verwohlt: Juergen.Verwohlt@jCatalog.com, - Rainer Steinkuhle: Rainer.Steinkuhle@jCatalog.com, - Stanislav Gorkhover: Stanislav.Gorkhover@jCatalog.com - + * originally contributed by + * Juergen Verwohlt: Juergen.Verwohlt@jCatalog.com, + * Rainer Steinkuhle: Rainer.Steinkuhle@jCatalog.com, + * Stanislav Gorkhover: Stanislav.Gorkhover@jCatalog.com */ import org.apache.fop.messaging.MessageHandler; import org.apache.fop.viewer.*; @@ -50,20 +50,20 @@ public class AWTStarter extends CommandLineStarter { PreviewDialog frame; AWTRenderer renderer; - public static String TRANSLATION_PATH = "/org/apache/fop/viewer/resources/"; + public static String TRANSLATION_PATH = + "/org/apache/fop/viewer/resources/"; private Translator resource; - public AWTStarter (CommandLineOptions commandLineOptions) - throws FOPException { + public AWTStarter(CommandLineOptions commandLineOptions) + throws FOPException { super(commandLineOptions); init(); } - private void init () { + private void init() { try { - UIManager.setLookAndFeel( - new javax.swing.plaf.metal.MetalLookAndFeel()); + UIManager.setLookAndFeel(new javax.swing.plaf.metal.MetalLookAndFeel()); } catch (Exception e) { e.printStackTrace(); } @@ -73,12 +73,12 @@ public class AWTStarter extends CommandLineStarter { if (language == null) language = System.getProperty("user.language"); - resource = getResourceBundle(TRANSLATION_PATH + "resources." + - language); + resource = getResourceBundle(TRANSLATION_PATH + "resources." + + language); - UserMessage.setTranslator( - getResourceBundle(TRANSLATION_PATH + "messages." + - language)); + UserMessage.setTranslator(getResourceBundle(TRANSLATION_PATH + + "messages." + + language)); resource.setMissingEmphasized(false); renderer = new AWTRenderer(resource); @@ -90,13 +90,13 @@ public class AWTStarter extends CommandLineStarter { } - public void run () throws FOPException { + public void run() throws FOPException { Driver driver = new Driver(); if (errorDump) { driver.setErrorDump(true); } - //init parser + // init parser frame.progress(resource.getString("Init parser") + " ..."); XMLReader parser = inputHandler.getParser(); @@ -126,7 +126,7 @@ public class AWTStarter extends CommandLineStarter { } catch (Exception e) { if (e instanceof FOPException) { - throw (FOPException) e; + throw (FOPException)e; } throw new FOPException(e); } @@ -134,7 +134,7 @@ public class AWTStarter extends CommandLineStarter { } protected PreviewDialog createPreviewDialog(AWTRenderer renderer, - Translator res) { + Translator res) { PreviewDialog frame = new PreviewDialog(renderer, res); frame.validate(); @@ -160,11 +160,12 @@ public class AWTStarter extends CommandLineStarter { URL url = getClass().getResource(path); in = url.openStream(); } catch (Exception ex) { - MessageHandler.logln("Can't find URL to: <" + path + "> " + - ex.getMessage()); + MessageHandler.logln("Can't find URL to: <" + path + "> " + + ex.getMessage()); } return new SecureResourceBundle(in); } + } diff --git a/src/org/apache/fop/apps/CommandLineOptions.java b/src/org/apache/fop/apps/CommandLineOptions.java index 61b78a4d0..c13e65518 100644 --- a/src/org/apache/fop/apps/CommandLineOptions.java +++ b/src/org/apache/fop/apps/CommandLineOptions.java @@ -1,4 +1,5 @@ -/* $Id$ +/* + * $Id$ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -6,7 +7,7 @@ package org.apache.fop.apps; -//java +// java import java.util.Vector; import java.io.File; import java.io.FileNotFoundException; @@ -17,29 +18,29 @@ import org.apache.fop.configuration.Configuration; import org.apache.fop.apps.FOPException; /** - * Options parses the commandline arguments + * Options parses the commandline arguments */ public class CommandLineOptions { /* input / output not set */ private static final int NOT_SET = 0; - /* input: fo file */ + /* input: fo file */ private static final int FO_INPUT = 1; - /* input: xml+xsl file */ + /* input: xml+xsl file */ private static final int XSLT_INPUT = 2; - /* output: pdf file */ + /* output: pdf file */ private static final int PDF_OUTPUT = 1; - /* output: screen using swing */ + /* output: screen using swing */ private static final int AWT_OUTPUT = 2; - /* output: mif file */ + /* output: mif file */ private static final int MIF_OUTPUT = 3; - /* output: sent swing rendered file to printer */ + /* output: sent swing rendered file to printer */ private static final int PRINT_OUTPUT = 4; - /* output: pcl file */ + /* output: pcl file */ private static final int PCL_OUTPUT = 5; - /* output: postscript file */ + /* output: postscript file */ private static final int PS_OUTPUT = 6; - /* output: text file */ + /* output: text file */ private static final int TXT_OUTPUT = 7; /* System buffers */ @@ -48,29 +49,29 @@ public class CommandLineOptions { /* System buffers */ private static final int AREA_OUTPUT = 9; - /* use debug mode*/ + /* use debug mode */ Boolean errorDump = new Boolean(false); /* show configuration information */ Boolean dumpConfiguration = new Boolean(false); - /*suppress any progress information */ + /* 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); - /* name of user configuration file*/ + /* name of user configuration file */ File userConfigFile = null; - /* name of input fo file */ + /* name of input fo file */ File fofile = null; - /* name of xsltfile (xslt transformation as input)*/ + /* name of xsltfile (xslt transformation as input) */ File xsltfile = null; - /* name of xml file (xslt transformation as input)*/ + /* name of xml file (xslt transformation as input) */ File xmlfile = null; - /* name of output file */ + /* name of output file */ File outfile = null; /* name of buffer file */ File bufferFile = null; /* input mode */ int inputmode = NOT_SET; - /*output mode */ + /* output mode */ int outputmode = NOT_SET; /* buffer mode */ int buffermode = NOT_SET; @@ -79,14 +80,14 @@ public class CommandLineOptions { private java.util.Hashtable rendererOptions; - public CommandLineOptions (String [] args) throws FOPException, - FileNotFoundException { + public CommandLineOptions(String[] args) + throws FOPException, FileNotFoundException { boolean optionsParsed = true; rendererOptions = new java.util.Hashtable(); try { optionsParsed = parseOptions(args); if (optionsParsed) { - checkSettings (); + checkSettings(); if (errorDump != null && errorDump.booleanValue()) { debug(); } @@ -94,8 +95,7 @@ public class CommandLineOptions { } catch (FOPException e) { printUsage(); throw e; - } - catch (java.io.FileNotFoundException e) { + } catch (java.io.FileNotFoundException e) { printUsage(); throw e; } @@ -103,29 +103,30 @@ public class CommandLineOptions { } /** - * parses the commandline arguments + * 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); - } else if (args[i].equals("-x") || args[i].equals("--dump-config")) { + } else if (args[i].equals("-x") + || args[i].equals("--dump-config")) { dumpConfiguration = new Boolean(true); } else if (args[i].equals("-q") || args[i].equals("--quiet")) { quiet = new Boolean(true); } else if (args[i].equals("-c")) { - if ((i + 1 == args.length) || - (args[i + 1].charAt(0) == '-')) { + 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"); } else { - userConfigFile = new File (args[i + 1]); + userConfigFile = new File(args[i + 1]); i++; } } else if (args[i].equals("-l")) { - if ((i + 1 == args.length) || - (args[i + 1].charAt(0) == '-')) { + if ((i + 1 == args.length) + || (args[i + 1].charAt(0) == '-')) { throw new FOPException("if you use '-l', you must specify a language"); } else { language = args[i + 1]; @@ -135,17 +136,17 @@ public class CommandLineOptions { suppressLowLevelAreas = new Boolean(true); } else if (args[i].equals("-fo")) { inputmode = FO_INPUT; - if ((i + 1 == args.length) || - (args[i + 1].charAt(0) == '-')) { + if ((i + 1 == args.length) + || (args[i + 1].charAt(0) == '-')) { throw new FOPException("you must specify the fo file for the '-fo' option"); } else { - fofile = new File (args[i + 1]); + fofile = new File(args[i + 1]); i++; } } else if (args[i].equals("-xsl")) { inputmode = XSLT_INPUT; - if ((i + 1 == args.length) || - (args[i + 1].charAt(0) == '-')) { + if ((i + 1 == args.length) + || (args[i + 1].charAt(0) == '-')) { throw new FOPException("you must specify the stylesheet file for the '-xsl' option"); } else { xsltfile = new File(args[i + 1]); @@ -153,8 +154,8 @@ public class CommandLineOptions { } } else if (args[i].equals("-xml")) { inputmode = XSLT_INPUT; - if ((i + 1 == args.length) || - (args[i + 1].charAt(0) == '-')) { + if ((i + 1 == args.length) + || (args[i + 1].charAt(0) == '-')) { throw new FOPException("you must specify the input file for the '-xml' option"); } else { xmlfile = new File(args[i + 1]); @@ -164,17 +165,17 @@ public class CommandLineOptions { setOutputMode(AWT_OUTPUT); } else if (args[i].equals("-pdf")) { setOutputMode(PDF_OUTPUT); - if ((i + 1 == args.length) || - (args[i + 1].charAt(0) == '-')) { + 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]); + outfile = new File(args[i + 1]); i++; } } else if (args[i].equals("-mif")) { setOutputMode(MIF_OUTPUT); - if ((i + 1 == args.length) || - (args[i + 1].charAt(0) == '-')) { + if ((i + 1 == args.length) + || (args[i + 1].charAt(0) == '-')) { throw new FOPException("you must specify the mif output file"); } else { outfile = new File(args[i + 1]); @@ -182,7 +183,7 @@ public class CommandLineOptions { } } else if (args[i].equals("-print")) { setOutputMode(PRINT_OUTPUT); - //show print help + // show print help if (i + 1 < args.length) { if (args[i + 1].equals("help")) { printUsagePrintOutput(); @@ -191,41 +192,41 @@ public class CommandLineOptions { } } else if (args[i].equals("-pcl")) { setOutputMode(PCL_OUTPUT); - if ((i + 1 == args.length) || - (args[i + 1].charAt(0) == '-')) { + 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]); + 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) == '-')) { + 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]); + outfile = new File(args[i + 1]); i++; } } else if (args[i].equals("-txt")) { setOutputMode(TXT_OUTPUT); - if ((i + 1 == args.length) || - (args[i + 1].charAt(0) == '-')) { + if ((i + 1 == args.length) + || (args[i + 1].charAt(0) == '-')) { throw new FOPException("you must specify the text output file"); } else { - outfile = new File (args[i + 1]); + outfile = new File(args[i + 1]); i++; } } else if (args[i].charAt(0) != '-') { if (inputmode == NOT_SET) { inputmode = FO_INPUT; - fofile = new File (args[i]); + fofile = new File(args[i]); } else if (outputmode == NOT_SET) { 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")) { if (buffermode == NOT_SET) { @@ -234,21 +235,21 @@ public class CommandLineOptions { MessageHandler.errorln("ERROR: you can only set one buffer method"); printUsage(); } - if ((i + 1 == args.length) || - (args[i + 1].charAt(0) == '-')) { + if ((i + 1 == args.length) + || (args[i + 1].charAt(0) == '-')) { MessageHandler.errorln("ERROR: you must specify the buffer output file"); printUsage(); } else { - bufferFile = new File (args[i + 1]); + bufferFile = new File(args[i + 1]); i++; } } else if (args[i].equals("-at")) { setOutputMode(AREA_OUTPUT); - if ((i + 1 == args.length) || - (args[i + 1].charAt(0) == '-')) { + if ((i + 1 == args.length) + || (args[i + 1].charAt(0) == '-')) { throw new FOPException("you must specify the area-tree output file"); } else { - outfile = new File (args[i + 1]); + outfile = new File(args[i + 1]); i++; } } else { @@ -257,7 +258,7 @@ public class CommandLineOptions { } } return true; - } //end parseOptions + } // end parseOptions private void setOutputMode(int mode) throws FOPException { if (outputmode == NOT_SET) { @@ -270,8 +271,7 @@ public class CommandLineOptions { /** * 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"); } @@ -281,7 +281,7 @@ public class CommandLineOptions { } if (inputmode == XSLT_INPUT) { - //check whether xml *and* xslt file have been set + // check whether xml *and* xslt file have been set if (xmlfile == null) { throw new FOPException("XML file must be specified for the tranform mode"); } @@ -289,22 +289,25 @@ public class CommandLineOptions { throw new FOPException("XSLT file must be specified for the tranform mode"); } - //warning if fofile has been set in xslt 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()); + 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()); } 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 "); + throw new FileNotFoundException("xsl file " + + xsltfile.getAbsolutePath() + + " not found "); } } else if (inputmode == FO_INPUT) { @@ -314,53 +317,54 @@ public class CommandLineOptions { 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 + } // end checkSettings /** - * returns the chosen renderer, throws FOPException + * returns the chosen renderer, throws FOPException */ - public int getRenderer () throws FOPException { + public int getRenderer() throws FOPException { switch (outputmode) { - case NOT_SET: - throw new FOPException("Renderer has not been set!"); - case PDF_OUTPUT: - return Driver.RENDER_PDF; - case AWT_OUTPUT: - return Driver.RENDER_AWT; - case MIF_OUTPUT: - return Driver.RENDER_MIF; - case PRINT_OUTPUT: - 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; - default: - throw new FOPException("Invalid Renderer setting!"); + case NOT_SET: + throw new FOPException("Renderer has not been set!"); + case PDF_OUTPUT: + return Driver.RENDER_PDF; + case AWT_OUTPUT: + return Driver.RENDER_AWT; + case MIF_OUTPUT: + return Driver.RENDER_MIF; + case PRINT_OUTPUT: + 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; + default: + throw new FOPException("Invalid Renderer setting!"); } } /** * - **/ - public InputHandler getInputHandler () { + */ + public InputHandler getInputHandler() { switch (inputmode) { - case FO_INPUT: - return new FOInputHandler(fofile); - case XSLT_INPUT: - return new XSLTInputHandler(xmlfile, xsltfile); - default: - return new FOInputHandler(fofile); + case FO_INPUT: + return new FOInputHandler(fofile); + case XSLT_INPUT: + return new XSLTInputHandler(xmlfile, xsltfile); + default: + return new FOInputHandler(fofile); } } @@ -370,35 +374,36 @@ public class CommandLineOptions { public Starter getStarter() throws FOPException { switch (outputmode) { - case AWT_OUTPUT: - try { - return((Starter) Class.forName( - "org.apache.fop.apps.AWTStarter"). - getConstructor( - 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); + case AWT_OUTPUT: + try { + return ((Starter)Class.forName("org.apache.fop.apps.AWTStarter").getConstructor(new Class[] { + CommandLineOptions.class + }).newInstance(new Object[] { + this + })); + } catch (Exception e) { + if (e instanceof FOPException) { + throw (FOPException)e; } - case PRINT_OUTPUT: - try { - return((Starter) Class.forName( - "org.apache.fop.apps.PrintStarter"). - getConstructor( - 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); + throw new FOPException("AWTStarter could not be loaded.", e); + } + case PRINT_OUTPUT: + try { + return ((Starter)Class.forName("org.apache.fop.apps.PrintStarter").getConstructor(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); + } - default: - return new CommandLineStarter(this); + default: + return new CommandLineStarter(this); } } @@ -426,7 +431,7 @@ public class CommandLineOptions { return outfile; } - public File getUserConfigFile () { + public File getUserConfigFile() { return userConfigFile; } @@ -459,132 +464,131 @@ public class CommandLineOptions { */ public File getInputFile() { switch (inputmode) { - case FO_INPUT: - return fofile; - case XSLT_INPUT: - return xmlfile; - default: - return fofile; + case FO_INPUT: + return fofile; + case XSLT_INPUT: + return xmlfile; + default: + return fofile; } } /** - * 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|-ps|-txt|-at|-print] <outfile>\n" + - " [OPTIONS] \n" + " -d debug mode \n" + - " -x dump configuration settings \n" + - " -q quiet mode \n" + - " -c cfg.xml use additional configuration file cfg.xml\n" + - " -l lang the language to use for user information \n" + - " -s for area tree XML, down to block areas only\n\n" + - " [INPUT] \n" + - " infile xsl:fo input file (the same as the next) \n" + - " -fo infile xsl:fo input file \n" + - " -xml infile xml input file, must be used together with -xsl \n" + - " -xsl stylesheet xslt stylesheet \n \n" + - " [OUTPUT] \n" + - " outfile input will be rendered as pdf file into outfile \n" + - " -pdf outfile input will be rendered as pdf file (outfile req'd) \n" + - " -awt input will be displayed on screen \n" + - " -mif outfile input will be rendered as mif file (outfile req'd)\n" + - " -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" + - " see options with \"-print help\" \n\n" + - " [Examples]\n" + " Fop foo.fo foo.pdf \n" + - " Fop -fo foo.fo -pdf foo.pdf (does the same as the previous line)\n" + - " Fop -xsl foo.xsl -xml foo.xml -pdf foo.pdf\n" + - " Fop foo.fo -mif foo.mif\n" + - " Fop foo.fo -print or Fop -print foo.fo \n" + " Fop foo.fo -awt \n"); + MessageHandler.errorln("\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" + + " [INPUT] \n" + + " infile xsl:fo input file (the same as the next) \n" + + " -fo infile xsl:fo input file \n" + + " -xml infile xml input file, must be used together with -xsl \n" + + " -xsl stylesheet xslt stylesheet \n \n" + + " [OUTPUT] \n" + + " outfile input will be rendered as pdf file into outfile \n" + + " -pdf outfile input will be rendered as pdf file (outfile req'd) \n" + + " -awt input will be displayed on screen \n" + + " -mif outfile input will be rendered as mif file (outfile req'd)\n" + + " -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" + + " see options with \"-print help\" \n\n" + + " [Examples]\n" + " Fop foo.fo foo.pdf \n" + + " Fop -fo foo.fo -pdf foo.pdf (does the same as the previous line)\n" + + " Fop -xsl foo.xsl -xml foo.xml -pdf foo.pdf\n" + + " Fop foo.fo -mif foo.mif\n" + + " Fop foo.fo -print or Fop -print foo.fo \n" + + " Fop foo.fo -awt \n"); } /** - * 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] " + - " org.apache.fop.apps.Fop (..) -print \n" + - "Example:\n" + "java -Dstart=1 -Dend=2 org.apache.Fop.apps.Fop infile.fo -print "); + MessageHandler.errorln("USAGE: -print [-Dstart=i] [-Dend=i] [-Dcopies=i] [-Deven=true|false] " + + " org.apache.fop.apps.Fop (..) -print \n" + + "Example:\n" + + "java -Dstart=1 -Dend=2 org.apache.Fop.apps.Fop infile.fo -print "); } /** * debug mode. outputs all commandline settings */ - private void debug () { + private void debug() { System.out.print("Input mode: "); switch (inputmode) { - case NOT_SET: - MessageHandler.logln("not set"); - break; - case FO_INPUT: - MessageHandler.logln("FO "); - MessageHandler.logln("fo input file: " + fofile.toString()); - break; - case XSLT_INPUT: - MessageHandler.logln("xslt transformation"); - MessageHandler.logln("xml input file: " + - xmlfile.toString()); - MessageHandler.logln("xslt stylesheet: " + - xsltfile.toString()); - break; - default: - MessageHandler.logln("unknown input type"); + case NOT_SET: + MessageHandler.logln("not set"); + break; + case FO_INPUT: + MessageHandler.logln("FO "); + MessageHandler.logln("fo input file: " + fofile.toString()); + break; + case XSLT_INPUT: + MessageHandler.logln("xslt transformation"); + MessageHandler.logln("xml input file: " + xmlfile.toString()); + MessageHandler.logln("xslt stylesheet: " + xsltfile.toString()); + break; + default: + MessageHandler.logln("unknown input type"); } System.out.print("Output mode: "); switch (outputmode) { - case NOT_SET: - MessageHandler.logln("not set"); - break; - case PDF_OUTPUT: - MessageHandler.logln("pdf"); - MessageHandler.logln("output file: " + outfile.toString()); - break; - case AWT_OUTPUT: - MessageHandler.logln("awt on screen"); - if (outfile != null) { - MessageHandler.logln("ERROR: awt mode, but outfile is set:"); - MessageHandler.logln("out file: " + outfile.toString()); - } - break; - case MIF_OUTPUT: - MessageHandler.logln("mif"); - MessageHandler.logln("output file: " + outfile.toString()); - break; - case PRINT_OUTPUT: - MessageHandler.logln("print directly"); - if (outfile != null) { - MessageHandler.logln("ERROR: print mode, but outfile is set:"); - MessageHandler.logln("out file: " + outfile.toString()); - } - break; - case PCL_OUTPUT: - 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()); - break; - default: - MessageHandler.logln("unknown input type"); + case NOT_SET: + MessageHandler.logln("not set"); + break; + case PDF_OUTPUT: + MessageHandler.logln("pdf"); + MessageHandler.logln("output file: " + outfile.toString()); + break; + case AWT_OUTPUT: + MessageHandler.logln("awt on screen"); + if (outfile != null) { + MessageHandler.logln("ERROR: awt mode, but outfile is set:"); + MessageHandler.logln("out file: " + outfile.toString()); + } + break; + case MIF_OUTPUT: + MessageHandler.logln("mif"); + MessageHandler.logln("output file: " + outfile.toString()); + break; + case PRINT_OUTPUT: + MessageHandler.logln("print directly"); + if (outfile != null) { + MessageHandler.logln("ERROR: print mode, but outfile is set:"); + MessageHandler.logln("out file: " + outfile.toString()); + } + break; + case PCL_OUTPUT: + 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()); + break; + default: + MessageHandler.logln("unknown input type"); } MessageHandler.logln("OPTIONS"); if (userConfigFile != null) { - MessageHandler.logln("user configuration file: " + - userConfigFile.toString()); + MessageHandler.logln("user configuration file: " + + userConfigFile.toString()); } else { MessageHandler.logln("no user configuration file is used [default]"); } @@ -606,19 +610,21 @@ public class CommandLineOptions { } - //debug: create class and output all settings - public static void main (String args[]) { + // 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]+"<"); - }*/ + * for (int i = 0; i < args.length; i++) { + * MessageHandler.logln(">"+args[i]+"<"); + * } + */ try { - CommandLineOptions options = new CommandLineOptions (args); + CommandLineOptions options = new CommandLineOptions(args); } catch (Exception e) { e.printStackTrace(); } - //options.debug(); + // options.debug(); } + } diff --git a/src/org/apache/fop/apps/CommandLineStarter.java b/src/org/apache/fop/apps/CommandLineStarter.java index 7565df347..648365826 100644 --- a/src/org/apache/fop/apps/CommandLineStarter.java +++ b/src/org/apache/fop/apps/CommandLineStarter.java @@ -1,3 +1,10 @@ +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + */ + package org.apache.fop.apps; // SAX @@ -16,58 +23,55 @@ import org.apache.fop.messaging.MessageHandler; import org.apache.fop.configuration.Configuration; /** - * super class for all classes which start Fop from the commandline + * super class for all classes which start Fop from the commandline */ public class CommandLineStarter extends Starter { - + CommandLineOptions commandLineOptions; - boolean errorDump; - - public CommandLineStarter (CommandLineOptions commandLineOptions) - throws FOPException - { + boolean errorDump; + + public CommandLineStarter(CommandLineOptions commandLineOptions) + throws FOPException { this.commandLineOptions = commandLineOptions; - options.setCommandLineOptions(commandLineOptions); - errorDump = Configuration.getBooleanValue("debugMode").booleanValue(); - super.setInputHandler(commandLineOptions.getInputHandler()); + options.setCommandLineOptions(commandLineOptions); + errorDump = Configuration.getBooleanValue("debugMode").booleanValue(); + super.setInputHandler(commandLineOptions.getInputHandler()); } - + /** * Run the format. * @exception FOPException if there is an error during processing */ - public void run() - throws FOPException - { + public void run() throws FOPException { String version = Version.getVersion(); MessageHandler.logln(version); XMLReader parser = inputHandler.getParser(); setParserFeatures(parser); - - Driver driver = new Driver(); - driver.setBufferFile(commandLineOptions.getBufferFile()); + + Driver driver = new Driver(); + driver.setBufferFile(commandLineOptions.getBufferFile()); if (errorDump) { driver.setErrorDump(true); } - + try { driver.setRenderer(commandLineOptions.getRenderer()); - driver.getRenderer().setOptions(commandLineOptions.getRendererOptions()); + driver.getRenderer().setOptions(commandLineOptions.getRendererOptions()); driver.buildFOTree(parser, inputHandler.getInputSource()); driver.format(); driver.setOutputStream(new FileOutputStream(commandLineOptions.getOutputFile())); driver.render(); System.exit(0); } catch (Exception e) { - if (e instanceof FOPException) { - throw (FOPException) e; - } - throw new FOPException(e); - } + if (e instanceof FOPException) { + throw (FOPException)e; + } + throw new FOPException(e); + } } - + } diff --git a/src/org/apache/fop/apps/Driver.java b/src/org/apache/fop/apps/Driver.java index b263e2d99..60c250176 100644 --- a/src/org/apache/fop/apps/Driver.java +++ b/src/org/apache/fop/apps/Driver.java @@ -1,4 +1,5 @@ -/* $Id$ +/* + * $Id$ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -47,12 +48,11 @@ import java.util.*; * 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(); + * 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 @@ -78,76 +78,109 @@ import java.util.*; * 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(); + * 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 */ + /** + * Render to PDF. OutputStream must be set + */ public static final int RENDER_PDF = 1; - /** Render to a GUI window. No OutputStream neccessary */ + /** + * Render to a GUI window. No OutputStream neccessary + */ public static final int RENDER_AWT = 2; - /** Render to MIF. OutputStream must be set */ + /** + * Render to MIF. OutputStream must be set + */ public static final int RENDER_MIF = 3; - /** Render to XML. OutputStream must be set */ + /** + * Render to XML. OutputStream must be set + */ public static final int RENDER_XML = 4; - /** Render to PRINT. No OutputStream neccessary */ + /** + * Render to PRINT. No OutputStream neccessary + */ public static final int RENDER_PRINT = 5; - /** Render to PCL. OutputStream must be set */ + /** + * Render to PCL. OutputStream must be set + */ public static final int RENDER_PCL = 6; - /** Render to Postscript. OutputStream must be set */ + /** + * Render to Postscript. OutputStream must be set + */ public static final int RENDER_PS = 7; - /** Render to Text. OutputStream must be set */ + /** + * Render to Text. OutputStream must be set + */ public static final int RENDER_TXT = 8; - /** the FO tree builder */ + /** + * the FO tree builder + */ private FOTreeBuilder _treeBuilder; - /** the area tree that is the result of formatting the FO tree */ + /** + * the area tree that is the result of formatting the FO tree + */ private AreaTree _areaTree; - /** the renderer to use to output the area tree */ + /** + * the renderer to use to output the area tree + */ private Renderer _renderer; - /** the source of the FO file */ + /** + * the source of the FO file + */ private InputSource _source; - /** the stream to use to output the results of the renderer */ + /** + * the stream to use to output the results of the renderer + */ private OutputStream _stream; - /** The XML parser to use when building the FO tree */ + /** + * The XML parser to use when building the FO tree + */ private XMLReader _reader; - /** If true, full error stacks are reported */ + /** + * If true, full error stacks are reported + */ private boolean _errorDump = false; - /** the system resources that FOP will use */ + /** + * the system resources that FOP will use + */ private BufferManager _bufferManager; public static final String getParserClassName() { String parserClassName = null; try { parserClassName = System.getProperty("org.xml.sax.parser"); - } catch(SecurityException se) { - } + } catch (SecurityException se) {} if (parserClassName == null) { parserClassName = "org.apache.xerces.parsers.SAXParser"; } return parserClassName; } - /** create a new Driver */ + /** + * create a new Driver + */ public Driver() { _stream = null; _bufferManager = new BufferManager(); @@ -173,7 +206,7 @@ public class Driver { } public boolean hasData() { - return(_treeBuilder.hasData()); + return (_treeBuilder.hasData()); } /** @@ -221,14 +254,14 @@ public class Driver { addElementMapping("org.apache.fop.extensions.ExtensionElementMapping"); // add mappings from available services - Enumeration providers = Service.providers(org.apache.fop.fo.ElementMapping.class); + Enumeration providers = + Service.providers(org.apache.fop.fo.ElementMapping.class); if (providers != null) { - while(providers.hasMoreElements()) { + while (providers.hasMoreElements()) { String str = (String)providers.nextElement(); try { addElementMapping(str); - } catch (IllegalArgumentException e) { - } + } catch (IllegalArgumentException e) {} } } } @@ -236,42 +269,42 @@ public class Driver { /** * 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 + * <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"); + 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"); } } @@ -306,25 +339,23 @@ public class Driver { * @see #setRenderer(int) */ public void setRenderer(String rendererClassName) - throws IllegalArgumentException { + throws IllegalArgumentException { try { - _renderer = (Renderer) Class.forName( - rendererClassName).newInstance(); + _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"); + 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"); } } @@ -342,25 +373,23 @@ public class Driver { * add the element mapping with the given class name */ public void addElementMapping(String mappingClassName) - throws IllegalArgumentException { + throws IllegalArgumentException { try { - ElementMapping mapping = (ElementMapping) Class.forName( - mappingClassName).newInstance(); + 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"); + 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"); } } @@ -379,21 +408,19 @@ public class Driver { * Build the formatting object tree using the given SAX Parser and * SAX InputSource */ - public synchronized void buildFOTree(XMLReader parser, - InputSource source) - throws FOPException { + 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(); + throw (FOPException)e.getException(); } else { throw new FOPException(e); } - } - catch (IOException e) { + } catch (IOException e) { throw new FOPException(e); } } @@ -402,7 +429,7 @@ public class Driver { * Build the formatting object tree using the given DOM Document */ public synchronized void buildFOTree(Document document) - throws FOPException { + throws FOPException { try { DocumentInputSource source = new DocumentInputSource(document); DocumentReader reader = new DocumentReader(); @@ -410,8 +437,7 @@ public class Driver { reader.parse(source); } catch (SAXException e) { throw new FOPException(e); - } - catch (IOException e) { + } catch (IOException e) { throw new FOPException(e); } @@ -424,13 +450,13 @@ public class Driver { if (_errorDump) { if (e instanceof SAXException) { e.printStackTrace(); - if (((SAXException) e).getException() != null) { - ((SAXException) e).getException().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(); + if (((FOPException)e).getException() != null) { + ((FOPException)e).getException().printStackTrace(); } } else { e.printStackTrace(); @@ -447,8 +473,7 @@ public class Driver { /** * format the formatting object tree into an area tree */ - public synchronized void format() - throws FOPException { + public synchronized void format() throws FOPException { FontInfo fontInfo = new FontInfo(); _renderer.setupFontInfo(fontInfo); @@ -461,8 +486,7 @@ public class Driver { /** * render the area tree to the output form */ - public synchronized void render() - throws IOException, FOPException { + public synchronized void render() throws IOException, FOPException { _renderer.render(_areaTree, _stream); } @@ -470,8 +494,7 @@ public class Driver { * Runs the formatting and renderering process using the previously set * inputsource and outputstream */ - public synchronized void run() - throws IOException, FOPException { + public synchronized void run() throws IOException, FOPException { if (_renderer == null) { setRenderer(RENDER_PDF); } @@ -491,11 +514,13 @@ public class Driver { format(); render(); } + } // code stolen from org.apache.batik.util and modified slightly // does what sun.misc.Service probably does, but it cannot be relied on. // hopefully will be part of standard jdk sometime. + /** * This class loads services present in the class path. */ @@ -505,7 +530,7 @@ class Service { public static synchronized Enumeration providers(Class cls) { ClassLoader cl = cls.getClassLoader(); - String serviceFile = "META-INF/services/"+cls.getName(); + String serviceFile = "META-INF/services/" + cls.getName(); // System.out.println("File: " + serviceFile); @@ -528,8 +553,8 @@ class Service { java.net.URL u = (java.net.URL)e.nextElement(); // System.out.println("URL: " + u); - InputStream is = u.openStream(); - Reader r = new InputStreamReader(is, "UTF-8"); + InputStream is = u.openStream(); + Reader r = new InputStreamReader(is, "UTF-8"); BufferedReader br = new BufferedReader(r); String line = br.readLine(); @@ -540,7 +565,7 @@ class Service { if (idx != -1) line = line.substring(0, idx); - // Trim whitespace. + // Trim whitespace. line = line.trim(); // If nothing left then loop around... @@ -551,7 +576,7 @@ class Service { // System.out.println("Line: " + line); // Try and load the class - //Object obj = cl.loadClass(line).newInstance(); + // Object obj = cl.loadClass(line).newInstance(); // stick it into our vector... v.add(line); } catch (Exception ex) { @@ -565,5 +590,6 @@ class Service { } return v.elements(); } + } diff --git a/src/org/apache/fop/apps/ErrorHandler.java b/src/org/apache/fop/apps/ErrorHandler.java index 79c889897..d559c9357 100644 --- a/src/org/apache/fop/apps/ErrorHandler.java +++ b/src/org/apache/fop/apps/ErrorHandler.java @@ -1,54 +1,13 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ + package org.apache.fop.apps; -/** not implemented yet */ +/** + * not implemented yet + */ public interface ErrorHandler {} diff --git a/src/org/apache/fop/apps/FOInputHandler.java b/src/org/apache/fop/apps/FOInputHandler.java index 5fd055a4c..f2828dd20 100644 --- a/src/org/apache/fop/apps/FOInputHandler.java +++ b/src/org/apache/fop/apps/FOInputHandler.java @@ -1,4 +1,5 @@ -/* $Id$ +/* + * $Id$ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -10,10 +11,10 @@ package org.apache.fop.apps; import org.xml.sax.InputSource; import org.xml.sax.XMLReader; -//fop +// fop import org.apache.fop.messaging.MessageHandler; -//java +// java import java.io.File; /** @@ -22,16 +23,17 @@ import java.io.File; public class FOInputHandler extends InputHandler { File fofile; - public FOInputHandler (File fofile) { + public FOInputHandler(File fofile) { this.fofile = fofile; } - public InputSource getInputSource () { + public InputSource getInputSource() { return super.fileInputSource(fofile); } public XMLReader getParser() throws FOPException { return super.createParser(); } + } diff --git a/src/org/apache/fop/apps/FOPException.java b/src/org/apache/fop/apps/FOPException.java index 765d9eede..f6391ce6c 100644 --- a/src/org/apache/fop/apps/FOPException.java +++ b/src/org/apache/fop/apps/FOPException.java @@ -1,6 +1,7 @@ -/* +/* + * $Id$ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the + * For details on use and redistribution please refer to the * LICENSE file included with these sources." */ @@ -15,9 +16,9 @@ import org.xml.sax.SAXException; public class FOPException extends Exception { private static final String EXCEPTION_SEPARATOR = "\n---------\n"; - + private Throwable _exception; - + /** * create a new FOP Exception * @@ -26,86 +27,82 @@ public class FOPException extends Exception { public FOPException(String message) { super(message); } + public FOPException(Throwable e) { super(e.getMessage()); - setException(e); + setException(e); } - + public FOPException(String message, Throwable e) { super(message); - setException(e); + setException(e); } - - protected void setException(Throwable t) - { - _exception = t; + + protected void setException(Throwable t) { + _exception = t; } - - public Throwable getException() - { - return _exception; + + public Throwable getException() { + return _exception; } - protected Throwable getRootException() - { - Throwable result = _exception; - - if (result instanceof SAXException) { - result = ((SAXException)result).getException(); - } - if (result instanceof java.lang.reflect.InvocationTargetException) { - result = ((java.lang.reflect.InvocationTargetException)result).getTargetException(); - } - if (result != _exception) { - return result; - } - return null; + protected Throwable getRootException() { + Throwable result = _exception; + + if (result instanceof SAXException) { + result = ((SAXException)result).getException(); + } + if (result instanceof java.lang.reflect.InvocationTargetException) { + result = + ((java.lang.reflect.InvocationTargetException)result).getTargetException(); + } + if (result != _exception) { + return result; + } + return null; } - - - public void printStackTrace() - { - synchronized (System.err) { - super.printStackTrace(); - if (_exception != null) { - System.err.println(EXCEPTION_SEPARATOR); - _exception.printStackTrace(); - } - if (getRootException() != null) { - System.err.println(EXCEPTION_SEPARATOR); - getRootException().printStackTrace(); - } - } + + + public void printStackTrace() { + synchronized (System.err) { + super.printStackTrace(); + if (_exception != null) { + System.err.println(EXCEPTION_SEPARATOR); + _exception.printStackTrace(); + } + if (getRootException() != null) { + System.err.println(EXCEPTION_SEPARATOR); + getRootException().printStackTrace(); + } + } } - - public void printStackTrace(java.io.PrintStream stream) - { - synchronized (stream) { - super.printStackTrace(stream); - if (_exception != null) { - stream.println(EXCEPTION_SEPARATOR); - _exception.printStackTrace(stream); - } - if (getRootException() != null) { - System.err.println(EXCEPTION_SEPARATOR); - getRootException().printStackTrace(stream); - } - } + + public void printStackTrace(java.io.PrintStream stream) { + synchronized (stream) { + super.printStackTrace(stream); + if (_exception != null) { + stream.println(EXCEPTION_SEPARATOR); + _exception.printStackTrace(stream); + } + if (getRootException() != null) { + System.err.println(EXCEPTION_SEPARATOR); + getRootException().printStackTrace(stream); + } + } } - - public void printStackTrace(java.io.PrintWriter writer) - { - synchronized (writer) { - super.printStackTrace(writer); - if (_exception != null) { - writer.println(EXCEPTION_SEPARATOR); - _exception.printStackTrace(writer); - } - if (getRootException() != null) { - System.err.println(EXCEPTION_SEPARATOR); - getRootException().printStackTrace(writer); - } - } + + public void printStackTrace(java.io.PrintWriter writer) { + synchronized (writer) { + super.printStackTrace(writer); + if (_exception != null) { + writer.println(EXCEPTION_SEPARATOR); + _exception.printStackTrace(writer); + } + if (getRootException() != null) { + System.err.println(EXCEPTION_SEPARATOR); + getRootException().printStackTrace(writer); + } + } } - + } diff --git a/src/org/apache/fop/apps/Fop.java b/src/org/apache/fop/apps/Fop.java index 801bf8a81..b4ae7d708 100644 --- a/src/org/apache/fop/apps/Fop.java +++ b/src/org/apache/fop/apps/Fop.java @@ -1,4 +1,5 @@ -/* $Id$ +/* + * $Id$ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -9,21 +10,20 @@ package org.apache.fop.apps; import org.apache.fop.messaging.MessageHandler; public class Fop { - public static void main (String [] args) { + public static void main(String[] args) { CommandLineOptions options = null; try { - options = new CommandLineOptions (args); + options = new CommandLineOptions(args); Starter starter = options.getStarter(); starter.run(); } catch (FOPException e) { - MessageHandler.errorln("ERROR: "+e.getMessage()); + MessageHandler.errorln("ERROR: " + e.getMessage()); if (options != null && options.isDebugMode().booleanValue()) { e.printStackTrace(); } - } - catch (java.io.FileNotFoundException e) { - MessageHandler.errorln("ERROR: "+e.getMessage()); + } catch (java.io.FileNotFoundException e) { + MessageHandler.errorln("ERROR: " + e.getMessage()); if (options != null && options.isDebugMode().booleanValue()) { e.printStackTrace(); } diff --git a/src/org/apache/fop/apps/InputHandler.java b/src/org/apache/fop/apps/InputHandler.java index 731e375e9..fe2d7cd7a 100644 --- a/src/org/apache/fop/apps/InputHandler.java +++ b/src/org/apache/fop/apps/InputHandler.java @@ -1,4 +1,5 @@ -/* $Id$ +/* + * $Id$ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -61,22 +62,19 @@ abstract public class InputHandler { MessageHandler.logln("using SAX parser " + parserClassName); try { - return (XMLReader) Class.forName( - parserClassName).newInstance(); + 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); + } 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); } } + } diff --git a/src/org/apache/fop/apps/Options.java b/src/org/apache/fop/apps/Options.java index 9f65b4c78..a6e16f31b 100644 --- a/src/org/apache/fop/apps/Options.java +++ b/src/org/apache/fop/apps/Options.java @@ -1,4 +1,5 @@ -/* $Id$ +/* + * $Id$ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -6,100 +7,95 @@ package org.apache.fop.apps; -//sax +// sax import org.xml.sax.InputSource; -//java +// java import java.io.File; import java.io.InputStream; -//fop +// fop import org.apache.fop.messaging.MessageHandler; import org.apache.fop.configuration.Configuration; import org.apache.fop.configuration.ConfigurationReader; /** - * Options handles loading of configuration files and - * additional setting of commandline options + * Options handles loading of configuration files and + * additional setting of commandline options */ public class Options { boolean errorDump = false; - public Options () throws FOPException { + public Options() throws FOPException { this.loadStandardConfiguration(); - initOptions (); + initOptions(); } - public Options (File userConfigFile) throws FOPException { + public Options(File userConfigFile) throws FOPException { this(); this.loadUserconfiguration(userConfigFile); } - public Options (CommandLineOptions clOptions) throws FOPException - { + public Options(CommandLineOptions clOptions) throws FOPException { this(); this.setCommandLineOptions(clOptions); } - //initializing option settings - void initOptions () { + // initializing option settings + void initOptions() { if (Configuration.getBooleanValue("quiet").booleanValue()) { MessageHandler.setQuiet(true); } if (Configuration.getBooleanValue("debugMode").booleanValue()) { errorDump = true; } - if (Configuration.getBooleanValue( - "dumpConfiguration").booleanValue()) { - Configuration.put("dumpConfiguration","true"); + if (Configuration.getBooleanValue("dumpConfiguration").booleanValue()) { + Configuration.put("dumpConfiguration", "true"); Configuration.dumpConfiguration(); } } - //setting clOptions + // setting clOptions void setCommandLineOptions(CommandLineOptions clOptions) { - //load user configuration file,if there is one + // load user configuration file,if there is one File userConfigFile = clOptions.getUserConfigFile(); if (userConfigFile != null) { this.loadUserconfiguration(userConfigFile); } - //debug mode + // debug mode if (clOptions.isDebugMode() != null) { errorDump = clOptions.isDebugMode().booleanValue(); - Configuration.put("debugMode",new Boolean(errorDump)); + Configuration.put("debugMode", new Boolean(errorDump)); } - //show configuration settings + // show configuration settings boolean dumpConfiguration; if (clOptions.dumpConfiguration() != null) { - dumpConfiguration = - clOptions.dumpConfiguration().booleanValue(); + dumpConfiguration = clOptions.dumpConfiguration().booleanValue(); } else { - dumpConfiguration = Configuration.getBooleanValue( - "dumpConfiguration").booleanValue(); + dumpConfiguration = + Configuration.getBooleanValue("dumpConfiguration").booleanValue(); } if (dumpConfiguration) { - Configuration.put("dumpConfiguration","true"); + Configuration.put("dumpConfiguration", "true"); Configuration.dumpConfiguration(); System.exit(0); } - //quiet mode + // quiet mode if (clOptions.isQuiet() != null) { MessageHandler.setQuiet(clOptions.isQuiet().booleanValue()); } - //set base directory + // set base directory String baseDir = Configuration.getStringValue("baseDir"); if (baseDir == null) { try { - baseDir = new File( - clOptions.getInputFile().getAbsolutePath()). - getParentFile().toURL().toExternalForm(); + baseDir = + new File(clOptions.getInputFile().getAbsolutePath()).getParentFile().toURL().toExternalForm(); Configuration.put("baseDir", baseDir); - } catch (Exception e) { - } + } catch (Exception e) {} } if (errorDump) { MessageHandler.logln("base directory: " + baseDir); @@ -107,7 +103,7 @@ public class Options { } /** - * loads standard configuration file and a user file, if it has been specified + * loads standard configuration file and a user file, if it has been specified */ public void loadStandardConfiguration() throws FOPException { String file = "config.xml"; @@ -116,23 +112,21 @@ public class Options { // Try to use Context Class Loader to load the properties file. try { java.lang.reflect.Method getCCL = - Thread.class.getMethod("getContextClassLoader", - new Class[0]); + Thread.class.getMethod("getContextClassLoader", new Class[0]); if (getCCL != null) { ClassLoader contextClassLoader = - (ClassLoader) getCCL.invoke( - Thread.currentThread(), new Object[0]); - configfile = - contextClassLoader.getResourceAsStream("conf/" + - file); + (ClassLoader)getCCL.invoke(Thread.currentThread(), + new Object[0]); + configfile = contextClassLoader.getResourceAsStream("conf/" + + file); } } catch (Exception e) {} // the entry /conf/config.xml refers to a directory conf which is a sibling of org if (configfile == null) configfile = - ConfigurationReader.class.getResourceAsStream("/conf/"+ - file); + ConfigurationReader.class.getResourceAsStream("/conf/" + + file); if (configfile == null) { throw new FOPException("can't find default configuration file"); } @@ -140,7 +134,7 @@ public class Options { MessageHandler.logln("reading default configuration file"); } ConfigurationReader reader = - new ConfigurationReader (new InputSource(configfile)); + new ConfigurationReader(new InputSource(configfile)); if (errorDump) { reader.setDumpError(true); } @@ -153,20 +147,19 @@ public class Options { } public void loadUserconfiguration(File userConfigFile) { - //read user configuration file + // read user configuration file if (userConfigFile != null) { MessageHandler.logln("reading user configuration file"); - ConfigurationReader reader = new ConfigurationReader ( - InputHandler.fileInputSource(userConfigFile)); + ConfigurationReader reader = + new ConfigurationReader(InputHandler.fileInputSource(userConfigFile)); if (errorDump) { reader.setDumpError(true); } try { reader.start(); } catch (org.apache.fop.apps.FOPException error) { - MessageHandler.errorln( - "Can't find user configuration file " + - userConfigFile); + MessageHandler.errorln("Can't find user configuration file " + + userConfigFile); MessageHandler.errorln("using default values"); if (errorDump) { reader.dumpError(error); @@ -174,6 +167,7 @@ public class Options { } } } + } diff --git a/src/org/apache/fop/apps/PDFOutputHandler.java b/src/org/apache/fop/apps/PDFOutputHandler.java index aadba4b2f..0b39c67c8 100644 --- a/src/org/apache/fop/apps/PDFOutputHandler.java +++ b/src/org/apache/fop/apps/PDFOutputHandler.java @@ -1,3 +1,10 @@ +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + */ + package org.apache.fop.apps; import org.xml.sax.*; @@ -6,182 +13,201 @@ import java.io.*; // FOP import org.apache.fop.fo.XTFOTreeBuilder; -import org.apache.fop.fo.XTElementMapping; +import org.apache.fop.fo.XTElementMapping; import org.apache.fop.layout.AreaTree; import org.apache.fop.layout.FontInfo; import org.apache.fop.render.Renderer; import org.apache.fop.messaging.MessageHandler; -////////////////////////////////////////////////////////////////////////////////////// +// //////////////////////////////////////////////////////////////////////////////////// + /** * A DocumentHandler that writes a PDF representation to an OutputStream. - * + * * Use with James Clark's XT. Just put FOP on your class path and add - * <xsl:output method="fop:org.apache.fop.apps.PDFOutputHandler" - * xmlns:fop="http://www.jclark.com/xt/java"/> + * <xsl:output method="fop:org.apache.fop.apps.PDFOutputHandler" + * xmlns:fop="http://www.jclark.com/xt/java"/> * to your stylesheet. Now XT will automatically call FOP. - * + * */ -public class PDFOutputHandler extends XTFOTreeBuilder implements OutputDocumentHandler { - - /** the area tree that is the result of formatting the FO tree */ - protected AreaTree areaTree; - - /** the renderer to use to output the area tree */ - protected Renderer renderer; - - /** the PrintWriter to use to output the results of the renderer */ - protected PrintWriter writer; - - /** the stream to use to output the results of the renderer */ - protected OutputStream stream; - - private boolean keepOpen; - - ////////////////////////////////////////////////////////////////////////////////////// - /** - */ - public PDFOutputHandler() { - } - - ////////////////////////////////////////////////////////////////////////////////////// - /** - */ - public PDFOutputHandler(OutputStream out) { - this(); - this.stream = out; - } - - ////////////////////////////////////////////////////////////////////////////////////// - /** - */ - public DocumentHandler init(Destination dest, AttributeList atts) throws IOException { - this.stream = dest.getOutputStream("application/pdf", null); - this.keepOpen = dest.keepOpen(); - - String version = org.apache.fop.apps.Version.getVersion(); - setRenderer("org.apache.fop.render.pdf.PDFRenderer", version); - addElementMapping("org.apache.fop.fo.StandardElementMapping"); - addElementMapping("org.apache.fop.svg.SVGElementMapping"); - return this; - } - - ////////////////////////////////////////////////////////////////////////////////////// - /** - * set the class name of the Renderer to use as well as the - * producer string for those renderers that can make use of it - */ - public void setRenderer(String rendererClassName, String producer) { - this.renderer = createRenderer(rendererClassName); - this.renderer.setProducer(producer); - } - - ////////////////////////////////////////////////////////////////////////////////////// - /** - * SAX passthrough, finish rendering the document - */ - public void endDocument() throws SAXException { - super.endDocument(); - - try { - doFormat(); - doRender(); - } catch (IOException io) { - throw new SAXException(io); - } catch (FOPException fop) { - throw new SAXException(fop); +public class PDFOutputHandler extends XTFOTreeBuilder + implements OutputDocumentHandler { + + /** + * the area tree that is the result of formatting the FO tree + */ + protected AreaTree areaTree; + + /** + * the renderer to use to output the area tree + */ + protected Renderer renderer; + + /** + * the PrintWriter to use to output the results of the renderer + */ + protected PrintWriter writer; + + /** + * the stream to use to output the results of the renderer + */ + protected OutputStream stream; + + private boolean keepOpen; + + // //////////////////////////////////////////////////////////////////////////////////// + + /** + */ + public PDFOutputHandler() {} + + // //////////////////////////////////////////////////////////////////////////////////// + + /** + */ + public PDFOutputHandler(OutputStream out) { + this(); + this.stream = out; + } + + // //////////////////////////////////////////////////////////////////////////////////// + + /** + */ + public DocumentHandler init(Destination dest, + AttributeList atts) throws IOException { + this.stream = dest.getOutputStream("application/pdf", null); + this.keepOpen = dest.keepOpen(); + + String version = org.apache.fop.apps.Version.getVersion(); + setRenderer("org.apache.fop.render.pdf.PDFRenderer", version); + addElementMapping("org.apache.fop.fo.StandardElementMapping"); + addElementMapping("org.apache.fop.svg.SVGElementMapping"); + return this; + } + + // //////////////////////////////////////////////////////////////////////////////////// + + /** + * set the class name of the Renderer to use as well as the + * producer string for those renderers that can make use of it + */ + public void setRenderer(String rendererClassName, String producer) { + this.renderer = createRenderer(rendererClassName); + this.renderer.setProducer(producer); } - writer.flush(); - } - - ////////////////////////////////////////////////////////////////////////////////////// - /** - * format the formatting object tree into an area tree - */ - public void doFormat() - throws FOPException { - FontInfo fontInfo = new FontInfo(); - this.renderer.setupFontInfo(fontInfo); - - this.areaTree = new AreaTree(); - this.areaTree.setFontInfo(fontInfo); - - format(areaTree); - } - - ////////////////////////////////////////////////////////////////////////////////////// - /** - * render the area tree to the output form - */ - public void doRender() - throws IOException,FOPException { - this.renderer.render(areaTree, this.stream); - } - - ////////////////////////////////////////////////////////////////////////////////////// - /** - * add the given element mapping. - * - * an element mapping maps element names to Java classes - */ - public void addElementMapping(XTElementMapping mapping) { - mapping.addToBuilder(this); - } - - ////////////////////////////////////////////////////////////////////////////////////// - /** - * add the element mapping with the given class name - */ - public void addElementMapping(String mappingClassName) { - createElementMapping(mappingClassName).addToBuilder(this); - } - - ////////////////////////////////////////////////////////////////////////////////////// - /** - * protected method used by addElementMapping(String) to - * instantiate element mapping class - */ - protected XTElementMapping createElementMapping(String mappingClassName) { - MessageHandler.logln("using element mapping " + mappingClassName); - - try { - return (XTElementMapping) - Class.forName(mappingClassName).newInstance(); - } catch (ClassNotFoundException e) { - MessageHandler.errorln("Could not find " + mappingClassName); - } catch (InstantiationException e) { - MessageHandler.errorln("Could not instantiate " - + mappingClassName); - } catch (IllegalAccessException e) { - MessageHandler.errorln("Could not access " + mappingClassName); - } catch (ClassCastException e) { - MessageHandler.errorln(mappingClassName + " is not an element mapping"); + + // //////////////////////////////////////////////////////////////////////////////////// + + /** + * SAX passthrough, finish rendering the document + */ + public void endDocument() throws SAXException { + super.endDocument(); + + try { + doFormat(); + doRender(); + } catch (IOException io) { + throw new SAXException(io); + } catch (FOPException fop) { + throw new SAXException(fop); + } + writer.flush(); + } + + // //////////////////////////////////////////////////////////////////////////////////// + + /** + * format the formatting object tree into an area tree + */ + public void doFormat() throws FOPException { + FontInfo fontInfo = new FontInfo(); + this.renderer.setupFontInfo(fontInfo); + + this.areaTree = new AreaTree(); + this.areaTree.setFontInfo(fontInfo); + + format(areaTree); } - return null; - } - - ////////////////////////////////////////////////////////////////////////////////////// - /** - * protected method used by setRenderer(String, String) to - * instantiate the Renderer class - */ - protected Renderer createRenderer(String rendererClassName) { - MessageHandler.logln("using renderer " + rendererClassName); - - try { - return (Renderer) - Class.forName(rendererClassName).newInstance(); - } catch (ClassNotFoundException e) { - MessageHandler.errorln("Could not find " + rendererClassName); - } catch (InstantiationException e) { - MessageHandler.errorln("Could not instantiate " - + rendererClassName); - } catch (IllegalAccessException e) { - MessageHandler.errorln("Could not access " + rendererClassName); - } catch (ClassCastException e) { - MessageHandler.errorln(rendererClassName + " is not a renderer"); + + // //////////////////////////////////////////////////////////////////////////////////// + + /** + * render the area tree to the output form + */ + public void doRender() throws IOException, FOPException { + this.renderer.render(areaTree, this.stream); } - return null; - } + + // //////////////////////////////////////////////////////////////////////////////////// + + /** + * add the given element mapping. + * + * an element mapping maps element names to Java classes + */ + public void addElementMapping(XTElementMapping mapping) { + mapping.addToBuilder(this); + } + + // //////////////////////////////////////////////////////////////////////////////////// + + /** + * add the element mapping with the given class name + */ + public void addElementMapping(String mappingClassName) { + createElementMapping(mappingClassName).addToBuilder(this); + } + + // //////////////////////////////////////////////////////////////////////////////////// + + /** + * protected method used by addElementMapping(String) to + * instantiate element mapping class + */ + protected XTElementMapping createElementMapping(String mappingClassName) { + MessageHandler.logln("using element mapping " + mappingClassName); + + try { + return (XTElementMapping)Class.forName(mappingClassName).newInstance(); + } catch (ClassNotFoundException e) { + MessageHandler.errorln("Could not find " + mappingClassName); + } catch (InstantiationException e) { + MessageHandler.errorln("Could not instantiate " + + mappingClassName); + } catch (IllegalAccessException e) { + MessageHandler.errorln("Could not access " + mappingClassName); + } catch (ClassCastException e) { + MessageHandler.errorln(mappingClassName + + " is not an element mapping"); + } + return null; + } + + // //////////////////////////////////////////////////////////////////////////////////// + + /** + * protected method used by setRenderer(String, String) to + * instantiate the Renderer class + */ + protected Renderer createRenderer(String rendererClassName) { + MessageHandler.logln("using renderer " + rendererClassName); + + try { + return (Renderer)Class.forName(rendererClassName).newInstance(); + } catch (ClassNotFoundException e) { + MessageHandler.errorln("Could not find " + rendererClassName); + } catch (InstantiationException e) { + MessageHandler.errorln("Could not instantiate " + + rendererClassName); + } catch (IllegalAccessException e) { + MessageHandler.errorln("Could not access " + rendererClassName); + } catch (ClassCastException e) { + MessageHandler.errorln(rendererClassName + " is not a renderer"); + } + return null; + } + } diff --git a/src/org/apache/fop/apps/PrintStarter.java b/src/org/apache/fop/apps/PrintStarter.java index 3d2c52a0d..c50172c4d 100644 --- a/src/org/apache/fop/apps/PrintStarter.java +++ b/src/org/apache/fop/apps/PrintStarter.java @@ -1,4 +1,5 @@ -/* $Id$ +/* + * $Id$ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -7,9 +8,9 @@ package org.apache.fop.apps; /* - originally contributed by - Stanislav Gorkhover: stanislav.gorkhover@jcatalog.com - jCatalog Software AG + * originally contributed by + * Stanislav Gorkhover: stanislav.gorkhover@jcatalog.com + * jCatalog Software AG */ @@ -43,11 +44,11 @@ import org.apache.fop.messaging.MessageHandler; */ public class PrintStarter extends CommandLineStarter { - public PrintStarter (CommandLineOptions options) throws FOPException { + public PrintStarter(CommandLineOptions options) throws FOPException { super(options); } - public void run () throws FOPException { + public void run() throws FOPException { Driver driver = new Driver(); if (errorDump) { driver.setErrorDump(true); @@ -69,7 +70,7 @@ public class PrintStarter extends CommandLineStarter { driver.render(); } catch (Exception e) { if (e instanceof FOPException) { - throw (FOPException) e; + throw (FOPException)e; } throw new FOPException(e); } @@ -111,8 +112,7 @@ public class PrintStarter extends CommandLineStarter { if (str != null) { try { mode = Boolean.valueOf(str).booleanValue() ? EVEN : ODD; - } catch (Exception e) { - } + } catch (Exception e) {} } } @@ -140,14 +140,13 @@ public class PrintStarter extends CommandLineStarter { Vector numbers = getInvalidPageNumbers(); for (int i = numbers.size() - 1; i > -1; i--) - tree.getPages().removeElementAt( - Integer.parseInt((String) numbers.elementAt(i))); + tree.getPages().removeElementAt(Integer.parseInt((String)numbers.elementAt(i))); } public void renderPage(Page page) { - pageWidth = (int)((float) page.getWidth() / 1000f); - pageHeight = (int)((float) page.getHeight() / 1000f); + pageWidth = (int)((float)page.getWidth() / 1000f); + pageHeight = (int)((float)page.getHeight() / 1000f); super.renderPage(page); } @@ -184,8 +183,8 @@ public class PrintStarter extends CommandLineStarter { } - } // class PrintRenderer -} // class PrintCommandLine + } // class PrintRenderer +} // class PrintCommandLine diff --git a/src/org/apache/fop/apps/Starter.java b/src/org/apache/fop/apps/Starter.java index 130e2f1ac..c0882e93f 100644 --- a/src/org/apache/fop/apps/Starter.java +++ b/src/org/apache/fop/apps/Starter.java @@ -1,4 +1,5 @@ -/* $Id$ +/* + * $Id$ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -28,7 +29,7 @@ public abstract class Starter { InputHandler inputHandler; public Starter() throws FOPException { - options = new Options (); + options = new Options(); } public void setInputHandler(InputHandler inputHandler) { @@ -37,15 +38,15 @@ public abstract class Starter { abstract public void run() throws FOPException; - // setting the parser features - public void setParserFeatures (XMLReader parser) throws FOPException { + // setting the parser features + public void setParserFeatures(XMLReader parser) throws FOPException { try { parser.setFeature("http://xml.org/sax/features/namespace-prefixes", true); } catch (SAXException e) { - throw new FOPException( - "Error in setting up parser feature namespace-prefixes\n" + - "You need a parser which supports SAX version 2",e); + throw new FOPException("Error in setting up parser feature namespace-prefixes\n" + + "You need a parser which supports SAX version 2", e); } } + } diff --git a/src/org/apache/fop/apps/TraxInputHandler.java b/src/org/apache/fop/apps/TraxInputHandler.java index 0b1e10f43..4cebd7521 100644 --- a/src/org/apache/fop/apps/TraxInputHandler.java +++ b/src/org/apache/fop/apps/TraxInputHandler.java @@ -1,4 +1,5 @@ -/* $Id$ +/* + * $Id$ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -39,21 +40,21 @@ public class TraxInputHandler extends InputHandler { File xmlfile, xsltfile; - public TraxInputHandler (File xmlfile, File xsltfile) { + public TraxInputHandler(File xmlfile, File xsltfile) { this.xmlfile = xmlfile; this.xsltfile = xsltfile; } /** - * overwrites the method of the super class to return the xmlfile + * overwrites the method of the super class to return the xmlfile */ - public InputSource getInputSource () { + public InputSource getInputSource() { return fileInputSource(xmlfile); } /** - * overwrites this method of the super class and returns an XMLFilter instead of a - * simple XMLReader which allows chaining of transformations + * overwrites this method of the super class and returns an XMLFilter instead of a + * simple XMLReader which allows chaining of transformations * */ public XMLReader getParser() throws FOPException { @@ -69,21 +70,21 @@ public class TraxInputHandler extends InputHandler { * @param xsltfile An xslt stylesheet * @return XMLFilter an XMLFilter which can be chained together with other XMLReaders or XMLFilters */ - public static XMLFilter getXMLFilter (File xmlfile, - File xsltfile) throws FOPException { + public static XMLFilter getXMLFilter(File xmlfile, + File xsltfile) throws FOPException { try { // Instantiate a TransformerFactory. TransformerFactory tFactory = TransformerFactory.newInstance(); // Determine whether the TransformerFactory supports The use uf SAXSource // and SAXResult - if (tFactory.getFeature(SAXSource.FEATURE) && - tFactory.getFeature(SAXResult.FEATURE)) { + if (tFactory.getFeature(SAXSource.FEATURE) + && tFactory.getFeature(SAXResult.FEATURE)) { // Cast the TransformerFactory to SAXTransformerFactory. SAXTransformerFactory saxTFactory = - ((SAXTransformerFactory) tFactory); + ((SAXTransformerFactory)tFactory); // Create an XMLFilter for each stylesheet. - XMLFilter xmlfilter = saxTFactory.newXMLFilter( - new StreamSource(xsltfile)); + XMLFilter xmlfilter = + saxTFactory.newXMLFilter(new StreamSource(xsltfile)); // Create an XMLReader. XMLReader parser = createParser(); @@ -95,17 +96,16 @@ public class TraxInputHandler extends InputHandler { xmlfilter.setParent(parser); return xmlfilter; } else { - throw new FOPException( - "Your parser doesn't support the features SAXSource and SAXResult." + - "\nMake sure you are using a xsl parser which supports TrAX"); + throw new FOPException("Your parser doesn't support the features SAXSource and SAXResult." + + "\nMake sure you are using a xsl parser which supports TrAX"); } - } - catch (Exception ex) { + } catch (Exception ex) { if (ex instanceof FOPException) { - throw (FOPException) ex; + throw (FOPException)ex; } throw new FOPException(ex); } } + } diff --git a/src/org/apache/fop/apps/Version.java b/src/org/apache/fop/apps/Version.java index cb4e86572..a7d64534b 100644 --- a/src/org/apache/fop/apps/Version.java +++ b/src/org/apache/fop/apps/Version.java @@ -1,12 +1,14 @@ -/* +/* + * $Id$ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the + * For details on use and redistribution please refer to the * LICENSE file included with these sources." */ package org.apache.fop.apps; import org.apache.fop.configuration.Configuration; + /** * class representing the version of FOP. */ @@ -20,4 +22,5 @@ public class Version { public static String getVersion() { return Configuration.getStringValue("version"); } + } diff --git a/src/org/apache/fop/apps/XSLTInputHandler.java b/src/org/apache/fop/apps/XSLTInputHandler.java index 1169e5870..3b035838a 100644 --- a/src/org/apache/fop/apps/XSLTInputHandler.java +++ b/src/org/apache/fop/apps/XSLTInputHandler.java @@ -1,4 +1,5 @@ -/* $Id$ +/* + * $Id$ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. * For details on use and redistribution please refer to the * LICENSE file included with these sources. @@ -30,15 +31,15 @@ public class XSLTInputHandler extends InputHandler { File xmlfile, xsltfile; boolean useOldTransform = false; - public XSLTInputHandler (File xmlfile, File xsltfile) { + public XSLTInputHandler(File xmlfile, File xsltfile) { this.xmlfile = xmlfile; this.xsltfile = xsltfile; } /** - * overwrites the method of the super class to return the xmlfile + * overwrites the method of the super class to return the xmlfile */ - public InputSource getInputSource () { + public InputSource getInputSource() { if (useOldTransform) { try { java.io.Writer writer; @@ -87,26 +88,29 @@ public class XSLTInputHandler extends InputHandler { XMLReader result = null; try { // try trax first - Class transformer = Class.forName("javax.xml.transform.Transformer"); - transformer = Class.forName("org.apache.fop.apps.TraxInputHandler"); - Class[] argTypes = { File.class, File.class }; - Method getFilterMethod = - transformer.getMethod("getXMLFilter",argTypes); - File[] args = {xmlfile, xsltfile}; + Class transformer = + Class.forName("javax.xml.transform.Transformer"); + transformer = + Class.forName("org.apache.fop.apps.TraxInputHandler"); + Class[] argTypes = { + File.class, File.class + }; + Method getFilterMethod = transformer.getMethod("getXMLFilter", + argTypes); + File[] args = { + xmlfile, xsltfile + }; Object obj = getFilterMethod.invoke(null, args); if (obj instanceof XMLReader) { - result = (XMLReader) obj; + result = (XMLReader)obj; } } catch (ClassNotFoundException ex) { throw new FOPException(ex); - } - catch (InvocationTargetException ex) { + } catch (InvocationTargetException ex) { throw new FOPException(ex); - } - catch (IllegalAccessException ex) { + } catch (IllegalAccessException ex) { throw new FOPException(ex); - } - catch (NoSuchMethodException ex) { + } catch (NoSuchMethodException ex) { throw new FOPException(ex); } // otherwise, use DOM documents via our XSLTransform tool class old style @@ -117,5 +121,6 @@ public class XSLTInputHandler extends InputHandler { return result; } + } diff --git a/src/org/apache/fop/apps/XTDriver.java b/src/org/apache/fop/apps/XTDriver.java index b069bbabc..0fd8094d2 100644 --- a/src/org/apache/fop/apps/XTDriver.java +++ b/src/org/apache/fop/apps/XTDriver.java @@ -1,52 +1,8 @@ -/*-- $Id$ -- - - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - - 4. The names "FOP" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber <jtauber@jtauber.com>. For more information on the Apache - Software Foundation, please see <http://www.apache.org/>. - +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ package org.apache.fop.apps; @@ -102,41 +58,55 @@ import java.io.*; * <P>Here is an example use of Driver from CommandLine.java: * * <PRE> - * Driver driver = new Driver(); - * driver.setRenderer("org.apache.fop.render.pdf.PDFRenderer", version); - * driver.addElementMapping("org.apache.fop.fo.StandardElementMapping"); - * driver.addElementMapping("org.apache.fop.svg.SVGElementMapping"); - * driver.setWriter(new PrintWriter(new FileWriter(args[1]))); - * driver.buildFOTree(parser, fileInputSource(args[0])); - * driver.format(); - * driver.render(); + * Driver driver = new Driver(); + * driver.setRenderer("org.apache.fop.render.pdf.PDFRenderer", version); + * driver.addElementMapping("org.apache.fop.fo.StandardElementMapping"); + * driver.addElementMapping("org.apache.fop.svg.SVGElementMapping"); + * driver.setWriter(new PrintWriter(new FileWriter(args[1]))); + * driver.buildFOTree(parser, fileInputSource(args[0])); + * driver.format(); + * driver.render(); * </PRE> */ public class XTDriver { - /** the FO tree builder */ + /** + * the FO tree builder + */ protected XTFOTreeBuilder treeBuilder; - /** the area tree that is the result of formatting the FO tree */ + /** + * the area tree that is the result of formatting the FO tree + */ protected AreaTree areaTree; - /** the renderer to use to output the area tree */ + /** + * the renderer to use to output the area tree + */ protected Renderer renderer; - /** the PrintWriter to use to output the results of the renderer */ + /** + * the PrintWriter to use to output the results of the renderer + */ protected PrintWriter writer; - /** the stream to use to output the results of the renderer */ + /** + * the stream to use to output the results of the renderer + */ protected OutputStream stream; - /** create a new Driver */ + /** + * create a new Driver + */ public XTDriver() { - this.treeBuilder = new XTFOTreeBuilder(); + this.treeBuilder = new XTFOTreeBuilder(); } - - /** set the Renderer to use */ + + /** + * set the Renderer to use + */ public void setRenderer(Renderer renderer) { - this.renderer = renderer; + this.renderer = renderer; } /** @@ -144,8 +114,8 @@ public class XTDriver { * producer string for those renderers that can make use of it */ public void setRenderer(String rendererClassName, String producer) { - this.renderer = createRenderer(rendererClassName); - this.renderer.setProducer(producer); + this.renderer = createRenderer(rendererClassName); + this.renderer.setProducer(producer); } /** @@ -153,38 +123,37 @@ public class XTDriver { * instantiate the Renderer class */ protected Renderer createRenderer(String rendererClassName) { - MessageHandler.logln("using renderer " + rendererClassName); - - try { - return (Renderer) - Class.forName(rendererClassName).newInstance(); - } catch (ClassNotFoundException e) { - MessageHandler.errorln("Could not find " + rendererClassName); - } catch (InstantiationException e) { - MessageHandler.errorln("Could not instantiate " - + rendererClassName); - } catch (IllegalAccessException e) { - MessageHandler.errorln("Could not access " + rendererClassName); - } catch (ClassCastException e) { - MessageHandler.errorln(rendererClassName + " is not a renderer"); - } - return null; + MessageHandler.logln("using renderer " + rendererClassName); + + try { + return (Renderer)Class.forName(rendererClassName).newInstance(); + } catch (ClassNotFoundException e) { + MessageHandler.errorln("Could not find " + rendererClassName); + } catch (InstantiationException e) { + MessageHandler.errorln("Could not instantiate " + + rendererClassName); + } catch (IllegalAccessException e) { + MessageHandler.errorln("Could not access " + rendererClassName); + } catch (ClassCastException e) { + MessageHandler.errorln(rendererClassName + " is not a renderer"); + } + return null; } - + /** * add the given element mapping. * * an element mapping maps element names to Java classes */ public void addElementMapping(ElementMapping mapping) { - mapping.addToBuilder(this.treeBuilder); + mapping.addToBuilder(this.treeBuilder); } - + /** * add the element mapping with the given class name */ public void addElementMapping(String mappingClassName) { - createElementMapping(mappingClassName).addToBuilder(this.treeBuilder); + createElementMapping(mappingClassName).addToBuilder(this.treeBuilder); } /** @@ -192,29 +161,29 @@ public class XTDriver { * instantiate element mapping class */ protected ElementMapping createElementMapping(String mappingClassName) { - MessageHandler.logln("using element mapping " + mappingClassName); - - try { - return (ElementMapping) - Class.forName(mappingClassName).newInstance(); - } catch (ClassNotFoundException e) { - MessageHandler.errorln("Could not find " + mappingClassName); - } catch (InstantiationException e) { - MessageHandler.errorln("Could not instantiate " - + mappingClassName); - } catch (IllegalAccessException e) { - MessageHandler.errorln("Could not access " + mappingClassName); - } catch (ClassCastException e) { - MessageHandler.errorln(mappingClassName + " is not an element mapping"); - } - return null; + MessageHandler.logln("using element mapping " + mappingClassName); + + try { + return (ElementMapping)Class.forName(mappingClassName).newInstance(); + } catch (ClassNotFoundException e) { + MessageHandler.errorln("Could not find " + mappingClassName); + } catch (InstantiationException e) { + MessageHandler.errorln("Could not instantiate " + + mappingClassName); + } catch (IllegalAccessException e) { + MessageHandler.errorln("Could not access " + mappingClassName); + } catch (ClassCastException e) { + MessageHandler.errorln(mappingClassName + + " is not an element mapping"); + } + return null; } /** * add the element mapping with the given class name */ public void addPropertyList(String listClassName) { - createPropertyList(listClassName).addToBuilder(this.treeBuilder); + createPropertyList(listClassName).addToBuilder(this.treeBuilder); } /** @@ -222,22 +191,21 @@ public class XTDriver { * instantiate list mapping class */ protected PropertyListMapping createPropertyList(String listClassName) { - MessageHandler.logln("using property list mapping " + listClassName); - - try { - return (PropertyListMapping) - Class.forName(listClassName).newInstance(); - } catch (ClassNotFoundException e) { - MessageHandler.errorln("Could not find " + listClassName); - } catch (InstantiationException e) { - MessageHandler.errorln("Could not instantiate " - + listClassName); - } catch (IllegalAccessException e) { - MessageHandler.errorln("Could not access " + listClassName); - } catch (ClassCastException e) { - MessageHandler.errorln(listClassName + " is not an property list"); - } - return null; + MessageHandler.logln("using property list mapping " + listClassName); + + try { + return (PropertyListMapping)Class.forName(listClassName).newInstance(); + } catch (ClassNotFoundException e) { + MessageHandler.errorln("Could not find " + listClassName); + } catch (InstantiationException e) { + MessageHandler.errorln("Could not instantiate " + listClassName); + } catch (IllegalAccessException e) { + MessageHandler.errorln("Could not access " + listClassName); + } catch (ClassCastException e) { + MessageHandler.errorln(listClassName + + " is not an property list"); + } + return null; } /** @@ -248,116 +216,115 @@ public class XTDriver { * events but isn't a SAX Parser itself. */ public DocumentHandler getDocumentHandler() { - return this.treeBuilder; + return this.treeBuilder; } /** * build the formatting object tree using the given SAX Parser and * SAX InputSource */ - public void buildFOTree(Parser parser, InputSource source) - throws FOPException { - - parser.setDocumentHandler(this.treeBuilder); - try { - parser.parse(source); - } catch (SAXException e) { - if (e.getException() instanceof FOPException) - throw (FOPException) e.getException(); - else - throw new FOPException(e.getMessage()); - } catch (IOException e) { - throw new FOPException(e.getMessage()); - } + public void buildFOTree(Parser parser, + InputSource source) throws FOPException { + + parser.setDocumentHandler(this.treeBuilder); + try { + parser.parse(source); + } catch (SAXException e) { + if (e.getException() instanceof FOPException) + throw (FOPException)e.getException(); + else + throw new FOPException(e.getMessage()); + } catch (IOException e) { + throw new FOPException(e.getMessage()); + } } /** * build the formatting object tree using the given DOM Document */ - public void buildFOTree(Document document) - throws FOPException { - - /* most of this code is modified from John Cowan's */ - - Node currentNode; - AttributesImpl currentAtts; - - /* temporary array for making Strings into character arrays */ - char[] array = null; - - currentAtts = new AttributesImpl(); - - /* start at the document element */ - currentNode = document; - - try { - while (currentNode != null) { - switch (currentNode.getNodeType()) { - case Node.DOCUMENT_NODE: - this.treeBuilder.startDocument(); - break; - case Node.CDATA_SECTION_NODE: - case Node.TEXT_NODE: - String data = currentNode.getNodeValue(); - int datalen = data.length(); - if (array == null || array.length < datalen) { - /* if the array isn't big enough, make a new - one */ - array = new char[datalen]; - } - data.getChars(0, datalen, array, 0); - this.treeBuilder.characters(array, 0, datalen); - break; - case Node.PROCESSING_INSTRUCTION_NODE: - this.treeBuilder.processingInstruction( - currentNode.getNodeName(), - currentNode.getNodeValue()); - break; - case Node.ELEMENT_NODE: - NamedNodeMap map = currentNode.getAttributes(); - currentAtts.clear(); - for (int i = map.getLength() - 1; i >= 0; i--) { - Attr att = (Attr)map.item(i); - currentAtts.addAttribute("", - att.getName(), - "", - "CDATA", - att.getValue()); - } - this.treeBuilder.startElement( - "", currentNode.getNodeName(), "", currentAtts); - break; - } - - Node nextNode = currentNode.getFirstChild(); - if (nextNode != null) { - currentNode = nextNode; - continue; - } - - while (currentNode != null) { - switch (currentNode.getNodeType()) { - case Node.DOCUMENT_NODE: - this.treeBuilder.endDocument(); - break; - case Node.ELEMENT_NODE: - this.treeBuilder.endElement( - "", currentNode.getNodeName(), "" ); - break; - } - - nextNode = currentNode.getNextSibling(); - if (nextNode != null) { - currentNode = nextNode; - break; - } - - currentNode = currentNode.getParentNode(); - } - } - } catch (SAXException e) { - throw new FOPException(e.getMessage()); - } + public void buildFOTree(Document document) throws FOPException { + + /* most of this code is modified from John Cowan's */ + + Node currentNode; + AttributesImpl currentAtts; + + /* temporary array for making Strings into character arrays */ + char[] array = null; + + currentAtts = new AttributesImpl(); + + /* start at the document element */ + currentNode = document; + + try { + while (currentNode != null) { + switch (currentNode.getNodeType()) { + case Node.DOCUMENT_NODE: + this.treeBuilder.startDocument(); + break; + case Node.CDATA_SECTION_NODE: + case Node.TEXT_NODE: + String data = currentNode.getNodeValue(); + int datalen = data.length(); + if (array == null || array.length < datalen) { + /* + * if the array isn't big enough, make a new + * one + */ + array = new char[datalen]; + } + data.getChars(0, datalen, array, 0); + this.treeBuilder.characters(array, 0, datalen); + break; + case Node.PROCESSING_INSTRUCTION_NODE: + this.treeBuilder.processingInstruction(currentNode.getNodeName(), + currentNode.getNodeValue()); + break; + case Node.ELEMENT_NODE: + NamedNodeMap map = currentNode.getAttributes(); + currentAtts.clear(); + for (int i = map.getLength() - 1; i >= 0; i--) { + Attr att = (Attr)map.item(i); + currentAtts.addAttribute("", att.getName(), "", + "CDATA", att.getValue()); + } + this.treeBuilder.startElement("", + currentNode.getNodeName(), + "", currentAtts); + break; + } + + Node nextNode = currentNode.getFirstChild(); + if (nextNode != null) { + currentNode = nextNode; + continue; + } + + while (currentNode != null) { + switch (currentNode.getNodeType()) { + case Node.DOCUMENT_NODE: + this.treeBuilder.endDocument(); + break; + case Node.ELEMENT_NODE: + this.treeBuilder.endElement("", + currentNode.getNodeName(), + ""); + break; + } + + nextNode = currentNode.getNextSibling(); + if (nextNode != null) { + currentNode = nextNode; + break; + } + + currentNode = currentNode.getParentNode(); + } + } + } catch (SAXException e) { + throw new FOPException(e.getMessage()); + } } /** @@ -365,13 +332,13 @@ public class XTDriver { * (if applicable) */ public void setWriter(PrintWriter writer) { - this.writer = writer; + this.writer = writer; } /** - * set the OutputStream to use to output the result of the Renderer - * (if applicable) - */ + * set the OutputStream to use to output the result of the Renderer + * (if applicable) + */ public void setOutputStream(OutputStream stream) { this.stream = stream; } @@ -379,22 +346,21 @@ public class XTDriver { /** * format the formatting object tree into an area tree */ - public void format() - throws FOPException { - FontInfo fontInfo = new FontInfo(); - this.renderer.setupFontInfo(fontInfo); + public void format() throws FOPException { + FontInfo fontInfo = new FontInfo(); + this.renderer.setupFontInfo(fontInfo); - this.areaTree = new AreaTree(); - this.areaTree.setFontInfo(fontInfo); + this.areaTree = new AreaTree(); + this.areaTree.setFontInfo(fontInfo); - this.treeBuilder.format(areaTree); + this.treeBuilder.format(areaTree); } /** * render the area tree to the output form */ - public void render() - throws IOException, FOPException { - this.renderer.render(areaTree, this.stream); + public void render() throws IOException, FOPException { + this.renderer.render(areaTree, this.stream); } + } |