Example usage for org.apache.commons.configuration HierarchicalConfiguration getString

List of usage examples for org.apache.commons.configuration HierarchicalConfiguration getString

Introduction

In this page you can find the example usage for org.apache.commons.configuration HierarchicalConfiguration getString.

Prototype

public String getString(String key, String defaultValue) 

Source Link

Usage

From source file:com.servioticy.dispatcher.DispatcherContext.java

public void loadConf(String path) {
    HierarchicalConfiguration config;

    try {/*  w w  w. j  a v  a 2 s  . c om*/
        if (path == null) {
            config = new XMLConfiguration(DispatcherContext.DEFAULT_CONFIG_PATH);
        } else {
            config = new XMLConfiguration(path);
        }
        config.setExpressionEngine(new XPathExpressionEngine());

        this.restBaseURL = config.getString("servioticyAPI", this.restBaseURL);

        ArrayList<String> updates = new ArrayList<String>();
        if (config.containsKey("spouts/updates/addresses/address[1]")) {
            for (int i = 1; config.containsKey("spouts/updates/addresses/address[" + i + "]"); i++) {
                updates.add(config.getString("spouts/updates/addresses/address[" + i + "]"));
            }
        } else {
            for (String address : this.updatesAddresses) {
                updates.add(address);
            }
        }
        this.updatesAddresses = (String[]) updates.toArray(new String[] {});
        this.updatesPort = config.getInt("spouts/updates/port", this.updatesPort);
        this.updatesQueue = config.getString("spouts/updates/name", this.updatesQueue);

        ArrayList<String> actions = new ArrayList<String>();
        if (config.containsKey("spouts/actions/addresses/address[1]")) {
            for (int i = 1; config.containsKey("spouts/actions/addresses/address[" + i + "]"); i++) {
                actions.add(config.getString("spouts/actions/addresses/address[" + i + "]"));
            }
        } else {
            for (String address : this.actionsAddresses) {
                actions.add(address);
            }
        }
        this.actionsAddresses = (String[]) actions.toArray(new String[] {});
        this.actionsPort = config.getInt("spouts/actions/port", this.actionsPort);
        this.actionsQueue = config.getString("spouts/actions/name", this.actionsQueue);

        this.benchmark = config.getBoolean("benchmark", this.benchmark);

        this.externalPubAddress = config.getString("publishers/external/address", this.externalPubAddress);
        this.externalPubPort = config.getInt("publishers/external/port", this.externalPubPort);
        this.externalPubUser = config.getString("publishers/external/username", this.externalPubUser);
        this.externalPubPassword = config.getString("publishers/external/password", this.externalPubPassword);
        this.externalPubClassName = config.getString("publishers/external/class", this.externalPubClassName);

        this.internalPubAddress = config.getString("publishers/internal/address", this.internalPubAddress);
        this.internalPubPort = config.getInt("publishers/internal/port", this.internalPubPort);
        this.internalPubUser = config.getString("publishers/internal/username", this.internalPubUser);
        this.internalPubPassword = config.getString("publishers/internal/password", this.internalPubPassword);
        this.internalPubClassName = config.getString("publishers/internal/class", this.internalPubClassName);

        this.actionsPubAddress = config.getString("publishers/actions/address", this.actionsPubAddress);
        this.actionsPubPort = config.getInt("publishers/actions/port", this.actionsPubPort);
        this.actionsPubUser = config.getString("publishers/actions/username", this.actionsPubUser);
        this.actionsPubPassword = config.getString("publishers/actions/password", this.actionsPubPassword);
        this.actionsPubClassName = config.getString("publishers/actions/class", this.actionsPubClassName);

        this.benchResultsDir = config.getString("benchResultsDir", this.benchResultsDir);

    } catch (Exception e) {
        e.printStackTrace();
        return;
    }
}

From source file:com.vmware.qe.framework.datadriven.impl.filter.DataFilterBasedOnTestId.java

@Override
public boolean canRun(String className, HierarchicalConfiguration dataToFilter,
        HierarchicalConfiguration context) {
    String testIdKey = className + "-testids";
    String testIdArray[];//from  w w  w .j  av  a 2s. co  m
    testIdArray = context.getStringArray(testIdKey);
    testIdArray = testIdArray == null ? DDConfig.getSingleton().getData().getStringArray(testIdKey)
            : testIdArray;
    List<String> testIds = Arrays.asList(testIdArray);
    if (testIds.isEmpty()) {
        return true;
    }
    String testId = dataToFilter.getString(TAG_TESTID_ATTR, "");
    boolean canRun = false;
    // Ignoring testIds if they are not in the selected test-ids to run
    if (testIds != null && !testIds.isEmpty()) {
        canRun = testIds.contains(testId);
    }
    log.debug("CanRun: {}", canRun);
    return canRun;
}

