use of freemarker.template.Template in project bamboobsc by billchen198318.
the class TemplateUtils method processTemplate.
/**
* 單獨提供單處理 template 取出結果
*
* @param name
* @param classLoader
* @param templateResource
* @param parameter
* @return
* @throws Exception
*/
public static String processTemplate(String name, ClassLoader classLoader, String templateResource, Map<String, Object> parameter) throws Exception {
StringTemplateLoader templateLoader = new StringTemplateLoader();
templateLoader.putTemplate("resourceTemplate", getResourceSrc(classLoader, templateResource));
Configuration cfg = new Configuration(Configuration.VERSION_2_3_21);
cfg.setTemplateLoader(templateLoader);
Template template = cfg.getTemplate("resourceTemplate", Constants.BASE_ENCODING);
Writer out = new StringWriter();
template.process(parameter, out);
return out.toString();
}
use of freemarker.template.Template in project bamboobsc by billchen198318.
the class DynamicHqlUtils method process.
public static String process(String resource, String queryName, Map<String, Object> paramMap) throws Exception {
DynamicHql dynamicHql = loadResource(resource);
if (null == dynamicHql) {
logger.error("no dynamic hql resource.");
throw new Exception("no dynamic hql resource.");
}
String hql = "";
for (int i = 0; i < dynamicHql.getQuery().size() && hql.length() < 1; i++) {
Query queryObj = dynamicHql.getQuery().get(i);
if (!queryObj.getName().equals(queryName)) {
continue;
}
StringTemplateLoader templateLoader = new StringTemplateLoader();
templateLoader.putTemplate(TEMPLATE_ID, queryObj.getContent());
Configuration cfg = new Configuration(Configuration.VERSION_2_3_21);
cfg.setTemplateLoader(templateLoader);
Template template = cfg.getTemplate(TEMPLATE_ID, Constants.BASE_ENCODING);
Writer out = new StringWriter();
template.process(paramMap, out);
hql = out.toString();
}
if (StringUtils.isBlank(hql)) {
logger.warn("hql is blank.");
}
return hql;
}
use of freemarker.template.Template in project leopard by tanhaichao.
the class FtlView method render.
@Override
public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception {
Template template = this.getTemplate(viewName + ".ftl");
response.setContentType(getContentType());
Writer out = response.getWriter();
template.process(model, out);
}
use of freemarker.template.Template in project waltz by khartec.
the class WaltzEmailer method sendEmail.
public void sendEmail(String subject, String body, String[] to) {
Checks.checkNotEmpty(subject, "subject cannot be empty");
Checks.checkNotEmpty(body, "body cannot be empty");
Checks.checkNotEmpty(to, "to cannot be empty");
Checks.checkAll(to, StringUtilities::notEmpty, "email address cannot be empty");
MimeMessagePreparator preparator = mimeMessage -> {
MimeMessageHelper message = new MimeMessageHelper(mimeMessage, true);
message.setSubject(subject);
message.setFrom(fromEmail);
message.setBcc(to);
message.addAttachment("waltz.png", IOUtilities.getFileResource("/images/waltz.png"));
message.addAttachment("client-logo", IOUtilities.getFileResource("/templates/images/client-logo.png"));
Map model = new HashMap();
model.put("body", body);
Configuration cfg = new Configuration(Configuration.VERSION_2_3_23);
try (InputStreamReader templateReader = new InputStreamReader(IOUtilities.getFileResource(DEFAULT_EMAIL_TEMPLATE_LOCATION).getInputStream())) {
Template template = new Template("template", templateReader, cfg);
String text = FreeMarkerTemplateUtils.processTemplateIntoString(template, model);
message.setText(text, true);
}
};
this.mailSender.send(preparator);
}
use of freemarker.template.Template in project paascloud-master by paascloud.
the class UacFreeMarkerServiceImpl method getTemplate.
@Override
public String getTemplate(Map<String, Object> map, String templateLocation) throws IOException, TemplateException {
Preconditions.checkArgument(StringUtils.isNotEmpty(templateLocation), "模板不能为空");
Template t = configuration.getTemplate(templateLocation, "UTF-8");
return FreeMarkerTemplateUtils.processTemplateIntoString(t, map);
// return VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, templateLocation, "UTF-8", map);
}
Aggregations