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 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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.addElementMapping("org.apache.fop.fo.StandardElementMapping");
  37. driver.addElementMapping("org.apache.fop.svg.SVGElementMapping");
  38. driver.addElementMapping("org.apache.fop.extensions.ExtensionElementMapping");
  39. driver.addPropertyList("org.apache.fop.fo.StandardPropertyListMapping");
  40. driver.addPropertyList("org.apache.fop.svg.SVGPropertyListMapping");
  41. driver.addPropertyList("org.apache.fop.extensions.ExtensionPropertyListMapping");
  42. driver.buildFOTree(parser,inputHandler.getInputSource());
  43. driver.format();
  44. driver.setOutputStream(new FileOutputStream(commandLineOptions.getOutputFile()));
  45. driver.render();
  46. } catch (Exception e) {
  47. MessageHandler.errorln("FATAL ERROR: " + e.getMessage());
  48. if (errorDump) {
  49. e.printStackTrace();
  50. }
  51. System.exit(1);
  52. }
  53. }
  54. }