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

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

Introduction

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

Prototype

List getList(String key);

Source Link

Document

Get a List of strings associated with the given configuration key.

Usage

From source file:org.zaproxy.zap.extension.alertFilters.ExtensionAlertFilters.java

@Override
public void importContextData(Context ctx, Configuration config) {
    List<Object> list = config.getList(CONTEXT_CONFIG_ALERT_FILTER);
    ContextAlertFilterManager m = getContextAlertFilterManager(ctx.getIndex());
    for (Object o : list) {
        AlertFilter af = AlertFilter.decode(ctx.getIndex(), o.toString());
        m.addAlertFilter(af);/*from ww w  . j  a  v  a  2  s . c o m*/
    }
}

From source file:org.zaproxy.zap.extension.users.ExtensionUserManagement.java

@Override
public void importContextData(Context ctx, Configuration config) {
    List<Object> list = config.getList(CONTEXT_CONFIG_USERS_USER);
    ContextUserAuthManager m = getContextUserAuthManager(ctx.getIndex());
    for (Object o : list) {
        User usersManager = User.decode(ctx.getIndex(), o.toString());
        m.addUser(usersManager);/*  w  w w  .j a va  2 s.  c  o  m*/
    }
}

From source file:pl.edu.icm.coansys.commons.reparser.RegexpParser.java

@SuppressWarnings("unchecked")
private void loadConfiguration(String resource, String mainNode) {
    Iterator<String> iter = null;
    URL url = this.getClass().getClassLoader().getResource(resource);
    Configuration cfg;
    try {//from ww w. jav a  2s .  c om
        cfg = new PropertiesConfiguration(url);
    } catch (ConfigurationException e) {
        throw new RuntimeException(e);
    }

    /* Collect all nodes */
    Map<String, NodeCategory> nodes = new HashMap<String, NodeCategory>();
    iter = (Iterator<String>) cfg.getKeys(NODE);
    while (iter.hasNext()) {
        String nodeId = iter.next();
        nodeId = nodeId.replaceFirst("^" + NODE + "\\.", "").replaceFirst("\\..*$", "");
        if (!nodes.containsKey(nodeId)) {
            nodes.put(nodeId, new NodeCategory());
        }
    }
    log.debug("Found nodes: " + nodes.keySet());
    if (!nodes.containsKey(mainNode)) {
        throw new IllegalArgumentException(
                "Main node not found in the configuration file.  The required node is: " + mainNode);
    }

    for (Map.Entry<String, NodeCategory> entry : nodes.entrySet()) {
        NodeCategory node = entry.getValue();
        String id = entry.getKey();
        node.setId(id);

        String regexp = cfg.getString(NODE + "." + id + "." + REGEXP);
        if (regexp != null) {
            node.setRegexp(regexp);
        }

        String name = cfg.getString(NODE + "." + id + "." + NAME);
        if (name != null) {
            node.setName(name);
        }

        iter = (Iterator<String>) cfg.getKeys(NODE + "." + id + "." + TEMPLATE);
        while (iter.hasNext()) {
            String type = iter.next();
            type = type.replaceFirst("^" + NODE + "\\." + id + "\\." + TEMPLATE + "\\.?+", "");
            List<String> templates = (List<String>) cfg.getList(NODE + "." + id + "." + TEMPLATE + "." + type);

            for (String template : templates) {
                Template t = new Template();
                t.setType(type);

                String[] fields = template.split("\\s+");
                for (String field : fields) {
                    NodeCategory n = nodes.get(field);
                    if (n == null) {
                        log.warn("Node '" + field + "' does not exist.  Referenced in template: " + template);
                    }
                    t.addField(n);
                }
                node.addTemplate(t);
            }
        }
    }
    mainNodeCategory = nodes.get(mainNode);
}

From source file:pl.psnc.synat.wrdz.common.metadata.xmlns.DefaultNamespaceDictionary.java

/**
 * Private constructor. Loads namespaces from the config file.
 *///from w  ww . ja  v a2s .c  o  m
private DefaultNamespaceDictionary() {
    try {
        Configuration config = new XMLConfiguration(CONFIG_FILE);
        namespaces = new HashMap<String, Map<String, Object>>();
        int size = config.getList("namespace.uri").size();
        for (int i = 0; i < size; i++) {
            String uri = config.getString("namespace(" + i + ").uri");
            Map<String, Object> values = new HashMap<String, Object>();
            String schemaLocation = config.getString("namespace(" + i + ").schemaLocation");
            if (schemaLocation.length() > 0) {
                values.put("schemaLocation", schemaLocation);
            } else {
                values.put("schemaLocation", null);
            }
            values.put("type", NamespaceType.valueOf(config.getString("namespace(" + i + ").type")));
            namespaces.put(uri, values);
        }
    } catch (ConfigurationException e) {
        logger.error("There was a problem with loading the configuration with namespaces.", e);
        throw new RuntimeException(e);
    }
}