use of org.apache.commons.configuration2.builder.fluent.Parameters 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.builder.fluent.Parameters in project cas by apereo.
the class CasConfigurationPropertiesEnvironmentManager method savePropertyForStandaloneProfile.
/**
* Save property for standalone profile.
*
* @param pair the pair
*/
@SneakyThrows
public void savePropertyForStandaloneProfile(final Pair<String, String> pair) {
final File file = getStandaloneProfileConfigurationDirectory();
final Parameters params = new Parameters();
final FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class).configure(params.properties().setFile(new File(file, getApplicationName() + ".properties")));
final Configuration config = builder.getConfiguration();
config.setProperty(pair.getKey(), pair.getValue());
builder.save();
}
use of org.apache.commons.configuration2.builder.fluent.Parameters in project nifi by apache.
the class CommonsConfigurationLookupService method onEnabled.
@OnEnabled
public void onEnabled(final ConfigurationContext context) throws InitializationException {
final String config = context.getProperty(CONFIGURATION_FILE).getValue();
final FileBasedBuilderParameters params = new Parameters().fileBased().setFile(new File(config));
this.builder = new ReloadingFileBasedConfigurationBuilder<>(resultClass).configure(params);
builder.addEventListener(ConfigurationBuilderEvent.CONFIGURATION_REQUEST, new EventListener<ConfigurationBuilderEvent>() {
@Override
public void onEvent(ConfigurationBuilderEvent event) {
if (builder.getReloadingController().checkForReloading(null)) {
getLogger().debug("Reloading " + config);
}
}
});
try {
// Try getting configuration to see if there is any issue, for example wrong file format.
// Then throw InitializationException to keep this service in 'Enabling' state.
builder.getConfiguration();
} catch (ConfigurationException e) {
throw new InitializationException(e);
}
}
use of org.apache.commons.configuration2.builder.fluent.Parameters in project winery by eclipse.
the class Environment method copyConfiguration.
/**
* Overwrite configuration parameters by using the given file
*
* @param path a path pointing to a file where the configuration should be read from
*/
public static void copyConfiguration(Path path) throws Exception {
Configurations configs = new Configurations();
Configuration configuration = configs.properties(path.toFile());
copyConfiguration(configuration);
}
use of org.apache.commons.configuration2.builder.fluent.Parameters in project winery by eclipse.
the class Environment method copyConfiguration.
/**
* Overwrite configuration parameters by using the given URL
*
* @param url a URL pointing to a file where the configuration should be read from
*/
public static void copyConfiguration(URL url) throws Exception {
Configurations configs = new Configurations();
Configuration configuration = configs.properties(url);
copyConfiguration(configuration);
}
Aggregations