[FOray-commit] SF.net SVN: foray:[10905] trunk/foray
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2010-02-01 15:40:03
|
Revision: 10905
http://foray.svn.sourceforge.net/foray/?rev=10905&view=rev
Author: victormote
Date: 2010-02-01 15:39:30 +0000 (Mon, 01 Feb 2010)
Log Message:
-----------
Introduce the Commons CLI parsing to the main FOray class. Used only for validation right now.
Modified Paths:
--------------
trunk/foray/doc/web/00-release/notes-unreleased.html
trunk/foray/foray-app/.classpath
trunk/foray/foray-app/scripts/build.xml
trunk/foray/foray-app/src/java/org/foray/app/FOray.java
trunk/foray/foray-app/src/javatest/org/foray/app/TestFOrayApp.java
Added Paths:
-----------
trunk/foray/foray-app/src/javatest/org/foray/app/TestFOray.java
Modified: trunk/foray/doc/web/00-release/notes-unreleased.html
===================================================================
--- trunk/foray/doc/web/00-release/notes-unreleased.html 2010-01-31 19:56:21 UTC (rev 10904)
+++ trunk/foray/doc/web/00-release/notes-unreleased.html 2010-02-01 15:39:30 UTC (rev 10905)
@@ -38,6 +38,11 @@
<li>Miscellaneous improvements to the Panose class, thanks to Jason Harrop.
These include greatly improved Panose matching, and methods to return bold and italic Panose
instances.</li>
+ <li>Some minor changes have been made to the command-line options.
+Previously, assumptions were made that the input file was and FO file and that the output was PDF.
+These options must now be explicitly set on the command-line.
+For example, previously "FOray foo.fo foo.pdf" would have parsed an FO file and produced a PDF.
+To get the same results now, use "FOray -fo foo.fo -pdf foo.pdf".</li>
</ul>
<h3>Unreleased changes of interest to Developers</h3>
Modified: trunk/foray/foray-app/.classpath
===================================================================
--- trunk/foray/foray-app/.classpath 2010-01-31 19:56:21 UTC (rev 10904)
+++ trunk/foray/foray-app/.classpath 2010-02-01 15:39:30 UTC (rev 10905)
@@ -41,5 +41,6 @@
<classpathentry combineaccessrules="false" kind="src" path="/FOrayMIF"/>
<classpathentry combineaccessrules="false" kind="src" path="/axslPs"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="lib" path="/FOray Lib/commons-cli-1.2.jar" sourcepath="/FOray Lib-Build/commons-cli/commons-cli-1.2-sources.jar"/>
<classpathentry kind="output" path="build/eclipse"/>
</classpath>
Modified: trunk/foray/foray-app/scripts/build.xml
===================================================================
--- trunk/foray/foray-app/scripts/build.xml 2010-01-31 19:56:21 UTC (rev 10904)
+++ trunk/foray/foray-app/scripts/build.xml 2010-02-01 15:39:30 UTC (rev 10905)
@@ -29,6 +29,7 @@
<include name="axsl*.jar"/>
<include name="commons-io-*.jar"/>
<include name="commons-logging-*.jar"/>
+ <include name="commons-cli-*.jar"/>
<include name="servlet*.jar"/>
<include name="xercesImpl*.jar"/>
<include name="xml-apis*.jar"/>
Modified: trunk/foray/foray-app/src/java/org/foray/app/FOray.java
===================================================================
--- trunk/foray/foray-app/src/java/org/foray/app/FOray.java 2010-01-31 19:56:21 UTC (rev 10904)
+++ trunk/foray/foray-app/src/java/org/foray/app/FOray.java 2010-02-01 15:39:30 UTC (rev 10905)
@@ -32,6 +32,14 @@
import org.foray.core.FOrayException;
import org.foray.core.SessionConfig;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionGroup;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.PosixParser;
import org.apache.commons.logging.Log;
import java.io.FileNotFoundException;
@@ -41,6 +49,21 @@
*/
public final class FOray {
+ /** Command-line status constant indicating that the command line itself was not properly formed. */
+ public static final byte STATUS_COMMAND_LINE_ERROR = 1;
+
+ /** Command-line example for testing and documentation. */
+ public static final String COMMAND_LINE_EXAMPLE_001 = "-fo foo.fo -pdf foo.pdf";
+
+ /** Examples of command-line arguments. These are used for testing, and for generating help documentation. */
+ public static final String[] COMMAND_LINE_EXAMPLES = new String[] {
+ "foray -fo foo.fo -pdf foo.pdf",
+ "foray -xsl foo.xsl -xml foo.xml -pdf foo.pdf",
+ "foray foo.fo -mif foo.mif",
+ "foray foo.fo -print or foray -print foo.fo",
+ "foray foo.fo -awt"
+ };
+
/**
* Private Constructor. This is a utility class and should never be
* instantiated.
@@ -48,12 +71,77 @@
private FOray() { }
/**
+ * Returns the command-line options for the {@link #main(String[])} method.
+ * @return Command-line options.
+ */
+ static Options getCommandLineOptions() {
+ final Options clOptions = new Options();
+
+ /* Configuration file and configuration options. */
+ final Option configurationFile = new Option("c", "configuration-file", true, "path to the configuration file");
+ configurationFile.setRequired(false);
+ configurationFile.setArgName("file");
+ clOptions.addOption(configurationFile);
+
+ /* Input. */
+ final OptionGroup inputGroup = new OptionGroup();
+ inputGroup.setRequired(true);
+
+ final Option foInputOption = new Option("fo", "fo-input", true, "XSL-FO input file");
+ foInputOption.setArgName("file");
+ inputGroup.addOption(foInputOption);
+
+ final Option xmlInputOption = new Option("xml", "xml-input", true, "XML input file (-xsl option required)");
+ xmlInputOption.setArgName("file");
+ inputGroup.addOption(xmlInputOption);
+
+ clOptions.addOptionGroup(inputGroup);
+
+ /* Output. */
+ final OptionGroup outputGroup = new OptionGroup();
+ outputGroup.setRequired(true);
+
+ final Option pdfOutputOption = new Option("pdf", "pdf-output", true, "Document will be rendered as PDF");
+ pdfOutputOption.setArgName("file");
+ outputGroup.addOption(pdfOutputOption);
+
+ clOptions.addOptionGroup(outputGroup);
+
+ return clOptions;
+ }
+
+ /**
+ * Parses a command-line.
+ * @param commandLineOptions The command-line options controlling the parsing.
+ * @param args The command-line arguments to be parsed.
+ * @return The results of the parsing.
+ * @throws ParseException For errors in <code>args</code>.
+ */
+ public static CommandLine parseCommandLine(final Options commandLineOptions, final String[] args)
+ throws ParseException {
+ final CommandLineParser commandLineParser = new PosixParser();
+ final CommandLine parsedCommandLine = commandLineParser.parse(commandLineOptions, args);
+ return parsedCommandLine;
+ }
+
+ /**
* Main command-line entry point to FOray.
* @param args The command-line arguments. See the application documentation
* for details on these arguments.
*/
public static void main(final String[] args) {
/* Checkstyle-GenericIllegalRegexp-Off. */
+ final Options commandLineOptions = FOray.getCommandLineOptions();
+ try {
+ /* TODO: Keep the return value and use it downstream. Right now all we are doing is testing the options. */
+ FOray.parseCommandLine(commandLineOptions, args);
+ } catch (final ParseException e) {
+ System.out.println(e.getMessage());
+ final HelpFormatter helpFormatter = new HelpFormatter();
+ helpFormatter.printHelp("java -cp $FORAY_CLASSPATH " + FOray.class.getName(), commandLineOptions,
+ true);
+ System.exit(FOray.STATUS_COMMAND_LINE_ERROR);
+ }
CommandLineOptions options = null;
final Log logger = Logging.makeDefaultLogger();
Added: trunk/foray/foray-app/src/javatest/org/foray/app/TestFOray.java
===================================================================
--- trunk/foray/foray-app/src/javatest/org/foray/app/TestFOray.java (rev 0)
+++ trunk/foray/foray-app/src/javatest/org/foray/app/TestFOray.java 2010-02-01 15:39:30 UTC (rev 10905)
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2010 The FOray Project.
+ * http://www.foray.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * This work is in part derived from the following work(s), used with the
+ * permission of the licensor:
+ * Apache FOP, licensed by the Apache Software Foundation
+ *
+ */
+
+/*
+ * $LastChangedRevision: 9908 $
+ * $LastChangedDate: 2007-07-02 12:22:30 -0600 (Mon, 02 Jul 2007) $
+ * $LastChangedBy$
+ */
+
+package org.foray.app;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.ParseException;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests of {@link FOray}.
+ */
+public class TestFOray extends TestCase {
+
+ /**
+ * Splits the raw command-line into an array of Strings expected by "main" methods.
+ * @param input The raw command-line to be split into arguments.
+ * @return The array of Strings parsed by using space as a delimiter.
+ */
+ private String[] splitCommandLineArgs(final String input) {
+ return input.split(" ");
+ }
+
+ /**
+ * Parses a raw command-line into its component pieces.
+ * @param input The raw command-line to be tested.
+ * @return The parsed command-line.
+ * @throws ParseException For errors on the input line.
+ */
+ private CommandLine parseCommandLine(final String input) throws ParseException {
+ final org.apache.commons.cli.Options commandLineOptions = FOray.getCommandLineOptions();
+ final String[] commandLineArgs = splitCommandLineArgs(input);
+ final CommandLine commandLine = FOray.parseCommandLine(commandLineOptions, commandLineArgs);
+ return commandLine;
+ }
+
+ /**
+ * Test of {@link FOray#parseCommandLine(org.apache.commons.cli.Options, String[])}.
+ * @throws ParseException For errors on the input line.
+ */
+ public void testParseCommandLine001() throws ParseException {
+ final CommandLine commandLine = parseCommandLine(FOray.COMMAND_LINE_EXAMPLE_001);
+ assertEquals("foo.fo", commandLine.getOptionValue("fo"));
+ assertEquals("foo.pdf", commandLine.getOptionValue("pdf"));
+ }
+
+}
Modified: trunk/foray/foray-app/src/javatest/org/foray/app/TestFOrayApp.java
===================================================================
--- trunk/foray/foray-app/src/javatest/org/foray/app/TestFOrayApp.java 2010-01-31 19:56:21 UTC (rev 10904)
+++ trunk/foray/foray-app/src/javatest/org/foray/app/TestFOrayApp.java 2010-02-01 15:39:30 UTC (rev 10905)
@@ -54,12 +54,12 @@
public static Test suite() {
final TestSuite testSuite = new TestSuite("The FOray Application");
- /* First the FO Tree tests. */
+ /* FO Tree tests. */
testSuite.addTestSuite(TestInvalidXml.class);
testSuite.addTestSuite(TestFont.class);
testSuite.addTestSuite(TestGraphic.class);
- /* Now the Area Tree tests. */
+ /* Area Tree tests. */
testSuite.addTestSuite(TestBorder.class);
testSuite.addTestSuite(TestBlock.class);
testSuite.addTestSuite(TestInline.class);
@@ -67,6 +67,9 @@
testSuite.addTestSuite(TestGraphicArea.class);
testSuite.addTestSuite(TestVertical.class);
+ /* Tests of classes in this project. */
+ testSuite.addTestSuite(TestFOray.class);
+
return testSuite;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|