pbwest 2004/03/13 18:44:54 Modified: src/java/org/apache/fop/configuration Tag: FOP_0-20-0_Alt-Design SystemOptions.java CLI_Options.java UserOptions.java ConfigurationParser.java Removed: src/java/org/apache/fop/configuration Tag: FOP_0-20-0_Alt-Design FOPOptions.java Log: Fixes to options hierarchy Revision Changes Path No revision No revision 1.1.2.2 +84 -98 xml-fop/src/java/org/apache/fop/configuration/Attic/SystemOptions.java Index: SystemOptions.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/configuration/Attic/SystemOptions.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- SystemOptions.java 13 Mar 2004 08:41:29 -0000 1.1.2.1 +++ SystemOptions.java 14 Mar 2004 02:44:53 -0000 1.1.2.2 @@ -76,27 +76,12 @@ protected Configuration configuration = null; - /* show configuration information */ - protected boolean dumpConfig = false; - /* name of user configuration file */ - protected File userConfigFile = null; - /* name of input fo file */ - protected File foFile = null; - /* name of xsltFile (xslt transformation as input) */ - protected File xsltFile = null; - /* name of xml file (xslt transformation as input) */ - protected File xmlFile = null; - /* name of output file */ - protected File outputFile = null; - /* name of buffer file */ - protected File bufferFile = null; +// /* show configuration information */ +// protected boolean dumpConfig = false; /* input mode */ protected int inputmode = NOT_SET; /* output mode */ protected int outputmode = NOT_SET; - /* buffer mode */ - protected int buffermode = NOT_SET; - /* language for user information */ // baseDir (set from the config files protected String baseDir = null; @@ -130,13 +115,6 @@ public SystemOptions(Configuration configuration) { setup(); this.configuration = configuration; - try { - configure(); - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } catch (FOPException e) { - throw new RuntimeException(e); - } } private void setup() { @@ -214,7 +192,7 @@ * @return the index of that name in the array of input mode names, * or -1 if not found */ - public int inputModeNameToIndex(String name) { + protected int inputModeNameToIndex(String name) { for (int i = 0; i <= LAST_INPUT_MODE; i++) { if (name.equals(inputModes[i])) return i; } @@ -227,7 +205,7 @@ * @return the index of that name in the array of output mode names, * or -1 if not found */ - public int outputModeNameToIndex(String name) { + protected int outputModeNameToIndex(String name) { for (int i = 0; i <= LAST_INPUT_MODE; i++) { if (name.equals(outputModes[i])) return i; } @@ -250,26 +228,9 @@ * * @exception FOPException */ - void initOptions() throws FOPException { + protected void initOptions() throws FOPException { String str = null; - // show configuration settings - dumpConfig = configuration.isTrue("dumpConfiguration"); - - if ((str = getFoFileName()) != null) - foFile = new File(str); - if ((str = getXmlFileName()) != null) - xmlFile = new File(str); - if ((str = getXsltFileName()) != null) - xsltFile = new File(str); - if ((str = getOutputFileName()) != null) - outputFile = new File(str); - if ((str = getBufferFileName()) != null) - bufferFile = new File(str); - // userConfigFile may be set in the process of loading said file - if (userConfigFile == null && (str = getUserConfigFileName()) != null) - userConfigFile = new File(str); - if ((str = getInputMode()) != null) inputmode = inputModeIndex(str); if ((str = getOutputMode()) != null) @@ -291,7 +252,7 @@ log.config("base directory: " + baseDir); } - if (dumpConfig) { + if (dumpConfig()) { configuration.dumpConfiguration(); System.exit(0); } @@ -313,7 +274,7 @@ * @exception FOPException if the configuration file * cannot be discovered. */ - public void loadConfiguration(String fname) + protected void loadConfiguration(String fname) throws FOPException { InputStream configfile = ConfigurationResource.getResourceFile( "conf/" + fname, ConfigurationReader.class); @@ -331,7 +292,7 @@ * Get the log. * @return the log */ - public Logger getLogger() { + protected Logger getLogger() { return log; } @@ -388,7 +349,7 @@ /** * checks whether all necessary information has been given in a consistent way */ - private void checkSettings() throws FOPException, FileNotFoundException { + protected void checkSettings() throws FOPException, FileNotFoundException { if (inputmode == NOT_SET) { throw new FOPException("No input file specified"); } @@ -398,31 +359,31 @@ } if (inputmode == XSLT_INPUT) { - if (xmlFile == null) { + if (getXmlFile() == null) { throw new FOPException("No xml input file specified"); } - if (!xmlFile.exists()) { + if (!getXmlFile().exists()) { throw new FileNotFoundException("Error: xml file " - + xmlFile.getAbsolutePath() + + getXmlFile().getAbsolutePath() + " not found "); } - if (xsltFile == null ) { + if (getXsltFile() == null ) { throw new FOPException( "No xslt transformation file specified"); } - if (!xsltFile.exists()) { + if (!getXsltFile().exists()) { throw new FileNotFoundException("Error: xsl file " - + xsltFile.getAbsolutePath() + + getXsltFile().getAbsolutePath() + " not found "); } } else if (inputmode == FO_INPUT) { - if (foFile == null) { + if (getFoFile() == null) { throw new FOPException("No fo input file specified"); } - if (!foFile.exists()) { + if (!getFoFile().exists()) { throw new FileNotFoundException("Error: fo file " - + foFile.getAbsolutePath() + + getFoFile().getAbsolutePath() + " not found "); } } @@ -470,9 +431,10 @@ public InputHandler getInputHandler() throws FOPException { switch (inputmode) { case FO_INPUT: - return new FOFileHandler(foFile); + return new FOFileHandler(getFoFile()); case XSLT_INPUT: - return new XSLTInputHandler(xmlFile, xsltFile, xsltParams); + return new XSLTInputHandler( + getXmlFile(), getXsltFile(), xsltParams); default: throw new FOPException("Invalid inputmode setting!"); } @@ -495,7 +457,7 @@ * Returns the input mode (type of input data, ex. NOT_SET or FO_INPUT) * @return the input mode */ - public int getInputModeIndex() throws FOPException { + protected int getInputModeIndex() throws FOPException { String mode; if ((mode = getInputMode()) == null) return NOT_SET; return inputModeIndex(mode); @@ -509,7 +471,7 @@ * Returns the output mode (output format, ex. NOT_SET or PDF_OUTPUT) * @return the output mode */ - public int getOutputModeIndex() throws FOPException { + protected int getOutputModeIndex() throws FOPException { String mode; if ((mode = getOutputMode()) == null) return NOT_SET; return outputModeIndex(mode); @@ -521,7 +483,11 @@ } public File getFoFile() { - return foFile; + String fname; + if ((fname = getFoFileName()) == null) { + return null; + } + return new File(fname); } public String getXmlFileName() { @@ -529,7 +495,11 @@ } public File getXmlFile() { - return xmlFile; + String fname; + if ((fname = getXmlFileName()) == null) { + return null; + } + return new File(fname); } public String getXsltFileName() { @@ -537,7 +507,11 @@ } public File getXsltFile() { - return xsltFile; + String fname; + if ((fname = getXsltFileName()) == null) { + return null; + } + return new File(fname); } public String getOutputFileName() { @@ -545,7 +519,11 @@ } public File getOutputFile() { - return outputFile; + String fname; + if ((fname = getOutputFileName()) == null) { + return null; + } + return new File(fname); } public String getSystemConfigFileName() { @@ -557,20 +535,24 @@ return defaultConfigFile; } + public File getSystemConfigFile() { + String fname; + if ((fname = getSystemConfigFileName()) == null) { + return null; + } + return new File(fname); + } + public String getUserConfigFileName() { return configuration.getStringValue("userConfigFileName"); } public File getUserConfigFile() { - return userConfigFile; - } - - public String getBufferFileName() { - return configuration.getStringValue("bufferFileName"); - } - - public File getBufferFile() { - return bufferFile; + String fname; + if ((fname = getUserConfigFileName()) == null) { + return null; + } + return new File(fname); } public String getLanguage() { @@ -585,6 +567,10 @@ return configuration.getBooleanObject("dumpConfiguration"); } + public boolean dumpConfig() { + return doDumpConfiguration().booleanValue(); + } + public boolean isDebugMode() { return configuration.isTrue("debugMode"); } @@ -603,18 +589,18 @@ public File getInputFile() { switch (inputmode) { case FO_INPUT: - return foFile; + return getFoFile(); case XSLT_INPUT: - return xmlFile; + return getXmlFile(); default: - return foFile; + return getFoFile(); } } /** * shows the commandline syntax including a summary of all available options and some examples */ - public void printUsage() { + protected void printUsage() { HelpFormatter help = new HelpFormatter(); help.printHelp("FOP", options, true); } @@ -622,7 +608,7 @@ /** * shows the options for print output */ - public void printUsagePrintOutput() { + protected 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" @@ -633,7 +619,7 @@ /** * debug mode. outputs all commandline settings */ - private void debug() { + protected void debug() { StringBuffer fine = new StringBuffer(); StringBuffer severe = new StringBuffer(); fine.append("Input mode: "); @@ -643,12 +629,12 @@ break; case FO_INPUT: fine.append("FO "); - fine.append("fo input file: " + foFile.toString()); + fine.append("fo input file: " + getFoFileName()); break; case XSLT_INPUT: fine.append("xslt transformation"); - fine.append("xml input file: " + xmlFile.toString()); - fine.append("xslt stylesheet: " + xsltFile.toString()); + fine.append("xml input file: " + getXmlFileName()); + fine.append("xslt stylesheet: " + getXsltFileName()); break; default: fine.append("unknown input type"); @@ -660,45 +646,45 @@ break; case PDF_OUTPUT: fine.append("pdf"); - fine.append("output file: " + outputFile.toString()); + fine.append("output file: " + getOutputFileName()); break; case AWT_OUTPUT: fine.append("awt on screen"); - if (outputFile != null) { + if (getOutputFile() != null) { severe.append("awt mode, but outfile is set:\n"); - fine.append("out file: " + outputFile.toString()); + severe.append("output file: " + getOutputFileName() + "\n"); } break; case MIF_OUTPUT: fine.append("mif"); - fine.append("output file: " + outputFile.toString()); + fine.append("output file: " + getOutputFileName()); break; case RTF_OUTPUT: fine.append("rtf"); - fine.append("output file: " + outputFile.toString()); + fine.append("output file: " + getOutputFileName()); break; case PRINT_OUTPUT: fine.append("print directly"); - if (outputFile != null) { + if (getOutputFile() != null) { severe.append("print mode, but outfile is set:\n"); - severe.append("out file: " + outputFile.toString() + "\n"); + severe.append("output file: " + getOutputFileName() + "\n"); } break; case PCL_OUTPUT: fine.append("pcl"); - fine.append("output file: " + outputFile.toString()); + fine.append("output file: " + getOutputFileName()); break; case PS_OUTPUT: fine.append("PostScript"); - fine.append("output file: " + outputFile.toString()); + fine.append("output file: " + getOutputFileName()); break; case TXT_OUTPUT: fine.append("txt"); - fine.append("output file: " + outputFile.toString()); + fine.append("output file: " + getOutputFileName()); break; case SVG_OUTPUT: fine.append("svg"); - fine.append("output file: " + outputFile.toString()); + fine.append("output file: " + getOutputFileName()); break; default: fine.append("unknown input type"); @@ -706,14 +692,14 @@ fine.append("\nOPTIONS\n"); - if (userConfigFile != null) { + if (getUserConfigFileName() != null) { fine.append("user configuration file: " - + userConfigFile.toString()); + + getUserConfigFileName()); } else { fine.append("no user configuration file is used [default]"); } fine.append("\n"); - if (dumpConfig == true) { + if (dumpConfig()) { fine.append("dump configuration"); } else { fine.append("don't dump configuration [default]"); 1.1.2.2 +28 -50 xml-fop/src/java/org/apache/fop/configuration/Attic/CLI_Options.java Index: CLI_Options.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/configuration/Attic/CLI_Options.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- CLI_Options.java 13 Mar 2004 08:41:29 -0000 1.1.2.1 +++ CLI_Options.java 14 Mar 2004 02:44:53 -0000 1.1.2.2 @@ -19,8 +19,6 @@ package org.apache.fop.configuration; -// java -import java.io.File; import java.io.FileNotFoundException; import java.util.Locale; import java.util.logging.Level; @@ -40,17 +38,12 @@ * additional setting of commandline options */ public class CLI_Options extends UserOptions { - + + String[] args = null; + public CLI_Options(Configuration configuration, String[] args) { super(configuration); - this.configuration = configuration; - try { - configure(args); - } catch (FileNotFoundException e) { - throw new RuntimeException(e); - } catch (FOPException e) { - throw new RuntimeException(e); - } + this.args = args; } /** @@ -69,18 +62,20 @@ private Options makeOptions() { // Create the Options object that will be returned Options options = new Options(); + OptionBuilder.withArgName("help"); + OptionBuilder.withLongOpt("help"); + OptionBuilder.withDescription("Describe usage"); + options.addOption(OptionBuilder.create("?")); // The mutually exclusive verbosity group includes the -d and -q flags OptionGroup verbosity = new OptionGroup(); OptionBuilder.withArgName("debug mode"); OptionBuilder.withLongOpt("full-error-dump"); OptionBuilder.withDescription("Debug mode: verbose reporting"); - verbosity.addOption( - OptionBuilder.create("d")); + verbosity.addOption(OptionBuilder.create("d")); OptionBuilder.withArgName("quiet mode"); OptionBuilder.withLongOpt("quiet"); OptionBuilder.withDescription("Quiet mode: report errors only"); - verbosity.addOption( - OptionBuilder.create("q")); + verbosity.addOption(OptionBuilder.create("q")); verbosity.setRequired(false); // Add verbosity to options options.addOptionGroup(verbosity); @@ -95,23 +90,20 @@ OptionBuilder.withLongOpt("config-file"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Configuration file"); - options.addOption( - OptionBuilder.create("c")); + options.addOption(OptionBuilder.create("c")); // Add the language option directly OptionBuilder.withArgName("language"); OptionBuilder.withLongOpt("language"); OptionBuilder.hasArg(); OptionBuilder.withDescription("ISO639 language code"); - options.addOption( - OptionBuilder.create("l")); + options.addOption(OptionBuilder.create("l")); // Create the mutually exclusive input group OptionGroup input = new OptionGroup(); OptionBuilder.withArgName("fo:file"); OptionBuilder.withLongOpt("fo"); OptionBuilder.hasArg(); OptionBuilder.withDescription("XSL-FO input file"); - input.addOption( - OptionBuilder.create("fo")); + input.addOption(OptionBuilder.create("fo")); OptionBuilder.withArgName("xml file"); OptionBuilder.withLongOpt("xml"); OptionBuilder.hasArg(); @@ -126,8 +118,7 @@ OptionBuilder.withLongOpt("xsl"); OptionBuilder.hasArg(); OptionBuilder.withDescription("XSL stylesheet for transforming XML to XSL-FO"); - options.addOption( - OptionBuilder.create("xsl")); + options.addOption(OptionBuilder.create("xsl")); // Work-around for the xsl parameters // Allow multiple arguments (does this apply to multiple instances // of the argument specifier?) of the form <name=value>, using '=' @@ -137,80 +128,68 @@ OptionBuilder.withLongOpt("xsl-param"); OptionBuilder.hasArgs(Option.UNLIMITED_VALUES); OptionBuilder.withDescription("Parameter to XSL stylesheet"); - options.addOption( - OptionBuilder.create("param")); + options.addOption(OptionBuilder.create("param")); // Create the mutually exclusive output group OptionGroup output = new OptionGroup(); OptionBuilder.withArgName("screen renderer"); OptionBuilder.withLongOpt("awt"); OptionBuilder.withDescription("Input will be renderered to display"); - output.addOption( - OptionBuilder.create("awt")); + output.addOption(OptionBuilder.create("awt")); OptionBuilder.withArgName("pdf output file"); OptionBuilder.withLongOpt("pdf"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Input will be rendered as PDF to named file"); - output.addOption( - OptionBuilder.create("pdf")); + output.addOption(OptionBuilder.create("pdf")); OptionBuilder.withArgName("postscript output file"); OptionBuilder.withLongOpt("ps"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Input will be rendered as Postscript to named file"); - output.addOption( - OptionBuilder.create("ps")); + output.addOption(OptionBuilder.create("ps")); OptionBuilder.withArgName("pcl output file"); OptionBuilder.withLongOpt("pcl"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Input will be rendered as PCL to named file"); - output.addOption( - OptionBuilder.create("pcl")); + output.addOption(OptionBuilder.create("pcl")); OptionBuilder.withArgName("rtf output file"); OptionBuilder.withLongOpt("rtf"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Input will be rendered as RTF to named file"); - output.addOption( - OptionBuilder.create("rtf")); + output.addOption(OptionBuilder.create("rtf")); OptionBuilder.withArgName("mif output file"); OptionBuilder.withLongOpt("mif"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Input will be rendered as MIF to named file"); - output.addOption( - OptionBuilder.create("mif")); + output.addOption(OptionBuilder.create("mif")); OptionBuilder.withArgName("svg output file"); OptionBuilder.withLongOpt("svg"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Input will be rendered as SVG to named file"); - output.addOption( - OptionBuilder.create("svg")); + output.addOption(OptionBuilder.create("svg")); OptionBuilder.withArgName("text output file"); OptionBuilder.withLongOpt("plain-text"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Input will be rendered as plain text to named file"); - output.addOption( - OptionBuilder.create("txt")); + output.addOption(OptionBuilder.create("txt")); OptionBuilder.withArgName("area tree output file"); OptionBuilder.withLongOpt("area-tree"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Area tree will be output as XML to named file"); - output.addOption( - OptionBuilder.create("at")); + output.addOption(OptionBuilder.create("at")); OptionBuilder.withArgName("help"); OptionBuilder.withLongOpt("print"); OptionBuilder.hasOptionalArg(); OptionBuilder.withDescription("Input will be rendered and sent to the printer. " + "Requires extra arguments to the \"java\" command. " + "See options with \"-print help\"."); - output.addOption( - OptionBuilder.create("print")); + output.addOption(OptionBuilder.create("print")); // -s option relevant only to -at area tree output. Again, no way // to express this directly OptionBuilder.withArgName("supress low-level areas"); OptionBuilder.withLongOpt("only-block-areas"); OptionBuilder.withDescription("Suppress non-block areas in XML renderer"); - options.addOption( - OptionBuilder.create("s")); + options.addOption(OptionBuilder.create("s")); return options; } @@ -328,7 +307,7 @@ if (cli.getOptionValue("print").toLowerCase(Locale.getDefault()) == "help") { printUsagePrintOutput(); - throw new FOPException("Usage only"); + throw new FOPException("Print usage only"); } } // Get any remaining non-options @@ -341,7 +320,6 @@ setInputMode(FO_INPUT); filename = remArgs[i++]; configuration.put("foFileName", filename); - foFile = new File(filename); } if (outputmode == NOT_SET && i < remArgs.length && remArgs[i].charAt(0) != '-') { 1.1.2.2 +19 -3 xml-fop/src/java/org/apache/fop/configuration/Attic/UserOptions.java Index: UserOptions.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/configuration/Attic/UserOptions.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- UserOptions.java 13 Mar 2004 08:41:29 -0000 1.1.2.1 +++ UserOptions.java 14 Mar 2004 02:44:53 -0000 1.1.2.2 @@ -22,6 +22,7 @@ // java import java.io.File; +import java.io.FileNotFoundException; // fop import org.apache.fop.apps.FOPException; import org.apache.fop.apps.InputHandler; @@ -41,6 +42,17 @@ public UserOptions(Configuration configuration) { super(configuration); } + + /** + * Configure the system according to the system configuration file + * config.xml and the user configuration file if it is specified in the + * system configuration file. + */ + public void configure() + throws FOPException, FileNotFoundException { + loadUserConfiguration(getUserConfigFileName()); + super.configure(); + } /** * Load a user-defined configuration file. @@ -50,10 +62,14 @@ * <code>loadConfiguration</code>. * @param userConfigFileName the name of the user configuration file. */ - public void loadConfiguration(String userConfigFileName) { + public void loadUserConfiguration(String userConfigFileName) { // read user configuration file boolean readOk = true; - userConfigFile = new File(userConfigFileName); + if (userConfigFileName == null) { + log.config("No user config file name"); + return; + } + File userConfigFile = new File(userConfigFileName); if (userConfigFile == null) { return; } 1.1.2.7 +3 -2 xml-fop/src/java/org/apache/fop/configuration/Attic/ConfigurationParser.java Index: ConfigurationParser.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/configuration/Attic/ConfigurationParser.java,v retrieving revision 1.1.2.6 retrieving revision 1.1.2.7 diff -u -r1.1.2.6 -r1.1.2.7 --- ConfigurationParser.java 13 Mar 2004 08:41:29 -0000 1.1.2.6 +++ ConfigurationParser.java 14 Mar 2004 02:44:53 -0000 1.1.2.7 @@ -270,8 +270,9 @@ configuration.logger.config( "Existing value for key " + key + ":" + val.toString() + " overrides " + value.toString()); + } else { + activeConfiguration.put(key, value); } - activeConfiguration.put(key, value); } else { configuration.logger.warning("Unknown role >" + role + "< for new configuration entry. \n"
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]