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

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