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:eu.scape_project.planning.repository.RODAConnector.java

/**
 * Loads the config file and exposes it as a Map.
 * /*from w  w w  . j a  va 2  s  .co  m*/
 * @return the map of properties.
 */
private Map<String, String> loadConfig() {
    if (this.config != null) {
        return this.config;
    }

    ConfigurationLoader configurationLoader = new ConfigurationLoader();
    Configuration configuration = configurationLoader.load();
    if (configuration == null) {
        LOGGER.warn("An error occurred while reading the properties file.");
        return new HashMap<String, String>();
    }

    Map<String, String> map = new HashMap<String, String>();
    Iterator<String> configIt = configuration.getKeys();
    while (configIt.hasNext()) {
        String key = configIt.next();
        map.put(key, configuration.getString(key));
    }

    return map;
}

From source file:com.evolveum.midpoint.wf.impl.WfConfiguration.java

public void checkAllowedKeys(Configuration c, List<String> knownKeys, List<String> deprecatedKeys) {
    Set<String> knownKeysSet = new HashSet<>(knownKeys);
    Set<String> deprecatedKeysSet = new HashSet<>(deprecatedKeys);

    Iterator<String> keyIterator = c.getKeys();
    while (keyIterator.hasNext()) {
        String keyName = keyIterator.next();
        String normalizedKeyName = StringUtils.substringBefore(keyName, "."); // because of subkeys
        normalizedKeyName = StringUtils.substringBefore(normalizedKeyName, "["); // because of [@xmlns:c]
        int colon = normalizedKeyName.indexOf(':'); // because of c:generalChangeProcessorConfiguration
        if (colon != -1) {
            normalizedKeyName = normalizedKeyName.substring(colon + 1);
        }/*from   ww w .  j  a  va  2  s .  co m*/
        if (deprecatedKeysSet.contains(keyName) || deprecatedKeysSet.contains(normalizedKeyName)) {
            throw new SystemException("Deprecated key " + keyName
                    + " in workflow configuration. Please see https://wiki.evolveum.com/display/midPoint/Workflow+configuration.");
        }
        if (!knownKeysSet.contains(keyName) && !knownKeysSet.contains(normalizedKeyName)) { // ...we need to test both because of keys like 'midpoint.home'
            throw new SystemException("Unknown key " + keyName + " in workflow configuration");
        }
    }
}

From source file:com.boozallen.cognition.ingest.storm.topology.ConfigurableIngestTopology.java

protected void configureStorm(Configuration conf, Config stormConf) throws IllegalAccessException {
    stormConf.registerSerialization(LogRecord.class);
    //stormConf.registerSerialization(Entity.class);
    stormConf.registerMetricsConsumer(LoggingMetricsConsumer.class);

    for (Iterator<String> iter = conf.getKeys(); iter.hasNext();) {
        String key = iter.next();

        String keyString = key.toString();
        String cleanedKey = keyString.replaceAll("\\.\\.", ".");

        String schemaFieldName = cleanedKey.replaceAll("\\.", "_").toUpperCase() + "_SCHEMA";
        Field field = FieldUtils.getField(Config.class, schemaFieldName);
        Object fieldObject = field.get(null);

        if (fieldObject == Boolean.class)
            stormConf.put(cleanedKey, conf.getBoolean(keyString));
        else if (fieldObject == String.class)
            stormConf.put(cleanedKey, conf.getString(keyString));
        else if (fieldObject == ConfigValidation.DoubleValidator)
            stormConf.put(cleanedKey, conf.getDouble(keyString));
        else if (fieldObject == ConfigValidation.IntegerValidator)
            stormConf.put(cleanedKey, conf.getInt(keyString));
        else if (fieldObject == ConfigValidation.PowerOf2Validator)
            stormConf.put(cleanedKey, conf.getLong(keyString));
        else if (fieldObject == ConfigValidation.StringOrStringListValidator)
            stormConf.put(cleanedKey, Arrays.asList(conf.getStringArray(keyString)));
        else if (fieldObject == ConfigValidation.StringsValidator)
            stormConf.put(cleanedKey, Arrays.asList(conf.getStringArray(keyString)));
        else {//w ww .j a  v  a2 s  .co  m
            logger.error(
                    "{} cannot be configured from XML. Consider configuring in navie storm configuration.");
            throw new UnsupportedOperationException(cleanedKey + " cannot be configured from XML");
        }
    }
}

