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

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

Introduction

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

Prototype

public Iterator getKeys() 

Source Link

Document

Returns an iterator with all keys defined in this configuration.

Usage

From source file:com.wrmsr.neurosis.util.Configs.java

public static List<String> getAllStrings(HierarchicalConfiguration hc, String key) {
    List<String> values = hc.getList(key).stream().filter(o -> o != null).map(Object::toString)
            .collect(Collectors.toList());
    try {/*from w  w w  . j a va 2  s . c  om*/
        HierarchicalConfiguration subhc = hc.configurationAt(key);
        for (String subkey : Lists.newArrayList(subhc.getKeys())) {
            if (!isNullOrEmpty(subkey)) {
                String subvalue = subhc.getString(subkey);
                if (subvalue != null) {
                    values.add(subvalue);
                }
            }
        }
    } catch (IllegalArgumentException e) {
        // pass
    }
    return values;
}

From source file:com.github.steveash.typedconfig.ConfigurationPrinter.java

public String printToString(HierarchicalConfiguration config) {
    StringBuilder sb = new StringBuilder();

    String name = (config.getRootNode() != null ? config.getRootNode().getName() : "");
    sb.append("Configuration root: ").append(name).append("\n");
    sb.append("----------------------------------\n");
    Iterator<String> keys = config.getKeys();
    while (keys != null && keys.hasNext()) {
        String key = keys.next();
        sb.append("  ");
        sb.append("[").append(key).append("] -> ").append(config.getString(key));
        sb.append("\n");
    }//www  .j  a  v  a 2  s  .  c  o  m
    return sb.toString();
}

From source file:com.processpuzzle.persistence.domain.HibernatePersistenceProvider.java

@SuppressWarnings("unchecked")
private void addPropertiesToTheHibernateConfiguration() {
    HierarchicalConfiguration hibernateProperties = configuration.configurationAt(HIBERNATE_PROPERTY_SELECTOR);
    for (Iterator<String> iter = hibernateProperties.getKeys(); iter.hasNext();) {
        String propertyKey = (String) iter.next();
        String propertyValue = hibernateProperties.getString(propertyKey);

        if (propertyKey != "" && propertyValue != "") {
            propertyKey = propertyKey.toLowerCase();
            propertyKey = propertyKey.replace(PersistenceContext.NAME_SPACE_PREFIX, "");
            propertyKey = "hibernate." + propertyKey.replace('/', '.');
            hibernateConfiguration.setProperty(propertyKey, propertyValue);
        }//from   w ww . j  av a 2s  .  c  o  m
    }
}

From source file:com.sinfonier.util.XMLProperties.java

/**
 * Get a complex property. Complex property is a label which contains several sublabels.
 * //from   w  ww.j  a  v a 2 s .  c  om
 * @param type {@code com.sinfonier.util.ComponentType}.
 * @param componentName Name of component.
 * @param propertyName Property name.
 * @return
 */
public List<Map<String, Object>> getComplexProperty(ComponentType type, String componentName,
        String propertyName) {
    StringBuilder sb = new StringBuilder();
    String itemName = propertyName.substring(0, propertyName.length() - 1);
    List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

    switch (type) {
    case BOLT:
        sb.append("bolts/bolt[@abstractionId='");
        break;
    case SPOUT:
        sb.append("spouts/spout[@abstractionId='");
        break;
    case DRAIN:
        sb.append("drains/drain[@abstractionId='");
        break;
    default:
        break;
    }
    sb.append(componentName).append("']/").append(propertyName).append("/").append(itemName);

    List<HierarchicalConfiguration> items = xml.configurationsAt(sb.toString());
    for (HierarchicalConfiguration item : items) {
        Iterator<String> keys = item.getKeys();
        Map<String, Object> map = new HashMap<String, Object>();
        while (keys.hasNext()) {
            String key = keys.next();
            map.put(key, item.getProperty(key));
        }
        list.add(map);
    }

    return list;
}

From source file:com.legstar.config.commons.LegStarConfigCommons.java

/**
 * Sets bean members using configuration attributes.
 * /*from ww w  .j  a v  a 2s.  co  m*/
 * @param endpoint the bean
 * @param endpointConfig the configuration hierarchy
 * @throws LegStarConfigurationException if setting value on bean fails
 */
protected void setValues(final Object endpoint, final HierarchicalConfiguration endpointConfig)
        throws LegStarConfigurationException {
    for (Iterator<?> iterator = endpointConfig.getKeys(); iterator.hasNext();) {
        String key = (String) iterator.next();
        setValue(endpoint, key, endpointConfig.getString(key));
    }
}

From source file:edu.uw.sig.frames2owl.util.ConfigReader.java

