com.jfinal.template.io.Writer Java Examples
The following examples show how to use
com.jfinal.template.io.Writer.
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: ParaDirective.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onRender(Env env, Scope scope, Writer writer) { Controller controller = JbootControllerContext.get(); String key = getPara(0, scope); String defaultValue = getPara(1, scope); if (StrUtil.isBlank(key)) { throw new IllegalArgumentException("#para(...) argument must not be empty" + getLocation()); } String value = controller.getPara(key); if (StrUtil.isBlank(value)) { value = StrUtil.isNotBlank(defaultValue) ? defaultValue : ""; } try { writer.write(value); } catch (IOException e) { e.printStackTrace(); } }
Example #2
Source File: StatusTplDirective.java From jboot-admin with Apache License 2.0 | 6 votes |
@Override public void exec(Env env, Scope scope, Writer writer) { if (exprList.length() > 2) { throw new ParseException("Wrong number parameter of #date directive, two parameters allowed at most", location); } status = getParam(0, scope); if (status == null) { throw new ParseException("status is null", location); } if (exprList.length() > 1) { attrName = getParam(1, "status", scope); } write(writer, "<div>"); for (String key : status.all().keySet()) { write(writer, "{{# if(d." + attrName + " == \\'" + key + "\\') { }}"); write(writer, status.desc(key)); write(writer, "{{# } }}"); } write(writer, "</div>"); }
Example #3
Source File: EditorContentDirective.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onRender(Env env, Scope scope, Writer writer) { String originalContent = getPara(0, scope); if (originalContent == null) { return; } String editMode = JbootControllerContext.get().getAttr("editMode"); if (StrUtil.isNotBlank(editMode) && !JPressConsts.EDIT_MODE_HTML.equals(editMode)){ renderText(writer,originalContent); } //ckeditor 编辑器有个bug,自动把 < 转化为 < 和 把 > 转化为 > //因此,此处需要 把 "<" 替换为 "&lt;" 和 把 ">" 替换为 "&gt;" //方案:http://komlenic.com/246/encoding-entities-to-work-with-ckeditor-3/ else { renderText(writer, StringUtils.replaceEach(originalContent, originalChars, newChars)); } }
Example #4
Source File: OptionDirective.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onRender(Env env, Scope scope, Writer writer) { String key = getPara(0, scope); if (StrUtil.isBlank(key)) { throw new IllegalArgumentException("#option(...) argument must not be empty " + getLocation()); } String defaultValue = getPara(1, scope, ""); String value = JPressOptions.get(key); if (value == null || value == "") { value = defaultValue; } try { writer.write(value); } catch (IOException e) { throw new TemplateException(e.getMessage(), location, e); } }
Example #5
Source File: ProductPageDirective.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onRender(Env env, Scope scope, Writer writer) { Controller controller = JbootControllerContext.get(); int page = controller.getParaToInt(1, 1); int pageSize = getParaToInt("pageSize", scope, 10); String orderBy = getPara("orderBy", scope, "id desc"); // 可以指定当前的分类ID Long categoryId = getParaToLong("categoryId", scope, 0L); ProductCategory category = controller.getAttr("category"); if (categoryId == 0 && category != null) { categoryId = category.getId(); } Page<Product> productPage = categoryId == 0 ? service.paginateInNormal(page, pageSize, orderBy) : service.paginateByCategoryIdInNormal(page, pageSize, categoryId, orderBy); scope.setGlobal("productPage", productPage); renderBody(env, scope, writer); }
Example #6
Source File: DataTplDirective.java From jboot-admin with Apache License 2.0 | 6 votes |
@Override public void exec(Env env, Scope scope, Writer writer) { if (exprList.length() > 2) { throw new ParseException("Wrong number parameter of #date directive, two parameters allowed at most", location); } typeCode = getParam(0, scope); if (StrKit.isBlank(typeCode)) { throw new ParseException("typeCode is null", location); } if (exprList.length() > 1) { attrName = getParam(1, "type", scope); } List<Data> list = dataApi.getListByTypeOnUse(typeCode); write(writer, "<div>"); for (Data data : list) { write(writer, "{{# if(d." + attrName + " == \\'" + data.getCode() + "\\') { }}"); write(writer, data.getCodeDesc()); write(writer, "{{# } }}"); } write(writer, "</div>"); }
Example #7
Source File: ProductCategoriesDirective.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onRender(Env env, Scope scope, Writer writer) { Long id = getParaToLong(0, scope); String type = getPara(1, scope); if (id == null || type == null) { throw new IllegalArgumentException("#productCategories() args error. id or type must not be null." + getLocation()); } List<ProductCategory> categories = categoryService.findListByProductId(id, type); if (categories == null || categories.isEmpty()) { return; } scope.setLocal("categories", categories); renderBody(env, scope, writer); }
Example #8
Source File: OptionDirective.java From jboot-admin with Apache License 2.0 | 6 votes |
@Override public void exec(Env env, Scope scope, Writer writer) { LogKit.info("option====="+typeCode); if (exprList.length() > 2) { throw new ParseException("Wrong number parameter of #date directive, two parameters allowed at most", location); } typeCode = getParam(0, scope); if (StrKit.isBlank(typeCode)) { throw new ParseException("typeCode is null", location); } if (exprList.length() > 1) { value = getParam(1, "", scope); } List<Data> list = dataApi.getListByTypeOnUse(typeCode); for (Data data : list) { if (value != null && data.getCode().equals(value)) { write(writer, "<option selected value=\"" + data.getCode() + "\">" + data.getCodeDesc() + "</option>"); } else { write(writer, "<option value=\"" + data.getCode() + "\">" + data.getCodeDesc() + "</option>"); } } }
Example #9
Source File: HasPermissionDirective.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onRender(Env env, Scope scope, Writer writer) { User user = UserInterceptor.getThreadLocalUser(); if (user == null || !user.isStatusOk()) { return; } String permission = getPara(0, scope); if (permission == null || permission.trim().length() == 0) { throw new IllegalArgumentException("#hasPermission(...) argument must not be empty," + getLocation()); } if (permissionService.hasPermission(user.getId(), permission)) { renderBody(env, scope, writer); } }
Example #10
Source File: ProductSearchPageDirective.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onRender(Env env, Scope scope, Writer writer) { Controller controller = JbootControllerContext.get(); String keyword = controller.getAttr("keyword"); int page = controller.getAttr("page"); int pageSize = getParaToInt("pageSize", scope, 10); Page<Product> dataPage = StrUtil.isNotBlank(keyword) ? productService.search(keyword, page, pageSize) : null; if (dataPage != null) { scope.setGlobal("productPage", dataPage); } //需要页面自行判断 productPage 是否为空 renderBody(env, scope, writer); }
Example #11
Source File: ProductPageDirective.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected String getUrl(int pageNumber, Env env, Scope scope, Writer writer) { HttpServletRequest request = JbootControllerContext.get().getRequest(); String url = request.getRequestURI(); String contextPath = JFinal.me().getContextPath(); boolean firstGotoIndex = getPara("firstGotoIndex", scope, false); if (pageNumber == 1 && firstGotoIndex) { return contextPath + "/"; } // 如果当前页面是首页的话 // 需要改变url的值,因为 上一页或下一页是通过当前的url解析出来的 if (url.equals(contextPath + "/")) { url = contextPath + "/product/category/index" + JPressOptions.getAppUrlSuffix(); } return DirectveKit.replacePageNumber(url, pageNumber); }
Example #12
Source File: OptionStatusDirective.java From jboot-admin with Apache License 2.0 | 6 votes |
@Override public void exec(Env env, Scope scope, Writer writer) { if (exprList.length() > 2) { throw new ParseException("Wrong number parameter of #date directive, two parameters allowed at most", location); } status = getParam(0, scope); if (status == null) { throw new ParseException("status is null", location); } if (exprList.length() > 1) { value = getParam(1, "", scope); } for (String key : status.all().keySet()) { if (value != null && key.equals(value)) { write(writer, "<option selected value=\"" + key + "\">" + status.desc(key) + "</option>"); } else { write(writer, "<option value=\"" + key + "\">" + status.desc(key) + "</option>"); } } }
Example #13
Source File: PageDirective.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onRender(Env env, Scope scope, Writer writer) { String slug = getPara("slug", scope); if (StrUtil.isBlank(slug)) { throw new IllegalArgumentException("#page(slug = ...) argument must not be empty "); } SinglePage page = singlePageService.findFirstBySlug(slug); if (page == null) { return; } scope.setLocal("page", page); renderBody(env, scope, writer); }
Example #14
Source File: RelevantProductsDirective.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onRender(Env env, Scope scope, Writer writer) { Product product = getPara(0, scope); if (product == null) { throw new IllegalArgumentException("#relevantProducts(...) argument must not be null or empty." + getLocation()); } //默认值 3 int count = getParaToInt(1, scope, 3); List<Product> relevantProducts = service.findRelevantListByProductId(product.getId(), Product.STATUS_NORMAL, count); if (relevantProducts == null || relevantProducts.isEmpty()) { return; } scope.setLocal("relevantProducts", relevantProducts); renderBody(env, scope, writer); }
Example #15
Source File: CommentsDirective.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onRender(Env env, Scope scope, Writer writer) { String orderBy = getPara("orderBy", scope, "id desc"); int count = getParaToInt("count", scope, 10); Columns columns = Columns.create("status", ArticleComment.STATUS_NORMAL); List<ArticleComment> comments = service.findListByColumns(columns, orderBy, count); if (comments == null || comments.isEmpty()) { return; } scope.setLocal("comments", comments); renderBody(env, scope, writer); }
Example #16
Source File: MaxLengthDirective.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onRender(Env env, Scope scope, Writer writer) { String content = getPara(0, scope); if (StrUtil.isBlank(content)) { return; } int maxLength = getParaToInt(1, scope, 0); if (maxLength <= 0) { throw new IllegalArgumentException("#maxLength(content,length) 参数错误,length必须大于0 " + getLocation()); } String suffix = getPara(2, scope); try { writer.write(CommonsUtils.maxLength(content, maxLength, suffix)); } catch (IOException e) { throw new TemplateException(e.getMessage(), location, e); } }
Example #17
Source File: RelevantArticlesDirective.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onRender(Env env, Scope scope, Writer writer) { Article article = getPara(0, scope); if (article == null) { throw new IllegalArgumentException("#relevantArticles(...) argument must not be null or empty." + getLocation()); } //默认值 3 int count = getParaToInt(1, scope, 3); List<Article> relevantArticles = service.findRelevantListByArticleId(article.getId(), Article.STATUS_NORMAL, count); if (relevantArticles == null || relevantArticles.isEmpty()) { return; } scope.setLocal("relevantArticles", relevantArticles); renderBody(env, scope, writer); }
Example #18
Source File: ArticlePageDirective.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onRender(Env env, Scope scope, Writer writer) { Controller controller = JbootControllerContext.get(); int page = controller.getParaToInt(1, 1); int pageSize = getParaToInt("pageSize", scope, 10); String orderBy = getPara("orderBy", scope, "id desc"); // 可以指定当前的分类ID Long categoryId = getParaToLong("categoryId", scope, 0L); ArticleCategory category = controller.getAttr("category"); if (categoryId == 0 && category != null) { categoryId = category.getId(); } Page<Article> articlePage = categoryId == 0 ? service.paginateInNormal(page, pageSize, orderBy) : service.paginateByCategoryIdInNormal(page, pageSize, categoryId, orderBy); scope.setGlobal("articlePage", articlePage); renderBody(env, scope, writer); }
Example #19
Source File: ArticlePageDirective.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected String getUrl(int pageNumber, Env env, Scope scope, Writer writer) { HttpServletRequest request = JbootControllerContext.get().getRequest(); String url = request.getRequestURI(); String contextPath = JFinal.me().getContextPath(); boolean firstGotoIndex = getPara("firstGotoIndex", scope, false); if (pageNumber == 1 && firstGotoIndex) { return contextPath + "/"; } // 如果当前页面是首页的话 // 需要改变url的值,因为 上一页或下一页是通过当前的url解析出来的 if (url.equals(contextPath + "/")) { url = contextPath + "/article/category/index" + JPressOptions.getAppUrlSuffix(); } return DirectveKit.replacePageNumber(url, pageNumber); }
Example #20
Source File: ArticleCategoriesDirective.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onRender(Env env, Scope scope, Writer writer) { Long id = getParaToLong(0, scope); String type = getPara(1, scope); if (id == null || type == null) { throw new IllegalArgumentException("#articleCategories() args error. id or type must not be null." + getLocation()); } List<ArticleCategory> categories = categoryService.findListByArticleId(id, type); if (categories == null || categories.isEmpty()) { return; } scope.setLocal("categories", categories); renderBody(env, scope, writer); }
Example #21
Source File: RoleDirective.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onRender(Env env, Scope scope, Writer writer) { User user = UserInterceptor.getThreadLocalUser(); if (user == null || !user.isStatusOk()) { return; } Set<String> roles = StrUtil.splitToSet(getPara(0, scope), ","); if (roles == null || roles.size() == 0) { throw new IllegalArgumentException("#role(...) argument must not be empty"); } if (roleService.hasRole(user.getId(), roles.toArray(new String[]{}))) { renderBody(env, scope, writer); } }
Example #22
Source File: AnyRoleDirective.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onRender(Env env, Scope scope, Writer writer) { User user = UserInterceptor.getThreadLocalUser(); if (user == null || !user.isStatusOk()) { return; } Set<String> roles = StrUtil.splitToSet(getPara(0, scope), ","); if (roles == null || roles.size() == 0) { throw new IllegalArgumentException("#anyRole(...) argument must not be empty"); } if (roleService.hasAnyRole(user.getId(), roles.toArray(new String[]{}))) { renderBody(env, scope, writer); } }
Example #23
Source File: ArticleSearchPageDirective.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onRender(Env env, Scope scope, Writer writer) { Controller controller = JbootControllerContext.get(); String keyword = controller.getAttr("keyword"); int page = controller.getAttr("page"); int pageSize = getParaToInt("pageSize", scope, 10); Page<Article> dataPage = StrUtil.isNotBlank(keyword) ? articleService.search(keyword, page, pageSize) : null; if (dataPage != null) { scope.setGlobal("articlePage", dataPage); } //需要页面自行判断 articlePage 是否为空 renderBody(env, scope, writer); }
Example #24
Source File: ShiroHasAllPermissionDirective.java From jboot with Apache License 2.0 | 6 votes |
@Override public void onRender(Env env, Scope scope, Writer writer) { if (getSubject() != null && ArrayUtil.isNotEmpty(exprList.getExprArray())) { boolean hasAllPermission = true; for (Expr expr : exprList.getExprArray()) { if (!getSubject().isPermitted(expr.eval(scope).toString())) { hasAllPermission = false; break; } } if (hasAllPermission) { renderBody(env, scope, writer); } } }
Example #25
Source File: ProductTagsDirective.java From jpress with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onRender(Env env, Scope scope, Writer writer) { Long id = getParaToLong(0, scope); if (id == null) { throw new IllegalArgumentException("#productTags(id) args error. id must not be null." + getLocation()); } List<ProductCategory> categories = categoryService.findListByProductId(id, ProductCategory.TYPE_TAG); if (categories == null || categories.isEmpty()) { return; } scope.setLocal("tags", categories); renderBody(env, scope, writer); }
Example #26
Source File: UserArticlesDirective.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void onRender(Env env, Scope scope, Writer writer) { Long userId = getParaToLong("userId", scope); User user = JbootControllerContext.get().getAttr("user"); if (userId == null && user == null) { throw new RuntimeException("#userArticles() args is error,userId must not be null." + getLocation()); } if (userId == null) { userId = user.getId(); } String orderBy = getPara("orderBy", scope, "id desc"); String status = getPara("status", scope, Article.STATUS_NORMAL); int count = getParaToInt("count", scope, 10); Columns columns = Columns.create("user_id", userId); columns.add("status", status); List<Article> articles = service.findListByColumns(columns, orderBy, count); if (articles == null || articles.isEmpty()) { return; } scope.setLocal("articles", articles); renderBody(env, scope, writer); }
Example #27
Source File: PageCommentPageDirective.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected String getUrl(int pageNumber, Env env, Scope scope, Writer writer) { HttpServletRequest request = JbootControllerContext.get().getRequest(); String url = DirectveKit.replacePageNumber(request.getRequestURI(), pageNumber); String anchor = getPara("anchor", scope); return StrUtil.isBlank(anchor) ? url : url + "#" + anchor; }
Example #28
Source File: ProductTagListDirective.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void onRender(Env env, Scope scope, Writer writer) { String orderBy = getPara("orderBy", scope, "id desc"); int count = getParaToInt("count", scope, 10); List<ProductCategory> categories = categoryService.findListByType(ProductCategory.TYPE_TAG, orderBy, count); if (categories == null || categories.isEmpty()) { return; } scope.setLocal("tags", categories); renderBody(env, scope, writer); }
Example #29
Source File: PageCommentPageDirective.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void onRender(Env env, Scope scope, Writer writer) { Controller controller = JbootControllerContext.get(); int page = controller.getParaToInt(1, 1); int pageSize = getParaToInt("pageSize", scope, 10); SinglePage singlePage = controller.getAttr("page"); if (singlePage != null) { Page<SinglePageComment> articlePage = service.paginateByPageIdInNormal(page, pageSize, singlePage.getId()); scope.setGlobal("commentPage", articlePage); renderBody(env, scope, writer); } }
Example #30
Source File: PreviousProductDirective.java From jpress with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void onRender(Env env, Scope scope, Writer writer) { Product product = JbootControllerContext.get().getAttr("product"); Product previousProduct = service.findPreviousById(product.getId()); if (previousProduct == null) { return; } scope.setLocal("previous", previousProduct); renderBody(env, scope, writer); }