Java Code Examples for org.apache.commons.configuration2.HierarchicalConfiguration#configurationAt()

The following examples show how to use org.apache.commons.configuration2.HierarchicalConfiguration#configurationAt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestMergeCombiner.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
  * Helper method for checking the combined table structure.
  *
  * @param config the config
  * @return the node for the table element
  */
 private ImmutableNode checkTable(
         final HierarchicalConfiguration<ImmutableNode> config)
 {
     assertEquals("Wrong number of tables", 1,
             config.getMaxIndex("database.tables.table"));
     final HierarchicalConfiguration<ImmutableNode> c =
             config.configurationAt("database.tables.table(0)");
     assertEquals("Wrong table name", "documents", c.getString("name"));
     assertEquals("Wrong number of fields", 2,
             c.getMaxIndex("fields.field.name"));
     assertEquals("Wrong field", "docname",
             c.getString("fields.field(1).name"));

     final NodeHandler<ImmutableNode> nodeHandler = config.getNodeModel().getNodeHandler();
     final List<QueryResult<ImmutableNode>> nds =
             config.getExpressionEngine().query(nodeHandler.getRootNode(),
                     "database.tables.table",
                     nodeHandler);
     assertFalse("No node found", nds.isEmpty());
     assertFalse("Not a node result", nds.get(0).isAttributeResult());
     return nds.get(0).getNode();
}
 
Example 2
Source File: CamelMailetContainerModule.java    From james-project with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
HierarchicalConfiguration<ImmutableNode> getMailetContextConfiguration(ConfigurationProvider configurationProvider) throws ConfigurationException {
    HierarchicalConfiguration<ImmutableNode> mailetContainerConfiguration = configurationProvider.getConfiguration("mailetcontainer");
    try {
        return mailetContainerConfiguration.configurationAt("context");
    } catch (ConfigurationRuntimeException e) {
        LOGGER.warn("Could not locate configuration for Mailet context. Assuming empty configuration for this component.");
        return new BaseHierarchicalConfiguration();
    }
}
 
Example 3
Source File: CamelMailetContainerModule.java    From james-project with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
HierarchicalConfiguration<ImmutableNode> getProcessorConfiguration() throws ConfigurationException {
    HierarchicalConfiguration<ImmutableNode> mailetContainerConfiguration = configurationProvider.getConfiguration("mailetcontainer");
    try {
        return mailetContainerConfiguration.configurationAt("processors");
    } catch (ConfigurationRuntimeException e) {
        LOGGER.warn("Could not load configuration for Processors. Fallback to default.");
        return defaultProcessorsConfigurationSupplier.getDefaultConfiguration();
    }
}
 
