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

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