Search in sources :

Example 1 with StringTemplateLoader

use of freemarker.cache.StringTemplateLoader in project bamboobsc by billchen198318.

the class ComponentResourceUtils method generatorResource.

public static String generatorResource(Class<?> c, String type, String metaInfFile, Map<String, Object> params) throws Exception {
    StringTemplateLoader templateLoader = new StringTemplateLoader();
    templateLoader.putTemplate("resourceTemplate", getResourceSrc(c, type, metaInfFile));
    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(params, 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) Template(freemarker.template.Template)

Example 2 with StringTemplateLoader

use of freemarker.cache.StringTemplateLoader in project moco by dreamhead.

the class TemplateResourceReader method createTemplateLoader.

private StringTemplateLoader createTemplateLoader(final MessageContent messageContent) {
    StringTemplateLoader templateLoader = new StringTemplateLoader();
    templateLoader.putTemplate(TEMPLATE_NAME, messageContent.toString());
    return templateLoader;
}
Also used : StringTemplateLoader(freemarker.cache.StringTemplateLoader)

Example 3 with StringTemplateLoader

use of freemarker.cache.StringTemplateLoader in project bamboobsc by billchen198318.

the class TemplateUtils method processTemplate.

private static String processTemplate(String resource, Map<String, Object> params) throws Exception {
    StringTemplateLoader templateLoader = new StringTemplateLoader();
    templateLoader.putTemplate("sysTemplate", resource);
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_21);
    cfg.setTemplateLoader(templateLoader);
    Template template = cfg.getTemplate("sysTemplate", Constants.BASE_ENCODING);
    Writer out = new StringWriter();
    template.process(params, 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 4 with StringTemplateLoader

use of freemarker.cache.StringTemplateLoader 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 5 with StringTemplateLoader

use of freemarker.cache.StringTemplateLoader 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)

Aggregations

StringTemplateLoader (freemarker.cache.StringTemplateLoader)5 Configuration (freemarker.template.Configuration)4 Template (freemarker.template.Template)4 StringWriter (java.io.StringWriter)4 Writer (java.io.Writer)4 TbSysTemplate (com.netsteadfast.greenstep.po.hbm.TbSysTemplate)2 DynamicHql (com.netsteadfast.greenstep.base.model.dynamichql.DynamicHql)1 Query (com.netsteadfast.greenstep.base.model.dynamichql.Query)1 IOException (java.io.IOException)1