Example usage for org.apache.commons.configuration PropertiesConfiguration PropertiesConfiguration

List of usage examples for org.apache.commons.configuration PropertiesConfiguration PropertiesConfiguration

Introduction

In this page you can find the example usage for org.apache.commons.configuration PropertiesConfiguration PropertiesConfiguration.

Prototype

public PropertiesConfiguration(URL url) throws ConfigurationException 

Source Link

Document

Creates and loads the extended properties from the specified URL.

Usage

From source file:eu.ascetic.zabbixdatalogger.datasource.hostvmfilter.NamedList.java

/**
 * This creates a name filter that checks to see if the start of a host name
 * matches particular criteria or not. if it does then it will indicate
 * accordingly that the "Zabbix JSON API host" is a host or VM.
 *//*from www .  ja  v  a 2  s.  c om*/
public NamedList() {
    try {
        PropertiesConfiguration config;
        if (new File(CONFIG_FILE).exists()) {
            config = new PropertiesConfiguration(CONFIG_FILE);
        } else {
            config = new PropertiesConfiguration();
            config.setFile(new File(CONFIG_FILE));
        }
        config.setAutoSave(true); //This will save the configuration file back to disk. In case the defaults need setting.
        namedSet = config.getString("data.logger.filter.names", namedSet);
        config.setProperty("data.logger.filter.names", namedSet);
        hostNames.addAll(Arrays.asList(namedSet.split(",")));
    } catch (ConfigurationException ex) {
        Logger.getLogger(NameBeginsFilter.class.getName()).log(Level.INFO,
                "Error loading the configuration of the named list filter");
    }
}

From source file:net.audumla.util.ExpiringCacheTest.java

@Test
public void testPropertyLoad() throws ConfigurationException {
    Time.setNow(new Date());
    ExpiringMap ec = new ExpiringMap(new PropertiesConfiguration("cache.properties"));
    ec.add("default");
    ec.add("testCache.json");
    Time.setNow(Time.offset(Time.getNow(), 0, 0, 14));
    Assert.assertFalse(ec.hasDataExpired("testCache.json"));
    Assert.assertFalse(ec.hasDataExpired("default"));
    Time.setNow(Time.offset(Time.getNow(), 0, 0, 16));
    Assert.assertTrue(ec.hasDataExpired("testCache.json"));
    Assert.assertFalse(ec.hasDataExpired("default"));
}

From source file:de.anhquan.config4j.internal.ConfigHandler.java

public ConfigHandler(Class<?> configType) {
    this.configType = configType;
    ConfigContainer annotation = configType.getAnnotation(ConfigContainer.class);
    configLocation = annotation.Location();
    prefix = annotation.Prefix();//from w ww  .j  av a 2s . c  om

    try {
        configuration = new PropertiesConfiguration(configLocation);
    } catch (ConfigurationException e) {
        e.printStackTrace();
    }
}

From source file:dk.cubing.liveresults.uploader.configuration.Configuration.java

/**
 * @param engine//from   w ww  . j  a  va2s .co m
 */
public Configuration(ResultsEngine engine) {
    this.engine = engine;
    try {
        File configFile = new File(new File(".").getAbsolutePath() + "/conf/config.properties");
        if (!configFile.getCanonicalFile().exists()) {
            configFile = new File(ClassLoader.getSystemResource("config.properties").getFile());
        }
        log.debug("Config file: {}", configFile.getCanonicalFile());
        config = new PropertiesConfiguration(configFile.getCanonicalFile());
        config.setReloadingStrategy(new ResultsConfigReloadingStrategy(engine));
    } catch (Exception e) {
        log.error("Could not load configuration file", e);
        engine.shutdown();
    }
}

From source file:net.craigstars.app.config.CSHibernateConfigurer.java

public void configure(Configuration configuration) {
    try {// w  w  w  .  j a  v  a 2s.  c om
        // Reads an external file in the ~/bootstrap directory
        // This file contains all the hibernate credentials/driver for the current server.
        File cfgFile = new File(System.getProperty("user.home"), "bootstrap/cs.hibernate.cfg.properties");
        PropertiesConfiguration config = new PropertiesConfiguration(cfgFile.getAbsolutePath());
        Properties properties = new Properties();
        properties.put("hibernate.connection.driver_class", config.getProperty("driver"));
        properties.put("hibernate.connection.url", config.getProperty("url"));
        properties.put("hibernate.dialect", config.getProperty("dialect"));
        properties.put("hibernate.connection.username", config.getProperty("username"));
        properties.put("hibernate.connection.password", config.getProperty("password"));
        configuration.addProperties(properties);
    } catch (Exception ex) {
        throw new RuntimeException("Failed to load hibernate properties file", ex);
    }
}

