Example usage for org.apache.commons.configuration Configuration getString

List of usage examples for org.apache.commons.configuration Configuration getString

Introduction

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

Prototype

String getString(String key);

Source Link

Document

Get a string associated with the given configuration key.

Usage

From source file:com.appeligo.channelfeed.CaptureApp.java

private void configureLogging(Configuration config, PatternLayout pattern) {
    Logger.getRootLogger().setLevel(Level.WARN);
    String logEmail = config.getString("logEmail[@address]");
    if ((logEmail == null) || (logEmail.trim().length() == 0)) {
        logEmail = "root@localhost";
    }/*  w w w.  ja va  2 s .c o m*/
    log.info("logEmail = " + logEmail);
    configureFatalLogging(pattern, logEmail);

    int loggerCount = config.getList("loggers.logger[@name]").size();

    for (int i = 0; i < loggerCount; i++) {
        Configuration logger = config.subset("loggers.logger(" + i + ")");
        String loggerName = logger.getString("[@name]");
        String loggerLevel = logger.getString("[@level]");
        log.info("Setting logger " + loggerName + " to level " + loggerLevel);
        Logger newlog = Logger.getLogger(loggerName);
        Level level = Level.toLevel(loggerLevel, null);
        if (level == null) {
            log.error("Invalid log level '" + loggerLevel + "' in: " + configFile);
        } else {
            newlog.setLevel(level);
        }
    }
}

From source file:com.kixeye.chassis.bootstrap.ConfigurationBuilderTest.java

@Test
public void defaultModuleConfigurations() {
    Configuration configuration = configurationBuilder.build();

    Assert.assertEquals(MODULE_1_VALUE_1, configuration.getString(MODULE_1_KEY_1));
    Assert.assertEquals(MODULE_1_VALUE_2, configuration.getString(MODULE_1_KEY_2));
    Assert.assertEquals(MODULE_1_VALUE_3, configuration.getString(MODULE_1_KEY_3));
}

From source file:com.linkedin.pinot.routing.builder.LargeClusterRoutingTableBuilder.java

@Override
public void init(Configuration configuration) {
    // TODO jfim This is a broker-level configuration for now, until we refactor the configuration of the routing table to allow per-table routing settings
    if (configuration.containsKey("offlineTargetServerCountPerQuery")) {
        final String targetServerCountPerQuery = configuration.getString("offlineTargetServerCountPerQuery");
        try {// w  w w  . j  a  v  a 2 s.  c o  m
            TARGET_SERVER_COUNT_PER_QUERY = Integer.parseInt(targetServerCountPerQuery);
            LOGGER.info("Using offline target server count of {}", TARGET_SERVER_COUNT_PER_QUERY);
        } catch (Exception e) {
            LOGGER.warn(
                    "Could not get the offline target server count per query from configuration value {}, keeping default value {}",
                    targetServerCountPerQuery, TARGET_SERVER_COUNT_PER_QUERY, e);
        }
    } else {
        LOGGER.info("Using default value for offline target server count of {}", TARGET_SERVER_COUNT_PER_QUERY);
    }
}

From source file:com.processpuzzle.application.configuration.domain.PropertyContext.java

public Properties getProperties(String key) {
    Configuration subConfiguration = configuration.configurationAt(key);
    Properties properties = new Properties();
    for (Iterator<?> iter = subConfiguration.getKeys(); iter.hasNext();) {
        String propertyKey = (String) iter.next();
        String propertyValue = subConfiguration.getString(propertyKey);
        properties.put(propertyKey.replace('/', '.'), propertyValue);
    }//from w  w w.  jav a  2 s. c om
    return properties;
}

From source file:com.kixeye.chassis.bootstrap.ConfigurationBuilderTest.java

@Test
public void zookeeperHappy() throws Exception {
    String key = ZOOKEEPER_CONFIG_ROOT + "/" + MODULE_1_KEY_1;
    curatorFramework.create().creatingParentsIfNeeded().forPath(key, MODULE_1_VALUE_1.getBytes());
    Assert.assertEquals(MODULE_1_VALUE_1, new String(curatorFramework.getData().forPath(key)));

    configurationBuilder/*from w w w  .j  a  va2s.c om*/
            .withConfigurationProvider(new ZookeeperConfigurationProvider(zookeeperServer.getConnectString()));
    Configuration configuration = configurationBuilder.build();

    Assert.assertEquals(MODULE_1_VALUE_1, configuration.getString(MODULE_1_KEY_1));
}

From source file:com.appeligo.captions.CaptionListener.java

/**
 * /* www.ja v a  2 s .c  o m*/
 *
 */
