Search in sources :

Example 76 with Template

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();
}
Also used : StringTemplateLoader(freemarker.cache.StringTemplateLoader) Configuration(freemarker.template.Configuration) StringWriter(java.io.StringWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer) TbSysTemplate(com.netsteadfast.greenstep.po.hbm.TbSysTemplate) Template(freemarker.template.Template)

Example 77 with Template

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;
}
Also used : StringTemplateLoader(freemarker.cache.StringTemplateLoader) Query(com.netsteadfast.greenstep.base.model.dynamichql.Query) Configuration(freemarker.template.Configuration) StringWriter(java.io.StringWriter) DynamicHql(com.netsteadfast.greenstep.base.model.dynamichql.DynamicHql) IOException(java.io.IOException) StringWriter(java.io.StringWriter) Writer(java.io.Writer) Template(freemarker.template.Template)

Example 78 with Template

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);
}
Also used : Writer(java.io.Writer) Template(freemarker.template.Template)

Example 79 with Template

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);
}
Also used : MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper) Autowired(org.springframework.beans.factory.annotation.Autowired) JavaMailSender(org.springframework.mail.javamail.JavaMailSender) HashMap(java.util.HashMap) IOUtilities(com.khartec.waltz.common.IOUtilities) InputStreamReader(java.io.InputStreamReader) Checks(com.khartec.waltz.common.Checks) Value(org.springframework.beans.factory.annotation.Value) MimeMessagePreparator(org.springframework.mail.javamail.MimeMessagePreparator) Configuration(freemarker.template.Configuration) Service(org.springframework.stereotype.Service) Map(java.util.Map) FreeMarkerTemplateUtils(org.springframework.ui.freemarker.FreeMarkerTemplateUtils) Template(freemarker.template.Template) StringUtilities(com.khartec.waltz.common.StringUtilities) MimeMessagePreparator(org.springframework.mail.javamail.MimeMessagePreparator) Configuration(freemarker.template.Configuration) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) StringUtilities(com.khartec.waltz.common.StringUtilities) MimeMessageHelper(org.springframework.mail.javamail.MimeMessageHelper) HashMap(java.util.HashMap) Map(java.util.Map) Template(freemarker.template.Template)

Example 80 with Template

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);
}
Also used : Template(freemarker.template.Template)

Aggregations

Template (freemarker.template.Template)81 StringWriter (java.io.StringWriter)35 IOException (java.io.IOException)34 Configuration (freemarker.template.Configuration)33 HashMap (java.util.HashMap)28 Writer (java.io.Writer)27 TemplateException (freemarker.template.TemplateException)24 OutputStreamWriter (java.io.OutputStreamWriter)13 File (java.io.File)9 Map (java.util.Map)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 SimpleHash (freemarker.template.SimpleHash)6 JSONObject (org.json.JSONObject)6 DefaultObjectWrapper (freemarker.template.DefaultObjectWrapper)5 ThirdEyeAnomalyConfiguration (com.linkedin.thirdeye.anomaly.ThirdEyeAnomalyConfiguration)4 StringTemplateLoader (freemarker.cache.StringTemplateLoader)4 Environment (freemarker.core.Environment)4 BufferedWriter (java.io.BufferedWriter)4 FileOutputStream (java.io.FileOutputStream)4 StringReader (java.io.StringReader)4