Example usage for java.util Properties putAll

List of usage examples for java.util Properties putAll

Introduction

In this page you can find the example usage for java.util Properties putAll.

Prototype

@Override
    public synchronized void putAll(Map<?, ?> t) 

Source Link

Usage

From source file:org.codehaus.groovy.grails.context.support.PluginAwareResourceBundleMessageSource.java

/**
 * Get a PropertiesHolder that contains the actually visible properties
 * for a Locale, after merging all specified resource bundles.
 * Either fetches the holder from the cache or freshly loads it.
 * <p>Only used when caching resource bundle contents forever, i.e.
 * with cacheSeconds < 0. Therefore, merged properties are always
 * cached forever./*w  w w  . jav a 2  s  .c om*/
 */
protected PropertiesHolder getMergedPluginProperties(Locale locale) {
    PropertiesHolder mergedHolder = cachedMergedPluginProperties.get(locale);
    if (mergedHolder != null) {
        return mergedHolder;
    }

    Properties mergedProps = new Properties();
    mergedHolder = new PropertiesHolder(mergedProps, -1);
    for (String basename : pluginBaseNames) {
        List<String> filenames = calculateAllFilenames(basename, locale);
        for (int j = filenames.size() - 1; j >= 0; j--) {
            String filename = filenames.get(j);
            PropertiesHolder propHolder = getProperties(filename);
            if (propHolder.getProperties() != null) {
                mergedProps.putAll(propHolder.getProperties());
            }
        }
    }
    final GrailsPlugin[] allPlugins = pluginManager.getAllPlugins();
    for (GrailsPlugin plugin : allPlugins) {
        if (plugin instanceof BinaryGrailsPlugin) {
            BinaryGrailsPlugin binaryPlugin = (BinaryGrailsPlugin) plugin;
            final Properties binaryPluginProperties = binaryPlugin.getProperties(locale);
            if (binaryPluginProperties != null) {
                mergedProps.putAll(binaryPluginProperties);
            }
        }
    }
    cachedMergedPluginProperties.put(locale, mergedHolder);
    return mergedHolder;
}

From source file:org.alfresco.ibatis.HierarchicalXMLConfigBuilder.java

private void propertiesElement(XNode context) throws Exception {
    if (context != null) {
        Properties defaults = context.getChildrenAsProperties();
        String resource = context.getStringAttribute("resource");
        String url = context.getStringAttribute("url");
        if (resource != null && url != null) {
            throw new BuilderException(
                    "The properties element cannot specify both a URL and a resource based property file reference.  Please specify one or the other.");
        }/*from w  ww .j a v  a  2  s  .c o m*/
        if (resource != null) {
            defaults.putAll(Resources.getResourceAsProperties(resource));
        } else if (url != null) {
            defaults.putAll(Resources.getUrlAsProperties(url));
        }
        Properties vars = configuration.getVariables();
        if (vars != null) {
            defaults.putAll(vars);
        }
        parser.setVariables(defaults);
        configuration.setVariables(defaults);
    }
}

From source file:com.wavemaker.commons.i18n.MultipleReloadableResourceBundleMessageSource.java

private PropertiesHolder refreshClassPathProperties(String filename, PropertiesHolder propHolder) {
    Properties properties = new Properties();
    long lastModified = -1;

    try {//from  w w  w  .j  av  a 2s.c  o m
        Resource[] resources = null;
        Resource[] propertiesResources = resolver.getResources(filename + PROPERTIES_SUFFIX);
        Resource[] xmlResources = resolver.getResources(filename + XML_SUFFIX);

        resources = getMergedResources(propertiesResources, xmlResources);

        if (resources != null && resources.length > 0) {
            String sourcePath = null;
            PropertiesHolder holder = null;
            for (Resource resource : resources) {
                sourcePath = resource.getURI().toString().replace(PROPERTIES_SUFFIX, "");
                holder = super.refreshProperties(sourcePath, propHolder);
                properties.putAll(holder.getProperties());
                if (lastModified < resource.lastModified())
                    lastModified = resource.lastModified();
            }
        }
    } catch (IOException ex) {
        if (logger.isDebugEnabled()) {
            logger.debug(filename + " could not be resolved in the file system", ex);
        }
    }

    return new PropertiesHolder(properties, lastModified);
}

From source file:com.netflix.suro.sink.kafka.KafkaSinkV2.java

