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 50KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.cli;
  19. // java
  20. import java.io.File;
  21. import java.io.FileNotFoundException;
  22. import java.io.IOException;
  23. import java.io.PrintStream;
  24. import java.util.Locale;
  25. import java.util.Map;
  26. import java.util.Vector;
  27. import javax.swing.UIManager;
  28. import org.xml.sax.SAXException;
  29. import org.apache.commons.logging.Log;
  30. import org.apache.commons.logging.LogFactory;
  31. import org.apache.fop.Version;
  32. import org.apache.fop.apps.FOPException;
  33. import org.apache.fop.apps.FOUserAgent;
  34. import org.apache.fop.apps.FopFactory;
  35. import org.apache.fop.apps.MimeConstants;
  36. import org.apache.fop.pdf.PDFAMode;
  37. import org.apache.fop.pdf.PDFEncryptionManager;
  38. import org.apache.fop.pdf.PDFEncryptionParams;
  39. import org.apache.fop.pdf.PDFXMode;
  40. import org.apache.fop.render.Renderer;
  41. import org.apache.fop.render.awt.AWTRenderer;
  42. import org.apache.fop.render.intermediate.IFRenderer;
  43. import org.apache.fop.render.pdf.PDFRenderer;
  44. import org.apache.fop.render.print.PagesMode;
  45. import org.apache.fop.render.print.PrintRenderer;
  46. import org.apache.fop.render.xml.XMLRenderer;
  47. import org.apache.fop.util.CommandLineLogger;
  48. /**
  49. * Options parses the commandline arguments
  50. */
  51. public class CommandLineOptions {
  52. /** Used to indicate that only the result of the XSL transformation should be output */
  53. public static final int RENDER_NONE = -1;
  54. /* These following constants are used to describe the input (either .FO, .XML/.XSL or
  55. * intermediate format)
  56. */
  57. /** (input) not set */
  58. public static final int NOT_SET = 0;
  59. /** input: fo file */
  60. public static final int FO_INPUT = 1;
  61. /** input: xml+xsl file */
  62. public static final int XSLT_INPUT = 2;
  63. /** input: Area Tree XML file */
  64. public static final int AREATREE_INPUT = 3;
  65. /** input: Intermediate Format XML file */
  66. public static final int IF_INPUT = 4;
  67. /** input: Image file */
  68. public static final int IMAGE_INPUT = 5;
  69. /* show configuration information */
  70. private Boolean showConfiguration = Boolean.FALSE;
  71. /* for area tree XML output, only down to block area level */
  72. private Boolean suppressLowLevelAreas = Boolean.FALSE;
  73. /* user configuration file */
  74. private File userConfigFile = null;
  75. /* input fo file */
  76. private File fofile = null;
  77. /* xsltfile (xslt transformation as input) */
  78. private File xsltfile = null;
  79. /* xml file (xslt transformation as input) */
  80. private File xmlfile = null;
  81. /* area tree input file */
  82. private File areatreefile = null;
  83. /* intermediate format input file */
  84. private File iffile = null;
  85. /* area tree input file */
  86. private File imagefile = null;
  87. /* output file */
  88. private File outfile = null;
  89. /* input mode */
  90. private int inputmode = NOT_SET;
  91. /* output mode */
  92. private String outputmode = null;
  93. /* true if System.in (stdin) should be used for the input file */
  94. private boolean useStdIn = false;
  95. /* true if System.out (stdout) should be used for the output file */
  96. private boolean useStdOut = false;
  97. /* rendering options (for the user agent) */
  98. private Map renderingOptions = new java.util.HashMap();
  99. /* target resolution (for the user agent) */
  100. private int targetResolution = 0;
  101. private FopFactory factory = FopFactory.newInstance();
  102. private FOUserAgent foUserAgent;
  103. private InputHandler inputHandler;
  104. private Log log;
  105. private Vector xsltParams = null;
  106. private String mimicRenderer = null;
  107. /**
  108. * Construct a command line option object.
  109. */
  110. public CommandLineOptions() {
  111. LogFactory logFactory = LogFactory.getFactory();
  112. // Enable the simple command line logging when no other logger is
  113. // defined.
  114. if (System.getProperty("org.apache.commons.logging.Log") == null) {
  115. logFactory.setAttribute("org.apache.commons.logging.Log",
  116. CommandLineLogger.class.getName());
  117. setLogLevel("info");
  118. }
  119. log = LogFactory.getLog("FOP");
  120. }
  121. /**
  122. * Parses the command line arguments.
  123. *
  124. * @param args the command line arguments.
  125. * @throws FOPException for general errors
  126. * @throws IOException if the the configuration file could not be loaded
  127. * @return true if the processing can continue, false to abort
  128. */
  129. public boolean parse(String[] args)
  130. throws FOPException, IOException {
  131. boolean optionsParsed = true;
  132. try {
  133. optionsParsed = parseOptions(args);
  134. if (optionsParsed) {
  135. if (showConfiguration == Boolean.TRUE) {
  136. dumpConfiguration();
  137. }
  138. checkSettings();
  139. setUserConfig();
  140. //Factory config is set up, now we can create the user agent
  141. foUserAgent = factory.newFOUserAgent();
  142. foUserAgent.getRendererOptions().putAll(renderingOptions);
  143. if (targetResolution != 0) {
  144. foUserAgent.setTargetResolution(targetResolution);
  145. }
  146. addXSLTParameter("fop-output-format", getOutputFormat());
  147. addXSLTParameter("fop-version", Version.getVersion());
  148. } else {
  149. return false;
  150. }
  151. } catch (FOPException e) {
  152. printUsage(System.err);
  153. throw e;
  154. } catch (java.io.FileNotFoundException e) {
  155. printUsage(System.err);
  156. throw e;
  157. }
  158. inputHandler = createInputHandler();
  159. if (MimeConstants.MIME_FOP_AWT_PREVIEW.equals(outputmode)) {
  160. //set the system look&feel for the preview dialog
  161. try {
  162. UIManager.setLookAndFeel(
  163. UIManager.getSystemLookAndFeelClassName());
  164. } catch (Exception e) {
  165. System.err.println("Couldn't set system look & feel!");
  166. }
  167. AWTRenderer renderer = new AWTRenderer(true);
  168. renderer.setRenderable(inputHandler); //set before user agent!
  169. renderer.setUserAgent(foUserAgent);
  170. foUserAgent.setRendererOverride(renderer);
  171. } else if (MimeConstants.MIME_FOP_AREA_TREE.equals(outputmode)
  172. && mimicRenderer != null) {
  173. // render from FO to Intermediate Format
  174. Renderer targetRenderer = foUserAgent.getRendererFactory().createRenderer(
  175. foUserAgent, mimicRenderer);
  176. XMLRenderer xmlRenderer = new XMLRenderer();
  177. xmlRenderer.setUserAgent(foUserAgent);
  178. //Tell the XMLRenderer to mimic the target renderer
  179. xmlRenderer.mimicRenderer(targetRenderer);
  180. //Make sure the prepared XMLRenderer is used
  181. foUserAgent.setRendererOverride(xmlRenderer);
  182. } else if (MimeConstants.MIME_FOP_IF.equals(outputmode)) {
  183. // render from FO to Intermediate Format
  184. IFRenderer xml2Renderer = new IFRenderer();
  185. xml2Renderer.setUserAgent(foUserAgent);
  186. //Make sure the prepared IFRenderer is used
  187. foUserAgent.setRendererOverride(xml2Renderer);
  188. }
  189. return true;
  190. }
  191. /**
  192. * @return the InputHandler instance defined by the command-line options.
  193. */
  194. public InputHandler getInputHandler() {
  195. return inputHandler;
  196. }
  197. /**
  198. * Get the logger.
  199. * @return the logger
  200. */
  201. public Log getLogger() {
  202. return log;
  203. }
  204. private void addXSLTParameter(String name, String value) {
  205. if (xsltParams == null) {
  206. xsltParams = new Vector();
  207. }
  208. xsltParams.addElement(name);
  209. xsltParams.addElement(value);
  210. }
  211. /**
  212. * Parses the command line arguments.
  213. *
  214. * @return true if processing can continue, false if it should stop (nothing to do)
  215. * @exception FOPException if there was an error in the format of the options
  216. */
  217. private boolean parseOptions(String[] args) throws FOPException {
  218. // do not throw an exception for no args
  219. if (args.length == 0) {
  220. printVersion();
  221. printUsage(System.out);
  222. return false;
  223. }
  224. for (int i = 0; i < args.length; i++) {
  225. if (args[i].equals("-x")
  226. || args[i].equals("--dump-config")) {
  227. showConfiguration = Boolean.TRUE;
  228. } else if (args[i].equals("-c")) {
  229. i = i + parseConfigurationOption(args, i);
  230. } else if (args[i].equals("-l")) {
  231. i = i + parseLanguageOption(args, i);
  232. } else if (args[i].equals("-s")) {
  233. suppressLowLevelAreas = Boolean.TRUE;
  234. } else if (args[i].equals("-d")) {
  235. setLogOption("debug", "debug");
  236. } else if (args[i].equals("-r")) {
  237. factory.setStrictValidation(false);
  238. } else if (args[i].equals("-dpi")) {
  239. i = i + parseResolution(args, i);
  240. } else if (args[i].equals("-q") || args[i].equals("--quiet")) {
  241. setLogOption("quiet", "error");
  242. } else if (args[i].equals("-fo")) {
  243. i = i + parseFOInputOption(args, i);
  244. } else if (args[i].equals("-xsl")) {
  245. i = i + parseXSLInputOption(args, i);
  246. } else if (args[i].equals("-xml")) {
  247. i = i + parseXMLInputOption(args, i);
  248. } else if (args[i].equals("-atin")) {
  249. i = i + parseAreaTreeInputOption(args, i);
  250. } else if (args[i].equals("-ifin")) {
  251. i = i + parseIFInputOption(args, i);
  252. } else if (args[i].equals("-imagein")) {
  253. i = i + parseImageInputOption(args, i);
  254. } else if (args[i].equals("-awt")) {
  255. i = i + parseAWTOutputOption(args, i);
  256. } else if (args[i].equals("-pdf")) {
  257. i = i + parsePDFOutputOption(args, i, null);
  258. } else if (args[i].equals("-pdfa1b")) {
  259. i = i + parsePDFOutputOption(args, i, "PDF/A-1b");
  260. } else if (args[i].equals("-mif")) {
  261. i = i + parseMIFOutputOption(args, i);
  262. } else if (args[i].equals("-rtf")) {
  263. i = i + parseRTFOutputOption(args, i);
  264. } else if (args[i].equals("-tiff")) {
  265. i = i + parseTIFFOutputOption(args, i);
  266. } else if (args[i].equals("-png")) {
  267. i = i + parsePNGOutputOption(args, i);
  268. } else if (args[i].equals("-print")) {
  269. // show print help
  270. if (i + 1 < args.length) {
  271. if (args[i + 1].equals("help")) {
  272. printUsagePrintOutput();
  273. return false;
  274. }
  275. }
  276. i = i + parsePrintOutputOption(args, i);
  277. } else if (args[i].equals("-copies")) {
  278. i = i + parseCopiesOption(args, i);
  279. } else if (args[i].equals("-pcl")) {
  280. i = i + parsePCLOutputOption(args, i);
  281. } else if (args[i].equals("-ps")) {
  282. i = i + parsePostscriptOutputOption(args, i);
  283. } else if (args[i].equals("-txt")) {
  284. i = i + parseTextOutputOption(args, i);
  285. } else if (args[i].equals("-svg")) {
  286. i = i + parseSVGOutputOption(args, i);
  287. } else if (args[i].equals("-afp")) {
  288. i = i + parseAFPOutputOption(args, i);
  289. } else if (args[i].equals("-foout")) {
  290. i = i + parseFOOutputOption(args, i);
  291. } else if (args[i].equals("-out")) {
  292. i = i + parseCustomOutputOption(args, i);
  293. } else if (args[i].equals("-at")) {
  294. i = i + parseAreaTreeOption(args, i);
  295. } else if (args[i].equals("-if")) {
  296. i = i + parseIntermediateFormatOption(args, i);
  297. } else if (args[i].equals("-v")) {
  298. printVersion();
  299. return false;
  300. } else if (args[i].equals("-param")) {
  301. if (i + 2 < args.length) {
  302. String name = args[++i];
  303. String expression = args[++i];
  304. addXSLTParameter(name, expression);
  305. } else {
  306. throw new FOPException("invalid param usage: use -param <name> <value>");
  307. }
  308. } else if (args[i].equals("-o")) {
  309. i = i + parsePDFOwnerPassword(args, i);
  310. } else if (args[i].equals("-u")) {
  311. i = i + parsePDFUserPassword(args, i);
  312. } else if (args[i].equals("-pdfprofile")) {
  313. i = i + parsePDFProfile(args, i);
  314. } else if (args[i].equals("-noprint")) {
  315. getPDFEncryptionParams().setAllowPrint(false);
  316. } else if (args[i].equals("-nocopy")) {
  317. getPDFEncryptionParams().setAllowCopyContent(false);
  318. } else if (args[i].equals("-noedit")) {
  319. getPDFEncryptionParams().setAllowEditContent(false);
  320. } else if (args[i].equals("-noannotations")) {
  321. getPDFEncryptionParams().setAllowEditAnnotations(false);
  322. } else if (!isOption(args[i])) {
  323. i = i + parseUnknownOption(args, i);
  324. } else {
  325. printUsage(System.err);
  326. System.exit(1);
  327. }
  328. }
  329. return true;
  330. } // end parseOptions
  331. private int parseConfigurationOption(String[] args, int i) throws FOPException {
  332. if ((i + 1 == args.length)
  333. || (isOption(args[i + 1]))) {
  334. throw new FOPException("if you use '-c', you must specify "
  335. + "the name of the configuration file");
  336. } else {
  337. userConfigFile = new File(args[i + 1]);
  338. return 1;
  339. }
  340. }
  341. private int parseLanguageOption(String[] args, int i) throws FOPException {
  342. if ((i + 1 == args.length)
  343. || (isOption(args[i + 1]))) {
  344. throw new FOPException("if you use '-l', you must specify a language");
  345. } else {
  346. Locale.setDefault(new Locale(args[i + 1], ""));
  347. return 1;
  348. }
  349. }
  350. private int parseResolution(String[] args, int i) throws FOPException {
  351. if ((i + 1 == args.length)
  352. || (isOption(args[i + 1]))) {
  353. throw new FOPException(
  354. "if you use '-dpi', you must specify a resolution (dots per inch)");
  355. } else {
  356. this.targetResolution = Integer.parseInt(args[i + 1]);
  357. return 1;
  358. }
  359. }
  360. private int parseFOInputOption(String[] args, int i) throws FOPException {
  361. setInputFormat(FO_INPUT);
  362. if ((i + 1 == args.length)
  363. || (isOption(args[i + 1]))) {
  364. throw new FOPException("you must specify the fo file for the '-fo' option");
  365. } else {
  366. String filename = args[i + 1];
  367. if (isSystemInOutFile(filename)) {
  368. this.useStdIn = true;
  369. } else {
  370. fofile = new File(filename);
  371. }
  372. return 1;
  373. }
  374. }
  375. private int parseXSLInputOption(String[] args, int i) throws FOPException {
  376. setInputFormat(XSLT_INPUT);
  377. if ((i + 1 == args.length)
  378. || (isOption(args[i + 1]))) {
  379. throw new FOPException("you must specify the stylesheet "
  380. + "file for the '-xsl' option");
  381. } else {
  382. xsltfile = new File(args[i + 1]);
  383. return 1;
  384. }
  385. }
  386. private int parseXMLInputOption(String[] args, int i) throws FOPException {
  387. setInputFormat(XSLT_INPUT);
  388. if ((i + 1 == args.length)
  389. || (isOption(args[i + 1]))) {
  390. throw new FOPException("you must specify the input file "
  391. + "for the '-xml' option");
  392. } else {
  393. String filename = args[i + 1];
  394. if (isSystemInOutFile(filename)) {
  395. this.useStdIn = true;
  396. } else {
  397. xmlfile = new File(filename);
  398. }
  399. return 1;
  400. }
  401. }
  402. private int parseAWTOutputOption(String[] args, int i) throws FOPException {
  403. setOutputMode(MimeConstants.MIME_FOP_AWT_PREVIEW);
  404. return 0;
  405. }
  406. private int parsePDFOutputOption(String[] args, int i, String pdfAMode) throws FOPException {
  407. setOutputMode(MimeConstants.MIME_PDF);
  408. if ((i + 1 == args.length)
  409. || (isOption(args[i + 1]))) {
  410. throw new FOPException("you must specify the PDF output file");
  411. } else {
  412. setOutputFile(args[i + 1]);
  413. if (pdfAMode != null) {
  414. if (renderingOptions.get("pdf-a-mode") != null) {
  415. throw new FOPException("PDF/A mode already set");
  416. }
  417. renderingOptions.put("pdf-a-mode", pdfAMode);
  418. }
  419. return 1;
  420. }
  421. }
  422. private void setOutputFile(String filename) {
  423. if (isSystemInOutFile(filename)) {
  424. this.useStdOut = true;
  425. } else {
  426. outfile = new File(filename);
  427. }
  428. }
  429. /**
  430. * Checks whether the given argument is the next option or the specification of
  431. * stdin/stdout.
  432. *
  433. * TODO this is very ad-hoc and should be better handled. Consider the adoption of
  434. * Apache Commons CLI.
  435. *
  436. * @param arg an argument
  437. * @return true if the argument is an option ("-something"), false otherwise
  438. */
  439. private boolean isOption(String arg) {
  440. return arg.length() > 1 && arg.startsWith("-");
  441. }
  442. private boolean isSystemInOutFile(String filename) {
  443. return "-".equals(filename);
  444. }
  445. private int parseMIFOutputOption(String[] args, int i) throws FOPException {
  446. setOutputMode(MimeConstants.MIME_MIF);
  447. if ((i + 1 == args.length)
  448. || (isOption(args[i + 1]))) {
  449. throw new FOPException("you must specify the MIF output file");
  450. } else {
  451. setOutputFile(args[i + 1]);
  452. return 1;
  453. }
  454. }
  455. private int parseRTFOutputOption(String[] args, int i) throws FOPException {
  456. setOutputMode(MimeConstants.MIME_RTF);
  457. if ((i + 1 == args.length)
  458. || (isOption(args[i + 1]))) {
  459. throw new FOPException("you must specify the RTF output file");
  460. } else {
  461. setOutputFile(args[i + 1]);
  462. return 1;
  463. }
  464. }
  465. private int parseTIFFOutputOption(String[] args, int i) throws FOPException {
  466. setOutputMode(MimeConstants.MIME_TIFF);
  467. if ((i + 1 == args.length)
  468. || (isOption(args[i + 1]))) {
  469. throw new FOPException("you must specify the TIFF output file");
  470. } else {
  471. setOutputFile(args[i + 1]);
  472. return 1;
  473. }
  474. }
  475. private int parsePNGOutputOption(String[] args, int i) throws FOPException {
  476. setOutputMode(MimeConstants.MIME_PNG);
  477. if ((i + 1 == args.length)
  478. || (isOption(args[i + 1]))) {
  479. throw new FOPException("you must specify the PNG output file");
  480. } else {
  481. setOutputFile(args[i + 1]);
  482. return 1;
  483. }
  484. }
  485. private int parsePrintOutputOption(String[] args, int i) throws FOPException {
  486. setOutputMode(MimeConstants.MIME_FOP_PRINT);
  487. if ((i + 1 <= args.length)
  488. && (args[i + 1].charAt(0) != '-')) {
  489. String arg = args[i + 1];
  490. String[] parts = arg.split(",");
  491. for (int j = 0; j < parts.length; j++) {
  492. String s = parts[j];
  493. if (s.matches("\\d+")) {
  494. renderingOptions.put(PrintRenderer.START_PAGE, new Integer(s));
  495. } else if (s.matches("\\d+-\\d+")) {
  496. String[] startend = s.split("-");
  497. renderingOptions.put(PrintRenderer.START_PAGE, new Integer(startend[0]));
  498. renderingOptions.put(PrintRenderer.END_PAGE, new Integer(startend[1]));
  499. } else {
  500. PagesMode mode = PagesMode.byName(s);
  501. renderingOptions.put(PrintRenderer.PAGES_MODE, mode);
  502. }
  503. }
  504. return 1;
  505. } else {
  506. return 0;
  507. }
  508. }
  509. private int parseCopiesOption(String[] args, int i) throws FOPException {
  510. if ((i + 1 == args.length)
  511. || (isOption(args[i + 1]))) {
  512. throw new FOPException("you must specify the number of copies");
  513. } else {
  514. renderingOptions.put(PrintRenderer.COPIES, new Integer(args[i + 1]));
  515. return 1;
  516. }
  517. }
  518. private int parsePCLOutputOption(String[] args, int i) throws FOPException {
  519. setOutputMode(MimeConstants.MIME_PCL);
  520. if ((i + 1 == args.length)
  521. || (isOption(args[i + 1]))) {
  522. throw new FOPException("you must specify the PDF output file");
  523. } else {
  524. setOutputFile(args[i + 1]);
  525. return 1;
  526. }
  527. }
  528. private int parsePostscriptOutputOption(String[] args, int i) throws FOPException {
  529. setOutputMode(MimeConstants.MIME_POSTSCRIPT);
  530. if ((i + 1 == args.length)
  531. || (isOption(args[i + 1]))) {
  532. throw new FOPException("you must specify the PostScript output file");
  533. } else {
  534. setOutputFile(args[i + 1]);
  535. return 1;
  536. }
  537. }
  538. private int parseTextOutputOption(String[] args, int i) throws FOPException {
  539. setOutputMode(MimeConstants.MIME_PLAIN_TEXT);
  540. if ((i + 1 == args.length)
  541. || (isOption(args[i + 1]))) {
  542. throw new FOPException("you must specify the text output file");
  543. } else {
  544. setOutputFile(args[i + 1]);
  545. return 1;
  546. }
  547. }
  548. private int parseSVGOutputOption(String[] args, int i) throws FOPException {
  549. setOutputMode(MimeConstants.MIME_SVG);
  550. if ((i + 1 == args.length)
  551. || (isOption(args[i + 1]))) {
  552. throw new FOPException("you must specify the SVG output file");
  553. } else {
  554. setOutputFile(args[i + 1]);
  555. return 1;
  556. }
  557. }
  558. private int parseAFPOutputOption(String[] args, int i) throws FOPException {
  559. setOutputMode(MimeConstants.MIME_AFP);
  560. if ((i + 1 == args.length)
  561. || (isOption(args[i + 1]))) {
  562. throw new FOPException("you must specify the AFP output file");
  563. } else {
  564. setOutputFile(args[i + 1]);
  565. return 1;
  566. }
  567. }
  568. private int parseFOOutputOption(String[] args, int i) throws FOPException {
  569. setOutputMode(MimeConstants.MIME_XSL_FO);
  570. if ((i + 1 == args.length)
  571. || (isOption(args[i + 1]))) {
  572. throw new FOPException("you must specify the FO output file");
  573. } else {
  574. setOutputFile(args[i + 1]);
  575. return 1;
  576. }
  577. }
  578. private int parseCustomOutputOption(String[] args, int i) throws FOPException {
  579. String mime = null;
  580. if ((i + 1 < args.length)
  581. || (args[i + 1].charAt(0) != '-')) {
  582. mime = args[i + 1];
  583. if ("list".equals(mime)) {
  584. String[] mimes = factory.getRendererFactory().listSupportedMimeTypes();
  585. System.out.println("Supported MIME types:");
  586. for (int j = 0; j < mimes.length; j++) {
  587. System.out.println(" " + mimes[j]);
  588. }
  589. System.exit(0);
  590. }
  591. }
  592. if ((i + 2 >= args.length)
  593. || (isOption(args[i + 1]))
  594. || (isOption(args[i + 2]))) {
  595. throw new FOPException("you must specify the output format and the output file");
  596. } else {
  597. setOutputMode(mime);
  598. setOutputFile(args[i + 2]);
  599. return 2;
  600. }
  601. }
  602. private int parseUnknownOption(String[] args, int i) throws FOPException {
  603. if (inputmode == NOT_SET) {
  604. inputmode = FO_INPUT;
  605. String filename = args[i];
  606. if (isSystemInOutFile(filename)) {
  607. this.useStdIn = true;
  608. } else {
  609. fofile = new File(filename);
  610. }
  611. } else if (outputmode == null) {
  612. outputmode = MimeConstants.MIME_PDF;
  613. setOutputFile(args[i]);
  614. } else {
  615. throw new FOPException("Don't know what to do with "
  616. + args[i]);
  617. }
  618. return 0;
  619. }
  620. private int parseAreaTreeOption(String[] args, int i) throws FOPException {
  621. setOutputMode(MimeConstants.MIME_FOP_AREA_TREE);
  622. if ((i + 1 == args.length)
  623. || (isOption(args[i + 1]))) {
  624. throw new FOPException("you must specify the area-tree output file");
  625. } else if ((i + 2 == args.length)
  626. || (isOption(args[i + 2]))) {
  627. // only output file is specified
  628. setOutputFile(args[i + 1]);
  629. return 1;
  630. } else {
  631. // mimic format and output file have been specified
  632. mimicRenderer = args[i + 1];
  633. setOutputFile(args[i + 2]);
  634. return 2;
  635. }
  636. }
  637. private int parseIntermediateFormatOption(String[] args, int i) throws FOPException {
  638. setOutputMode(MimeConstants.MIME_FOP_IF);
  639. if ((i + 1 == args.length)
  640. || (args[i + 1].charAt(0) == '-')) {
  641. throw new FOPException("you must specify the intermediate format output file");
  642. } else if ((i + 2 == args.length)
  643. || (args[i + 2].charAt(0) == '-')) {
  644. // only output file is specified
  645. outfile = new File(args[i + 1]);
  646. return 1;
  647. } else {
  648. // mimic format and output file have been specified
  649. outfile = new File(args[i + 2]);
  650. return 2;
  651. }
  652. }
  653. private int parseAreaTreeInputOption(String[] args, int i) throws FOPException {
  654. setInputFormat(AREATREE_INPUT);
  655. if ((i + 1 == args.length)
  656. || (isOption(args[i + 1]))) {
  657. throw new FOPException("you must specify the Area Tree file for the '-atin' option");
  658. } else {
  659. String filename = args[i + 1];
  660. if (isSystemInOutFile(filename)) {
  661. this.useStdIn = true;
  662. } else {
  663. areatreefile = new File(filename);
  664. }
  665. return 1;
  666. }
  667. }
  668. private int parseIFInputOption(String[] args, int i) throws FOPException {
  669. setInputFormat(IF_INPUT);
  670. if ((i + 1 == args.length)
  671. || (isOption(args[i + 1]))) {
  672. throw new FOPException("you must specify the intermediate file for the '-ifin' option");
  673. } else {
  674. String filename = args[i + 1];
  675. if (isSystemInOutFile(filename)) {
  676. this.useStdIn = true;
  677. } else {
  678. iffile = new File(filename);
  679. }
  680. return 1;
  681. }
  682. }
  683. private int parseImageInputOption(String[] args, int i) throws FOPException {
  684. setInputFormat(IMAGE_INPUT);
  685. if ((i + 1 == args.length)
  686. || (isOption(args[i + 1]))) {
  687. throw new FOPException("you must specify the image file for the '-imagein' option");
  688. } else {
  689. String filename = args[i + 1];
  690. if (isSystemInOutFile(filename)) {
  691. this.useStdIn = true;
  692. } else {
  693. imagefile = new File(filename);
  694. }
  695. return 1;
  696. }
  697. }
  698. private PDFEncryptionParams getPDFEncryptionParams() throws FOPException {
  699. PDFEncryptionParams params = (PDFEncryptionParams)renderingOptions.get(
  700. PDFRenderer.ENCRYPTION_PARAMS);
  701. if (params == null) {
  702. if (!PDFEncryptionManager.checkAvailableAlgorithms()) {
  703. throw new FOPException("PDF encryption requested but it is not available."
  704. + " Please make sure MD5 and RC4 algorithms are available.");
  705. }
  706. params = new PDFEncryptionParams();
  707. renderingOptions.put(PDFRenderer.ENCRYPTION_PARAMS, params);
  708. }
  709. return params;
  710. }
  711. private int parsePDFOwnerPassword(String[] args, int i) throws FOPException {
  712. if ((i + 1 == args.length)
  713. || (isOption(args[i + 1]))) {
  714. getPDFEncryptionParams().setOwnerPassword("");
  715. return 0;
  716. } else {
  717. getPDFEncryptionParams().setOwnerPassword(args[i + 1]);
  718. return 1;
  719. }
  720. }
  721. private int parsePDFUserPassword(String[] args, int i) throws FOPException {
  722. if ((i + 1 == args.length)
  723. || (isOption(args[i + 1]))) {
  724. getPDFEncryptionParams().setUserPassword("");
  725. return 0;
  726. } else {
  727. getPDFEncryptionParams().setUserPassword(args[i + 1]);
  728. return 1;
  729. }
  730. }
  731. private int parsePDFProfile(String[] args, int i) throws FOPException {
  732. if ((i + 1 == args.length)
  733. || (isOption(args[i + 1]))) {
  734. throw new FOPException("You must specify a PDF profile");
  735. } else {
  736. String profile = args[i + 1];
  737. PDFAMode pdfAMode = PDFAMode.valueOf(profile);
  738. if (pdfAMode != null && pdfAMode != PDFAMode.DISABLED) {
  739. if (renderingOptions.get("pdf-a-mode") != null) {
  740. throw new FOPException("PDF/A mode already set");
  741. }
  742. renderingOptions.put("pdf-a-mode", pdfAMode.getName());
  743. return 1;
  744. } else {
  745. PDFXMode pdfXMode = PDFXMode.valueOf(profile);
  746. if (pdfXMode != null && pdfXMode != PDFXMode.DISABLED) {
  747. if (renderingOptions.get("pdf-x-mode") != null) {
  748. throw new FOPException("PDF/X mode already set");
  749. }
  750. renderingOptions.put("pdf-x-mode", pdfXMode.getName());
  751. return 1;
  752. }
  753. }
  754. throw new FOPException("Unsupported PDF profile: " + profile);
  755. }
  756. }
  757. private void setOutputMode(String mime) throws FOPException {
  758. if (outputmode == null) {
  759. outputmode = mime;
  760. } else {
  761. throw new FOPException("you can only set one output method");
  762. }
  763. }
  764. private void setLogOption (String option, String level) {
  765. if (log instanceof CommandLineLogger
  766. || System.getProperty("org.apache.commons.logging.Log") == null) {
  767. setLogLevel(level);
  768. } else if (log != null) {
  769. log.warn("The option " + option + " can only be used");
  770. log.warn("with FOP's command line logger,");
  771. log.warn("which is the default on the command line.");
  772. log.warn("Configure other loggers using Java system properties.");
  773. }
  774. }
  775. private void setLogLevel(String level) {
  776. // Set the level for future loggers.
  777. LogFactory.getFactory().setAttribute("level", level);
  778. if (log instanceof CommandLineLogger) {
  779. // Set the level for the logger created already.
  780. ((CommandLineLogger) log).setLogLevel(level);
  781. }
  782. }
  783. private void setInputFormat(int format) throws FOPException {
  784. if (inputmode == NOT_SET || inputmode == format) {
  785. inputmode = format;
  786. } else {
  787. throw new FOPException("Only one input mode can be specified!");
  788. }
  789. }
  790. /**
  791. * checks whether all necessary information has been given in a consistent way
  792. */
  793. private void checkSettings() throws FOPException, FileNotFoundException {
  794. if (inputmode == NOT_SET) {
  795. throw new FOPException("No input file specified");
  796. }
  797. if (outputmode == null) {
  798. throw new FOPException("No output file specified");
  799. }
  800. if ((outputmode.equals(MimeConstants.MIME_FOP_AWT_PREVIEW)
  801. || outputmode.equals(MimeConstants.MIME_FOP_PRINT))
  802. && outfile != null) {
  803. throw new FOPException("Output file may not be specified "
  804. + "for AWT or PRINT output");
  805. }
  806. if (inputmode == XSLT_INPUT) {
  807. // check whether xml *and* xslt file have been set
  808. if (xmlfile == null && !this.useStdIn) {
  809. throw new FOPException("XML file must be specified for the transform mode");
  810. }
  811. if (xsltfile == null) {
  812. throw new FOPException("XSLT file must be specified for the transform mode");
  813. }
  814. // warning if fofile has been set in xslt mode
  815. if (fofile != null) {
  816. log.warn("Can't use fo file with transform mode! Ignoring.\n"
  817. + "Your input is " + "\n xmlfile: "
  818. + xmlfile.getAbsolutePath()
  819. + "\nxsltfile: "
  820. + xsltfile.getAbsolutePath()
  821. + "\n fofile: "
  822. + fofile.getAbsolutePath());
  823. }
  824. if (xmlfile != null && !xmlfile.exists()) {
  825. throw new FileNotFoundException("Error: xml file "
  826. + xmlfile.getAbsolutePath()
  827. + " not found ");
  828. }
  829. if (!xsltfile.exists()) {
  830. throw new FileNotFoundException("Error: xsl file "
  831. + xsltfile.getAbsolutePath()
  832. + " not found ");
  833. }
  834. } else if (inputmode == FO_INPUT) {
  835. if (outputmode.equals(MimeConstants.MIME_XSL_FO)) {
  836. throw new FOPException(
  837. "FO output mode is only available if you use -xml and -xsl");
  838. }
  839. if (fofile != null && !fofile.exists()) {
  840. throw new FileNotFoundException("Error: fo file "
  841. + fofile.getAbsolutePath()
  842. + " not found ");
  843. }
  844. } else if (inputmode == AREATREE_INPUT) {
  845. if (outputmode.equals(MimeConstants.MIME_XSL_FO)) {
  846. throw new FOPException(
  847. "FO output mode is only available if you use -xml and -xsl");
  848. } else if (outputmode.equals(MimeConstants.MIME_FOP_AREA_TREE)) {
  849. throw new FOPException(
  850. "Area Tree Output is not available if Area Tree is used as input!");
  851. }
  852. if (areatreefile != null && !areatreefile.exists()) {
  853. throw new FileNotFoundException("Error: area tree file "
  854. + areatreefile.getAbsolutePath()
  855. + " not found ");
  856. }
  857. } else if (inputmode == IF_INPUT) {
  858. if (outputmode.equals(MimeConstants.MIME_XSL_FO)) {
  859. throw new FOPException(
  860. "FO output mode is only available if you use -xml and -xsl");
  861. } else if (outputmode.equals(MimeConstants.MIME_FOP_AREA_TREE)) {
  862. throw new FOPException(
  863. "Area Tree Output is not available if Intermediate Format is used as input!");
  864. } else if (outputmode.equals(MimeConstants.MIME_FOP_IF)) {
  865. throw new FOPException(
  866. "Intermediate Output is not available if Intermediate Format is used as input!");
  867. }
  868. if (iffile != null && !iffile.exists()) {
  869. throw new FileNotFoundException("Error: intermediate format file "
  870. + iffile.getAbsolutePath()
  871. + " not found ");
  872. }
  873. } else if (inputmode == IMAGE_INPUT) {
  874. if (outputmode.equals(MimeConstants.MIME_XSL_FO)) {
  875. throw new FOPException(
  876. "FO output mode is only available if you use -xml and -xsl");
  877. }
  878. if (imagefile != null && !imagefile.exists()) {
  879. throw new FileNotFoundException("Error: image file "
  880. + imagefile.getAbsolutePath()
  881. + " not found ");
  882. }
  883. }
  884. } // end checkSettings
  885. /**
  886. * Sets the user configuration.
  887. * @throws FOPException if creating the user configuration fails
  888. * @throws IOException
  889. */
  890. private void setUserConfig() throws FOPException, IOException {
  891. if (userConfigFile == null) {
  892. return;
  893. }
  894. try {
  895. factory.setUserConfig(userConfigFile);
  896. } catch (SAXException e) {
  897. throw new FOPException(e);
  898. }
  899. }
  900. /**
  901. * @return the chosen output format (MIME type)
  902. * @throws FOPException for invalid output formats
  903. */
  904. protected String getOutputFormat() throws FOPException {
  905. if (outputmode == null) {
  906. throw new FOPException("Renderer has not been set!");
  907. }
  908. if (outputmode.equals(MimeConstants.MIME_FOP_AREA_TREE)) {
  909. renderingOptions.put("fineDetail", isCoarseAreaXml());
  910. }
  911. return outputmode;
  912. }
  913. /**
  914. * Create an InputHandler object based on command-line parameters
  915. * @return a new InputHandler instance
  916. * @throws IllegalArgumentException if invalid/missing parameters
  917. */
  918. private InputHandler createInputHandler() {
  919. switch (inputmode) {
  920. case FO_INPUT:
  921. return new InputHandler(fofile);
  922. case AREATREE_INPUT:
  923. return new AreaTreeInputHandler(areatreefile);
  924. case IF_INPUT:
  925. return new IFInputHandler(iffile);
  926. case XSLT_INPUT:
  927. return new InputHandler(xmlfile, xsltfile, xsltParams);
  928. case IMAGE_INPUT:
  929. return new ImageInputHandler(imagefile, xsltfile, xsltParams);
  930. default:
  931. throw new IllegalArgumentException("Error creating InputHandler object.");
  932. }
  933. }
  934. /**
  935. * Get the FOUserAgent for this Command-Line run
  936. * @return FOUserAgent instance
  937. */
  938. protected FOUserAgent getFOUserAgent() {
  939. return foUserAgent;
  940. }
  941. /**
  942. * Returns the XSL-FO file if set.
  943. * @return the XSL-FO file, null if not set
  944. */
  945. public File getFOFile() {
  946. return fofile;
  947. }
  948. /**
  949. * Returns the input XML file if set.
  950. * @return the input XML file, null if not set
  951. */
  952. public File getXMLFile() {
  953. return xmlfile;
  954. }
  955. /**
  956. * Returns the stylesheet to be used for transformation to XSL-FO.
  957. * @return stylesheet
  958. */
  959. public File getXSLFile() {
  960. return xsltfile;
  961. }
  962. /**
  963. * Returns the output file
  964. * @return the output file
  965. */
  966. public File getOutputFile() {
  967. return outfile;
  968. }
  969. /**
  970. * Returns the user configuration file to be used.
  971. * @return the userconfig.xml file
  972. */
  973. public File getUserConfigFile() {
  974. return userConfigFile;
  975. }
  976. /**
  977. * Indicates whether the XML renderer should generate coarse area XML
  978. * @return true if coarse area XML is desired
  979. */
  980. public Boolean isCoarseAreaXml() {
  981. return suppressLowLevelAreas;
  982. }
  983. /**
  984. * Indicates whether input comes from standard input (stdin).
  985. * @return true if input comes from standard input (stdin)
  986. */
  987. public boolean isInputFromStdIn() {
  988. return this.useStdIn;
  989. }
  990. /**
  991. * Indicates whether output is sent to standard output (stdout).
  992. * @return true if output is sent to standard output (stdout)
  993. */
  994. public boolean isOutputToStdOut() {
  995. return this.useStdOut;
  996. }
  997. /**
  998. * Returns the input file.
  999. * @return either the fofile or the xmlfile
  1000. */
  1001. public File getInputFile() {
  1002. switch (inputmode) {
  1003. case FO_INPUT:
  1004. return fofile;
  1005. case XSLT_INPUT:
  1006. return xmlfile;
  1007. default:
  1008. return fofile;
  1009. }
  1010. }
  1011. private static void printVersion() {
  1012. System.out.println("FOP Version " + Version.getVersion());
  1013. }
  1014. /**
  1015. * Shows the command line syntax including a summary of all available options and some
  1016. * examples.
  1017. *
  1018. * @param out the stream to which the message must be printed
  1019. */
  1020. public static void printUsage(PrintStream out) {
  1021. out.println(
  1022. "\nUSAGE\nfop [options] [-fo|-xml] infile [-xsl file] "
  1023. + "[-awt|-pdf|-mif|-rtf|-tiff|-png|-pcl|-ps|-txt|-at [mime]|-print] <outfile>\n"
  1024. + " [OPTIONS] \n"
  1025. + " -d debug mode \n"
  1026. + " -x dump configuration settings \n"
  1027. + " -q quiet mode \n"
  1028. + " -c cfg.xml use additional configuration file cfg.xml\n"
  1029. + " -l lang the language to use for user information \n"
  1030. + " -r relaxed/less strict validation (where available)\n"
  1031. + " -dpi xxx target resolution in dots per inch (dpi) where xxx is a number\n"
  1032. + " -s for area tree XML, down to block areas only\n"
  1033. + " -v to show FOP version being used\n\n"
  1034. + " -o [password] PDF file will be encrypted with option owner password\n"
  1035. + " -u [password] PDF file will be encrypted with option user password\n"
  1036. + " -noprint PDF file will be encrypted without printing permission\n"
  1037. + " -nocopy PDF file will be encrypted without copy content permission\n"
  1038. + " -noedit PDF file will be encrypted without edit content permission\n"
  1039. + " -noannotations PDF file will be encrypted without edit annotation permission\n"
  1040. + " -pdfprofile prof PDF file will be generated with the specified profile\n"
  1041. + " (Examples for prof: PDF/A-1b or PDF/X-3:2003)\n\n"
  1042. + " [INPUT] \n"
  1043. + " infile xsl:fo input file (the same as the next) \n"
  1044. + " (use '-' for infile to pipe input from stdin)\n"
  1045. + " -fo infile xsl:fo input file \n"
  1046. + " -xml infile xml input file, must be used together with -xsl \n"
  1047. + " -atin infile area tree input file \n"
  1048. + " -ifin infile intermediate format input file \n"
  1049. + " -imagein infile image input file (piping through stdin not supported)\n"
  1050. + " -xsl stylesheet xslt stylesheet \n \n"
  1051. + " -param name value <value> to use for parameter <name> in xslt stylesheet\n"
  1052. + " (repeat '-param name value' for each parameter)\n \n"
  1053. + " [OUTPUT] \n"
  1054. + " outfile input will be rendered as PDF into outfile\n"
  1055. + " (use '-' for outfile to pipe output to stdout)\n"
  1056. + " -pdf outfile input will be rendered as PDF (outfile req'd)\n"
  1057. + " -pdfa1b outfile input will be rendered as PDF/A-1b compliant PDF\n"
  1058. + " (outfile req'd, same as \"-pdf outfile -pdfprofile PDF/A-1b\")\n"
  1059. + " -awt input will be displayed on screen \n"
  1060. + " -rtf outfile input will be rendered as RTF (outfile req'd)\n"
  1061. + " -pcl outfile input will be rendered as PCL (outfile req'd) \n"
  1062. + " -ps outfile input will be rendered as PostScript (outfile req'd) \n"
  1063. + " -afp outfile input will be rendered as AFP (outfile req'd)\n"
  1064. + " -tiff outfile input will be rendered as TIFF (outfile req'd)\n"
  1065. + " -png outfile input will be rendered as PNG (outfile req'd)\n"
  1066. + " -txt outfile input will be rendered as plain text (outfile req'd) \n"
  1067. + " -at [mime] out representation of area tree as XML (outfile req'd) \n"
  1068. + " specify optional mime output to allow AT to be converted\n"
  1069. + " to final format later\n"
  1070. + " -if out representation of area tree as intermediate format XML (outfile req'd)\n"
  1071. + " -print input file will be rendered and sent to the printer \n"
  1072. + " see options with \"-print help\" \n"
  1073. + " -out mime outfile input will be rendered using the given MIME type\n"
  1074. + " (outfile req'd) Example: \"-out application/pdf D:\\out.pdf\"\n"
  1075. + " (Tip: \"-out list\" prints the list of supported MIME types)\n"
  1076. + " -mif outfile input will be rendered as MIF (FrameMaker) (outfile req'd)\n"
  1077. + " Experimental feature - requires additional fop-sandbox.jar.\n"
  1078. + " -svg outfile input will be rendered as an SVG slides file (outfile req'd) \n"
  1079. + " Experimental feature - requires additional fop-sandbox.jar.\n"
  1080. + "\n"
  1081. + " -foout outfile input will only be XSL transformed. The intermediate \n"
  1082. + " XSL-FO file is saved and no rendering is performed. \n"
  1083. + " (Only available if you use -xml and -xsl parameters)\n\n"
  1084. + "\n"
  1085. + " [Examples]\n" + " fop foo.fo foo.pdf \n"
  1086. + " fop -fo foo.fo -pdf foo.pdf (does the same as the previous line)\n"
  1087. + " fop -xml foo.xml -xsl foo.xsl -pdf foo.pdf\n"
  1088. + " fop -xml foo.xml -xsl foo.xsl -foout foo.fo\n"
  1089. + " fop -xml - -xsl foo.xsl -pdf -\n"
  1090. + " fop foo.fo -mif foo.mif\n"
  1091. + " fop foo.fo -rtf foo.rtf\n"
  1092. + " fop foo.fo -print\n"
  1093. + " fop foo.fo -awt\n");
  1094. }
  1095. /**
  1096. * shows the options for print output
  1097. */
  1098. private void printUsagePrintOutput() {
  1099. System.err.println("USAGE: -print [from[-to][,even|odd]] [-copies numCopies]\n\n"
  1100. + "Example:\n"
  1101. + "all pages: fop infile.fo -print\n"
  1102. + "all pages with two copies: fop infile.fo -print -copies 2\n"
  1103. + "all pages starting with page 7: fop infile.fo -print 7\n"
  1104. + "pages 2 to 3: fop infile.fo -print 2-3\n"
  1105. + "only even page between 10 and 20: fop infile.fo -print 10-20,even\n");
  1106. }
  1107. /**
  1108. * Outputs all commandline settings
  1109. */
  1110. private void dumpConfiguration() {
  1111. log.info("Input mode: ");
  1112. switch (inputmode) {
  1113. case NOT_SET:
  1114. log.info("not set");
  1115. break;
  1116. case FO_INPUT:
  1117. log.info("FO ");
  1118. if (this.useStdIn) {
  1119. log.info("fo input file: from stdin");
  1120. } else {
  1121. log.info("fo input file: " + fofile.toString());
  1122. }
  1123. break;
  1124. case XSLT_INPUT:
  1125. log.info("xslt transformation");
  1126. if (this.useStdIn) {
  1127. log.info("xml input file: from stdin");
  1128. } else {
  1129. log.info("xml input file: " + xmlfile.toString());
  1130. }
  1131. log.info("xslt stylesheet: " + xsltfile.toString());
  1132. break;
  1133. case AREATREE_INPUT:
  1134. log.info("AT ");
  1135. if (this.useStdIn) {
  1136. log.info("area tree input file: from stdin");
  1137. } else {
  1138. log.info("area tree input file: " + areatreefile.toString());
  1139. }
  1140. break;
  1141. case IF_INPUT:
  1142. log.info("IF ");
  1143. if (this.useStdIn) {
  1144. log.info("intermediate input file: from stdin");
  1145. } else {
  1146. log.info("intermediate input file: " + iffile.toString());
  1147. }
  1148. break;
  1149. case IMAGE_INPUT:
  1150. log.info("Image ");
  1151. if (this.useStdIn) {
  1152. log.info("image input file: from stdin");
  1153. } else {
  1154. log.info("image input file: " + imagefile.toString());
  1155. }
  1156. break;
  1157. default:
  1158. log.info("unknown input type");
  1159. }
  1160. log.info("Output mode: ");
  1161. if (outputmode == null) {
  1162. log.info("not set");
  1163. } else if (MimeConstants.MIME_FOP_AWT_PREVIEW.equals(outputmode)) {
  1164. log.info("awt on screen");
  1165. if (outfile != null) {
  1166. log.error("awt mode, but outfile is set:");
  1167. log.error("out file: " + outfile.toString());
  1168. }
  1169. } else if (MimeConstants.MIME_FOP_PRINT.equals(outputmode)) {
  1170. log.info("print directly");
  1171. if (outfile != null) {
  1172. log.error("print mode, but outfile is set:");
  1173. log.error("out file: " + outfile.toString());
  1174. }
  1175. } else if (MimeConstants.MIME_FOP_AREA_TREE.equals(outputmode)) {
  1176. log.info("area tree");
  1177. if (mimicRenderer != null) {
  1178. log.info("mimic renderer: " + mimicRenderer);
  1179. }
  1180. if (this.useStdOut) {
  1181. log.info("output file: to stdout");
  1182. } else {
  1183. log.info("output file: " + outfile.toString());
  1184. }
  1185. } else if (MimeConstants.MIME_FOP_IF.equals(outputmode)) {
  1186. log.info("intermediate format");
  1187. log.info("output file: " + outfile.toString());
  1188. } else {
  1189. log.info(outputmode);
  1190. if (this.useStdOut) {
  1191. log.info("output file: to stdout");
  1192. } else {
  1193. log.info("output file: " + outfile.toString());
  1194. }
  1195. }
  1196. log.info("OPTIONS");
  1197. if (userConfigFile != null) {
  1198. log.info("user configuration file: "
  1199. + userConfigFile.toString());
  1200. } else {
  1201. log.info("no user configuration file is used [default]");
  1202. }
  1203. }
  1204. }