use of org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder in project data-prep by Talend.
the class PropertiesEncryption method modifyAndSave.
/**
* Applies the specified function to the specified set of parameters contained in the input file.
*
* @param input The specified name of file to encrypt
* @param mustBeModified the specified set of parameters
* @param function the specified function to apply to the set of specified parameters
*/
private void modifyAndSave(String input, Set<String> mustBeModified, Function<String, String> function) {
Path inputFilePath = Paths.get(input);
if (Files.exists(inputFilePath) && Files.isRegularFile(inputFilePath) && Files.isReadable(inputFilePath)) {
try {
Parameters params = new Parameters();
//
FileBasedConfigurationBuilder<PropertiesConfiguration> builder = //
new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class).configure(params.fileBased().setFile(//
inputFilePath.toFile()));
PropertiesConfiguration config = builder.getConfiguration();
mustBeModified.stream().filter(config::containsKey).forEach(key -> config.setProperty(key, function.apply(config.getString(key))));
builder.save();
} catch (ConfigurationException e) {
LOGGER.error("unable to read {} {}", input, e);
}
} else {
LOGGER.debug("No readable file at {}", input);
}
}
use of org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder 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);
}
}
use of org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder in project midpoint by Evolveum.
the class StartupConfiguration method createXmlConfiguration.
private void createXmlConfiguration(String filename) throws ConfigurationException {
Map<String, Lookup> lookups = new HashMap<>(ConfigurationInterpolator.getDefaultPrefixLookups());
lookups.put(RandomLookup.PREFIX, new RandomLookup());
lookups.put(HostnameLookup.PREFIX, new HostnameLookup());
FileBasedConfigurationBuilder<XMLConfiguration> builder = new FileBasedConfigurationBuilder<>(XMLConfiguration.class).configure(new Parameters().xml().setFileName(filename).setPrefixLookups(lookups));
/*
On debug level this shows stacktrace for:
DEBUG org.apache.commons.beanutils.FluentPropertyBeanIntrospector - Exception is:
java.beans.IntrospectionException: bad write method arg count:
public final void org.apache.commons.configuration2.AbstractConfiguration.setProperty
This is reportedly beanutils over-strictness issue but is nowhere close to be fixed.
Jira for commons-configuration can be also found, but they rely on beanutils fix.
*/
config = builder.getConfiguration();
config.addProperty(MIDPOINT_HOME_PROPERTY, midPointHomePath);
applyEnvironmentProperties();
resolveFileReferences();
}
use of org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder in project zeppelin by apache.
the class ZeppelinConfiguration method loadXMLConfig.
private void loadXMLConfig(@Nullable String filename) throws ConfigurationException {
if (StringUtils.isBlank(filename)) {
filename = ZEPPELIN_SITE_XML;
}
List<FileLocationStrategy> subs = Arrays.asList(new ZeppelinLocationStrategy(), new ClasspathLocationStrategy());
FileLocationStrategy strategy = new CombinedLocationStrategy(subs);
Parameters params = new Parameters();
FileBasedConfigurationBuilder<XMLConfiguration> xmlbuilder = new FileBasedConfigurationBuilder<XMLConfiguration>(XMLConfiguration.class).configure(params.xml().setLocationStrategy(strategy).setFileName(filename).setBasePath(File.separator + "conf" + File.separator));
XMLConfiguration xmlConfig = xmlbuilder.getConfiguration();
List<ImmutableNode> nodes = xmlConfig.getNodeModel().getRootNode().getChildren();
if (nodes != null && !nodes.isEmpty()) {
for (ImmutableNode p : nodes) {
String name = String.valueOf(p.getChildren("name").get(0).getValue());
String value = String.valueOf(p.getChildren("value").get(0).getValue());
if (StringUtils.isNotBlank(name) && StringUtils.isNotBlank(value)) {
setProperty(name, value);
}
}
}
}
Aggregations