@JsonCreator
public KafkaSinkV2(@JsonProperty("queue4Sink") MessageQueue4Sink queue4Sink,
        @JsonProperty("client.id") String clientId,
        @JsonProperty("metadata.broker.list") String bootstrapServers,
        @JsonProperty("compression.codec") String codec, @JsonProperty("send.buffer.bytes") int sendBufferBytes,
        @JsonProperty("batchSize") int batchSize, @JsonProperty("batchTimeout") int batchTimeout,
        @JsonProperty("request.timeout.ms") int requestTimeout, @JsonProperty("kafka.etc") Properties etcProps,
        @JsonProperty("keyTopicMap") Map<String, String> keyTopicMap,
        @JsonProperty("jobQueueSize") int jobQueueSize, @JsonProperty("corePoolSize") int corePoolSize,
        @JsonProperty("maxPoolSize") int maxPoolSize, @JsonProperty("jobTimeout") long jobTimeout,
        @JsonProperty("pauseOnLongQueue") boolean pauseOnLongQueue) {
    super(jobQueueSize, corePoolSize, maxPoolSize, jobTimeout,
            KafkaSink.class.getSimpleName() + "-" + clientId);

    Preconditions.checkNotNull(bootstrapServers);
    Preconditions.checkNotNull(clientId);

    this.clientId = clientId;
    initialize("kafka_" + clientId, queue4Sink == null ? new MemoryQueue4Sink(10000) : queue4Sink, batchSize,
            batchTimeout, pauseOnLongQueue);

    Properties props = new Properties();
    props.put("client.id", clientId);
    // metadata.broker.list was renamed to bootstrap.servers in the new kafka producer
    props.put("bootstrap.servers", bootstrapServers);
    if (codec != null) {
        props.put("compression.codec", codec);
    }/*from  w  w w  .  ja v  a  2  s .  c  om*/
    if (sendBufferBytes > 0) {
        props.put("send.buffer.bytes", Integer.toString(sendBufferBytes));
    }
    if (requestTimeout > 0) {
        props.put("request.timeout.ms", Integer.toString(requestTimeout));
    }

    if (etcProps != null) {
        props.putAll(etcProps);
    }

    this.keyTopicMap = keyTopicMap != null ? keyTopicMap : Maps.<String, String>newHashMap();

    producer = new KafkaProducer<>(props, new ByteArraySerializer(), new ByteArraySerializer());

    Monitors.registerObject(clientId, this);
}

From source file:org.bonitasoft.engine.home.BonitaHomeServer.java

private Properties mergeProperties(final Folder folder, Properties mergeInto) throws IOException {
    final FilenameFilter filter = new FilenameFilter() {

        public boolean accept(File dir, String filename) {
            return filename.endsWith(".properties");
        }//from   w  ww.j  a v  a 2 s .  c om
    };

    final List<File> files = folder.listFiles(filter);
    for (File file : files) {
        //System.out.println("load properties " + file);
        Properties properties = getProperties(file);
        for (Map.Entry<Object, Object> property : properties.entrySet()) {
            Object put = mergeInto.put(property.getKey(), property.getValue());
            if (put != null) {
                //System.out.println("Overriding " + property.getKey() + " with " + property.getValue());
            }
        }
        properties.putAll(properties);
    }
    return mergeInto;
}

From source file:com.liferay.ide.sdk.core.SDK.java

protected void persistAppServerProperties(Map<String, String> properties)
        throws FileNotFoundException, IOException, ConfigurationException {
    IPath loc = getLocation();/* ww  w .  j av a 2s.  c om*/

    // check for build.<username>.properties

    String userName = System.getProperty("user.name"); //$NON-NLS-1$

    File userBuildFile = loc.append("build." + userName + ".properties").toFile(); //$NON-NLS-1$ //$NON-NLS-2$

    if (userBuildFile.exists()) {
        /*
         * the build file exists so we need to check the following conditions 1. if the header in the comment
         * contains the text written by a previous SDK operation then we can write it again 2. if the file was not
         * previously written by us we will need to prompt the user with permission yes/no to update the
         * build.<username>.properties file
         */

        PropertiesConfiguration propsConfig = new PropertiesConfiguration(userBuildFile);

        String header = propsConfig.getHeader();

        boolean shouldUpdateBuildFile = false;

        if (header != null && header.contains(MSG_MANAGED_BY_LIFERAY_IDE)) {
            shouldUpdateBuildFile = true;
        } else {
            String overwrite = getPrefStore().get(SDKCorePlugin.PREF_KEY_OVERWRITE_USER_BUILD_FILE, ALWAYS);

            if (ALWAYS.equals(overwrite)) {
                shouldUpdateBuildFile = true;
            } else {
                shouldUpdateBuildFile = false;
            }
        }

        if (shouldUpdateBuildFile) {
            for (String key : properties.keySet()) {
                propsConfig.setProperty(key, properties.get(key));
            }

            propsConfig.setHeader(MSG_MANAGED_BY_LIFERAY_IDE);
            propsConfig.save(userBuildFile);
        }

    } else {
        Properties props = new Properties();

        props.putAll(properties);

        props.store(new FileOutputStream(userBuildFile), MSG_MANAGED_BY_LIFERAY_IDE);
    }

}

