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:com.savy3.util.DBConfiguration.java

/** Returns a connection object to the DB.
 * @throws ClassNotFoundException// w w  w .  j a v a2s  .  co  m
 * @throws SQLException */
public Connection getConnection() throws ClassNotFoundException, SQLException {
    Connection connection;

    Class.forName(conf.get(DBConfiguration.DRIVER_CLASS_PROPERTY));

    String username = conf.get(DBConfiguration.USERNAME_PROPERTY);
    String password = getPassword((JobConf) conf);
    String connectString = conf.get(DBConfiguration.URL_PROPERTY);
    String connectionParamsStr = conf.get(DBConfiguration.CONNECTION_PARAMS_PROPERTY);
    Properties connectionParams = propertiesFromString(connectionParamsStr);

    if (connectionParams != null && connectionParams.size() > 0) {
        Properties props = new Properties();
        if (username != null) {
            props.put("user", username);
        }

        if (password != null) {
            props.put("password", password);
        }

        props.putAll(connectionParams);
        connection = DriverManager.getConnection(connectString, props);
    } else {
        if (username == null) {
            connection = DriverManager.getConnection(connectString);
        } else {
            connection = DriverManager.getConnection(connectString, username, password);
        }
    }

    return connection;
}

From source file:org.codehaus.redback.rest.services.DefaultUtilServices.java

private void loadResource(final Properties finalProperties, String resourceName, String locale)
        throws IOException {
    InputStream is = null;//from   w  w  w  .j  av a2  s. c  o  m
    Properties properties = new Properties();
    try {
        if (StringUtils.isNotEmpty(locale)) {
            resourceName = resourceName + "_" + locale;
        }
        resourceName = resourceName + ".properties";
        is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName.toString());
        if (is != null) {
            properties.load(is);
            finalProperties.putAll(properties);
        } else {
            if (!StringUtils.equalsIgnoreCase(locale, "en")) {
                log.info("cannot load resource {}", resourceName);
            }
        }
    } finally {
        IOUtils.closeQuietly(is);
    }

}

From source file:gov.nasa.ensemble.common.CommonPlugin.java

/**
 * Initialize Ensemble with the ensemble properties file. This method will
 * attempt to find the properties file in the following manner:
 * //  www. ja va  2  s  .  c  o  m
 * 1. Search for the system property "ensemble.properties.file". If this
 * property is defined, then use the property's value to find the properties
 * file.
 * 
 * 2. Search for the extension point
 * gov.nasa.ensemble.core.rcp.EnsemblePropertiesProvider. If one and only
 * one of these extension points are defined, then use it to create an
 * EnsemblePropertiesProvider class and then ask this class for the
 * properties file location.
 * 
 * 3. If neither of these options provide a properties file location, then
 * return an empty properties object. Else read in the properties file to a
 * properties object and return it.  In addition, populate the System
 * properties with all the Ensemble properties.
 * 
 * 4. If there are any registered implementations of IEnsemblePropertiesPatch,
 * load their properties on top of the properties assembled thus far.
 * 
 */
private Properties initializeEnsembleProperties() {
    final Properties props = basicInitializeEnsembleProperties();
    ensemblePropertiesDefinedInFile = new ArrayList(props.keySet());
    TreeSet<EnsemblePropertiesPatch> patchers = new TreeSet<EnsemblePropertiesPatch>(
            ClassRegistry.createInstances(EnsemblePropertiesPatch.class));
    for (EnsemblePropertiesPatch patch : patchers)
        props.putAll(patch.getPatchedProperties(props));

    // MAE-5459, -D<property>=<value> should override ensemble.properties
    props.putAll(System.getProperties());

    // add the ensemble properties to the System properties 
    for (Object obj : props.keySet()) {
        String key = (String) obj;

        // Don't patch in empty keys
        if (key.isEmpty())
            continue;

        System.setProperty(key, props.getProperty(key));
    }

    return props;
}

From source file:org.hibernate.internal.SessionFactoryImpl.java

@SuppressWarnings({ "unchecked" })
private static Properties createPropertiesFromMap(Map map) {
    Properties properties = new Properties();
    properties.putAll(map);
    return properties;
}

