Example usage for java.util Properties put

List of usage examples for java.util Properties put

Introduction

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

Prototype

@Override
    public synchronized Object put(Object key, Object value) 

Source Link

Usage

From source file:com.panet.imeta.core.database.ConnectionPoolUtil.java

private static void createPool(DatabaseMeta databaseMeta, String partitionId, int initialSize, int maximumSize)
        throws KettleDatabaseException {
    LogWriter.getInstance().logBasic(databaseMeta.toString(),
            Messages.getString("Database.CreatingConnectionPool", databaseMeta.getName()));
    GenericObjectPool gpool = new GenericObjectPool();

    gpool.setMaxIdle(-1);/*w  w w .j  a v  a2  s  . co m*/
    gpool.setWhenExhaustedAction(GenericObjectPool.WHEN_EXHAUSTED_GROW);
    gpool.setMaxActive(maximumSize);

    String clazz = databaseMeta.getDriverClass();
    try {
        Class.forName(clazz).newInstance();
    } catch (Exception e) {
        throw new KettleDatabaseException(Messages.getString(
                "Database.UnableToLoadConnectionPoolDriver.Exception", databaseMeta.getName(), clazz), e);
    }

    String url;
    String userName;
    String password;

    try {
        url = databaseMeta.environmentSubstitute(databaseMeta.getURL(partitionId));
        userName = databaseMeta.environmentSubstitute(databaseMeta.getUsername());
        password = databaseMeta.environmentSubstitute(databaseMeta.getPassword());
    } catch (RuntimeException e) {
        url = databaseMeta.getURL(partitionId);
        userName = databaseMeta.getUsername();
        password = databaseMeta.getPassword();
    }

    // Get the list of pool properties
    Properties originalProperties = databaseMeta.getConnectionPoolingProperties();
    //Add user/pass
    originalProperties.setProperty("user", Const.NVL(userName, ""));
    originalProperties.setProperty("password", Const.NVL(password, ""));

    // Now, replace the environment variables in there...
    Properties properties = new Properties();
    Iterator<Object> iterator = originalProperties.keySet().iterator();
    while (iterator.hasNext()) {
        String key = (String) iterator.next();
        String value = originalProperties.getProperty(key);
        properties.put(key, databaseMeta.environmentSubstitute(value));
    }

    // Create factory using these properties.
    //
    ConnectionFactory cf = new DriverManagerConnectionFactory(url, properties);

    new PoolableConnectionFactory(cf, gpool, null, null, false, false);

    for (int i = 0; i < initialSize; i++) {
        try {
            gpool.addObject();
        } catch (Exception e) {
            throw new KettleDatabaseException(
                    Messages.getString("Database.UnableToPreLoadConnectionToConnectionPool.Exception"), e);
        }
    }

    pd.registerPool(databaseMeta.getName(), gpool);

    LogWriter.getInstance().logBasic(databaseMeta.toString(),
            Messages.getString("Database.CreatedConnectionPool", databaseMeta.getName()));
}

From source file:com.sun.socialsite.config.Config.java

/**
 * Get properties starting with a specified string.
 *//*  www .ja v  a 2  s.  c o m*/
public static Properties getPropertiesStartingWith(String startingWith) {
    Properties ret = new Properties();
    for (Iterator it = expandedProperties.keySet().iterator(); it.hasNext();) {
        String key = (String) it.next();
        ret.put(key, expandedProperties.get(key));
    }
    return ret;
}

From source file:frameworkcontentspeed.Utils.SendEmailAtachament.java

