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();
}
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;
}
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();
}
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();
}
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;
}
Aggregations