KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > apps > CommandLineOptions


1 /*
2  * $Id: CommandLineOptions.java,v 1.14.2.10 2003/03/05 18:58:15 pietsch Exp $
3  * ============================================================================
4  * The Apache Software License, Version 1.1
5  * ============================================================================
6  *
7  * Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without modifica-
10  * tion, are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * 3. The end-user documentation included with the redistribution, if any, must
20  * include the following acknowledgment: "This product includes software
21  * developed by the Apache Software Foundation (http://www.apache.org/)."
22  * Alternately, this acknowledgment may appear in the software itself, if
23  * and wherever such third-party acknowledgments normally appear.
24  *
25  * 4. The names "FOP" and "Apache Software Foundation" must not be used to
26  * endorse or promote products derived from this software without prior
27  * written permission. For written permission, please contact
28  * apache@apache.org.
29  *
30  * 5. Products derived from this software may not be called "Apache", nor may
31  * "Apache" appear in their name, without prior written permission of the
32  * Apache Software Foundation.
33  *
34  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
35  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
36  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
37  * APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
38  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
39  * DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
40  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
41  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
42  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
43  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44  * ============================================================================
45  *
46  * This software consists of voluntary contributions made by many individuals
47  * on behalf of the Apache Software Foundation and was originally created by
48  * James Tauber <jtauber@jtauber.com>. For more information on the Apache
49  * Software Foundation, please see <http://www.apache.org/>.
50  */

51 package org.apache.fop.apps;
52
53 // FOP
54
import org.apache.fop.apps.FOPException;
55 import org.apache.fop.messaging.MessageHandler;
56 import org.apache.fop.render.txt.TXTRenderer;
57
58 // Avalon
59
import org.apache.avalon.framework.logger.ConsoleLogger;
60 import org.apache.avalon.framework.logger.Logger;
61
62 // Java
63
import java.io.File JavaDoc;
64 import java.io.FileNotFoundException JavaDoc;
65
66 /**
67  * Options parses the commandline arguments
68  */

