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(String prefix) 

Source Link

Document

Returns an iterator with all keys defined in this configuration that start with the given prefix.

Usage

From source file:edu.isi.wings.portal.classes.config.Config.java

@SuppressWarnings("rawtypes")
private ExeEngine getExeEngine(HierarchicalConfiguration node) {
    String name = node.getString("name");
    String impl = node.getString("implementation");
    ExeEngine.Type type = ExeEngine.Type.valueOf(node.getString("type"));
    ExeEngine engine = new ExeEngine(name, impl, type);
    for (Iterator it = node.getKeys("properties"); it.hasNext();) {
        String key = (String) it.next();
        String value = node.getString(key);
        engine.addProperty(key.replace("properties.", ""), value);
    }//from ww  w .  j av  a2 s.c o  m
    return engine;
}

From source file:org.apache.james.container.spring.bean.factory.mailrepositorystore.MailRepositoryStoreBeanFactory.java

/**
 * <p>/* www. j  a va2  s .  c  o  m*/
 * Registers a new mail repository type in the mail store's registry based
 * upon a passed in <code>Configuration</code> object.
 * </p>
 * <p/>
 * <p>
 * This is presumably synchronized to prevent corruption of the internal
 * registry.
 * </p>
 *
 * @param repConf the Configuration object used to register the repository
 * @throws ConfigurationException if an error occurs accessing the Configuration object
 */
public synchronized void registerRepository(HierarchicalConfiguration repConf) throws ConfigurationException {

    String className = repConf.getString("[@class]");

    boolean infoEnabled = getLogger().isInfoEnabled();

    for (String protocol : repConf.getStringArray("protocols.protocol")) {
        HierarchicalConfiguration defConf = null;

        if (repConf.getKeys("config").hasNext()) {
            // Get the default configuration for these protocol/type
            // combinations.
            defConf = repConf.configurationAt("config");
        }

        if (infoEnabled) {
            StringBuilder infoBuffer = new StringBuilder(128);
            infoBuffer.append("Registering Repository instance of class ");
            infoBuffer.append(className);
            infoBuffer.append(" to handle ");
            infoBuffer.append(protocol);
            infoBuffer.append(" protocol requests for repositories with key ");
            infoBuffer.append(protocol);
            getLogger().info(infoBuffer.toString());
        }

        if (classes.get(protocol) != null) {
            throw new ConfigurationException(
                    "The combination of protocol and type comprise a unique key for repositories.  This constraint has been violated.  Please check your repository configuration.");
        }

        classes.put(protocol, className);

        if (defConf != null) {
            defaultConfigs.put(protocol, defConf);
        }
    }

}

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

/**
 * Propagate any Session parameters in the configuration to the Session.
 *
 * @param configuration The configuration containing the parameters
 * @throws ConfigurationException/*from   ww w.j  a v a2 s  . c o m*/
 */
protected void setSessionParameters(HierarchicalConfiguration configuration) {

    if (configuration.getKeys("javaMailProperties.property").hasNext()) {
        Properties properties = getSession().getProperties();
        List<HierarchicalConfiguration> allProperties = configuration
                .configurationsAt("javaMailProperties.property");
        for (HierarchicalConfiguration propConf : allProperties) {
            properties.setProperty(propConf.getString("[@name]"), propConf.getString("[@value]"));
            if (logger.isDebugEnabled()) {
                StringBuilder messageBuffer = new StringBuilder("Set property name: ");
                messageBuffer.append(propConf.getString("[@name]"));
                messageBuffer.append(" to: ");
                messageBuffer.append(propConf.getString("[@value]"));
                logger.debug(messageBuffer.toString());
            }
        }
    }
}

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