From source file:com.util.InstallUtil.java

private Properties getProperties() {
    Properties properties = new Properties();
    try {/*w  w  w  . j a v a 2s  .  c  om*/
        properties = getDefaultProperties();
    } catch (IOException e) {
        log.error(e.getMessage(), e);
    }

    properties.putAll(InstallValues.getProperties());

    properties.put("Jboss_JNDI_prefix", "topic/");
    properties.put("ldap_user_password", encodeMD5(properties.getProperty("ldap_password")));
    properties.put("super_admin_password", encodeMD5(properties.getProperty("system4_admin_password")));

    String pop3Server = "";
    String mailAddress = properties.getProperty("admin_email");
    if (mailAddress != null && mailAddress.contains("@"))
        pop3Server = "pop3." + mailAddress.substring(mailAddress.indexOf("@") + 1);
    else
        pop3Server = properties.getProperty("mailserver");

    properties.put("mailserver_pop3", pop3Server);

    boolean useSSLMail = "true".equalsIgnoreCase(properties.getProperty("mailserver_use_ssl"));
    if (useSSLMail)
        properties.put("mail_transport_protocol", "smtps");
    else
        properties.put("mail_transport_protocol", "smtp");

    boolean enableSSL = "true".equalsIgnoreCase(properties.getProperty("server_ssl_enable", "false"));
    if (enableSSL) {
        properties.setProperty("ssl_comments_end", "-->");
        properties.setProperty("ssl_comments_start", "<!--");
        String kspwd = properties.getProperty("server_ssl_ks_pwd");
        if (kspwd == null || "".equals(kspwd.trim()))
            properties.setProperty("server_ssl_ks_pwd", "changeit");
    } else {
        properties.setProperty("ssl_comments_end", "");
        properties.setProperty("ssl_comments_start", "");
        properties.setProperty("server_ssl_port", "443");
        properties.setProperty("server_ssl_ks_pwd", "changeit");
    }

    boolean enableEmailServer = "true"
            .equalsIgnoreCase(properties.getProperty("system_notification_enabled", "false"));
    properties.setProperty("mail_smtp_start", enableEmailServer ? "" : "<!--");
    properties.setProperty("mail_smtp_end", enableEmailServer ? "" : "-->");

    boolean enableEmailAuthentication = "true"
            .equalsIgnoreCase(properties.getProperty("email_authentication_enabled", "false"));
    if (!enableEmailServer) {
        enableEmailAuthentication = true;
    }
    properties.setProperty("mail_authentication_start", enableEmailAuthentication ? "" : "<!--");
    properties.setProperty("mail_authentication_end", enableEmailAuthentication ? "" : "-->");

    return properties;
}

From source file:io.swagger.assert4j.maven.RunMojo.java

private void readRecipeProperties() throws IOException {
    File recipeProperties = new File(recipeDirectory, "recipe.properties");
    if (properties == null) {
        properties = new HashMap();
    }//from  www . j  a  va  2s .  c  o  m
    if (recipeProperties.exists()) {
        Properties props = new Properties();
        props.load(new FileInputStream(recipeProperties));
        getLog().debug("Read " + props.size() + " properties from recipe.properties");

        // override with properties in config section
        if (properties != null) {
            props.putAll(properties);
        }

        properties = props;
    }
}

From source file:io.lavagna.service.MailTicketService.java