69 public class CommandLineOptions {
70
71     /* input / output not set */
72     private static final int NOT_SET = 0;
73     /* input: fo file */
74     private static final int FO_INPUT = 1;
75     /* input: xml+xsl file */
76     private static final int XSLT_INPUT = 2;
77     /* output: pdf file */
78     private static final int PDF_OUTPUT = 1;
79     /* output: screen using swing */
80     private static final int AWT_OUTPUT = 2;
81     /* output: mif file */
82     private static final int MIF_OUTPUT = 3;
83     /* output: sent swing rendered file to printer */
84     private static final int PRINT_OUTPUT = 4;
85     /* output: pcl file */
86     private static final int PCL_OUTPUT = 5;
87     /* output: postscript file */
88     private static final int PS_OUTPUT = 6;
89     /* output: text file */
90     private static final int TXT_OUTPUT = 7;
91     /* output: svg file */
92     private static final int SVG_OUTPUT = 8;
93     /* output: XML area tree */
94     private static final int AREA_OUTPUT = 9;
95
96     /* use debug mode */
97     Boolean JavaDoc errorDump = Boolean.FALSE;
98     /* show configuration information */
99     Boolean JavaDoc dumpConfiguration = Boolean.FALSE;
100     /* suppress any progress information */
101     Boolean JavaDoc quiet = Boolean.FALSE;
102     /* for area tree XML output, only down to block area level */
103     Boolean JavaDoc suppressLowLevelAreas = Boolean.FALSE;
104     /* user configuration file */
105     File JavaDoc userConfigFile = null;
106     /* input fo file */
107     File JavaDoc fofile = null;
108     /* xsltfile (xslt transformation as input) */
109     File JavaDoc xsltfile = null;
110     /* xml file (xslt transformation as input) */
111     File JavaDoc xmlfile = null;
112     /* output file */
113     File JavaDoc outfile = null;
114     /* input mode */
115     int inputmode = NOT_SET;
116     /* output mode */
117     int outputmode = NOT_SET;
118     /* language for user information */
119     String JavaDoc language = null;
120
121     private java.util.HashMap JavaDoc rendererOptions;
122
123     private Logger log;
124
125     public CommandLineOptions(String JavaDoc[] args)
126             throws FOPException, FileNotFoundException JavaDoc {
127
128         setLogger(new ConsoleLogger(ConsoleLogger.LEVEL_INFO));
129
130         boolean optionsParsed = true;
131         rendererOptions = new java.util.HashMap JavaDoc();
132         try {
133             optionsParsed = parseOptions(args);
134             if (optionsParsed) {
135                 checkSettings();
136                 if (errorDump != null && errorDump.booleanValue()) {
137                     debug();
138                 }
139             }
140         } catch (FOPException e) {
141             printUsage();
142             throw e;
143         } catch (java.io.FileNotFoundException JavaDoc e) {
144             printUsage();
145             throw e;
146         }
147
148     }
149
150     private boolean pdfEncryptionAvailable = false;
151     private boolean pdfEncryptionChecked = false;
152     private boolean encryptionAvailable() {
153         if (!pdfEncryptionChecked) {
154             try {
155                 Class JavaDoc c = Class.forName("javax.crypto.Cipher");
156                 pdfEncryptionAvailable
157                     = org.apache.fop.pdf.PDFEncryption.encryptionAvailable();
158             }
159             catch(ClassNotFoundException JavaDoc e) {
160                 pdfEncryptionAvailable = false;
161             }
162             pdfEncryptionChecked = true;
163             if (!pdfEncryptionAvailable) {
164                 log.warn("PDF encryption not available.");
165             }
166         }
167         return pdfEncryptionAvailable;
168     }
169     
170     /**
171      * parses the commandline arguments
172      * @return true if parse was successful and procesing can continue, false if processing should stop
173      * @exception FOPException if there was an error in the format of the options
174      */

175     private boolean parseOptions(String JavaDoc args[]) throws FOPException {
176         for (int i = 0; i < args.length; i++) {
177             if (args[i].equals("-d") || args[i].equals("--full-error-dump")) {
178                 errorDump = Boolean.TRUE;
179                 setLogger(new ConsoleLogger(ConsoleLogger.LEVEL_DEBUG));
180             } else if (args[i].equals("-x")
181                        || args[i].equals("--dump-config")) {
182                 dumpConfiguration = Boolean.TRUE;
183             } else if (args[i].equals("-q") || args[i].equals("--quiet")) {
184                 quiet = Boolean.TRUE;
185                 setLogger(new ConsoleLogger(ConsoleLogger.LEVEL_ERROR));
186             } else if (args[i].equals("-c")) {
187                 if ((i + 1 == args.length)
188                         || (args[i + 1].charAt(0) == '-')) {
189                     throw new FOPException("if you use '-c', you must specify the name of the configuration file");
190                 } else {
191                     userConfigFile = new File JavaDoc(args[i + 1]);
192                     i++;
193                 }
194             } else if (args[i].equals("-l")) {
195                 if ((i + 1 == args.length)
196                         || (args[i + 1].charAt(0) == '-')) {
197                     throw new FOPException("if you use '-l', you must specify a language");
198                 } else {
199                     language = args[i + 1];
200                     i++;
201                 }
202             } else if (args[i].equals("-s")) {
203                 suppressLowLevelAreas = Boolean.TRUE;
204             } else if (args[i].equals("-fo")) {
205                 inputmode = FO_INPUT;
206                 if ((i + 1 == args.length)
207                         || (args[i + 1].charAt(0) == '-')) {
208                     throw new FOPException("you must specify the fo file for the '-fo' option");
209                 } else {
210                     fofile = new File JavaDoc(args[i + 1]);
211                     i++;
212                 }
213             } else if (args[i].equals("-xsl")) {
214                 inputmode = XSLT_INPUT;
215                 if ((i + 1 == args.length)
216                         || (args[i + 1].charAt(0) == '-')) {
217                     throw new FOPException("you must specify the stylesheet file for the '-xsl' option");
218                 } else {
219                     xsltfile = new File JavaDoc(args[i + 1]);
220                     i++;
221                 }
222             } else if (args[i].equals("-xml")) {
223                 inputmode = XSLT_INPUT;
224                 if ((i + 1 == args.length)
225                         || (args[i + 1].charAt(0) == '-')) {
226                     throw new FOPException("you must specify the input file for the '-xml' option");
227                 } else {
228                     xmlfile = new File JavaDoc(args[i + 1]);
229                     i++;
230                 }
231             } else if (args[i].equals("-awt")) {
232                 setOutputMode(AWT_OUTPUT);
233             } else if (args[i].equals("-pdf")) {
234                 setOutputMode(PDF_OUTPUT);
235                 if ((i + 1 == args.length)
236                         || (args[i + 1].charAt(0) == '-')) {
237                     throw new FOPException("you must specify the pdf output file");
238                 } else {
239                     outfile = new File JavaDoc(args[i + 1]);
240                     i++;
241                 }
242             } else if (args[i].equals("-o")) {
243                 if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) {
244                     if (encryptionAvailable()) {
245                         rendererOptions.put("ownerPassword", "");
246                     }
247                 } else {
248                     if (encryptionAvailable()) {
249                         rendererOptions.put("ownerPassword", args[i + 1]);
250                     }
251                     i++;
252                 }
253             } else if (args[i].equals("-u")) {
254                 if ((i + 1 == args.length) || (args[i + 1].charAt(0) == '-')) {
255                     if (encryptionAvailable()) {
256                         rendererOptions.put("userPassword", "");
257                     }
258                 } else {
259                     if (encryptionAvailable()) {
260                         rendererOptions.put("userPassword", args[i + 1]);
261                     }
262                     i++;
263                 }
264             } else if (args[i].equals("-noprint")) {
265                 if (encryptionAvailable()) {
266                     rendererOptions.put("allowPrint", "FALSE");
267                 }
268             } else if (args[i].equals("-nocopy")) {
269                 if (encryptionAvailable()) {
270                     rendererOptions.put("allowCopyContent", "FALSE");
271                 }
272             } else if (args[i].equals("-noedit")) {
273                 if (encryptionAvailable()) {
274                     rendererOptions.put("allowEditContent", "FALSE");
275                 }
276             } else if (args[i].equals("-noannotations")) {
277                 if (encryptionAvailable()) {
278                     rendererOptions.put("allowEditAnnotations", "FALSE");
279                 }
280             } else if (args[i].equals("-mif")) {
281                 setOutputMode(MIF_OUTPUT);
282                 if ((i + 1 == args.length)
283                         || (args[i + 1].charAt(0) == '-')) {
284                     throw new FOPException("you must specify the mif output file");
285                 } else {
286                     outfile = new File JavaDoc(args[i + 1]);
287                     i++;
288                 }
289             } else if (args[i].equals("-print")) {
290                 setOutputMode(PRINT_OUTPUT);
291                 // show print help
292
if (i + 1 < args.length) {
293                     if (args[i + 1].equals("help")) {
294                         printUsagePrintOutput();
295                         return false;
296                     }
297                 }
298             } else if (args[i].equals("-pcl")) {
299                 setOutputMode(PCL_OUTPUT);
300                 if ((i + 1 == args.length)
301                         || (args[i + 1].charAt(0) == '-')) {
302                     throw new FOPException("you must specify the pdf output file");
303                 } else {
304                     outfile = new File JavaDoc(args[i + 1]);
305                     i++;
306                 }
307             } else if (args[i].equals("-ps")) {
308                 setOutputMode(PS_OUTPUT);
309                 if ((i + 1 == args.length)
310                         || (args[i + 1].charAt(0) == '-')) {
311                     throw new FOPException("you must specify the PostScript output file");
312                 } else {
313                     outfile = new File JavaDoc(args[i + 1]);
314                     i++;
315                 }
316             } else if (args[i].equals("-txt")) {
317                 setOutputMode(TXT_OUTPUT);
318                 if ((i + 1 == args.length)
319                         || (args[i + 1].charAt(0) == '-')) {
320                     throw new FOPException("you must specify the text output file");
321                 } else {
322                     outfile = new File JavaDoc(args[i + 1]);
323                     i++;
324                 }
325             } else if (args[i].equals("-svg")) {
326                 setOutputMode(SVG_OUTPUT);
327                 if ((i + 1 == args.length)
328                         || (args[i + 1].charAt(0) == '-')) {
329                     throw new FOPException("you must specify the svg output file"); } else {
330                     outfile = new File JavaDoc(args[i + 1]);
331                     i++;
332                 }
333             } else if (args[i].charAt(0) != '-') {
334                 if (inputmode == NOT_SET) {
335                     inputmode = FO_INPUT;
336                     fofile = new File JavaDoc(args[i]);
337                 } else if (outputmode == NOT_SET) {
338                     outputmode = PDF_OUTPUT;
339                     outfile = new File JavaDoc(args[i]);
340                 } else {
341                     throw new FOPException("Don't know what to do with "
342                                            + args[i]);
343                 }
344             } else if (args[i].equals("-at")) {
345                 setOutputMode(AREA_OUTPUT);
346                 if ((i + 1 == args.length)
347                         || (args[i + 1].charAt(0) == '-')) {
348                     throw new FOPException("you must specify the area-tree output file");
349                 } else {
350                     outfile = new File JavaDoc(args[i + 1]);
351                     i++;
352                 }
353             } else if (args[i].equals("-" + TXTRenderer.encodingOptionName)) {
354                 if ((i + 1 == args.length)
355                     || (args[i + 1].charAt(0) == '-')) {
356                     throw new FOPException("you must specify text renderer encoding");
357                 } else {
358                     rendererOptions.put(TXTRenderer.encodingOptionName, args[i + 1]);
359                     i++;
360                 }
361             } else {
362                 printUsage();
363                 return false;
364             }
365         }
366         return true;
367     } // end parseOptions
368

