Search in sources :

Example 1 with DecryptionLookup

use of org.craftercms.commons.config.DecryptionLookup 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;
    }
}
Also used : XMLConfiguration(org.apache.commons.configuration2.XMLConfiguration) HierarchicalConfiguration(org.apache.commons.configuration2.HierarchicalConfiguration) Configuration(org.apache.commons.configuration2.Configuration) CombinedConfiguration(org.apache.commons.configuration2.CombinedConfiguration) ArrayList(java.util.ArrayList) Resource(org.springframework.core.io.Resource) DecryptionLookup(org.craftercms.commons.config.DecryptionLookup) CombinedConfiguration(org.apache.commons.configuration2.CombinedConfiguration) HierarchicalConfiguration(org.apache.commons.configuration2.HierarchicalConfiguration) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) OverrideCombiner(org.apache.commons.configuration2.tree.OverrideCombiner) XMLConfiguration(org.apache.commons.configuration2.XMLConfiguration) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) DecryptionLookup(org.craftercms.commons.config.DecryptionLookup) Lookup(org.apache.commons.configuration2.interpol.Lookup)

Aggregations

ArrayList (java.util.ArrayList)1 CombinedConfiguration (org.apache.commons.configuration2.CombinedConfiguration)1 Configuration (org.apache.commons.configuration2.Configuration)1 HierarchicalConfiguration (org.apache.commons.configuration2.HierarchicalConfiguration)1 XMLConfiguration (org.apache.commons.configuration2.XMLConfiguration)1 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)1 Lookup (org.apache.commons.configuration2.interpol.Lookup)1 OverrideCombiner (org.apache.commons.configuration2.tree.OverrideCombiner)1 DecryptionLookup (org.craftercms.commons.config.DecryptionLookup)1 Resource (org.springframework.core.io.Resource)1