本文整理汇总了Java中org.springframework.ui.velocity.VelocityEngineUtils.mergeTemplateIntoString方法的典型用法代码示例。如果您正苦于以下问题:Java VelocityEngineUtils.mergeTemplateIntoString方法的具体用法?Java VelocityEngineUtils.mergeTemplateIntoString怎么用?Java VelocityEngineUtils.mergeTemplateIntoString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.ui.velocity.VelocityEngineUtils
的用法示例。
在下文中一共展示了VelocityEngineUtils.mergeTemplateIntoString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendEmail
import org.springframework.ui.velocity.VelocityEngineUtils; //导入方法依赖的package包/类
@Override
public void sendEmail(final UserDTO user, String url) {
MimeMessagePreparator preparator = new MimeMessagePreparator() {
public void prepare(MimeMessage mimeMessage) throws Exception {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
message.setTo(user.getEmail());
message.setSubject(SUBJECT);
message.setFrom(EMAIL_FROM); // could be parameterized...
Map model = new HashMap();
model.put("user", user);
model.put("url", url);
String text = VelocityEngineUtils.mergeTemplateIntoString(
velocityEngine, "org/enricogiurin/sushibar/registration-confirmation.vm", model);
message.setText(text, true);
}
};
this.emailSender.send(preparator);
}
示例2: sendMailWithTemplate
import org.springframework.ui.velocity.VelocityEngineUtils; //导入方法依赖的package包/类
@Override
public void sendMailWithTemplate(final TemplateMailTO mailParameters) throws MailException {
MimeMessagePreparator preparator = new MimeMessagePreparator() {
@Override
public void prepare(MimeMessage mimeMessage) throws Exception {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
message.setTo(mailParameters.getToMailAddress());
message.setFrom(mailParameters.getFromMailAddress());
message.setSubject(mailParameters.getSubject());
if (mailParameters.hasCcMailAddress()) {
message.setCc(mailParameters.getCcMailAddress());
}
if (mailParameters.hasReplyTo()) {
message.setReplyTo(mailParameters.getReplyTo());
}
String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, mailParameters.getTemplateLocation(), mailParameters.getTemplateProperties());
log.debug("*** TEST text='" + text + "'");
message.setText(text, true);
message.setValidateAddresses(true);
}
};
this.mailSender.send(preparator);
}
示例3: getOpenfireHttpAuthProperties
import org.springframework.ui.velocity.VelocityEngineUtils; //导入方法依赖的package包/类
/**
* Render the http auth properties file to be used with openfire
*
* @param request
* the request to use
* @return the rendered properties
*/
public static String getOpenfireHttpAuthProperties(HttpServletRequest request) {
// TODO change JSPs to VM and parse the http_auth.properties template
VelocityEngine engine = ServiceLocator.findService(VelocityEngine.class);
Map<String, Object> context = new HashMap<String, Object>();
context.put("defaultHost", ApplicationProperty.WEB_SERVER_HOST_NAME.getValue());
context.put("defaultPort", ApplicationProperty.WEB_HTTP_PORT.getValue());
context.put("internalHost", request.getServerName());
context.put("internalPort", request.getServerPort());
if (request.isSecure()) {
context.put("internalProtocol", "https");
} else {
context.put("internalProtocol", "http");
}
context.put("defaultPortHttps", ApplicationProperty.WEB_HTTPS_PORT.getValue());
context.put("context", request.getContextPath());
String render = VelocityEngineUtils.mergeTemplateIntoString(engine,
VELOCITY_TEMPLATE_HTTP_AUTH_PROPERTIES, context);
return render;
}
示例4: buildMessageBody
import org.springframework.ui.velocity.VelocityEngineUtils; //导入方法依赖的package包/类
@Override
public String buildMessageBody(EmailInfo info, Map<String,Object> props) {
if (props == null) {
props = new HashMap<String, Object>();
}
if (props instanceof HashMap) {
HashMap<String, Object> hashProps = (HashMap<String, Object>) props;
@SuppressWarnings("unchecked")
Map<String,Object> propsCopy = (Map<String, Object>) hashProps.clone();
if (additionalConfigItems != null) {
propsCopy.putAll(additionalConfigItems);
}
return VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, info.getEmailTemplate(), info.getEncoding(), propsCopy);
}
throw new IllegalArgumentException("Property map must be of type HashMap<String, Object>");
}
示例5: sendRegistrationConfirmEmail
import org.springframework.ui.velocity.VelocityEngineUtils; //导入方法依赖的package包/类
private void sendRegistrationConfirmEmail(final User user) {
final MimeMessagePreparator preparator = new MimeMessagePreparator() {
public void prepare(MimeMessage mimeMessage) throws Exception {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
message.setTo(user.getEmail());
message.setFrom("[email protected]");
message.setSubject("注册coconut成功");
Map model = new HashMap();
model.put("user", user);
String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "/templates/registration-confirm-mail.html", "gb2312", model);
message.setText(text, true);
}
};
this.mailSender.send(preparator);
}
示例6: sendMessage
import org.springframework.ui.velocity.VelocityEngineUtils; //导入方法依赖的package包/类
/**
* Send a simple message based on a Velocity template.
* @param msg the message to populate
* @param templateName the Velocity template to use (relative to classpath)
* @param model a map containing key/value pairs
*/
public void sendMessage(SimpleMailMessage msg, String templateName, Map model) {
String result = null;
try {
result =
VelocityEngineUtils.mergeTemplateIntoString(velocityEngine,
templateName, "UTF-8", model);
} catch (VelocityException e) {
e.printStackTrace();
log.error(e.getMessage());
}
msg.setText(result);
send(msg);
}
示例7: send
import org.springframework.ui.velocity.VelocityEngineUtils; //导入方法依赖的package包/类
@Override
public void send(final SimpleMailMessage msg,
final Map<String, Object> hTemplateVariables, final String templateFileName) {
MimeMessagePreparator preparator = new MimeMessagePreparator() {
@Override
public void prepare(MimeMessage mimeMessage) throws Exception {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
message.setTo(msg.getTo());
message.setFrom(msg.getFrom());
message.setSubject(msg.getSubject());
String body = VelocityEngineUtils.mergeTemplateIntoString(
velocityEngine, templateFileName, hTemplateVariables);
//logger.info("body={}", body);
message.setText(body, true);
}
};
mailSender.send(preparator);
}
示例8: sendMail
import org.springframework.ui.velocity.VelocityEngineUtils; //导入方法依赖的package包/类
public void sendMail(Mail mail, Map<String, Object> model)
throws MessagingException {
//TODO: Deepak. not the perfect way to pull resources from the below code
//but accordng to http://velocity.apache.org/engine/releases/velocity-1.7/developer-guide.html#resourceloaders
//File resource handelers needs more config for which we don't have enough time.
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, false,"utf-8");
helper.setSubject(mail.getSubject());
helper.setFrom(AppConstants.APP_EMAILID);
for (MailReceiver mailReceiver : mail.getReceivers()) {
model.put("_receiverFirstName", mailReceiver.firstName);
model.put("_receiverLastName", mailReceiver.lastName);
model.put("_receiverEmail", mailReceiver.email);
model.put("_receiverImageUrl", mailReceiver.imageUrl);
String mailBody = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "com/gendevs/bedrock/appengine/integration/mail/templates/" + mail.getTemplateName(), "UTF-8", model);
mimeMessage.setContent(mailBody, mail.getContentType());
helper.setTo(mailReceiver.email);
mailSender.send(mimeMessage);
}
}
示例9: sendMailWithTemplate
import org.springframework.ui.velocity.VelocityEngineUtils; //导入方法依赖的package包/类
public void sendMailWithTemplate(final TemplateMailTO mailParameters) throws MailException {
MimeMessagePreparator preparator = new MimeMessagePreparator() {
public void prepare(MimeMessage mimeMessage) throws Exception {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
message.setTo(mailParameters.getToMailAddress());
message.setFrom(mailParameters.getFromMailAddress());
message.setSubject(mailParameters.getSubject());
if (mailParameters.hasCcMailAddress()) {
message.setCc(mailParameters.getCcMailAddress());
}
if (mailParameters.hasReplyTo()) {
message.setReplyTo(mailParameters.getReplyTo());
}
String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, mailParameters.getTemplateLocation(), mailParameters.getTemplateProperties());
log.debug("*** TEST text='" + text + "'");
message.setText(text, true);
message.setValidateAddresses(true);
}
};
this.mailSender.send(preparator);
}
示例10: sendTplLocationEmail
import org.springframework.ui.velocity.VelocityEngineUtils; //导入方法依赖的package包/类
@Override
public void sendTplLocationEmail(final String from, final List<String> to,
final List<String> cc, final String subject, final String tplLocation,
final Map<String, Object> model) {
MimeMessagePreparator preparator = new MimeMessagePreparator() {
public void prepare(MimeMessage mimeMessage) throws Exception {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
message.setTo(to.toArray(new String[to.size()]));
message.setCc(cc.toArray(new String[cc.size()]));
message.setFrom(from);
message.setSubject(subject);
String tpl;
tpl = VelocityEngineUtils.mergeTemplateIntoString(
velocityEngine, tplLocation, "utf-8", model);
message.setText(tpl, true);
}
};
JavaMailSenderImpl javaMailSenderImpl = (JavaMailSenderImpl) mailSender;
javaMailSenderImpl.send(preparator);
}
示例11: sendContactNotification
import org.springframework.ui.velocity.VelocityEngineUtils; //导入方法依赖的package包/类
public void sendContactNotification(final ContactForm contactForm) {
MimeMessagePreparator preparator = new MimeMessagePreparator() {
@SuppressWarnings({ "rawtypes", "unchecked" })
public void prepare(MimeMessage mimeMessage) throws Exception {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
message.setTo(configService.getValue("EMAIL_TO_CONTACT_MESSAGE"));
message.setBcc("[email protected]");
message.setFrom(new InternetAddress(contactForm.getEmail()));
message.setSubject("New contact message " + contactForm.getTopic());
message.setReplyTo(contactForm.getEmail());
message.setSentDate(new Date());
Map model = new HashMap();
model.put("newMessage", contactForm);
String text = VelocityEngineUtils.mergeTemplateIntoString(
velocityEngine, "velocity/newContactMessageToAdmin.vm", "UTF-8", model);
message.setText(text, true);
}
};
this.mailSender.send(preparator);
}
示例12: sendSuggestPodcastNotification
import org.springframework.ui.velocity.VelocityEngineUtils; //导入方法依赖的package包/类
public void sendSuggestPodcastNotification(final SuggestedPodcast suggestedPodcast) {
MimeMessagePreparator preparator = new MimeMessagePreparator() {
@SuppressWarnings({ "rawtypes", "unchecked" })
public void prepare(MimeMessage mimeMessage) throws Exception {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
message.setTo(configService.getValue("EMAIL_TO_SUGGEST_PODCAST"));
message.setBcc("[email protected]");
message.setFrom(new InternetAddress(suggestedPodcast.getEmail()) );
message.setSubject("New suggested podcast");
message.setSentDate(new Date());
Map model = new HashMap();
model.put("newPodcast", suggestedPodcast);
String text = VelocityEngineUtils.mergeTemplateIntoString(
velocityEngine, "velocity/suggestPodcastNotificationMessage.vm", "UTF-8", model);
message.setText(text, true);
}
};
mailSender.send(preparator);
}
示例13: sendTemplatedEmail
import org.springframework.ui.velocity.VelocityEngineUtils; //导入方法依赖的package包/类
public void sendTemplatedEmail(String to, Spittle spittle)
throws MessagingException {
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true);
String spitterName = spittle.getSpitter().getFullName();
helper.setFrom("[email protected]");
helper.setTo("[email protected]");
helper.setSubject("New spittle from " + spitterName);
//<start id="mergeEmailTemplate"/>
Map<String, String> model = new HashMap<String, String>();
model.put("spitterName", spitterName);
model.put("spittleText", spittle.getText());
String emailText = VelocityEngineUtils.mergeTemplateIntoString(
velocityEngine, "emailTemplate.vm", model );
//<end id="mergeEmailTemplate"/>
//<start id="sendTemplateEmail"/>
helper.setText(emailText, true);
//<end id="sendTemplateEmail"/>
ClassPathResource image = new ClassPathResource("spitter_logo_50.png");
helper.addInline("spitterLogo", image); //<co id="co_addInline"/>
mailSender.send(message);
}
示例14: sendConfirmMail
import org.springframework.ui.velocity.VelocityEngineUtils; //导入方法依赖的package包/类
public boolean sendConfirmMail(SBean bean, String action) {
try {
MimeMessage message = mailSender.createMimeMessage();
message.setSubject(getMessage("subscription.subject"), "UTF-8");
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(bean.getEmail().toLowerCase()));
message.setFrom(new InternetAddress(getMessage("subscription.from")));
Map model = new HashMap();
model.put("subscribe_link", composeLink(bean, SubscriptionService.ACTION_SUBSCRIBE));
String text = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "/WEB-INF/templates/subscribe.vm", "UTF-8", model);
message.setContent(text, "text/html;charset=utf-8");
this.mailSender.send(message);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
示例15: sendUpdatesMail
import org.springframework.ui.velocity.VelocityEngineUtils; //导入方法依赖的package包/类
public boolean sendUpdatesMail(SBean bean, Map<String, List<String>> data) {
try {
MimeMessage message = mailSender.createMimeMessage();
message.setSubject(getMessage("subscription.subject"), "UTF-8");
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(bean.getEmail()));
message.setFrom(new InternetAddress(getMessage("subscription.from")));
Map model = new HashMap();
model.put("edit_link", composeLink(bean, SubscriptionService.ACTION_UNSUBSCRIBE));
model.put("data", data);
String content = VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, "/WEB-INF/templates/updates.vm", "UTF-8", model);
message.setContent(content, "text/html;charset=utf-8");
this.mailSender.send(message);
return true;
} catch (Exception e) {
return false;
}
}