369     private void setOutputMode(int mode) throws FOPException {
370         if (outputmode == NOT_SET) {
371             outputmode = mode;
372         } else {
373             throw new FOPException("you can only set one output method");
374         }
375     }
376
377     /**
378      * checks whether all necessary information has been given in a consistent way
379      */

380     private void checkSettings() throws FOPException, FileNotFoundException JavaDoc {
381         if (inputmode == NOT_SET) {
382             throw new FOPException("No input file specified");
383         }
384
385         if (outputmode == NOT_SET) {
386             throw new FOPException("No output file specified");
387         }
388
389         if (inputmode == XSLT_INPUT) {
390             // check whether xml *and* xslt file have been set
391
if (xmlfile == null) {
392                 throw new FOPException("XML file must be specified for the tranform mode");
393             }
394             if (xsltfile == null) {
395                 throw new FOPException("XSLT file must be specified for the tranform mode");
396             }
397
398             // warning if fofile has been set in xslt mode
399
if (fofile != null) {
400                 log.warn("Can't use fo file with transform mode! Ignoring.\n"
401                                        + "Your input is " + "\n xmlfile: "
402                                        + xmlfile.getAbsolutePath()
403                                        + "\nxsltfile: "
404                                        + xsltfile.getAbsolutePath()
405                                        + "\n fofile: "
406                                        + fofile.getAbsolutePath());
407             }
408             if (!xmlfile.exists()) {
409                 throw new FileNotFoundException JavaDoc("xml file "
410                                                 + xmlfile.getAbsolutePath()
411                                                 + " not found ");
412             }
413             if (!xsltfile.exists()) {
414                 throw new FileNotFoundException JavaDoc("xsl file "
415                                                 + xsltfile.getAbsolutePath()
416                                                 + " not found ");
417             }
418
419         } else if (inputmode == FO_INPUT) {
420             if (xmlfile != null || xsltfile != null) {
421                 log.warn("fo input mode, but xmlfile or xslt file are set:");
422                 log.error("xml file: " + xmlfile.toString());
423                 log.error("xslt file: " + xsltfile.toString());
424             }
425             if (!fofile.exists()) {
426                 throw new FileNotFoundException JavaDoc("fo file "
427                                                 + fofile.getAbsolutePath()
428                                                 + " not found ");
429             }
430
431         }
432     } // end checkSettings
433