protected void configure(HierarchicalConfiguration conf) throws ConfigurationException {
    setHost(conf.getString("host"));

    setFetchTaskName(conf.getString("[@name]"));
    setJavaMailProviderName(conf.getString("javaMailProviderName"));
    setJavaMailFolderName(conf.getString("javaMailFolderName"));
    setRecurse(conf.getBoolean("recursesubfolders"));

    HierarchicalConfiguration recipientNotFound = conf.configurationAt("recipientnotfound");
    setDeferRecipientNotFound(recipientNotFound.getBoolean("[@defer]"));
    setRejectRecipientNotFound(recipientNotFound.getBoolean("[@reject]"));
    setLeaveRecipientNotFound(recipientNotFound.getBoolean("[@leaveonserver]"));
    setMarkRecipientNotFoundSeen(recipientNotFound.getBoolean("[@markseen]"));
    setDefaultDomainName(conf.getString("defaultdomain", "localhost"));

    setFetchAll(conf.getBoolean("fetchall"));

    HierarchicalConfiguration fetched = conf.configurationAt("fetched");
    setLeave(fetched.getBoolean("[@leaveonserver]"));
    setMarkSeen(fetched.getBoolean("[@markseen]"));

    HierarchicalConfiguration remoterecipient = conf.configurationAt("remoterecipient");
    setRejectRemoteRecipient(remoterecipient.getBoolean("[@reject]"));
    setLeaveRemoteRecipient(remoterecipient.getBoolean("[@leaveonserver]"));
    setMarkRemoteRecipientSeen(remoterecipient.getBoolean("[@markseen]"));

    HierarchicalConfiguration blacklist = conf.configurationAt("blacklist");
    setBlacklist(conf.getString("blacklist", ""));
    setRejectBlacklisted(blacklist.getBoolean("[@reject]"));
    setLeaveBlacklisted(blacklist.getBoolean("[@leaveonserver]"));
    setMarkBlacklistedSeen(blacklist.getBoolean("[@markseen]"));

    HierarchicalConfiguration userundefined = conf.configurationAt("userundefined");
    setRejectUserUndefined(userundefined.getBoolean("[@reject]"));
    setLeaveUserUndefined(userundefined.getBoolean("[@leaveonserver]"));
    setMarkUserUndefinedSeen(userundefined.getBoolean("[@markseen]"));

    HierarchicalConfiguration undeliverable = conf.configurationAt("undeliverable");
    setLeaveUndeliverable(undeliverable.getBoolean("[@leaveonserver]"));
    setMarkUndeliverableSeen(undeliverable.getBoolean("[@markseen]"));

    if (conf.getKeys("remotereceivedheader").hasNext()) {
        HierarchicalConfiguration remotereceivedheader = conf.configurationAt("remotereceivedheader");

        setRemoteReceivedHeaderIndex(remotereceivedheader.getInt("[@index]"));
        setRejectRemoteReceivedHeaderInvalid(remotereceivedheader.getBoolean("[@reject]"));
        setLeaveRemoteReceivedHeaderInvalid(remotereceivedheader.getBoolean("[@leaveonserver]"));
        setMarkRemoteReceivedHeaderInvalidSeen(remotereceivedheader.getBoolean("[@markseen]"));
    }/*w w w .j a v a 2 s.  co  m*/

    if (conf.getKeys("maxmessagesize").hasNext()) {
        HierarchicalConfiguration maxmessagesize = conf.configurationAt("maxmessagesize");

        setMaxMessageSizeLimit(maxmessagesize.getInt("[@limit]") * 1024);
        setRejectMaxMessageSizeExceeded(maxmessagesize.getBoolean("[@reject]"));
        setLeaveMaxMessageSizeExceeded(maxmessagesize.getBoolean("[@leaveonserver]"));
        setMarkMaxMessageSizeExceededSeen(maxmessagesize.getBoolean("[@markseen]"));
    }

    if (getLogger().isDebugEnabled()) {
        getLogger().info("Configured FetchMail fetch task " + getFetchTaskName());
    }
}

From source file:org.apache.james.mailrepository.memory.MemoryMailRepositoryStore.java

private void registerRepositoryDefaultConfiguration(HierarchicalConfiguration repositoryConfiguration,
        Protocol protocol) {/*  w  ww  .  j  ava2 s. c  om*/
    HierarchicalConfiguration defConf = null;
    if (repositoryConfiguration.getKeys("config").hasNext()) {
        defConf = repositoryConfiguration.configurationAt("config");
    }
    if (defConf != null) {
        perProtocolMailRepositoryDefaultConfiguration.put(protocol, defConf);
    }
}

From source file:org.apache.james.user.jdbc.AbstractJdbcUsersRepository.java

