* an error occurs reading the properties files.
*/
public static Properties readProperties(String resourceName)
throws Exception {
Properties defaultProps = new Properties();
try {
// Apparently hardcoded slashes are OK here
// jdk1.1/docs/guide/misc/resources.html
Utils utils = new Utils();
Enumeration<URL> urls = utils.getClass().getClassLoader().getResources(resourceName);
boolean first = true;
while (urls.hasMoreElements()) {
URL url = urls.nextElement();
if (first) {
defaultProps.load(url.openStream());
first = false;
}
else {
Properties props = new Properties(defaultProps);
props.load(url.openStream());
defaultProps = props;
}
}
} catch (Exception ex) {
System.err.println("Warning, unable to load properties file(s) from "
+"system resource (Utils.java): " + resourceName);
}
// Hardcoded slash is OK here
// eg: see jdk1.1/docs/guide/misc/resources.html
int slInd = resourceName.lastIndexOf('/');
if (slInd != -1) {
resourceName = resourceName.substring(slInd + 1);
}
// Allow a properties file in the WekaPackageManager.PROPERTIES_DIR to override
Properties userProps = new Properties(defaultProps);
if (!WekaPackageManager.PROPERTIES_DIR.exists()) {
WekaPackageManager.PROPERTIES_DIR.mkdir();
}
File propFile = new File(WekaPackageManager.PROPERTIES_DIR.toString()
+ File.separator
+ resourceName);
if (propFile.exists()) {
try {
userProps.load(new FileInputStream(propFile));
} catch (Exception ex) {
throw new Exception("Problem reading user properties: " + propFile);
}
}
// Allow a properties file in the current directory to override
Properties localProps = new Properties(userProps);
propFile = new File(resourceName);
if (propFile.exists()) {
try {
localProps.load(new FileInputStream(propFile));
} catch (Exception ex) {
throw new Exception("Problem reading local properties: " + propFile);
}
}