434     private void setLogger(Logger newLogger) {
435         this.log = newLogger;
436         MessageHandler.setScreenLogger(newLogger);
437     }
438
439     /**
440      * returns the chosen renderer, throws FOPException
441      */

442     public int getRenderer() throws FOPException {
443         switch (outputmode) {
444         case NOT_SET:
445             throw new FOPException("Renderer has not been set!");
446         case PDF_OUTPUT:
447             return Driver.RENDER_PDF;
448         case AWT_OUTPUT:
449             return Driver.RENDER_AWT;
450         case MIF_OUTPUT:
451             return Driver.RENDER_MIF;
452         case PRINT_OUTPUT:
453             return Driver.RENDER_PRINT;
454         case PCL_OUTPUT:
455             return Driver.RENDER_PCL;
456         case PS_OUTPUT:
457             return Driver.RENDER_PS;
458         case TXT_OUTPUT:
459             return Driver.RENDER_TXT;
460         case SVG_OUTPUT:
461             return Driver.RENDER_SVG;
462         case AREA_OUTPUT:
463             rendererOptions.put("fineDetail", isCoarseAreaXml());
464             return Driver.RENDER_XML;
465         default:
466             throw new FOPException("Invalid Renderer setting!");
467         }
468     }
469
470     /**
471      *
472      */

