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

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

Introduction

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

Prototype

String[] getStringArray(String key);

Source Link

Document

Get an array of strings associated with the given configuration key.

Usage

From source file:org.apache.atlas.web.integration.BaseResourceIT.java

@BeforeClass
public void setUp() throws Exception {

    //set high timeouts so that tests do not fail due to read timeouts while you
    //are stepping through the code in a debugger
    ApplicationProperties.get().setProperty("atlas.client.readTimeoutMSecs", "100000000");
    ApplicationProperties.get().setProperty("atlas.client.connectTimeoutMSecs", "100000000");

    Configuration configuration = ApplicationProperties.get();
    atlasUrls = configuration.getStringArray(ATLAS_REST_ADDRESS);

    if (atlasUrls == null || atlasUrls.length == 0) {
        atlasUrls = new String[] { "http://localhost:21000/" };
    }//  www. ja v  a  2  s .c om

    if (!AuthenticationUtil.isKerberosAuthenticationEnabled()) {
        atlasClientV1 = new AtlasClient(atlasUrls, new String[] { "admin", "admin" });
        atlasClientV2 = new AtlasClientV2(atlasUrls, new String[] { "admin", "admin" });
    } else {
        atlasClientV1 = new AtlasClient(atlasUrls);
        atlasClientV2 = new AtlasClientV2(atlasUrls);
    }
}

From source file:org.apache.james.backends.cassandra.init.configuration.ClusterConfiguration.java

private static List<Host> listCassandraServers(Configuration configuration) {
    String[] ipAndPorts = configuration.getStringArray(CASSANDRA_NODES);

    return Arrays.stream(ipAndPorts)
            .map(string -> Host.parseConfString(string, ClusterBuilder.DEFAULT_CASSANDRA_PORT))
            .collect(Guavate.toImmutableList());
}

From source file:org.apache.james.backends.es.ElasticSearchConfiguration.java

private static ImmutableList<Host> getHosts(Configuration propertiesReader) throws ConfigurationException {
    AbstractConfiguration.setDefaultListDelimiter(',');
    Optional<String> masterHost = Optional
            .ofNullable(propertiesReader.getString(ELASTICSEARCH_MASTER_HOST, null));
    Optional<Integer> masterPort = Optional.ofNullable(propertiesReader.getInteger(ELASTICSEARCH_PORT, null));
    List<String> multiHosts = Arrays.asList(propertiesReader.getStringArray(ELASTICSEARCH_HOSTS));

    validateHostsConfigurationOptions(masterHost, masterPort, multiHosts);

    if (masterHost.isPresent()) {
        return ImmutableList.of(Host.from(masterHost.get(), masterPort.get()));
    } else {// w ww .j a  v a2  s .  c o  m
        return multiHosts.stream().map(ipAndPort -> Host.parse(ipAndPort, DEFAULT_PORT_AS_OPTIONAL))
                .collect(Guavate.toImmutableList());
    }
}

From source file:org.apache.james.mailetcontainer.impl.MailetConfigImpl.java

/**
 * Set the Avalon Configuration object for the mailet.
 * //from   w  ww.  j av a  2s.  c  o m
 * @param newConfiguration
 *            the new Configuration for the mailet
 */
public void setConfiguration(Configuration newConfiguration) {
    DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();

    // Disable the delimiter parsing. See JAMES-1232
    builder.setDelimiterParsingDisabled(true);
    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;
}

From source file:org.apache.james.modules.mailbox.TikaConfigurationReader.java

