Example usage for org.apache.commons.configuration ConfigurationConverter getProperties

List of usage examples for org.apache.commons.configuration ConfigurationConverter getProperties

Introduction

In this page you can find the example usage for org.apache.commons.configuration ConfigurationConverter getProperties.

Prototype

public static Properties getProperties(Configuration config) 

Source Link

Document

Convert a Configuration class into a Properties class.

Usage

From source file:de.kaiserpfalzEdv.commons.jee.spring.CommonsConfigurationConfigurer.java

private void loadProperties(Properties props, String filename) throws ConfigurationException {
    DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(filename);
    configuration = builder.getConfiguration();

    Properties commonsProperties = ConfigurationConverter.getProperties(configuration);

    log.debug("got properties " + commonsProperties);
    for (Map.Entry<Object, Object> entry : commonsProperties.entrySet()) {
        props.setProperty((String) entry.getKey(), (String) entry.getValue());
    }/*from  ww  w  .  ja v  a 2  s  .  c  o  m*/
}

From source file:gobblin.util.JobConfigurationUtils.java

/**
 * Load the properties from the specified file into a {@link Properties} object.
 *
 * @param fileName the name of the file to load properties from
 * @param conf configuration object to determine the file system to be used
 * @return a new {@link Properties} instance
 *//*from   w  w w .  ja  v a 2 s  .  c o  m*/
public static Properties fileToProperties(String fileName, Configuration conf)
        throws IOException, ConfigurationException {

    PropertiesConfiguration propsConfig = new PropertiesConfiguration();
    Path filePath = new Path(fileName);
    URI fileURI = filePath.toUri();

    if (fileURI.getScheme() == null && fileURI.getAuthority() == null) {
        propsConfig.load(FileSystem.getLocal(conf).open(filePath));
    } else {
        propsConfig.load(filePath.getFileSystem(conf).open(filePath));
    }
    return ConfigurationConverter.getProperties(propsConfig);
}

From source file:io.fluo.stress.TrieMapRedIT.java

@Test
public void testEndToEnd() throws Exception {
    File testDir = new File("target/MRIT");
    FileUtils.deleteQuietly(testDir);//from   w w  w .  j ava 2  s .c o m
    testDir.mkdirs();
    File fluoPropsFile = new File(testDir, "fluo.props");

    BufferedWriter propOut = new BufferedWriter(new FileWriter(fluoPropsFile));
    ConfigurationConverter.getProperties(config).store(propOut, "");
    propOut.close();

    File out1 = new File(testDir, "nums-1");

    generate(2, 100, 500, out1);
    init(8, fluoPropsFile, out1, new File(testDir, "initTmp"));
    int ucount = unique(out1);

    Assert.assertTrue(ucount > 0);

    miniFluo.waitForObservers();

    Assert.assertEquals(new Print.Stats(0, ucount, false), Print.getStats(config));

    // reload same data
    load(8, fluoPropsFile, out1);

    miniFluo.waitForObservers();

    Assert.assertEquals(new Print.Stats(0, ucount, false), Print.getStats(config));

    // load some new data
    File out2 = new File(testDir, "nums-2");
    generate(2, 100, 500, out2);
    load(8, fluoPropsFile, out2);
    int ucount2 = unique(out1, out2);
    Assert.assertTrue(ucount2 > ucount); // used > because the probability that no new numbers are chosen is exceedingly small

    miniFluo.waitForObservers();

    Assert.assertEquals(new Print.Stats(0, ucount2, false), Print.getStats(config));

    File out3 = new File(testDir, "nums-3");
    generate(2, 100, 500, out3);
    load(8, fluoPropsFile, out3);
    int ucount3 = unique(out1, out2, out3);
    Assert.assertTrue(ucount3 > ucount2); // used > because the probability that no new numbers are chosen is exceedingly small

    miniFluo.waitForObservers();

    Assert.assertEquals(new Print.Stats(0, ucount3, false), Print.getStats(config));
}

From source file:com.capgemini.archaius.spring.ArchaiusBridgePropertyPlaceholderConfigurer.java

@Override
public void setLocations(Resource[] locations) {
    try {//from   w ww.  jav  a  2 s  .co  m
        Map parameterMap = propertyPlaceholderSupport.getParameterMap(delayMillis, initialDelayMillis,
                ignoreDeletesFromSource, ignoreResourceNotFound, allowMultiplePlaceholders,
                includeSystemConfiguration);

        // If there is not also a JDBC properties location to consider
        if (jdbcConnectionDetailMap == null) {
            propertyPlaceholderSupport.setLocations(parameterMap, locations);
            super.setLocations(locations);
        } else {
            ConcurrentCompositeConfiguration conComConfiguration = propertyPlaceholderSupport
                    .setMixedResourcesAsPropertySources(parameterMap, locations, jdbcConnectionDetailMap);
            super.setProperties(ConfigurationConverter.getProperties(conComConfiguration));
        }
    } catch (IOException ex) {
        LOGGER.error("Problem setting the locations", ex);
        throw new RuntimeException("Problem setting the locations.", ex);
    }
}

From source file:com.germinus.easyconf.ComponentProperties.java

/**
 * Returns a <b>copy </b> of the configuration into a
 * <tt>java.util.Properties</tt> class. Multivalued properties will be
 * converted to comma-separated strings. Any changes made to the
 * configuration will <b>not </b>be available to the Properties and
 * viceversa.//from  w ww . j a v  a2s  . c o m
 * 
 * @return a <code>Properties</code> instance
 */
