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:org.finra.dm.dao.config.DaoSpringModuleConfig.java

/**
 * The database supplied property sources placeholder configurer that allows access to externalized properties from a database. This method also adds a new
 * property source that contains the database properties to the environment.
 *
 * @return the property sources placeholder configurer.
 *///  www . j  a v  a2 s . c om
@Bean
public static PropertySourcesPlaceholderConfigurer databasePropertySourcesPlaceholderConfigurer() {
    // Get the configurable environment and add a new property source to it that contains the database properties.
    // That way, the properties can be accessed via the environment or via an injected @Value annotation.
    // We are adding this property source last so other property sources (e.g. system properties, environment variables) can be used
    // to override the database properties.
    Environment environment = ApplicationContextHolder.getApplicationContext().getEnvironment();
    if (environment instanceof ConfigurableEnvironment) {
        ConfigurableEnvironment configurableEnvironment = (ConfigurableEnvironment) environment;
        ReloadablePropertySource reloadablePropertySource = new ReloadablePropertySource(
                ReloadablePropertySource.class.getName(),
                ConfigurationConverter.getProperties(getPropertyDatabaseConfiguration()),
                getPropertyDatabaseConfiguration());
        configurableEnvironment.getPropertySources().addLast(reloadablePropertySource);
    }

    return new PropertySourcesPlaceholderConfigurer();
}

From source file:org.finra.dm.dao.ReloadablePropertySource.java

/**
 * Refreshes the properties from the configuration if it's time to.
 *///from   w ww.  j  av  a2s  .c  o  m
@SuppressWarnings("unchecked")
protected void refreshPropertiesIfNeeded() {
    // Ensure we update the properties in a synchronized fashion to avoid possibly corrupting the properties.
    synchronized (this) {
        // See if it's time to refresh the properties (i.e. the elapsed time is greater than the configured refresh interval).
        LOGGER.debug("Checking if properties need to be refreshed. Current time is "
                + System.currentTimeMillis() + " and last refresh time is " + lastRefreshTime
                + " which is a delta of " + (System.currentTimeMillis() - lastRefreshTime) + ".");

        if (System.currentTimeMillis() - lastRefreshTime >= refreshIntervalMillis) {
            // Enough time has passed so refresh the properties.
            LOGGER.debug("Refreshing properties.");

            // Get the latest properties from the configuration.
            Properties properties = ConfigurationConverter.getProperties(configuration);

            // Log the properties we just retrieved from the configuration.
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("New properties just retrieved.");
                for (Map.Entry<Object, Object> entry : properties.entrySet()) {
                    LOGGER.debug("Key [" + entry.getKey() + "] = " + entry.getValue());
                }
            }

            // Update our property sources properties with the ones just read by clearing and adding in the new ones since the "source" is final.
            this.source.clear();
            this.source.putAll((Map) properties);

            // Log the properties we have in our property source.
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Updated reloadable properties.");
                for (Object key : source.keySet()) {
                    LOGGER.debug("Key [" + key + "] = " + properties.get(key));
                }
            }

            // Update the last refresh time and refresh interval.
            updateLastRefreshTime();
            updateRefreshInterval();

            LOGGER.debug("The properties have been refreshed from the configuration.");
        }
    }
}

From source file:org.finra.herd.dao.ReloadablePropertySource.java

/**
 * Refreshes the properties from the configuration if it's time to.
 *//*from w  ww .j  a va2s  .co m*/
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void refreshPropertiesIfNeeded() {
    // Ensure we update the properties in a synchronized fashion to avoid possibly corrupting the properties.
    synchronized (this) {
        // See if it's time to refresh the properties (i.e. the elapsed time is greater than the configured refresh interval).
        LOGGER.debug(
                "Checking if properties need to be refreshed. currentTime={} lastRefreshTime={} millisecondsSinceLastPropertiesRefresh={}",
                System.currentTimeMillis(), lastRefreshTime, System.currentTimeMillis() - lastRefreshTime);

        if (System.currentTimeMillis() - lastRefreshTime >= refreshIntervalMillis) {
            // Enough time has passed so refresh the properties.
            LOGGER.debug("Refreshing properties...");

            // Get the latest properties from the configuration.
            Properties properties = ConfigurationConverter.getProperties(configuration);

            if (lastConfigurationErrorEvent != null) {
                LOGGER.error(
                        "An error occurred while retrieving configurations. Previous values are retained. See cause for details.",
                        lastConfigurationErrorEvent.getCause());
                lastConfigurationErrorEvent = null;
            } else {
                // Log the properties we just retrieved from the configuration.
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("New properties just retrieved.");
                    for (Map.Entry<Object, Object> entry : properties.entrySet()) {
                        LOGGER.debug("{}=\"{}\"", entry.getKey(), entry.getValue());
                    }
                }

                // Update our property sources properties with the ones just read by clearing and adding in the new ones since the "source" is final.
                this.source.clear();
                this.source.putAll((Map) properties);

                // Log the properties we have in our property source.
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Updated reloadable properties.");
                    for (Object key : source.keySet()) {
                        LOGGER.debug("{}=\"{}\"", key, properties.get(key));
                    }
                }
            }

            // Update the last refresh time and refresh interval.
            updateLastRefreshTime();
            updateRefreshInterval();

            LOGGER.debug("The properties have been refreshed from the configuration.");
        }
    }
}