public static TikaConfiguration readTikaConfiguration(Configuration configuration) {
    AbstractConfiguration.setDefaultListDelimiter(',');
    Optional<Boolean> enabled = Optional.ofNullable(configuration.getBoolean(TIKA_ENABLED, null));

    Optional<Boolean> cacheEnabled = Optional.ofNullable(configuration.getBoolean(TIKA_CACHE_ENABLED, null));

    Optional<String> host = Optional.ofNullable(configuration.getString(TIKA_HOST, null));

    Optional<Integer> port = Optional.ofNullable(configuration.getInteger(TIKA_PORT, null));

    Optional<Integer> timeoutInMillis = Optional.ofNullable(configuration.getInteger(TIKA_TIMEOUT_IN_MS, null));

    Optional<Duration> cacheEvictionPeriod = Optional
            .ofNullable(configuration.getString(TIKA_CACHE_EVICTION_PERIOD, null))
            .map(rawString -> TimeConverter.getMilliSeconds(rawString, TimeConverter.Unit.SECONDS))
            .map(Duration::ofMillis);

    Optional<Long> cacheWeight = Optional.ofNullable(configuration.getString(TIKA_CACHE_WEIGHT_MAX, null))
            .map(Throwing.function(Size::parse)).map(Size::asBytes);

    Set<String> contentTypeBlacklist = StreamUtils
            .ofNullable(configuration.getStringArray(TIKA_CONTENT_TYPE_BLACKLIST)).map(String::trim)
            .collect(ImmutableSet.toImmutableSet());

    return TikaConfiguration.builder().enable(enabled).host(host).port(port).timeoutInMillis(timeoutInMillis)
            .cacheEnable(cacheEnabled).cacheEvictionPeriod(cacheEvictionPeriod).cacheWeightInBytes(cacheWeight)
            .contentTypeBlacklist(contentTypeBlacklist).build();
}

From source file:org.apache.james.smtpserver.fastfail.SpamTrapHandler.java

@Override
public void init(Configuration config) throws ConfigurationException {
    String[] rcpts = config.getStringArray("spamTrapRecip");

    if (rcpts.length == 0) {
        setSpamTrapRecipients(Arrays.asList(rcpts));
    } else {/*from w w  w  .  ja v  a2  s  . c om*/
        throw new ConfigurationException("Please configure a spamTrapRecip.");
    }

    setBlockTime(config.getLong("blockTime", blockTime));
}

From source file:org.apache.james.smtpserver.fastfail.URIRBLHandler.java

@Override
public void init(Configuration config) throws ConfigurationException {
    String[] servers = config.getStringArray("uriRblServers.server");
    Collection<String> serverCollection = new ArrayList<String>();
    for (String rblServerName : servers) {
        serverCollection.add(rblServerName);
        if (serviceLog.isInfoEnabled()) {
            serviceLog.info("Adding uriRBL server: " + rblServerName);
        }/*w  w w  . j  ava  2 s  .c  o  m*/
    }
    if (serverCollection != null && serverCollection.size() > 0) {
        setUriRblServer(serverCollection);
    } else {
        throw new ConfigurationException("Please provide at least one server");
    }

    setGetDetail(config.getBoolean("getDetail", false));
}

From source file:org.apache.james.smtpserver.fastfail.ValidRcptMX.java

@Override
public void init(Configuration config) throws ConfigurationException {

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

    if (networks.length == 0) {

        Collection<String> bannedNetworks = new ArrayList<String>();
        for (String network : networks) {
            bannedNetworks.add(network.trim());
        }//w w  w  . j a  v a2  s . com

        setBannedNetworks(bannedNetworks, dnsService);

        serviceLog.info("Invalid MX Networks: " + bNetwork.toString());

    } else {
        throw new ConfigurationException("Please configure at least on invalid MX network");
    }
}

From source file:org.apache.juddi.v3.client.config.ClientConfig.java