public java.util.Properties getProperties() {
    return ConfigurationConverter.getProperties(properties);
}

From source file:com.ariht.maven.plugins.config.ConfigProcessorMojo.java

/**
 * Filter files contain the properties we wish to substitute in templates.
 *
 * Uses Apache Commons Configuration to load filters.
 *//*from   w ww .  j a  v a2 s .  c  om*/
private Properties readFilterIntoProperties(final FileInfo filter) throws ConfigurationException {
    final PropertiesConfiguration config = new PropertiesConfiguration(filter.getFile());
    config.setEncoding(encoding);
    // Add one more property:   filter.source=/relative/sub/dir/filenameNoExtension
    final String filterSource = filter.getRelativeSubDirectory() + filter.getNameWithoutExtension();
    config.setProperty("filter.source", FilenameUtils.separatorsToUnix(filterSource));
    return ConfigurationConverter.getProperties(config);
}

From source file:com.nesscomputing.jdbc.C3P0DataSourceProvider.java

private Properties getProperties(final String suffix) {
    final CombinedConfiguration cc = new CombinedConfiguration(new OverrideCombiner());

    if (props != null) {
        // Allow setting of internal defaults by using "ds.xxx" and "pool.xxx" if a properties
        // object is present.
        cc.addConfiguration(/*from  ww  w  .  j a  v  a2  s .  c  o  m*/
                new ImmutableConfiguration(ConfigurationConverter.getConfiguration(props).subset(suffix)));
    }

    if (config != null) {
        cc.addConfiguration(config.getConfiguration(propertiesPrefix + "." + suffix));
        cc.addConfiguration(config.getConfiguration(DEFAULTS_PREFIX + "." + suffix));
    }

    return ConfigurationConverter.getProperties(cc);
}

From source file:com.dm.estore.common.config.Cfg.java

public Properties getAllProperties() {
    return ConfigurationConverter.getProperties(config);
}

From source file:com.mirth.connect.model.DatabaseSettings.java

@Override
public Properties getProperties() {
    PropertiesConfiguration configuration = new PropertiesConfiguration();

    if (getDirBase() != null) {
        configuration.setProperty(DIR_BASE, getDirBase());
    }//from   ww  w  .  j  av a 2s  . c  om

    if (getDatabase() != null) {
        configuration.setProperty(DATABASE, getDatabase());
    }

    if (getDatabaseUrl() != null) {
        configuration.setProperty(DATABASE_URL, getDatabaseUrl());
    }

    if (getMappedDatabaseDriver() != null) {
        configuration.setProperty(DATABASE_DRIVER, getMappedDatabaseDriver());
    }

    if (getDatabasePool() != null) {
        configuration.setProperty(DATABASE_POOL, getDatabasePool());
    }

    if (getMappedJdbc4() != null) {
        configuration.setProperty(DATABASE_JDBC4, getMappedJdbc4());
    }

    if (getMappedTestQuery() != null) {
        configuration.setProperty(DATABASE_TEST_QUERY, getMappedTestQuery());
    }

    /*
     * MIRTH-1749: in case someone comments out the username and password properties
     */
    if (getDatabaseUsername() != null) {
        configuration.setProperty(DATABASE_USERNAME, getDatabaseUsername());
    } else {
        configuration.setProperty(DATABASE_USERNAME, StringUtils.EMPTY);
    }

    if (getDatabasePassword() != null) {
        configuration.setProperty(DATABASE_PASSWORD, getDatabasePassword());
    } else {
        configuration.setProperty(DATABASE_PASSWORD, StringUtils.EMPTY);
    }

    if (getDatabaseMaxConnections() != null) {
        configuration.setProperty(DATABASE_MAX_CONNECTIONS, getDatabaseMaxConnections().toString());
    } else {
        configuration.setProperty(DATABASE_MAX_CONNECTIONS, StringUtils.EMPTY);
    }

    if (getDatabaseTestIdleTime() != null) {
        configuration.setProperty(DATABASE_TEST_IDLE_TIME, getDatabaseTestIdleTime().toString());
    } else {
        configuration.setProperty(DATABASE_TEST_IDLE_TIME, "10000");
    }

    return ConfigurationConverter.getProperties(configuration);
}

From source file:gobblin.util.PullFileLoader.java

/**
 * Load a {@link Properties} compatible path using fallback as fallback.
 * @return The {@link Config} in path with fallback as fallback.
 * @throws IOException/*w ww  . j av a2  s  . co m*/
 */
private Config loadJavaPropsWithFallback(Path propertiesPath, Config fallback) throws IOException {

    PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration();
    try (InputStreamReader inputStreamReader = new InputStreamReader(this.fs.open(propertiesPath),
            Charsets.UTF_8)) {
        propertiesConfiguration.load(inputStreamReader);

        Config configFromProps = ConfigUtils
                .propertiesToConfig(ConfigurationConverter.getProperties(propertiesConfiguration));

        return ConfigFactory
                .parseMap(ImmutableMap.of(ConfigurationKeys.JOB_CONFIG_FILE_PATH_KEY,
                        PathUtils.getPathWithoutSchemeAndAuthority(propertiesPath).toString()))
                .withFallback(configFromProps).withFallback(fallback);
    } catch (ConfigurationException ce) {
        throw new IOException(ce);
    }
}