473     public InputHandler getInputHandler()
474       throws FOPException {
475         switch (inputmode) {
476         case FO_INPUT:
477             return new FOInputHandler(fofile);
478         case XSLT_INPUT:
479             return new XSLTInputHandler(xmlfile, xsltfile);
480         default:
481             return new FOInputHandler(fofile);
482         }
483     }
484
485     public java.util.HashMap JavaDoc getRendererOptions() {
486         return rendererOptions;
487     }
488
489     public Starter getStarter() throws FOPException {
490         Starter starter = null;
491         switch (outputmode) {
492         case AWT_OUTPUT:
493             try {
494                 starter = ((Starter)Class.forName("org.apache.fop.apps.AWTStarter").getConstructor(new Class JavaDoc[] {
495                     CommandLineOptions.class
496                 }).newInstance(new Object JavaDoc[] {
497                     this
498                 }));
499             } catch (Exception JavaDoc e) {
500                 if (e instanceof FOPException) {
501                     throw (FOPException)e;
502                 }
503                 throw new FOPException("AWTStarter could not be loaded.", e);
504             }
505         break;
506         case PRINT_OUTPUT:
507             try {
508                 starter = ((Starter)Class.forName("org.apache.fop.apps.PrintStarter").getConstructor(new Class JavaDoc[] {
509                     CommandLineOptions.class
510                 }).newInstance(new Object JavaDoc[] {
511                     this
512                 }));
513             } catch (Exception JavaDoc e) {
514                 if (e instanceof FOPException) {
515                     throw (FOPException)e;
516                 }
517                 throw new FOPException("PrintStarter could not be loaded.",
518                                        e);
519             }
520         break;
521         default:
522             starter = new CommandLineStarter(this);
523         }
524         starter.setLogger(log);
525         return starter;
526     }
527
528     public int getInputMode() {
529         return inputmode;
530     }
531
532     public int getOutputMode() {
533         return outputmode;
534     }
535
536     public File JavaDoc getFOFile() {
537         return fofile;
538     }
539
540     public File JavaDoc getXMLFile() {
541         return xmlfile;
542     }
543
544     public File JavaDoc getXSLFile() {
545         return xsltfile;
546     }
547
548     public File JavaDoc getOutputFile() {
549         return outfile;
550     }
551
552     public File JavaDoc getUserConfigFile() {
553         return userConfigFile;
554     }
555
556     public String JavaDoc getLanguage() {
557         return language;
558     }
559
560     public Boolean JavaDoc isQuiet() {
561         return quiet;
562     }
563
564     public Boolean JavaDoc dumpConfiguration() {
565         return dumpConfiguration;
566     }
567
568     public Boolean JavaDoc isDebugMode() {
569         return errorDump;
570     }
571
572     public Boolean JavaDoc isCoarseAreaXml() {
573         return suppressLowLevelAreas;
574     }
575
576     /**
577      * return either the fofile or the xmlfile
578      */

