Search in sources :

Example 6 with FileBasedConfigurationBuilder

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);
    }
}
Also used : XMLConfiguration(org.apache.commons.configuration2.XMLConfiguration) ConfigurationRuntimeException(org.apache.commons.configuration2.ex.ConfigurationRuntimeException) Parameters(org.apache.commons.configuration2.builder.fluent.Parameters) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException)

Example 7 with FileBasedConfigurationBuilder

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;
}
Also used : Parameters(org.apache.commons.configuration2.builder.fluent.Parameters) FileBasedBuilderParameters(org.apache.commons.configuration2.builder.fluent.FileBasedBuilderParameters) FileBasedConfigurationBuilder(org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder) ConfigurationException(org.vcell.util.ConfigurationException) FileBasedBuilderParameters(org.apache.commons.configuration2.builder.fluent.FileBasedBuilderParameters) ReadWriteSynchronizer(org.apache.commons.configuration2.sync.ReadWriteSynchronizer) IOException(java.io.IOException) File(java.io.File)

Example 8 with FileBasedConfigurationBuilder

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();
}
Also used : FileBasedConfigurationBuilder(org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder) PropertiesBuilderParameters(org.apache.commons.configuration2.builder.fluent.PropertiesBuilderParameters) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

Example 9 with FileBasedConfigurationBuilder

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;
}
Also used : Parameters(org.apache.commons.configuration2.builder.fluent.Parameters) PropertiesBuilderParameters(org.apache.commons.configuration2.builder.fluent.PropertiesBuilderParameters) FileBasedConfigurationBuilder(org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration) Configuration(org.apache.commons.configuration2.Configuration) PropertiesBuilderParameters(org.apache.commons.configuration2.builder.fluent.PropertiesBuilderParameters) File(java.io.File) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

Example 10 with FileBasedConfigurationBuilder

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);
    }
}
Also used : Parameters(org.apache.commons.configuration2.builder.fluent.Parameters) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) FileBasedConfiguration(org.apache.commons.configuration2.FileBasedConfiguration) PropertiesConfiguration(org.apache.commons.configuration2.PropertiesConfiguration)

Aggregations

Parameters (org.apache.commons.configuration2.builder.fluent.Parameters)11 PropertiesConfiguration (org.apache.commons.configuration2.PropertiesConfiguration)8 XMLConfiguration (org.apache.commons.configuration2.XMLConfiguration)5 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)5 File (java.io.File)4 FileBasedConfigurationBuilder (org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder)4 Configurations (org.apache.commons.configuration2.builder.fluent.Configurations)3 IOException (java.io.IOException)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 Configuration (org.apache.commons.configuration2.Configuration)2 FileBasedConfiguration (org.apache.commons.configuration2.FileBasedConfiguration)2 PropertiesBuilderParameters (org.apache.commons.configuration2.builder.fluent.PropertiesBuilderParameters)2 DefaultListDelimiterHandler (org.apache.commons.configuration2.convert.DefaultListDelimiterHandler)2 Lookup (org.apache.commons.configuration2.interpol.Lookup)2 HostnameLookup (com.evolveum.midpoint.init.interpol.HostnameLookup)1 RandomLookup (com.evolveum.midpoint.init.interpol.RandomLookup)1 URL (java.net.URL)1 Path (java.nio.file.Path)1 SneakyThrows (lombok.SneakyThrows)1 HashProcessor (org.apache.activemq.artemis.utils.HashProcessor)1