pbwest 2004/03/05 21:53:16
Modified: src/java/org/apache/fop/apps Tag: FOP_0-20-0_Alt-Design
Driver.java InputHandler.java Fop.java
Added: src/java/org/apache/fop/apps Tag: FOP_0-20-0_Alt-Design
FOPOptions.java FOFileHandler.java
XSLTInputHandler.java
Removed: src/java/org/apache/fop/apps Tag: FOP_0-20-0_Alt-Design
Options.java FOInputHandler.java
Log:
Aligned Alt-Design apps more with HEAD.
Made Configuration instance.
Echoed HEAD in using of InputHandler, FOFileHandler and XSLTInputHandler
Used org.apache.commons.cli.Options for CLI processing.
Revision Changes Path
No revision
No revision
1.9.2.11 +42 -26 xml-fop/src/java/org/apache/fop/apps/Driver.java
Index: Driver.java
===================================================================
RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/Driver.java,v
retrieving revision 1.9.2.10
retrieving revision 1.9.2.11
diff -u -r1.9.2.10 -r1.9.2.11
--- Driver.java 19 Feb 2004 03:11:57 -0000 1.9.2.10
+++ Driver.java 6 Mar 2004 05:53:16 -0000 1.9.2.11
@@ -42,8 +42,34 @@
*/
public class Driver {
+
+ /** private constant to indicate renderer was not defined. */
+ private static final int NOT_SET = 0;
+ /** Render to PDF. OutputStream must be set */
+ public static final int RENDER_PDF = 1;
+ /** Render to a GUI window. No OutputStream neccessary */
+ public static final int RENDER_AWT = 2;
+ /** Render to MIF. OutputStream must be set */
+ public static final int RENDER_MIF = 3;
+ /** Render to XML. OutputStream must be set */
+ public static final int RENDER_XML = 4;
+ /** Render to PRINT. No OutputStream neccessary */
+ public static final int RENDER_PRINT = 5;
+ /** Render to PCL. OutputStream must be set */
+ public static final int RENDER_PCL = 6;
+ /** Render to Postscript. OutputStream must be set */
+ public static final int RENDER_PS = 7;
+ /** Render to Text. OutputStream must be set */
+ public static final int RENDER_TXT = 8;
+ /** Render to SVG. OutputStream must be set */
+ public static final int RENDER_SVG = 9;
+ /** Render to RTF. OutputStream must be set */
+ public static final int RENDER_RTF = 10;
+
/** If true, full error stacks are reported */
- private static boolean _errorDump = false;
+ private boolean _errorDump = false;
+ private Configuration configuration = null;
+ private FOPOptions options = null;
private InputHandler inputHandler;
private XMLReader parser;
@@ -67,9 +93,18 @@
* Error handling, version and logging initialization.
*/
public Driver() {
- _errorDump =
- Configuration.getBooleanValue("debugMode").booleanValue();
String version = Version.getVersion();
+ configuration = new Configuration();
+ options = new FOPOptions(configuration);
+ _errorDump = configuration.isTrue("debugMode");
+ Fop.logger.config(version);
+ }
+
+ public Driver(String[] args, Configuration config, FOPOptions options) {
+ String version = Version.getVersion();
+ configuration = config;
+ this.options = options;
+ _errorDump = configuration.isTrue("debugMode");
Fop.logger.config(version);
}
@@ -103,7 +138,7 @@
* @throws FOPException
*/
public void run () throws FOPException {
- setInputHandler(Options.getInputHandler());
+ setInputHandler(options.getInputHandler());
parser = inputHandler.getParser();
saxSource = inputHandler.getInputSource();
// Setting of namespace-prefixes feature no longer required
@@ -140,26 +175,7 @@
}
/**
- * Gets the parser Class name.
- *
- * @return a String with the value of the property
- * <code>org.xml.sax.parser</code> or the default value
- * <code>org.apache.xerces.parsers.SAXParser</code>.
- */
- public static final String getParserClassName() {
- String parserClassName = null;
- try {
- parserClassName = System.getProperty("org.xml.sax.parser");
- } catch (SecurityException se) {}
-
- if (parserClassName == null) {
- parserClassName = "org.apache.xerces.parsers.SAXParser";
- }
- return parserClassName;
- }
-
- /**
- * Sets the InputHandler for XML imput as specified in Options.
+ * Sets the InputHandler for XML imput as specified in FOPOptions.
* @param inputHandler the InputHandler
*/
public void setInputHandler(InputHandler inputHandler) {
@@ -180,7 +196,7 @@
* Prints stack trace of an exception
* @param e the exception to trace
*/
- public static void dumpError(Exception e) {
+ public void dumpError(Exception e) {
if (_errorDump) {
if (e instanceof SAXException) {
e.printStackTrace();
1.4.2.5 +43 -50 xml-fop/src/java/org/apache/fop/apps/InputHandler.java
Index: InputHandler.java
===================================================================
RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/InputHandler.java,v
retrieving revision 1.4.2.4
retrieving revision 1.4.2.5
diff -u -r1.4.2.4 -r1.4.2.5
--- InputHandler.java 19 Feb 2004 03:11:57 -0000 1.4.2.4
+++ InputHandler.java 6 Mar 2004 05:53:16 -0000 1.4.2.5
@@ -1,86 +1,79 @@
/*
- * $Id$
+ * Copyright 1999-2004 The Apache Software Foundation.
*
- *
- * Copyright 1999-2003 The Apache Software Foundation.
- *
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
- *
- *
*/
+/* $Id$ */
+
package org.apache.fop.apps;
// SAX
-import java.io.File;
-import java.net.URL;
-
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
+// Java
+import java.net.URL;
+import java.io.File;
-abstract public class InputHandler {
+/**
+ * Abstract super class for input handlers.
+ * Should be used to abstract the various possibilities on how input
+ * can be provided to FOP (but actually isn't).
+ */
+public abstract class InputHandler {
+ /**
+ * Get the input source associated with this input handler.
+ * @return the input source
+ */
+ public abstract InputSource getInputSource();
- abstract public InputSource getInputSource();
- abstract public XMLReader getParser() throws FOPException;
+ /**
+ * Get the SAX parser associated with this input handler.
+ * @return the SAX parser
+ * @throws FOPException in case of an error determining the SAX parser
+ */
+ public abstract XMLReader getParser() throws FOPException;
/**
- * create an InputSource from a File
- *
- * @param file the File
- * @return the InputSource created
+ * Creates an InputSource from a URL.
+ * @param url URL to use
+ * @return the newly created InputSource
*/
- static public InputSource fileInputSource(File file) {
+ public static InputSource urlInputSource(URL url) {
+ return new InputSource(url.toString());
+ }
+
+ /**
+ * Creates an <code>InputSource</code> from a <code>File</code>
+ * @param file the <code>File</code>
+ * @return the <code>InputSource</code> created
+ */
+ public static InputSource fileInputSource(File file) {
/* this code adapted from James Clark's in XT */
String path = file.getAbsolutePath();
String fSep = System.getProperty("file.separator");
- if (fSep != null && fSep.length() == 1)
+ if (fSep != null && fSep.length() == 1) {
path = path.replace(fSep.charAt(0), '/');
- if (path.length() > 0 && path.charAt(0) != '/')
+ }
+ if (path.length() > 0 && path.charAt(0) != '/') {
path = '/' + path;
+ }
try {
return new InputSource(new URL("file", null, path).toString());
} catch (java.net.MalformedURLException e) {
throw new Error("unexpected MalformedURLException");
- }
- }
-
- /**
- * 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";
- }
- Fop.logger.config("using SAX parser " + parserClassName);
-
- try {
- 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);
}
}
1.1.2.8 +34 -11 xml-fop/src/java/org/apache/fop/apps/Fop.java
Index: Fop.java
===================================================================
RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/Fop.java,v
retrieving revision 1.1.2.7
retrieving revision 1.1.2.8
diff -u -r1.1.2.7 -r1.1.2.8
--- Fop.java 25 Feb 2004 04:50:17 -0000 1.1.2.7
+++ Fop.java 6 Mar 2004 05:53:16 -0000 1.1.2.8
@@ -20,8 +20,11 @@
package org.apache.fop.apps;
+import java.util.logging.Level;
import java.util.logging.Logger;
+import org.apache.fop.configuration.Configuration;
+
public class Fop {
public static Runtime runtime;
@@ -37,11 +40,18 @@
public static final String fopPackage = "org.apache.fop";
public static final Logger logger = Logger.getLogger(fopPackage);
+ static {
+ logger.setLevel(Level.INFO);
+ }
+
+ public Configuration configuration = new Configuration();
public static void main(String[] args) {
long endtotal, endfree, gctotal, gcfree;
Driver driver;
+ Configuration configuration;
+ FOPOptions options = null;
Boolean bool = null;
runtime = Runtime.getRuntime();
@@ -50,8 +60,9 @@
startTime = System.currentTimeMillis();
try {
- Options.configure(args);
- driver = new Driver();
+ configuration = new Configuration();
+ options = new FOPOptions(configuration, args);
+ driver = new Driver(args, configuration, options);
driver.run();
System.out.println("Back from driver.run()");
System.out.println("Elapsed time: " +
@@ -85,17 +96,29 @@
} catch (FOPException e) {
logger.warning(e.getMessage());
- if ((bool = Options.isDebugMode()) != null
- && bool.booleanValue()) {
- e.printStackTrace();
- }
- } catch (java.io.FileNotFoundException e) {
- logger.warning(e.getMessage());
- if ((bool = Options.isDebugMode()) != null
- && bool.booleanValue()) {
+ if (options.isDebugMode()) {
e.printStackTrace();
}
}
+ }
+
+ /**
+ * Gets the parser Class name.
+ *
+ * @return a String with the value of the property
+ * <code>org.xml.sax.parser</code> or the default value
+ * <code>org.apache.xerces.parsers.SAXParser</code>.
+ */
+ public static final String getParserClassName() {
+ String parserClassName = null;
+ try {
+ parserClassName = System.getProperty("org.xml.sax.parser");
+ } catch (SecurityException se) {}
+
+ if (parserClassName == null) {
+ parserClassName = "org.apache.xerces.parsers.SAXParser";
+ }
+ return parserClassName;
}
private Fop() {
No revision
Index: Fop.java
===================================================================
RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/Fop.java,v
retrieving revision 1.1.2.7
retrieving revision 1.1.2.8
diff -u -r1.1.2.7 -r1.1.2.8
--- Fop.java 25 Feb 2004 04:50:17 -0000 1.1.2.7
+++ Fop.java 6 Mar 2004 05:53:16 -0000 1.1.2.8
@@ -20,8 +20,11 @@
package org.apache.fop.apps;
+import java.util.logging.Level;
import java.util.logging.Logger;
+import org.apache.fop.configuration.Configuration;
+
public class Fop {
public static Runtime runtime;
@@ -37,11 +40,18 @@
public static final String fopPackage = "org.apache.fop";
public static final Logger logger = Logger.getLogger(fopPackage);
+ static {
+ logger.setLevel(Level.INFO);
+ }
+
+ public Configuration configuration = new Configuration();
public static void main(String[] args) {
long endtotal, endfree, gctotal, gcfree;
Driver driver;
+ Configuration configuration;
+ FOPOptions options = null;
Boolean bool = null;
runtime = Runtime.getRuntime();
@@ -50,8 +60,9 @@
startTime = System.currentTimeMillis();
try {
- Options.configure(args);
- driver = new Driver();
+ configuration = new Configuration();
+ options = new FOPOptions(configuration, args);
+ driver = new Driver(args, configuration, options);
driver.run();
System.out.println("Back from driver.run()");
System.out.println("Elapsed time: " +
@@ -85,17 +96,29 @@
} catch (FOPException e) {
logger.warning(e.getMessage());
- if ((bool = Options.isDebugMode()) != null
- && bool.booleanValue()) {
- e.printStackTrace();
- }
- } catch (java.io.FileNotFoundException e) {
- logger.warning(e.getMessage());
- if ((bool = Options.isDebugMode()) != null
- && bool.booleanValue()) {
+ if (options.isDebugMode()) {
e.printStackTrace();
}
}
+ }
+
+ /**
+ * Gets the parser Class name.
+ *
+ * @return a String with the value of the property
+ * <code>org.xml.sax.parser</code> or the default value
+ * <code>org.apache.xerces.parsers.SAXParser</code>.
+ */
+ public static final String getParserClassName() {
+ String parserClassName = null;
+ try {
+ parserClassName = System.getProperty("org.xml.sax.parser");
+ } catch (SecurityException se) {}
+
+ if (parserClassName == null) {
+ parserClassName = "org.apache.xerces.parsers.SAXParser";
+ }
+ return parserClassName;
}
private Fop() {
No revision
Index: Fop.java
===================================================================
RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/Fop.java,v
retrieving revision 1.1.2.7
retrieving revision 1.1.2.8
diff -u -r1.1.2.7 -r1.1.2.8
--- Fop.java 25 Feb 2004 04:50:17 -0000 1.1.2.7
+++ Fop.java 6 Mar 2004 05:53:16 -0000 1.1.2.8
@@ -20,8 +20,11 @@
package org.apache.fop.apps;
+import java.util.logging.Level;
import java.util.logging.Logger;
+import org.apache.fop.configuration.Configuration;
+
public class Fop {
public static Runtime runtime;
@@ -37,11 +40,18 @@
public static final String fopPackage = "org.apache.fop";
public static final Logger logger = Logger.getLogger(fopPackage);
+ static {
+ logger.setLevel(Level.INFO);
+ }
+
+ public Configuration configuration = new Configuration();
public static void main(String[] args) {
long endtotal, endfree, gctotal, gcfree;
Driver driver;
+ Configuration configuration;
+ FOPOptions options = null;
Boolean bool = null;
runtime = Runtime.getRuntime();
@@ -50,8 +60,9 @@
startTime = System.currentTimeMillis();
try {
- Options.configure(args);
- driver = new Driver();
+ configuration = new Configuration();
+ options = new FOPOptions(configuration, args);
+ driver = new Driver(args, configuration, options);
driver.run();
System.out.println("Back from driver.run()");
System.out.println("Elapsed time: " +
@@ -85,17 +96,29 @@
} catch (FOPException e) {
logger.warning(e.getMessage());
- if ((bool = Options.isDebugMode()) != null
- && bool.booleanValue()) {
- e.printStackTrace();
- }
- } catch (java.io.FileNotFoundException e) {
- logger.warning(e.getMessage());
- if ((bool = Options.isDebugMode()) != null
- && bool.booleanValue()) {
+ if (options.isDebugMode()) {
e.printStackTrace();
}
}
+ }
+
+ /**
+ * Gets the parser Class name.
+ *
+ * @return a String with the value of the property
+ * <code>org.xml.sax.parser</code> or the default value
+ * <code>org.apache.xerces.parsers.SAXParser</code>.
+ */
+ public static final String getParserClassName() {
+ String parserClassName = null;
+ try {
+ parserClassName = System.getProperty("org.xml.sax.parser");
+ } catch (SecurityException se) {}
+
+ if (parserClassName == null) {
+ parserClassName = "org.apache.xerces.parsers.SAXParser";
+ }
+ return parserClassName;
}
private Fop() {
1.1.2.1 +1164 -0 xml-fop/src/java/org/apache/fop/apps/Attic/FOPOptions.java
1.2.2.1 +22 -24 xml-fop/src/java/org/apache/fop/apps/FOFileHandler.java
Index: FOFileHandler.java
===================================================================
RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/FOFileHandler.java,v
retrieving revision 1.2
retrieving revision 1.2.2.1
diff -u -r1.2 -r1.2.2.1
--- FOFileHandler.java 27 Feb 2004 17:39:05 -0000 1.2
+++ FOFileHandler.java 6 Mar 2004 05:53:16 -0000 1.2.2.1
@@ -21,12 +21,6 @@
// Imported SAX classes
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
-import org.xml.sax.SAXException;
-import org.xml.sax.SAXNotSupportedException;
-
-// java
-import javax.xml.parsers.SAXParserFactory;
-import javax.xml.parsers.ParserConfigurationException;
import java.io.File;
import java.net.URL;
@@ -74,26 +68,30 @@
}
/**
- * Creates <code>XMLReader</code> object using default
- * <code>SAXParserFactory</code>
- * @return the created <code>XMLReader</code>
- * @throws FOPException if the parser couldn't be created or configured for
proper operation.
+ * creates a SAX parser, using the value of org.xml.sax.parser
+ * defaulting to org.apache.xerces.parsers.SAXParser
+ *
+ * @return the created SAX parser
*/
protected static XMLReader createParser() throws FOPException {
+ String parserClassName = System.getProperty("org.xml.sax.parser");
+ if (parserClassName == null) {
+ parserClassName = "org.apache.xerces.parsers.SAXParser";
+ }
+ Fop.logger.config("using SAX parser " + parserClassName);
+
try {
- SAXParserFactory factory = SAXParserFactory.newInstance();
- factory.setNamespaceAware(true);
- factory.setFeature(
- "http://xml.org/sax/features/namespace-prefixes", true);
- return factory.newSAXParser().getXMLReader();
- } catch (SAXNotSupportedException se) {
- throw new FOPException("Error: You need a parser which allows the"
- + " http://xml.org/sax/features/namespace-prefixes"
- + " feature to be set to true to support namespaces", se);
- } catch (SAXException se) {
- throw new FOPException("Couldn't create XMLReader", se);
- } catch (ParserConfigurationException pce) {
- throw new FOPException("Couldn't create XMLReader", pce);
+ return (XMLReader)Class.forName(parserClassName).newInstance();
+ } catch (ClassNotFoundException e) {
+ throw new FOPException(e);
+ } catch (InstantiationException e) {
+ throw new FOPException("Could not instantiate "
+ + parserClassName, e);
+ } catch (IllegalAccessException e) {
+ throw new FOPException("Could not access " + parserClassName, e);
+ } catch (ClassCastException e) {
+ throw new FOPException(parserClassName + " is not a SAX driver",
+ e);
}
}
1.12.2.1 +8 -13 xml-fop/src/java/org/apache/fop/apps/XSLTInputHandler.java
Index: XSLTInputHandler.java
===================================================================
RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/apps/XSLTInputHandler.java,v
retrieving revision 1.12
retrieving revision 1.12.2.1
diff -u -r1.12 -r1.12.2.1
--- XSLTInputHandler.java 27 Feb 2004 17:39:05 -0000 1.12
+++ XSLTInputHandler.java 6 Mar 2004 05:53:16 -0000 1.12.2.1
@@ -24,7 +24,6 @@
// Imported TraX classes
import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamSource;
import javax.xml.transform.sax.SAXResult;
@@ -52,9 +51,8 @@
* @param xsltfile XSLT file
* @param params Vector of command-line parameters (name, value,
* name, value, ...) for XSL stylesheet
- * @throws FOPException if initializing the Transformer fails
*/
- public XSLTInputHandler(File xmlfile, File xsltfile, Vector params) throws
FOPException {
+ public XSLTInputHandler(File xmlfile, File xsltfile, Vector params) {
this.xmlSource = new StreamSource(xmlfile);
this.xsltSource = new StreamSource(xsltfile);
xsltParams = params;
@@ -64,10 +62,9 @@
* Constructor for files as input
* @param xmlfile XML file
* @param xsltfile XSLT file
- * @throws FOPException if initializing the Transformer fails
* @deprecated Use JAXP instead.
*/
- public XSLTInputHandler(File xmlfile, File xsltfile) throws FOPException {
+ public XSLTInputHandler(File xmlfile, File xsltfile) {
this.xmlSource = new StreamSource(xmlfile);
this.xsltSource = new StreamSource(xsltfile);
}
@@ -76,10 +73,9 @@
* Constructor with URIs/URLs as input.
* @param xmlURL XML URL
* @param xsltURL XSLT URL
- * @throws FOPException if initializing the Transformer fails
* @deprecated Use JAXP instead.
*/
- public XSLTInputHandler(String xmlURL, String xsltURL) throws FOPException {
+ public XSLTInputHandler(String xmlURL, String xsltURL) {
this.xmlSource = new StreamSource(xmlURL);
this.xsltSource = new StreamSource(xsltURL);
}
@@ -88,11 +84,9 @@
* Constructor with InputSources as input.
* @param xmlSource XML InputSource
* @param xsltSource XSLT InputSource
- * @throws FOPException if initializing the Transformer fails
* @deprecated Use JAXP instead.
*/
- public XSLTInputHandler(InputSource xmlSource, InputSource xsltSource)
- throws FOPException {
+ public XSLTInputHandler(InputSource xmlSource, InputSource xsltSource) {
this.xmlSource = new StreamSource(xmlSource.getByteStream(),
xmlSource.getSystemId());
this.xsltSource = new StreamSource(xsltSource.getByteStream(),
@@ -128,12 +122,13 @@
* XMLReaders or XMLFilters
* @throws FOPException if setting up the XMLFilter fails
*/
- public static XMLFilter getXMLFilter(Source xsltSource, Vector inParams) throws
FOPException {
+ public static XMLFilter getXMLFilter(Source xsltSource, Vector inParams)
+ throws FOPException {
try {
// Instantiate a TransformerFactory.
TransformerFactory tFactory = TransformerFactory.newInstance();
- // Determine whether the TransformerFactory supports The use of
SAXSource
- // and SAXResult
+ // Determine whether the TransformerFactory supports the use of
+ // SAXSource and SAXResult
if (tFactory.getFeature(SAXSource.FEATURE)
&& tFactory.getFeature(SAXResult.FEATURE)) {
// Cast the TransformerFactory to SAXTransformerFactory.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]