Java Code Examples for org.apache.commons.configuration2.Configuration#getStringArray()

The following examples show how to use org.apache.commons.configuration2.Configuration#getStringArray() . 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: ValidRcptMX.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Override
public void init(Configuration config) throws ConfigurationException {

    String[] networks = config.getStringArray("invalidMXNetworks");

    if (networks.length == 0) {

        Collection<String> bannedNetworks = Arrays.stream(networks)
            .map(String::trim)
            .collect(Guavate.toImmutableList());

        setBannedNetworks(bannedNetworks, dnsService);

        LOGGER.info("Invalid MX Networks: {}", bNetwork);
    } else {
        throw new ConfigurationException("Please configure at least on invalid MX network");
    }
}
 
Example 2
Source File: URIRBLHandler.java    From james-project with Apache License 2.0 6 votes vote down vote up
@Override
public void init(Configuration config) throws ConfigurationException {
    String[] servers = config.getStringArray("uriRblServers.server");
    Collection<String> serverCollection = new ArrayList<>();
    for (String rblServerName : servers) {
        serverCollection.add(rblServerName);
        LOGGER.info("Adding uriRBL server: {}", rblServerName);
    }
    if (serverCollection != null && serverCollection.size() > 0) {
        setUriRblServer(serverCollection);
    } else {
        throw new ConfigurationException("Please provide at least one server");
    }

    setGetDetail(config.getBoolean("getDetail", false));        
}
 
Example 3
Source File: TestServletRequestConfiguration.java    From commons-configuration with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a new servlet request configuration that is backed by the passed
 * in configuration.
 *
 * @param base the configuration with the underlying values
 * @return the servlet request configuration
 */
private ServletRequestConfiguration createConfiguration(final Configuration base)
{
    final ServletRequest request = new MockHttpServletRequest()
    {
        @Override
        public String[] getParameterValues(final String key)
        {
            return base.getStringArray(key);
        }

        @Override
        public Map<?, ?> getParameterMap()
        {
            return new ConfigurationMap(base);
        }
    };

    final ServletRequestConfiguration config = new ServletRequestConfiguration(request);
    config.setListDelimiterHandler(new DefaultListDelimiterHandler(','));
    return config;
}
 
Example 4
Source File: ClusterConfiguration.java    From james-project with Apache License 2.0 5 votes vote down vote up
private static List<Host> listCassandraServers(Configuration configuration) {
    String[] ipAndPorts = configuration.getStringArray(CASSANDRA_NODES);

    return Arrays.stream(ipAndPorts)
        .map(string -> Host.parseConfString(string, DEFAULT_CASSANDRA_PORT))
        .collect(Guavate.toImmutableList());
}
 
Example 5
Source File: MailetConfigImpl.java    From james-project with Apache License 2.0 5 votes vote down vote up
/**
 * Set the Avalon Configuration object for the mailet.
 * 
 * @param newConfiguration
 *            the new Configuration for the mailet
 */
public void setConfiguration(Configuration newConfiguration) {
    BaseHierarchicalConfiguration builder = new BaseHierarchicalConfiguration();
    
    // Disable the delimiter parsing. See JAMES-1232
    builder.setListDelimiterHandler(new DisabledListDelimiterHandler());
    Iterator<String> keys = newConfiguration.getKeys();
    while (keys.hasNext()) {
        String key = keys.next();
        String[] values = newConfiguration.getStringArray(key);
        // See JAMES-1177
        // Need to replace ".." with "."
        // See
        // http://commons.apache.org/configuration/userguide-1.2/howto_xml.html
        // Escaping dot characters in XML tags
        key = key.replaceAll("\\.\\.", "\\.");
        
        // Convert array values to a "," delimited string value
        StringBuilder valueBuilder = new StringBuilder();
        for (int i = 0; i < values.length; i++) {
            valueBuilder.append(values[i]);
            if (i + 1 < values.length) {
                valueBuilder.append(",");
            }
        }
        builder.addProperty(key, valueBuilder.toString());
    }

    configuration = builder;
}
 
Example 6
Source File: SpamTrapHandler.java    From james-project with Apache License 2.0 5 votes vote down vote up
@Override
public void init(Configuration config) throws ConfigurationException {
    String[] rcpts = config.getStringArray("spamTrapRecip");

    if (rcpts.length == 0) {
        setSpamTrapRecipients(Arrays.asList(rcpts));
    } else {
        throw new ConfigurationException("Please configure a spamTrapRecip.");
    }

    setBlockTime(config.getLong("blockTime", blockTime));
}
 
Example 7
Source File: SiteProperties.java    From engine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the list of available target IDs.
 */
public static String[] getAvailableTargetIds() {
    Configuration config = ConfigUtils.getCurrentConfig();
    if (config != null) {
        return config.getStringArray(AVAILABLE_TARGET_IDS_CONFIG_KEY);
    } else {
        return null;
    }
}
 
Example 8
Source File: SiteProperties.java    From engine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the folders that will be handled for targeted content.
 */
public static String[] getRootFolders() {
    Configuration config = ConfigUtils.getCurrentConfig();
    if (config != null) {
        return config.getStringArray(ROOT_FOLDERS_CONFIG_KEY);
    } else {
        return null;
    }
}
 
Example 9
Source File: SiteProperties.java    From engine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the patterns that a path might match if it should be excluded
 */
public static String[] getExcludePatterns() {
    Configuration config = ConfigUtils.getCurrentConfig();
    if (config != null) {
        return config.getStringArray(EXCLUDE_PATTERNS_CONFIG_KEY);
    } else {
        return null;
    }
}
 
Example 10
Source File: SiteProperties.java    From engine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the list of additional fields that navigation items should extract from the item descriptor.
 */
public static String[] getNavigationAdditionalFields() {
    Configuration config = ConfigUtils.getCurrentConfig();
    if(config != null && config.containsKey(NAVIGATION_ADDITIONAL_FIELDS_CONFIG_KEY)) {
        return config.getStringArray(NAVIGATION_ADDITIONAL_FIELDS_CONFIG_KEY);
    } else {
        return new String[] {};
    }
}
 
Example 11
Source File: SiteProperties.java    From engine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the list of descriptor folders to preload in the cache. Each folder can have it's depth specified
 * after a colon, like {@code PATH:DEPTH}
 */
public static final Map<String, Integer> getDescriptorPreloadFolders() {
    Configuration config = ConfigUtils.getCurrentConfig();
    if (config != null) {
        String[] folders = config.getStringArray(CACHE_WARMUP_DESCRIPTOR_FOLDERS_CONFIG_KEY);
        if (ArrayUtils.isNotEmpty(folders)) {
            return CacheUtils.parsePreloadFoldersList(folders);
        }
    }

    return Collections.emptyMap();
}
 
Example 12
Source File: SiteProperties.java    From engine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the list of content folders to preload in the cache. Each folder can have it's depth specified
 * after a colon, like {@code PATH:DEPTH}
 */
public static final Map<String, Integer> getContentPreloadFolders() {
    Configuration config = ConfigUtils.getCurrentConfig();
    if (config != null) {
        String[] folders = config.getStringArray(CACHE_WARMUP_CONTENT_FOLDERS_CONFIG_KEY);
        if (ArrayUtils.isNotEmpty(folders)) {
            return CacheUtils.parsePreloadFoldersList(folders);
        }
    }

    return Collections.emptyMap();
}