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

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