private MailReceiver getImapMailReceiver(ProjectMailTicketConfigData config) {
    String sanitizedUsername = sanitizeUsername(config.getInboundUser());
    String inboxFolder = getInboxFolder(config);

    String url = config.getInboundProtocol() + "://" + sanitizedUsername + ":" + config.getInboundPassword()
            + "@" + config.getInboundServer() + ":" + config.getInboundPort() + "/" + inboxFolder.toLowerCase();

    ImapMailReceiver receiver = new ImapMailReceiver(url);
    receiver.setShouldMarkMessagesAsRead(true);
    receiver.setShouldDeleteMessages(false);

    Properties mailProperties = new Properties();
    if (config.getInboundProtocol().equals("imaps")) {
        mailProperties.setProperty("mail.pop3.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        mailProperties.setProperty("mail.pop3.socketFactory.fallback", "false");
    }//from  w w  w . ja v  a  2  s  .com
    mailProperties.setProperty("mail.store.protocol", config.getInboundProtocol());
    mailProperties.putAll(config.generateInboundProperties());
    receiver.setJavaMailProperties(mailProperties);

    receiver.afterPropertiesSet();

    return receiver;
}

From source file:it.greenvulcano.gvesb.api.controller.GvConfigurationControllerRest.java

@PUT
@Path("/property")
@Consumes(MediaType.APPLICATION_JSON)//from  w  ww  .  j a  va 2s. c  o m
@RolesAllowed({ Authority.ADMINISTRATOR, Authority.MANAGER })
public void updateProperties(String properties) {
    try {
        JSONObject configJson = new JSONObject(properties);

        Properties configProperties = new Properties();
        configProperties.putAll(gvConfigurationManager.getXMLConfigProperties());

        configJson.keySet().stream().filter(k -> !configJson.isNull(k))
                .forEach(k -> configProperties.put(k, configJson.get(k).toString()));

        gvConfigurationManager.saveXMLConfigProperties(configProperties);

    } catch (JSONException e) {
        throw new WebApplicationException(Response.status(Response.Status.BAD_REQUEST).build());
    } catch (Exception e) {
        LOG.error("Failed to update XMLConfigProperties ", e);
        throw new WebApplicationException(Response.status(Response.Status.SERVICE_UNAVAILABLE).build());
    }
}

From source file:io.joynr.runtime.MessagingServletConfig.java

@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {

    ServletContext servletContext = servletContextEvent.getServletContext();

    // properties from appProperties will extend and override the default
    // properties
    Properties properties = new LowerCaseProperties(
            PropertyLoader.loadProperties(DEFAULT_SERVLET_MESSAGING_PROPERTIES));
    String appPropertiesFileName = servletContext.getInitParameter("properties");
    if (appPropertiesFileName != null) {
        Properties appProperties = ServletPropertyLoader.loadProperties(appPropertiesFileName, servletContext);
        properties.putAll(appProperties);
    } else {/*from   w  ww .j a v a  2 s  .  c  o m*/
        logger.warn("to load properties, set the initParameter 'properties' ");
    }

    // add OS environment properties
    properties.putAll(System.getenv());

    servletModuleName = properties.getProperty(INIT_PARAM_SERVLET_MODULE_CLASSNAME);
    servletModuleName = servletModuleName == null ? DEFAULT_SERVLET_MODULE_NAME : servletModuleName;

    // create a reflection set used to find
    // * all plugin application classes implementing the JoynApplication interface
    // * all servlets annotated as WebServlet
    // * the class implementing JoynrInjectorFactory (should be only one)
    Object[] appPackages = mergeAppPackages(properties);

    // Add Java system properties (set with -D)
    properties.putAll(System.getProperties());

    // TODO if reflections is ever a performance problem, can statically scan and save the reflections data using
    // Maven,
    // then work on the previously scanned data
    // see: https://code.google.com/p/reflections/wiki/UseCases
    Reflections reflections = new Reflections("io.joynr.runtime", appPackages);
    final Set<Class<?>> classesAnnotatedWithWebServlet = reflections
            .getTypesAnnotatedWith(JoynrWebServlet.class);
    final Set<Class<?>> classesAnnotatedWithProvider = reflections
            .getTypesAnnotatedWith(javax.ws.rs.ext.Provider.class);

    // The jerseyServletModule injects the servicing classes using guice,
    // instead of letting jersey do it natively
    jerseyServletModule = new AbstractJoynrServletModule() {

        @SuppressWarnings("unchecked")
        @Override
        protected void configureJoynrServlets() {
            bind(GuiceContainer.class);
            bind(JacksonJsonProvider.class).asEagerSingleton();

            bind(MessagingService.class);
            //get all classes annotated with @Provider and bind them
            for (Class<?> providerClass : classesAnnotatedWithProvider) {
                bind(providerClass).in(Scopes.SINGLETON);
            }

            for (Class<?> webServletClass : classesAnnotatedWithWebServlet) {
                if (!HttpServlet.class.isAssignableFrom(webServletClass)) {
                    continue;
                }

                bind(webServletClass);
                JoynrWebServlet webServletAnnotation = webServletClass.getAnnotation(JoynrWebServlet.class);
                if (webServletAnnotation == null) {
                    logger.error("webServletAnnotation was NULL.");
                    continue;
                }
                serve(webServletAnnotation.value()).with((Class<? extends HttpServlet>) webServletClass);
            }
        }

        // this @SuppressWarnings is needed for the build on jenkins
        @SuppressWarnings("unused")
        @Provides
        public IServletMessageReceivers providesMessageReceivers() {
            return messageReceivers;
        }

    };
    Class<?> servletModuleClass = null;
    Module servletModule = null;
    try {
        servletModuleClass = this.getClass().getClassLoader().loadClass(servletModuleName);
        servletModule = (Module) servletModuleClass.newInstance();
    } catch (ClassNotFoundException e) {
        logger.debug("Servlet module class not found will use default configuration");
    } catch (Exception e) {
        logger.error("", e);
    }

    if (servletModule == null) {
        servletModule = new EmptyModule();
    }

    properties.put(MessagingPropertyKeys.PROPERTY_SERVLET_CONTEXT_ROOT, servletContext.getContextPath());

    String hostPath = properties.getProperty(MessagingPropertyKeys.PROPERTY_SERVLET_HOST_PATH);
    if (hostPath == null) {
        hostPath = properties.getProperty("hostpath");
    }
    if (hostPath != null) {
        properties.setProperty(MessagingPropertyKeys.PROPERTY_SERVLET_HOST_PATH, hostPath);
    }

    // find all plugin application classes implementing the JoynApplication interface
    Set<Class<? extends JoynrApplication>> joynrApplicationsClasses = reflections
            .getSubTypesOf(JoynrApplication.class);
    Set<Class<? extends AbstractJoynrInjectorFactory>> joynrInjectorFactoryClasses = reflections
            .getSubTypesOf(AbstractJoynrInjectorFactory.class);
    assert (joynrInjectorFactoryClasses.size() == 1);

    Injector injector = Guice.createInjector(new AbstractModule() {
        @Override
        protected void configure() {
        }
    });
    AbstractJoynrInjectorFactory injectorFactory = injector
            .getInstance(joynrInjectorFactoryClasses.iterator().next());
    appLauncher = injector.getInstance(JoynrApplicationLauncher.class);

    logger.info("starting joynr with properties: {}", properties);

    appLauncher.init(properties, joynrApplicationsClasses, injectorFactory,
            Modules.override(jerseyServletModule, new CCInProcessRuntimeModule()).with(servletModule,
                    new ServletMessagingModule()));

    super.contextInitialized(servletContextEvent);
}

From source file:com.adaptris.core.QuartzCronPoller.java

private Properties createQuartzProperties() throws CoreException {
    try {//from  w  w w  . j a  v  a  2s .  com
        Properties result = PropertyHelper.load(() -> {
            return openQuartzProperties();
        });
        result.put(StdSchedulerFactory.PROP_SCHED_MAKE_SCHEDULER_THREAD_DAEMON, Boolean.TRUE.toString());
        result.putAll(System.getProperties());
        if (useCustomThreadPool()) {
            result.put(StdSchedulerFactory.PROP_THREAD_POOL_CLASS,
                    NonBlockingQuartzThreadPool.class.getCanonicalName());
        }
        // result.put(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, schedulerName);
        // result.put("org.quartz.plugin.shutdownhook.class",
        // org.quartz.plugins.management.ShutdownHookPlugin.class.getCanonicalName());
        // result.put("org.quartz.plugin.shutdownhook.cleanShutdown", Boolean.FALSE.toString());
        return result;
    } catch (Exception e) {
        throw ExceptionHelper.wrapCoreException(e);
    }
}