Ви не можете вибрати більше 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. log.info(version);
  41. XMLReader parser = inputHandler.getParser();
  42. setParserFeatures(parser);
  43. Driver driver = new Driver();
  44. driver.setLogger(log);
  45. driver.setBufferFile(commandLineOptions.getBufferFile());
  46. driver.initialize();
  47. if (errorDump) {
  48. driver.setErrorDump(true);
  49. }
  50. try {
  51. driver.setRenderer(commandLineOptions.getRenderer());
  52. BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(
  53. commandLineOptions.getOutputFile()));
  54. driver.setOutputStream(bos);
  55. driver.getRenderer().setOptions(
  56. commandLineOptions.getRendererOptions());
  57. driver.render(parser, inputHandler.getInputSource());
  58. bos.close();
  59. System.exit(0);
  60. } catch (Exception e) {
  61. if (e instanceof FOPException) {
  62. throw (FOPException) e;
  63. }
  64. throw new FOPException(e);
  65. }
  66. }
  67. }