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

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