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

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

Introduction

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

Prototype

public Iterator getKeys() 

Source Link

Document

Returns an Iterator with the keys contained in this configuration.

Usage

From source file:fr.inria.atlanmod.neoemf.graph.blueprints.resources.BlueprintsResourceSaveTest.java

protected int getKeyCount(PropertiesConfiguration configuration) {
    @SuppressWarnings("unchecked")
    Iterator<String> keyIterator = configuration.getKeys();
    int keyCount = 0;
    while (keyIterator.hasNext()) {
        keyCount++;//from ww  w.jav  a 2s  . c o m
        keyIterator.next();
    }
    return keyCount;
}

From source file:com.astamuse.asta4d.web.initialization.SimplePropertyFileInitializer.java

@Override
public void initliaze(InputStream input, WebApplicationConfiguration configuration) throws Exception {
    PropertiesConfiguration pc = new PropertiesConfiguration();
    pc.load(input);/*from   w w  w.  j  a v a 2  s  . co m*/

    BeanUtilsBean bu = retrieveBeanUtilsBean();
    Iterator<String> keys = pc.getKeys();
    while (keys.hasNext()) {
        String key = keys.next();
        String value = pc.getString(key);
        fillConfiguration(configuration, bu, key, value);
    }

}

From source file:com.uber.stream.kafka.mirrormaker.manager.ManagerConf.java