public static void sendGRUP(String from, String password, String bcc, String sub, String msg, String filename)
        throws Exception {
    //Get properties object    
    Properties props = new Properties();
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.socketFactory.port", "465");
    props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.port", "465");
    //get Session   
    Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(from, password);
        }//w  ww. ja va2s . c  o  m
    });
    //compose message    
    try {
        MimeMessage message = new MimeMessage(session);
        //message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
        message.addRecipient(Message.RecipientType.BCC, new InternetAddress(bcc));

        message.setSubject(sub);
        message.setText(msg);

        BodyPart messageBodyPart = new MimeBodyPart();

        messageBodyPart.setText("Raport teste automat");

        Multipart multipart = new MimeMultipart();

        multipart.addBodyPart(messageBodyPart);

        messageBodyPart = new MimeBodyPart();

        DataSource source = new FileDataSource(filename);

        messageBodyPart.setDataHandler(new DataHandler(source));

        messageBodyPart.setFileName(filename);

        multipart.addBodyPart(messageBodyPart);

        //message.setContent(multipart);
        StringWriter writer = new StringWriter();
        IOUtils.copy(new FileInputStream(new File(filename)), writer);

        message.setContent(writer.toString(), "text/html");

        //send message  
        Transport.send(message);
        System.out.println("message sent successfully");
    } catch (MessagingException e) {
        throw new RuntimeException(e);
    }

}

From source file:frameworkcontentspeed.Utils.SendEmailAtachament.java

public static void SendEmailAnda(String from, String to1, String subject, String filename)
        throws FileNotFoundException, IOException {
    //Get properties object    
    Properties props = new Properties();
    props.put("mail.smtp.host", "smtp.gmail.com");
    props.put("mail.smtp.socketFactory.port", "465");
    props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.port", "465");
    //get Session   
    Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(from, "anda.cristea");
        }/*www  .ja  va2s  . co  m*/
    });
    //compose message    
    try {
        MimeMessage message = new MimeMessage(session);
        message.addRecipient(Message.RecipientType.TO, new InternetAddress(to1));

        message.setSubject(subject);
        // message.setText(msg);

        BodyPart messageBodyPart = new MimeBodyPart();

        messageBodyPart.setText("Raport teste automate");

        Multipart multipart = new MimeMultipart();

        multipart.addBodyPart(messageBodyPart);

        messageBodyPart = new MimeBodyPart();

        DataSource source = new FileDataSource(filename);

        messageBodyPart.setDataHandler(new DataHandler(source));

        messageBodyPart.setFileName(filename);

        multipart.addBodyPart(messageBodyPart);

        //message.setContent(multipart);

        StringWriter writer = new StringWriter();
        IOUtils.copy(new FileInputStream(new File(filename)), writer);

        message.setContent(writer.toString(), "text/html");

        //send message  
        Transport.send(message);

    } catch (MessagingException e) {
        throw new RuntimeException(e);
    }

}

From source file:IOUtils.java

public static ContentHandler getSerializer(File file) throws IOException, TransformerException {
    final FileWriter writer = new FileWriter(file);

    final TransformerHandler transformerHandler = FACTORY.newTransformerHandler();
    final Transformer transformer = transformerHandler.getTransformer();

    final Properties format = new Properties();
    format.put(OutputKeys.METHOD, "xml");
    format.put(OutputKeys.OMIT_XML_DECLARATION, "no");
    format.put(OutputKeys.ENCODING, "UTF-8");
    format.put(OutputKeys.INDENT, "yes");
    transformer.setOutputProperties(format);

    transformerHandler.setResult(new StreamResult(writer));

    try {/*from   ww  w .  j  av a2  s . com*/
        if (needsNamespacesAsAttributes(format)) {
            return new NamespaceAsAttributes(transformerHandler);
        }
    } catch (SAXException se) {
        throw new TransformerException("Unable to detect of namespace support for sax works properly.", se);
    }
    return transformerHandler;
}

From source file:com.glaf.core.util.CalendarUtils.java

public static Properties loadCalendarProperties() {
    List<SystemParam> params = getSystemParamService().getSystemParams("calendar", "calendar");
    if (params != null && !params.isEmpty()) {
        Properties props = new Properties();
        for (SystemParam p : params) {
            props.put(p.getKeyName(), p.getStringVal());
        }/*from  w w  w . j  a v a2 s  .co  m*/
        return props;
    }
    String filename = SystemProperties.getAppPath() + "/WEB-INF/conf/work_calendar.properties";
    return PropertiesUtils.loadFilePathResource(filename);
}

From source file:com.wingnest.blueprints.impls.jpa.internal.wrappers.EntityManagerFactoryWrapper.java