Example 4
Source File: MailRepositoryStoreBeanFactory.java    From james-project with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * 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<ImmutableNode> repConf) throws ConfigurationException {

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

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

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

        LOGGER.info("Registering Repository instance of class {} to handle {} protocol requests", className, protocol);

        if (classes.get(new Protocol(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(new Protocol(protocol), className);

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

}
 
Example 5
Source File: FileConfigurationProvider.java    From james-project with Apache License 2.0 5 votes vote down vote up
private HierarchicalConfiguration<ImmutableNode> selectHierarchicalConfigPart(HierarchicalConfiguration<ImmutableNode> config, Iterable<String> configsPathParts) {
    HierarchicalConfiguration<ImmutableNode> currentConfig = config;
    for (String nextPathPart : configsPathParts) {
        currentConfig = currentConfig.configurationAt(nextPathPart);
    }
    return currentConfig;
}
 
Example 6
Source File: SiteAwareCORSFilter.java    From engine with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean isDisableCORS() {
    SiteContext siteContext = SiteContext.getCurrent();
    HierarchicalConfiguration config = siteContext.getConfig();
    try {
        HierarchicalConfiguration corsConfig = config.configurationAt(CONFIG_KEY);
        if (corsConfig != null) {
            return !corsConfig.getBoolean(ENABLE_KEY, false);
        }
    } catch (Exception e) {
        logger.debug("Site '{}' has no CORS configuration", siteContext.getSiteName());
    }
    return true;
}
 
Example 7
Source File: LdapRepositoryConfiguration.java    From james-project with Apache License 2.0 4 votes vote down vote up
public static LdapRepositoryConfiguration from(HierarchicalConfiguration<ImmutableNode> configuration) throws ConfigurationException {
    String ldapHost = configuration.getString("[@ldapHost]", "");
    String principal = configuration.getString("[@principal]", "");
    String credentials = configuration.getString("[@credentials]", "");
    String userBase = configuration.getString("[@userBase]");
    String userIdAttribute = configuration.getString("[@userIdAttribute]");
    String userObjectClass = configuration.getString("[@userObjectClass]");
    // Default is to use connection pooling
    boolean useConnectionPool = configuration.getBoolean("[@useConnectionPool]", USE_CONNECTION_POOL);
    int connectionTimeout = configuration.getInt("[@connectionTimeout]", NO_CONNECTION_TIMEOUT);
    int readTimeout = configuration.getInt("[@readTimeout]", NO_READ_TIME_OUT);
    // Default maximum retries is 1, which allows an alternate connection to
    // be found in a multi-homed environment
    int maxRetries = configuration.getInt("[@maxRetries]", 1);
    boolean supportsVirtualHosting = configuration.getBoolean(SUPPORTS_VIRTUAL_HOSTING, !ENABLE_VIRTUAL_HOSTING);
    // Default retry start interval is 0 second
    long retryStartInterval = configuration.getLong("[@retryStartInterval]", 0);
    // Default maximum retry interval is 60 seconds
    long retryMaxInterval = configuration.getLong("[@retryMaxInterval]", 60);
    int scale = configuration.getInt("[@retryIntervalScale]", 1000); // seconds

    HierarchicalConfiguration<ImmutableNode> restrictionConfig = null;
    // Check if we have a restriction we can use
    // See JAMES-1204
    if (configuration.containsKey("restriction[@memberAttribute]")) {
        restrictionConfig = configuration.configurationAt("restriction");
    }
    ReadOnlyLDAPGroupRestriction restriction = new ReadOnlyLDAPGroupRestriction(restrictionConfig);

    //see if there is a filter argument
    String filter = configuration.getString("[@filter]");

    Optional<String> administratorId = Optional.ofNullable(configuration.getString("[@administratorId]"));

    return new LdapRepositoryConfiguration(
        ldapHost,
        principal,
        credentials,
        userBase,
        userIdAttribute,
        userObjectClass,
        useConnectionPool,
        connectionTimeout,
        readTimeout,
        maxRetries,
        supportsVirtualHosting,
        retryStartInterval,
        retryMaxInterval,
        scale,
        restriction,
        filter,
        administratorId);
}
 
Example 8
Source File: ParsedConfiguration.java    From james-project with Apache License 2.0 4 votes vote down vote up
protected void configure(HierarchicalConfiguration<ImmutableNode> conf) throws ConfigurationException {
    setHost(conf.getString("host"));

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

    HierarchicalConfiguration<ImmutableNode> 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<ImmutableNode> fetched = conf.configurationAt("fetched");
    setLeave(fetched.getBoolean("[@leaveonserver]"));
    setMarkSeen(fetched.getBoolean("[@markseen]"));

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

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

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

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

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

        setRemoteReceivedHeaderIndex(remotereceivedheader.getInt("[@index]"));
        setRejectRemoteReceivedHeaderInvalid(remotereceivedheader.getBoolean("[@reject]"));
        setLeaveRemoteReceivedHeaderInvalid(remotereceivedheader.getBoolean("[@leaveonserver]"));
        setMarkRemoteReceivedHeaderInvalidSeen(remotereceivedheader.getBoolean("[@markseen]"));
    }

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

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

    LOGGER.info("Configured FetchMail fetch task {}", getFetchTaskName());
}
 
Example 9
Source File: MailRepositoryStoreConfiguration.java    From james-project with Apache License 2.0 4 votes vote down vote up
private static HierarchicalConfiguration<ImmutableNode> extraConfig(HierarchicalConfiguration<ImmutableNode> configuration) {
    if (configuration.getKeys("config").hasNext()) {
        return configuration.configurationAt("config");
    }
    return new BaseHierarchicalConfiguration();
}
 
Example 10
Source File: ConfigurationProviderImpl.java    From james-project with Apache License 2.0 4 votes vote down vote up
@Override
public HierarchicalConfiguration<ImmutableNode> getConfiguration(String name) throws ConfigurationException {

    HierarchicalConfiguration<ImmutableNode> conf = configurations.get(name);

    // Simply return the configuration if it is already loaded.
    if (conf != null) {
        return conf;
    } else {
        // Load the configuration.

        // Compute resourceName and configPart (if any, configPart can
        // remain null).
        int i = name.indexOf(".");
        String resourceName;
        String configPart = null;

        if (i > -1) {
            resourceName = name.substring(0, i);
            configPart = name.substring(i + 1);
        } else {
            resourceName = name;
        }

        Resource resource = loader.getResource(getConfigPrefix() + resourceName + CONFIGURATION_FILE_SUFFIX);

        if (resource.exists()) {
            try {
                HierarchicalConfiguration<ImmutableNode> config = getConfig(resource);
                if (configPart != null) {
                    return config.configurationAt(configPart);
                } else {
                    return config;
                }

            } catch (Exception e) {
                throw new ConfigurationException("Unable to load configuration for component " + name, e);
            }
        }
    }

    // Configuration was not loaded, throw exception.
    throw new ConfigurationException("Unable to load configuration for component " + name);

}