public static ManagerConf getManagerConf(CommandLine cmd) {
    ManagerConf managerConf = new ManagerConf();
    if (cmd.hasOption("config")) {
        managerConf.setConfigFile(cmd.getOptionValue("config"));
    } else {//from  ww  w  .ja  va 2 s . com
        managerConf.setConfigFile("");
    }
    if (cmd.hasOption("srcClusters")) {
        managerConf.setSourceClusters(cmd.getOptionValue("srcClusters"));
    } else {
        managerConf.setSourceClusters("");
    }
    if (cmd.hasOption("destClusters")) {
        managerConf.setDestinationClusters(cmd.getOptionValue("destClusters"));
    } else {
        managerConf.setDestinationClusters("");
    }
    if (cmd.hasOption("enableRebalance")) {
        managerConf.setEnableRebalance(cmd.getOptionValue("enableRebalance"));
    } else {
        managerConf.setEnableRebalance(Boolean.toString(DEFAULT_ENABLE_REBALANCE));
    }
    if (cmd.hasOption("zookeeper")) {
        managerConf.setManagerZkStr(cmd.getOptionValue("zookeeper"));
    } else {
        throw new RuntimeException("Missing option: --zookeeper");
    }
    if (cmd.hasOption("managerPort")) {
        managerConf.setManagerPort(cmd.getOptionValue("managerPort"));
    } else {
        throw new RuntimeException("Missing option: --managerPort");
    }
    if (cmd.hasOption("deployment")) {
        managerConf.setManagerDeployment(cmd.getOptionValue("deployment"));
    } else {
        throw new RuntimeException("Missing option: --deployment");
    }
    if (cmd.hasOption("env")) {
        managerConf.setEnvironment(cmd.getOptionValue("env"));
    } else {
        throw new RuntimeException("Missing option: --env");
    }
    if (cmd.hasOption("instanceId")) {
        managerConf.setManagerInstanceId(cmd.getOptionValue("instanceId"));
    } else {
        try {
            managerConf.setManagerInstanceId(InetAddress.getLocalHost().getHostName());
        } catch (UnknownHostException e) {
            throw new RuntimeException("Missing option: --instanceId");
        }
    }
    if (cmd.hasOption("controllerPort")) {
        managerConf.setControllerPort(cmd.getOptionValue("controllerPort"));
    } else {
        throw new RuntimeException("Missing option: --controllerPort");
    }
    if (cmd.hasOption("graphiteHost")) {
        managerConf.setGraphiteHost(cmd.getOptionValue("graphiteHost"));
    }
    if (cmd.hasOption("graphitePort")) {
        managerConf.setGraphitePort(cmd.getOptionValue("graphitePort"));
    } else {
        managerConf.setGraphitePort("0");
    }
    if (cmd.hasOption("metricsPrefix")) {
        managerConf.setMetricsPrefix(cmd.getOptionValue("metricsPrefix"));
    } else {
        managerConf.setMetricsPrefix(DEFAULT_METRICS_PREFIX);
    }
    if (cmd.hasOption("c3Host")) {
        managerConf.setC3Host(cmd.getOptionValue("c3Host"));
    } else {
        managerConf.setC3Host(DEFAULT_C3_HOST);
    }
    if (cmd.hasOption("c3Port")) {
        managerConf.setC3Port(cmd.getOptionValue("c3Port"));
    } else {
        managerConf.setC3Port(Integer.toString(DEFAULT_C3_PORT));
    }
    if (cmd.hasOption("clusterPrefixLength")) {
        managerConf.setClusterPrefixLength(cmd.getOptionValue("clusterPrefixLength"));
    } else {
        managerConf.setClusterPrefixLength(Integer.toString(DEFAULT_CLUSTER_PREFIX_LENGTH));
    }
    if (cmd.hasOption("workloadRefreshPeriodInSeconds")) {
        managerConf.setWorkloadRefreshPeriodInSeconds(cmd.getOptionValue("workloadRefreshPeriodInSeconds"));
    } else {
        managerConf.setWorkloadRefreshPeriodInSeconds(
                Integer.toString(DEFAULT_WORKLOAD_REFRESH_PERIOD_IN_SECONDS));
    }
    if (cmd.hasOption("initMaxNumPartitionsPerRoute")) {
        managerConf.setInitMaxNumPartitionsPerRoute(cmd.getOptionValue("initMaxNumPartitionsPerRoute"));
    } else {
        managerConf
                .setInitMaxNumPartitionsPerRoute(Integer.toString(DEFAULT_INIT_MAX_NUM_PARTITIONS_PER_ROUTE));
    }
    if (cmd.hasOption("maxNumPartitionsPerRoute")) {
        managerConf.setMaxNumPartitionsPerRoute(cmd.getOptionValue("maxNumPartitionsPerRoute"));
    } else {
        managerConf.setMaxNumPartitionsPerRoute(Integer.toString(DEFAULT_MAX_NUM_PARTITIONS_PER_ROUTE));
    }
    if (cmd.hasOption("initMaxNumWorkersPerRoute")) {
        managerConf.setInitMaxNumWorkersPerRoute(cmd.getOptionValue("initMaxNumWorkersPerRoute"));
    } else {
        managerConf.setInitMaxNumWorkersPerRoute(Integer.toString(DEFAULT_INIT_MAX_NUM_WORKERS_PER_ROUTE));
    }
    if (cmd.hasOption("maxNumWorkersPerRoute")) {
        managerConf.setMaxNumWorkersPerRoute(cmd.getOptionValue("maxNumWorkersPerRoute"));
    } else {
        managerConf.setMaxNumWorkersPerRoute(Integer.toString(DEFAULT_MAX_NUM_WORKERS_PER_ROUTE));
    }
    if (cmd.hasOption("bytesPerSecondDefault")) {
        managerConf.setBytesPerSecondDefault(cmd.getOptionValue("bytesPerSecondDefault"));
    } else {
        managerConf.setBytesPerSecondDefault(Double.toString(DEFAULT_BYTES_PER_SECOND_DEFAULT));
    }
    if (cmd.hasOption("msgsPerSecondDefault")) {
        managerConf.setMsgsPerSecondDefault(cmd.getOptionValue("msgsPerSecondDefault"));
    } else {
        managerConf.setMsgsPerSecondDefault(Double.toString(DEFAULT_MSGS_PER_SECOND_DEFAULT));
    }
    if (cmd.hasOption("updateStatusCoolDownMs")) {
        managerConf.setUpdateStatusCoolDownMs(cmd.getOptionValue("updateStatusCoolDownMs"));
    } else {
        managerConf.setUpdateStatusCoolDownMs(Integer.toString(DEFAULT_UPDATE_STATUS_COOL_DOWN_MS));
    }

    if (cmd.hasOption("config")) {
        String fileName = cmd.getOptionValue("config");
        managerConf.setConfigFile(fileName);
        // load config from file
        PropertiesConfiguration configFromFile = new PropertiesConfiguration();
        configFromFile.setDelimiterParsingDisabled(true);
        try {
            configFromFile.load(fileName);
        } catch (ConfigurationException e) {
            throw new RuntimeException("Failed to load config from file " + fileName + ": " + e.getMessage());
        }
        // merge the config with command line. Option from command line has higher priority to override config from file
        @SuppressWarnings("unchecked")
        Iterator<String> keyIter = configFromFile.getKeys();
        while (keyIter.hasNext()) {
            String key = keyIter.next();
            if (!managerConf.containsKey(key)) {
                managerConf.addPropertyDirect(key, configFromFile.getProperty(key));
            }
        }
    } else {
        managerConf.setConfigFile("");
    }

    return managerConf;
}

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

