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 fo...@locus.apache.org on 2000/12/12 22:12:21 UTC

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

fotis       00/12/12 13:12:20

  Modified:    src/org/apache/fop/apps XalanCommandLine.java Driver.java
                        CommandLine.java
  Log:
  making XalanCommandLine similar to CommandLine
  
  Revision  Changes    Path
  1.8       +104 -48   xml-fop/src/org/apache/fop/apps/XalanCommandLine.java
  
  Index: XalanCommandLine.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/apps/XalanCommandLine.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- XalanCommandLine.java	2000/12/12 19:18:31	1.7
  +++ XalanCommandLine.java	2000/12/12 21:12:16	1.8
  @@ -92,17 +92,63 @@
    */
   public class XalanCommandLine {
   
  +    private String foFile = null;
  +    private String pdfFile = null;
  +    private String xsltFile = null;
       private String userConfigFile = null;
  +    private String baseDir = null;
   
  -    /** show a full dump on error */  //this should be implemented here too
  +
  +    /** show a full dump on error */ //this should be implemented here too
       private static boolean errorDump = false;
   
  +    public XalanCommandLine(String[] args) {
  +        for (int i = 0; i < args.length; i++) {
  +            if (args[i].equals("-d") || args[i].equals("--full-error-dump")) {
  +                errorDump = true;
  +            } else if ((args[i].charAt(0) == '-') &&
  +                    (args[i].charAt(1) == 'c')) {
  +                userConfigFile = args[i].substring(2);
  +            } else if (args[i].charAt(0) == '-') {
  +                printUsage(args[i]);
  +            } else if (foFile == null) {
  +                foFile = args[i];
  +            } else if (xsltFile == null) {
  +                xsltFile = args[i];
  +            } else if (pdfFile == null) {
  +                pdfFile = args[i];
  +            } else {
  +                printUsage(args[i]);
  +            }
  +        }
  +        if (foFile == null || pdfFile == null || xsltFile == null) {
  +            printUsage(null);
  +        }
  +    }
  +
  +
  +    /*
  +      * shows usage info
  +      */
  +    public void printUsage(String arg) {
  +        if (arg != null) {
  +            MessageHandler.errorln("Unkown argument: '"+ arg + "'");
  +            MessageHandler.errorln("Usage: java [-d] " +
  +                                   "[-cMyConfigFile] " +
  +                                   "org.apache.fop.apps.XalanCommandLine " + "xml-file xslt-file pdf-file");
  +            MessageHandler.errorln("Options:\n" + "  -d or --full-error-dump    Show stack traces upon error");
  +            MessageHandler.errorln("-cMyConfigFile use values in configuration file MyConfigFile instead of/additional to default");
  +
  +            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
  -     */
  +      * 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 XMLReader createParser() {
           String parserClassName = System.getProperty("org.xml.sax.parser");
           if (parserClassName == null) {
  @@ -134,11 +180,11 @@
       }
   
       /**
  -      * create an InputSource from a file name
  -      *
  -      * @param filename the name of the file
  -      * @return the InputSource created
  -      */
  +       * 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 */
  @@ -158,35 +204,27 @@
   
   
       /**
  -      * mainline method
  -      *
  -      * first command line argument is xml input file
  -      * second command line argument is xslt file which commands the conversion from xml to xsl:fo
  -      * third command line argument is the output file
  -      *
  -      * @param command line arguments
  -      */
  -    public static void main(String[] args) {
  -        if (args.length != 3) {
  -            MessageHandler.errorln("usage: java " +
  -                                   "org.apache.fop.apps.XalanCommandLine " + "xml-file xslt-file pdf-file");
  -            System.exit(1);
  +       * mainline method
  +       *
  +       * first command line argument is xml input file
  +       * second command line argument is xslt file which commands the conversion from xml to xsl:fo
  +       * third command line argument is the output file
  +       *
  +       * @param command line arguments
  +       */
  +    public void run () {
  +        Driver driver = new Driver();
  +        if (errorDump)  {
  +            driver.setErrorDump(true);
           }
  -
  -        Driver driver  = new Driver();
           driver.loadStandardConfiguration("standard");
  -//must be redone like CommandLine
  -/*        if (userConfigFile != null)  {
  -            driver.loadUserconfiguration(userConfigFile,"standard");
  +        if (userConfigFile != null) {
  +            driver.loadUserconfiguration(userConfigFile, "standard");
           }
  -*/
  -        driver.setBaseDir(args[0]);
  -
  +        driver.setBaseDir(foFile);
           String version = Version.getVersion();
           MessageHandler.logln(version);
   
  -
  -
           XMLReader parser = createParser();
   
           if (parser == null) {
  @@ -216,8 +254,8 @@
               // create a Writer
               // the following is an ugly hack to allow processing of larger files
               // if xml file size is larger than 700 kb write the fo:file to disk
  -            if ((new File(args[0]).length()) > 500000) {
  -                writer = new FileWriter(args[2] + ".tmp");
  +            if ((new File(foFile).length()) > 500000) {
  +                writer = new FileWriter(pdfFile + ".tmp");
                   usefile = true;
               } else {
                   writer = new StringWriter();
  @@ -229,14 +267,12 @@
               // Create the 3 objects the XSLTProcessor needs to perform the transformation.
               // Fix up the args...
               XMLParserLiaison xmlPL = processor.getXMLProcessorLiaison();
  -            URL urlTmp = xmlPL.getURLFromString(args[0], null);
  -            System.err.println("XML File: " + args[0]);
  -            System.err.println("URL: " + urlTmp);
  +            URL urlTmp = xmlPL.getURLFromString(foFile, null);
  +            MessageHandler.errorln("xml: " + urlTmp);
               XSLTInputSource xmlSource =
                 new XSLTInputSource (urlTmp.toString());
  -            urlTmp = xmlPL.getURLFromString(args[1], null);
  -            System.err.println("XSL File: " + args[1]);
  -            System.err.println("URL: " + urlTmp);
  +            urlTmp = xmlPL.getURLFromString(xsltFile, null);
  +            MessageHandler.errorln("xslt: " + urlTmp);
               XSLTInputSource xslSheet =
                 new XSLTInputSource (urlTmp.toString());
   
  @@ -246,7 +282,7 @@
               processor.process(xmlSource, xslSheet, xmlResult);
   
               if (usefile) {
  -                reader = new FileReader(args[2] + ".tmp");
  +                reader = new FileReader(pdfFile + ".tmp");
               } else {
                   // create a input source containing the xsl:fo file which can be fed to Fop
                   reader = new StringReader(writer.toString());
  @@ -261,21 +297,41 @@
               driver.addElementMapping("org.apache.fop.svg.SVGElementMapping");
               driver.addPropertyList("org.apache.fop.fo.StandardPropertyListMapping");
               driver.addPropertyList("org.apache.fop.svg.SVGPropertyListMapping");
  -		    PrintWriter pwriter = new PrintWriter(new BufferedWriter(new FileWriter(args[2])));
  -		    driver.setWriter(pwriter);
  +            PrintWriter pwriter = new PrintWriter(
  +                                    new BufferedWriter(new FileWriter(pdfFile)));
  +            driver.setWriter(pwriter);
               driver.buildFOTree(parser, new InputSource(reader));
               reader.close();
               driver.format();
               driver.render();
               if (usefile) {
  -                new File (args[2] + ".tmp").delete();
  +                new File (pdfFile + ".tmp").delete();
               }
  -			pwriter.flush();
  -			pwriter.close();
  +            pwriter.flush();
  +            pwriter.close();
           }
           catch (Exception e) {
               MessageHandler.errorln("FATAL ERROR: " + e.getMessage());
  +            if (errorDump) {
  +                e.printStackTrace();
  +            }
               System.exit(1);
           }
       }
  +
  +    /**
  +       * mainline method
  +       *
  +       * first command line argument is xml input file
  +       * second command line argument is xslt file
  +       * third command line argument is the target pdf file
  +       *
  +       * @param command line arguments
  +       */
  +    public static void main(String[] args) {
  +        XalanCommandLine xcmdLine = new XalanCommandLine(args);
  +        xcmdLine.run();
  +
  +    }
  +
   }
  
  
  
  1.16      +4 -2      xml-fop/src/org/apache/fop/apps/Driver.java
  
  Index: Driver.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/apps/Driver.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- Driver.java	2000/12/12 19:18:30	1.15
  +++ Driver.java	2000/12/12 21:12:16	1.16
  @@ -1,4 +1,4 @@
  -/*-- $Id: Driver.java,v 1.15 2000/12/12 19:18:30 fotis Exp $ --
  +/*-- $Id: Driver.java,v 1.16 2000/12/12 21:12:16 fotis Exp $ --
   
    ============================================================================
                      The Apache Software License, Version 1.1
  @@ -472,7 +472,9 @@
               MessageHandler.errorln("Fatal error: can't find default configuration file");
               System.exit(1);
           }
  -        MessageHandler.logln("reading default configuration file");
  +        if (errorDump) {
  +            MessageHandler.logln("reading default configuration file");
  +        }
           ConfigurationReader reader =
             new ConfigurationReader (new InputSource(configfile),
                                      "standard");
  
  
  
  1.15      +5 -2      xml-fop/src/org/apache/fop/apps/CommandLine.java
  
  Index: CommandLine.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/apps/CommandLine.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- CommandLine.java	2000/12/12 19:18:29	1.14
  +++ CommandLine.java	2000/12/12 21:12:17	1.15
  @@ -1,4 +1,4 @@
  -/*-- $Id: CommandLine.java,v 1.14 2000/12/12 19:18:29 fotis Exp $ --
  +/*-- $Id: CommandLine.java,v 1.15 2000/12/12 21:12:17 fotis Exp $ --
   
    ============================================================================
                      The Apache Software License, Version 1.1
  @@ -125,6 +125,9 @@
   
       public void run() {
           Driver driver  = new Driver();
  +        if (errorDump)  {
  +            driver.setErrorDump(true);
  +        }
           driver.loadStandardConfiguration("standard");
   //        driver.loadStandardConfiguration("pdf");
           if (userConfigFile != null)  {
  @@ -132,6 +135,7 @@
           }
           driver.setBaseDir(foFile);
   
  +
           String version = Version.getVersion();
           MessageHandler.logln(version);
   
  @@ -156,7 +160,6 @@
           }
   
           try {
  -            driver.setErrorDump(errorDump);
               driver.setRenderer("org.apache.fop.render.pdf.PDFRenderer",
                                  Version.getVersion());
               driver.addElementMapping("org.apache.fop.fo.StandardElementMapping");