use of org.apache.commons.configuration.tree.OverrideCombiner in project engine by craftercms.
the class MultiConfigurationBuilder method getConfiguration.
@Override
public Configuration getConfiguration() throws ConfigurationException {
List<Configuration> configs = new ArrayList<>();
// Last configurations should be loaded and added first so that they have greater priority.
logger.info("Loading XML configurations in the order in which the properties will be resolved");
for (int i = configPaths.length - 1; i >= 0; i--) {
try {
Resource resource = resourceLoader.getResource(configPaths[i]);
if (resource.exists()) {
XMLConfiguration config = new XMLConfiguration();
config.load(resource.getInputStream());
logger.info("XML configuration loaded from " + resource);
configs.add(config);
}
} catch (Exception e) {
throw new ConfigurationException("Unable to load configuration at " + configPaths[i], e);
}
}
if (configs.size() > 1) {
CombinedConfiguration combinedConfig = new CombinedConfiguration(new OverrideCombiner());
for (Configuration config : configs) {
combinedConfig.addConfiguration((AbstractConfiguration) config);
}
return combinedConfig;
} else if (configs.size() == 1) {
return configs.get(0);
} else {
return null;
}
}
Aggregations