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.

CommandLineOptions.java 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. /*
  2. * $Id: CommandLineOptions.java,v 1.22 2003/02/27 10:13:06 jeremias Exp $
  3. * ============================================================================
  4. * The Apache Software License, Version 1.1
  5. * ============================================================================
  6. *
  7. * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without modifica-
  10. * tion, are permitted provided that the following conditions are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. *
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if any, must
  20. * include the following acknowledgment: "This product includes software
  21. * developed by the Apache Software Foundation (http://www.apache.org/)."
  22. * Alternately, this acknowledgment may appear in the software itself, if
  23. * and wherever such third-party acknowledgments normally appear.
  24. *
  25. * 4. The names "FOP" and "Apache Software Foundation" must not be used to
  26. * endorse or promote products derived from this software without prior
  27. * written permission. For written permission, please contact
  28. * apache@apache.org.
  29. *
  30. * 5. Products derived from this software may not be called "Apache", nor may
  31. * "Apache" appear in their name, without prior written permission of the
  32. * Apache Software Foundation.
  33. *
  34. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
  35. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  36. * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  37. * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  38. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
  39. * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  40. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  41. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  42. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  43. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  44. * ============================================================================
  45. *
  46. * This software consists of voluntary contributions made by many individuals
  47. * on behalf of the Apache Software Foundation and was originally created by
  48. * James Tauber <jtauber@jtauber.com>. For more information on the Apache
  49. * Software Foundation, please see <http://www.apache.org/>.
  50. */
  51. package org.apache.fop.apps;
  52. // java
  53. import java.io.File;
  54. import java.io.FileNotFoundException;
  55. // Avalon
  56. import org.apache.avalon.framework.logger.ConsoleLogger;
  57. import org.apache.avalon.framework.logger.Logger;
  58. /**
  59. * Options parses the commandline arguments
  60. */
  61. public class CommandLineOptions {
  62. /* input / output not set */
  63. private static final int NOT_SET = 0;
  64. /* input: fo file */
  65. private static final int FO_INPUT = 1;
  66. /* input: xml+xsl file */
  67. private static final int XSLT_INPUT = 2;
  68. /* output: pdf file */
  69. private static final int PDF_OUTPUT = 1;
  70. /* output: screen using swing */
  71. private static final int AWT_OUTPUT = 2;
  72. /* output: mif file */
  73. private static final int MIF_OUTPUT = 3;
  74. /* output: sent swing rendered file to printer */
  75. private static final int PRINT_OUTPUT = 4;
  76. /* output: pcl file */
  77. private static final int PCL_OUTPUT = 5;
  78. /* output: postscript file */
  79. private static final int PS_OUTPUT = 6;
  80. /* output: text file */
  81. private static final int TXT_OUTPUT = 7;
  82. /* output: svg file */
  83. private static final int SVG_OUTPUT = 8;
  84. /* output: XML area tree */
  85. private static final int AREA_OUTPUT = 9;
  86. /* output: RTF file */
  87. private static final int RTF_OUTPUT = 10;
  88. /* show configuration information */
  89. private Boolean dumpConfiguration = Boolean.FALSE;
  90. /* suppress any progress information */
  91. private Boolean quiet = Boolean.FALSE;
  92. /* for area tree XML output, only down to block area level */
  93. private Boolean suppressLowLevelAreas = Boolean.FALSE;
  94. /* user configuration file */
  95. private File userConfigFile = null;
  96. /* input fo file */
  97. private File fofile = null;
  98. /* xsltfile (xslt transformation as input) */
  99. private File xsltfile = null;
  100. /* xml file (xslt transformation as input) */
  101. private File xmlfile = null;
  102. /* output file */
  103. private File outfile = null;
  104. /* input mode */
  105. private int inputmode = NOT_SET;
  106. /* output mode */
  107. private int outputmode = NOT_SET;
  108. /* language for user information */
  109. private String language = null;
  110. private java.util.HashMap rendererOptions;
  111. private Logger log;
  112. /**
  113. * Construct a command line option object from command line arguments
  114. * @param args command line parameters
  115. * @throws FOPException for general errors
  116. * @throws FileNotFoundException if an input file wasn't found.
  117. */
  118. public CommandLineOptions(String[] args)
  119. throws FOPException, FileNotFoundException {
  120. log = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
  121. boolean optionsParsed = true;
  122. rendererOptions = new java.util.HashMap();
  123. try {
  124. optionsParsed = parseOptions(args);
  125. if (optionsParsed) {
  126. checkSettings();
  127. }
  128. } catch (FOPException e) {
  129. printUsage();
  130. throw e;
  131. } catch (java.io.FileNotFoundException e) {
  132. printUsage();
  133. throw e;
  134. }
  135. }
  136. /**
  137. * Get the logger.
  138. * @return the logger
  139. */
  140. public Logger getLogger() {
  141. return log;
  142. }
  143. /**
  144. * parses the commandline arguments
  145. * @return true if parse was successful and processing can continue, false
  146. * if processing should stop
  147. * @exception FOPException if there was an error in the format of the options
  148. */
  149. private boolean parseOptions(String[] args) throws FOPException {
  150. for (int i = 0; i < args.length; i++) {
  151. if (args[i].equals("-d") || args[i].equals("--full-error-dump")) {
  152. log = new ConsoleLogger(ConsoleLogger.LEVEL_DEBUG);
  153. } else if (args[i].equals("-x")
  154. || args[i].equals("--dump-config")) {
  155. dumpConfiguration = Boolean.TRUE;
  156. } else if (args[i].equals("-q") || args[i].equals("--quiet")) {
  157. quiet = Boolean.TRUE;
  158. log = new ConsoleLogger(ConsoleLogger.LEVEL_ERROR);
  159. } else if (args[i].equals("-c")) {
  160. i = i + parseConfigurationOption(args, i);
  161. } else if (args[i].equals("-l")) {
  162. i = i + parseLanguageOption(args, i);
  163. } else if (args[i].equals("-s")) {
  164. suppressLowLevelAreas = Boolean.TRUE;
  165. } else if (args[i].equals("-fo")) {
  166. i = i + parseFOInputOption(args, i);
  167. } else if (args[i].equals("-xsl")) {
  168. i = i + parseXSLInputOption(args, i);
  169. } else if (args[i].equals("-xml")) {
  170. i = i + parseXMLInputOption(args, i);
  171. } else if (args[i].equals("-awt")) {
  172. i = i + parseAWTOutputOption(args, i);
  173. } else if (args[i].equals("-pdf")) {
  174. i = i + parsePDFOutputOption(args, i);
  175. } else if (args[i].equals("-mif")) {
  176. i = i + parseMIFOutputOption(args, i);
  177. } else if (args[i].equals("-rtf")) {
  178. i = i + parseRTFOutputOption(args, i);
  179. } else if (args[i].equals("-print")) {
  180. i = i + parsePrintOutputOption(args, i);
  181. // show print help
  182. if (i + 1 < args.length) {
  183. if (args[i + 1].equals("help")) {
  184. printUsagePrintOutput();
  185. return false;
  186. }
  187. }
  188. } else if (args[i].equals("-pcl")) {
  189. i = i + parsePCLOutputOption(args, i);
  190. } else if (args[i].equals("-ps")) {
  191. i = i + parsePostscriptOutputOption(args, i);
  192. } else if (args[i].equals("-txt")) {
  193. i = i + parseTextOutputOption(args, i);
  194. } else if (args[i].equals("-svg")) {
  195. i = i + parseSVGOutputOption(args, i);
  196. } else if (args[i].charAt(0) != '-') {
  197. i = i + parseUnknownOption(args, i);
  198. } else if (args[i].equals("-at")) {
  199. i = i + parseAreaTreeOption(args, i);
  200. } else {
  201. printUsage();
  202. return false;
  203. }
  204. }
  205. return true;
  206. } // end parseOptions
  207. private int parseConfigurationOption(String[] args, int i) throws FOPException {
  208. if ((i + 1 == args.length)
  209. || (args[i + 1].charAt(0) == '-')) {
  210. throw new FOPException("if you use '-c', you must specify "
  211. + "the name of the configuration file");
  212. } else {
  213. userConfigFile = new File(args[i + 1]);
  214. return 1;
  215. }
  216. }
  217. private int parseLanguageOption(String[] args, int i) throws FOPException {
  218. if ((i + 1 == args.length)
  219. || (args[i + 1].charAt(0) == '-')) {
  220. throw new FOPException("if you use '-l', you must specify a language");
  221. } else {
  222. language = args[i + 1];
  223. return 1;
  224. }
  225. }
  226. private int parseFOInputOption(String[] args, int i) throws FOPException {
  227. inputmode = FO_INPUT;
  228. if ((i + 1 == args.length)
  229. || (args[i + 1].charAt(0) == '-')) {
  230. throw new FOPException("you must specify the fo file for the '-fo' option");
  231. } else {
  232. fofile = new File(args[i + 1]);
  233. return 1;
  234. }
  235. }
  236. private int parseXSLInputOption(String[] args, int i) throws FOPException {
  237. inputmode = XSLT_INPUT;
  238. if ((i + 1 == args.length)
  239. || (args[i + 1].charAt(0) == '-')) {
  240. throw new FOPException("you must specify the stylesheet "
  241. + "file for the '-xsl' option");
  242. } else {
  243. xsltfile = new File(args[i + 1]);
  244. return 1;
  245. }
  246. }
  247. private int parseXMLInputOption(String[] args, int i) throws FOPException {
  248. inputmode = XSLT_INPUT;
  249. if ((i + 1 == args.length)
  250. || (args[i + 1].charAt(0) == '-')) {
  251. throw new FOPException("you must specify the input file "
  252. + "for the '-xml' option");
  253. } else {
  254. xmlfile = new File(args[i + 1]);
  255. return 1;
  256. }
  257. }
  258. private int parseAWTOutputOption(String[] args, int i) throws FOPException {
  259. setOutputMode(AWT_OUTPUT);
  260. return 0;
  261. }
  262. private int parsePDFOutputOption(String[] args, int i) throws FOPException {
  263. setOutputMode(PDF_OUTPUT);
  264. if ((i + 1 == args.length)
  265. || (args[i + 1].charAt(0) == '-')) {
  266. throw new FOPException("you must specify the pdf output file");
  267. } else {
  268. outfile = new File(args[i + 1]);
  269. return 1;
  270. }
  271. }
  272. private int parseMIFOutputOption(String[] args, int i) throws FOPException {
  273. setOutputMode(MIF_OUTPUT);
  274. if ((i + 1 == args.length)
  275. || (args[i + 1].charAt(0) == '-')) {
  276. throw new FOPException("you must specify the mif output file");
  277. } else {
  278. outfile = new File(args[i + 1]);
  279. return 1;
  280. }
  281. }
  282. private int parseRTFOutputOption(String[] args, int i) throws FOPException {
  283. setOutputMode(RTF_OUTPUT);
  284. if ((i + 1 == args.length)
  285. || (args[i + 1].charAt(0) == '-')) {
  286. throw new FOPException("you must specify the rtf output file");
  287. } else {
  288. outfile = new File(args[i + 1]);
  289. return 1;
  290. }
  291. }
  292. private int parsePrintOutputOption(String[] args, int i) throws FOPException {
  293. setOutputMode(PRINT_OUTPUT);
  294. return 0;
  295. }
  296. private int parsePCLOutputOption(String[] args, int i) throws FOPException {
  297. setOutputMode(PCL_OUTPUT);
  298. if ((i + 1 == args.length)
  299. || (args[i + 1].charAt(0) == '-')) {
  300. throw new FOPException("you must specify the pdf output file");
  301. } else {
  302. outfile = new File(args[i + 1]);
  303. return 1;
  304. }
  305. }
  306. private int parsePostscriptOutputOption(String[] args, int i) throws FOPException {
  307. setOutputMode(PS_OUTPUT);
  308. if ((i + 1 == args.length)
  309. || (args[i + 1].charAt(0) == '-')) {
  310. throw new FOPException("you must specify the PostScript output file");
  311. } else {
  312. outfile = new File(args[i + 1]);
  313. return 1;
  314. }
  315. }
  316. private int parseTextOutputOption(String[] args, int i) throws FOPException {
  317. setOutputMode(TXT_OUTPUT);
  318. if ((i + 1 == args.length)
  319. || (args[i + 1].charAt(0) == '-')) {
  320. throw new FOPException("you must specify the text output file");
  321. } else {
  322. outfile = new File(args[i + 1]);
  323. return 1;
  324. }
  325. }
  326. private int parseSVGOutputOption(String[] args, int i) throws FOPException {
  327. setOutputMode(SVG_OUTPUT);
  328. if ((i + 1 == args.length)
  329. || (args[i + 1].charAt(0) == '-')) {
  330. throw new FOPException("you must specify the svg output file");
  331. } else {
  332. outfile = new File(args[i + 1]);
  333. return 1;
  334. }
  335. }
  336. private int parseUnknownOption(String[] args, int i) throws FOPException {
  337. if (inputmode == NOT_SET) {
  338. inputmode = FO_INPUT;
  339. fofile = new File(args[i]);
  340. } else if (outputmode == NOT_SET) {
  341. outputmode = PDF_OUTPUT;
  342. outfile = new File(args[i]);
  343. } else {
  344. throw new FOPException("Don't know what to do with "
  345. + args[i]);
  346. }
  347. return 0;
  348. }
  349. private int parseAreaTreeOption(String[] args, int i) throws FOPException {
  350. setOutputMode(AREA_OUTPUT);
  351. if ((i + 1 == args.length)
  352. || (args[i + 1].charAt(0) == '-')) {
  353. throw new FOPException("you must specify the area-tree output file");
  354. } else {
  355. outfile = new File(args[i + 1]);
  356. return 1;
  357. }
  358. }
  359. private void setOutputMode(int mode) throws FOPException {
  360. if (outputmode == NOT_SET) {
  361. outputmode = mode;
  362. } else {
  363. throw new FOPException("you can only set one output method");
  364. }
  365. }
  366. /**
  367. * checks whether all necessary information has been given in a consistent way
  368. */
  369. private void checkSettings() throws FOPException, FileNotFoundException {
  370. if (inputmode == NOT_SET) {
  371. throw new FOPException("No input file specified");
  372. }
  373. if (outputmode == NOT_SET) {
  374. throw new FOPException("No output file specified");
  375. }
  376. if (inputmode == XSLT_INPUT) {
  377. // check whether xml *and* xslt file have been set
  378. if (xmlfile == null) {
  379. throw new FOPException("XML file must be specified for the tranform mode");
  380. }
  381. if (xsltfile == null) {
  382. throw new FOPException("XSLT file must be specified for the tranform mode");
  383. }
  384. // warning if fofile has been set in xslt mode
  385. if (fofile != null) {
  386. log.warn("Can't use fo file with transform mode! Ignoring.\n"
  387. + "Your input is " + "\n xmlfile: "
  388. + xmlfile.getAbsolutePath()
  389. + "\nxsltfile: "
  390. + xsltfile.getAbsolutePath()
  391. + "\n fofile: "
  392. + fofile.getAbsolutePath());
  393. }
  394. if (!xmlfile.exists()) {
  395. throw new FileNotFoundException("xml file "
  396. + xmlfile.getAbsolutePath()
  397. + " not found ");
  398. }
  399. if (!xsltfile.exists()) {
  400. throw new FileNotFoundException("xsl file "
  401. + xsltfile.getAbsolutePath()
  402. + " not found ");
  403. }
  404. } else if (inputmode == FO_INPUT) {
  405. if (xmlfile != null || xsltfile != null) {
  406. log.warn("fo input mode, but xmlfile or xslt file are set:");
  407. log.error("xml file: " + xmlfile.toString());
  408. log.error("xslt file: " + xsltfile.toString());
  409. }
  410. if (!fofile.exists()) {
  411. throw new FileNotFoundException("fo file "
  412. + fofile.getAbsolutePath()
  413. + " not found ");
  414. }
  415. }
  416. } // end checkSettings
  417. /**
  418. * @return the type chosen renderer
  419. * @throws FOPException for invalid output modes
  420. */
  421. public int getRenderer() throws FOPException {
  422. switch (outputmode) {
  423. case NOT_SET:
  424. throw new FOPException("Renderer has not been set!");
  425. case PDF_OUTPUT:
  426. return Driver.RENDER_PDF;
  427. case AWT_OUTPUT:
  428. return Driver.RENDER_AWT;
  429. case MIF_OUTPUT:
  430. return Driver.RENDER_MIF;
  431. case PRINT_OUTPUT:
  432. return Driver.RENDER_PRINT;
  433. case PCL_OUTPUT:
  434. return Driver.RENDER_PCL;
  435. case PS_OUTPUT:
  436. return Driver.RENDER_PS;
  437. case TXT_OUTPUT:
  438. return Driver.RENDER_TXT;
  439. case SVG_OUTPUT:
  440. return Driver.RENDER_SVG;
  441. case AREA_OUTPUT:
  442. rendererOptions.put("fineDetail", isCoarseAreaXml());
  443. return Driver.RENDER_XML;
  444. case RTF_OUTPUT:
  445. return Driver.RENDER_RTF;
  446. default:
  447. throw new FOPException("Invalid Renderer setting!");
  448. }
  449. }
  450. /**
  451. * Get the input handler.
  452. * @return the input handler
  453. * @throws FOPException if creating the InputHandler fails
  454. */
  455. public InputHandler getInputHandler() throws FOPException {
  456. switch (inputmode) {
  457. case FO_INPUT:
  458. return new FOInputHandler(fofile);
  459. case XSLT_INPUT:
  460. return new XSLTInputHandler(xmlfile, xsltfile);
  461. default:
  462. return new FOInputHandler(fofile);
  463. }
  464. }
  465. /**
  466. * Get the renderer specific options.
  467. * @return hash map with option/value pairs.
  468. */
  469. public java.util.HashMap getRendererOptions() {
  470. return rendererOptions;
  471. }
  472. /**
  473. * Get the starter for the process.
  474. * @return the starter.
  475. * @throws FOPException In case of failure while getting the starter
  476. */
  477. public Starter getStarter() throws FOPException {
  478. Starter starter = null;
  479. switch (outputmode) {
  480. case AWT_OUTPUT:
  481. try {
  482. starter = new AWTStarter(this);
  483. } catch (FOPException e) {
  484. throw e;
  485. } catch (Exception e) {
  486. throw new FOPException("AWTStarter could not be loaded.", e);
  487. }
  488. break;
  489. case PRINT_OUTPUT:
  490. try {
  491. starter = new PrintStarter(this);
  492. } catch (FOPException e) {
  493. throw e;
  494. } catch (Exception e) {
  495. throw new FOPException("PrintStarter could not be loaded.", e);
  496. }
  497. break;
  498. default:
  499. starter = new CommandLineStarter(this);
  500. }
  501. starter.enableLogging(log);
  502. return starter;
  503. }
  504. /**
  505. * Returns the input mode (type of input data, ex. NOT_SET or FO_INPUT)
  506. * @return the input mode
  507. */
  508. public int getInputMode() {
  509. return inputmode;
  510. }
  511. /**
  512. * Returns the output mode (output format, ex. NOT_SET or PDF_OUTPUT)
  513. * @return the output mode
  514. */
  515. public int getOutputMode() {
  516. return outputmode;
  517. }
  518. /**
  519. * Returns the XSL-FO file if set.
  520. * @return the XSL-FO file, null if not set
  521. */
  522. public File getFOFile() {
  523. return fofile;
  524. }
  525. /**
  526. * Returns the input XML file if set.
  527. * @return the input XML file, null if not set
  528. */
  529. public File getXMLFile() {
  530. return xmlfile;
  531. }
  532. /**
  533. * Returns the stylesheet to be used for transformation to XSL-FO.
  534. * @return stylesheet
  535. */
  536. public File getXSLFile() {
  537. return xsltfile;
  538. }
  539. /**
  540. * Returns the output file
  541. * @return the output file
  542. */
  543. public File getOutputFile() {
  544. return outfile;
  545. }
  546. /**
  547. * Returns the user configuration file to be used.
  548. * @return the userconfig.xml file
  549. */
  550. public File getUserConfigFile() {
  551. return userConfigFile;
  552. }
  553. /**
  554. * Returns the default language
  555. * @return the default language
  556. */
  557. public String getLanguage() {
  558. return language;
  559. }
  560. /**
  561. * Indicates if FOP should be silent.
  562. * @return true if should be silent
  563. */
  564. public Boolean isQuiet() {
  565. return quiet;
  566. }
  567. /**
  568. * Indicates if FOP should dump its configuration during runtime.
  569. * @return true if config dump is enabled
  570. */
  571. public Boolean dumpConfiguration() {
  572. return dumpConfiguration;
  573. }
  574. /**
  575. * Indicates whether the XML renderer should generate course area XML
  576. * @return true if coarse area XML is desired
  577. */
  578. public Boolean isCoarseAreaXml() {
  579. return suppressLowLevelAreas;
  580. }
  581. /**
  582. * Returns the input file.
  583. * @return either the fofile or the xmlfile
  584. */
  585. public File getInputFile() {
  586. switch (inputmode) {
  587. case FO_INPUT:
  588. return fofile;
  589. case XSLT_INPUT:
  590. return xmlfile;
  591. default:
  592. return fofile;
  593. }
  594. }
  595. /**
  596. * shows the commandline syntax including a summary of all available options and some examples
  597. */
  598. public static void printUsage() {
  599. System.err.println(
  600. "\nUSAGE\nFop [options] [-fo|-xml] infile [-xsl file] "
  601. + "[-awt|-pdf|-mif|-rtf|-pcl|-ps|-txt|-at|-print] <outfile>\n"
  602. + " [OPTIONS] \n"
  603. + " -d debug mode \n"
  604. + " -x dump configuration settings \n"
  605. + " -q quiet mode \n"
  606. + " -c cfg.xml use additional configuration file cfg.xml\n"
  607. + " -l lang the language to use for user information \n"
  608. + " -s for area tree XML, down to block areas only\n\n"
  609. + " [INPUT] \n"
  610. + " infile xsl:fo input file (the same as the next) \n"
  611. + " -fo infile xsl:fo input file \n"
  612. + " -xml infile xml input file, must be used together with -xsl \n"
  613. + " -xsl stylesheet xslt stylesheet \n \n"
  614. + " [OUTPUT] \n"
  615. + " outfile input will be rendered as pdf file into outfile \n"
  616. + " -pdf outfile input will be rendered as pdf file (outfile req'd) \n"
  617. + " -awt input will be displayed on screen \n"
  618. + " -mif outfile input will be rendered as mif file (outfile req'd)\n"
  619. + " -rtf outfile input will be rendered as rtf file (outfile req'd)\n"
  620. + " -pcl outfile input will be rendered as pcl file (outfile req'd) \n"
  621. + " -ps outfile input will be rendered as PostScript file (outfile req'd) \n"
  622. + " -txt outfile input will be rendered as text file (outfile req'd) \n"
  623. + " -svg outfile input will be rendered as an svg slides file (outfile req'd) \n"
  624. + " -at outfile representation of area tree as XML (outfile req'd) \n"
  625. + " -print input file will be rendered and sent to the printer \n"
  626. + " see options with \"-print help\" \n\n"
  627. + " [Examples]\n" + " Fop foo.fo foo.pdf \n"
  628. + " Fop -fo foo.fo -pdf foo.pdf (does the same as the previous line)\n"
  629. + " Fop -xsl foo.xsl -xml foo.xml -pdf foo.pdf\n"
  630. + " Fop foo.fo -mif foo.mif\n"
  631. + " Fop foo.fo -rtf foo.rtf\n"
  632. + " Fop foo.fo -print or Fop -print foo.fo \n"
  633. + " Fop foo.fo -awt \n");
  634. }
  635. /**
  636. * shows the options for print output
  637. */
  638. public void printUsagePrintOutput() {
  639. System.err.println("USAGE: -print [-Dstart=i] [-Dend=i] [-Dcopies=i] [-Deven=true|false] "
  640. + " org.apache.fop.apps.Fop (..) -print \n"
  641. + "Example:\n"
  642. + "java -Dstart=1 -Dend=2 org.apache.Fop.apps.Fop infile.fo -print ");
  643. }
  644. /**
  645. * debug mode. outputs all commandline settings
  646. */
  647. private void debug() {
  648. log.debug("Input mode: ");
  649. switch (inputmode) {
  650. case NOT_SET:
  651. log.debug("not set");
  652. break;
  653. case FO_INPUT:
  654. log.debug("FO ");
  655. log.debug("fo input file: " + fofile.toString());
  656. break;
  657. case XSLT_INPUT:
  658. log.debug("xslt transformation");
  659. log.debug("xml input file: " + xmlfile.toString());
  660. log.debug("xslt stylesheet: " + xsltfile.toString());
  661. break;
  662. default:
  663. log.debug("unknown input type");
  664. }
  665. log.debug("Output mode: ");
  666. switch (outputmode) {
  667. case NOT_SET:
  668. log.debug("not set");
  669. break;
  670. case PDF_OUTPUT:
  671. log.debug("pdf");
  672. log.debug("output file: " + outfile.toString());
  673. break;
  674. case AWT_OUTPUT:
  675. log.debug("awt on screen");
  676. if (outfile != null) {
  677. log.error("awt mode, but outfile is set:");
  678. log.debug("out file: " + outfile.toString());
  679. }
  680. break;
  681. case MIF_OUTPUT:
  682. log.debug("mif");
  683. log.debug("output file: " + outfile.toString());
  684. break;
  685. case RTF_OUTPUT:
  686. log.debug("rtf");
  687. log.debug("output file: " + outfile.toString());
  688. break;
  689. case PRINT_OUTPUT:
  690. log.debug("print directly");
  691. if (outfile != null) {
  692. log.error("print mode, but outfile is set:");
  693. log.error("out file: " + outfile.toString());
  694. }
  695. break;
  696. case PCL_OUTPUT:
  697. log.debug("pcl");
  698. log.debug("output file: " + outfile.toString());
  699. break;
  700. case PS_OUTPUT:
  701. log.debug("PostScript");
  702. log.debug("output file: " + outfile.toString());
  703. break;
  704. case TXT_OUTPUT:
  705. log.debug("txt");
  706. log.debug("output file: " + outfile.toString());
  707. break;
  708. case SVG_OUTPUT:
  709. log.debug("svg");
  710. log.debug("output file: " + outfile.toString());
  711. break;
  712. default:
  713. log.debug("unknown input type");
  714. }
  715. log.debug("OPTIONS");
  716. if (userConfigFile != null) {
  717. log.debug("user configuration file: "
  718. + userConfigFile.toString());
  719. } else {
  720. log.debug("no user configuration file is used [default]");
  721. }
  722. if (dumpConfiguration != null) {
  723. log.debug("dump configuration");
  724. } else {
  725. log.debug("don't dump configuration [default]");
  726. }
  727. if (quiet != null) {
  728. log.debug("quiet mode on");
  729. } else {
  730. log.debug("quiet mode off [default]");
  731. }
  732. }
  733. }