From source file:com.cisco.oss.foundation.http.netlifx.netty.NettyNetflixHttpClient.java

private InternalServerProxyMetadata loadServersMetadataConfiguration() {

    Configuration subset = ConfigurationFactory.getConfiguration().subset(getApiName());
    final Iterator<String> keysIterator = subset.getKeys();

    // read default values
    int readTimeout = subset.getInt("http." + LoadBalancerConstants.READ_TIME_OUT,
            LoadBalancerConstants.DEFAULT_READ_TIMEOUT);
    int connectTimeout = subset.getInt("http." + LoadBalancerConstants.CONNECT_TIME_OUT,
            LoadBalancerConstants.DEFAULT_CONNECT_TIMEOUT);
    long waitingTime = subset.getLong("http." + LoadBalancerConstants.WAITING_TIME,
            LoadBalancerConstants.DEFAULT_WAITING_TIME);
    int numberOfAttempts = subset.getInt("http." + LoadBalancerConstants.NUMBER_OF_ATTEMPTS,
            LoadBalancerConstants.DEFAULT_NUMBER_OF_ATTEMPTS);
    long retryDelay = subset.getLong("http." + LoadBalancerConstants.RETRY_DELAY,
            LoadBalancerConstants.DEFAULT_RETRY_DELAY);

    long idleTimeout = subset.getLong("http." + LoadBalancerConstants.IDLE_TIME_OUT,
            LoadBalancerConstants.DEFAULT_IDLE_TIMEOUT);
    int maxConnectionsPerAddress = subset.getInt("http." + LoadBalancerConstants.MAX_CONNECTIONS_PER_ADDRESS,
            LoadBalancerConstants.DEFAULT_MAX_CONNECTIONS_PER_ADDRESS);
    int maxConnectionsTotal = subset.getInt("http." + LoadBalancerConstants.MAX_CONNECTIONS_TOTAL,
            LoadBalancerConstants.DEFAULT_MAX_CONNECTIONS_TOTAL);
    int maxQueueSizePerAddress = subset.getInt("http." + LoadBalancerConstants.MAX_QUEUE_PER_ADDRESS,
            LoadBalancerConstants.DEFAULT_MAX_QUEUE_PER_ADDRESS);
    boolean followRedirects = subset.getBoolean("http." + LoadBalancerConstants.FOLLOW_REDIRECTS, false);
    boolean disableCookies = subset.getBoolean("http." + LoadBalancerConstants.DISABLE_COOKIES, false);
    boolean autoCloseable = subset.getBoolean("http." + LoadBalancerConstants.AUTO_CLOSEABLE, true);
    boolean autoEncodeUri = subset.getBoolean("http." + LoadBalancerConstants.AUTO_ENCODE_URI, true);
    boolean staleConnectionCheckEnabled = subset
            .getBoolean("http." + LoadBalancerConstants.IS_STALE_CONN_CHECK_ENABLED, false);
    boolean serviceDirectoryEnabled = subset
            .getBoolean("http." + LoadBalancerConstants.SERVICE_DIRECTORY_IS_ENABLED, false);
    String serviceName = subset.getString("http." + LoadBalancerConstants.SERVICE_DIRECTORY_SERVICE_NAME,
            "UNKNOWN");

    String keyStorePath = subset.getString("http." + LoadBalancerConstants.KEYSTORE_PATH, "");
    String keyStorePassword = subset.getString("http." + LoadBalancerConstants.KEYSTORE_PASSWORD, "");
    String trustStorePath = subset.getString("http." + LoadBalancerConstants.TRUSTSTORE_PATH, "");
    String trustStorePassword = subset.getString("http." + LoadBalancerConstants.TRUSTSTORE_PASSWORD, "");
    startEurekaClient = subset.getBoolean("http.startEurekaClient", true);

    final List<String> keys = new ArrayList<String>();

    while (keysIterator.hasNext()) {
        String key = keysIterator.next();
        keys.add(key);//from  ww  w. ja  v  a  2s .  c o m
    }

    Collections.sort(keys);

    List<Pair<String, Integer>> hostAndPortPairs = new CopyOnWriteArrayList<Pair<String, Integer>>();

    for (String key : keys) {

        if (key.contains(LoadBalancerConstants.HOST)) {

            String host = subset.getString(key);

            // trim the host name
            if (org.apache.commons.lang.StringUtils.isNotEmpty(host)) {
                host = host.trim();
            }
            final String portKey = key.replace(LoadBalancerConstants.HOST, LoadBalancerConstants.PORT);
            if (subset.containsKey(portKey)) {
                int port = subset.getInt(portKey);
                // save host and port for future creation of server list
                hostAndPortPairs.add(Pair.of(host, port));
            }
        }

    }

    InternalServerProxyMetadata metadata = new InternalServerProxyMetadata(readTimeout, connectTimeout,
            idleTimeout, maxConnectionsPerAddress, maxConnectionsTotal, maxQueueSizePerAddress, waitingTime,
            numberOfAttempts, retryDelay, hostAndPortPairs, keyStorePath, keyStorePassword, trustStorePath,
            trustStorePassword, followRedirects, autoCloseable, staleConnectionCheckEnabled, disableCookies,
            serviceDirectoryEnabled, serviceName, autoEncodeUri);

    return metadata;

}

