You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ar...@locus.apache.org on 2000/07/11 04:33:05 UTC

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

arved       00/07/10 19:33:05

  Modified:    src/org/apache/fop/apps XTCommandLine.java
  Log:
  Just in case
  
  Revision  Changes    Path
  1.8       +60 -3     xml-fop/src/org/apache/fop/apps/XTCommandLine.java
  
  Index: XTCommandLine.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/apps/XTCommandLine.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XTCommandLine.java	2000/06/27 22:13:06	1.7
  +++ XTCommandLine.java	2000/07/11 02:33:04	1.8
  @@ -1,4 +1,4 @@
  -/*-- $Id: XTCommandLine.java,v 1.7 2000/06/27 22:13:06 fotis Exp $ -- 
  +/*-- $Id: XTCommandLine.java,v 1.8 2000/07/11 02:33:04 arved Exp $ -- 
   
    ============================================================================
                      The Apache Software License, Version 1.1
  @@ -67,6 +67,7 @@
   import org.xml.sax.SAXParseException;
   
   // Java
  +import java.io.File;
   import java.io.FileReader;
   import java.io.FileWriter;
   import java.io.PrintWriter;
  @@ -82,7 +83,7 @@
    * treats XSLProcessor as SAXParser
    *
    */
  -public class XTCommandLine extends CommandLine {
  +public class XTCommandLine {
   
       /**
        * mainline method.
  @@ -113,7 +114,7 @@
   	try {
   	    xslProcessor.loadStylesheet(fileInputSource(args[1]));
   
  -	    Driver driver = new Driver();
  +	    XTDriver driver = new XTDriver();
   	    driver.setRenderer("org.apache.fop.render.pdf.PDFRenderer",
   			       version);
   	    driver.addElementMapping("org.apache.fop.fo.StandardElementMapping");
  @@ -127,4 +128,60 @@
   	    System.exit(1);
   	}
       }
  +
  +    /**
  +     * creates a SAX parser, using the value of org.xml.sax.parser
  +     * defaulting to org.apache.xerces.parsers.SAXParser
  +     *
  +     * @return the created SAX parser
  +     */
  +    static Parser createParser() {
  +	String parserClassName =
  +	    System.getProperty("org.xml.sax.parser");
  +	if (parserClassName == null) {
  +	    parserClassName = "com.jclark.xml.sax.Driver";
  +	}
  +	org.apache.fop.messaging.MessageHandler.logln("using SAX parser " + parserClassName);
  +
  +	try {
  +	    return (Parser)
  +		Class.forName(parserClassName).newInstance();
  +	} catch (ClassNotFoundException e) {
  +	    org.apache.fop.messaging.MessageHandler.errorln("Could not find " + parserClassName);
  +	} catch (InstantiationException e) {
  +	    org.apache.fop.messaging.MessageHandler.errorln("Could not instantiate "
  +			       + parserClassName);
  +	} catch (IllegalAccessException e) {
  +	    org.apache.fop.messaging.MessageHandler.errorln("Could not access " + parserClassName);
  +	} catch (ClassCastException e) {
  +	    org.apache.fop.messaging.MessageHandler.errorln(parserClassName + " is not a SAX driver"); 
  +	}
  +	return null;
  +    }
  +
  +    /**
  +     * create an InputSource from a file name
  +     *
  +     * @param filename the name of the file
  +     * @return the InputSource created
  +     */
  +    protected static InputSource fileInputSource(String filename) {
  +	
  +	/* this code adapted from James Clark's in XT */
  +	File file = new File(filename);
  +	String path = file.getAbsolutePath();
  +	String fSep = System.getProperty("file.separator");
  +	if (fSep != null && fSep.length() == 1)
  +	    path = path.replace(fSep.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");
  +	}
  +    }
  +
   }