private void init() {
    /*/*from   www . jav  a2 s  . com*/
     <iri project='cho'>
       <value_source>FMAID</value_source>
       <value_comp>{value}</value_comp>
       <fragment_separator>#</fragment_separator>
    </iri>
     */
    // read iri config info
    List<HierarchicalConfiguration> iriConfs = config.configurationsAt("iri");
    for (HierarchicalConfiguration iriConf : iriConfs) {
        // get the project name
        String projectName = iriConf.getString("[@project]");
        String iriDomain = iriConf.getString("iri_domain");
        String valSource = iriConf.getString("value_source");
        String valComp = iriConf.getString("value_comp");
        String fragSep = iriConf.getString("fragment_separator");
        IRIConf currIriConf = new IRIConf(valSource, iriDomain, valComp, fragSep);
        proj2IriConfMap.put(projectName, currIriConf);
    }

    // read config flags and add to map
    HierarchicalConfiguration flags = config.configurationAt("conf-flags");
    if (flags != null) {
        Iterator<String> flagsIt = flags.getKeys();
        while (flagsIt.hasNext()) {
            // get the name of the flag
            String flagName = flagsIt.next();

            // get flag value as string
            boolean flagVal = flags.getBoolean(flagName);

            // put in flag map
            configFlags.put(flagName, flagVal);
        }
    }
    //System.err.println(configFlags);

    // read general configuration parameters
    List<HierarchicalConfiguration> reifExcl = config.configurationsAt("general_conv_args.reif_exclusion");
    for (HierarchicalConfiguration exclusion : reifExcl) {
        // get slot name and conversion class name
        String excludedSlots = exclusion.getString("[@excluded_slots]");
        for (String excl : excludedSlots.split(","))
            reifExclusions.add(excl);
    }

    List<HierarchicalConfiguration> slotAnnotExcl = config
            .configurationsAt("general_conv_args.slot_annot_exclusion");
    for (HierarchicalConfiguration exclusion : slotAnnotExcl) {
        // get slot name and conversion class name
        String excludedSlots = exclusion.getString("[@excluded_slots]");
        for (String excl : excludedSlots.split(","))
            slotAnnotExclusions.add(excl);
    }

    // name and location of class that will be used to contruct named domain classes for annotation props
    List<HierarchicalConfiguration> domainConfs = config.configurationsAt("general_conv_args.domain");
    for (HierarchicalConfiguration domainConf : domainConfs) {
        // get slot name and conversion class name
        domainClsName = domainConf.getString("[@cls-name]");
        domainSuperClsName = domainConf.getString("[@super-cls-name]");
    }

    // name and location of class that will be used to contruct named range classes for annotation props
    List<HierarchicalConfiguration> rangeConfs = config.configurationsAt("general_conv_args.range");
    for (HierarchicalConfiguration rangeConf : rangeConfs) {
        // get slot name and conversion class name
        rangeClsName = rangeConf.getString("[@cls-name]");
        rangeSuperClsName = rangeConf.getString("[@super-cls-name]");
    }

    // read config file to determine which Java classes to use for which slot conversion
    List<HierarchicalConfiguration> slotConverters = config
            .configurationsAt("slot_conv_classes.slot_conv_class");
    for (HierarchicalConfiguration slotConverter : slotConverters) {
        // get slot name and conversion class name
        String slotName = slotConverter.getString("[@slot_name]");
        String convClsName = slotConverter.getString("[@conv_cls_name]");

        try {
            Class convClass = Class.forName(convClsName);
            slotConvMap.put(slotName, convClass);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            continue;
        }

        // gather additional arguments if there are any
        Iterator<String> iter = slotConverter.getKeys();
        Map<String, String> attrMap = new HashMap<String, String>();
        while (iter.hasNext()) {
            String key = iter.next();

            if (!key.equals("[@slot_name]") && !key.equals("[@conv_cls_name]")) {
                //System.err.println("found key for init args = "+key+" for slot "+slotName);
                String attrVal = slotConverter.getString(key);
                key = key.replaceAll("^\\[@", "");
                key = key.replaceAll("\\]$", "");
                attrMap.put(key, attrVal);
            }

        }
        convInitArgsMap.put(slotName, attrMap);
    }

    /*
     <inst_conv_classes>
      <inst_conv_class type="Mapping" 
    conv_cls_name="edu.uw.sig.frames2owl.instconv.impl.MappingConverter" 
    source_slot="source" 
    target_slot="target" 
    direct_property_name="mapsTo" 
    excluded_slots=""/>
    </inst_conv_classes>
     */

    // read config file to determine which Java classes to use for which slot conversion
    List<HierarchicalConfiguration> instConverters = config
            .configurationsAt("inst_conv_classes.inst_conv_class");
    for (HierarchicalConfiguration instConverter : instConverters) {
        String typeName = instConverter.getString("[@type_name]");
        String convClsName = instConverter.getString("[@conv_cls_name]");

        try {
            Class convClass = Class.forName(convClsName);
            instConvMap.put(typeName, convClass);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            continue;
        }

        // gather additional arguments if there are any
        Iterator<String> iter = instConverter.getKeys();
        Map<String, String> attrMap = new HashMap<String, String>();
        while (iter.hasNext()) {
            String key = iter.next();

            if (!key.equals("[@type]") && !key.equals("[@conv_cls_name]")) {
                //System.err.println("found key for init args = "+key+" for slot "+slotName);
                String attrVal = instConverter.getString(key);
                key = key.replaceAll("^\\[@", "");
                key = key.replaceAll("\\]$", "");
                attrMap.put(key, attrVal);
            }

        }
        instConvInitArgsMap.put(typeName, attrMap);
    }

}