From source file:org.rzo.yajsw.wrapper.FileUtils.java

/**
 * The main method.//from w ww.j av a2 s. c  om
 * 
 * @param args
 *            the arguments
 */
public static void main(String[] args) {
    try {
        // String
        // fileName=FilenameUtils.separatorsToSystem("C:\\init\\MOBILEguard\\yajsw/lib/jvmstat/*.jar");
        // System.out.println("FileName: "+fileName);
        CompositeConfiguration compConfig = new CompositeConfiguration();
        AbstractConfiguration configuraton = new BaseConfiguration();
        compConfig.addConfiguration(new EnvironmentConfiguration());
        configuraton.setProperty("wrapper.java.classpath.1", "${VERSANT_ROOT}/lib/jvi.*jar");
        configuraton.setProperty("wrapper.java.classpath.2", "${GROOVY_HOME}/lib/*.jar");
        compConfig.addConfiguration(configuraton);
        System.out.println("Configuration: " + ConfigurationConverter.getProperties(compConfig));
        System.out
                .println("subset: " + ConfigurationConverter.getProperties(compConfig.subset("wrapper.java")));

        // Collection files=FileUtils.getFiles("../..",
        // "C:/versant/7_0_1/lib/jvi*.jar");
        // Collection collection=
        // org.apache.commons.io.FileUtils.listFiles(new File("C:/"),
        // new WildcardFileFilter("jvi*.jar"), new
        // WildcardFileFilter("*jar"));
        // File[] files= new
        // File("C:").listFiles((FilenameFilter)FileFilterUtils.nameFileFilter("C:/versant/7_0_1/lib/jvi*.jar"));

        //         
        // FileUtils.getFiles("C:/versant/7_0_1/lib/", "jvi*.jar");
        // System.out.println("FileList="+
        // FileUtils.getFiles("C:/versant/7_0_1/lib/", "jvi*.jar"));
        // java.util.Arrays.asList(files));
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:org.talend.mdm.commmon.util.core.MDMConfiguration.java

private Properties getProperties(boolean reload, boolean ignoreIfNotFound) {
    if (reload) {
        properties = null;//ww  w  .ja  v  a 2s. com
    }
    if (properties != null) {
        return properties;
    }
    properties = new Properties();

    File file = new File(location);
    if (file.exists()) {
        LOGGER.info("MDM Configuration: found in '" + file.getAbsolutePath() + "'."); //$NON-NLS-1$ //$NON-NLS-2$           
        try {
            PropertiesConfiguration config = new PropertiesConfiguration();
            config.setDelimiterParsingDisabled(true);
            config.load(file);
            // Decrypt the passwords in mdm.conf
            config.setProperty(ADMIN_PASSWORD, Crypt.decrypt(config.getString(ADMIN_PASSWORD)));
            config.setProperty(TECHNICAL_PASSWORD, Crypt.decrypt(config.getString(TECHNICAL_PASSWORD)));
            config.setProperty(TDS_PASSWORD, Crypt.decrypt(config.getString(TDS_PASSWORD)));
            properties = ConfigurationConverter.getProperties(config);
        } catch (Exception e) {
            if (!ignoreIfNotFound) {
                throw new IllegalStateException("Unable to load MDM configuration from '" //$NON-NLS-1$
                        + file.getAbsolutePath() + "'", e); //$NON-NLS-1$
            }
            LOGGER.warn("Unable to load MDM configuration from '" + file.getAbsolutePath() + "'", e); //$NON-NLS-1$ //$NON-NLS-2$
        }
    } else {
        if (!ignoreIfNotFound) {
            throw new IllegalStateException("Unable to load MDM configuration from '" + file.getAbsolutePath() //$NON-NLS-1$
                    + "'"); //$NON-NLS-1$
        }
        LOGGER.warn("Unable to load MDM configuration from '" + file.getAbsolutePath() + "'"); //$NON-NLS-1$ //$NON-NLS-2$
    }
    return properties;
}

From source file:org.wisdom.configuration.ConfigurationImpl.java

/**
 * @return All properties that are currently loaded from internal and
 * external files//from  w w  w . ja v a 2  s  .com
 */
@Override
public Properties asProperties() {
    return ConfigurationConverter.getProperties(configuration);
}

From source file:services.plugins.atlassian.jira.jira1.JiraPluginRunner.java

/**
 * Get the properties for a portfolio entry registration as a byte array.
 * // www. j  a  v a2  s .  co  m
 * @param needs
 *            set to true if the needs should be synchronized
 * @param defects
 *            set to true if the defects should be synchronized
 */
public static byte[] getPropertiesForPortfolioEntryAsByte(boolean needs, boolean defects) {

    PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration();
    propertiesConfiguration.addProperty("needs", needs);
    propertiesConfiguration.addProperty("defects", defects);

    Properties properties = ConfigurationConverter.getProperties(propertiesConfiguration);
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    try {
        properties.store(buffer, "properties");
        return buffer.toByteArray();
    } catch (IOException e) {
        Logger.error("impossible to store the properties in the buffer", e);
        return null;
    }

}

From source file:services.plugins.redmine.RedminePluginRunner.java

/**
 * Get the properties for a portfolio entry registration as a byte array.
 * //from  w ww  .  j  a  v  a  2s .  co m
 * @param needs
 *            set to true if the needs should be synchronized
 * @param defects
 *            set to true if the defects should be synchronized
 * @param iterations
 *            set to true if the iterations should be synchronized
 */
public static byte[] getPropertiesForPortfolioEntryAsByte(boolean needs, boolean defects, boolean iterations) {

    PropertiesConfiguration propertiesConfiguration = new PropertiesConfiguration();
    propertiesConfiguration.addProperty("needs", needs);
    propertiesConfiguration.addProperty("defects", defects);
    propertiesConfiguration.addProperty("iterations", iterations);

    Properties properties = ConfigurationConverter.getProperties(propertiesConfiguration);
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    try {
        properties.store(buffer, "properties");
        return buffer.toByteArray();
    } catch (IOException e) {
        Logger.error("impossible to store the properties in the buffer", e);
        return null;
    }

}

From source file:uk.ac.open.kmi.iserve.core.SystemConfiguration.java

private Properties readConfiguration(String configFilePath) {

    // Use default configuration if unset
    if (configFilePath == null || configFilePath.isEmpty()) {
        log.warn("The URL of the configuration file is incorrect {}. Using default configuration.",
                configFilePath);/*from   ww w .  j a  v  a  2 s. com*/
        return new Properties();
    }

    // Else load properties using default procedure
    log.debug("Attempting to read configuration file - {} from classpath or home directory.", configFilePath);
    try {
        PropertiesConfiguration properties = new PropertiesConfiguration(configFilePath);
        log.info("Configuration loaded from {}", configFilePath);
        return ConfigurationConverter.getProperties(properties);
    } catch (ConfigurationException e) {
        log.warn("Unable to load configuration file - {}. Falling back to default values.", configFilePath);
        return new Properties();
    }
}

From source file:uk.ac.ox.it.ords.api.database.services.impl.hibernate.SQLServicePostgresImpl.java

@Override
public File exportSQLFileFromDatabase(int dbId) throws Exception {
    OrdsPhysicalDatabase database = this.getPhysicalDatabaseFromID(dbId);
    DatabaseServer server = ServerConfigurationService.Factory.getInstance()
            .getDatabaseServer(database.getDatabaseServer());
    // create the file
    String databaseName = database.getDbConsumedName();
    File file = File.createTempFile("dump_" + databaseName, "sql");
    Properties properties = ConfigurationConverter.getProperties(MetaConfiguration.getConfiguration());
    String postgres_bin = "";
    if (properties.containsKey("ords.postgresql.bin.path")) {
        postgres_bin = properties.getProperty("ords.postgresql.bin.path");
    }//from  w  w w  . j a v a  2 s.  c  o  m
    ProcessBuilder processBuilder = new ProcessBuilder(postgres_bin + "pg_dump", "-f", file.toString(), "-v",
            "-o", "-h", database.getDatabaseServer(), "-U", server.getUsername(), database.getDbConsumedName());

    processBuilder.environment().put("PGPASSWORD", server.getPassword());
    Process process = processBuilder.start();
    try {
        InputStream is = process.getInputStream();
        InputStreamReader reader = new InputStreamReader(is);
        BufferedReader buffer = new BufferedReader(reader);
        String line;
        while ((line = buffer.readLine()) != null) {
            System.out.println(line);
            if (log.isDebugEnabled()) {
                log.debug(line);
            }
        }
    } catch (Exception e) {
        log.error("ERROR", e);
    }
    return file;
}