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

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

Introduction

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

Prototype

String getString(String key);

Source Link

Document

Get a string associated with the given configuration key.

Usage

From source file:net.sf.jclal.classifier.WekaClassifier.java

/**
 *
 * @param configuration The configuration object for WekaClassifier.
 *The XML labels supported are://from  w  w  w .j  a  v  a 2  s  . c om
 * <ul>
 * <li>
 * <b>classifier type= class</b>
 * <p>
 * Package: weka.classifiers</p>
 * <p>
 * Class: All</p>
 * </li>
 * </ul>
 */
@Override
public void configure(Configuration configuration) {

    String classifierError = "classifier type= ";
    try {

        // classifier classname
        String classifierClassname = configuration.getString("classifier[@type]");
        classifierError += classifierClassname;
        // classifier class
        Class<? extends Classifier> classifierClass = (Class<? extends Classifier>) Class
                .forName(classifierClassname);
        // classifier instance
        Classifier classifierTemp = classifierClass.newInstance();
        // Configure classifier (if necessary)
        if (classifierTemp instanceof IConfigure) {
            ((IConfigure) classifierTemp).configure(configuration.subset("classifier"));
        }
        // Add this classifier
        setClassifier(classifierTemp);
    } catch (ClassNotFoundException e) {
        throw new ConfigurationRuntimeException("\nIllegal classifier classname: " + classifierError, e);
    } catch (InstantiationException e) {
        throw new ConfigurationRuntimeException("\nIllegal classifier classname: " + classifierError, e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationRuntimeException("\nIllegal classifier classname: " + classifierError, e);
    }
}

From source file:edu.lternet.pasta.client.LoginClient.java

/**
 * Create an new LoginService object with the user's credentials and, if the
 * user's authentication is successful, place the user's authentication token
 * into the "tokenstore" for future use.
 * //ww  w  .j  ava2  s.  c om
 * @param uid
 *          The user identifier.
 * @param password
 *          The user password.
 * 
 * @throws PastaAuthenticationException
 */
public LoginClient(String uid, String password) throws PastaAuthenticationException {

    Configuration options = ConfigurationListener.getOptions();

    this.pastaHost = options.getString("pasta.hostname");
    this.pastaProtocol = options.getString("pasta.protocol");
    this.pastaPort = options.getInt("pasta.port");

    String pastaUrl = PastaClient.composePastaUrl(this.pastaProtocol, this.pastaHost, this.pastaPort);
    this.LOGIN_URL = pastaUrl + "/package/";

    String token = this.login(uid, password);

    if (token == null) {
        String gripe = "User '" + uid + "' did not successfully authenticate.";
        throw new PastaAuthenticationException(gripe);
    } else {
        TokenManager tokenManager = new TokenManager();
        try {
            tokenManager.setToken(uid, token);
        } catch (SQLException e) {
            logger.error(e);
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            logger.error(e);
            e.printStackTrace();
        }
    }

}

From source file:de.chdev.artools.loga.controller.SqlController.java

private boolean checkSqlCommit(String textWoPrefix, int lineNumber) {
    Configuration keywords = KeywordLoader.getConfiguration(PREFIX);
    String regexKey = keywords.getString("sql.commit");
    Pattern p = Pattern.compile(regexKey);
    Matcher m = p.matcher(textWoPrefix.trim());
    boolean valid = m.matches();
    if (valid) {/*from w w  w . j  a v  a 2s .  c  o m*/

        LogElement parent = mainController.getLastOpenLogElement();

        // Extract API information
        String temp = textWoPrefix;
        String threadId = temp.substring(0, temp.indexOf(">") + 1);
        temp = temp.substring(threadId.length());
        String rpcId = temp.substring(0, temp.indexOf(">") + 1);
        temp = temp.substring(rpcId.length());
        String queue = temp.substring(0, temp.indexOf(">") + 1);
        temp = temp.substring(queue.length());
        String clientRpc = temp.substring(0, temp.indexOf(">") + 1);
        temp = temp.substring(clientRpc.length());
        String user = temp.substring(0, temp.indexOf(">") + 1);
        temp = temp.substring(user.length());
        String overlay = temp.substring(0, temp.indexOf(">") + 1);
        temp = temp.substring(overlay.length());
        String timestampString = temp.substring(0, temp.indexOf("*/") + 2);
        temp = temp.substring(timestampString.length());
        String sqlText = temp;
        String result = temp.substring(sqlText.length());

        Long timestamp = mainController
                .convertToTimestamp(timestampString.substring(3, timestampString.length() - 3).trim(), PREFIX);

        // Create new SQL Log Element
        SqlLogElement logElement = new SqlLogElement();
        logElement.setElementAlias("SQL");
        logElement.setElementType(LogElementType.SERVERACTION);
        logElement.setName(sqlText);
        logElement.setParentLogElement(parent);
        logElement.setQueue(queue);
        logElement.setRpcId(rpcId);
        logElement.setStartLineNumber(lineNumber);
        logElement.setStartTimestamp(timestamp);
        logElement.setText(textWoPrefix);
        logElement.setThreadId(threadId);
        logElement.setUser(user);
        logElement.setValid(true);
        mainController.openNewLogElement(logElement);

        // Close sql log element immediately
        logElement.setEndLineNumber(lineNumber - 1);
        logElement.setEndTimestamp(timestamp);
        mainController.closeLastLogElement();

        return true;
    } else {
        return false;
    }
}

From source file:com.cisco.oss.foundation.http.server.HttpMethodFilter.java

private void updateAllowedMethodsFromConfig(String serviceName) {
    Configuration configuration = ConfigurationFactory.getConfiguration();
    Configuration subset = configuration.subset(serviceName + ".http.httpMethodFilter.methods");
    @SuppressWarnings("unchecked")
    Iterator<String> keys = subset.getKeys();
    while (keys.hasNext()) {
        String key = (String) keys.next();
        methods.add(subset.getString(key).toUpperCase(Locale.getDefault()));
    }//from  w  w  w.ja v  a 2 s  . c o m

}

From source file:com.boozallen.cognition.ingest.storm.topology.ConfigurableIngestTopology.java

void configureStreamFieldsGrouping(String prevComponent, String streamId, Configuration boltConf,
        BoltDeclarer declarer) throws ConfigurationException {

    String streamTypeArgs = boltConf.getString(STREAM_GROUPING_CONF_ARGS);

    if (StringUtils.isBlank(streamTypeArgs)) {
        logger.error("{} stream grouping requires {} configuration", STREAM_GROUPING_FIELDS,
                STREAM_GROUPING_CONF_ARGS);
        throw new ConfigurationException("Missing stream grouping configuration");
    } else {/*from  www.j a va  2 s.com*/
        String[] fields = streamTypeArgs.split(",");
        declarer.fieldsGrouping(prevComponent, streamId, new Fields(fields));
    }
}

From source file:es.udc.gii.common.eaf.algorithm.operator.evaluate.LocalSearchOperator.java

@Override
public void configure(Configuration conf) {
    super.configure(conf);
    try {//  ww  w. j  ava  2  s .  c  o m
        if (conf.containsKey("IndividualImprover.Class")) {
            this.improver = (IndividualImprover) Class.forName(conf.getString("IndividualImprover.Class"))
                    .newInstance();
            this.improver.configure(conf.subset("IndividualImprover"));
        }

        if (conf.containsKey("IndividualChooser.Class")) {
            this.chooser = (IndividualChooser) Class.forName(conf.getString("IndividualChooser.Class"))
                    .newInstance();
            this.chooser.configure(conf.subset("IndividualChooser"));
        } else {
            this.chooser = new BestIndividual();
        }

        this.evaluateReference = !conf.containsKey("IndividualImprover.DontEvaluateReference");

    } catch (Exception ex) {
        Logger.getLogger(LocalSearchOperator.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.qmetry.qaf.automation.ws.rest.RestTestBase.java

public void setClient(Client client) {
    client.addFilter(new ConnectionListenerFilter(getRequestListener()));
    client.addFilter(getRequestListener());
    client.addFilter(getRequestTracker());

    Configuration props = getBundle().subset(REST_CLIENT_PROP_PREFIX);
    Iterator<?> iter = props.getKeys();

    while (iter.hasNext()) {
        String prop = (String) iter.next();
        client.getProperties().put(REST_CLIENT_PROP_PREFIX + prop, props.getString(prop));
    }// w  w  w .j a v a  2  s  .co  m

    getTestBase().getContext().setProperty(REST_CLIENT_KEY, client);
}

From source file:fr.mby.portal.coreimpl.configuration.PropertiesConfigurationManagerTest.java

/**
 * test 2.// www.j  av  a  2s.  c om
 * 
 * @throws Exception
 */
@Test
public void test2() throws Exception {
    final Configuration config1 = this.configManager.initConfiguration(PropertiesConfigurationManagerTest.KEY2,
            PropertiesConfigurationManagerTest.TYPE2, PropertiesConfigurationManagerTest.TAG2);
    Assert.assertNotNull("Config not initialized !", config1);
    config1.addProperty("key2", "Value2");

    final Configuration config2 = this.configManager.getConfiguration(PropertiesConfigurationManagerTest.KEY2);
    Assert.assertNotNull("Config cannot be retrieved !", config2);
    Assert.assertEquals("Bad property value in config !", "Value2", config2.getString("key2"));

    Assert.assertNotNull("Tags cannot be retrieved !", this.configManager.getConfigurationTags());
    Assert.assertEquals("Tags count bad !", 1, this.configManager.getConfigurationTags().size());
    final String configKey = this.configManager.getConfigurationTags().iterator().next();
    Assert.assertEquals("Tag name bad !", PropertiesConfigurationManagerTest.KEY2, configKey);

    Assert.assertNotNull("Empty collection not returned !",
            this.configManager.getConfigurationKeys("unknownTag"));
}

From source file:fr.mby.portal.coreimpl.configuration.PropertiesConfigurationManagerTest.java

/**
 * test 3./*  w  w  w  . ja va 2  s. co  m*/
 * 
 * @throws Exception
 */
@Test
public void testFlush() throws Exception {
    final Configuration config1 = this.configManager.initConfiguration(PropertiesConfigurationManagerTest.KEY2,
            PropertiesConfigurationManagerTest.TYPE2, PropertiesConfigurationManagerTest.TAG2);
    Assert.assertNotNull("Config not initialized !", config1);
    config1.addProperty("key2", "Value2");

    // Flush
    this.configManager.flushConfiguration(PropertiesConfigurationManagerTest.KEY2);

    final Configuration config2 = this.configManager.getConfiguration(PropertiesConfigurationManagerTest.KEY2);
    Assert.assertNotNull("Config cannot be retrieved !", config2);
    Assert.assertEquals("Bad property value in config !", "Value2", config2.getString("key2"));

    Assert.assertNotNull("Tags cannot be retrieved !", this.configManager.getConfigurationTags());
    Assert.assertEquals("Tags count bad !", 1, this.configManager.getConfigurationTags().size());
    final String configKey = this.configManager.getConfigurationTags().iterator().next();
    Assert.assertEquals("Tag name bad !", PropertiesConfigurationManagerTest.KEY2, configKey);

    Assert.assertNotNull("Empty collection not returned !",
            this.configManager.getConfigurationKeys("unknownTag"));
}

From source file:net.sf.jclal.classifier.MOAWrapper.java

/**
 * {@inheritDoc}/*from   w w  w  .j av  a  2s. c o m*/
 */
@Override
public void configure(Configuration configuration) {

    String classifierError = "classifier type= ";
    try {

        // classifier classname
        String classifierClassname = configuration.getString("classifier[@type]");

        classifierError += classifierClassname;

        // classifier class
        Class<? extends Classifier> classifierClass = (Class<? extends Classifier>) Class
                .forName(classifierClassname);

        // Add this classifier
        setClassifier(classifierClass.newInstance());

    } catch (ClassNotFoundException e) {
        throw new ConfigurationRuntimeException("\nIllegal classifier classname: " + classifierError, e);
    } catch (InstantiationException e) {
        throw new ConfigurationRuntimeException("\nIllegal classifier classname: " + classifierError, e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationRuntimeException("\nIllegal classifier classname: " + classifierError, e);
    }

}