From source file:com.linkedin.pinot.broker.broker.BrokerRequestValidationTest.java

/**
 * Setup method to start the broker. Stars the broker with
 * a query response limit of {@value QUERY_RESPONSE_LIMIT}
 * @return// w  w  w. j a v  a 2  s  .co  m
 * @throws Exception
 */
@BeforeClass
public BrokerServerBuilder setup() throws Exception {
    // Read default configurations.
    PropertiesConfiguration config = new PropertiesConfiguration(
            new File(BrokerServerBuilderTest.class.getClassLoader().getResource("broker.properties").toURI()));

    // Set the value for query response limit.
    config.addProperty(QUERY_RESPONSE_LIMIT_CONFIG, QUERY_RESPONSE_LIMIT);
    brokerBuilder = new BrokerServerBuilder(config, null, null, null);

    brokerBuilder.buildNetwork();
    brokerBuilder.buildHTTP();
    brokerBuilder.start();

    return brokerBuilder;
}

From source file:fr.jetoile.hadoopunit.test.hive.HiveConnectionUtils.java

private void loadConfig() throws ConfigException {
    try {/*w ww . ja va2  s.c  o m*/
        configuration = new PropertiesConfiguration(HadoopUnitConfig.DEFAULT_PROPS_FILE);
    } catch (ConfigurationException e) {
        throw new ConfigException("bad config", e);
    }

    port = configuration.getInt(HadoopUnitConfig.HIVE_SERVER2_PORT_KEY);
    host = configuration.getString(HadoopUnitConfig.HIVE_SERVER2_HOSTNAME_KEY);
    databaseName = configuration.getString(HadoopUnitConfig.HIVE_TEST_DATABASE_NAME_KEY);
}

From source file:com.cloudera.nav.sdk.client.ClientConfigFactory.java

/**
 * Create a PluginConfiguration from the properties contained in the
 * given filePath/*from   w  w  w  . j  av  a 2s . c  o  m*/
 *
 * @param filePath
 * @return
 */
public ClientConfig readConfigurations(String filePath) {
    try {
        PropertiesConfiguration props = new PropertiesConfiguration(filePath);
        ClientConfig config = new ClientConfig();
        config.setApplicationUrl(props.getString(APP_URL));
        config.setFormat(Format.valueOf(props.getString(FILE_FORMAT, Format.JSON.name())));
        config.setNamespace(props.getString(NAMESPACE));
        config.setNavigatorUrl(props.getString(NAV_URL));
        config.setApiVersion(props.getInt(API_VERSION));
        config.setUsername(props.getString(USERNAME));
        config.setPassword(props.getString(PASSWORD));
        config.setAutocommit(props.getBoolean(AUTOCOMMIT, false));
        config.setDisableSSLValidation(props.getBoolean(DISABLE_SSL_VALIDATION, false));
        config.setSSLTrustStoreLocation(props.getString(SSL_KEYSTORE_LOCATION, null));
        config.setSSLTrustStorePassword(props.getString(SSL_KEYSTORE_PASSWORD, null));
        return config;
    } catch (ConfigurationException e) {
        throw Throwables.propagate(e);
    }
}

From source file:com.shadwelldacunha.byteswipe.core.ConfigHandler.java

private void setup(String file) {
    this.file = file;
    try {//from w w w .j  a  v a2s. com
        config = new PropertiesConfiguration("byteswipe.properties");
    } catch (ConfigurationException e) {
        e.printStackTrace();
    }
}

From source file:com.arcbees.plugin.template.presenter.PresenterRemoteTest.java

@Test(expected = ConfigurationException.class)
public void testRemotePropertiesObjectFail() throws MalformedURLException, ConfigurationException {
    URL url = new URL(propertiesUrlPath);
    Configuration config = new PropertiesConfiguration(url + "fail");
}