configFileName = completeFileName(configFileName, contextDir);
LOGGER.info("Loading XML configuration from {}", configFileName);
T instance;
XmlConfigParser xmlConfigParser = new XmlConfigParser();
InputStream input;
final File configFile = new File(contextDir, configFileName);
if (configFileName.endsWith(".ftl")) {
// the input file is a FreeMarker template, so process it
// TODO:could be used normalize from file
// configFileName can be in form ../configuration/Template.ftl, we have to remove ../ so fm can recognize path
String trimedConfigFileName = configFileName;
while(trimedConfigFileName.startsWith("../")) {
trimedConfigFileName = trimedConfigFileName.substring(3);
}
input = processFreeMarkerTemplate(trimedConfigFileName);
} else {
input = new FileInputStream(configFile);
}
final XmlConfig xmlConfig;
try {
xmlConfig = xmlConfigParser.loadConfig(input);
} finally {
input.close();
}
Class<?> cls = Thread.currentThread().getContextClassLoader().loadClass(xmlConfig.getClassName());