use of org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder 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.FileBasedConfigurationBuilder 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.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 xwiki-platform by xwiki.
the class XWikiPropertiesConfigurationSource method loadConfiguration.
private Configuration loadConfiguration() {
// Looking for /etc/xwiki/xwiki.properties first
File file = new File("/etc/xwiki/" + XWIKI_PROPERTIES_FILE);
if (file.exists()) {
try {
return new Configurations().properties(file);
} catch (Exception e) {
// Note: if we cannot read the configuration file for any reason we log a warning but continue since
// XWiki will use default values for all configurable elements.
this.logger.warn("Failed to load configuration file [{}]", file, e.getMessage());
}
}
// Register the Commons Properties Configuration, looking for a xwiki.properties file
// in the XWiki path somewhere.
URL xwikiPropertiesUrl = null;
try {
xwikiPropertiesUrl = this.environment.getResource(XWIKI_PROPERTIES_WARPATH);
if (xwikiPropertiesUrl != null) {
FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<PropertiesConfiguration>(PropertiesConfiguration.class).configure(new Parameters().properties().setListDelimiterHandler(new DefaultListDelimiterHandler(',')).setURL(xwikiPropertiesUrl));
return builder.getConfiguration();
} else {
// We use a debug logging level here since we consider it's ok that there's no XWIKI_PROPERTIES_FILE
// available, in which case default values are used.
this.logger.debug("No configuration file [{}] found. Using default configuration values.", XWIKI_PROPERTIES_WARPATH);
}
} catch (Exception e) {
// Note: if we cannot read the configuration file for any reason we log a warning but continue since XWiki
// will use default values for all configurable elements.
this.logger.warn("Failed to load configuration file [{}]. Using default configuration values. " + "Internal error [{}]", XWIKI_PROPERTIES_WARPATH, e.getMessage());
}
// implementation.
return new BaseConfiguration();
}
use of org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder in project activemq-artemis by apache.
the class ArtemisTest method checkRole.
private void checkRole(String user, File roleFile, String... roles) throws Exception {
Configurations configs = new Configurations();
FileBasedConfigurationBuilder<PropertiesConfiguration> roleBuilder = configs.propertiesBuilder(roleFile);
PropertiesConfiguration roleConfig = roleBuilder.getConfiguration();
for (String r : roles) {
String storedUsers = (String) roleConfig.getProperty(r);
System.out.println("users in role: " + r + " ; " + storedUsers);
List<String> userList = StringUtil.splitStringList(storedUsers, ",");
assertTrue(userList.contains(user));
}
}
Aggregations