private Map<String, UDDIClerk> readClerkConfig(Configuration config, Map<String, UDDINode> uddiNodes)
        throws ConfigurationException {
    clientName = config.getString("client[@name]");
    clientCallbackUrl = config.getString("client[@callbackUrl]");
    Map<String, UDDIClerk> clerks = new HashMap<String, UDDIClerk>();
    if (config.containsKey("client.clerks.clerk[@name]")) {
        String[] names = config.getStringArray("client.clerks.clerk[@name]");

        log.debug("clerk names=" + names.length);
        for (int i = 0; i < names.length; i++) {
            UDDIClerk uddiClerk = new UDDIClerk();
            uddiClerk.setManagerName(clientName);
            uddiClerk.setName(config.getString("client.clerks.clerk(" + i + ")[@name]"));
            String nodeRef = config.getString("client.clerks.clerk(" + i + ")[@node]");
            if (!uddiNodes.containsKey(nodeRef))
                throw new ConfigurationException("Could not find Node with name=" + nodeRef);
            UDDINode uddiNode = uddiNodes.get(nodeRef);
            uddiClerk.setUDDINode(uddiNode);
            uddiClerk.setPublisher(config.getString("client.clerks.clerk(" + i + ")[@publisher]"));
            uddiClerk.setPassword(config.getString("client.clerks.clerk(" + i + ")[@password]"));
            uddiClerk.setIsPasswordEncrypted(
                    config.getBoolean("client.clerks.clerk(" + i + ")[@isPasswordEncrypted]", false));
            uddiClerk.setCryptoProvider(config.getString("client.clerks.clerk(" + i + ")[@cryptoProvider]"));

            String clerkBusinessKey = config.getString("client.clerks.clerk(" + i + ")[@businessKey]");
            String clerkBusinessName = config.getString("client.clerks.clerk(" + i + ")[@businessName]");
            String clerkKeyDomain = config.getString("client.clerks.clerk(" + i + ")[@keyDomain]");

            String[] classes = config.getStringArray("client.clerks.clerk(" + i + ").class");
            uddiClerk.setClassWithAnnotations(classes);

            int numberOfWslds = config.getStringArray("client.clerks.clerk(" + i + ").wsdl").length;
            if (numberOfWslds > 0) {
                UDDIClerk.WSDL[] wsdls = new UDDIClerk.WSDL[numberOfWslds];
                for (int w = 0; w < wsdls.length; w++) {
                    UDDIClerk.WSDL wsdl = uddiClerk.new WSDL();
                    String fileName = config.getString("client.clerks.clerk(" + i + ").wsdl(" + w + ")");
                    wsdl.setFileName(fileName);
                    String businessKey = config
                            .getString("client.clerks.clerk(" + i + ").wsdl(" + w + ")[@businessKey]");
                    String businessName = config
                            .getString("client.clerks.clerk(" + i + ").wsdl(" + w + ")[@businessName]");
                    String keyDomain = config
                            .getString("client.clerks.clerk(" + i + ").wsdl(" + w + ")[@keyDomain]");
                    if (businessKey == null)
                        businessKey = clerkBusinessKey;
                    if (businessKey == null)
                        businessKey = uddiClerk.getUDDINode().getProperties().getProperty("businessKey");
                    if (businessKey == null) {
                        //use key convention to build the businessKey
                        if (businessName == null)
                            businessName = clerkBusinessName;
                        if (keyDomain == null)
                            keyDomain = clerkKeyDomain;
                        if (keyDomain == null)
                            keyDomain = uddiClerk.getUDDINode().getProperties().getProperty("keyDomain");
                        if ((businessName == null
                                && !uddiClerk.getUDDINode().getProperties().containsKey("businessName"))
                                || keyDomain == null
                                        && !uddiClerk.getUDDINode().getProperties().containsKey("keyDomain"))
                            throw new ConfigurationException("Either the wsdl(" + wsdls[w] + ") or clerk ("
                                    + uddiClerk.name
                                    + ") elements require a businessKey, or businessName & keyDomain attributes");
                        else {
                            Properties properties = new Properties(uddiClerk.getUDDINode().getProperties());
                            if (businessName != null)
                                properties.put("businessName", businessName);
                            if (keyDomain != null)
                                properties.put("keyDomain", keyDomain);
                            businessKey = UDDIKeyConvention.getBusinessKey(properties);
                        }/*from w  w w . j  ava2 s  .com*/
                    }
                    if (!businessKey.toLowerCase().startsWith("uddi:")
                            || !businessKey.substring(5).contains(":")) {
                        throw new ConfigurationException("The businessKey " + businessKey
                                + " does not implement a valid UDDI v3 key format.");
                    }
                    wsdl.setBusinessKey(businessKey);
                    if (keyDomain == null) {
                        keyDomain = businessKey.split(":")[1];
                    }
                    wsdl.setKeyDomain(keyDomain);
                    wsdls[w] = wsdl;
                }
                uddiClerk.setWsdls(wsdls);
            }

            clerks.put(names[i], uddiClerk);
        }
    }
    return clerks;
}