/**
 * <p>/*from w  ww. j  a va  2s .  co  m*/
 * Configures the UserRepository for JDBC access.
 * </p>
 * <p>
 * Requires a configuration element in the .conf.xml file of the form:
 * </p>
 * 
 * <pre>
 *   &lt;repository name=&quot;so even &quot;
 *       class=&quot;org.apache.james.userrepository.JamesUsersJdbcRepository&quot;&gt;
 *       &lt;!-- Name of the datasource to use --&gt;
 *       &lt;data-source&gt;MailDb&lt;/data-source&gt;
 *       &lt;!-- File to load the SQL definitions from --&gt;
 *       &lt;sqlFile&gt;dist/conf/sqlResources.xml&lt;/sqlFile&gt;
 *       &lt;!-- replacement parameters for the sql file --&gt;
 *       &lt;sqlParameters table=&quot;JamesUsers&quot;/&gt;
 *   &lt;/repository&gt;
 * </pre>
 * 
 * @see org.apache.james.user.lib.AbstractJamesUsersRepository#doConfigure(org.apache.commons.configuration.HierarchicalConfiguration)
 */
protected void doConfigure(HierarchicalConfiguration configuration) throws ConfigurationException {
    StringBuffer logBuffer;
    if (getLogger().isDebugEnabled()) {
        logBuffer = new StringBuffer(64).append(this.getClass().getName()).append(".configure()");
        getLogger().debug(logBuffer.toString());
    }

    // Parse the DestinationURL for the name of the datasource,
    // the table to use, and the (optional) repository Key.
    String destUrl = configuration.getString("[@destinationURL]", null);
    // throw an exception if the attribute is missing
    if (destUrl == null)
        throw new ConfigurationException("destinationURL attribute is missing from Configuration");

    // normalise the destination, to simplify processing.
    if (!destUrl.endsWith("/")) {
        destUrl += "/";
    }
    // Split on "/", starting after "db://"
    List<String> urlParams = new ArrayList<String>();
    int start = 5;
    int end = destUrl.indexOf('/', start);
    while (end > -1) {
        urlParams.add(destUrl.substring(start, end));
        start = end + 1;
        end = destUrl.indexOf('/', start);
    }

    // Build SqlParameters and get datasource name from URL parameters
    m_sqlParameters = new HashMap<String, String>();
    switch (urlParams.size()) {
    case 3:
        m_sqlParameters.put("key", urlParams.get(2));
    case 2:
        m_sqlParameters.put("table", urlParams.get(1));
    case 1:
        urlParams.get(0);
        break;
    default:
        throw new ConfigurationException("Malformed destinationURL - "
                + "Must be of the format \"db://<data-source>[/<table>[/<key>]]\".");
    }

    if (getLogger().isDebugEnabled()) {
        logBuffer = new StringBuffer(128).append("Parsed URL: table = '").append(m_sqlParameters.get("table"))
                .append("', key = '").append(m_sqlParameters.get("key")).append("'");
        getLogger().debug(logBuffer.toString());
    }

    // Get the SQL file location
    m_sqlFileName = configuration.getString("sqlFile", null);

    // Get other sql parameters from the configuration object,
    // if any.
    Iterator<String> paramIt = configuration.getKeys("sqlParameters");
    while (paramIt.hasNext()) {
        String rawName = paramIt.next();
        String paramName = paramIt.next().substring("sqlParameters.[@".length(), rawName.length() - 1);
        String paramValue = configuration.getString(rawName);
        m_sqlParameters.put(paramName, paramValue);
    }
}

From source file:org.apache.james.user.ldap.ReadOnlyLDAPGroupRestriction.java

/**
 * Initialises an instance from the contents of a
 * <code>&lt;restriction&gt;<code> configuration XML
 * element.//from   ww w  . ja v a2 s.c  o m
 *
 * @param configuration The avalon configuration instance that encapsulates the
 *                      contents of the <code>&lt;restriction&gt;<code> XML element.
 * @throws org.apache.commons.configuration.ConfigurationException
 *          If an error occurs extracting values from the configuration
 *          element.
 */
public ReadOnlyLDAPGroupRestriction(HierarchicalConfiguration configuration) {
    groupDNs = new ArrayList<String>();

    if (configuration != null) {
        memberAttribute = configuration.getString("[@memberAttribute]");

        if (configuration.getKeys("group").hasNext()) {
            Collections.addAll(groupDNs, configuration.getStringArray("group"));
        }
    }
}

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

private void registerRepositoryDefaultConfiguration(HierarchicalConfiguration repositoryConfiguration,
        String protocol) {//from w  w w. java 2 s  . co m
    HierarchicalConfiguration defConf = null;
    if (repositoryConfiguration.getKeys("config").hasNext()) {
        defConf = repositoryConfiguration.configurationAt("config");
    }
    if (defConf != null) {
        perProtocolMailRepositoryDefaultConfiguration.put(protocol, defConf);
    }
}