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:eu.eco2clouds.accounting.conf.ConfigurationTest.java

@Test
public void loadMonitoringPropertiesFile() {

    String propertiesFile = "MonitoringCollector.properties";

    File f = new File(etcConfiguration);
    if (f.exists()) {
        propertiesFile = etcConfiguration;
    }// w w w  .  j a va  2 s .c  o m

    org.apache.commons.configuration.Configuration config;
    try {
        config = new PropertiesConfiguration(propertiesFile);

        assertEquals("root", config.getString("mysql.username"));
        assertEquals("1234", config.getString("mysql.password"));
        assertEquals("localhost/metricsdb", config.getString("mysql.host"));

    } catch (ConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:com.manydesigns.elements.fields.search.AbstractDateSearchField.java

public AbstractDateSearchField(PropertyAccessor accessor, String prefix) {
    super(accessor, prefix);

    DateFormat dateFormatAnnotation = accessor.getAnnotation(DateFormat.class);
    if (dateFormatAnnotation != null) {
        datePattern = dateFormatAnnotation.value();
    } else {//  w ww.  j  a v  a 2s  . c  o  m
        Configuration elementsConfiguration = ElementsProperties.getConfiguration();
        datePattern = elementsConfiguration.getString(ElementsProperties.FIELDS_DATE_FORMAT);
    }
    dateTimeFormatter = DateTimeFormat.forPattern(datePattern);
    setSize(dateTimeFormatter.getParser().estimateParsedLength());

    containsTime = datePattern.contains("HH") || datePattern.contains("mm") || datePattern.contains("ss");
}

From source file:es.udc.gii.common.eaf.algorithm.operator.reproduction.mutation.de.crossover.CrossOverScheme.java

@Override
public void configure(Configuration conf) {

    try {//from  w w  w.  j  a  va2  s.com
        if (conf.containsKey("CR.Class")) {
            this.CR_plugin = (Parameter) Class.forName(conf.getString("CR.Class")).newInstance();
            this.CR_plugin.configure(conf.subset("CR"));
        }

    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException ex) {
        throw new ConfigurationException(this.getClass(), ex);
    }
}

From source file:com.cisco.oss.foundation.message.RabbitMQMessageProducer.java

RabbitMQMessageProducer(String producerName) {
    super(producerName);
    Configuration subset = configuration.subset(producerName);
    queueName = subset.getString("queue.name");

    if (StringUtils.isBlank(queueName)) {
        throw new QueueException(
                "Check Configuration - missing required queue name for producer: " + producerName);
    }/* w  ww .jav  a2 s  . c o  m*/

    //update expiration
    expiration = subset.getLong("queue.expiration", 1800000);
    groupId = subset.getString("queue.groupId", "");
    isDurable = subset.getBoolean("queue.isDurable", true);
    isPersistent = subset.getBoolean("queue.isPersistent", true);

    try {
        Channel channel = RabbitMQMessagingFactory.getChannel();
        channel.exchangeDeclare(queueName, "topic", isDurable, false, false, null);
        isInitialized.set(true);
    } catch (QueueException e) {
        LOGGER.debug("can't init producer as its underlying connection is not ready");
    } catch (IOException e) {
        throw new QueueException("Can't create producer: " + e, e);
    }

    LOGGER.info("created rabbitmq producer: {} on exchange: {}", producerName, queueName);

}

From source file:com.linkedin.pinot.filesystem.HadoopPinotFS.java

private void authenticate(org.apache.hadoop.conf.Configuration hadoopConf,
        org.apache.commons.configuration.Configuration configs) {
    String principal = configs.getString(PRINCIPAL);
    String keytab = configs.getString(KEYTAB);
    if (!Strings.isNullOrEmpty(principal) && !Strings.isNullOrEmpty(keytab)) {
        UserGroupInformation.setConfiguration(hadoopConf);
        if (UserGroupInformation.isSecurityEnabled()) {
            try {
                if (!UserGroupInformation.getCurrentUser().hasKerberosCredentials()
                        || !UserGroupInformation.getCurrentUser().getUserName().equals(principal)) {
                    LOGGER.info("Trying to authenticate user [%s] with keytab [%s]..", principal, keytab);
                    UserGroupInformation.loginUserFromKeytab(principal, keytab);
                }//from ww  w  .j  a  v  a2s. c om
            } catch (IOException e) {
                throw new RuntimeException(String.format(
                        "Failed to authenticate user principal [%s] with keytab [%s]", principal, keytab), e);
            }
        }
    }
}

From source file:com.parallax.server.blocklyprop.servlets.ConfirmRequestServlet.java

@Inject
public void setConfiguration(Configuration configuration) {
    this.configuration = configuration;
    cloudSessionLocalUserService = new CloudSessionLocalUserService(
            configuration.getString("cloudsession.server"), configuration.getString("cloudsession.baseurl"));
}

From source file:com.springrts.springls.updateproperties.UpdateProperties.java

public boolean read(String fileName) {

    boolean success = false;

    updateProperties = new Properties();

    File updatePropsFile = new File(fileName);
    if (updatePropsFile.exists()) {
        FileInputStream fStream = null;
        try {//from ww  w .  j av a  2s .  c  om
            fStream = new FileInputStream(updatePropsFile);
            updateProperties.loadFromXML(fStream);
            success = true;
        } catch (IOException ex) {
            LOG.warn("Could not read from file '" + fileName + "'.", ex);
        } finally {
            if (fStream != null) {
                try {
                    fStream.close();
                } catch (IOException ex) {
                    LOG.trace("Failed to close file input stream: " + fileName, ex);
                }
            }
        }
    } else {
        Configuration conf = getContext().getService(Configuration.class);
        String engineVersion = conf.getString(ServerConfiguration.ENGINE_VERSION);
        // Not having update properties is only possibly a problem
        // when we try to enforce a certain engine version.
        if (!engineVersion.equals("*")) {
            LOG.warn("Could not find file '{}';" + " not using any update properties.", fileName.toString());
        }
    }

    return success;
}

From source file:com.manydesigns.portofino.stripes.AuthenticationRequiredResolution.java

public void execute(HttpServletRequest request, HttpServletResponse response) throws Exception {
    if (request.getParameter("__portofino_quiet_auth_failure") != null) {
        return;/* ww w  .j  a  v  a 2  s.  co  m*/
    }
    ServletContext servletContext = request.getServletContext();
    Configuration configuration = (Configuration) servletContext
            .getAttribute(BaseModule.PORTOFINO_CONFIGURATION);
    String loginPage = configuration.getString(PortofinoProperties.LOGIN_PAGE);
    if (response.getContentType() == null || response.getContentType().contains("text/html")) {
        ElementsActionBeanContext context = new ElementsActionBeanContext();
        context.setRequest(request);
        String originalPath = context.getActionPath();
        UrlBuilder urlBuilder = new UrlBuilder(Locale.getDefault(), originalPath, false);
        Map<?, ?> parameters = request.getParameterMap();
        urlBuilder.addParameters(parameters);
        String returnUrl = urlBuilder.toString();
        logger.info("Anonymous user not allowed to see {}. Redirecting to login.", originalPath);
        RedirectResolution redirectResolution = new RedirectResolution(loginPage, true);
        redirectResolution.addParameter("returnUrl", returnUrl);
        redirectResolution.execute(request, response);
    } else {
        logger.debug("AJAX call while user disconnected");
        UrlBuilder loginUrlBuilder = new UrlBuilder(request.getLocale(), loginPage, false);
        response.setHeader(LOGIN_PAGE_HEADER, loginUrlBuilder.toString());
        new ErrorResolution(STATUS, errorMessage).execute(request, response);
    }
}

From source file:de.shadowhunt.sonar.plugins.ignorecode.batch.IgnoreCoverageDecoratorTest.java

@Test
public void testLoadPatternsEmptyConfigFile() {
    final Configuration configuration = Mockito.mock(Configuration.class);
    Mockito.when(configuration.getString(IgnoreCoverageDecorator.CONFIG_FILE)).thenReturn("");
    final List<CoveragePattern> patterns = IgnoreCoverageDecorator.loadPatterns(configuration);
    Assert.assertNotNull("List must not be null", patterns);
    Assert.assertTrue("List must be empty", patterns.isEmpty());
}

From source file:de.shadowhunt.sonar.plugins.ignorecode.batch.IgnoreCoverageDecoratorTest.java

@Test
public void testLoadPatternsNoConfigFile() {
    final Configuration configuration = Mockito.mock(Configuration.class);
    Mockito.when(configuration.getString(IgnoreCoverageDecorator.CONFIG_FILE)).thenReturn("no file");
    final List<CoveragePattern> patterns = IgnoreCoverageDecorator.loadPatterns(configuration);
    Assert.assertNotNull("List must not be null", patterns);
    Assert.assertTrue("List must be empty", patterns.isEmpty());
}