use of org.thymeleaf.context.Context in project be5 by DevelopmentOnTheEdge.
the class TemplateProcessor method generate.
@Override
public void generate(Request req, Response res, Injector injector) {
UserAwareMeta userAwareMeta = injector.get(UserAwareMeta.class);
String title = userAwareMeta.getColumnTitle("index", "page", "title");
String description = userAwareMeta.getColumnTitle("index", "page", "description");
Context context = new Context();
context.setVariable("lang", UserInfoHolder.getLanguage());
context.setVariable("title", title);
context.setVariable("description", description);
String reqWithoutContext = req.getRequestUri().replaceFirst(req.getContextPath(), "");
if (!reqWithoutContext.endsWith("/"))
reqWithoutContext += "/";
context.setVariable("baseUrl", req.getContextPath() + reqWithoutContext);
context.setVariable("baseUrlWithoutContext", reqWithoutContext);
res.sendHtml(templateEngine.process(reqWithoutContext + "index", context));
}
use of org.thymeleaf.context.Context in project cetc by DiscoverForever.
the class MailService method sendEmailFromTemplate.
@Async
public void sendEmailFromTemplate(User user, String templateName, String titleKey) {
Locale locale = Locale.forLanguageTag(user.getLangKey());
Context context = new Context(locale);
context.setVariable(USER, user);
context.setVariable(BASE_URL, jHipsterProperties.getMail().getBaseUrl());
String content = templateEngine.process(templateName, context);
String subject = messageSource.getMessage(titleKey, null, locale);
sendEmail(user.getEmail(), subject, content, false, true);
}
use of org.thymeleaf.context.Context in project irida by phac-nml.
the class EmailControllerImpl method sendSubscriptionUpdateEmail.
/**
* {@inheritDoc}
*/
@Override
public void sendSubscriptionUpdateEmail(User user, List<ProjectEvent> events) {
logger.debug("Sending subscription email to " + user.getEmail());
final Context ctx = new Context();
ctx.setVariable("ngsEmail", serverEmail);
ctx.setVariable("serverURL", serverURL);
ctx.setVariable("user", user);
Locale locale = Locale.forLanguageTag(user.getLocale());
ctx.setVariable("dateFormat", messageSource.getMessage("locale.date.long", null, locale));
List<Map<String, Object>> eventsList = buildEventsListFromCollection(events);
ctx.setVariable("events", eventsList);
final String htmlContent = templateEngine.process(SUBSCRIPTION_TEMPLATE, ctx);
try {
final MimeMessage mimeMessage = this.javaMailSender.createMimeMessage();
final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");
message.setSubject(messageSource.getMessage("email.subscription.title", null, locale));
message.setFrom(serverEmail);
message.setTo(user.getEmail());
message.setText(htmlContent, true);
javaMailSender.send(mimeMessage);
} catch (Exception e) {
logger.error("Error trying to send subcription email.", e);
throw new MailSendException("Failed to send e-mail for project event subscription.", e);
}
}
use of org.thymeleaf.context.Context in project irida by phac-nml.
the class EmailControllerImpl method sendPasswordResetLinkEmail.
/**
* {@inheritDoc}
*/
@Override
public void sendPasswordResetLinkEmail(User user, PasswordReset passwordReset) throws MailSendException {
logger.debug("Sending password reset email to " + user.getEmail());
final Context ctx = new Context();
ctx.setVariable("ngsEmail", serverEmail);
ctx.setVariable("serverURL", serverURL);
Locale locale = LocaleContextHolder.getLocale();
// add the reset information
ctx.setVariable("passwordReset", passwordReset);
ctx.setVariable("user", user);
try {
final MimeMessage mimeMessage = this.javaMailSender.createMimeMessage();
final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");
message.setSubject(messageSource.getMessage("email.reset.subject", null, locale));
message.setFrom(serverEmail);
message.setTo(user.getEmail());
final String htmlContent = templateEngine.process(RESET_TEMPLATE, ctx);
message.setText(htmlContent, true);
javaMailSender.send(mimeMessage);
} catch (Exception e) {
logger.error("Error trying to send a password reset link email.", e);
throw new MailSendException("Failed to send e-mail when doing password reset.", e);
}
}
use of org.thymeleaf.context.Context in project dubion by valsamiq.
the class MailService method sendEmailFromTemplate.
@Async
public void sendEmailFromTemplate(User user, String templateName, String titleKey) {
Locale locale = Locale.forLanguageTag(user.getLangKey());
Context context = new Context(locale);
context.setVariable(USER, user);
context.setVariable(BASE_URL, jHipsterProperties.getMail().getBaseUrl());
String content = templateEngine.process(templateName, context);
String subject = messageSource.getMessage(titleKey, null, locale);
sendEmail(user.getEmail(), subject, content, false, true);
}
Aggregations