Example usage for org.apache.commons.configuration PropertiesConfiguration load

List of usage examples for org.apache.commons.configuration PropertiesConfiguration load

Introduction

In this page you can find the example usage for org.apache.commons.configuration PropertiesConfiguration load.

Prototype

public synchronized void load(Reader in) throws ConfigurationException 

Source Link

Document

Load the properties from the given reader.

Usage

From source file:org.dataone.proto.trove.mn.dao.v1.SolrLogIndexer.java

/**
 * Include additional properties in the global configuration. Properties included in the given file will override
 * existing properties in the global configuration if they are present.
 *
 * @param addProperties/*  w ww.  j  a  va2  s  .  c  o m*/
 * @return Configuration
 * @throws ConfigurationException
 * @throws java.io.IOException
 */
public Configuration getApacheConfiguration(Properties addProperties)
        throws ConfigurationException, IOException {

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    addProperties.store(baos, "hold your comments please");

    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    PropertiesConfiguration propertyConfiguration = new PropertiesConfiguration();
    propertyConfiguration.load(bais);
    CompositeConfiguration compositeConfiguration = new CompositeConfiguration();
    compositeConfiguration.addConfiguration(propertyConfiguration);
    return compositeConfiguration;

}

From source file:org.debux.webmotion.server.ConfigurationTest.java

@Test
public void testString() throws ConfigurationException {
    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.load(new StringReader("name=value"));
    AssertJUnit.assertEquals("value", configuration.getString("name"));
}

From source file:org.debux.webmotion.server.ConfigurationTest.java

@Test
public void testComposite() throws ConfigurationException {
    PropertiesConfiguration local = new PropertiesConfiguration();
    local.load(new StringReader("name=value"));

    PropertiesConfiguration file = new PropertiesConfiguration();
    file.load(new StringReader("name=other"));

    CompositeConfiguration composite = new CompositeConfiguration();
    composite.addConfiguration(file);//from w ww .java2s .  co m
    composite.addConfiguration(local);

    AssertJUnit.assertEquals("other", composite.getString("name"));
}

From source file:org.debux.webmotion.server.ConfigurationTest.java

@Test
public void testData() throws ConfigurationException {
    PropertiesConfiguration test = new PropertiesConfiguration();
    test.load(new StringReader("color=#0000FF"));

    DataConfiguration configuration = new DataConfiguration(test);
    AssertJUnit.assertNotNull(configuration.getColor("color"));
}

From source file:org.debux.webmotion.server.ConfigurationTest.java

@Test
public void testLoad() throws ConfigurationException {
    ClassLoader classLoader = ConfigurationTest.class.getClassLoader();

    PropertiesConfiguration configuration = new PropertiesConfiguration();
    configuration.load(classLoader.getResource("properties/etc.properties"));
    configuration.load(classLoader.getResource("properties/home.properties"));
    configuration.load(classLoader.getResource("properties/local.properties"));

    AssertJUnit.assertEquals("etc", configuration.getString("key1"));
    AssertJUnit.assertEquals("home", configuration.getString("key2"));
    AssertJUnit.assertEquals("local", configuration.getString("key3"));
}

From source file:org.eclipse.winery.repository.backend.filebased.FilebasedRepository.java

@Override
public Configuration getConfiguration(RepositoryFileReference ref) {
    Path path = this.ref2AbsolutePath(ref);

    PropertiesConfiguration configuration = new PropertiesConfiguration();
    if (Files.exists(path)) {
        try (Reader r = Files.newBufferedReader(path, Charset.defaultCharset())) {
            configuration.load(r);
        } catch (ConfigurationException | IOException e) {
            FilebasedRepository.logger.error("Could not read config file", e);
            throw new IllegalStateException("Could not read config file", e);
        }//  w ww.  ja v  a 2 s . c  o  m
    }

    configuration.addConfigurationListener(new AutoSaveListener(path, configuration));

    // We do NOT implement reloading as the configuration is only accessed
    // in JAX-RS resources, which are created on a per-request basis

    return configuration;
}

From source file:org.glite.security.voms.admin.configuration.VOMSConfiguration.java

private void loadVersionProperties() {

    InputStream versionPropStream = this.getClass().getClassLoader().getResourceAsStream("version.properties");
    PropertiesConfiguration versionProperties = new PropertiesConfiguration();

    try {//from   w w w . j  a  v a2 s . co  m
        versionProperties.load(versionPropStream);

        config.addConfiguration(versionProperties);

    } catch (ConfigurationException e) {

        log.error("Error configuring version properties:" + e.getMessage(), e);
        throw new VOMSConfigurationException("Error configuring version properties!", e);

    }
}