From source file:com.cisco.oss.foundation.logging.FoundationLoggerConfiguration.java

private void initLoggers(org.apache.commons.configuration.Configuration loggerSubset) {
    Iterator<String> keys = loggerSubset.getKeys();
    List<LoggerConfig> loggerConfigs = new ArrayList<LoggerConfig>();
    while (keys.hasNext()) {
        String key = keys.next();
        String name = "";
        String level = "";
        boolean additivity = true;
        if (key.startsWith("additivity")) {
            LoggerConfig logger = getLogger(key.substring("additivity.".length()));
            Boolean additive = Boolean.valueOf(loggerSubset.getString(key));
            logger.setAdditive(additive);
        } else {/*from   w ww .ja  va  2 s .com*/
            List<String> appenderRefs = new ArrayList<String>();
            name = key;
            String val = loggerSubset.getString(key);
            if (StringUtils.isNotBlank(val)) {
                if (val.contains(",")) {
                    String[] strings = val.split(",");
                    level = strings[0];
                    if (strings.length > 1) {
                        for (int i = 1; i < strings.length; i++) {
                            String appenderName = strings[i].trim();
                            appenderRefs.add(appenderName);
                        }
                    }
                } else {
                    level = val;
                }
            }
            Level level1 = Level.getLevel(level.toUpperCase());
            LoggerConfig loggerConfig = new LoggerConfig(name, level1, additivity);
            for (String appenderRef : appenderRefs) {
                loggerConfig.addAppender(getAppender(appenderRef), level1, null);
            }
            //                loggerConfig.getAppenderRefs()
            addLogger(name, loggerConfig);
        }

    }

}

From source file:com.cisco.oss.foundation.logging.FoundationLoggerConfiguration.java

private void initAppenders(org.apache.commons.configuration.Configuration appenderSubset, Layout layout) {
    Iterator<String> keys = appenderSubset.getKeys();
    while (keys.hasNext()) {
        String key = keys.next();

        String val = appenderSubset.getString(key);
        if (key.contains(".file") && StringUtils.isNotBlank(val)) {
            int endIndex = key.indexOf('.');
            String appenderName = key.substring(0, endIndex);
            String fileName = val;
            String filePattern = fileName + ".%d{yyyy-MM-dd}.%i.gz";
            TriggeringPolicy trigerringPolicy = CompositeTriggeringPolicy.createPolicy(
                    OnStartupTriggeringPolicy.createPolicy(),
                    TimeBasedTriggeringPolicy.createPolicy("1", "false"),
                    SizeBasedTriggeringPolicy.createPolicy("100 MB"));
            RolloverStrategy rolloverStrategy = DefaultRolloverStrategy.createStrategy("100", null, null, null,
                    this);
            FoundationRollingRandomAccessFileAppender appender = FoundationRollingRandomAccessFileAppender
                    .createAppender(fileName, filePattern, "true", appenderName, "false", null,
                            trigerringPolicy, rolloverStrategy, layout, null, null, null, null, this);
            appender.start();//from ww w  .  j  a  v  a2  s . c  om
            addAppender(appender);
            //                appender.

        }

        if (StringUtils.isNotBlank(val) && val.contains("org.apache.log4j.ConsoleAppender")) {
            Appender appender = ConsoleAppender.createAppender(layout, null, "SYSTEM_OUT", key, "false",
                    "true");
            appender.start();
            addAppender(appender);
        }

    }
}

From source file:com.github.htfv.maven.plugins.buildconfigurator.core.configurators.propertyfiles.PropertyFileConfigurator.java