From source file:com.norconex.collector.http.url.impl.HtmlLinkExtractor.java

@Override
public void loadFromXML(Reader in) {
    XMLConfiguration xml = ConfigurationUtil.newXMLConfiguration(in);
    setMaxURLLength(xml.getInt("[@maxURLLength]", getMaxURLLength()));
    setIgnoreNofollow(xml.getBoolean("[@ignoreNofollow]", isIgnoreNofollow()));
    setKeepReferrerData(xml.getBoolean("[@keepReferrerData]", isKeepReferrerData()));

    // Content Types
    ContentType[] cts = ContentType/*  ww w.j  a  v a  2s .  co m*/
            .valuesOf(StringUtils.split(StringUtils.trimToNull(xml.getString("contentTypes")), ", "));
    if (!ArrayUtils.isEmpty(cts)) {
        setContentTypes(cts);
    }

    // tag & attributes
    List<HierarchicalConfiguration> tagNodes = xml.configurationsAt("tags.tag");
    if (!tagNodes.isEmpty()) {
        clearLinkTags();
        for (HierarchicalConfiguration tagNode : tagNodes) {
            String name = tagNode.getString("[@name]", null);
            String attr = tagNode.getString("[@attribute]", null);
            if (!StringUtils.isAnyBlank(name, attr)) {
                addLinkTag(name, attr);
            }
        }
    }
}

From source file:com.norconex.collector.http.url.impl.GenericLinkExtractor.java

@Override
public void loadFromXML(Reader in) {
    XMLConfiguration xml = ConfigurationUtil.newXMLConfiguration(in);
    setMaxURLLength(xml.getInt("[@maxURLLength]", getMaxURLLength()));
    setIgnoreNofollow(xml.getBoolean("[@ignoreNofollow]", isIgnoreNofollow()));
    setKeepReferrerData(xml.getBoolean("[@keepReferrerData]", isKeepReferrerData()));
    if (xml.getBoolean("[@keepFragment]", false)) {
        LOG.warn("'keepFragment' on GenericLinkExtractor was removed. "
                + "Instead, URL normalization now always takes place by "
                + "default unless disabled, and removeFragment is part of "
                + "the default normalization rules.");
    }//from ww  w  .j ava2  s  . c om

    // Content Types
    ContentType[] cts = ContentType
            .valuesOf(StringUtils.split(StringUtils.trimToNull(xml.getString("contentTypes")), ", "));
    if (!ArrayUtils.isEmpty(cts)) {
        setContentTypes(cts);
    }

    // tag & attributes
    List<HierarchicalConfiguration> tagNodes = xml.configurationsAt("tags.tag");
    if (!tagNodes.isEmpty()) {
        clearLinkTags();
        for (HierarchicalConfiguration tagNode : tagNodes) {
            String name = tagNode.getString("[@name]", null);
            String attr = tagNode.getString("[@attribute]", null);
            if (StringUtils.isNotBlank(name)) {
                addLinkTag(name, attr);
            }
        }
    }
}

From source file:net.datenwerke.sandbox.util.SandboxParser.java

protected void configureThreadRestrictions(SandboxContext context, HierarchicalConfiguration contextConf) {
    long maximumRunTime = contextConf.getLong("[@maximumRunTime]", -1);
    context.setMaximumRunTime(maximumRunTime);

    String maximumRunTimeUnit = contextConf.getString("[@maximumRunTimeUnit]", null);
    if (null != maximumRunTimeUnit && !"".equals(maximumRunTimeUnit.trim()))
        context.setMaximumRunTimeUnit(TimeUnit.valueOf(maximumRunTimeUnit.toUpperCase()));

    String maximumRunTimeMode = contextConf.getString("[@maximumRunTimeMode]", null);
    if (null != maximumRunTimeMode && !"".equals(maximumRunTimeMode.trim()))
        context.setMaximumRuntimeMode(RuntimeMode.valueOf(maximumRunTimeMode.toUpperCase()));

    int maxStackDepth = contextConf.getInteger("[@maximumStackDepth]", -1);
    context.setMaximumStackDepth(maxStackDepth);
}

From source file:com.moviejukebox.model.Library.java

