You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CommandLineStarter.java 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package org.apache.fop.apps;
  2. // SAX
  3. import org.xml.sax.XMLReader;
  4. import org.xml.sax.InputSource;
  5. import org.xml.sax.SAXException;
  6. import org.xml.sax.SAXParseException;
  7. // Java
  8. import java.io.*;
  9. import java.net.URL;
  10. // FOP
  11. import org.apache.fop.messaging.MessageHandler;
  12. import org.apache.fop.configuration.Configuration;
  13. /**
  14. * super class for all classes which start Fop from the commandline
  15. */
  16. public class CommandLineStarter extends Starter {
  17. CommandLineOptions commandLineOptions;
  18. boolean errorDump;
  19. public CommandLineStarter (CommandLineOptions commandLineOptions) {
  20. this.commandLineOptions = commandLineOptions;
  21. options.setCommandLineOptions(commandLineOptions);
  22. errorDump = Configuration.getBooleanValue("debugMode").booleanValue();
  23. super.setInputHandler(commandLineOptions.getInputHandler());
  24. }
  25. public void run() {
  26. String version = Version.getVersion();
  27. MessageHandler.logln(version);
  28. XMLReader parser = inputHandler.getParser();
  29. setParserFeatures(parser,errorDump);
  30. Driver driver = new Driver();
  31. if (errorDump) {
  32. driver.setErrorDump(true);
  33. }
  34. try {
  35. driver.setRenderer(commandLineOptions.getRenderer());
  36. driver.buildFOTree(parser, inputHandler.getInputSource());
  37. driver.format();
  38. driver.setOutputStream(new FileOutputStream(commandLineOptions.getOutputFile()));
  39. driver.render();
  40. } catch (Exception e) {
  41. MessageHandler.errorln("FATAL ERROR: " + e.getMessage());
  42. if (errorDump) {
  43. e.printStackTrace();
  44. }
  45. System.exit(1);
  46. }
  47. }
  48. }