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

CommandLineStarter.java 2.2KB

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