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

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

Introduction

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

Prototype

Iterator getKeys();

Source Link

Document

Get the list of the keys contained in the configuration.

Usage

From source file:org.sonar.batch.Batch.java

static Properties convertToProperties(Configuration configuration) {
    Properties props = new Properties();
    Iterator keys = configuration.getKeys();
    while (keys.hasNext()) {
        String key = (String) keys.next();
        // Configuration#getString() automatically splits strings by comma separator.
        String value = StringUtils.join(configuration.getStringArray(key), ",");
        props.setProperty(key, value);//from   w ww  .j a va2s. c o  m
    }
    return props;
}

From source file:org.sonar.jpa.session.AbstractDatabaseConnector.java

protected Properties getHibernateProperties() {
    Properties props = new Properties();
    if (transactionIsolation != null) {
        props.put("hibernate.connection.isolation", Integer.toString(transactionIsolation));
    }// w  w w  .ja  v a  2 s .  c  o  m
    props.put("hibernate.hbm2ddl.auto",
            getConfiguration().getString(DatabaseProperties.PROP_HIBERNATE_HBM2DLL, "validate"));
    props.put("hibernate.dialect", getDialectClass());

    props.put("hibernate.generate_statistics",
            getConfiguration().getBoolean(DatabaseProperties.PROP_HIBERNATE_GENERATE_STATISTICS, false));
    props.put("hibernate.show_sql", Boolean.valueOf(LOG_SQL.isInfoEnabled()).toString());

    Configuration subset = getConfiguration().subset("sonar.hibernate");
    for (Iterator keys = subset.getKeys(); keys.hasNext();) {
        String key = (String) keys.next();
        if (StringUtils.isNotBlank((String) subset.getProperty(key))) {
            props.put("hibernate." + key, subset.getProperty(key));
        }
    }

    // custom impl setup
    setupEntityManagerFactory(props);

    return props;
}

From source file:org.sonar.server.configuration.ConfigurationLogger.java

public static void log(Configuration configuration) {
    Logger log = LoggerFactory.getLogger(ConfigurationLogger.class);
    if (log.isDebugEnabled()) {
        Iterator<String> keys = configuration.getKeys();
        while (keys.hasNext()) {
            String key = keys.next();
            String property = getTruncatedProperty(configuration, key);
            log.debug("Property: " + key + " is: '" + property + "'");
        }//from  w w w .j  av a  2 s  .c o m
    }
}

From source file:org.sonar.server.database.JndiDatabaseConnector.java

private Reference createDatasourceReference() {
    try {//from  ww  w  . ja va2  s.c o  m
        Reference ref = new Reference(DataSource.class.getName(), UniqueDatasourceFactory.class.getName(),
                null);
        Configuration dsConfig = getConfiguration().subset("sonar.jdbc");
        for (Iterator<String> it = dsConfig.getKeys(); it.hasNext();) {
            String key = it.next();
            String value = dsConfig.getString(key);
            ref.add(new StringRefAddr(key, value));

            // backward compatibility
            if (value != null && key.equals("user")) {
                ref.add(new StringRefAddr("username", value));
            }
            if (value != null && key.equals("driver")) {
                ref.add(new StringRefAddr("driverClassName", value));
            }
        }
        return ref;
    } catch (Exception e) {
        throw new RuntimeException("Cannot create the JDBC datasource", e);
    }

}

From source file:org.w3.i18n.AssertionProvider.java

private static void interpretAssertionDefinitions(Configuration configuration) {
    // Find all prefixes.
    Set<String> prefixes = new TreeSet<>();
    Iterator<String> keyIterator = configuration.getKeys();
    while (keyIterator.hasNext()) {
        String key = keyIterator.next();
        String[] keySplit = key.split("\\.");
        boolean invalid = false;
        if (keySplit.length != 3) {
            invalid = true;/*from w ww .  j a  va 2s.c  om*/
        } else {
            if (keySplit[0].trim().isEmpty() || keySplit[1].trim().isEmpty() || keySplit[2].trim().isEmpty()
                    || (!keySplit[2].trim().equalsIgnoreCase("title")
                            && !keySplit[2].trim().equalsIgnoreCase("description"))) {
                invalid = true;
            } else {
                try {
                    Assertion.Level.valueOf(keySplit[1].trim().toUpperCase());
                } catch (IllegalArgumentException e) {
                    invalid = true;
                }
            }
        }
        if (invalid) {
            throw new RuntimeException("Invalid key in assertion" + " configuration. Keys should be of the form"
                    + " \"<assertion_id>.<assertion_level>." + "{title|description}\". Key: " + key
                    + ", configuration: " + configuration);

        }
        prefixes.add(keySplit[0] + "." + keySplit[1]);
    }
    for (String prefix : prefixes) {
        interpretAssertionDefinition(prefix, configuration);
    }
}