579     public File JavaDoc getInputFile() {
580         switch (inputmode) {
581         case FO_INPUT:
582             return fofile;
583         case XSLT_INPUT:
584             return xmlfile;
585         default:
586             return fofile;
587         }
588     }
589
590     /**
591      * shows the commandline syntax including a summary of all available options and some examples
592      */

593     public static void printUsage() {
594         System.err.println("\nUSAGE\nFop [options] [-fo|-xml] infile [-xsl file] [-awt|-pdf|-mif|-pcl|-ps|-txt|-at|-print] <outfile>\n"
595                                + " [OPTIONS]\n"
596                                + " -d debug mode\n"
597                                + " -x dump configuration settings\n"
598                                + " -q quiet mode\n"
599                                + " -c cfg.xml use additional configuration file cfg.xml\n"
600                                + " -l lang the language to use for user information\n"
601                                + " -s (-at output) omit tree below block areas\n"
602                                + " -"+TXTRenderer.encodingOptionName+" (-txt output encoding use the encoding for the output file.\n"
603                                + " The encoding must be a valid java encoding.\n"
604                                + " -o [password] pdf file will be encrypted with option owner password\n"
605                                + " -u [password] pdf file will be encrypted with option user password\n"
606                                + " -noprint pdf file will be encrypted without printing permission\n"
607                                + " -nocopy pdf file will be encrypted without copy content permission\n"
608                                + " -noedit pdf file will be encrypted without edit content permission\n"
609                                + " -noannotations pdf file will be encrypted without edit annotation permission\n"
610                                + "\n [INPUT]\n"
611                                + " infile xsl:fo input file (the same as the next)\n"
612                                + " -fo infile xsl:fo input file\n"
613                                + " -xml infile xml input file, must be used together with -xsl\n"
614                                + " -xsl stylesheet xslt stylesheet\n"
615                                + "\n [OUTPUT]\n"
616                                + " outfile input will be rendered as pdf file into outfile\n"
617                                + " -pdf outfile input will be rendered as pdf file (outfile req'd)\n"
618                                + " -awt input will be displayed on screen\n"
619                                + " -mif outfile input will be rendered as mif file (outfile req'd)\n"
620                                + " -pcl outfile input will be rendered as pcl file (outfile req'd)\n"
621                                + " -ps outfile input will be rendered as PostScript file (outfile req'd)\n"
622                                + " -txt outfile input will be rendered as text file (outfile req'd)\n"
623                                + " -svg outfile input will be rendered as an svg slides file (outfile req'd)\n"
624                                + " -at outfile representation of area tree as XML (outfile req'd)\n"
625                                + " -print input file will be rendered and sent to the printer\n"
626                                + " see print specific options with \"-print help\"\n"
627                                + "\n [Examples]\n"
628                                + " Fop foo.fo foo.pdf\n"
629                                + " Fop -fo foo.fo -pdf foo.pdf (does the same as the previous line)\n"
630                                + " Fop -xsl foo.xsl -xml foo.xml -pdf foo.pdf\n"
631                                + " Fop foo.fo -mif foo.mif\n"
632                                + " Fop foo.fo -print or Fop -print foo.fo\n"
633                                + " Fop foo.fo -awt\n");
634     }
635
636     /**
637      * shows the options for print output
638      */

