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

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