From: bruce m. <tr...@us...> - 2004-07-30 00:14:10
|
Update of /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28587/modules/core/src/com/babeldoc/core Modified Files: BabeldocCommand.java Log Message: When BabeldocCommand is run with an option -d, the logger is put into debug mode. Index: BabeldocCommand.java =================================================================== RCS file: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/BabeldocCommand.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** BabeldocCommand.java 23 Jul 2004 22:28:09 -0000 1.18 --- BabeldocCommand.java 30 Jul 2004 00:13:54 -0000 1.19 *************** *** 78,81 **** --- 78,83 ---- import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; + import org.apache.log4j.Logger; + import org.apache.log4j.Level; /** *************** *** 91,297 **** */ public abstract class BabeldocCommand ! extends Named { ! /** Options */ ! private Options options = new Options(); ! /** The description of the command */ ! private String desc; ! /** instance: is this verbose */ ! private boolean verbose = false; ! /** ! * Had to lessen this from private access. This is because it is too strict ! * for all purposes. ! */ ! protected BabeldocCommand() { ! } ! /** ! * construct the object. The arguments from the command line. ! * ! * @param name command name ! * @param desc command description ! * @param args command line arguments ! */ ! protected BabeldocCommand(String name, String desc, String[] args) { ! setName(name); ! this.desc = desc; ! setup(); ! setupCommandLine(options); ! CommandLine commandLine = null; ! try { ! commandLine = new GnuParser().parse(options, args); ! } catch (ParseException e) { ! printUsage(); ! return; ! } ! setupShutdownHook(); ! executeCommand(commandLine); ! } ! /** ! * Set the verbose flag ! * ! * @param verbose flag ! */ ! public void setVerbose(boolean verbose) { ! this.verbose = verbose; ! } ! /** ! * @return get the verbose flag ! */ ! public boolean isVerbose() { ! return verbose; ! } ! /** ! * execute the commandline. This must be overloaded to handle the command ! * line options ! * ! * @param commandLine the command line options that have been detected ! */ ! public void executeCommand(CommandLine commandLine) { ! if (commandLine.hasOption('h')) { ! printUsage(); ! return; ! }; ! if (commandLine.hasOption('v')) { ! setVerbose(true); ! }; ! if (commandLine.hasOption('d')) { ! printConfigInfo(); ! }; ! execute(commandLine); EnvironmentLoader.shutdown(); ! } ! ! ! /** ! * @param commandLine ! */ ! public abstract void execute(CommandLine commandLine); ! /** ! * Stopping - execute all necessary shutdown processing. ! */ ! public void finishUp() { ! } ! /** ! * print the usage instructions ! */ ! public void printUsage() { ! System.out.println(getName()); ! System.out.println(desc); ! new HelpFormatter().printHelp(getName(), options); ! String version = ! ConfigService.getString("env/build", "babeldoc_version"); ! System.out.println("\n" + I18n.get("001006", version)); ! System.out.println(I18n.get("001007")); ! System.out.println(I18n.get("001008")); ! System.out.println(I18n.get("001009")); ! } ! /** ! * print configuration info ! */ ! public void printConfigInfo() { ! // NOTE: copied from LightConfigService.mergePropertiesFileFromUserSearchPath ! // get all the 'config.properties' files that are/will be loaded ! URL[] urls = ! ResourceLoader.getMatchingUrlsInSearchPath( ! "env/config.properties", ! EnvironmentLoader.getSearchPaths()); ! // display the name and contents of each config file ! System.out.println("Showing configuration files and contents:"); ! for (int i = urls.length - 1; i >= 0; --i) { ! URL url = urls[i]; ! System.out.println(" === " + url + " ==="); ! try { ! BufferedReader reader = ! new BufferedReader(new InputStreamReader(url.openStream())); ! String line; ! do { ! line = reader.readLine(); ! if (line != null) { ! System.out.println(line); ! } ! } while (line != null); ! } catch (IOException e) { ! LogService.getInstance().logError(e); ! } ! } ! } ! /** ! * setup the options on the command line. ! * ! * @param options the options to access ! */ ! public void setupCommandLine(Options options) { ! options.addOption( ! "v", ! "verbose", ! false, ! I18n.get("001002")); ! options.addOption( ! "h", ! "help", ! false, ! I18n.get("001003")); ! options.addOption("d", "debug", false, "Write config info to stdout"); ! } ! /** ! * Setup the shutdown hook. ! */ ! public void setupShutdownHook() { ! /** ! * Thread class that will be executed when this command shutsdown. ! */ ! class ShutMeDownNicely extends Thread { ! BabeldocCommand command; ! /** ! * Creates a new ShutMeDownNicely object. ! * ! * @param command DOCUMENT ME! ! */ ! ShutMeDownNicely(BabeldocCommand command) { ! super("shutdown"); ! this.command = command; ! } ! /** ! * shut down the command by calling finishUp ! */ ! public void run() { ! LogService.getInstance().logDebug(I18n.get("001001")); ! command.finishUp(); ! } ! } ! Runtime.getRuntime().addShutdownHook(new ShutMeDownNicely(this)); ! } ! /** ! * Setup - calls the Environment loader which bootstraps the ! * <sttrong>Babeldoc</strong> environment. ! */ ! protected void setup() { ! // EnvironmentLoader.loadEnvironment(); ! } } --- 93,310 ---- */ public abstract class BabeldocCommand ! extends Named { ! /** Available options. */ ! private Options options = new Options(); ! /** The description of the command. */ ! private String desc; ! /** instance: is this verbose. */ ! private boolean verbose = false; ! private static final String LOGGER_NAME = "com.babeldoc"; ! /** ! * Had to lessen this from private access. This is because it is too strict ! * for all purposes. ! */ ! protected BabeldocCommand() { ! } ! /** ! * Construct the object. The arguments from the command line are ! * parsed into the CommandLine object which is then passed to ! * the executeCommand method. ! * ! * @param name command name ! * @param desc command description ! * @param args command line arguments ! */ ! protected BabeldocCommand(String name, String desc, String[] args) { ! setName(name); ! this.desc = desc; ! setup(); ! setupCommandLine(options); ! CommandLine commandLine = null; ! try { ! commandLine = new GnuParser().parse(options, args); ! } catch (ParseException e) { ! printUsage(); ! return; ! } ! setupShutdownHook(); ! executeCommand(commandLine); ! } ! /** ! * Set the verbose flag. ! * ! * @param verbose flag ! */ ! public void setVerbose(boolean verbose) { ! this.verbose = verbose; ! if(this.verbose) { ! Logger.getLogger(LOGGER_NAME).setLevel((Level)Level.DEBUG); ! } ! } ! /** ! * Get the verbose flag. ! * ! * @return get the verbose flag ! */ ! public boolean isVerbose() { ! return verbose; ! } ! /** ! * execute the commandline. This must be overloaded to handle the command ! * line options ! * ! * @param commandLine the command line options that have been detected ! */ ! public void executeCommand(CommandLine commandLine) { ! if (commandLine.hasOption('h')) { ! printUsage(); ! return; ! }; ! if (commandLine.hasOption('v')) { ! setVerbose(true); ! }; ! if (commandLine.hasOption('d')) { ! printConfigInfo(); ! }; ! execute(commandLine); EnvironmentLoader.shutdown(); ! } ! ! ! /** ! * Execute the command specific arguments from using the command line. ! * ! * @param commandLine parsed arguments from main. ! */ ! public abstract void execute(CommandLine commandLine); ! /** ! * Stopping - execute all necessary shutdown processing. ! */ ! public void finishUp() { ! } ! /** ! * print the usage instructions. Child classes must call this prior ! * to printing their usage instructions. ! */ ! public void printUsage() { ! System.out.println(getName()); ! System.out.println(desc); ! new HelpFormatter().printHelp(getName(), options); ! String version = ! ConfigService.getString("env/build", "babeldoc_version"); ! System.out.println("\n" + I18n.get("001006", version)); ! System.out.println(I18n.get("001007")); ! System.out.println(I18n.get("001008")); ! System.out.println(I18n.get("001009")); ! } ! /** ! * print configuration infomation. ! */ ! public void printConfigInfo() { ! // NOTE: copied from LightConfigService.mergePropertiesFileFromUserSearchPath ! // get all the 'config.properties' files that are/will be loaded ! URL[] urls = ! ResourceLoader.getMatchingUrlsInSearchPath( ! "env/config.properties", ! EnvironmentLoader.getSearchPaths()); ! // display the name and contents of each config file ! System.out.println("Showing configuration files and contents:"); ! for (int i = urls.length - 1; 0 <= i; --i) { ! URL url = urls[i]; ! System.out.println(" === " + url + " ==="); ! try { ! BufferedReader reader = ! new BufferedReader(new InputStreamReader(url.openStream())); ! String line; ! do { ! line = reader.readLine(); ! if (null != line) { ! System.out.println(line); ! } ! } while (null != line); ! } catch (IOException e) { ! LogService.getInstance().logError(e); ! } ! } ! } ! /** ! * setup the options on the command line. ! * ! * @param options the options to access ! */ ! public void setupCommandLine(Options options) { ! options.addOption( ! "v", ! "verbose", ! false, ! I18n.get("001002")); ! options.addOption( ! "h", ! "help", ! false, ! I18n.get("001003")); ! options.addOption("d", "debug", false, "Write config info to stdout"); ! } ! /** ! * Setup the shutdown hook. ! */ ! public void setupShutdownHook() { ! /** ! * Thread class that will be executed when this command shutsdown. ! */ ! class ShutMeDownNicely extends Thread { ! BabeldocCommand command; ! /** ! * Creates a new ShutMeDownNicely object. ! * ! * @param command DOCUMENT ME! ! */ ! ShutMeDownNicely(BabeldocCommand command) { ! super("shutdown"); ! this.command = command; ! } ! /** ! * shut down the command by calling finishUp ! */ ! public void run() { ! LogService.getInstance().logDebug(I18n.get("001001")); ! command.finishUp(); ! } ! } ! Runtime.getRuntime().addShutdownHook(new ShutMeDownNicely(this)); ! } ! /** ! * Setup - calls the Environment loader which bootstraps the ! * <sttrong>Babeldoc</strong> environment. ! */ ! protected void setup() { ! // EnvironmentLoader.loadEnvironment(); ! } } |