cn.hutool.core.text.StrBuilder Java Examples
The following examples show how to use
cn.hutool.core.text.StrBuilder.
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: 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 #2
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 #3
Source File: HaloUtils.java From stone with GNU General Public License v3.0 | 6 votes |
/** * 获取sitemap * * @param posts posts * * @return String */ public static String getSiteMap(List<Post> posts) { Assert.notEmpty(posts, "post mut not be empty"); final StrBuilder head = new StrBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">"); final StrBuilder urlBody = new StrBuilder(); final 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: 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 #5
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 #6
Source File: ApiMetaWeBlog.java From stone with GNU General Public License v3.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 #7
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 #8
Source File: FrontCommentController.java From blog-sharon with Apache License 2.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 { //发送邮件到博主 Map<String, Object> map = new HashMap<>(5); 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 #9
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 #10
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 #11
Source File: ApiMetaWeBlog.java From blog-sharon with Apache License 2.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 #12
Source File: ApiMetaWeBlog.java From blog-sharon with Apache License 2.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 #13
Source File: ApiMetaWeBlog.java From blog-sharon with Apache License 2.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 #14
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 #15
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 #16
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 #17
Source File: ApiMetaWeBlog.java From blog-sharon with Apache License 2.0 | 5 votes |
/** * @param methodCall * @return * @throws Exception */ private Post parsetPost(final JSONObject methodCall) throws Exception { final Post ret = new Post(); final JSONArray params = methodCall.getJSONObject("params").getJSONArray("param"); final JSONObject post = params.getJSONObject(3).getJSONObject("value").getJSONObject("struct"); final JSONArray members = post.getJSONArray("member"); for (int i = 0; i < members.length(); i++) { final JSONObject member = members.getJSONObject(i); final String name = member.getString("name"); if("dateCreated".equals(name)){ final String dateString = member.getJSONObject("value").getString("dateTime.iso8601"); Date date = DateUtil.parseDate(dateString); ret.setPostDate(date); }else if ("title".equals(name)){ ret.setPostTitle(member.getJSONObject("value").getString("string")); }else if("description".equals(name)){ final String content = member.getJSONObject("value").optString("string"); ret.setPostContent(content); ret.setPostContentMd(content); }else if("categories".equals(name)){ final StrBuilder cateBuilder = new StrBuilder(); final JSONObject data = member.getJSONObject("value").getJSONObject("array").getJSONObject("data"); if(0==data.length()){ throw new Exception("At least one category"); } } } return ret; }
Example #18
Source File: CommentController.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.COMMENT_REPLY_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) { try { if (status == 1 && Validator.isEmail(comment.getCommentAuthorEmail())) { Map<String, Object> map = new HashMap<>(6); 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("pageName", post.getPostTitle()); map.put("commentContent", comment.getCommentContent()); map.put("blogUrl", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp())); map.put("blogTitle", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp())); map.put("author", user.getUserDisplayName()); mailService.sendTemplateMail( comment.getCommentAuthorEmail(), "您在" + HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "的评论已审核通过!", map, "common/mail_template/mail_passed.ftl"); } } catch (Exception e) { log.error("Mail server not configured: {}", e.getMessage()); } } }
Example #19
Source File: CommentController.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.COMMENT_REPLY_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) { if (Validator.isEmail(lastComment.getCommentAuthorEmail())) { Map<String, Object> map = new HashMap<>(8); map.put("blogTitle", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_TITLE.getProp())); map.put("commentAuthor", lastComment.getCommentAuthor()); map.put("pageName", lastComment.getPost().getPostTitle()); 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("commentContent", lastComment.getCommentContent()); map.put("replyAuthor", user.getUserDisplayName()); map.put("replyContent", commentContent); map.put("blogUrl", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp())); mailService.sendTemplateMail( lastComment.getCommentAuthorEmail(), "您在" + HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "的评论有了新回复", map, "common/mail_template/mail_reply.ftl"); } } }
Example #20
Source File: HaloUtils.java From blog-sharon with Apache License 2.0 | 5 votes |
/** * 获取备份文件信息 * * @param dir dir * @return List */ public static List<BackupDto> getBackUps(String dir) { StrBuilder srcPathStr = new StrBuilder(System.getProperties().getProperty("user.home")); srcPathStr.append("/halo/backup/"); srcPathStr.append(dir); File srcPath = new File(srcPathStr.toString()); File[] files = srcPath.listFiles(); 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 #21
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 #22
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 #23
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 #24
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 #25
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 #26
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 #27
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 #28
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 #29
Source File: ApiMetaWeBlog.java From stone with GNU General Public License v3.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 #30
Source File: ApiMetaWeBlog.java From stone with GNU General Public License v3.0 | 5 votes |
/** * @param methodCall * @return * @throws Exception */ private Post parsetPost(final JSONObject methodCall) throws Exception { final Post ret = new Post(); final JSONArray params = methodCall.getJSONObject("params").getJSONArray("param"); final JSONObject post = params.getJSONObject(3).getJSONObject("value").getJSONObject("struct"); final JSONArray members = post.getJSONArray("member"); for (int i = 0; i < members.length(); i++) { final JSONObject member = members.getJSONObject(i); final String name = member.getString("name"); if("dateCreated".equals(name)){ final String dateString = member.getJSONObject("value").getString("dateTime.iso8601"); Date date = DateUtil.parseDate(dateString); ret.setPostDate(date); }else if ("title".equals(name)){ ret.setPostTitle(member.getJSONObject("value").getString("string")); }else if("description".equals(name)){ final String content = member.getJSONObject("value").optString("string"); ret.setPostContent(content); ret.setPostContentMd(content); }else if("categories".equals(name)){ final StrBuilder cateBuilder = new StrBuilder(); final JSONObject data = member.getJSONObject("value").getJSONObject("array").getJSONObject("data"); if(0==data.length()){ throw new Exception("At least one category"); } } } return ret; }