diff options
author | Keiron Liddle <keiron@apache.org> | 2001-07-04 12:41:09 +0000 |
---|---|---|
committer | Keiron Liddle <keiron@apache.org> | 2001-07-04 12:41:09 +0000 |
commit | 6a99271a265b037c7df93fa1decde3be41a048fb (patch) | |
tree | 0e2cc1dff626002e719935343427f24cf95b2077 /src/org/apache/fop/apps | |
parent | ebc6e7ec5afcf37060db6ef9e87d37ab1802c5d7 (diff) | |
download | xmlgraphics-fop-6a99271a265b037c7df93fa1decde3be41a048fb.tar.gz xmlgraphics-fop-6a99271a265b037c7df93fa1decde3be41a048fb.zip |
fixed line endings
some cleanup also
no code changes
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194328 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache/fop/apps')
-rw-r--r-- | src/org/apache/fop/apps/AWTStarter.java | 27 | ||||
-rw-r--r-- | src/org/apache/fop/apps/FOInputHandler.java | 16 | ||||
-rw-r--r-- | src/org/apache/fop/apps/Fop.java | 46 | ||||
-rw-r--r-- | src/org/apache/fop/apps/InputHandler.java | 42 | ||||
-rw-r--r-- | src/org/apache/fop/apps/Options.java | 1 | ||||
-rw-r--r-- | src/org/apache/fop/apps/PrintStarter.java | 28 | ||||
-rw-r--r-- | src/org/apache/fop/apps/Starter.java | 44 | ||||
-rw-r--r-- | src/org/apache/fop/apps/TraxInputHandler.java | 59 | ||||
-rw-r--r-- | src/org/apache/fop/apps/XSLTInputHandler.java | 172 |
9 files changed, 201 insertions, 234 deletions
diff --git a/src/org/apache/fop/apps/AWTStarter.java b/src/org/apache/fop/apps/AWTStarter.java index d78f1232f..a38edf207 100644 --- a/src/org/apache/fop/apps/AWTStarter.java +++ b/src/org/apache/fop/apps/AWTStarter.java @@ -1,7 +1,7 @@ -/* +/* $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." + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ package org.apache.fop.apps; @@ -54,9 +54,8 @@ public class AWTStarter extends CommandLineStarter { private Translator resource; - public AWTStarter (CommandLineOptions commandLineOptions) - throws FOPException - { + public AWTStarter (CommandLineOptions commandLineOptions) + throws FOPException { super(commandLineOptions); init(); } @@ -91,10 +90,8 @@ public class AWTStarter extends CommandLineStarter { } - public void run () - throws FOPException - { - Driver driver = new Driver(); + public void run () throws FOPException { + Driver driver = new Driver(); if (errorDump) { driver.setErrorDump(true); } @@ -104,7 +101,7 @@ public class AWTStarter extends CommandLineStarter { XMLReader parser = inputHandler.getParser(); if (parser == null) { - throw new FOPException("Unable to create SAX parser"); + throw new FOPException("Unable to create SAX parser"); } setParserFeatures(parser); @@ -128,10 +125,10 @@ public class AWTStarter extends CommandLineStarter { frame.showPage(); } 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/FOInputHandler.java b/src/org/apache/fop/apps/FOInputHandler.java index 6f99e223c..5fd055a4c 100644 --- a/src/org/apache/fop/apps/FOInputHandler.java +++ b/src/org/apache/fop/apps/FOInputHandler.java @@ -1,10 +1,9 @@ -/* +/* $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." + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ - package org.apache.fop.apps; // Imported SAX classes @@ -20,21 +19,18 @@ import java.io.File; /** * Manages input if it is an xsl:fo file */ - public class FOInputHandler extends InputHandler { - File fofile; + File fofile; public FOInputHandler (File fofile) { - this.fofile = fofile; + this.fofile = fofile; } public InputSource getInputSource () { return super.fileInputSource(fofile); } - public XMLReader getParser() - throws FOPException - { + public XMLReader getParser() throws FOPException { return super.createParser(); } } diff --git a/src/org/apache/fop/apps/Fop.java b/src/org/apache/fop/apps/Fop.java index 2f4032deb..801bf8a81 100644 --- a/src/org/apache/fop/apps/Fop.java +++ b/src/org/apache/fop/apps/Fop.java @@ -1,36 +1,34 @@ -/* +/* $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." + * 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.messaging.MessageHandler; public class Fop { public static void main (String [] args) { - CommandLineOptions options = null; - - try { - options = new CommandLineOptions (args); - Starter starter = options.getStarter(); - starter.run(); - } - catch (FOPException e) { - MessageHandler.errorln("ERROR: "+e.getMessage()); - if (options != null && options.isDebugMode().booleanValue()) { - e.printStackTrace(); - } - } - catch (java.io.FileNotFoundException e) { - MessageHandler.errorln("ERROR: "+e.getMessage()); - if (options != null && options.isDebugMode().booleanValue()) { - e.printStackTrace(); - } - } + CommandLineOptions options = null; + + try { + options = new CommandLineOptions (args); + Starter starter = options.getStarter(); + starter.run(); + } catch (FOPException e) { + MessageHandler.errorln("ERROR: "+e.getMessage()); + if (options != null && options.isDebugMode().booleanValue()) { + e.printStackTrace(); + } + } + 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 868a2de15..731e375e9 100644 --- a/src/org/apache/fop/apps/InputHandler.java +++ b/src/org/apache/fop/apps/InputHandler.java @@ -1,10 +1,9 @@ -/* +/* $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." + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ - package org.apache.fop.apps; // SAX @@ -28,11 +27,11 @@ abstract public class InputHandler { /** - * create an InputSource from a File - * - * @param file the File - * @return the InputSource created - */ + * create an InputSource from a File + * + * @param file the File + * @return the InputSource created + */ static public InputSource fileInputSource(File file) { /* this code adapted from James Clark's in XT */ String path = file.getAbsolutePath(); @@ -49,14 +48,12 @@ abstract public class InputHandler { } /** - * creates a SAX parser, using the value of org.xml.sax.parser - * defaulting to org.apache.xerces.parsers.SAXParser - * - * @return the created SAX parser - */ - protected static XMLReader createParser() - throws FOPException - { + * creates a SAX parser, using the value of org.xml.sax.parser + * defaulting to org.apache.xerces.parsers.SAXParser + * + * @return the created SAX parser + */ + protected static XMLReader createParser() throws FOPException { String parserClassName = System.getProperty("org.xml.sax.parser"); if (parserClassName == null) { parserClassName = "org.apache.xerces.parsers.SAXParser"; @@ -67,17 +64,18 @@ abstract public class InputHandler { return (XMLReader) Class.forName( parserClassName).newInstance(); } catch (ClassNotFoundException e) { - throw new FOPException(e); + throw new FOPException(e); } catch (InstantiationException e) { - throw new FOPException("Could not instantiate " + - parserClassName,e); + throw new FOPException("Could not instantiate " + + parserClassName, e); } catch (IllegalAccessException e) { - throw new FOPException("Could not access " + parserClassName,e); + throw new FOPException("Could not access " + + parserClassName, e); } catch (ClassCastException e) { - throw new FOPException(parserClassName + " is not a SAX driver",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 db54cc413..03655e645 100644 --- a/src/org/apache/fop/apps/Options.java +++ b/src/org/apache/fop/apps/Options.java @@ -23,7 +23,6 @@ import org.apache.fop.configuration.ConfigurationReader; * Options handles loading of configuration files and * additional setting of commandline options */ - public class Options { boolean errorDump = false; diff --git a/src/org/apache/fop/apps/PrintStarter.java b/src/org/apache/fop/apps/PrintStarter.java index dbd1269ee..3d2c52a0d 100644 --- a/src/org/apache/fop/apps/PrintStarter.java +++ b/src/org/apache/fop/apps/PrintStarter.java @@ -1,10 +1,9 @@ -/* +/* $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." + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ - package org.apache.fop.apps; /* @@ -44,15 +43,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); @@ -62,7 +57,7 @@ public class PrintStarter extends CommandLineStarter { MessageHandler.errorln(version); XMLReader parser = inputHandler.getParser(); - + setParserFeatures(parser); PrintRenderer renderer = new PrintRenderer(); @@ -73,11 +68,11 @@ public class PrintStarter extends CommandLineStarter { driver.format(); driver.render(); } 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); + } int copies = PrintRenderer.getIntProperty("copies", 1); renderer.setCopies(copies); @@ -193,3 +188,4 @@ public class PrintStarter extends CommandLineStarter { } // class PrintCommandLine + diff --git a/src/org/apache/fop/apps/Starter.java b/src/org/apache/fop/apps/Starter.java index c82ef9323..130e2f1ac 100644 --- a/src/org/apache/fop/apps/Starter.java +++ b/src/org/apache/fop/apps/Starter.java @@ -1,10 +1,9 @@ -/* +/* $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." + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ - package org.apache.fop.apps; // SAX @@ -18,10 +17,8 @@ import java.net.URL; // FOP import org.apache.fop.messaging.MessageHandler; - /** - * - * abstract super class + * abstract super class * Creates a SAX Parser (defaulting to Xerces). * */ @@ -29,29 +26,26 @@ public abstract class Starter { Options options; InputHandler inputHandler; - - public Starter() - throws FOPException - { - options = new Options (); + + public Starter() throws FOPException { + options = new Options (); } - + public void setInputHandler(InputHandler inputHandler) { - this.inputHandler = inputHandler; + this.inputHandler = inputHandler; } - - abstract public void run() - throws FOPException; - - // setting the parser features - public void setParserFeatures (XMLReader parser) - throws FOPException - { + + abstract public void run() throws FOPException; + + // setting the parser features + public void setParserFeatures (XMLReader parser) throws FOPException { try { - parser.setFeature("http://xml.org/sax/features/namespace-prefixes",true); + 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 473d7cdf6..0b1e10f43 100644 --- a/src/org/apache/fop/apps/TraxInputHandler.java +++ b/src/org/apache/fop/apps/TraxInputHandler.java @@ -1,10 +1,9 @@ -/* +/* $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." + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ - package org.apache.fop.apps; @@ -36,44 +35,42 @@ import org.apache.fop.messaging.MessageHandler; * XSLTInputHandler basically takes an xmlfile and transforms it with an xsltfile * and the resulting xsl:fo document is input for Fop. */ - public class TraxInputHandler extends InputHandler { - File xmlfile, xsltfile; + File xmlfile, xsltfile; - public TraxInputHandler (File xmlfile, File xsltfile ) { + public TraxInputHandler (File xmlfile, File xsltfile) { this.xmlfile = xmlfile; - this.xsltfile = xsltfile; + 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 () { 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 { - return this.getXMLFilter(xmlfile,xsltfile); + return this.getXMLFilter(xmlfile, xsltfile); } /** - * Creates from the transformer an instance of an XMLFilter which - * then can be used in a chain with the XMLReader passed to Driver. This way - * during the conversion of the xml file + xslt stylesheet the resulting - * data is fed into Fop. This should help to avoid memory problems - * @param xmlfile The xmlfile containing the text data - * @param xsltfile An xslt stylesheet - * @return XMLFilter an XMLFilter which can be chained together with other XMLReaders or XMLFilters - */ - public static XMLFilter getXMLFilter (File xmlfile, File xsltfile) - throws FOPException - { + * Creates from the transformer an instance of an XMLFilter which + * then can be used in a chain with the XMLReader passed to Driver. This way + * during the conversion of the xml file + xslt stylesheet the resulting + * data is fed into Fop. This should help to avoid memory problems + * @param xmlfile The xmlfile containing the text data + * @param xsltfile An xslt stylesheet + * @return XMLFilter an XMLFilter which can be chained together with other XMLReaders or XMLFilters + */ + public static XMLFilter getXMLFilter (File xmlfile, + File xsltfile) throws FOPException { try { // Instantiate a TransformerFactory. TransformerFactory tFactory = TransformerFactory.newInstance(); @@ -104,11 +101,11 @@ public class TraxInputHandler extends InputHandler { } } catch (Exception ex) { - if (ex instanceof FOPException) { - throw (FOPException)ex; - } - throw new FOPException(ex); - } + if (ex instanceof FOPException) { + throw (FOPException) ex; + } + throw new FOPException(ex); + } } } diff --git a/src/org/apache/fop/apps/XSLTInputHandler.java b/src/org/apache/fop/apps/XSLTInputHandler.java index ccce94447..1169e5870 100644 --- a/src/org/apache/fop/apps/XSLTInputHandler.java +++ b/src/org/apache/fop/apps/XSLTInputHandler.java @@ -1,10 +1,9 @@ -/* +/* $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." + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ - package org.apache.fop.apps; import java.lang.reflect.*; @@ -26,104 +25,97 @@ import org.apache.fop.tools.xslt.XSLTransform; * XSLTInputHandler basically takes an xmlfile and transforms it with an xsltfile * and the resulting xsl:fo document is input for Fop. */ - 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; + 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 () { - if (useOldTransform) { - try { - java.io.Writer writer; - java.io.Reader reader; - File tmpFile = null; - - // create a Writer - // the following is an ugly hack to allow processing of larger files - // if xml file size is larger than 500 kb write the fo:file to disk - if ((xmlfile.length()) > 500000) { - tmpFile = new File(xmlfile.getName()+".fo.tmp"); - writer = new FileWriter(tmpFile); - } else { - writer = new StringWriter(); - } - - XSLTransform.transform(xmlfile.getCanonicalPath(), xsltfile.getCanonicalPath(), writer); - - writer.flush(); - writer.close(); - - if (tmpFile != null) { - reader = new FileReader(tmpFile); - } else { - // create a input source containing the xsl:fo file which can be fed to Fop - reader = new StringReader(writer.toString()); - } - return new InputSource(reader); - } - catch (Exception ex) { - ex.printStackTrace(); - return null; - } - } - else { - return fileInputSource(xmlfile); - } - + if (useOldTransform) { + try { + java.io.Writer writer; + java.io.Reader reader; + File tmpFile = null; + + // create a Writer + // the following is an ugly hack to allow processing of larger files + // if xml file size is larger than 500 kb write the fo:file to disk + if ((xmlfile.length()) > 500000) { + tmpFile = new File(xmlfile.getName() + ".fo.tmp"); + writer = new FileWriter(tmpFile); + } else { + writer = new StringWriter(); + } + + XSLTransform.transform(xmlfile.getCanonicalPath(), + xsltfile.getCanonicalPath(), writer); + + writer.flush(); + writer.close(); + + if (tmpFile != null) { + reader = new FileReader(tmpFile); + } else { + // create a input source containing the xsl:fo file which can be fed to Fop + reader = new StringReader(writer.toString()); + } + return new InputSource(reader); + } catch (Exception ex) { + ex.printStackTrace(); + return null; + } + } else { + return fileInputSource(xmlfile); + } + } /** - * This looks to see if the Trax api is supported and uses that to - * get an XMLFilter. Otherwise, it falls back to using DOM documents - * - */ - public XMLReader getParser() - throws FOPException - { - 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}; - Object obj = getFilterMethod.invoke(null,args); - if (obj instanceof XMLReader) { - result = (XMLReader)obj; - } - } - catch (ClassNotFoundException ex){ - throw new FOPException(ex); - } - catch (InvocationTargetException ex) { - throw new FOPException(ex); - } - catch (IllegalAccessException ex) { - throw new FOPException(ex); - } - catch (NoSuchMethodException ex) { - throw new FOPException(ex); - } - // otherwise, use DOM documents via our XSLTransform tool class old style - if (result == null) { - useOldTransform = true; - result = createParser(); - } - return result; - - } + * This looks to see if the Trax api is supported and uses that to + * get an XMLFilter. Otherwise, it falls back to using DOM documents + * + */ + public XMLReader getParser() throws FOPException { + 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}; + Object obj = getFilterMethod.invoke(null, args); + if (obj instanceof XMLReader) { + result = (XMLReader) obj; + } + } catch (ClassNotFoundException ex) { + throw new FOPException(ex); + } + catch (InvocationTargetException ex) { + throw new FOPException(ex); + } + catch (IllegalAccessException ex) { + throw new FOPException(ex); + } + catch (NoSuchMethodException ex) { + throw new FOPException(ex); + } + // otherwise, use DOM documents via our XSLTransform tool class old style + if (result == null) { + useOldTransform = true; + result = createParser(); + } + return result; - - + } } |