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.

Fop.java 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright 1999-2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.apps;
  18. // Java
  19. import java.io.BufferedOutputStream;
  20. import java.io.FileOutputStream;
  21. // FOP
  22. import org.apache.fop.render.awt.AWTRenderer;
  23. /**
  24. * The main application class for the FOP command line interface (CLI).
  25. */
  26. public class Fop {
  27. /**
  28. * The main routine for the command line interface
  29. * @param args the command line parameters
  30. */
  31. public static void main(String[] args) {
  32. CommandLineOptions options = null;
  33. InputHandler inputHandler = null;
  34. BufferedOutputStream bos = null;
  35. String version = Version.getVersion();
  36. try {
  37. Driver driver = new Driver();
  38. options = new CommandLineOptions(args);
  39. driver.setUserAgent(options.getFOUserAgent());
  40. inputHandler = options.getInputHandler();
  41. try {
  42. if (options.getOutputMode() == CommandLineOptions.AWT_OUTPUT) {
  43. driver.setRenderer(new AWTRenderer(inputHandler));
  44. } else {
  45. driver.setRenderer(options.getRenderer());
  46. if (options.getOutputFile() != null) {
  47. bos = new BufferedOutputStream(new FileOutputStream(
  48. options.getOutputFile()));
  49. driver.setOutputStream(bos);
  50. }
  51. }
  52. driver.render(inputHandler);
  53. } finally {
  54. if (bos != null) {
  55. bos.close();
  56. }
  57. }
  58. // System.exit(0) called to close AWT/SVG-created threads, if any.
  59. // AWTRenderer closes with window shutdown, so exit() should not
  60. // be called here
  61. if (options.getOutputMode() != CommandLineOptions.AWT_OUTPUT) {
  62. System.exit(0);
  63. }
  64. } catch (FOPException e) {
  65. if (e.getMessage() == null) {
  66. System.err.println("Exception occured with a null error message");
  67. } else {
  68. System.err.println("" + e.getMessage());
  69. }
  70. if (options != null && options.getLogger().isDebugEnabled()) {
  71. e.printStackTrace();
  72. } else {
  73. System.err.println("Turn on debugging for more information");
  74. }
  75. System.exit(1);
  76. } catch (java.io.IOException e) {
  77. System.err.println("" + e.getMessage());
  78. if (options != null && options.getLogger().isDebugEnabled()) {
  79. e.printStackTrace();
  80. } else {
  81. System.err.println("Turn on debugging for more information");
  82. }
  83. System.exit(1);
  84. }
  85. }
  86. }