|
From: <tr...@us...> - 2003-08-05 23:13:47
|
Update of /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/config/light
In directory sc8-pr-cvs1:/tmp/cvs-serv17599/src/com/babeldoc/core/config/light
Modified Files:
LightConfigService.java
Added Files:
LightConfigCommand.java
Log Message:
LightConfig configuration tracing tool.
--- NEW FILE: LightConfigCommand.java ---
package com.babeldoc.core.config.light;
import com.babeldoc.core.*;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.CommandLine;
import java.net.URL;
import java.io.IOException;
import java.util.Properties;
/**
*/
public class LightConfigCommand extends BabeldocCommand{
public static final String SPACER = " ";
/**
* process the class
*
* @param args DOCUMENT ME!
*/
public LightConfigCommand(String[] args) {
super("lightconfig", I18n.get("core.config.light.command.desc"), args);
}
/**
* Execute the command
*
* @param commandLine The command line.
*/
public void execute(CommandLine commandLine) {
super.execute(commandLine);
if(commandLine.hasOption('l')) {
String trackKey = null;
if(commandLine.hasOption('t')) {
trackKey = commandLine.getOptionValue('t');
}
listConfigFiles(commandLine.getOptionValue('l'), trackKey);
}
}
/**
* list the configuration information.
*
* @param configName name of the configuration file to list
* @param trackKey option key in the configuration file to track
*/
public void listConfigFiles(String configName, String trackKey) {
// NOTE: copied from LightConfigService.mergePropertiesFileFromUserSearchPath
configName = LightConfigService.getPropertyFileName(configName);
// get all the 'config.properties' files that are/will be loaded
URL[] urls = ResourceLoader.getMatchingUrlsInSearchPath(configName, EnvironmentLoader.getSearchPaths());
// display the name and contents of each config file
System.out.println(I18n.get("core.config.light.command.list", configName));
for (int i = urls.length - 1; i >= 0; --i) {
URL url = urls[i];
System.out.println(i+": " + url);
if(trackKey!=null) {
Properties properties = new Properties();
try {
properties.load(url.openStream());
} catch (IOException e) {
LogService.getInstance().logError(e);
}
if(properties.containsKey(trackKey)) {
System.out.println(I18n.get("core.config.light.command.defined", trackKey,
properties.getProperty(trackKey)));
} else {
System.out.println(I18n.get("core.config.light.command.notdefined", trackKey));
}
}
}
}
/**
* setup the options on the command line.
*
* @param options the options to access
*/
public void setupCommandLine(Options options) {
super.setupCommandLine(options);
options.addOption(OptionBuilder.isRequired().hasArg()
.withDescription(I18n.get("core.config.light.command.option.l"))
.withLongOpt("list").create("l"));
options.addOption(OptionBuilder.hasArg()
.withDescription(I18n.get("core.config.light.command.option.t"))
.withLongOpt("track").create("t"));
}
/**
* Main entry point
*
* @param args the name of the stage and the name=value pairs
*/
public static void main(String[] args) {
new LightConfigCommand(args);
}
}
Index: LightConfigService.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/core/src/com/babeldoc/core/config/light/LightConfigService.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** LightConfigService.java 8 Jul 2003 02:46:50 -0000 1.11
--- LightConfigService.java 5 Aug 2003 23:13:44 -0000 1.12
***************
*** 126,129 ****
--- 126,146 ----
*/
public IConfig getConfig(String name) {
+ String newname = getPropertyFileName(name);
+
+ // System.out.println("Loading: "+ name);
+ Properties properties = mergePropertiesFileFromUserSearchPath(newname,
+ new Properties());
+
+ return new LightConfig(name, properties);
+ }
+
+ /**
+ * Get the name of the property file (adds properties to end of
+ * the name if necessary)
+ *
+ * @param name configuration file name
+ * @return name + .properties if necessary
+ */
+ static String getPropertyFileName(String name) {
String newname = name;
***************
*** 131,140 ****
newname += DOT_PROPERTIES;
}
!
! Properties properties = new Properties();
! // loadFromModules(newname, properties);
! mergePropertiesFileFromUserSearchPath(newname, properties);
!
! return new LightConfig(name, properties);
}
--- 148,152 ----
newname += DOT_PROPERTIES;
}
! return newname;
}
***************
*** 240,244 ****
* @param properties
*/
! private void mergePropertiesFileFromUserSearchPath(String name,
Properties properties) {
URL[] urls = ResourceLoader.getMatchingUrlsInSearchPath(name,
--- 252,256 ----
* @param properties
*/
! Properties mergePropertiesFileFromUserSearchPath(String name,
Properties properties) {
URL[] urls = ResourceLoader.getMatchingUrlsInSearchPath(name,
***************
*** 248,252 ****
URL url = urls[i];
- // System.out.println("Search path: "+url);
try {
properties.load(url.openStream());
--- 260,263 ----
***************
*** 255,258 ****
--- 266,270 ----
}
}
+ return properties;
}
}
|