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

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

Introduction

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

Prototype

@Override
public final Iterator<String> getKeys() 

Source Link

Document

This implementation takes care of synchronization and then delegates to getKeysInternal() for obtaining the actual iterator.

Usage

From source file:com.vmware.loginsightapi.Configuration.java

/**
 * Builds the Configuration object from the properties file (apache commons
 * properties file format). <br>/*from  w w w. j a  va  2s.c  o  m*/
 * The values provided in the config file will be overwritten environment
 * variables (if present)
 * 
 * List of the properties <br>
 * loginsight.host = host name <br>
 * loginsight.port = port number <br>
 * loginsight.user = User name <br>
 * loginsight.password = password <br>
 * loginsight.ingestion.agentId = agentId <br>
 * loginsight.connection.scheme = http protocol scheme <br>
 * loginsight.ingestion.port = Ingestion port number <br>
 * 
 * @param configFileName
 *            Name of the config file to read
 * @return Newly created Configuration object
 */
public static Configuration buildFromConfig(String configFileName) {
    try {
        List<FileLocationStrategy> subs = Arrays.asList(new ProvidedURLLocationStrategy(),
                new FileSystemLocationStrategy(), new ClasspathLocationStrategy());
        FileLocationStrategy strategy = new CombinedLocationStrategy(subs);

        FileBasedConfigurationBuilder<PropertiesConfiguration> builder = new FileBasedConfigurationBuilder<PropertiesConfiguration>(
                PropertiesConfiguration.class).configure(
                        new Parameters().fileBased().setLocationStrategy(strategy).setFileName(configFileName));
        PropertiesConfiguration propConfig = builder.getConfiguration();
        Map<String, String> propMap = new HashMap<String, String>();
        Iterator<String> keys = propConfig.getKeys();
        keys.forEachRemaining(key -> {
            logger.info(key + ":" + propConfig.getString(key));
            propMap.put(key, propConfig.getString(key));
        });
        Configuration config = Configuration.buildConfig(propMap);
        config.loadFromEnv();
        return config;
    } catch (ConfigurationException e1) {
        throw new RuntimeException("Unable to load config", e1);
    }
}

From source file:com.sikulix.core.SX.java

private static void setOptions(PropertiesConfiguration someOptions) {
    if (isNull(someOptions) || someOptions.size() == 0) {
        return;/*  w ww.j ava2 s .  c  o  m*/
    }
    Iterator<String> allKeys = someOptions.getKeys();
    List<String> sxSettings = new ArrayList<>();
    while (allKeys.hasNext()) {
        String key = allKeys.next();
        if (key.startsWith("Settings.")) {
            sxSettings.add(key);
            continue;
        }
        trace("!setOptions: %s = %s", key, someOptions.getProperty(key));
    }
    if (sxSettings.size() > 0) {
        Class cClass = null;
        try {
            cClass = Class.forName("org.sikuli.basics.Settings");
        } catch (ClassNotFoundException e) {
            error("!setOptions: %s", cClass);
        }
        if (!isNull(cClass)) {
            for (String sKey : sxSettings) {
                String sAttr = sKey.substring("Settings.".length());
                Field cField = null;
                Class ccField = null;
                try {
                    cField = cClass.getField(sAttr);
                    ccField = cField.getType();
                    if (ccField.getName() == "boolean") {
                        cField.setBoolean(null, someOptions.getBoolean(sKey));
                    } else if (ccField.getName() == "int") {
                        cField.setInt(null, someOptions.getInt(sKey));
                    } else if (ccField.getName() == "float") {
                        cField.setFloat(null, someOptions.getFloat(sKey));
                    } else if (ccField.getName() == "double") {
                        cField.setDouble(null, someOptions.getDouble(sKey));
                    } else if (ccField.getName() == "String") {
                        cField.set(null, someOptions.getString(sKey));
                    }
                    trace("!setOptions: %s = %s", sAttr, someOptions.getProperty(sKey));
                    someOptions.clearProperty(sKey);
                } catch (Exception ex) {
                    error("!setOptions: %s = %s", sKey, sxOptions.getProperty(sKey));
                }
            }
        }
    }
}

From source file:com.sikulix.core.SX.java

private static void mergeExtraOptions(PropertiesConfiguration baseOptions,
        PropertiesConfiguration extraOptions) {
    trace("loadOptions: have to merge extra Options");
    if (isNull(extraOptions) || extraOptions.size() == 0) {
        return;/*from  w w  w .  jav a2 s  .  com*/
    }
    Iterator<String> allKeys = extraOptions.getKeys();
    while (allKeys.hasNext()) {
        String key = allKeys.next();
        if (isNull(baseOptions.getProperty(key))) {
            baseOptions.addProperty(key, extraOptions.getProperty(key));
            trace("Option added: %s", key);
        } else {
            baseOptions.addProperty(key, extraOptions.getProperty(key));
            trace("Option changed: %s", key);
        }
    }
}

From source file:org.exist.launcher.LauncherWrapper.java

protected void getVMOpts(List<String> args, PropertiesConfiguration vmProperties) {
    for (final Iterator<String> i = vmProperties.getKeys(); i.hasNext();) {
        final String key = i.next();
        if (key.startsWith("memory.")) {
            if ("memory.max".equals(key)) {
                args.add("-Xmx" + vmProperties.getString(key) + 'm');
            } else if ("memory.min".equals(key)) {
                args.add("-Xms" + vmProperties.getString(key) + 'm');
            }//from  w w w .  j  ava 2 s.  c o m
        } else if ("vmoptions".equals(key)) {
            args.add(vmProperties.getString(key));
        } else if (key.startsWith("vmoptions.")) {
            final String os = key.substring("vmoptions.".length()).toLowerCase();
            if (OS.contains(os)) {
                final String value = vmProperties.getString(key);
                Arrays.stream(value.split("\\s+")).forEach(args::add);
            }
        }
    }
}

From source file:org.jbb.lib.properties.FreshInstallPropertiesCreator.java

private static void addMissingProperties(PropertiesConfiguration reference, PropertiesConfiguration target) {
    Lists.newArrayList(reference.getKeys()).stream().filter(propertyKey -> !target.containsKey(propertyKey))
            .forEach(missingKey -> target.setProperty(missingKey, reference.getProperty(missingKey)));
}

From source file:org.jbb.lib.properties.FreshInstallPropertiesCreator.java

private static void removeObsoleteProperties(PropertiesConfiguration reference,
        PropertiesConfiguration target) {
    Lists.newArrayList(target.getKeys()).stream().filter(propertyKey -> !reference.containsKey(propertyKey))
            .forEach(target::clearProperty);
}

From source file:org.roda_project.commons_ip.model.impl.bagit.BagitUtils.java

public static Map<String, String> getBagitInfo(Path metadataPath) {
    Map<String, String> metadataList = new HashMap<>();
    try {//from  ww  w . j a  va  2s.c  o  m
        PropertiesConfiguration config = new Configurations().properties(metadataPath.toFile());
        Iterator<String> keys = config.getKeys();

        while (keys.hasNext()) {
            String key = keys.next();
            metadataList.put(key, config.getString(key));
        }
    } catch (ConfigurationException e) {
        LOGGER.error("Could not load properties with bagit metadata", e);
    }

    return metadataList;
}