From: Keiron Liddle Date: Wed, 4 Jul 2001 13:53:28 +0000 (+0000) Subject: fixed error where configfile was not being set X-Git-Tag: PRE_CODEFORMATTING~50 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=da65d843480b5d4d3ded02ef7c3ba18b645b3fca;p=xmlgraphics-fop.git fixed error where configfile was not being set git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194329 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/org/apache/fop/apps/Options.java b/src/org/apache/fop/apps/Options.java index 03655e645..9f65b4c78 100644 --- a/src/org/apache/fop/apps/Options.java +++ b/src/org/apache/fop/apps/Options.java @@ -1,10 +1,9 @@ -/* +/* $Id$ * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. - * For details on use and redistribution please refer to the - * LICENSE file included with these sources." + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. */ - package org.apache.fop.apps; //sax @@ -18,89 +17,88 @@ import java.io.InputStream; import org.apache.fop.messaging.MessageHandler; import org.apache.fop.configuration.Configuration; import org.apache.fop.configuration.ConfigurationReader; - + /** - * Options handles loading of configuration files and + * Options handles loading of configuration files and * additional setting of commandline options */ public class Options { - boolean errorDump = false; - - public Options () - throws FOPException - { - this.loadStandardConfiguration(); - initOptions (); + boolean errorDump = false; + + public Options () throws FOPException { + this.loadStandardConfiguration(); + initOptions (); } - - public Options (File userConfigFile) - throws FOPException - { - this(); - this.loadUserconfiguration(userConfigFile); + + public Options (File userConfigFile) throws FOPException { + this(); + this.loadUserconfiguration(userConfigFile); } - - public Options (CommandLineOptions clOptions) - throws FOPException + public Options (CommandLineOptions clOptions) throws FOPException { - this(); - this.setCommandLineOptions(clOptions); + this(); + this.setCommandLineOptions(clOptions); } - - //initializing option settings + + //initializing option settings void initOptions () { - if (Configuration.getBooleanValue("quiet").booleanValue()) { - MessageHandler.setQuiet(true); - } - if (Configuration.getBooleanValue("debugMode").booleanValue()) { - errorDump = true; - } - if (Configuration.getBooleanValue("dumpConfiguration").booleanValue()) { - Configuration.put("dumpConfiguration","true"); - Configuration.dumpConfiguration(); - } + if (Configuration.getBooleanValue("quiet").booleanValue()) { + MessageHandler.setQuiet(true); + } + if (Configuration.getBooleanValue("debugMode").booleanValue()) { + errorDump = true; + } + if (Configuration.getBooleanValue( + "dumpConfiguration").booleanValue()) { + Configuration.put("dumpConfiguration","true"); + Configuration.dumpConfiguration(); + } } - + //setting clOptions void setCommandLineOptions(CommandLineOptions clOptions) { - //load user configuration file,if there is one - File userConfigFile = clOptions.getUserConfigFile(); + //load user configuration file,if there is one + File userConfigFile = clOptions.getUserConfigFile(); if (userConfigFile != null) { this.loadUserconfiguration(userConfigFile); } - + //debug mode - if (clOptions.isDebugMode() != null) { - errorDump = clOptions.isDebugMode().booleanValue(); - Configuration.put("debugMode",new Boolean(errorDump)); - } - - //show configuration settings - boolean dumpConfiguration; - if (clOptions.dumpConfiguration() != null) { - dumpConfiguration = clOptions.dumpConfiguration().booleanValue(); - } else { - dumpConfiguration = Configuration.getBooleanValue("dumpConfiguration").booleanValue(); - } - if (dumpConfiguration) { - Configuration.put("dumpConfiguration","true"); - Configuration.dumpConfiguration(); + if (clOptions.isDebugMode() != null) { + errorDump = clOptions.isDebugMode().booleanValue(); + Configuration.put("debugMode",new Boolean(errorDump)); + } + + //show configuration settings + boolean dumpConfiguration; + if (clOptions.dumpConfiguration() != null) { + dumpConfiguration = + clOptions.dumpConfiguration().booleanValue(); + } else { + dumpConfiguration = Configuration.getBooleanValue( + "dumpConfiguration").booleanValue(); + } + if (dumpConfiguration) { + Configuration.put("dumpConfiguration","true"); + Configuration.dumpConfiguration(); System.exit(0); - } - - //quiet mode + } + + //quiet mode if (clOptions.isQuiet() != null) { MessageHandler.setQuiet(clOptions.isQuiet().booleanValue()); - } - - //set base directory + } + + //set base directory String baseDir = Configuration.getStringValue("baseDir"); if (baseDir == null) { try { - baseDir = new File(clOptions.getInputFile().getAbsolutePath()).getParentFile().toURL().toExternalForm(); + baseDir = new File( + clOptions.getInputFile().getAbsolutePath()). + getParentFile().toURL().toExternalForm(); Configuration.put("baseDir", baseDir); - } catch(Exception e) { + } catch (Exception e) { } } if (errorDump) { @@ -109,30 +107,32 @@ public class Options { } /** - * loads standard configuration file and a user file, if it has been specified - */ - public void loadStandardConfiguration() - throws FOPException - { + * loads standard configuration file and a user file, if it has been specified + */ + public void loadStandardConfiguration() throws FOPException { String file = "config.xml"; InputStream configfile = null; // Try to use Context Class Loader to load the properties file. try { - java.lang.reflect.Method getCCL = - Thread.class.getMethod("getContextClassLoader", new Class[0]); - if (getCCL != null) { - ClassLoader contextClassLoader = - (ClassLoader) getCCL.invoke(Thread.currentThread(), new Object[0]); - configfile = contextClassLoader.getResourceAsStream("conf/" + file); - } - } - catch (Exception e) {} + java.lang.reflect.Method getCCL = + Thread.class.getMethod("getContextClassLoader", + new Class[0]); + if (getCCL != null) { + ClassLoader contextClassLoader = + (ClassLoader) getCCL.invoke( + Thread.currentThread(), new Object[0]); + configfile = + contextClassLoader.getResourceAsStream("conf/" + + file); + } + } catch (Exception e) {} // the entry /conf/config.xml refers to a directory conf which is a sibling of org - if(configfile == null) - ConfigurationReader.class.getResourceAsStream("/conf/"+ - file); + if (configfile == null) + configfile = + ConfigurationReader.class.getResourceAsStream("/conf/"+ + file); if (configfile == null) { throw new FOPException("can't find default configuration file"); } @@ -140,34 +140,33 @@ public class Options { MessageHandler.logln("reading default configuration file"); } ConfigurationReader reader = - new ConfigurationReader (new InputSource(configfile)); + new ConfigurationReader (new InputSource(configfile)); if (errorDump) { reader.setDumpError(true); } - reader.start(); - + reader.start(); + } - public void loadUserconfiguration(String userConfigFile) - { + public void loadUserconfiguration(String userConfigFile) { loadUserconfiguration(new File(userConfigFile)); } - public void loadUserconfiguration(File userConfigFile) - { + public void loadUserconfiguration(File userConfigFile) { //read user configuration file if (userConfigFile != null) { MessageHandler.logln("reading user configuration file"); ConfigurationReader reader = new ConfigurationReader ( - InputHandler.fileInputSource(userConfigFile)); + InputHandler.fileInputSource(userConfigFile)); if (errorDump) { reader.setDumpError(true); } - try { - reader.start(); + try { + reader.start(); } catch (org.apache.fop.apps.FOPException error) { - MessageHandler.errorln("Can't find user configuration file " + - userConfigFile); + MessageHandler.errorln( + "Can't find user configuration file " + + userConfigFile); MessageHandler.errorln("using default values"); if (errorDump) { reader.dumpError(error);