Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. try {
  36. Driver driver = new Driver();
  37. options = new CommandLineOptions(args);
  38. driver.setUserAgent(options.getFOUserAgent());
  39. inputHandler = options.getInputHandler();
  40. try {
  41. if (options.getOutputMode() == CommandLineOptions.AWT_OUTPUT) {
  42. driver.setRenderer(new AWTRenderer(inputHandler));
  43. } else {
  44. driver.setRenderer(options.getRenderer());
  45. if (options.getOutputFile() != null) {
  46. bos = new BufferedOutputStream(new FileOutputStream(
  47. options.getOutputFile()));
  48. driver.setOutputStream(bos);
  49. }
  50. }
  51. driver.render(inputHandler);
  52. } finally {
  53. if (bos != null) {
  54. bos.close();
  55. }
  56. }
  57. // System.exit(0) called to close AWT/SVG-created threads, if any.
  58. // AWTRenderer closes with window shutdown, so exit() should not
  59. // be called here
  60. if (options.getOutputMode() != CommandLineOptions.AWT_OUTPUT) {
  61. System.exit(0);
  62. }
  63. } catch (FOPException e) {
  64. if (e.getMessage() == null) {
  65. System.err.println("Exception occured with a null error message");
  66. } else {
  67. System.err.println("" + e.getMessage());
  68. }
  69. if (options != null && options.getLogger().isDebugEnabled()) {
  70. e.printStackTrace();
  71. } else {
  72. System.err.println("Turn on debugging for more information");
  73. }
  74. System.exit(1);
  75. } catch (java.io.IOException e) {
  76. System.err.println("" + e.getMessage());
  77. if (options != null && options.getLogger().isDebugEnabled()) {
  78. e.printStackTrace();
  79. } else {
  80. System.err.println("Turn on debugging for more information");
  81. }
  82. System.exit(1);
  83. }
  84. }
  85. /**
  86. * Get the version of FOP
  87. * @return the version string
  88. */
  89. public static String getVersion() {
  90. return "1.0dev";
  91. }
  92. }