String propertyFileName = this.strings.getGroup(1);
propertyFileName = fileUtils.addRoot(propertyFileName);
File propertyFile = new File(propertyFileName);
if (!propertyFile.isFile()) {
throw new InvalidConfigFileFormatException(
"Could not find properties file: " + propertyFile);
}
// Create the hashmap and list where properties will be stored.
HashMap<String,String> propsMap = new HashMap<String,String>();
List<String> propsList = new ArrayList<String>();
boolean result = xmlParseUtils.readProperties(propertyFile,
propsList,
propsMap);
// If error reading the properties file, throw exception.
if (!result) {
throw new InvalidConfigFileFormatException(
"Error reading Properties file: " + propertyFile + "; also see warning log.");
}
// Step through all properties and replace them.
for (int i = 0; i < propsList.size(); i++) {
String propName = propsList.get(i);
String propValue = propsMap.get(propName);
// Create the pattern and substitute.
String propPattern = "%%" + propName + "%%";
// Dollar signs in value must be escaped.
propValue = propValue.replace("$", "\\$");
cfgFileStr = this.strings.substitute(propPattern,
propValue,
cfgFileStr);
}
// See if there are any undefined properties.
if (this.strings.matches("\"%%[^\"\n%]+?%%\"", cfgFileStr)) {
throw new InvalidConfigFileFormatException(
this.strings.getGroup(0) + " property reference in GetMessage file " +
"was not found in properties file \"" + propertyFile + "\"");
}
return cfgFileStr;
}