@SuppressWarnings("rawtypes")
private static Map getProperties(Configuration configuration) {
    Iterator<String> it = configuration.getKeys(BLUEPRINTS_JPAGRAPH_PERSISTENCE_UNIT_PROPERTIES);
    Properties props = new Properties();
    while (it.hasNext()) {
        String key = it.next();//from  www.  j av  a 2 s.c  o m
        String newkey = key.substring(BLUEPRINTS_JPAGRAPH_PERSISTENCE_UNIT_PROPERTIES.length() + 1)
                .replaceAll("\\.\\.", ".");
        String value = configuration.getString(key);
        props.put(newkey, value);
        logger.debug("EntityManagerFactory getProperties : key = " + newkey + ", value = " + value);
    }
    return props;
}

From source file:frameworkcontentspeed.Utils.SendEmailAtachament.java

public static void SendEmailPassed(String from, String to1, String subject, String filename)
        throws FileNotFoundException, IOException {

    try {//from ww  w .j  a  v a  2s.  com

        //Get properties object    
        Properties props = new Properties();
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.socketFactory.port", "465");
        props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.port", "465");
        //get Session   
        Session session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(from, "anda.cristea");
            }
        });
        //compose message    
        try {
            MimeMessage message = new MimeMessage(session);
            message.addRecipient(Message.RecipientType.TO, new InternetAddress(to1));
            //message.addRecipient(Message.RecipientType.BCC, new InternetAddress(grupSephora));

            message.setSubject(subject);
            // message.setText(msg);

            BodyPart messageBodyPart = new MimeBodyPart();

            messageBodyPart.setText("Raport teste automate");

            Multipart multipart = new MimeMultipart();

            multipart.addBodyPart(messageBodyPart);

            messageBodyPart = new MimeBodyPart();

            DataSource source = new FileDataSource(filename);

            messageBodyPart.setDataHandler(new DataHandler(source));

            messageBodyPart.setFileName(filename);

            multipart.addBodyPart(messageBodyPart);

            message.setContent(multipart);

            //send message  
            Transport.send(message);
            System.out.println("message sent successfully");
        } catch (Exception ex) {
            System.out.println("eroare trimitere email-uri");
            System.out.println(ex.getMessage());

        }

    } catch (Exception ex) {
        System.out.println("eroare trimitere email-uri");
        System.out.println(ex.getMessage());

    }

}

From source file:org.paxml.launch.LaunchModel.java

private static List<Properties> explodeFactors(Settings settings) {

    List<String> factorNames = new ArrayList<String>();

    List<List<Object>> factors = new ArrayList<List<Object>>();
    for (Map.Entry<String, Factor> entry : settings.getFactors().entrySet()) {
        factors.add(new ArrayList<Object>(entry.getValue().getValues()));
        factorNames.add(entry.getKey());
    }//from   w w  w  . j a v a 2  s.  c o  m

    if (factorNames.size() < 1) {
        return null;
    } else {
        List<List<Object>> exploded = new ArrayList<List<Object>>();
        for (Object factor : factors.get(0)) {
            List<Object> item = new ArrayList<Object>();
            item.add(factor);
            exploded.add(item);
        }
        // make more combinations
        for (int i = 1; i < factors.size(); i++) {
            List<Object> more = factors.get(i);
            exploded = combineMoreFactors(exploded, more);
        }

        List<Properties> result = new ArrayList<Properties>();

        for (int i = 0; i < exploded.size(); i++) {
            List<Object> combination = exploded.get(i);
            Properties map = new Properties();
            for (int j = 0; j < factorNames.size(); j++) {
                map.put(factorNames.get(j), combination.get(j));
            }
            result.add(map);
        }

        return result;
    }
}

From source file:com.ikanow.aleph2.distributed_services.utils.KafkaUtils.java

private static Properties addGroupIdToProps(final String groupid) {
    final Properties np = new Properties();
    kafka_properties.forEach((key, val) -> np.put(key, val));
    np.put("group.id", groupid);
    return np;//from www  . j  a v  a  2  s. c o m
}