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

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