From source file:org.w3.i18n.I18nTestRunnerTest.java

private static Set<String> findPrefixes(Configuration configuration) {
    Set<String> prefixes = new TreeSet<>();
    Pattern prefixPattern = Pattern.compile("^[^;][^_]+_[^_]+");

    // Iterate through all keys in the configuration.
    Iterator<String> keyIterator = configuration.getKeys();
    while (keyIterator.hasNext()) {

        // Add the prefix of each key to the set.
        String key = keyIterator.next();
        Matcher prefixMatcher = prefixPattern.matcher(key);
        if (prefixMatcher.find()) {
            prefixes.add(prefixMatcher.group());
        }/*from w  w w .  java 2s  .c o  m*/
    }
    return prefixes;
}

From source file:org.wso2.andes.configuration.qpid.plugins.ConfigurationPlugin.java

/**
 * Sets the configuration for this plugin
 *
 * @param path//from  w w w. j av  a2  s.  c  o m
 * @param configuration the configuration for this plugin.
 */
public void setConfiguration(String path, Configuration configuration) throws ConfigurationException {
    _configuration = configuration;

    // Extract a list of elements for processing
    Iterator<?> keys = configuration.getKeys();

    Set<String> elements = new HashSet<String>();
    while (keys.hasNext()) {
        String key = (String) keys.next();

        int elementNameIndex = key.indexOf(".");

        String element = key.trim();
        if (elementNameIndex != -1) {
            element = key.substring(0, elementNameIndex).trim();
        }

        // Trim any element properties
        elementNameIndex = element.indexOf("[");
        if (elementNameIndex > 0) {
            element = element.substring(0, elementNameIndex).trim();
        }

        elements.add(element);
    }

    //Remove the items we already expect in the configuration
    for (String tag : getElementsProcessed()) {

        // Work round the issue with Commons configuration.
        // With an XMLConfiguration the key will be [@property]
        // but with a CompositeConfiguration it will be @property].
        // Hide this issue from our users so when/if we change the
        // configuration they don't have to. 
        int bracketIndex = tag.indexOf("[");
        if (bracketIndex != -1) {
            tag = tag.substring(bracketIndex + 1, tag.length());
        }

        elements.remove(tag);
    }

    if (_logger.isDebugEnabled()) {
        if (!elements.isEmpty()) {
            _logger.debug("Elements to lookup:" + path);
            for (String tag : elements) {
                _logger.debug("Tag:'" + tag + "'");
            }
        }
    }

    offerRemainingConfigurationToOtherPlugins(path, configuration, elements);

    validateConfiguration();
}

From source file:org.wso2.andes.configuration.qpid.ServerConfiguration.java

private static org.apache.commons.configuration.Configuration parseConfig(File file)
        throws ConfigurationException {
    ConfigurationFactory factory = new ConfigurationFactory();
    factory.setConfigurationFileName(file.getAbsolutePath());
    org.apache.commons.configuration.Configuration conf = factory.getConfiguration();

    Iterator<?> keys = conf.getKeys();
    if (!keys.hasNext()) {
        conf = flatConfig(file);//w w w.  ja  va2  s.  com
    }

    substituteEnvironmentVariables(conf);

    return conf;
}

From source file:org.wso2.andes.server.configuration.ServerConfiguration.java

private static Configuration parseConfig(File file) throws ConfigurationException {
    ConfigurationFactory factory = new ConfigurationFactory();
    factory.setConfigurationFileName(file.getAbsolutePath());
    Configuration conf = factory.getConfiguration();

    Iterator<?> keys = conf.getKeys();
    if (!keys.hasNext()) {
        keys = null;//www  . ja va  2s. co m
        conf = flatConfig(file);
    }

    substituteEnvironmentVariables(conf);

    return conf;
}

From source file:org.wso2.andes.server.store.SlowMessageStore.java

private void configureDelays(Configuration config) {
    Iterator delays = config.getKeys();

    while (delays.hasNext()) {
        String key = (String) delays.next();
        if (key.endsWith(PRE)) {
            _preDelays.put(key.substring(0, key.length() - PRE.length() - 1), config.getLong(key));
        } else if (key.endsWith(POST)) {
            _postDelays.put(key.substring(0, key.length() - POST.length() - 1), config.getLong(key));
        }/* www  . ja  v a 2s.  c o  m*/
    }
}