From source file:de.tudarmstadt.ukp.dkpro.core.api.resources.ResourceObjectProviderBase.java

/**
 * Builds the aggregated configuration from defaults and overrides.
 *
 * @return the aggregated effective configuration.
 * @throws IOException/*from www  .  j av a  2s .  c o m*/
 *             if the language-dependent default variants location is set but cannot be read.
 */
protected Properties getAggregatedProperties() throws IOException {
    Properties defaultValues = new Properties(defaults);
    Properties props = getProperties();
    if (props != null) {
        defaultValues.putAll(props);
    }

    Properties importedValues = new Properties(defaultValues);
    for (Entry<String, HasResourceMetadata> e : imports.entrySet()) {
        String value = e.getValue().getResourceMetaData().getProperty(e.getKey());
        if (value != null) {
            importedValues.setProperty(e.getKey(), value);
        }
    }

    Properties overriddenValues = new Properties(importedValues);
    overriddenValues.putAll(overrides);

    if ((defaultVariants == null) && (defaultVariantsLocation != null)) {
        String dvl = pph.replacePlaceholders(defaultVariantsLocation, overriddenValues);
        setDefaultVariants(PropertiesLoaderUtils.loadAllProperties(dvl));
    }

    String language = overriddenValues.getProperty(LANGUAGE);
    if ((defaultVariants != null) && defaultVariants.containsKey(language)) {
        defaultValues.setProperty(VARIANT, defaultVariants.getProperty(language));
    }

    return overriddenValues;
}

From source file:de.adorsys.forge.gwt.GWTFacet.java

public void addMessages(Map<String, String> messages) {
    Properties properties = new Properties();
    ResourceFacet resources = project.getFacet(ResourceFacet.class);
    MavenCoreFacet maven = project.getFacet(MavenCoreFacet.class);
    FileResource<?> resource = resources.getResource(getMessagePropertiesPath());
    InputStream is = resource.getResourceInputStream();
    FileOutputStream fileOutputStream = null;
    try {//from  w  w  w . jav a 2 s  .co  m
        // prefer the user messages
        properties.putAll(messages);
        properties.load(new InputStreamReader(is, UTF_8));
        is.close();
        fileOutputStream = new FileOutputStream(resource.getUnderlyingResourceObject());
        properties.store(new OutputStreamWriter(fileOutputStream, UTF_8), null);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        try {
            is.close();
            fileOutputStream.close();
        } catch (IOException e) {
        }
    }

    maven.executeMaven(Arrays.asList("generate-resources"));

}

From source file:io.fabric8.maven.plugin.AbstractDeployMojo.java

protected Properties getProjectAndFabric8Properties(MavenProject project) {
    Properties properties = project.getProperties();
    properties.putAll(project.getProperties());
    // let system properties override so we can read from the command line
    properties.putAll(System.getProperties());
    return properties;
}

From source file:com.meltmedia.cadmium.servlets.guice.CadmiumListener.java