From source file:org.apache.juddi.v3.client.config.ClientConfig.java

private Map<String, UDDINode> readNodeConfig(Configuration config, Properties properties)
        throws ConfigurationException {
    String[] names = config.getStringArray("client.nodes.node.name");
    Map<String, UDDINode> nodes = new HashMap<String, UDDINode>();
    log.debug("node names=" + names.length);
    for (int i = 0; i < names.length; i++) {
        UDDINode uddiNode = new UDDINode();
        String nodeName = config.getString("client.nodes.node(" + i + ").name");
        String[] propertyKeys = config
                .getStringArray("client.nodes.node(" + i + ").properties.property[@name]");

        if (propertyKeys != null && propertyKeys.length > 0) {
            if (properties == null)
                properties = new Properties();
            for (int p = 0; p < propertyKeys.length; p++) {
                String name = config
                        .getString("client.nodes.node(" + i + ").properties.property(" + p + ")[@name]");
                String value = config
                        .getString("client.nodes.node(" + i + ").properties.property(" + p + ")[@value]");
                log.debug("Property: name=" + name + " value=" + value);
                properties.put(name, value);
            }/*from w  w w.  ja va 2  s. c om*/
            uddiNode.setProperties(properties);
        }

        uddiNode.setHomeJUDDI(config.getBoolean("client.nodes.node(" + i + ")[@isHomeJUDDI]", false));
        uddiNode.setName(
                TokenResolver.replaceTokens(config.getString("client.nodes.node(" + i + ").name"), properties));
        uddiNode.setClientName(TokenResolver.replaceTokens(config.getString("client[@name]"), properties));
        uddiNode.setDescription(TokenResolver
                .replaceTokens(config.getString("client.nodes.node(" + i + ").description"), properties));
        uddiNode.setProxyTransport(TokenResolver
                .replaceTokens(config.getString("client.nodes.node(" + i + ").proxyTransport"), properties));
        uddiNode.setInquiryUrl(TokenResolver
                .replaceTokens(config.getString("client.nodes.node(" + i + ").inquiryUrl"), properties));
        uddiNode.setInquiryRESTUrl(TokenResolver
                .replaceTokens(config.getString("client.nodes.node(" + i + ").inquiryRESTUrl"), properties));
        uddiNode.setPublishUrl(TokenResolver
                .replaceTokens(config.getString("client.nodes.node(" + i + ").publishUrl"), properties));
        uddiNode.setCustodyTransferUrl(TokenResolver.replaceTokens(
                config.getString("client.nodes.node(" + i + ").custodyTransferUrl"), properties));
        uddiNode.setSecurityUrl(TokenResolver
                .replaceTokens(config.getString("client.nodes.node(" + i + ").securityUrl"), properties));
        uddiNode.setSubscriptionUrl(TokenResolver
                .replaceTokens(config.getString("client.nodes.node(" + i + ").subscriptionUrl"), properties));
        uddiNode.setSubscriptionListenerUrl(TokenResolver.replaceTokens(
                config.getString("client.nodes.node(" + i + ").subscriptionListenerUrl"), properties));
        uddiNode.setJuddiApiUrl(TokenResolver
                .replaceTokens(config.getString("client.nodes.node(" + i + ").juddiApiUrl"), properties));
        uddiNode.setFactoryInitial(TokenResolver.replaceTokens(
                config.getString("client.nodes.node(" + i + ").javaNamingFactoryInitial"), properties));
        uddiNode.setFactoryURLPkgs(TokenResolver.replaceTokens(
                config.getString("client.nodes.node(" + i + ").javaNamingFactoryUrlPkgs"), properties));
        uddiNode.setFactoryNamingProvider(TokenResolver.replaceTokens(
                config.getString("client.nodes.node(" + i + ").javaNamingProviderUrl"), properties));
        nodes.put(nodeName, uddiNode);
    }
    return nodes;
}