use of org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder in project selenium-tests by Wikia.
the class XMLReader method getValue.
/**
* method used to get credentials from configuration xml
*/
public static String getValue(File file, String key) {
if (!file.exists() || file.isDirectory()) {
throw new ConfigurationRuntimeException("Cannot find a file with credentials");
}
try {
Parameters params = new Parameters();
FileBasedConfigurationBuilder<XMLConfiguration> builder = new FileBasedConfigurationBuilder<>(XMLConfiguration.class).configure(params.fileBased().setFile(file));
org.apache.commons.configuration2.Configuration config = builder.getConfiguration();
return config.getString(key);
} catch (ConfigurationException e) {
throw new ConfigurationRuntimeException(e);
}
}
use of org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder in project vcell by virtualcell.
the class VCellConfiguration method getConfiguration.
private static synchronized Configuration getConfiguration() throws ConfigurationException {
if (configurationBuilder == null) {
Parameters params = new Parameters();
File propertiesFile = new File(ResourceUtil.getVcellHome(), "vcellconfig.properties");
if (!propertiesFile.exists()) {
try {
propertiesFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
FileBasedBuilderParameters thing = params.fileBased().setFile(propertiesFile);
configurationBuilder = new FileBasedConfigurationBuilder<PropertiesConfiguration>(PropertiesConfiguration.class).configure(thing);
configurationBuilder.setAutoSave(true);
try {
propertiesConfiguration = configurationBuilder.getConfiguration();
propertiesConfiguration.setSynchronizer(new ReadWriteSynchronizer());
} catch (org.apache.commons.configuration2.ex.ConfigurationException e) {
e.printStackTrace();
throw new ConfigurationException("failed to create configuration from file " + propertiesFile + ": " + e.getMessage());
}
}
return propertiesConfiguration;
}
use of org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder in project janusgraph by JanusGraph.
the class ConfigurationUtil method loadPropertiesConfig.
private static PropertiesConfiguration loadPropertiesConfig(PropertiesBuilderParameters params, boolean setCommaDelimiterHandler) throws ConfigurationException {
FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<PropertiesConfiguration>(PropertiesConfiguration.class);
PropertiesBuilderParameters newParams = params;
if (setCommaDelimiterHandler) {
newParams = newParams.setListDelimiterHandler(COMMA_DELIMITER_HANDLER);
}
return builder.configure(newParams).getConfiguration();
}
use of org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder in project scheduling by ow2-proactive.
the class NodeCommandLineProperties method loadConfig.
/**
* loads NodeSource configuration.
*
* @return NodeSource configuration
*/
public static Configuration loadConfig() throws ConfigurationException {
Configuration config;
File propertiesFile = new File(NodeCommandLineProperties.class.getClassLoader().getResource(PROPERTIES_FILE).getFile());
PropertiesBuilderParameters propertyParameters = new Parameters().properties();
propertyParameters.setFile(propertiesFile);
propertyParameters.setThrowExceptionOnMissing(true);
propertyParameters.setListDelimiterHandler(DELIMITER);
FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<>(PropertiesConfiguration.class);
builder.configure(propertyParameters);
config = builder.getConfiguration();
LOGGER.debug("NodeSources configuration loaded");
return config;
}
use of org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder in project ranger by apache.
the class LdapConfig method updateInputPropFile.
public void updateInputPropFile(String ldapUrl, String bindDn, String bindPassword, String userSearchBase, String userSearchFilter, String authUser, String authPass) {
try {
Parameters params = new Parameters();
FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class).configure(params.fileBased().setFileName(CONFIG_FILE));
FileBasedConfiguration config = builder.getConfiguration();
// Update properties in memory and update the file as well
prop.setProperty(LGSYNC_LDAP_URL, ldapUrl);
prop.setProperty(LGSYNC_LDAP_BIND_DN, bindDn);
prop.setProperty(LGSYNC_LDAP_BIND_PASSWORD, bindPassword);
prop.setProperty(LGSYNC_USER_SEARCH_BASE, userSearchBase);
prop.setProperty(LGSYNC_USER_SEARCH_FILTER, userSearchFilter);
prop.setProperty(AUTH_USERNAME, authUser);
prop.setProperty(AUTH_PASSWORD, authPass);
config.setProperty(LGSYNC_LDAP_URL, ldapUrl);
config.setProperty(LGSYNC_LDAP_BIND_DN, bindDn);
// config.setProperty(LGSYNC_LDAP_BIND_PASSWORD, bindPassword);
config.setProperty(LGSYNC_USER_SEARCH_BASE, userSearchBase);
config.setProperty(LGSYNC_USER_SEARCH_FILTER, userSearchFilter);
config.setProperty(AUTH_USERNAME, authUser);
// config.setProperty(AUTH_PASSWORD, authPass);
builder.save();
} catch (ConfigurationException e) {
System.out.println("Failed to update " + CONFIG_FILE + ": " + e);
}
}
Aggregations