/**
 * Updates project properties. Properties are immutable - if there is
 * already a user or a project property with the same key defined, it will
 * not be overwritten./* w  w  w  . ja v a  2 s .com*/
 *
 * @param ctx
 *            The configuration context.
 * @param resultBuilder
 *            The result builder.
 */
private void updateProjectProperties(final ConfigurationContext ctx, final Result.Builder resultBuilder) {
    final Configuration properties = ctx.getProperties();
    final MavenProject project = ctx.getProject();
    final Properties projectProperties = project.getProperties();

    final Properties userProperties = project.getProjectBuildingRequest().getUserProperties();

    @SuppressWarnings("unchecked")
    final Iterator<String> keys = properties.getKeys();

    while (keys.hasNext()) {
        final String key = keys.next();

        if (userProperties.containsKey(key) || projectProperties.containsKey(key)) {
            continue;
        }

        final String value = ctx.getStringValue(properties.getString(key));

        projectProperties.setProperty(key, value);
        resultBuilder.newProperty(key, value);
    }
}

From source file:com.evolveum.midpoint.init.StartupConfiguration.java

@Override
public Configuration getConfiguration(String componentName) {
    if (null == componentName) {
        throw new IllegalArgumentException("NULL argument");
    }// w w  w.java 2  s. c o m
    Configuration sub = config.subset(componentName);
    // Insert replacement for relative path to midpoint.home else clean
    // replace
    if (getMidpointHome() != null) {
        sub.addProperty(MIDPOINT_HOME, getMidpointHome());
    } else {
        @SuppressWarnings("unchecked")
        Iterator<String> i = sub.getKeys();
        while (i.hasNext()) {
            String key = i.next();
            sub.setProperty(key, sub.getString(key).replace("${" + MIDPOINT_HOME + "}/", ""));
            sub.setProperty(key, sub.getString(key).replace("${" + MIDPOINT_HOME + "}", ""));
        }
    }

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Configuration for {} :", componentName);
        @SuppressWarnings("unchecked")
        Iterator<String> i = sub.getKeys();
        while (i.hasNext()) {
            String key = i.next();
            LOGGER.debug("    {} = {}", key, sub.getString(key));
        }
    }
    return sub;
}

From source file:com.cisco.oss.foundation.http.AbstractHttpClient.java