private void checkDefaults(String file) {
    try {/*from  w w  w . jav  a  2 s .  c  o m*/
        PropertiesConfiguration defConfig = new PropertiesConfiguration(
                Utilities.getResource("byteswipe.properties"));
        Iterator<String> defKeys = defConfig.getKeys();

        //Add missing keys
        while (defKeys.hasNext()) {
            String key = defKeys.next();
            if (!config.containsKey(key)) {
                config.addProperty(key, defConfig.getProperty(key));
            }
        }

        config.save();
        //TODO: Handle exceptions
    } catch (ConfigurationException e) {
        e.printStackTrace();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
}

From source file:com.siemens.scr.avt.ad.query.common.MappingDictionaryTest.java

@Test
public void testLoadingFromHibernateMapping() throws JDOMException, IOException, ConfigurationException {
    DicomMappingDictionary dict = new DicomMappingDictionary();
    dict.loadFromHibernateMapping(mappingFile);

    PropertiesConfiguration config = new PropertiesConfiguration(expectedMappingFile);
    Map<String, MappingEntry> expected = new HashMap<String, MappingEntry>();
    Iterator it = config.getKeys();
    while (it.hasNext()) {
        String key = (String) it.next();

        List<String> list = config.getList(key);

        int type = Integer.parseInt(list.get(2));
        MappingEntry entry;/*from w  w w.  j a v  a2  s .  co  m*/
        if (type == java.sql.Types.OTHER) {
            entry = new WildcardEntry(list.get(0));
        } else {
            entry = new SimpleEntry(list.get(0), list.get(1), type);
        }
        expected.put(key, entry);
    }
    Map<String, MappingEntry> actual = dict.getDict();

    assertEquals(expected.size(), actual.size());

    for (String key : expected.keySet()) {
        assertEquals(expected.get(key), actual.get(key));
    }

}

From source file:com.siemens.scr.avt.ad.query.common.NaturalJoinTreeTest.java

@Test
public void testLoadingFromHibernateMapping() throws JDOMException, IOException, ConfigurationException {
    joinTree.loadFromHibernateMapping(this.getClass().getResourceAsStream(testMapping));

    PropertiesConfiguration config = new PropertiesConfiguration(expectedFK);
    HashMap<String, String[]> fks = new HashMap<String, String[]>();
    Iterator it = config.getKeys();
    while (it.hasNext()) {
        String key = (String) it.next();
        fks.put(key, config.getStringArray(key));
    }//from   w ww  .  ja  va2  s  .co m

    Set edges = getGraph().getEdges();

    assertEquals(fks.keySet().size(), edges.size());

    for (Object obj : edges) {
        NaturalFKEdge edge = (NaturalFKEdge) obj;
        assertEquals(fks.get(edge.getFK())[0], edge.getEndpoints().getFirst().toString());
        assertEquals(fks.get(edge.getFK())[1], edge.getEndpoints().getSecond().toString());
    }

}

From source file:com.carmatech.maven.MergeOperation.java

private void filter(final PropertiesConfiguration properties) {
    final Matcher variableMatcher = Pattern.compile(PATTERN_FOR_VARIABLE).matcher("");

    for (final Iterator<String> keys = properties.getKeys(); keys.hasNext();) {
        final String name = keys.next();
        final Object value = properties.getProperty(name);

        if (isVariable(value, variableMatcher)) {
            final String variableName = variableMatcher.group(INDEX_GROUP_VARIABLE_NAME);
            overrideIfNotNull(properties, name, variableName, "System", System.getProperty(variableName));
            overrideIfNotNull(properties, name, variableName, "Maven",
                    project.getProperties().getProperty(variableName));
            overrideIfNotNull(properties, name, variableName, "merged", properties.getProperty(variableName));
        }/*from   w ww .j  a v  a  2 s .c  o  m*/
    }
}

From source file:it.grid.storm.config.ConfigReader.java

public ConfigReader(String configurationPathname, int refresh) {

    if (configurationPathname != null) {
        if (refresh < 0)
            refresh = 0;//from ww  w .  jav  a 2  s.  c  o m
        this.refresh = refresh;
        this.configurationPathname = configurationPathname;
        log.info("Configuration file {}. Refresh rate: {} seconds", configurationPathname, refresh);

        try {
            FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy();
            strategy.setRefreshDelay(refresh);
            PropertiesConfiguration properties = new PropertiesConfiguration(configurationPathname);
            log.debug("Configuration properties:");
            String key;
            for (Iterator<?> i = properties.getKeys(); i.hasNext();) {
                key = (String) i.next();
                log.debug("{} = {}", key, properties.getProperty(key).toString());
            }
            properties.setReloadingStrategy(strategy);
            this.c = new CompositeConfiguration();
            ((CompositeConfiguration) this.c).addConfiguration(properties);
            log.info("Configuration read successfully.");
        } catch (ConfigurationException e) {
            this.c = makeEmptyConfiguration();
            log.error("Configuration parsing error: {}", e.getMessage(), e);
        }
    } else {
        throw new NullPointerException("Null configuration pathname.");
    }
}

From source file:ke.co.tawi.babblesms.server.servlet.util.PropertiesConfig.java

/**
 * Populate the internal HashMap which will hold configuration keys and values
 *///from   w w  w.  ja  v a2 s . c  o  m
private void initConfigHash() {
    PropertiesConfiguration config;
    String key;

    try {
        config = new PropertiesConfiguration();
        config.setListDelimiter('|'); // our array delimiter
        config.setFileName(configFile);
        config.load();

        Iterator<String> keys = config.getKeys();

        while (keys.hasNext()) {
            key = keys.next();
            configHash.put(key, (String) config.getProperty(key));
        }

    } catch (ConfigurationException e) {
        logger.error("ConfigurationException when trying to initialize configuration HashMap");
        logger.error(ExceptionUtils.getStackTrace(e));
    }
}

From source file:de.ingrid.portal.config.PortalConfig.java

private PortalConfig() throws Exception {
    super("ingrid-portal-apps.properties");
    //this.setReloadingStrategy(ReloadingStrategy)
    URL url = this.getClass().getResource("/ingrid-portal-apps.override.properties");
    if (url != null) {
        File f = new File(url.getPath());
        PropertiesConfiguration userConfig = new PropertiesConfiguration(f);
        Iterator<String> it = userConfig.getKeys();
        while (it.hasNext()) {
            String key = it.next();
            this.setProperty(key, userConfig.getProperty(key));
        }//from  ww w .j  a va2  s .  c o  m
    }
}