本文整理了Java中org.thymeleaf.context.Context
类的一些代码示例,展示了Context
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Context
类的具体详情如下:
包路径:org.thymeleaf.context.Context
类名称:Context
[英]Basic, non-web implementation of IContext, valid for most non-web scenarios.
Note a class with this name existed since 1.0, but it was completely reimplemented in Thymeleaf 3.0
[中]
代码示例来源:origin: cloudfoundry/uaa
private String getResetUnavailableEmailHtml(String email) {
String hostname = UaaUrlUtils.getUaaHost();
final Context ctx = new Context();
ctx.setVariable("serviceName", getServiceName());
ctx.setVariable("email", email);
ctx.setVariable("hostname", hostname);
return templateEngine.process("reset_password_unavailable", ctx);
}
代码示例来源:origin: codecentric/spring-boot-admin
@Override
protected Mono<Void> doNotify(InstanceEvent event, Instance instance) {
return Mono.fromRunnable(() -> {
Context ctx = new Context();
ctx.setVariables(additionalProperties);
ctx.setVariable("baseUrl", this.baseUrl);
ctx.setVariable("event", event);
ctx.setVariable("instance", instance);
ctx.setVariable("lastStatus", getLastStatus(event.getInstance()));
try {
MimeMessage mimeMessage = mailSender.createMimeMessage();
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, StandardCharsets.UTF_8.name());
message.setText(getBody(ctx).replaceAll("\\s+\\n", "\n"), true);
message.setSubject(getSubject(ctx));
message.setTo(this.to);
message.setCc(this.cc);
message.setFrom(this.from);
mailSender.send(mimeMessage);
} catch (MessagingException ex) {
throw new RuntimeException("Error sending mail notification", ex);
}
});
}
代码示例来源:origin: jbake-org/jbake
private void initializeContext(Locale locale, Map<String, Object> model) {
context.clearVariables();
context.setLocale(locale);
context.setVariables(model);
for (String key : extractors.keySet()) {
context.setVariable(key, new ContextVariable(db,key,model));
}
}
代码示例来源:origin: looly/hutool
@Override
public void render(Map<?, ?> bindingMap, Writer writer) {
final Map<String, Object> map = Convert.convert(new TypeReference<Map<String, Object>>() {}, bindingMap);
final Context context = new Context(Locale.getDefault(), map);
this.engine.process(this.template, context, writer);
}
代码示例来源:origin: org.restlet.jse/org.restlet.ext.thymeleaf
/**
* Sets the template's data model.
*
* @param dataModel
* The template's data model.
*/
public void setDataModel(Map<String, Object> dataModel) {
Context ctx = new Context(locale);
ctx.setVariables(dataModel);
setContext(ctx);
}
代码示例来源:origin: fr.sii.ogham/ogham-template-thymeleaf
@Override
public org.thymeleaf.context.Context convert(Context context) throws ContextException {
org.thymeleaf.context.Context thymeleafContext = new org.thymeleaf.context.Context();
thymeleafContext.setVariables(context.getVariables());
if (context instanceof LocaleContext) {
thymeleafContext.setLocale(((LocaleContext) context).getLocale());
}
return thymeleafContext;
}
}
代码示例来源:origin: stackoverflow.com
public boolean sendMail(Map<String, String> info, String template) throws MessagingException, IOException{
final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
final MimeMessageHelper message = new
MimeMessageHelper(mimeMessage,true, "UTF-8"); // true = multipart
message.setFrom("sender@example.com");
message.setTo("mymail@example.com");
message.setSubject("This is the message subject");
Context ctx = new Context(LocaleContextHolder.getLocale());
ctx.setVariable("info", info);
try{
String messageContent= engine.process(template, ctx);
mimeMessage.setContent(tt, "text/html; charset=utf-8");
}catch(Exception e){
e.printStackTrace();
}
this.mailSender.send(mimeMessage);
return true;
}
代码示例来源:origin: looly/hutool
@Override
public void render(Map<?, ?> bindingMap, Writer writer) {
final Map<String, Object> map = Convert.convert(new TypeReference<Map<String, Object>>() {}, bindingMap);
final Context context = new Context(Locale.getDefault(), map);
this.engine.process(this.template, context, writer);
}
代码示例来源:origin: purplejs/purplejs
private String doRender( final ResourcePath view, final Map<String, Object> model )
{
final Context context = new Context();
context.setVariables( model );
return this.engine.process( view.toString(), context );
}
代码示例来源:origin: cloudfoundry/uaa
private String getCodeSentEmailHtml(String code) {
String resetUrl = UaaUrlUtils.getUaaUrl("/reset_password");
final Context ctx = new Context();
ctx.setVariable("serviceName", getServiceName());
ctx.setVariable("code", code);
ctx.setVariable("resetUrl", resetUrl);
return templateEngine.process("reset_password", ctx);
}
代码示例来源:origin: Exrick/xpay
/**
* 发送模版邮件
* @param sender
* @param sendto
* @param templateName
* @param o
*/
@Async
public void sendTemplateMail(String sender, String sendto,String title, String templateName,Object o) {
log.info("开始给"+sendto+"发送邮件");
MimeMessage message = mailSender.createMimeMessage();
try {
//true表示需要创建一个multipart message html内容
MimeMessageHelper helper = new MimeMessageHelper(message, true);
helper.setFrom(sender);
helper.setTo(sendto);
helper.setSubject(title);
Context context = new Context();
context.setVariable("title",title);
context.setVariables(StringUtils.beanToMap(o));
//获取模板html代码
String content = templateEngine.process(templateName, context);
helper.setText(content, true);
mailSender.send(message);
log.info("给"+sendto+"发送邮件成功");
}catch (Exception e){
e.printStackTrace();
}
}
代码示例来源:origin: jooby-project/jooby
@SuppressWarnings({"rawtypes", "unchecked" })
@Override
public void render(final View view, final Context ctx) throws FileNotFoundException, Exception {
String vname = view.name();
Map<String, Object> vars = ctx.locals();
vars.putIfAbsent("_vname", vname);
// Locale:
Locale locale = (Locale) vars.getOrDefault("locale", ctx.locale());
Map model = view.model();
vars.forEach(model::putIfAbsent);
model.putIfAbsent("xss", new Thlxss(env));
IContext thlctx = new org.thymeleaf.context.Context(locale, model);
String output = this.engine.process(vname, thlctx);
ctx.type(MediaType.html)
.send(output);
}
代码示例来源:origin: airbnb/reair
@Override
@SuppressWarnings("unchecked")
public String render(ModelAndView modelAndView) {
Object model = modelAndView.getModel();
if (model instanceof Map) {
Map<String, ?> modelMap = (Map<String, ?>) model;
Context context = new Context();
context.setVariables(modelMap);
return templateEngine.process(modelAndView.getViewName(), context);
} else {
throw new IllegalArgumentException("modelAndView.getModel() must return a java.util.Map");
}
}
代码示例来源:origin: org.jbake/jbake-core
private void initializeContext(Locale locale, Map<String, Object> model) {
context.clearVariables();
context.setLocale(locale);
context.setVariables(model);
for (String key : extractors.keySet()) {
context.setVariable(key, new ContextVariable(db,key,model));
}
}
代码示例来源:origin: cloudfoundry/uaa
private String getEmailHtml(String code, String email) {
String accountsUrl = ScimUtils.getVerificationURL(null).toString();
final Context ctx = new Context();
String companyName = IdentityZoneHolder.resolveBranding().getCompanyName();
if (IdentityZoneHolder.isUaa()) {
ctx.setVariable("serviceName", StringUtils.hasText(companyName) ? companyName : "Cloud Foundry");
} else {
ctx.setVariable("serviceName", IdentityZoneHolder.get().getName());
}
ctx.setVariable("servicePhrase", StringUtils.hasText(companyName) && IdentityZoneHolder.isUaa() ? companyName + " account" : "an account");
ctx.setVariable("code", code);
ctx.setVariable("email", email);
ctx.setVariable("accountsUrl", accountsUrl);
return templateEngine.process("activate", ctx);
}
}
代码示例来源:origin: com.cosmicpush/push-server-engine
/**
* Writes the thymeleaf to the specified writer.
* @param thymeleaf the thymeleaf instanace to be rendered
* @param outputStream the output stream that the thymeleaf will be rendered to
* @throws java.io.IOException if we are having a bad day
*/
public void writeTo(Thymeleaf thymeleaf, OutputStream outputStream) throws IOException {
String view = thymeleaf.getView();
org.thymeleaf.context.Context context = new org.thymeleaf.context.Context();
context.setVariables(thymeleaf.getVariables());
String baseUri = StringUtils.substring(getBaseUri(), 0, -1);
context.setVariable("contextRoot", baseUri);
StringWriter writer = new StringWriter();
engine.process(view, context, writer);
String content = writer.toString();
outputStream.write(content.getBytes());
}
}
代码示例来源:origin: jbake-org/jbake
public ThymeleafTemplateEngine(final JBakeConfiguration config, final ContentStore db) {
super(config, db);
this.context = new Context();
initializeTemplateEngine();
}
代码示例来源:origin: airbnb/reair
@Override
@SuppressWarnings("unchecked")
public String render(ModelAndView modelAndView) {
Object model = modelAndView.getModel();
if (model instanceof Map) {
Map<String, ?> modelMap = (Map<String, ?>) model;
Context context = new Context();
context.setVariables(modelMap);
return templateEngine.process(modelAndView.getViewName(), context);
} else {
throw new IllegalArgumentException("modelAndView.getModel() must return a java.util.Map");
}
}
代码示例来源:origin: cloudfoundry/uaa
private String getEmailChangeEmailHtml(String email, String newEmail, String code) {
String verifyUrl = UaaUrlUtils.getUaaUrl("/verify_email");
final Context ctx = new Context();
if (IdentityZoneHolder.get().equals(IdentityZone.getUaa())) {
String companyName = IdentityZoneHolder.resolveBranding().getCompanyName();
ctx.setVariable("serviceName", StringUtils.hasText(companyName) ? companyName : "Cloud Foundry");
ctx.setVariable("servicePhrase", StringUtils.hasText(companyName) ? "a " + companyName + " account" : "an account");
}
else {
ctx.setVariable("serviceName", IdentityZoneHolder.get().getName());
ctx.setVariable("servicePhrase", IdentityZoneHolder.get().getName());
}
ctx.setVariable("code", code);
ctx.setVariable("newEmail", newEmail);
ctx.setVariable("email", email);
ctx.setVariable("verifyUrl", verifyUrl);
return templateEngine.process("verify_email", ctx);
}
代码示例来源:origin: org.tiogasolutions.jobs/tioga-jobs-agent
/**
* Writes the thymeleaf to the specified writer.
* @param thymeleaf the thymeleaf instanace to be rendered
* @param outputStream the output stream that the thymeleaf will be rendered to
* @throws IOException if we are having a bad day
*/
public void writeTo(Thymeleaf thymeleaf, OutputStream outputStream) throws IOException {
String view = thymeleaf.getView();
org.thymeleaf.context.Context context = new org.thymeleaf.context.Context();
context.setVariables(thymeleaf.getVariables());
String baseUri = StringUtils.substring(getBaseUri(), 0, -1);
context.setVariable("contextRoot", baseUri);
StringWriter writer = new StringWriter();
engine.process(view, context, writer);
String content = writer.toString();
outputStream.write(content.getBytes());
}
}
内容来源于网络,如有侵权,请联系作者删除!