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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. throws FOPException
  21. {
  22. this.commandLineOptions = commandLineOptions;
  23. options.setCommandLineOptions(commandLineOptions);
  24. errorDump = Configuration.getBooleanValue("debugMode").booleanValue();
  25. super.setInputHandler(commandLineOptions.getInputHandler());
  26. }
  27. /**
  28. * Run the format.
  29. * @exception FOPException if there is an error during processing
  30. */
  31. public void run()
  32. throws FOPException
  33. {
  34. String version = Version.getVersion();
  35. MessageHandler.logln(version);
  36. XMLReader parser = inputHandler.getParser();
  37. setParserFeatures(parser);
  38. Driver driver = new Driver();
  39. if (errorDump) {
  40. driver.setErrorDump(true);
  41. }
  42. try {
  43. driver.setRenderer(commandLineOptions.getRenderer());
  44. driver.buildFOTree(parser, inputHandler.getInputSource());
  45. driver.format();
  46. driver.setOutputStream(new FileOutputStream(commandLineOptions.getOutputFile()));
  47. driver.render();
  48. } catch (Exception e) {
  49. if (e instanceof FOPException) {
  50. throw (FOPException) e;
  51. }
  52. throw new FOPException(e);
  53. }
  54. }
  55. }