Example usage for org.springframework.core.io.support PropertiesLoaderUtils fillProperties

List of usage examples for org.springframework.core.io.support PropertiesLoaderUtils fillProperties

Introduction

In this page you can find the example usage for org.springframework.core.io.support PropertiesLoaderUtils fillProperties.

Prototype

public static void fillProperties(Properties props, Resource resource) throws IOException 

Source Link

Document

Fill the given properties from the given resource (in ISO-8859-1 encoding).

Usage

From source file:com.th.frame.core.message.impl.AbstractPropertiesMessage.java

/**
 * build default/*from   ww  w.  ja va 2  s. c  o  m*/
 */
private void buildDefaultProperties() {
    if (null == propertiesTemplate)
        return;
    properties = new Properties();
    log.info("\r\n***********************************************************************");
    log.info("Debug Mode : " + propertiesTemplate.getIsDebug());
    log.info("Loading system reference attributes ... ");
    if ("false".equals(propertiesTemplate.getIsDebug())) {
        for (String propFile : propertiesTemplate.getLiveFiles()) {
            log.info("Loading File : " + propFile);
            try {
                PropertiesLoaderUtils.fillProperties(properties, new ClassPathResource(propFile));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    } else {
        for (String propFile : propertiesTemplate.getDebugFiles()) {
            log.info("Loading File : " + propFile);
            try {
                PropertiesLoaderUtils.fillProperties(properties, new ClassPathResource(propFile));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    if (null == properties) {
        log.info("Loading system reference attributes : error ");
    } else {
        log.info("Loading system reference attributes : success ");
        if ("true".equals(propertiesTemplate.getIsDebug())) {
            log.info("***********************************************************************");
            log.info("List system reference attributes ");
            log.info("***********************************************************************");
            for (Object key : properties.keySet()) {
                log.info(key + " = " + properties.getProperty((String) key));
            }
        }
    }
    log.info("***********************************************************************\r\n");

}

From source file:gov.nih.nci.integration.util.CommonsPropertyLoaderUtil.java

/**
 * fill properties from given resource/* ww  w .java  2 s  .  c o m*/
 * 
 * @param resource - resource
 * @param properties - properties to fill
 */
private static void fillProperties(Resource resource, Properties properties) {
    try {
        if (resource.exists()) {
            LOG.info("merging properties form : " + resource.getDescription());
            PropertiesLoaderUtils.fillProperties(properties, resource);
        } else {
            LOG.info(String.format("can not merge property from %s as resource does not exists.",
                    resource.getDescription()));
        }
    } catch (IOException e) {
        final String message = "error while loading properties from resource" + resource;
        LOG.error(message, e);
        throw new RuntimeException(message, e);// NOPMD
    }
}

From source file:gov.nih.nci.cacis.common.util.CommonsPropertyLoaderUtil.java

/**
 * fill properties from given resource/*from ww  w  .  j  a  va  2s .c  o m*/
 *
 * @param resource   - resource
 * @param properties - properties to fill
 */
private static void fillProperties(Resource resource, Properties properties) {
    try {
        if (resource.exists()) {
            LOG.info("merging properties form : " + resource.getDescription());
            PropertiesLoaderUtils.fillProperties(properties, resource);
        } else {
            LOG.info(String.format("can not merge property from %s as resource does not exists.",
                    resource.getDescription()));
        }
    } catch (IOException e) {
        final String message = "error while loading properties from resource" + resource;
        LOG.error(message, e);
        throw new ApplicationRuntimeException(message, e);
    }
}

From source file:com.scf.core.context.app.cfg.module.ModuleConfigHandler.java

/**
 *
 * @param classPackage/*  w ww  .  java  2 s.  c  om*/
 * @param marges
 */
private static void loadModuleConfigs(String classPackage, Properties marges) {
    Resource[] resources = ClassScanner.scan(classPackage, "config.properties");
    for (Resource resource : resources) {
        try {
            if (!resource.exists()) {
                continue;
            }
            Properties props = new Properties();
            // ?file??
            String moduleName = resource.createRelative("/").getFilename();
            PropertiesLoaderUtils.fillProperties(props, new EncodedResource(resource, "utf-8"));
            ConfigParams cp = loadModuleConfig(marges, moduleName, props);
            _logger.info("Loaded module config for " + moduleName + " has " + cp.getParams().keySet().size()
                    + " properties.");
            map.put(moduleName, cp);
        } catch (IOException ex) {
            _logger.warn("Can not load module config for " + resource, ex);
        }
    }
}

From source file:com.themodernway.server.core.io.IO.java

public static final Properties toProperties(final Properties prop, final Resource resource) throws IOException {
    PropertiesLoaderUtils.fillProperties(prop, resource);

    return prop;//  w  w w  .  j  av a2  s . c  o  m
}

From source file:com.saysth.commons.quartz.SchedulerFactoryBean.java

/**
 * Load and/or apply Quartz properties to the given SchedulerFactory.
 * /*from   w ww  .j  a v a  2 s  .  c o  m*/
 * @param schedulerFactory
 *            the SchedulerFactory to initialize
 */
private void initSchedulerFactory(SchedulerFactory schedulerFactory) throws SchedulerException, IOException {

    if (!(schedulerFactory instanceof StdSchedulerFactory)) {
        if (this.configLocation != null || this.quartzProperties != null || this.taskExecutor != null
                || this.dataSource != null) {
            throw new IllegalArgumentException(
                    "StdSchedulerFactory required for applying Quartz properties: " + schedulerFactory);
        }
        // Otherwise assume that no initialization is necessary...
        return;
    }

    Properties mergedProps = new Properties();

    if (this.resourceLoader != null) {
        mergedProps.setProperty(StdSchedulerFactory.PROP_SCHED_CLASS_LOAD_HELPER_CLASS,
                ResourceLoaderClassLoadHelper.class.getName());
    }

    if (this.taskExecutor != null) {
        mergedProps.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS,
                LocalTaskExecutorThreadPool.class.getName());
    } else {
        // Set necessary default properties here, as Quartz will not apply
        // its default configuration when explicitly given properties.
        mergedProps.setProperty(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, SimpleThreadPool.class.getName());
        mergedProps.setProperty(PROP_THREAD_COUNT, Integer.toString(DEFAULT_THREAD_COUNT));
    }

    if (this.configLocation != null) {
        if (logger.isInfoEnabled()) {
            logger.info("Loading Quartz config from [" + this.configLocation + "]");
        }
        PropertiesLoaderUtils.fillProperties(mergedProps, this.configLocation);
    }

    CollectionUtils.mergePropertiesIntoMap(this.quartzProperties, mergedProps);

    if (this.dataSource != null) {
        mergedProps.put(StdSchedulerFactory.PROP_JOB_STORE_CLASS, LocalDataSourceJobStore.class.getName());
    }

    // Make sure to set the scheduler name as configured in the Spring
    // configuration.
    if (this.schedulerName != null) {
        mergedProps.put(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, this.schedulerName);
    }

    ((StdSchedulerFactory) schedulerFactory).initialize(mergedProps);
}

From source file:org.springframework.jmx.export.naming.KeyNamingStrategy.java

/**
 * Merges the {@code Properties} configured in the {@code mappings} and
 * {@code mappingLocations} into the final {@code Properties} instance
 * used for {@code ObjectName} resolution.
 *///from   w  ww.  j  av  a2 s  .co  m
@Override
public void afterPropertiesSet() throws IOException {
    this.mergedMappings = new Properties();
    CollectionUtils.mergePropertiesIntoMap(this.mappings, this.mergedMappings);

    if (this.mappingLocations != null) {
        for (Resource location : this.mappingLocations) {
            if (logger.isInfoEnabled()) {
                logger.info("Loading JMX object name mappings file from " + location);
            }
            PropertiesLoaderUtils.fillProperties(this.mergedMappings, location);
        }
    }
}

From source file:org.springframework.ui.freemarker.FreeMarkerConfigurationFactory.java

/**
 * Prepare the FreeMarker Configuration and return it.
 * @return the FreeMarker Configuration object
 * @throws IOException if the config file wasn't found
 * @throws TemplateException on FreeMarker initialization failure
 *//*from   w  w  w.ja  va2 s.  c o  m*/
public Configuration createConfiguration() throws IOException, TemplateException {
    Configuration config = newConfiguration();
    Properties props = new Properties();

    // Load config file if specified.
    if (this.configLocation != null) {
        if (logger.isInfoEnabled()) {
            logger.info("Loading FreeMarker configuration from " + this.configLocation);
        }
        PropertiesLoaderUtils.fillProperties(props, this.configLocation);
    }

    // Merge local properties if specified.
    if (this.freemarkerSettings != null) {
        props.putAll(this.freemarkerSettings);
    }

    // FreeMarker will only accept known keys in its setSettings and
    // setAllSharedVariables methods.
    if (!props.isEmpty()) {
        config.setSettings(props);
    }

    if (!CollectionUtils.isEmpty(this.freemarkerVariables)) {
        config.setAllSharedVariables(new SimpleHash(this.freemarkerVariables, config.getObjectWrapper()));
    }

    if (this.defaultEncoding != null) {
        config.setDefaultEncoding(this.defaultEncoding);
    }

    List<TemplateLoader> templateLoaders = new LinkedList<>(this.templateLoaders);

    // Register template loaders that are supposed to kick in early.
    if (this.preTemplateLoaders != null) {
        templateLoaders.addAll(this.preTemplateLoaders);
    }

    // Register default template loaders.
    if (this.templateLoaderPaths != null) {
        for (String path : this.templateLoaderPaths) {
            templateLoaders.add(getTemplateLoaderForPath(path));
        }
    }
    postProcessTemplateLoaders(templateLoaders);

    // Register template loaders that are supposed to kick in late.
    if (this.postTemplateLoaders != null) {
        templateLoaders.addAll(this.postTemplateLoaders);
    }

    TemplateLoader loader = getAggregateTemplateLoader(templateLoaders);
    if (loader != null) {
        config.setTemplateLoader(loader);
    }

    postProcessConfiguration(config);
    return config;
}