639     public void printUsagePrintOutput() {
640         System.err.println("USAGE: -print [-Dstart=i] [-Dend=i] [-Dcopies=i] [-Deven=true|false] "
641                                + " org.apache.fop.apps.Fop (..) -print\n"
642                                + "Example:\n"
643                                + "java -Dstart=1 -Dend=2 org.apache.Fop.apps.Fop infile.fo -print ");
644     }
645
646
647     /**
648      * debug mode. outputs all commandline settings
649      */

650     private void debug() {
651         log.debug("Input mode: ");
652         switch (inputmode) {
653         case NOT_SET:
654             log.debug("not set");
655             break;
656         case FO_INPUT:
657             log.debug("FO ");
658             log.debug("fo input file: " + fofile.toString());
659             break;
660         case XSLT_INPUT:
661             log.debug("xslt transformation");
662             log.debug("xml input file: " + xmlfile.toString());
663             log.debug("xslt stylesheet: " + xsltfile.toString());
664             break;
665         default:
666             log.debug("unknown input type");
667         }
668         log.debug("Output mode: ");
669         switch (outputmode) {
670         case NOT_SET:
671             log.debug("not set");
672             break;
673         case PDF_OUTPUT:
674             log.debug("pdf");
675             log.debug("output file: " + outfile.toString());
676             break;
677         case AWT_OUTPUT:
678             log.debug("awt on screen");
679             if (outfile != null) {
680                 log.error("awt mode, but outfile is set:");
681                 log.debug("out file: " + outfile.toString());
682             }
683             break;
684         case MIF_OUTPUT:
685             log.debug("mif");
686             log.debug("output file: " + outfile.toString());
687             break;
688         case PRINT_OUTPUT:
689             log.debug("print directly");
690             if (outfile != null) {
691                 log.error("print mode, but outfile is set:");
692                 log.error("out file: " + outfile.toString());
693             }
694             break;
695         case PCL_OUTPUT:
696             log.debug("pcl");
697             log.debug("output file: " + outfile.toString());
698             break;
699         case PS_OUTPUT:
700             log.debug("PostScript");
701             log.debug("output file: " + outfile.toString());
702             break;
703         case TXT_OUTPUT:
704             log.debug("txt");
705             log.debug("output file: " + outfile.toString());
706             if (rendererOptions.containsKey(TXTRenderer.encodingOptionName))
707                 log.debug("output encoding: " + rendererOptions.get(TXTRenderer.encodingOptionName));
708             break;
709         case SVG_OUTPUT:
710             log.debug("svg");
711             log.debug("output file: " + outfile.toString());
712             break;
713         default:
714             log.debug("unknown input type");
715         }
716
717
718         log.debug("OPTIONS");
719         if (userConfigFile != null) {
720             log.debug("user configuration file: "
721                                  + userConfigFile.toString());
722         } else {
723             log.debug("no user configuration file is used [default]");
724         }
725         if (errorDump != null) {
726             log.debug("debug mode on");
727         } else {
728             log.debug("debug mode off [default]");
729         }
730         if (dumpConfiguration != null) {
731             log.debug("dump configuration");
732         } else {
733             log.debug("don't dump configuration [default]");
734         }
735         if (quiet != null) {
736             log.debug("quiet mode on");
737         } else {
738             log.debug("quiet mode off [default]");
739         }
740
741     }
742
743     // debug: create class and output all settings
744
public static void main(String JavaDoc args[]) {
745         /*
746          * for (int i = 0; i < args.length; i++) {
747          * log.debug(">"+args[i]+"<");
748          * }
749          */

750         try {
751             CommandLineOptions options = new CommandLineOptions(args);
752         } catch (Exception JavaDoc e) {
753             e.printStackTrace();
754         }
755
756         // options.debug();
757
}
758
759 }
760
761
Popular Tags