@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
    //Force the use of slf4j logger in all JBoss log uses in this wars context!!!
    jboss = ContainerUtils.isJBoss();//from  ww  w .j av  a 2s  .c o  m
    if (jboss) {
        oldJBoss = ContainerUtils.isOldJBoss();
    }
    if (oldJBoss) {
        System.setProperty("org.jboss.logging.provider", "slf4j");
    }

    failOver = servletContextEvent.getServletContext().getRealPath("/");
    MaintenanceFilter.siteDown.start();
    context = servletContextEvent.getServletContext();

    configManager = new ConfigManager(context);

    Properties cadmiumProperties = configManager.getPropertiesByContext(context, "/WEB-INF/cadmium.properties");

    Properties configProperties = new Properties();
    configProperties = configManager.getSystemProperties();
    configProperties.putAll(cadmiumProperties);

    sharedContentRoot = sharedContextRoot(configProperties, context, log);

    // compute the directory for this application, based on the war name.
    warName = WarUtils.getWarName(context);

    vHostName = getVHostName(context);

    applicationContentRoot = applicationContentRoot(sharedContentRoot, warName, log);

    executor = new ScheduledThreadPoolExecutor(1);
    executor.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
    executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
    executor.setKeepAliveTime(5, TimeUnit.MINUTES);
    executor.setMaximumPoolSize(Math.min(Runtime.getRuntime().availableProcessors(), 4));

    configProperties = configManager.appendProperties(configProperties,
            new File(applicationContentRoot, CONFIG_PROPERTIES_FILE));

    configManager.setDefaultProperties(configProperties);
    configManager.setDefaultPropertiesFile(new File(applicationContentRoot, CONFIG_PROPERTIES_FILE));

    try {
        LogUtils.configureLogback(servletContextEvent.getServletContext(), applicationContentRoot,
                getVHostName(servletContextEvent.getServletContext()), log);
    } catch (IOException e) {
        log.error("Failed to reconfigure logging", e);
    }

    if ((sshDir = getSshDir(configProperties, sharedContentRoot, log)) != null) {
        GitService.setupSsh(sshDir.getAbsolutePath());
    }

    String repoDir = servletContextEvent.getServletContext().getInitParameter("repoDir");
    if (repoDir != null && repoDir.trim().length() > 0) {
        this.repoDir = repoDir;
    }
    String contentDir = servletContextEvent.getServletContext().getInitParameter("contentDir");
    if (contentDir != null && contentDir.trim().length() > 0) {
        this.contentDir = contentDir;
    }
    if (configProperties.containsKey(LAST_UPDATED_DIR)) {
        File cntDir = new File(configProperties.getProperty(LAST_UPDATED_DIR));
        if (cntDir.exists() && cntDir.canRead()) {
            this.contentDir = cntDir.getName();
        }
    }
    File repoFile = new File(this.applicationContentRoot, this.repoDir);
    if (repoFile.isDirectory() && repoFile.canWrite()) {
        this.repoDir = repoFile.getAbsoluteFile().getAbsolutePath();
    } else {
        log.warn("The repo directory may not have been initialized yet.");
        this.repoDir = repoFile.getAbsoluteFile().getAbsolutePath();
    }

    File contentFile = new File(this.applicationContentRoot, this.contentDir);
    if (contentFile.exists() && contentFile.isDirectory() && contentFile.canWrite()) {
        this.contentDir = contentFile.getAbsoluteFile().getAbsolutePath();
    } else {
        log.warn("The content directory may not have been initialized yet.");
        this.contentDir = contentFile.getAbsoluteFile().getAbsolutePath();
    }

    String channelCfgUrl = configProperties.getProperty(JGROUPS_CHANNEL_CONFIG_URL);
    //String channelCfgUrl = System.getProperty(JGROUPS_CHANNEL_CONFIG_URL);
    if (channelCfgUrl != null) {
        File channelCfgFile = null;
        URL fileUrl = null;
        try {
            fileUrl = new URL(channelCfgUrl);
        } catch (Exception e) {
            channelCfgFile = new File(channelCfgUrl);
        }
        if (fileUrl == null && channelCfgFile != null) {
            if (!channelCfgFile.isAbsolute() && !channelCfgFile.exists()) {
                channelCfgFile = new File(this.sharedContentRoot, channelCfgUrl);
                if (channelCfgFile.exists()) {
                    this.channelConfigUrl = "file://" + channelCfgFile.getAbsoluteFile().getAbsolutePath();
                }
            } else {
                this.channelConfigUrl = "file://" + channelCfgFile.getAbsoluteFile().getAbsolutePath();
            }
        } else if (fileUrl != null) {
            this.channelConfigUrl = fileUrl.toString();
        }
    }
    Vfs.addDefaultURLTypes(new JBossVfsUrlType());
    reflections = Reflections.collect();
    Module modules[] = new Module[] { createServletModule(), createModule() };
    InternalInjectorCreator guiceCreator = new InternalInjectorCreator().stage(Stage.DEVELOPMENT)
            .addModules(Arrays.asList(modules));
    try {
        injector = guiceCreator.build();

        //injector = Guice.createInjector(createServletModule(), createModule());

        // run the postConstruct methods.
        jsr250Executor = Jsr250Utils.createJsr250Executor(injector, log, Scopes.SINGLETON);
        jsr250Executor.postConstruct();

        super.contextInitialized(servletContextEvent);
        File graphFile = new File(applicationContentRoot, "injector.dot");
        graphGood(graphFile, injector);
    } catch (Throwable t) {
        try {
            log.error("Failed to initialize...", t);
            Method primaryInjector = InternalInjectorCreator.class.getDeclaredMethod("primaryInjector");
            primaryInjector.setAccessible(true);
            injector = (Injector) primaryInjector.invoke(guiceCreator);
            if (injector == null) {
                log.error("Injector must not have been created.");
            } else {
                log.error("Found injector {}", injector);
            }
        } catch (Throwable e) {
            log.error("Failed to retrieve injector that failed to initialize.", e);
        }
        throw new RuntimeException("Failed to Initialize", t);
    }
}