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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. // Avalon
  22. import org.apache.avalon.framework.logger.ConsoleLogger;
  23. // FOP
  24. import org.apache.fop.render.awt.AWTRenderer;
  25. /**
  26. * The main application class for the FOP command line interface (CLI).
  27. */
  28. public class Fop {
  29. /**
  30. * The main routine for the command line interface
  31. * @param args the command line parameters
  32. */
  33. public static void main(String[] args) {
  34. CommandLineOptions options = null;
  35. InputHandler inputHandler = null;
  36. BufferedOutputStream bos = null;
  37. String version = Version.getVersion();
  38. try {
  39. Driver driver = new Driver();
  40. driver.enableLogging(new ConsoleLogger(ConsoleLogger.LEVEL_INFO));
  41. driver.getLogger().info(version);
  42. options = new CommandLineOptions(args);
  43. inputHandler = options.getInputHandler();
  44. try {
  45. if (options.getOutputMode() == CommandLineOptions.AWT_OUTPUT) {
  46. driver.setRenderer(new AWTRenderer(inputHandler));
  47. } else {
  48. driver.setRenderer(options.getRenderer());
  49. if (options.getOutputFile() != null) {
  50. bos = new BufferedOutputStream(new FileOutputStream(
  51. options.getOutputFile()));
  52. driver.setOutputStream(bos);
  53. }
  54. }
  55. if (driver.getRenderer() != null) {
  56. driver.getRenderer().setOptions(options.getRendererOptions());
  57. }
  58. driver.render(inputHandler);
  59. } finally {
  60. if (bos != null) {
  61. bos.close();
  62. }
  63. }
  64. // System.exit(0) called to close AWT/SVG-created threads, if any.
  65. // AWTRenderer closes with window shutdown, so exit() should not
  66. // be called here
  67. if (options.getOutputMode() != CommandLineOptions.AWT_OUTPUT) {
  68. System.exit(0);
  69. }
  70. } catch (FOPException e) {
  71. if (e.getMessage() == null) {
  72. System.err.println("Exception occured with a null error message");
  73. } else {
  74. System.err.println("" + e.getMessage());
  75. }
  76. if (options != null && options.getLogger().isDebugEnabled()) {
  77. e.printStackTrace();
  78. } else {
  79. System.err.println("Turn on debugging for more information");
  80. }
  81. System.exit(1);
  82. } catch (java.io.IOException e) {
  83. System.err.println("" + e.getMessage());
  84. if (options != null && options.getLogger().isDebugEnabled()) {
  85. e.printStackTrace();
  86. } else {
  87. System.err.println("Turn on debugging for more information");
  88. }
  89. System.exit(1);
  90. }
  91. }
  92. }