@SuppressWarnings("unchecked")
public CaptionListener() throws MalformedURLException {
    if (log.isInfoEnabled()) {
        log.info("Instantiated a " + this.getClass().getName());
    }
    Configuration config = ConfigUtils.getSystemConfig();
    programIndexLocation = config.getString("luceneIndex");
    compositeIndexLocation = config.getString("compositeIndex");
    liveIndexLocation = config.getString("luceneLiveIndex");
    liveLineup = config.getString("liveLineup");

    //Set the optimization duraction of the live index to 30 minutes.
    int liveIndexOptimization = config.getInt("luceneLiveIndexOptimization", 30);
    LuceneIndexer liveIndex = LuceneIndexer.getInstance(liveIndexLocation);
    liveIndex.setOptimizeDuration(liveIndexOptimization);
    epg = DefaultEpg.getInstance();
    captions = new HashMap<String, ProgramCaptions>();
    //PENDING(CE): We should probably get this list form the EPG?  Seems like we should.
    Configuration lineupConfiguration = ConfigurationService.getConfiguration("lineups");
    lineupIds = (List<String>) lineupConfiguration.getList("lineups.lineup.id");

    DeleteOldProgramsThread.startThread();
}

From source file:com.kixeye.chassis.bootstrap.ConfigurationBuilderTest.java

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test/*from ww w  .  j a  v  a  2 s. co  m*/
public void applicationConfigurations() {
    TestUtils.writePropertiesToFile(TEST_APP_CONFIG_PROPERTIES, filesCreated,
            new SimpleEntry(MODULE_1_KEY_3, MODULE_1_VALUE_3 + "-override"));

    configurationBuilder.withApplicationProperties("file://" + TEST_APP_CONFIG_PROPERTIES);
    Configuration configuration = configurationBuilder.build();

    Assert.assertEquals(MODULE_1_VALUE_1, configuration.getString(MODULE_1_KEY_1));
    Assert.assertEquals(MODULE_1_VALUE_2, configuration.getString(MODULE_1_KEY_2));
    Assert.assertEquals(MODULE_1_VALUE_3 + "-override", configuration.getString(MODULE_1_KEY_3));
}

From source file:com.kixeye.chassis.bootstrap.ConfigurationBuilderTest.java

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test(expected = ResourceLoadingException.class)
public void invalidApplicationConfigurationPath() {
    TestUtils.writePropertiesToFile(TEST_APP_CONFIG_PROPERTIES, filesCreated,
            new SimpleEntry(MODULE_1_KEY_3, MODULE_1_VALUE_3 + "-override"));

    configurationBuilder.withApplicationProperties("file://" + TEST_APP_CONFIG_PROPERTIES + ".foo");
    Configuration configuration = configurationBuilder.build();

    Assert.assertEquals(MODULE_1_VALUE_1, configuration.getString(MODULE_1_KEY_1));
    Assert.assertEquals(MODULE_1_VALUE_2, configuration.getString(MODULE_1_KEY_2));
    Assert.assertEquals(MODULE_1_VALUE_3 + "-override", configuration.getString(MODULE_1_KEY_3));
}

From source file:com.kixeye.chassis.bootstrap.ConfigurationBuilderTest.java

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test//  w  w  w . j  a  v a 2s. com
public void applicationConfigurationsWithEnvironmentConfiguration() {
    TestUtils.writePropertiesToFile(TEST_APP_CONFIG_PROPERTIES, filesCreated,
            new SimpleEntry(MODULE_1_KEY_2, MODULE_1_VALUE_2 + "-override"),
            new SimpleEntry(MODULE_1_KEY_3, MODULE_1_VALUE_3 + "-override"));
    TestUtils.writePropertiesToFile(
            TEST_APP_CONFIG_PROPERTIES.replace(".properties", "." + ENVIRONMENT + ".properties"), filesCreated,
            new SimpleEntry(MODULE_1_KEY_2, MODULE_1_VALUE_2 + "-override"));

    configurationBuilder.withApplicationProperties("file://" + TEST_APP_CONFIG_PROPERTIES);
    Configuration configuration = configurationBuilder.build();

    Assert.assertEquals(MODULE_1_VALUE_1, configuration.getString(MODULE_1_KEY_1));
    Assert.assertEquals(MODULE_1_VALUE_2 + "-override", configuration.getString(MODULE_1_KEY_2));
    Assert.assertEquals(MODULE_1_VALUE_3 + "-override", configuration.getString(MODULE_1_KEY_3));
}

From source file:es.udc.gii.common.eaf.plugin.parameter.LinearAnnealing.java

@Override
public void configure(Configuration conf) {
    if (conf.containsKey("A")) {
        this.a = conf.getDouble("A");
    }/*from  w w  w.  jav  a 2 s  .c om*/
    if (conf.containsKey("B")) {
        this.b = conf.getDouble("B");
    }
    if (conf.containsKey("C")) {
        this.c = conf.getDouble("C");
    }
    try {
        if (conf.containsKey("Counter.Class")) {
            this.counter = (StopTestPlugin) Class.forName(conf.getString("Counter.Class")).newInstance();
            this.counter.configure(conf.subset("Counter"));
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}