private static void fillCategoryMap(String xmlCategoryFilename) {
    File xmlFile = new File(xmlCategoryFilename);
    if (xmlFile.exists() && xmlFile.isFile() && xmlCategoryFilename.toUpperCase().endsWith("XML")) {

        try {//from   w w w. j  ava  2  s. c om
            XMLConfiguration c = new XMLConfiguration(xmlFile);

            List<HierarchicalConfiguration> categories = c.configurationsAt("category");
            for (HierarchicalConfiguration category : categories) {
                boolean enabled = Boolean.parseBoolean(category.getString("enable", TRUE));

                if (enabled) {
                    String origName = category.getString(LIT_NAME);
                    String newName = category.getString("rename", origName);
                    CATEGORIES_MAP.put(origName, newName);
                    //logger.debug("Added category '" + origName + "' with name '" + newName + "'");
                }
            }
        } catch (ConfigurationException error) {
            LOG.error("Failed parsing moviejukebox category input file: {}", xmlFile.getName());
            LOG.error(SystemTools.getStackTrace(error));
        }
    } else {
        LOG.error("The moviejukebox category input file you specified is invalid: {}", xmlFile.getName());
    }
}

From source file:com.houghtonassociates.bamboo.plugins.GerritRepositoryAdapter.java

/**
 * Determine if plan uses this repository
 * //  w w  w.  jav a  2  s .c om
 * @param chain
 * @param isRemoteTrigger
 *            , dertmined if plan uses repository for remote use
 * @return
 */
private boolean isRepoTriggerFor(ImmutableChain chain, boolean isRemoteTrigger) {
    List<BuildStrategy> strats = chain.getTriggers();
    List<RepositoryDefinition> cRepos = new ArrayList<RepositoryDefinition>();

    cRepos = chain.getEffectiveRepositoryDefinitions();

    for (RepositoryDefinition rd : cRepos) {
        if (rd.getName().toLowerCase().equals(this.getName().toLowerCase())
                && rd.getPluginKey().equals(this.getKey())) {
            HierarchicalConfiguration hconfig = rd.getConfiguration();
            String strDefBranch = hconfig.getString(REPOSITORY_GERRIT_DEFAULT_BRANCH, "");
            String strCustBranch = hconfig.getString(REPOSITORY_GERRIT_CUSTOM_BRANCH, "");

            if (this.getVcsBranch().isEqualToBranchWith(strDefBranch)
                    || this.getVcsBranch().isEqualToBranchWith(strCustBranch)) {

                if (isRemoteTrigger) {
                    for (BuildStrategy s : strats) {
                        if (s instanceof TriggeredBuildStrategy) {
                            TriggeredBuildStrategy tbs = Narrow.downTo(s, TriggeredBuildStrategy.class);

                            Set<Long> repos = tbs.getTriggeringRepositories();

                            if (repos.contains(rd.getId())) {
                                return true;
                            } else {
                                for (Long rID : repos) {
                                    RepositoryDataEntity rde = repositoryDefinitionManager
                                            .getRepositoryDataEntity(rID);
                                    if (rde.getName().equals(this.getName())
                                            && rde.getPluginKey().equals(this.getKey())) {
                                        return true;
                                    }
                                }
                            }
                        } else {
                            return false;
                        }
                    }
                } else {
                    return true;
                }
            }

        }
    }

    return false;
}

From source file:org.apache.james.container.spring.bean.factorypostprocessor.EventsConfigurationBeanFactoryPostProcessor.java

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    ConfigurationProvider confProvider = beanFactory.getBean(ConfigurationProvider.class);
    try {/*from   w  w w  . j  a  v a 2 s. c om*/
        HierarchicalConfiguration config = confProvider.getConfiguration("events");
        String type = config.getString("type", "default");
        String serialization = config.getString("serialization", "json");
        String publisher = config.getString("publisher", "kafka");
        String registration = config.getString("registration", "cassandra");
        String delivery = config.getString("delivery", "synchronous");
        String delegatingListenerAlias = getDelegatingListenerAlias(type);
        String serializationAlias = getSerializationAlias(serialization);
        String registrationAlias = getRegistrationAlias(registration);
        String deliveryAlias = getDeliveryString(delivery);
        String publisherAlias = null;
        String consumerAlias = null;

        if (publisher.equals("kafka")) {
            publisherAlias = "kafka-publisher";
            consumerAlias = "kafka-consumer";
        }

        detectInvalidValue(delegatingListenerAlias, "Delegating listener type " + type + " not supported!");
        detectInvalidValue(deliveryAlias, "Event delivery " + delivery + " not supported");
        beanFactory.registerAlias(delegatingListenerAlias, "delegating-listener");
        beanFactory.registerAlias(deliveryAlias, "event-delivery");
        if (!delegatingListenerAlias.equals("default")) {
            detectInvalidValue(serializationAlias,
                    "Serialization system type " + serialization + " not supported!");
            detectInvalidValue(publisherAlias, "Publisher system type " + publisher + " not supported!");
            beanFactory.registerAlias(serializationAlias, "event-serializer");
            beanFactory.registerAlias(publisherAlias, "publisher");
            beanFactory.registerAlias(consumerAlias, "consumer");
            if (delegatingListenerAlias.equals("registered")) {
                detectInvalidValue(registrationAlias,
                        "Registration system type " + registration + " not supported!");
                beanFactory.registerAlias(registrationAlias, "distant-mailbox-path-register-mapper");
            }
        }

    } catch (ConfigurationException e) {
        throw new FatalBeanException("Unable to config the mailboxmanager", e);
    }
}

