List of usage examples for java.util Properties put
@Override public synchronized Object put(Object key, Object value)
From source file:gobblin.util.PropertiesUtils.java
/** * Extract all the keys that start with a <code>prefix</code> in {@link Properties} to a new {@link Properties} * instance.//from w w w . j a v a2s . c om * * @param properties the given {@link Properties} instance * @param prefix of keys to be extracted * @return a {@link Properties} instance */ public static Properties extractPropertiesWithPrefix(Properties properties, Optional<String> prefix) { Preconditions.checkNotNull(properties); Preconditions.checkNotNull(prefix); Properties extractedProperties = new Properties(); for (Map.Entry<Object, Object> entry : properties.entrySet()) { if (StringUtils.startsWith(entry.getKey().toString(), prefix.or(StringUtils.EMPTY))) { extractedProperties.put(entry.getKey().toString(), entry.getValue()); } } return extractedProperties; }
From source file:com.rxx.common.util.MailUtil.java
/** * html//from w w w . j ava 2 s . co m * * @param host * @param port * @param userName * @param password * @param title * @param contenthtml * @param fileslist<Map<key:,value:>> * @param toUser * @throws javax.mail.MessagingException */ public static void sendAttached(String host, int port, String userName, String password, String title, String content, List<Map<String, String>> files, String[] toUser) throws MessagingException, javax.mail.MessagingException { JavaMailSenderImpl senderImpl = new JavaMailSenderImpl(); // mail server senderImpl.setHost(host); // ,html MimeMessage mailMessage = senderImpl.createMimeMessage(); // boolean,MimeMessageHelpertrue // multipart true html MimeMessageHelper messageHelper = new MimeMessageHelper(mailMessage, true, "utf-8"); // messageHelper.setTo(toUser); messageHelper.setFrom(userName); messageHelper.setSubject(title); // true HTML messageHelper.setText(content, true); for (Map<String, String> filePath : files) { Iterator<String> it = filePath.keySet().iterator(); String fileName = it.next(); FileSystemResource file = new FileSystemResource(new File(filePath.get(fileName))); // messageHelper.addAttachment(fileName, file); } senderImpl.setUsername(userName); // ,username senderImpl.setPassword(password); // , password Properties prop = new Properties(); prop.put("mail.smtp.auth", "true"); // true, prop.put("mail.smtp.timeout", "25000"); senderImpl.setJavaMailProperties(prop); // senderImpl.send(mailMessage); }
From source file:uk.ac.cam.cl.dtg.picky.client.analytics.Analytics.java
private static void fillProperties(Properties properties, CachedReadingStrategy cachedReadingStrategy) { if (cachedReadingStrategy == null) return;// w w w .j a v a2 s . c om properties.put(KEY_REPOSITORY_BYTES_DOWNLOADED, "" + cachedReadingStrategy.getRepository().bytesRead()); }
From source file:io.mesosphere.mesos.frameworks.cassandra.executor.ProdObjectFactory.java
private static void modifyCassandraRackdc(@NotNull final Marker taskIdMarker, @NotNull final String version, @NotNull final CassandraServerConfig serverConfig) throws IOException { LOGGER.info(taskIdMarker, "Building cassandra-rackdc.properties"); final Properties props = new Properties(); final RackDc rackDc = serverConfig.getRackDc(); props.put("dc", rackDc.getDc()); props.put("rack", rackDc.getRack()); // Add a suffix to a datacenter name. Used by the Ec2Snitch and Ec2MultiRegionSnitch to append a string to the EC2 region name. //props.put("dc_suffix", ""); // Uncomment the following line to make this snitch prefer the internal ip when possible, as the Ec2MultiRegionSnitch does. //props.put("prefer_local", "true"); final File cassandraRackDc = new File("apache-cassandra-" + version + "/conf/cassandra-rackdc.properties"); try (BufferedWriter bw = new BufferedWriter(new FileWriter(cassandraRackDc))) { props.store(bw, "Created by Apache Mesos Cassandra framework"); }/*from www. jav a2 s . c o m*/ }
From source file:com.rxx.common.util.MailUtil.java
/** * html//w ww . java2s. c om * * @param host * @param port * @param userName * @param password * @param title * @param contenthtml * @param imgs * @param toUser * @throws javax.mail.MessagingException */ public static void sendNews(String host, int port, String userName, String password, String title, String content, List<String> imgs, String[] toUser) throws MessagingException, javax.mail.MessagingException { JavaMailSenderImpl senderImpl = new JavaMailSenderImpl(); // mail server senderImpl.setHost(host); // ,html MimeMessage mailMessage = senderImpl.createMimeMessage(); // boolean,MimeMessageHelpertrue // multipart MimeMessageHelper messageHelper = new MimeMessageHelper(mailMessage, true); // messageHelper.setTo(toUser); messageHelper.setFrom(userName); messageHelper.setSubject(title); // true HTML messageHelper.setText(content, true); int i = 0; for (String imagePath : imgs) { FileSystemResource img = new FileSystemResource(new File(imagePath)); messageHelper.addInline(i + "", img); i++; } senderImpl.setUsername(userName); // ,username senderImpl.setPassword(password); // , password Properties prop = new Properties(); prop.put("mail.smtp.auth", "true"); // true, prop.put("mail.smtp.timeout", "25000"); senderImpl.setJavaMailProperties(prop); // senderImpl.send(mailMessage); // senderImpl.send(mailMessage); }
From source file:com.mimp.hibernate.HiberMail.java
public static void generateAndSendEmail(String correo, String pass_plano, String user) { final String username = "formacionadopcion@gmail.com"; final String password = "cairani."; Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", "smtp.gmail.com"); props.put("mail.smtp.port", "587"); Session session = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); }//from w w w . j a v a2s. c o m }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress("formacionadopcion@gmail.com")); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(correo)); message.setSubject("Sistema de adopciones"); message.setText("Estimado solicitante," + "\n\n Su solicitud de recuperacin de contrasea ha sido procesada. Su usuario y contrasea para acceder a la plataforma de adopciones son los siguientes:" + "\n\n Usuario: " + user + "\n\n Contrasea: " + pass_plano + "\n\n Saludos cordiales, "); Transport.send(message); } catch (Exception ex) { } /*catch (MessagingException e) { throw new RuntimeException(e); }*/ }
From source file:eu.scidipes.toolkits.palibrary.utils.XMLUtils.java
private static String nodeToString(final Node doc, final Properties outputProperties) { try {//from w w w . j ava 2s. co m final Transformer transformer = transformerFactory.newTransformer(); outputProperties.put(OutputKeys.METHOD, "xml"); outputProperties.put(OutputKeys.ENCODING, "UTF-8"); transformer.setOutputProperties(outputProperties); final StringWriter writer = new StringWriter(); transformer.transform(new DOMSource(doc), new StreamResult(writer)); return writer.getBuffer().toString(); } catch (final TransformerException e) { LOG.error(e.getMessage(), e); } return ""; }
From source file:com.rxx.common.util.MailUtil.java
/** * html/*from w ww . jav a 2 s . co m*/ * * @param host * @param port * @param userName * @param password * @param title * @param contenthtml * @param toUser * @throws javax.mail.MessagingException */ public static void sendHtml(String host, int port, String userName, String password, String title, String content, String[] toUser) { JavaMailSenderImpl senderImpl = new JavaMailSenderImpl(); // mail server senderImpl.setHost(host); senderImpl.setPort(port); // ,html MimeMessage mailMessage = senderImpl.createMimeMessage(); try { MimeMessageHelper messageHelper = new MimeMessageHelper(mailMessage, true, "UTF-8"); try { // messageHelper.setTo(toUser); messageHelper.setFrom(userName); messageHelper.setSubject(title); // true HTML messageHelper.setText(content, true); } catch (javax.mail.MessagingException e) { // TODO Auto-generated catch block e.printStackTrace(); } senderImpl.setUsername(userName); // ,username senderImpl.setPassword(password); // , password Properties prop = new Properties(); prop.put("mail.smtp.auth", "true"); // true, prop.put("mail.smtp.timeout", "25000"); senderImpl.setJavaMailProperties(prop); // senderImpl.send(mailMessage); } catch (javax.mail.MessagingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
From source file:com.jaeksoft.searchlib.Logging.java
private final static Properties getLoggerProperties(String instanceId) throws SearchLibException { File dirLog = getLogDirectory(); if (!dirLog.exists()) dirLog.mkdir();//from w ww . j av a 2 s .c o m Properties props = new Properties(); if (isDebug) props.put("log4j.rootLogger", "DEBUG, R"); else props.put("log4j.rootLogger", "INFO, R"); props.put("log4j.appender.R", "org.apache.log4j.DailyRollingFileAppender"); String logPath = StringUtils.fastConcat("logs", File.separator, "oss.", instanceId, ".log"); File logFile = new File(StartStopListener.OPENSEARCHSERVER_DATA_FILE, logPath); props.put("log4j.appender.R.File", logFile.getAbsolutePath()); props.put("log4j.appender.R.DatePattern", "'.'yyyy-MM-dd"); props.put("log4j.appender.R.layout", "org.apache.log4j.PatternLayout"); props.put("log4j.appender.R.layout.ConversionPattern", "%d{HH:mm:ss,SSS} %p: %c - %m%n"); props.put("log4j.logger.org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper", "ERROR"); return props; }
From source file:com.mycompany.craftdemo.utility.java
public static void send(long phno, double price, double profit, String domain, String company) { HashMap<String, String> domainMap = new HashMap<>(); domainMap.put("TMobile", "tmomail.net "); domainMap.put("ATT", "txt.att.net"); domainMap.put("Sprint", "messaging.sprintpcs.com"); domainMap.put("Verizon", "vtext.com"); String to = phno + "@" + domainMap.get(domain); //change accordingly // Sender's email ID needs to be mentioned String from = "uni5prince@gmail.com"; //change accordingly final String username = "uni5prince"; //change accordingly final String password = "savageph8893"; //change accordingly // Assuming you are sending email through relay.jangosmtp.net String host = "smtp.gmail.com"; Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", host); props.put("mail.smtp.port", "587"); // Get the Session object. Session session = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); }//from w w w . j av a 2 s . com }); try { // Create a default MimeMessage object. Message message = new MimeMessage(session); // Set From: header field of the header. message.setFrom(new InternetAddress(from)); // Set To: header field of the header. message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to)); // Set Subject: header field message.setSubject("Prices have gone up!!"); // Now set the actual message message.setText("Hello Jane, Stock prices for " + company + " has reached to $" + price + " with profit of $" + profit); // Send message Transport.send(message); System.out.println("Sent message successfully...."); } catch (MessagingException e) { throw new RuntimeException(e); } }