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.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001-2003 The Apache Software Foundation. All rights reserved.
  4. * For details on use and redistribution please refer to the
  5. * LICENSE file included with these sources.
  6. */
  7. package org.apache.fop.apps;
  8. // SAX
  9. import org.xml.sax.XMLReader;
  10. // Java
  11. import java.io.BufferedOutputStream;
  12. import java.io.FileOutputStream;
  13. /**
  14. * super class for all classes which start Fop from the commandline
  15. *
  16. * Modified to use new streaming API by Mark Lillywhite, mark-fop@inomial.com
  17. */
  18. public class CommandLineStarter extends Starter {
  19. protected CommandLineOptions commandLineOptions;
  20. public CommandLineStarter(CommandLineOptions commandLineOptions)
  21. throws FOPException {
  22. this.commandLineOptions = commandLineOptions;
  23. super.setInputHandler(commandLineOptions.getInputHandler());
  24. }
  25. /**
  26. * Run the format.
  27. * @exception FOPException if there is an error during processing
  28. */
  29. public void run() throws FOPException {
  30. String version = Version.getVersion();
  31. getLogger().info(version);
  32. XMLReader parser = inputHandler.getParser();
  33. setParserFeatures(parser);
  34. Driver driver = new Driver();
  35. setupLogger(driver);
  36. driver.initialize();
  37. try {
  38. driver.setRenderer(commandLineOptions.getRenderer());
  39. BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(
  40. commandLineOptions.getOutputFile()));
  41. driver.setOutputStream(bos);
  42. if (driver.getRenderer() != null) {
  43. driver.getRenderer().setOptions(
  44. commandLineOptions.getRendererOptions());
  45. }
  46. driver.render(parser, inputHandler.getInputSource());
  47. bos.close();
  48. System.exit(0);
  49. } catch (Exception e) {
  50. if (e instanceof FOPException) {
  51. throw (FOPException) e;
  52. }
  53. throw new FOPException(e);
  54. }
  55. }
  56. }