@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 void execute( Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { String name = DirectiveUtils.getRequiredParam(params, "name"); String encoding = DirectiveUtils.getParam(params, "encoding", null); String includeTemplateName = TemplateCache.getFullTemplatePath(env, getTemplatePath(env), name); env.include(includeTemplateName, encoding, true); }
@Override public void execute( Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { long beginTime = System.currentTimeMillis(); Map<String, TemplateModel> paramsWrap = putRes(env, params, loopVars, body); Map<String, TemplateModel> origMap = DirectiveUtils.addParamsToVariable(env, paramsWrap); body.render(env.getOut()); DirectiveUtils.removeParamsFromVariable(env, paramsWrap, origMap); long endTime = System.currentTimeMillis(); log.debug(this.getClass().getName() + ":共耗时" + String.valueOf(endTime - beginTime) + "微秒"); }
@SuppressWarnings("unchecked") public void execute( Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { String s = DirectiveUtils.getString(PARAM_S, params); Integer len = DirectiveUtils.getInt(PARAM_LEN, params); String append = DirectiveUtils.getString(PARAM_APPEND, params); if (s != null) { Writer out = env.getOut(); if (len != null) { out.append(StrUtils.textCut(s, len, append)); } else { out.append(s); } } }
@SuppressWarnings("unchecked") protected List<Content> getList(Map<String, TemplateModel> params, Environment env) throws TemplateException { Integer[] ids = DirectiveUtils.getIntArray(PARAM_IDS, params); if (ids != null) { return contentMng.getListByIdsForTag(ids, getOrderBy(params)); } else { return (List<Content>) super.getData(params, env); } }