@Override @SuppressWarnings({"unchecked", "rawtypes"}) public void execute( Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { Site site = FrontUtils.getSite(env); List<Content> list = getList(params, env); Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>(params); paramWrap.put(OUT_LIST, DEFAULT_WRAPPER.wrap(list)); Map<String, TemplateModel> origMap = DirectiveUtils.addParamsToVariable(env, paramWrap); InvokeType type = DirectiveUtils.getInvokeType(params); String listStyle = DirectiveUtils.getString(PARAM_STYLE_LIST, params); if (InvokeType.sysDefined == type) { if (StringUtils.isBlank(listStyle)) { throw new ParamsRequiredException(PARAM_STYLE_LIST); } env.include(TPL_STYLE_LIST + listStyle + TPL_SUFFIX, UTF8, true); } else if (InvokeType.userDefined == type) { if (StringUtils.isBlank(listStyle)) { throw new ParamsRequiredException(PARAM_STYLE_LIST); } FrontUtils.includeTpl(TPL_STYLE_LIST, site, env); } else if (InvokeType.custom == type) { FrontUtils.includeTpl(TPL_NAME, site, params, env); } else if (InvokeType.body == type) { body.render(env.getOut()); } else { throw new RuntimeException("invoke type not handled: " + type); } DirectiveUtils.removeParamsFromVariable(env, paramWrap, origMap); }
public Writer getWriter(final Writer out, Map args) throws TemplateModelException, IOException { try { Environment env = Environment.getCurrentEnvironment(); boolean lastFIRE = env.setFastInvalidReferenceExceptions(false); try { env.include(template); } finally { env.setFastInvalidReferenceExceptions(lastFIRE); } } catch (Exception e) { throw new _TemplateModelException( e, "Template created with \"?", key, "\" has stopped with this error:\n\n", MessageUtil.EMBEDDED_MESSAGE_BEGIN, new _DelayedGetMessage(e), MessageUtil.EMBEDDED_MESSAGE_END); } return new Writer(out) { @Override public void close() {} @Override public void flush() throws IOException { out.flush(); } @Override public void write(char[] cbuf, int off, int len) throws IOException { out.write(cbuf, off, len); } }; }