private InternalServerProxyMetadata loadServersMetadataConfiguration() {

    Configuration subset = configuration.subset(apiName);
    final Iterator<String> keysIterator = subset.getKeys();

    // read default values
    int readTimeout = subset.getInt("http." + LoadBalancerConstants.READ_TIME_OUT,
            LoadBalancerConstants.DEFAULT_READ_TIMEOUT);
    int connectTimeout = subset.getInt("http." + LoadBalancerConstants.CONNECT_TIME_OUT,
            LoadBalancerConstants.DEFAULT_CONNECT_TIMEOUT);
    long waitingTime = subset.getLong("http." + LoadBalancerConstants.WAITING_TIME,
            LoadBalancerConstants.DEFAULT_WAITING_TIME);
    int numberOfAttempts = subset.getInt("http." + LoadBalancerConstants.NUMBER_OF_ATTEMPTS,
            LoadBalancerConstants.DEFAULT_NUMBER_OF_ATTEMPTS);
    long retryDelay = subset.getLong("http." + LoadBalancerConstants.RETRY_DELAY,
            LoadBalancerConstants.DEFAULT_RETRY_DELAY);

    long idleTimeout = subset.getLong("http." + LoadBalancerConstants.IDLE_TIME_OUT,
            LoadBalancerConstants.DEFAULT_IDLE_TIMEOUT);
    int maxConnectionsPerAddress = subset.getInt("http." + LoadBalancerConstants.MAX_CONNECTIONS_PER_ADDRESS,
            LoadBalancerConstants.DEFAULT_MAX_CONNECTIONS_PER_ADDRESS);
    int maxConnectionsTotal = subset.getInt("http." + LoadBalancerConstants.MAX_CONNECTIONS_TOTAL,
            LoadBalancerConstants.DEFAULT_MAX_CONNECTIONS_TOTAL);
    int maxQueueSizePerAddress = subset.getInt("http." + LoadBalancerConstants.MAX_QUEUE_PER_ADDRESS,
            LoadBalancerConstants.DEFAULT_MAX_QUEUE_PER_ADDRESS);
    boolean followRedirects = subset.getBoolean("http." + LoadBalancerConstants.FOLLOW_REDIRECTS, false);
    boolean disableCookies = subset.getBoolean("http." + LoadBalancerConstants.DISABLE_COOKIES, false);
    boolean autoCloseable = subset.getBoolean("http." + LoadBalancerConstants.AUTO_CLOSEABLE, true);
    boolean autoEncodeUri = subset.getBoolean("http." + LoadBalancerConstants.AUTO_ENCODE_URI, true);
    boolean staleConnectionCheckEnabled = subset
            .getBoolean("http." + LoadBalancerConstants.IS_STALE_CONN_CHECK_ENABLED, false);
    boolean serviceDirectoryEnabled = subset
            .getBoolean("http." + LoadBalancerConstants.SERVICE_DIRECTORY_IS_ENABLED, false);
    String serviceName = subset.getString("http." + LoadBalancerConstants.SERVICE_DIRECTORY_SERVICE_NAME,
            "UNKNOWN");

    String keyStorePath = subset.getString("http." + LoadBalancerConstants.KEYSTORE_PATH, "");
    String keyStorePassword = subset.getString("http." + LoadBalancerConstants.KEYSTORE_PASSWORD, "");
    String trustStorePath = subset.getString("http." + LoadBalancerConstants.TRUSTSTORE_PATH, "");
    String trustStorePassword = subset.getString("http." + LoadBalancerConstants.TRUSTSTORE_PASSWORD, "");

    final List<String> keys = new ArrayList<String>();

    while (keysIterator.hasNext()) {
        String key = keysIterator.next();
        keys.add(key);//  ww  w .ja va2  s  .c o  m
    }

    Collections.sort(keys);

    List<Pair<String, Integer>> hostAndPortPairs = new CopyOnWriteArrayList<Pair<String, Integer>>();

    for (String key : keys) {

        if (key.contains(LoadBalancerConstants.HOST)) {

            String host = subset.getString(key);

            // trim the host name
            if (StringUtils.isNotEmpty(host)) {
                host = host.trim();
            }
            final String portKey = key.replace(LoadBalancerConstants.HOST, LoadBalancerConstants.PORT);
            if (subset.containsKey(portKey)) {
                int port = subset.getInt(portKey);
                // save host and port for future creation of server list
                hostAndPortPairs.add(Pair.of(host, port));
            }
        }

    }

    InternalServerProxyMetadata metadata = new InternalServerProxyMetadata(readTimeout, connectTimeout,
            idleTimeout, maxConnectionsPerAddress, maxConnectionsTotal, maxQueueSizePerAddress, waitingTime,
            numberOfAttempts, retryDelay, hostAndPortPairs, keyStorePath, keyStorePassword, trustStorePath,
            trustStorePassword, followRedirects, autoCloseable, staleConnectionCheckEnabled, disableCookies,
            serviceDirectoryEnabled, serviceName, autoEncodeUri);
    //        metadata.getHostAndPortPairs().addAll(hostAndPortPairs);
    //        metadata.setReadTimeout(readTimeout);
    //        metadata.setConnectTimeout(connectTimeout);
    //        metadata.setNumberOfRetries(numberOfAttempts);
    //        metadata.setRetryDelay(retryDelay);
    //        metadata.setWaitingTime(waitingTime);

    return metadata;

}

From source file:com.evolveum.midpoint.task.quartzimpl.TaskManagerConfiguration.java

private void checkAllowedKeys(Configuration c, List<String> knownKeys)
        throws TaskManagerConfigurationException {
    Set<String> knownKeysSet = new HashSet<String>(knownKeys);

    Iterator<String> keyIterator = c.getKeys();
    while (keyIterator.hasNext()) {
        String keyName = keyIterator.next();
        String normalizedKeyName = StringUtils.substringBefore(keyName, "."); // because of subkeys
        normalizedKeyName = StringUtils.substringBefore(normalizedKeyName, "["); // because of [@xmlns:c]
        int colon = normalizedKeyName.indexOf(':'); // because of c:generalChangeProcessorConfiguration
        if (colon != -1) {
            normalizedKeyName = normalizedKeyName.substring(colon + 1);
        }/*from w w w  .j a  v a  2s  .  c o m*/
        if (!knownKeysSet.contains(keyName) && !knownKeysSet.contains(normalizedKeyName)) { // ...we need to test both because of keys like 'midpoint.home'
            throw new TaskManagerConfigurationException(
                    "Unknown key " + keyName + " in task manager configuration");
        }
    }
}