From source file:org.apache.james.container.spring.bean.factorypostprocessor.IndexerConfigurationBeanFactoryPostProcessor.java

/**
 * @see org.springframework.beans.factory.config.BeanFactoryPostProcessor#postProcessBeanFactory
 * (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
 *//*from  w  w  w .  jav a  2 s .co  m*/
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    ConfigurationProvider confProvider = beanFactory.getBean(ConfigurationProvider.class);
    try {
        HierarchicalConfiguration config = confProvider.getConfiguration("indexer");
        String provider = config.getString("provider", "lazyIndex");

        BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
        String indexer = null;
        String reIndexer = null;
        if (provider.equalsIgnoreCase("lazyIndex")) {
            indexer = "lazyIndex";
            reIndexer = "fake-reindexer";
        } else if (provider.equalsIgnoreCase("elasticsearch")) {
            indexer = "elasticsearch-listener";
            reIndexer = "reindexer-impl";
        }

        if (indexer == null)
            throw new ConfigurationException("Indexer provider " + provider + " not supported!");
        registry.registerAlias(indexer, "indexer");
        registry.registerAlias(reIndexer, "reindexer");

    } catch (ConfigurationException e) {
        throw new FatalBeanException("Unable to config the indexer", e);
    }

}

From source file:org.apache.james.container.spring.bean.factorypostprocessor.MailboxConfigurationBeanFactoryPostProcessor.java

/**
 * @see org.springframework.beans.factory.config.BeanFactoryPostProcessor#postProcessBeanFactory
 * (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)
 *///ww  w. ja v  a  2 s  .  c  o  m
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    ConfigurationProvider confProvider = beanFactory.getBean(ConfigurationProvider.class);
    try {
        HierarchicalConfiguration config = confProvider.getConfiguration("mailbox");
        String provider = config.getString("provider", "jpa");

        BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
        String mailbox = null;
        String subscription = null;
        String messageMapperFactory = null;
        String mailboxIdDeserializer = null;
        if (provider.equalsIgnoreCase("jpa")) {
            mailbox = "jpa-mailboxmanager";
            subscription = "jpa-subscriptionManager";
            messageMapperFactory = "jpa-sessionMapperFactory";
            mailboxIdDeserializer = "jpa-mailbox-id-deserializer";
        } else if (provider.equalsIgnoreCase("memory")) {
            mailbox = "memory-mailboxmanager";
            subscription = "memory-subscriptionManager";
            messageMapperFactory = "memory-sessionMapperFactory";
            mailboxIdDeserializer = "memory-mailbox-id-deserializer";
        } else if (provider.equalsIgnoreCase("jcr")) {
            mailbox = "jcr-mailboxmanager";
            subscription = "jcr-subscriptionManager";
            messageMapperFactory = "jcr-sessionMapperFactory";
            mailboxIdDeserializer = "jcr-mailbox-id-deserializer";
        } else if (provider.equalsIgnoreCase("maildir")) {
            mailbox = "maildir-mailboxmanager";
            subscription = "maildir-subscriptionManager";
            messageMapperFactory = "maildir-sessionMapperFactory";
            mailboxIdDeserializer = "maildir-mailbox-id-deserializer";
        } else if (provider.equalsIgnoreCase("hbase")) {
            mailbox = "hbase-mailboxmanager";
            subscription = "hbase-subscriptionManager";
            messageMapperFactory = "hbase-sessionMapperFactory";
            mailboxIdDeserializer = "hbase-mailbox-id-deserializer";
        } else if (provider.equalsIgnoreCase("cassandra")) {
            mailbox = "cassandra-mailboxmanager";
            subscription = "cassandra-subscriptionManager";
            messageMapperFactory = "cassandra-sessionMapperFactory";
            mailboxIdDeserializer = "cassandra-mailbox-id-deserializer";
        }

        if (mailbox == null)
            throw new ConfigurationException("Mailboxmanager provider " + provider + " not supported!");
        registry.registerAlias(mailbox, "mailboxmanager");
        registry.registerAlias(subscription, "subscriptionManager");
        registry.registerAlias(messageMapperFactory, "messageMapperFactory");
        registry.registerAlias(mailboxIdDeserializer, "mailbox-id-deserializer");

    } catch (ConfigurationException e) {
        throw new FatalBeanException("Unable to config the mailboxmanager", e);
    }

}