Search in sources :

Example 1 with FallbackBasePathLocationStrategy

use of org.openksavi.sponge.core.config.FallbackBasePathLocationStrategy in project sponge by softelnet.

the class DefaultConfigurationManager method createXmlConfiguration.

protected Pair<XMLConfiguration, URL> createXmlConfiguration(String fileName) {
    List<Lookup> lookups = Arrays.asList(new SystemPropertiesLookup(), new HomeLookup(), new ConfigLookup());
    Parameters params = new Parameters();
    FallbackBasePathLocationStrategy locationStrategy = new FallbackBasePathLocationStrategy(FileLocatorUtils.DEFAULT_LOCATION_STRATEGY, home);
    FileBasedConfigurationBuilder<XMLConfiguration> builder = new FileBasedConfigurationBuilder<>(XMLConfiguration.class).configure(params.xml().setDefaultLookups(lookups).setLocationStrategy(locationStrategy).setFileName(fileName).setSchemaValidation(true).setEntityResolver(new ResourceSchemaResolver()));
    try {
        XMLConfiguration xmlConfiguration = builder.getConfiguration();
        return new ImmutablePair<>(xmlConfiguration, locationStrategy.getLocatedUrl());
    } catch (ConfigurationException e) {
        throw new ConfigException("Error reading configuration file " + fileName, e);
    }
}
Also used : Parameters(org.apache.commons.configuration2.builder.fluent.Parameters) ConfigException(org.openksavi.sponge.config.ConfigException) XMLConfiguration(org.apache.commons.configuration2.XMLConfiguration) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) FallbackBasePathLocationStrategy(org.openksavi.sponge.core.config.FallbackBasePathLocationStrategy) SystemPropertiesLookup(org.apache.commons.configuration2.interpol.SystemPropertiesLookup) Lookup(org.apache.commons.configuration2.interpol.Lookup) SystemPropertiesLookup(org.apache.commons.configuration2.interpol.SystemPropertiesLookup)

Aggregations

XMLConfiguration (org.apache.commons.configuration2.XMLConfiguration)1 Parameters (org.apache.commons.configuration2.builder.fluent.Parameters)1 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)1 Lookup (org.apache.commons.configuration2.interpol.Lookup)1 SystemPropertiesLookup (org.apache.commons.configuration2.interpol.SystemPropertiesLookup)1 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1 ConfigException (org.openksavi.sponge.config.ConfigException)1 FallbackBasePathLocationStrategy (org.openksavi.sponge.core.config.FallbackBasePathLocationStrategy)1