Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

CommandLineStarter.java 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001 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. import org.xml.sax.InputSource;
  11. import org.xml.sax.SAXException;
  12. import org.xml.sax.SAXParseException;
  13. // Java
  14. import java.io.*;
  15. import java.net.URL;
  16. // FOP
  17. import org.apache.fop.configuration.Configuration;
  18. /**
  19. * super class for all classes which start Fop from the commandline
  20. *
  21. * Modified to use new streaming API by Mark Lillywhite, mark-fop@inomial.com
  22. */
  23. public class CommandLineStarter extends Starter {
  24. CommandLineOptions commandLineOptions;
  25. boolean errorDump;
  26. public CommandLineStarter(CommandLineOptions commandLineOptions)
  27. throws FOPException {
  28. this.commandLineOptions = commandLineOptions;
  29. options.setCommandLineOptions(commandLineOptions);
  30. errorDump =
  31. Configuration.getBooleanValue("debugMode").booleanValue();
  32. super.setInputHandler(commandLineOptions.getInputHandler());
  33. }
  34. /**
  35. * Run the format.
  36. * @exception FOPException if there is an error during processing
  37. */
  38. public void run() throws FOPException {
  39. String version = Version.getVersion();
  40. getLogger().info(version);
  41. XMLReader parser = inputHandler.getParser();
  42. setParserFeatures(parser);
  43. Driver driver = new Driver();
  44. setupLogger(driver);
  45. driver.initialize();
  46. if (errorDump) {
  47. driver.setErrorDump(true);
  48. }
  49. try {
  50. driver.setRenderer(commandLineOptions.getRenderer());
  51. BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(
  52. commandLineOptions.getOutputFile()));
  53. driver.setOutputStream(bos);
  54. if(driver.getRenderer() != null) {
  55. driver.getRenderer().setOptions(
  56. commandLineOptions.getRendererOptions());
  57. }
  58. driver.render(parser, inputHandler.getInputSource());
  59. bos.close();
  60. System.exit(0);
  61. } catch (Exception e) {
  62. if (e instanceof FOPException) {
  63. throw (FOPException) e;
  64. }
  65. throw new FOPException(e);
  66. }
  67. }
  68. }