Java Code Examples for freemarker.core.Environment#include()
The following examples show how to use
freemarker.core.Environment#include() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CmsGuestbookListDirective.java From Lottery with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unchecked") public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { CmsSite site = FrontUtils.getSite(env); int first = FrontUtils.getFirst(params); int max = FrontUtils.getCount(params); List<CmsGuestbook> list = cmsGuestbookMng.getList(getSiteId(params), getCtgId(params), getRecommend(params), getChecked(params), getDesc(params), true, first, max); 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); }
Example 2
Source File: FreeMarkerWorker.java From scipio-erp with Apache License 2.0 | 5 votes |
/** * SCIPIO: Includes the given template with the given environment. * <em>All macro renderer template include calls must be wrapped with this method! * See {@link #getCurrentEnvironment}.</em> * * @see #getCurrentEnvironment */ public static void includeTemplate(Template template, Environment env) throws TemplateException, IOException { Environment savedEnv = threadEnv.get(); threadEnv.set(env); try { env.include(template); } finally { threadEnv.set(savedEnv); } }
Example 3
Source File: ExtendsDirective.java From onetwo with Apache License 2.0 | 5 votes |
@Override public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { String file = DirectivesUtils.getParameterByString(params, PARAMS_FILE, DEFAULT_LAYOUT); String template = env.toFullTemplateName("/", getActaulFile(params, file)); if(!template.contains(".")){ template += FTL; } body.render(env.getOut()); env.include(template, DirectivesUtils.ENCODING, true); }
Example 4
Source File: FrontUtils.java From Lottery with GNU General Public License v2.0 | 5 votes |
/** * 标签中包含页面 * * @param tplName * @param site * @param params * @param env * @throws IOException * @throws TemplateException */ public static void includeTpl(String tplName, CmsSite site, Map<String, TemplateModel> params, Environment env) throws IOException, TemplateException { String subTpl = DirectiveUtils.getString(PARAM_TPL_SUB, params); String tpl; if (StringUtils.isBlank(subTpl)) { tpl = getTplPath(site.getSolutionPath(), TPLDIR_TAG, tplName); } else { tpl = getTplPath(site.getSolutionPath(), TPLDIR_TAG, tplName + "_" + subTpl); } env.include(tpl, UTF8, true); }
Example 5
Source File: ContentPageDirective.java From Lottery with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unchecked") public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { CmsSite site = FrontUtils.getSite(env); Pagination page = (Pagination) super.getData(params, env); Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>( params); paramWrap.put(OUT_PAGINATION, DEFAULT_WRAPPER.wrap(page)); paramWrap.put(OUT_LIST, DEFAULT_WRAPPER.wrap(page.getList())); 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); FrontUtils.includePagination(site, params, env); } else if (InvokeType.userDefined == type) { if (StringUtils.isBlank(listStyle)) { throw new ParamsRequiredException(PARAM_STYLE_LIST); } FrontUtils.includeTpl(TPL_STYLE_LIST, site, env); FrontUtils.includePagination(site, params, env); } else if (InvokeType.custom == type) { FrontUtils.includeTpl(TPL_NAME, site, params, env); FrontUtils.includePagination(site, params, env); } else if (InvokeType.body == type) { if (body != null) { body.render(env.getOut()); FrontUtils.includePagination(site, params, env); } } else { throw new RuntimeException("invoke type not handled: " + type); } DirectiveUtils.removeParamsFromVariable(env, paramWrap, origMap); }
Example 6
Source File: CmsCommentListDirective.java From Lottery with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unchecked") public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { CmsSite site = FrontUtils.getSite(env); List<CmsComment> list = cmsCommentMng.getListForTag(getSiteId(params), getContentId(params), getGreaterThen(params), getChecked(params), getRecommend(params), getDesc(params), FrontUtils.getCount(params)); 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); }
Example 7
Source File: CmsTopicPageDirective.java From Lottery with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unchecked") public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { CmsSite site = FrontUtils.getSite(env); Pagination page = cmsTopicMng.getPageForTag(getChannelId(params), getRecommend(params), FrontUtils.getPageNo(env), FrontUtils .getCount(params)); Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>( params); paramWrap.put(OUT_PAGINATION, DEFAULT_WRAPPER.wrap(page)); paramWrap.put(OUT_LIST, DEFAULT_WRAPPER.wrap(page.getList())); 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); FrontUtils.includePagination(site, params, env); } else if (InvokeType.userDefined == type) { if (StringUtils.isBlank(listStyle)) { throw new ParamsRequiredException(PARAM_STYLE_LIST); } FrontUtils.includeTpl(TPL_STYLE_LIST, site, env); FrontUtils.includePagination(site, params, env); } else if (InvokeType.custom == type) { FrontUtils.includeTpl(TPL_NAME, site, params, env); FrontUtils.includePagination(site, params, env); } else if (InvokeType.body == type) { body.render(env.getOut()); FrontUtils.includePagination(site, params, env); } else { throw new RuntimeException("invoke type not handled: " + type); } DirectiveUtils.removeParamsFromVariable(env, paramWrap, origMap); }
Example 8
Source File: CmsGuestbookCtgListDirective.java From Lottery with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unchecked") public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { CmsSite site = FrontUtils.getSite(env); List<CmsGuestbookCtg> list = cmsGuestbookCtgMng .getList(getSiteId(params)); 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); }
Example 9
Source File: ExtendsDirective.java From metadata with Apache License 2.0 | 5 votes |
@Override 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); }
Example 10
Source File: ContentListDirective.java From Lottery with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unchecked") public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { CmsSite 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); }
Example 11
Source File: CmsCommentPageDirective.java From Lottery with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unchecked") public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { CmsSite site = FrontUtils.getSite(env); Pagination page = cmsCommentMng.getPageForTag(null, getContentId(params), getGreaterThen(params), getChecked(params), getRecommend(params), getDesc(params), FrontUtils.getPageNo(env), FrontUtils.getCount(params)); Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>( params); paramWrap.put(OUT_PAGINATION, DEFAULT_WRAPPER.wrap(page)); paramWrap.put(OUT_LIST, DEFAULT_WRAPPER.wrap(page.getList())); 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); FrontUtils.includePagination(site, params, env); } else if (InvokeType.userDefined == type) { if (StringUtils.isBlank(listStyle)) { throw new ParamsRequiredException(PARAM_STYLE_LIST); } FrontUtils.includeTpl(TPL_STYLE_LIST, site, env); FrontUtils.includePagination(site, params, env); } else if (InvokeType.custom == type) { FrontUtils.includeTpl(TPL_NAME, site, params, env); FrontUtils.includePagination(site, params, env); } else if (InvokeType.body == type) { body.render(env.getOut()); FrontUtils.includePagination(site, params, env); } else { throw new RuntimeException("invoke type not handled: " + type); } DirectiveUtils.removeParamsFromVariable(env, paramWrap, origMap); }
Example 12
Source File: CmsTopicListDirective.java From Lottery with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unchecked") public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { CmsSite site = FrontUtils.getSite(env); List<CmsTopic> list = cmsTopicMng.getListForTag(getChannelId(params), getRecommend(params), FrontUtils.getCount(params)); 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); }
Example 13
Source File: ContentTagPageDirective.java From Lottery with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unchecked") public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { CmsSite site = FrontUtils.getSite(env); Pagination page = contentTagMng.getPageForTag( FrontUtils.getPageNo(env), FrontUtils.getCount(params)); Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>( params); paramWrap.put(OUT_PAGINATION, DEFAULT_WRAPPER.wrap(page)); paramWrap.put(OUT_LIST, DEFAULT_WRAPPER.wrap(page.getList())); 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); FrontUtils.includePagination(site, params, env); } else if (InvokeType.userDefined == type) { if (StringUtils.isBlank(listStyle)) { throw new ParamsRequiredException(PARAM_STYLE_LIST); } FrontUtils.includeTpl(TPL_STYLE_LIST, site, env); FrontUtils.includePagination(site, params, env); } else if (InvokeType.custom == type) { FrontUtils.includeTpl(TPL_NAME, site, params, env); FrontUtils.includePagination(site, params, env); } else if (InvokeType.body == type) { body.render(env.getOut()); FrontUtils.includePagination(site, params, env); } else { throw new RuntimeException("invoke type not handled: " + type); } DirectiveUtils.removeParamsFromVariable(env, paramWrap, origMap); }
Example 14
Source File: ChannelPageDirective.java From Lottery with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("unchecked") public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { CmsSite site = FrontUtils.getSite(env); Integer parentId = DirectiveUtils.getInt(PARAM_PARENT_ID, params); Integer siteId = DirectiveUtils.getInt(PARAM_SITE_ID, params); boolean hasContentOnly = getHasContentOnly(params); Pagination page; if (parentId != null) { page = channelMng.getChildPageForTag(parentId, hasContentOnly, FrontUtils.getPageNo(env), FrontUtils.getCount(params)); } else { if (siteId == null) { siteId = site.getId(); } page = channelMng.getTopPageForTag(siteId, hasContentOnly, FrontUtils.getPageNo(env), FrontUtils.getCount(params)); } Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>( params); paramWrap.put(OUT_PAGINATION, DEFAULT_WRAPPER.wrap(page)); 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); }
Example 15
Source File: CmsGuestbookPageDirective.java From Lottery with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("unchecked") public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { CmsSite site = FrontUtils.getSite(env); int pageNo = FrontUtils.getPageNo(env); int count = FrontUtils.getCount(params); Pagination page = cmsGuestbookMng.getPage(getSiteId(params), getCtgId(params),null, getRecommend(params), getChecked(params), getDesc(params), true, pageNo, count); Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>( params); paramWrap.put(OUT_PAGINATION, DEFAULT_WRAPPER.wrap(page)); paramWrap.put(OUT_LIST, DEFAULT_WRAPPER.wrap(page.getList())); 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); FrontUtils.includePagination(site, params, env); } else if (InvokeType.userDefined == type) { if (StringUtils.isBlank(listStyle)) { throw new ParamsRequiredException(PARAM_STYLE_LIST); } FrontUtils.includeTpl(TPL_STYLE_LIST, site, env); FrontUtils.includePagination(site, params, env); } else if (InvokeType.custom == type) { FrontUtils.includeTpl(TPL_NAME, site, params, env); FrontUtils.includePagination(site, params, env); } else if (InvokeType.body == type) { body.render(env.getOut()); FrontUtils.includePagination(site, params, env); } else { throw new RuntimeException("invoke type not handled: " + type); } DirectiveUtils.removeParamsFromVariable(env, paramWrap, origMap); }
Example 16
Source File: ChannelListDirective.java From Lottery with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("unchecked") public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { CmsSite site = FrontUtils.getSite(env); Integer parentId = DirectiveUtils.getInt(PARAM_PARENT_ID, params); Integer siteId = DirectiveUtils.getInt(PARAM_SITE_ID, params); boolean hasContentOnly = getHasContentOnly(params); List<Channel> list; if (parentId != null) { list = channelMng.getChildListForTag(parentId, hasContentOnly); } else { if (siteId == null) { siteId = site.getId(); } list = channelMng.getTopListForTag(siteId, hasContentOnly); } 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); }
Example 17
Source File: LuceneDirectivePage.java From Lottery with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("unchecked") public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { CmsSite site = FrontUtils.getSite(env); int pageNo = FrontUtils.getPageNo(env); int count = FrontUtils.getCount(params); String query = getQuery(params); String workplace= getWorkplace(params); String category= getCategory(params); Integer siteId = getSiteId(params); Integer channelId = getChannelId(params); Date startDate = getStartDate(params); Date endDate = getEndDate(params); Pagination page; try { String path = realPathResolver.get(Constants.LUCENE_PATH); page = luceneContentSvc.searchPage(path, query,category,workplace, siteId, channelId, startDate, endDate, pageNo, count); } catch (ParseException e) { throw new RuntimeException(e); } Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>( params); paramWrap.put(OUT_PAGINATION, DEFAULT_WRAPPER.wrap(page)); paramWrap.put(OUT_LIST, DEFAULT_WRAPPER.wrap(page.getList())); 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); FrontUtils.includePagination(site, params, env); } else if (InvokeType.userDefined == type) { if (StringUtils.isBlank(listStyle)) { throw new ParamsRequiredException(PARAM_STYLE_LIST); } FrontUtils.includeTpl(TPL_STYLE_LIST, site, env); FrontUtils.includePagination(site, params, env); } else if (InvokeType.custom == type) { FrontUtils.includeTpl(TPL_NAME, site, params, env); FrontUtils.includePagination(site, params, env); } else if (InvokeType.body == type) { body.render(env.getOut()); FrontUtils.includePagination(site, params, env); } else { throw new RuntimeException("invoke type not handled: " + type); } DirectiveUtils.removeParamsFromVariable(env, paramWrap, origMap); }
Example 18
Source File: LuceneDirectiveList.java From Lottery with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("unchecked") public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { CmsSite site = FrontUtils.getSite(env); int first = FrontUtils.getFirst(params); int count = FrontUtils.getCount(params); String query = getQuery(params); String workplace= getWorkplace(params); String category= getCategory(params); Integer siteId = getSiteId(params); Integer channelId = getChannelId(params); Date startDate = getStartDate(params); Date endDate = getEndDate(params); List<Content> list; try { String path = realPathResolver.get(Constants.LUCENE_PATH); list = luceneContentSvc.searchList(path, query,category,workplace, siteId, channelId, startDate, endDate, first, count); } catch (ParseException e) { throw new RuntimeException(e); } 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); }
Example 19
Source File: ExtendsDirective.java From freemarker-template-inheritance with Apache License 2.0 | 4 votes |
private void processLayout(Environment env, String layoutName) throws IOException, TemplateException { env.include(layoutName, null, true); }
Example 20
Source File: FrontUtils.java From Lottery with GNU General Public License v2.0 | 3 votes |
/** * 标签中包含用户预定义列表样式模板 * * @param listStyle * @param site * @param env * @throws IOException * @throws TemplateException */ public static void includeTpl(String listStyle, CmsSite site, Environment env) throws IOException, TemplateException { String tpl = getTplPath(site.getSolutionPath(), TPLDIR_STYLE_LIST, listStyle); env.include(tpl, UTF8, true); }