use of org.apache.commons.configuration2.XMLConfiguration in project engine by craftercms.
the class ConfigUtils method readXmlConfiguration.
public static XMLConfiguration readXmlConfiguration(Resource resource, char listDelimiter, Map<String, Lookup> prefixLookups) throws ConfigurationException {
Parameters params = new Parameters();
FileBasedConfigurationBuilder<XMLConfiguration> builder = new FileBasedConfigurationBuilder<>(XMLConfiguration.class);
try {
XMLBuilderParameters xmlParams = params.xml().setURL(resource.getURL()).setListDelimiterHandler(new DefaultListDelimiterHandler(listDelimiter));
if (MapUtils.isNotEmpty(prefixLookups)) {
xmlParams = xmlParams.setPrefixLookups(prefixLookups);
}
builder.configure(xmlParams);
} catch (IOException e) {
throw new ConfigurationException("Unable to get URL of resource " + resource, e);
}
return builder.getConfiguration();
}
use of org.apache.commons.configuration2.XMLConfiguration in project engine by craftercms.
the class MultiResourceConfigurationBuilder method getConfiguration.
@Override
public HierarchicalConfiguration getConfiguration() throws ConfigurationException {
List<HierarchicalConfiguration> 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()) {
Map<String, Lookup> prefixLookups = null;
if (configDecryptor != null) {
prefixLookups = Collections.singletonMap(encryptedValuePrefix, new DecryptionLookup(configDecryptor));
}
XMLConfiguration config = ConfigUtils.readXmlConfiguration(resource, configListDelimiter, prefixLookups);
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(config);
}
return combinedConfig;
} else if (configs.size() == 1) {
return configs.get(0);
} else {
return null;
}
}
use of org.apache.commons.configuration2.XMLConfiguration in project sponge by softelnet.
the class DefaultConfigurationManager method createRootConfig.
protected CommonsConfiguration createRootConfig() {
MergeCombiner combiner = new MergeCombiner();
combiner.addListNode(PluginManagerConstants.CFG_PLUGIN);
CombinedConfiguration cc = new CombinedConfiguration(combiner);
// Try to add explicit configuration
if (configurationFilename != null) {
logger.info("Loading configuration file {}...", configurationFilename);
Pair<XMLConfiguration, URL> configurationPair = createXmlConfiguration(configurationFilename);
cc.addConfiguration(configurationPair.getLeft());
configurationFileUrl = configurationPair.getRight();
}
// Add default configuration
cc.addConfiguration(createXmlConfiguration(ConfigurationConstants.DEFAULT_CONFIG).getLeft());
return new CommonsConfiguration(cc);
}
use of org.apache.commons.configuration2.XMLConfiguration in project engine by craftercms.
the class ScriptFilterTest method createSiteContext.
private SiteContext createSiteContext(ContentStoreService storeService) throws Exception {
SiteContext siteContext = spy(new SiteContext());
ScriptFactory scriptFactory = createScriptFactory(siteContext);
XMLConfiguration config = ConfigUtils.readXmlConfiguration(new ClassPathResource("config/site-config.xml"), ',', null);
config.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
when(siteContext.getSiteName()).thenReturn("default");
when(siteContext.getContext()).thenReturn(mock(Context.class));
when(siteContext.getStoreService()).thenReturn(storeService);
when(siteContext.getConfig()).thenReturn(config);
when(siteContext.getScriptFactory()).thenReturn(scriptFactory);
when(siteContext.getCacheTemplate()).thenReturn(cacheTemplate);
return siteContext;
}
use of org.apache.commons.configuration2.XMLConfiguration in project engine by craftercms.
the class RejectIndexFilesItemFilterTest method setUpCurrentConfig.
private void setUpCurrentConfig() {
XMLConfiguration config = mock(XMLConfiguration.class);
when(config.getString(INDEX_FILE_NAME_CONFIG_KEY, DEFAULT_INDEX_FILE_NAME)).thenReturn(DEFAULT_INDEX_FILE_NAME);
when(config.getBoolean(TARGETING_ENABLED_CONFIG_KEY, false)).thenReturn(true);
SiteContext siteContext = spy(new SiteContext());
when(siteContext.getSiteName()).thenReturn("test");
when(siteContext.getConfig()).thenReturn(config);
SiteContext.setCurrent(siteContext);
}
Aggregations