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

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

Introduction

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

Prototype

Iterator getKeys();

Source Link

Document

Get the list of the keys contained in the configuration.

Usage

From source file:gda.util.persistence.LocalParametersTest.java

private static List<Object> getKeysFromXMLConfiguration(FileConfiguration config) {
    List<Object> list = new Vector<Object>();
    Iterator<?> iterator = config.getKeys();
    while (iterator.hasNext()) {
        list.add(iterator.next());//from   www.  jav  a 2  s  .  c  om
    }
    return list;
}

From source file:com.twitter.distributedlog.config.ConfigurationSubscription.java

private void loadView(FileConfiguration fileConfig) {
    Iterator fileIter = fileConfig.getKeys();
    while (fileIter.hasNext()) {
        String key = (String) fileIter.next();
        setViewProperty(fileConfig, key, fileConfig.getProperty(key));
    }/*from  w  ww  . ja  v  a 2 s .c  om*/
}

From source file:halfpipe.properties.UrlPropertiesSource.java

private void loadConfig(Map<String, Object> map, FileConfiguration config) throws ConfigurationException {
    config.load();//from w w  w  . j a v  a 2s.  c  o m
    Iterator<String> keys = config.getKeys();
    while (keys.hasNext()) {
        String key = keys.next();
        map.put(key, config.getProperty(key));
    }
}

From source file:gda.jython.authoriser.FileAuthoriser.java

/**
 * @return Vector of strings of the entries in this file
 *///from  w  w  w  .  j  a  va 2  s  .c  o  m
public UserEntry[] getEntries() {
    try {
        FileConfiguration configFile = openConfigFile();
        UserEntry[] entries = new UserEntry[0];

        @SuppressWarnings("rawtypes")
        Iterator i = configFile.getKeys();
        while (i.hasNext()) {
            String username = (String) i.next();
            if (!username.equals("")) {
                int level = configFile.getInt(username);
                entries = (UserEntry[]) ArrayUtils.add(entries,
                        new UserEntry(username, level, isLocalStaff(username)));
            }
        }

        return entries;

    } catch (Exception e) {
        logger.error(
                "Exception while trying to read file of list of user authorisation levels:" + e.getMessage());
        return null;
    }

}

From source file:com.twitter.distributedlog.config.ConfigurationSubscription.java

@VisibleForTesting
void reload() {//www  .  j a  va2  s . co  m
    // No-op if already loaded.
    if (!initConfig()) {
        return;
    }
    // Reload if config exists.
    Set<String> confKeys = Sets.newHashSet();
    for (FileConfiguration fileConfig : fileConfigs) {
        LOG.debug("Check and reload config, file={}, lastModified={}", fileConfig.getFile(),
                fileConfig.getFile().lastModified());
        fileConfig.reload();
        // load keys
        Iterator keyIter = fileConfig.getKeys();
        while (keyIter.hasNext()) {
            String key = (String) keyIter.next();
            confKeys.add(key);
        }
    }
    // clear unexisted keys
    Iterator viewIter = viewConfig.getKeys();
    while (viewIter.hasNext()) {
        String key = (String) viewIter.next();
        if (!confKeys.contains(key)) {
            clearViewProperty(key);
        }
    }
    LOG.info("Reload features : {}", confKeys);
    // load keys from files
    for (FileConfiguration fileConfig : fileConfigs) {
        try {
            loadView(fileConfig);
        } catch (Exception ex) {
            if (!fileNotFound(ex)) {
                LOG.error("Config reload failed for file {}", fileConfig.getFileName(), ex);
            }
        }
    }
    for (ConfigurationListener listener : confListeners) {
        listener.onReload(viewConfig);
    }
}

From source file:openlr.mapviewer.coding.ui.AbstractCodingOptionsDialog.java

/**
 * Builds a configuration map from the given {@link FileConfiguration}. It is
 * assumed that the configuration contains of key with maximum nesting of
 * two levels. Each "topic" of parameters, i.e. parameters with the same
 * prefix, is stored in a map entry. The sub-keys configurations below the
 * topic parent represent the value to the key in form of a list of
 * key-value elements ({@link ConfigEntry}). If there is no nesting for a
 * configuration key the map key will be the original configuration key, the
 * value will be a {@link ConfigEntry} with again the property key as key
 * and the single value.//from  ww  w  .  java2 s.com
 * 
 * @param config
 *            The configuration to process
 * @return The configuration map
 */
private SortedMap<String, List<ConfigEntry>> buildConfigurationMap(final FileConfiguration config) {

    SortedMap<String, List<ConfigEntry>> map = new TreeMap<String, List<ConfigEntry>>();

    Iterator<?> iter = config.getKeys();
    while (iter.hasNext()) {

        String key = iter.next().toString();
        // skip all attributes in our case these are the XML attributes
        if (!key.startsWith("[@")) {

            String[] parts = key.split("\\.");
            String value = config.getString(key);

            if (parts.length == 2) {

                String topic = parts[0];
                String subKey = parts[1];

                List<ConfigEntry> subKeysAndValues = map.get(topic);
                if (subKeysAndValues == null) {
                    subKeysAndValues = new ArrayList<ConfigEntry>();
                    map.put(topic, subKeysAndValues);
                }

                subKeysAndValues.add(new ConfigEntry(key, subKey, value));
            } else if (parts.length == 1) {

                map.put(key, Arrays.asList(new ConfigEntry(key, key, value)));
            } else {
                throw new IllegalStateException(
                        "Unexpected format of OpenLR properties. Nesting level was assumed to be at most 2 but was "
                                + parts.length);
            }
        }
    }
    return map;
}