Java Code Examples for cn.hutool.core.text.StrBuilder#append()
The following examples show how to use
cn.hutool.core.text.StrBuilder#append() .
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: ThemeController.java From stone with GNU General Public License v3.0 | 6 votes |
/** * 获取模板文件内容 * * @param tplName 模板文件名 * * @return 模板内容 */ @GetMapping(value = "/getTpl", produces = "text/text;charset=UTF-8") @ResponseBody public String getTplContent(@RequestParam("tplName") String tplName) { String tplContent = ""; try { //获取项目根路径 final File basePath = new File(ResourceUtils.getURL("classpath:").getPath()); //获取主题路径 final StrBuilder themePath = new StrBuilder("templates/themes/"); themePath.append(BaseController.THEME); themePath.append("/"); themePath.append(tplName); final File themesPath = new File(basePath.getAbsolutePath(), themePath.toString()); final FileReader fileReader = new FileReader(themesPath); tplContent = fileReader.readString(); } catch (Exception e) { log.error("Get template file error: {}", e.getMessage()); } return tplContent; }
Example 2
Source File: ThemeController.java From stone with GNU General Public License v3.0 | 6 votes |
/** * 保存修改模板 * * @param tplName 模板名称 * @param tplContent 模板内容 * * @return JsonResult */ @PostMapping(value = "/editor/save") @ResponseBody public JsonResult saveTpl(@RequestParam("tplName") String tplName, @RequestParam("tplContent") String tplContent) { if (StrUtil.isBlank(tplContent)) { return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.theme.edit.no-content")); } try { //获取项目根路径 final File basePath = new File(ResourceUtils.getURL("classpath:").getPath()); //获取主题路径 final StrBuilder themePath = new StrBuilder("templates/themes/"); themePath.append(BaseController.THEME); themePath.append("/"); themePath.append(tplName); final File tplPath = new File(basePath.getAbsolutePath(), themePath.toString()); final FileWriter fileWriter = new FileWriter(tplPath); fileWriter.write(tplContent); } catch (Exception e) { log.error("Template save failed: {}", e.getMessage()); return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.common.save-failed")); } return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), localeMessageUtil.getMessage("code.admin.common.save-success")); }
Example 3
Source File: HaloUtils.java From blog-sharon with Apache License 2.0 | 6 votes |
/** * 获取sitemap * * @param posts posts * @return String */ public static String getSiteMap(List<Post> posts) { Assert.notEmpty(posts, "post mut not be empty"); StrBuilder head = new StrBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">"); StrBuilder urlBody = new StrBuilder(); String urlPath = HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/archives/"; for (Post post : posts) { urlBody.append("<url><loc>"); urlBody.append(urlPath); urlBody.append(post.getPostUrl()); urlBody.append("</loc><lastmod>"); urlBody.append(DateUtil.format(post.getPostDate(), "yyyy-MM-dd'T'HH:mm:ss.SSSXXX")); urlBody.append("</lastmod></url>"); } return head.append(urlBody).append("</urlset>").toString(); }
Example 4
Source File: ApiMetaWeBlog.java From blog-sharon with Apache License 2.0 | 6 votes |
/** * 根据文章编号构建文章信息 * * @param postId 文章编号 * @return 文章信息xml格式 */ private String buildPost(final Long postId) { final StrBuilder strBuilder = new StrBuilder(); final Post post = postService.findByPostId(postId).orElse(new Post()); strBuilder.append("<struct>"); strBuilder.append("<member><name>dateCreated</name>"); strBuilder.append("<value><dateTime.iso8601>"); strBuilder.append(DateUtil.format(post.getPostDate(), "yyyy-MM-dd'T'HH:mm:ssZZ")); strBuilder.append("</dateTime.iso8601></value></member>"); strBuilder.append("<member><name>description</name>"); strBuilder.append("<value>"); strBuilder.append(post.getPostSummary()); strBuilder.append("</value></member>"); strBuilder.append("<member><name>title</name>"); strBuilder.append("<value>"); strBuilder.append(post.getPostTitle()); strBuilder.append("</value></member>"); strBuilder.append("<member><name>categories</name>"); strBuilder.append("<value><array><data>"); List<Category> categories = post.getCategories(); for (Category category : categories) { strBuilder.append("<value>").append(category.getCateName()).append("</value>"); } strBuilder.append("</data></array></value></member></struct>"); return strBuilder.toString(); }
Example 5
Source File: ApiMetaWeBlog.java From blog-sharon with Apache License 2.0 | 6 votes |
/** * 构建分类信息 * * @return 分类信息xml节点 * @throws Exception Exception */ private String buildCategories() throws Exception { final StrBuilder strBuilder = new StrBuilder(); final List<Category> categories = categoryService.findAll(); for (Category category : categories) { final String cateName = category.getCateName(); final Long cateId = category.getCateId(); strBuilder.append("<value><struct>"); strBuilder.append("<member><name>description</name>").append("<value>").append(cateName).append("</value></member>"); strBuilder.append("<member><name>title</name>").append("<value>").append(cateName).append("</value></member>"); strBuilder.append("<member><name>categoryid</name>").append("<value>").append(cateId).append("</value></member>"); strBuilder.append("<member><name>htmlUrl</name>").append("<value>").append(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp())).append("/categories/").append(cateName).append("</value></member>"); strBuilder.append("</struct></value>"); } return strBuilder.toString(); }
Example 6
Source File: FrontCommentController.java From stone with GNU General Public License v3.0 | 6 votes |
@Override public void run() { if (StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getDesc()) && StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) { try { //发送邮件到博主 final Map<String, Object> map = new HashMap<>(5); final StrBuilder pageUrl = new StrBuilder(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp())); if (StrUtil.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) { pageUrl.append("/archives/"); } else { pageUrl.append("/p/"); } pageUrl.append(post.getPostUrl()); pageUrl.append("#comment-id-"); pageUrl.append(comment.getCommentId()); map.put("pageUrl", pageUrl.toString()); map.put("author", userService.findUser().getUserDisplayName()); map.put("pageName", post.getPostTitle()); map.put("visitor", comment.getCommentAuthor()); map.put("commentContent", comment.getCommentContent()); mailService.sendTemplateMail(userService.findUser().getUserEmail(), "有新的评论", map, "common/mail_template/mail_admin.ftl"); } catch (Exception e) { log.error("Mail server not configured: {}", e.getMessage()); } } }
Example 7
Source File: ApiMetaWeBlog.java From stone with GNU General Public License v3.0 | 6 votes |
/** * 构建分类信息 * * @return 分类信息xml节点 * @throws Exception Exception */ private String buildCategories() throws Exception { final StrBuilder strBuilder = new StrBuilder(); final List<Category> categories = categoryService.findAll(); for (Category category : categories) { final String cateName = category.getCateName(); final Long cateId = category.getCateId(); strBuilder.append("<value><struct>"); strBuilder.append("<member><name>description</name>").append("<value>").append(cateName).append("</value></member>"); strBuilder.append("<member><name>title</name>").append("<value>").append(cateName).append("</value></member>"); strBuilder.append("<member><name>categoryid</name>").append("<value>").append(cateId).append("</value></member>"); strBuilder.append("<member><name>htmlUrl</name>").append("<value>").append(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp())).append("/categories/").append(cateName).append("</value></member>"); strBuilder.append("</struct></value>"); } return strBuilder.toString(); }
Example 8
Source File: ApiMetaWeBlog.java From stone with GNU General Public License v3.0 | 5 votes |
/** * 组装分类信息 * * @return 分类信息xml格式 * @throws Exception Exception */ private String getCategories() throws Exception { final StrBuilder strBuilder = new StrBuilder( "<?xml version=\"1.0\" encoding=\"UTF-8\"?><methodResponse><params><param><value><array><data>"); final String categories = buildCategories(); strBuilder.append(categories); strBuilder.append("</data></array></value></param></params></methodResponse>"); return strBuilder.toString(); }
Example 9
Source File: HaloUtils.java From stone with GNU General Public License v3.0 | 5 votes |
/** * 获取备份文件信息 * * @param dir dir * * @return List */ public static List<BackupDto> getBackUps(String dir) { final StrBuilder srcPathStr = new StrBuilder(System.getProperties().getProperty("user.home")); srcPathStr.append("/halo/backup/"); srcPathStr.append(dir); final File srcPath = new File(srcPathStr.toString()); final File[] files = srcPath.listFiles(); final List<BackupDto> backupDtos = new ArrayList<>(); BackupDto backupDto = null; // 遍历文件 if (null != files) { for (File file : files) { if (file.isFile()) { if (StrUtil.equals(file.getName(), ".DS_Store")) { continue; } backupDto = new BackupDto(); backupDto.setFileName(file.getName()); backupDto.setCreateAt(getCreateTime(file.getAbsolutePath())); backupDto.setFileType(FileUtil.getType(file)); backupDto.setFileSize(parseSize(file.length())); backupDto.setBackupType(dir); backupDtos.add(backupDto); } } } return backupDtos; }
Example 10
Source File: Md5Util.java From stone with GNU General Public License v3.0 | 5 votes |
/** * 生成文件hash值 * * @param file file * * @return String * * @throws Exception Exception */ public static String getMD5Checksum(MultipartFile file) throws Exception { final byte[] b = createChecksum(file); StrBuilder result = new StrBuilder(); for (int i = 0; i < b.length; i++) { result.append(Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1)); } return result.toString(); }
Example 11
Source File: BaseController.java From stone with GNU General Public License v3.0 | 5 votes |
/** * 根据主题名称渲染页面 * * @param pageName pageName * @return 返回拼接好的模板路径 */ public String render(String pageName) { final StrBuilder themeStr = new StrBuilder("themes/"); themeStr.append(THEME); themeStr.append("/"); return themeStr.append(pageName).toString(); }
Example 12
Source File: FrontCommentController.java From stone with GNU General Public License v3.0 | 5 votes |
@Override public void run() { //发送通知给对方 if (StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getDesc()) && StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) { if (Validator.isEmail(lastComment.getCommentAuthorEmail())) { final Map<String, Object> map = new HashMap<>(8); final StrBuilder pageUrl = new StrBuilder(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp())); if (StrUtil.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) { pageUrl.append("/archives/"); } else { pageUrl.append("/p/"); } pageUrl.append(post.getPostUrl()); pageUrl.append("#comment-id-"); pageUrl.append(comment.getCommentId()); map.put("pageUrl", pageUrl.toString()); map.put("blogTitle", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp())); map.put("commentAuthor", lastComment.getCommentAuthor()); map.put("pageName", lastComment.getPost().getPostTitle()); map.put("commentContent", lastComment.getCommentContent()); map.put("replyAuthor", comment.getCommentAuthor()); map.put("replyContent", comment.getCommentContent()); map.put("blogUrl", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp())); mailService.sendTemplateMail( lastComment.getCommentAuthorEmail(), "您在" + HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp()) + "的评论有了新回复", map, "common/mail_template/mail_reply.ftl"); } } }
Example 13
Source File: ApiMetaWeBlog.java From blog-sharon with Apache License 2.0 | 5 votes |
/** * 根据文章编号获取文章信息 * * @param postId 文章编号 * @return 文章信息xml格式 */ private String getPost(Long postId) { final StrBuilder strBuilder = new StrBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?><methodResponse><params><param><value>"); final String posts = buildPost(postId); strBuilder.append(posts); strBuilder.append("</value></param></params></methodResponse>"); return strBuilder.toString(); }
Example 14
Source File: Md5Util.java From SENS with GNU General Public License v3.0 | 5 votes |
/** * 生成文件hash值 * * @param file file * @return String * @throws Exception Exception */ public static String getMD5Checksum(MultipartFile file) throws Exception { final byte[] b = createChecksum(file); StrBuilder result = new StrBuilder(); for (int i = 0; i < b.length; i++) { result.append(Integer.toString((b[i] & 0xff) + 0x100, 16).substring(1)); } return result.toString(); }
Example 15
Source File: ApiMetaWeBlog.java From stone with GNU General Public License v3.0 | 5 votes |
/** * 构建博客信息 * * @return 博客信息xml节点 */ private String buildBlogInfo() { final String blogId = HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()); final String blogTitle = HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp()); final StrBuilder strBuilder = new StrBuilder("<member><name>blogid</name><value>"); strBuilder.append(blogId); strBuilder.append("</value></member>"); strBuilder.append("<member><name>url</name><value>"); strBuilder.append(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp())); strBuilder.append("</value></member>"); strBuilder.append("<member><name>blogName</name><value>"); strBuilder.append(blogTitle); strBuilder.append("</value></member>"); return strBuilder.toString(); }
Example 16
Source File: ApiMetaWeBlog.java From stone with GNU General Public License v3.0 | 5 votes |
/** * 获取用户博客信息 * * @return 用户博客信息xml格式 */ private String getUserBlogs() { final StrBuilder strBuilder = new StrBuilder( "<?xml version=\"1.0\" encoding=\"UTF-8\"?><methodResponse><params><param><value><array><data><value><struct>"); final String blogInfo = buildBlogInfo(); strBuilder.append(blogInfo); strBuilder.append("</struct></value></data></array></value></param></params></methodResponse>"); return strBuilder.toString(); }
Example 17
Source File: FrontCommentController.java From blog-sharon with Apache License 2.0 | 5 votes |
@Override public void run() { //发送通知给对方 if (StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getDesc()) && StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) { if (Validator.isEmail(lastComment.getCommentAuthorEmail())) { Map<String, Object> map = new HashMap<>(8); StrBuilder pageUrl = new StrBuilder(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp())); if (StrUtil.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) { pageUrl.append("/archives/"); } else { pageUrl.append("/p/"); } pageUrl.append(post.getPostUrl()); pageUrl.append("#comment-id-"); pageUrl.append(comment.getCommentId()); map.put("pageUrl", pageUrl.toString()); map.put("blogTitle", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp())); map.put("commentAuthor", lastComment.getCommentAuthor()); map.put("pageName", lastComment.getPost().getPostTitle()); map.put("commentContent", lastComment.getCommentContent()); map.put("replyAuthor", comment.getCommentAuthor()); map.put("replyContent", comment.getCommentContent()); map.put("blogUrl", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp())); mailService.sendTemplateMail( lastComment.getCommentAuthorEmail(), "您在" + HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp()) + "的评论有了新回复", map, "common/mail_template/mail_reply.ftl"); } } }
Example 18
Source File: BaseController.java From blog-sharon with Apache License 2.0 | 5 votes |
/** * 根据主题名称渲染页面 * * @param pageName pageName * @return 返回拼接好的模板路径 */ public String render(String pageName) { StrBuilder themeStr = new StrBuilder("themes/"); themeStr.append(THEME); themeStr.append("/"); return themeStr.append(pageName).toString(); }
Example 19
Source File: BaseController.java From mayday with GNU General Public License v3.0 | 5 votes |
/** * 根据主题名称渲染页面 * * @param pageName * pageName * @return 返回拼接好的模板路径 */ public String render(String pageName) { //加载主题 if(MaydayConst.THEME_NAME!=null) { THEME=MaydayConst.THEME_NAME; } StrBuilder themeStr = new StrBuilder("themes/"); themeStr.append(THEME); themeStr.append("/"); return themeStr.append(pageName).toString(); }
Example 20
Source File: CommentController.java From blog-sharon with Apache License 2.0 | 4 votes |
/** * 管理员回复评论 * * @param commentId 被回复的评论 * @param commentContent 回复的内容 * @return JsonResult */ @PostMapping(value = "/reply") @ResponseBody public JsonResult replyComment(@RequestParam("commentId") Long commentId, @RequestParam("postId") Long postId, @RequestParam("commentContent") String commentContent, @RequestParam("userAgent") String userAgent, HttpServletRequest request, HttpSession session) { try { Post post = postService.findByPostId(postId).orElse(new Post()); //博主信息 User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY); //被回复的评论 Comment lastComment = commentService.findCommentById(commentId).orElse(new Comment()); //修改被回复的评论的状态 lastComment.setCommentStatus(CommentStatusEnum.PUBLISHED.getCode()); commentService.save(lastComment); //保存评论 Comment comment = new Comment(); comment.setPost(post); comment.setCommentAuthor(user.getUserDisplayName()); comment.setCommentAuthorEmail(user.getUserEmail()); comment.setCommentAuthorUrl(HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp())); comment.setCommentAuthorIp(ServletUtil.getClientIP(request)); comment.setCommentAuthorAvatarMd5(SecureUtil.md5(user.getUserEmail())); comment.setCommentDate(DateUtil.date()); StrBuilder buildContent = new StrBuilder("<a href='#comment-id-"); buildContent.append(lastComment.getCommentId()); buildContent.append("'>@"); buildContent.append(lastComment.getCommentAuthor()); buildContent.append("</a> "); buildContent.append(OwoUtil.markToImg(HtmlUtil.escape(commentContent).replace("<br/>", "<br/>"))); comment.setCommentContent(buildContent.toString()); comment.setCommentAgent(userAgent); comment.setCommentParent(commentId); comment.setCommentStatus(CommentStatusEnum.PUBLISHED.getCode()); comment.setIsAdmin(1); commentService.save(comment); //邮件通知 new EmailToAuthor(comment, lastComment, post, user, commentContent).start(); return new JsonResult(ResultCodeEnum.SUCCESS.getCode()); } catch (Exception e) { log.error("Reply to comment failed: {}", e.getMessage()); return new JsonResult(ResultCodeEnum.FAIL.getCode()); } }