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 engine by craftercms.
the class RenderComponentDirective method execute.
@SuppressWarnings("unchecked")
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException {
TemplateModel componentParam = (TemplateModel) params.get(COMPONENT_PARAM_NAME);
TemplateModel componentPathParam = (TemplateModel) params.get(COMPONENT_PATH_PARAM_NAME);
TemplateModel additionalModelParam = (TemplateModel) params.get(ADDITIONAL_MODEL_PARAM_NAME);
Map<String, Object> additionalModel = null;
SiteItem component;
if (componentParam == null && componentPathParam == null) {
throw new TemplateException("No '" + COMPONENT_PARAM_NAME + "' or '" + COMPONENT_PATH_PARAM_NAME + "' param specified", env);
} else if (componentParam != null) {
component = getComponentFromNode(componentParam, env);
} else {
component = getComponentFromPath(componentPathParam, env);
}
if (additionalModelParam != null) {
additionalModel = unwrap(ADDITIONAL_MODEL_PARAM_NAME, additionalModelParam, Map.class, env);
}
Map<String, Object> templateModel = executeScripts(component, additionalModel, env);
SimpleHash model = getFullModel(component, templateModel, additionalModel);
Template template = getTemplate(component, env);
Writer output = env.getOut();
processComponentTemplate(template, model, output, env);
}
Aggregations