Search in sources :

Example 1 with ConfigurationRuntimeException

use of org.apache.commons.configuration2.ex.ConfigurationRuntimeException 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)

Aggregations

XMLConfiguration (org.apache.commons.configuration2.XMLConfiguration)1 Parameters (org.apache.commons.configuration2.builder.fluent.Parameters)1 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)1 ConfigurationRuntimeException (org.apache.commons.configuration2.ex.ConfigurationRuntimeException)1