Java Code Examples for freemarker.core.Environment#setVariable()
The following examples show how to use
freemarker.core.Environment#setVariable() .
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: ArticleTagDirective.java From stone with GNU General Public License v3.0 | 6 votes |
@Override public void execute(Environment environment, Map map, TemplateModel[] templateModels, TemplateDirectiveBody templateDirectiveBody) throws TemplateException, IOException { final DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25); if (map.containsKey(METHOD_KEY)) { String method = map.get(METHOD_KEY).toString(); switch (method) { case "postsCount": environment.setVariable("postsCount", builder.build().wrap(postService.findPostByStatus(PostStatusEnum.PUBLISHED.getCode(), PostTypeEnum.POST_TYPE_POST.getDesc()).size())); break; case "archives": environment.setVariable("archives", builder.build().wrap(postService.findPostGroupByYearAndMonth())); break; case "archivesLess": environment.setVariable("archivesLess", builder.build().wrap(postService.findPostGroupByYear())); break; case "hotPosts": environment.setVariable("hotPosts", builder.build().wrap(postService.hotPosts())); break; default: break; } } templateDirectiveBody.render(environment.getOut()); }
Example 2
Source File: PhotoTagDirective.java From halo with GNU General Public License v3.0 | 6 votes |
@Override public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { final DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25); if (params.containsKey(HaloConst.METHOD_KEY)) { String method = params.get(HaloConst.METHOD_KEY).toString(); switch (method) { case "list": env.setVariable("photos", builder.build().wrap(photoService.listAll())); break; case "listTeams": env.setVariable("teams", builder.build().wrap(photoService.listTeamVos(Sort.by(DESC, "createTime")))); break; case "listByTeam": String team = params.get("team").toString(); env.setVariable("photos", builder.build().wrap(photoService.listByTeam(team, Sort.by(DESC, "createTime")))); break; case "count": env.setVariable("count", builder.build().wrap(photoService.count())); break; default: break; } } body.render(env.getOut()); }
Example 3
Source File: SiteTags.java From cms with Apache License 2.0 | 6 votes |
@Override public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { if (params.get("id") == null) { return; } String alias = params.get("alias") == null ? null : params.get("alias").toString(); String name = alias == null ? "site" : alias; String id = params.get("id").toString(); Site site = SystemCacheManager.get(ConstantsUtils.SITE_ID_KEY + id, Site.class); if (site == null) { site = siteService.get(Long.parseLong(id)); } env.setVariable(name, wrap(site)); if (body != null) { body.render(env.getOut()); } // env.getOut().write(site); }
Example 4
Source File: CommonTagDirective.java From SENS with GNU General Public License v3.0 | 6 votes |
@Override public void execute(Environment environment, Map map, TemplateModel[] templateModels, TemplateDirectiveBody templateDirectiveBody) throws TemplateException, IOException { DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25); if (map.containsKey(METHOD_KEY)) { String method = map.get(METHOD_KEY).toString(); switch (method) { case "menus": environment.setVariable("frontTopMenus", builder.build().wrap(menuService.findMenuTree(MenuTypeEnum.FRONT_TOP_MENU.getCode()))); environment.setVariable("frontMainMenus", builder.build().wrap(menuService.findMenuTree(MenuTypeEnum.FRONT_MAIN_MENU.getCode()))); break; case "slides": environment.setVariable("slides", builder.build().wrap(slideService.findBySlideType(SlideTypeEnum.INDEX_SLIDE.getCode()))); break; case "links": environment.setVariable("links", builder.build().wrap(linkService.findAll())); break; case "footerWidgets": environment.setVariable("footerWidgets", builder.build().wrap(widgetService.findByWidgetType(WidgetTypeEnum.FOOTER_WIDGET.getCode()))); break; default: break; } } templateDirectiveBody.render(environment.getOut()); }
Example 5
Source File: Usercount.java From FlyCms with MIT License | 6 votes |
@SuppressWarnings("rawtypes") public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25); // 获取页面的参数 Long userId = null; @SuppressWarnings("unchecked") Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>(params); for(String str:paramWrap.keySet()){ if("userId".equals(str)){ userId = Long.parseLong(paramWrap.get(str).toString()); } } // 获取文件的分页 UserCount count = userService.findUserCountById(userId); env.setVariable("count", builder.build().wrap(count)); body.render(env.getOut()); }
Example 6
Source File: IndexArticleDirective.java From mysiteforme with Apache License 2.0 | 6 votes |
@Override public void execute(Environment environment, Map map, TemplateModel[] templateModels, TemplateDirectiveBody templateDirectiveBody) throws TemplateException, IOException { Iterator iterator = map.entrySet().iterator(); Map<String,Object> paramMap = Maps.newHashMap(); Integer limit = 10; String order = "top,recommend,publish,sort,view"; while (iterator.hasNext()) { Map.Entry<String, TemplateModel> param = (Map.Entry<String, TemplateModel>) iterator.next(); String paramName = param.getKey(); TemplateModel paramValue = param.getValue(); if(paramName.toLowerCase().equals("limit")){ limit = getInt(paramName,paramValue); } if(paramName.toLowerCase().equals("order")){ order = getString(paramName,paramValue); } } paramMap.put("limit",limit); paramMap.put("order",order); List<BlogArticle> articleList = blogArticleService.selectBlogIndexArticles(paramMap); DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_26); environment.setVariable("result", builder.build().wrap(articleList)); templateDirectiveBody.render(environment.getOut()); }
Example 7
Source File: SystemDirective.java From mysiteforme with Apache License 2.0 | 6 votes |
@Override public void execute(Environment environment, Map map, TemplateModel[] templateModels, TemplateDirectiveBody templateDirectiveBody) throws TemplateException, IOException { Iterator iterator = map.entrySet().iterator(); EntityWrapper<Dict> wrapper = new EntityWrapper<>(); List<Dict> dictList = Lists.newArrayList(); while (iterator.hasNext()) { Map.Entry<String, TemplateModel> param = (Map.Entry<String, TemplateModel>) iterator.next(); String paramName = param.getKey(); TemplateModel paramValue = param.getValue(); if(paramName.toLowerCase().equals("type")){ String dicType = getString(paramName,paramValue); if(StringUtils.isBlank(dicType)){ throw new TemplateModelException("参数名称不正确"); }else{ dictList = dictService.getDictByType(dicType); } } } if(dictList.size()<=0){ throw new TemplateModelException("返回值为空"); } DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_26); environment.setVariable("result", builder.build().wrap(dictList)); templateDirectiveBody.render(environment.getOut()); }
Example 8
Source File: CommonTagDirective.java From blog-sharon with Apache License 2.0 | 5 votes |
@Override public void execute(Environment environment, Map map, TemplateModel[] templateModels, TemplateDirectiveBody templateDirectiveBody) throws TemplateException, IOException { DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25); if (map.containsKey(METHOD_KEY)) { String method = map.get(METHOD_KEY).toString(); switch (method) { case "menus": environment.setVariable("menus", builder.build().wrap(menuService.findAll())); break; case "categories": environment.setVariable("categories", builder.build().wrap(categoryService.findAll())); break; case "tags": environment.setVariable("tags", builder.build().wrap(tagService.findAll())); break; case "links": environment.setVariable("links", builder.build().wrap(linkService.findAll())); break; case "newComments": environment.setVariable("newComments", builder.build().wrap(commentService.findAll(1))); break; default: break; } } templateDirectiveBody.render(environment.getOut()); }
Example 9
Source File: Checktagfollow.java From FlyCms with MIT License | 5 votes |
@Override @SuppressWarnings("rawtypes") public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25); try { // 被关注者id Long userId = null; // 获取文件的分页 //话题id Long topicId = null; //处理标签变量 @SuppressWarnings("unchecked") Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>(params); for(String str:paramWrap.keySet()){ if("userId".equals(str)){ userId = Long.parseLong(paramWrap.get(str).toString()); } if("topicId".equals(str)){ topicId = Long.parseLong(paramWrap.get(str).toString()); } } if(userId!=null && topicId!=null){ boolean result=topicService.checkTopicByUserId(userId,topicId); env.setVariable("result", builder.build().wrap(result)); }else { env.setVariable("result", builder.build().wrap(false)); } } catch (Exception e) { e.printStackTrace(); } body.render(env.getOut()); }
Example 10
Source File: UserCommentsDirective.java From pybbs with GNU Affero General Public License v3.0 | 5 votes |
@Override public void execute(Environment environment, Map map, TemplateModel[] templateModels, TemplateDirectiveBody templateDirectiveBody) throws TemplateException, IOException { String username = String.valueOf(map.get("username")); Integer pageNo = Integer.parseInt(map.get("pageNo").toString()); Integer pageSize = map.get("pageSize") == null ? null : Integer.parseInt(map.get("pageSize").toString()); User user = userService.selectByUsername(username); DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_28); environment.setVariable("comments", builder.build().wrap(commentService.selectByUserId(user.getId(), pageNo, pageSize))); templateDirectiveBody.render(environment.getOut()); }
Example 11
Source File: LangFtlUtil.java From scipio-erp with Apache License 2.0 | 5 votes |
/** * Executes an arbitrary FTL macro - non-abstracted version (for optimization only!). */ public static void execMacro(Template macroCall, Map<String, TemplateModel> args, Environment env) throws TemplateModelException { if (args != null) { for(Map.Entry<String, TemplateModel> entry : args.entrySet()) { env.setVariable("_scpEfnArg_"+entry.getKey(), entry.getValue()); } } execFtlCode(macroCall, env); }
Example 12
Source File: ArticleTags.java From cms with Apache License 2.0 | 5 votes |
@Override public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { SimpleScalar id = (SimpleScalar) params.get("id"); SimpleScalar categoryId = (SimpleScalar) params.get("categoryId"); SimpleScalar type = (SimpleScalar) params.get("type"); SimpleScalar showCountParms = (SimpleScalar) params.get("showCount"); Integer showCount = showCountParms == null ? 10 : Integer.parseInt(showCountParms.toString()); SimpleScalar nameParms = (SimpleScalar) params.get("alias"); String name = nameParms == null ? "article" : nameParms.toString(); List<Article> list = null; try { Long catId = null; Integer _type = null; if (categoryId != null) { catId = Long.parseLong(categoryId.toString()); } if (type != null) { _type = Integer.parseInt(type.toString()); } list = articleService.getArticleList(Long.parseLong(id.toString()), catId, _type, showCount); } catch (Exception e) { } finally { env.setVariable(name, wrap(list)); if (body != null) { body.render(env.getOut()); } } }
Example 13
Source File: AdTags.java From cms with Apache License 2.0 | 5 votes |
@Override public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { SimpleScalar id = (SimpleScalar) params.get("id"); List<Ad> ads = adService.getAdByPositionId(Long.parseLong(id.toString())); env.setVariable("ads", wrap(ads)); if (body != null) { body.render(env.getOut()); } }
Example 14
Source File: Shareinfo.java From FlyCms with MIT License | 5 votes |
@SuppressWarnings("rawtypes") public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25); // 获取页面的参数 Long id = null; Integer status = 0; @SuppressWarnings("unchecked") Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>(params); for(String str:paramWrap.keySet()){ if("id".equals(str)){ id = Long.parseLong(paramWrap.get(str).toString()); } if("status".equals(str)){ status = Integer.parseInt(paramWrap.get(str).toString()); } } // 获取文件的分页 Share share = shareService.findShareById(id,status); if(share!=null){ //查询统计信息 ShareCount count=shareService.findShareCountById(share.getId()); share.setCountDigg(count.getCountDigg()); share.setCountBurys(count.getCountBurys()); share.setCountView(count.getCountView()); share.setCountComment(count.getCountComment()); } env.setVariable("share", builder.build().wrap(share)); body.render(env.getOut()); }
Example 15
Source File: MenuTagDirective.java From halo with GNU General Public License v3.0 | 5 votes |
@Override public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { final DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25); if (params.containsKey(HaloConst.METHOD_KEY)) { String method = params.get(HaloConst.METHOD_KEY).toString(); switch (method) { case "list": env.setVariable("menus", builder.build().wrap(menuService.listAll())); break; case "tree": env.setVariable("menus", builder.build().wrap(menuService.listAsTree(Sort.by(DESC, "priority")))); break; case "listTeams": env.setVariable("teams", builder.build().wrap(menuService.listTeamVos(Sort.by(DESC, "priority")))); break; case "listByTeam": String team = params.get("team").toString(); env.setVariable("menus", builder.build().wrap(menuService.listByTeam(team, Sort.by(DESC, "priority")))); break; case "treeByTeam": String treeTeam = params.get("team").toString(); env.setVariable("menus", builder.build().wrap(menuService.listByTeamAsTree(treeTeam, Sort.by(DESC, "priority")))); break; case "count": env.setVariable("count", builder.build().wrap(menuService.count())); break; default: break; } } body.render(env.getOut()); }
Example 16
Source File: FtlUtils.java From onetwo with Apache License 2.0 | 4 votes |
public static void setVariable(Environment env, String name, TemplateModel val){ env.setVariable(name, val); }
Example 17
Source File: Fanspage.java From FlyCms with MIT License | 4 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25); // 获取页面的参数 //被关注者用户id Long userFollow = null; //粉丝id,关注者的id Long userFans = null; String createTime=null; String orderby=null; String order=null; //翻页页数 Integer p = 1; //每页记录条数 Integer rows = 10; //处理标签变量 Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>(params); for(String str:paramWrap.keySet()){ if("userFollow".equals(str)){ userFollow = Long.parseLong(paramWrap.get(str).toString()); } if("userFans".equals(str)){ userFans = Long.parseLong(paramWrap.get(str).toString()); } if("createTime".equals(str)){ createTime = paramWrap.get(str).toString(); } if("orderby".equals(str)){ orderby = paramWrap.get(str).toString(); } if("order".equals(str)){ order = paramWrap.get(str).toString(); } if("p".equals(str)){ p = Integer.parseInt(paramWrap.get(str).toString()); } if("rows".equals(str)){ rows = Integer.parseInt(paramWrap.get(str).toString()); } } // 获取文件的分页 try { PageVo<UserFans> pageVo = userService.getUserFansListPage(userFollow,userFans,createTime,orderby,order,p,rows); env.setVariable("fans_page", builder.build().wrap(pageVo)); } catch (Exception e) { env.setVariable("fans_page", builder.build().wrap(null)); } body.render(env.getOut()); }
Example 18
Source File: Favoritepage.java From FlyCms with MIT License | 4 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25); // 获取页面的参数 Long userId = null; Integer infoType = null; String createTime = null; String orderby=null; String order=null; //翻页页数 Integer p = 1; //每页记录条数 Integer rows = 10; //处理标签变量 Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>(params); for(String str:paramWrap.keySet()){ if("userId".equals(str)){ userId = Long.parseLong(paramWrap.get(str).toString()); } if("infoType".equals(str)){ infoType = Integer.parseInt(paramWrap.get(str).toString()); } if("createTime".equals(str)){ createTime = paramWrap.get(str).toString(); } if("orderby".equals(str)){ orderby = paramWrap.get(str).toString(); } if("order".equals(str)){ order = paramWrap.get(str).toString(); } if("p".equals(str)){ p = Integer.parseInt(paramWrap.get(str).toString()); } if("rows".equals(str)){ rows = Integer.parseInt(paramWrap.get(str).toString()); } } // 获取文件的分页 try { PageVo<Favorite> pageVo = favoriteService.getFavoriteListPage(userId,infoType,createTime,orderby,order,p,rows); env.setVariable("favorite_page", builder.build().wrap(pageVo)); } catch (Exception e) { env.setVariable("favorite_page", builder.build().wrap(null)); } body.render(env.getOut()); }
Example 19
Source File: Sharepage.java From FlyCms with MIT License | 4 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25); // 获取页面的参数 //所属主信息类型,0是所有,1是文章,2是小组话题 String title = null; Long userId = null; String createTime=null; Integer status=null; String orderby=null; String order=null; //翻页页数 Integer p = 1; //每页记录条数 Integer rows = 10; //处理标签变量 Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>(params); for(String str:paramWrap.keySet()){ if("title".equals(str)){ title = paramWrap.get(str).toString(); } if("userId".equals(str)){ userId = Long.parseLong(paramWrap.get(str).toString()); } if("createTime".equals(str)){ createTime = paramWrap.get(str).toString(); } if("orderby".equals(str)){ orderby = paramWrap.get(str).toString(); } if("order".equals(str)){ order = paramWrap.get(str).toString(); } if("status".equals(str)){ status = Integer.parseInt(paramWrap.get(str).toString()); } if("p".equals(str)){ p = Integer.parseInt(paramWrap.get(str).toString()); } if("rows".equals(str)){ rows = Integer.parseInt(paramWrap.get(str).toString()); } } // 获取文件的分页 try { PageVo<Share> pageVo = shareService.getShareListPage(title,userId,createTime,status,orderby,order,p,rows); env.setVariable("share_page", builder.build().wrap(pageVo)); } catch (Exception e) { env.setVariable("share_page", builder.build().wrap(null)); } body.render(env.getOut()); }
Example 20
Source File: Scoredetailpage.java From FlyCms with MIT License | 4 votes |
@SuppressWarnings("rawtypes") public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException { DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25); // 获取页面的参数 Long userId = null; Integer status = null; String orderby=null; String order=null; //翻页页数 Integer p = 1; //每页记录条数 Integer rows = 10; @SuppressWarnings("unchecked") Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>(params); for(String str:paramWrap.keySet()){ if("userId".equals(str)){ userId = Long.parseLong(paramWrap.get(str).toString()); } if("status".equals(str)){ status = Integer.parseInt(paramWrap.get(str).toString()); } if("orderby".equals(str)){ orderby = paramWrap.get(str).toString(); } if("order".equals(str)){ order = paramWrap.get(str).toString(); } if("status".equals(str)){ status = Integer.parseInt(paramWrap.get(str).toString()); } if("p".equals(str)){ p = Integer.parseInt(paramWrap.get(str).toString()); } if("rows".equals(str)){ rows = Integer.parseInt(paramWrap.get(str).toString()); } } // 获取文件的分页 PageVo<ScoreDetail> detail_page = scoreDetailService.scoreDetaillistPage(userId, status, orderby, order, p, rows); env.setVariable("detail_page", builder.build().wrap(detail_page)); body.render(env.getOut()); }