From source file:org.apache.james.fetchmail.FetchMail.java

/**
 * Method configure parses and validates the Configuration data and creates
 * a new <code>ParsedConfiguration</code>, an <code>Account</code> for each
 * configured static account and a/*from   w w w . j av a2 s  .  co  m*/
 * <code>ParsedDynamicAccountParameters</code> for each dynamic account.
 *
 * @see org.apache.james.lifecycle.api.Configurable#configure(HierarchicalConfiguration)
 */
public void configure(HierarchicalConfiguration configuration) throws ConfigurationException {
    // Set any Session parameters passed in the Configuration
    setSessionParameters(configuration);

    // Create the ParsedConfiguration used in the delegation chain
    ParsedConfiguration parsedConfiguration = new ParsedConfiguration(configuration, logger, getLocalUsers(),
            getDNSService(), getDomainList(), getMailQueue());

    setParsedConfiguration(parsedConfiguration);

    // Setup the Accounts
    List<HierarchicalConfiguration> allAccounts = configuration.configurationsAt("accounts");
    if (allAccounts.size() < 1)
        throw new ConfigurationException("Missing <accounts> section.");
    if (allAccounts.size() > 1)
        throw new ConfigurationException("Too many <accounts> sections, there must be exactly one");
    HierarchicalConfiguration accounts = allAccounts.get(0);

    if (!accounts.getKeys().hasNext())
        throw new ConfigurationException("Missing <account> section.");

    int i = 0;
    // Create an Account for every configured account
    for (ConfigurationNode accountsChild : accounts.getRoot().getChildren()) {

        String accountsChildName = accountsChild.getName();

        List<HierarchicalConfiguration> accountsChildConfig = accounts.configurationsAt(accountsChildName);
        HierarchicalConfiguration conf = accountsChildConfig.get(i);

        if ("alllocal".equals(accountsChildName)) {
            // <allLocal> is dynamic, save the parameters for accounts to
            // be created when the task is triggered
            getParsedDynamicAccountParameters().add(new ParsedDynamicAccountParameters(i, conf));
            continue;
        }

        if ("account".equals(accountsChildName)) {
            // Create an Account for the named user and
            // add it to the list of static accounts
            getStaticAccounts().add(new Account(i, parsedConfiguration, conf.getString("[@user]"),
                    conf.getString("[@password]"), conf.getString("[@recipient]"),
                    conf.getBoolean("[@ignorercpt-header]"), conf.getString("[@customrcpt-header]", ""),
                    getSession()));
            continue;
        }

        throw new ConfigurationException("Illegal token: <" + accountsChildName + "> in <accounts>");
    }
    i++;
}

From source file:org.apache.james.utils.FileConfigurationProviderTest.java

@Test
public void getConfigurationShouldLoadCorrespondingXMLFile() throws Exception {
    HierarchicalConfiguration hierarchicalConfiguration = configurationProvider
            .getConfiguration(ROOT_CONFIG_KEY);
    assertThat(hierarchicalConfiguration.getKeys()).containsOnly(CONFIG_KEY_1,
            String.join(CONFIG_SEPARATOR, CONFIG_KEY_4, CONFIG_KEY_2),
            String.join(CONFIG_SEPARATOR, CONFIG_KEY_4, CONFIG_KEY_5, CONFIG_KEY_2));
    assertThat(hierarchicalConfiguration.getProperty(CONFIG_KEY_1)).isEqualTo(VALUE_1);
}

From source file:org.apache.james.utils.FileConfigurationProviderTest.java

@Test
public void getConfigurationShouldLoadCorrespondingXMLFilePart() throws Exception {
    HierarchicalConfiguration hierarchicalConfiguration = configurationProvider
            .getConfiguration(String.join(CONFIG_SEPARATOR, ROOT_CONFIG_KEY, CONFIG_KEY_4));
    assertThat(hierarchicalConfiguration.getKeys()).containsOnly(CONFIG_KEY_2,
            String.join(CONFIG_SEPARATOR, CONFIG_KEY_5, CONFIG_KEY_2));
    assertThat(hierarchicalConfiguration.getProperty(CONFIG_KEY_2)).isEqualTo(VALUE_2);
}

From source file:org.apache.james.utils.FileConfigurationProviderTest.java

@Test
public void getConfigurationShouldLoadCorrespondingXMLFileWhenAPathIsProvidedPart() throws Exception {
    HierarchicalConfiguration hierarchicalConfiguration = configurationProvider
            .getConfiguration(String.join(CONFIG_SEPARATOR, ROOT_CONFIG_KEY, CONFIG_KEY_4, CONFIG_KEY_5));
    assertThat(hierarchicalConfiguration.getKeys()).containsOnly(CONFIG_KEY_2);
    assertThat(hierarchicalConfiguration.getProperty(CONFIG_KEY_2)).isEqualTo(VALUE_3);
}