diff options
Diffstat (limited to 'src/java/org/apache/fop/cli/CommandLineOptions.java')
-rw-r--r-- | src/java/org/apache/fop/cli/CommandLineOptions.java | 61 |
1 files changed, 51 insertions, 10 deletions
diff --git a/src/java/org/apache/fop/cli/CommandLineOptions.java b/src/java/org/apache/fop/cli/CommandLineOptions.java index 3bb0aae7f..4e5c8ae44 100644 --- a/src/java/org/apache/fop/cli/CommandLineOptions.java +++ b/src/java/org/apache/fop/cli/CommandLineOptions.java @@ -46,6 +46,8 @@ import org.apache.fop.pdf.PDFXMode; import org.apache.fop.render.Renderer; import org.apache.fop.render.awt.AWTRenderer; import org.apache.fop.render.pdf.PDFRenderer; +import org.apache.fop.render.print.PagesMode; +import org.apache.fop.render.print.PrintRenderer; import org.apache.fop.render.xml.XMLRenderer; import org.apache.fop.util.CommandLineLogger; @@ -133,8 +135,9 @@ public class CommandLineOptions { * @throws FOPException for general errors * @throws FileNotFoundException if an input file wasn't found * @throws IOException if the the configuration file could not be loaded + * @return true if the processing can continue, false to abort */ - public void parse(String[] args) + public boolean parse(String[] args) throws FOPException, IOException { boolean optionsParsed = true; @@ -155,6 +158,8 @@ public class CommandLineOptions { } addXSLTParameter("fop-output-format", getOutputFormat()); addXSLTParameter("fop-version", Version.getVersion()); + } else { + return false; } } catch (FOPException e) { printUsage(); @@ -193,6 +198,7 @@ public class CommandLineOptions { //Make sure the prepared XMLRenderer is used foUserAgent.setRendererOverride(xmlRenderer); } + return true; } /** @@ -268,7 +274,6 @@ public class CommandLineOptions { } else if (args[i].equals("-png")) { i = i + parsePNGOutputOption(args, i); } else if (args[i].equals("-print")) { - i = i + parsePrintOutputOption(args, i); // show print help if (i + 1 < args.length) { if (args[i + 1].equals("help")) { @@ -276,6 +281,9 @@ public class CommandLineOptions { return false; } } + i = i + parsePrintOutputOption(args, i); + } else if (args[i].equals("-copies")) { + i = i + parseCopiesOption(args, i); } else if (args[i].equals("-pcl")) { i = i + parsePCLOutputOption(args, i); } else if (args[i].equals("-ps")) { @@ -302,7 +310,7 @@ public class CommandLineOptions { String expression = args[++i]; addXSLTParameter(name, expression); } else { - throw new FOPException("invalid param usage: use -param <name> <value>"); + throw new FOPException("invalid param usage: use -param <name> <value>"); } } else if (args[i].equals("-o")) { i = i + parsePDFOwnerPassword(args, i); @@ -461,7 +469,37 @@ public class CommandLineOptions { private int parsePrintOutputOption(String[] args, int i) throws FOPException { setOutputMode(MimeConstants.MIME_FOP_PRINT); - return 0; + if ((i + 1 <= args.length) + && (args[i + 1].charAt(0) != '-')) { + String arg = args[i + 1]; + String[] parts = arg.split(","); + for (int j = 0; j < parts.length; j++) { + String s = parts[j]; + if (s.matches("\\d+")) { + renderingOptions.put(PrintRenderer.START_PAGE, new Integer(s)); + } else if (s.matches("\\d+-\\d+")) { + String[] startend = s.split("-"); + renderingOptions.put(PrintRenderer.START_PAGE, new Integer(startend[0])); + renderingOptions.put(PrintRenderer.END_PAGE, new Integer(startend[1])); + } else { + PagesMode mode = PagesMode.byName(s); + renderingOptions.put(PrintRenderer.PAGES_MODE, mode); + } + } + return 1; + } else { + return 0; + } + } + + private int parseCopiesOption(String[] args, int i) throws FOPException { + if ((i + 1 == args.length) + || (args[i + 1].charAt(0) == '-')) { + throw new FOPException("you must specify the number of copies"); + } else { + renderingOptions.put(PrintRenderer.COPIES, new Integer(args[i + 1])); + return 1; + } } private int parsePCLOutputOption(String[] args, int i) throws FOPException { @@ -991,18 +1029,21 @@ public class CommandLineOptions { + " Fop -xml foo.xml -xsl foo.xsl -foout foo.fo\n" + " Fop foo.fo -mif foo.mif\n" + " Fop foo.fo -rtf foo.rtf\n" - + " Fop foo.fo -print or Fop -print foo.fo \n" - + " Fop foo.fo -awt \n"); + + " Fop foo.fo -print\n" + + " Fop foo.fo -awt\n"); } /** * shows the options for print output */ private void printUsagePrintOutput() { - System.err.println("USAGE: -print [-Dstart=i] [-Dend=i] [-Dcopies=i] [-Deven=true|false] " - + " org.apache.fop.apps.Fop (..) -print \n" - + "Example:\n" - + "java -Dstart=1 -Dend=2 org.apache.Fop.apps.Fop infile.fo -print "); + System.err.println("USAGE: -print [from[-to][,even|odd]] [-copies numCopies]\n\n" + + "Example:\n" + + "all pages: Fop infile.fo -print\n" + + "all pages with two copies: Fop infile.fo -print -copies 2\n" + + "all pages starting with page 7: Fop infile.fo -print 7\n" + + "pages 2 to 3: Fop infile.fo -print 2-3\n" + + "only even page between 10 and 20: Fop infile.fo -print 10-20,even\n"); } /** |