From source file:org.graphwalker.Util.java

public static String readWSPort() {
    PropertiesConfiguration conf = null;
    if (new File("graphwalker.properties").canRead()) {
        try {//from w  ww .j  av  a 2 s. c om
            conf = new PropertiesConfiguration("graphwalker.properties");
        } catch (ConfigurationException e) {
            Util.logger.error(e.getMessage());
        }
    } else {
        conf = new PropertiesConfiguration();
        try {
            conf.load(Util.class.getResourceAsStream("/org/graphwalker/resources/graphwalker.properties"));
        } catch (ConfigurationException e) {
            Util.logger.error(e.getMessage());
        }
    }
    String port = conf.getString("graphwalker.ws.port");
    Util.logger.debug("Read graphwalker.ws.port from graphwalker.properties: " + port);
    if (port == null) {
        port = "9090";
        Util.logger.debug("Setting port to: 9090");
    }
    return port;
}

From source file:org.keycloak.testsuite.util.LDAPTestConfiguration.java

protected void loadConnectionProperties(String connectionPropertiesLocation) {
    // TODO: Improve and possibly use FindFile
    InputStream is;/* ww  w. ja v a2s.  com*/
    try {
        if (connectionPropertiesLocation.startsWith(GenericConstants.PROTOCOL_CLASSPATH)) {
            String classPathLocation = connectionPropertiesLocation.replace(GenericConstants.PROTOCOL_CLASSPATH,
                    "");
            log.info("Reading LDAP configuration from classpath from: " + classPathLocation);
            is = LDAPTestConfiguration.class.getClassLoader().getResourceAsStream(classPathLocation);
        } else {
            String file = getResource(connectionPropertiesLocation);
            log.info("Reading LDAP configuration from: " + connectionPropertiesLocation);
            is = new FileInputStream(file);
        }
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }

    PropertiesConfiguration p;
    try {
        p = new PropertiesConfiguration();
        p.setDelimiterParsingDisabled(true);
        p.load(is);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    config = new HashMap<String, String>();
    for (Map.Entry<String, String> property : PROP_MAPPINGS.entrySet()) {
        String propertyName = property.getKey();
        String configName = property.getValue();

        String value = p.getString(configName);
        if (value == null) {
            value = DEFAULT_VALUES.get(propertyName);
        }

        config.put(propertyName, value);
    }

    startEmbeddedLdapServer = p.getBoolean("idm.test.ldap.start.embedded.ldap.server", true);
    sleepTime = p.getInteger("idm.test.ldap.sleepTime", 1000);
    caseSensitiveLogin = p.getBoolean("idm.test.kerberos.caseSensitiveLogin", true);
    log.info("Start embedded server: " + startEmbeddedLdapServer);
    log.info("Read config: " + config);
}

From source file:org.kontalk.util.Tr.java

public static void init() {
    // get language
    String lang = Locale.getDefault().getLanguage();
    if (lang.equals(DEFAULT_LANG)) {
        return;/*w  w w  .  ja  va2  s.  com*/
    }

    LOGGER.info("Setting language: " + lang);

    // load string keys file
    String path = Kontalk.RES_PATH + I18N_DIR + STRING_FILE + PROP_EXT;
    PropertiesConfiguration stringKeys;
    try {
        stringKeys = new PropertiesConfiguration(ClassLoader.getSystemResource(path));
    } catch (ConfigurationException ex) {
        LOGGER.log(Level.WARNING, "can't load string key file", ex);
        return;
    }

    // load translation file
    path = Kontalk.RES_PATH + I18N_DIR + STRING_FILE + "_" + lang + PROP_EXT;
    URL url = ClassLoader.getSystemResource(path);
    if (url == null) {
        LOGGER.info("can't find translation file: " + path);
        return;
    }
    PropertiesConfiguration tr = new PropertiesConfiguration();
    tr.setEncoding("UTF-8");
    try {
        tr.load(url);
    } catch (ConfigurationException ex) {
        LOGGER.log(Level.WARNING, "can't load translation file", ex);
        return;
    }

    TR_MAP = new HashMap<>();
    Iterator<String> it = tr.getKeys();
    while (it.hasNext()) {
        String k = it.next();
        if (!stringKeys.containsKey(k)) {
            LOGGER.warning("key in translation but not in key file: " + k);
            continue;
        }
        TR_MAP.put(stringKeys.getString(k), tr.getString(k));
    }
}