Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

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