From 036b17f57df455a3c615c435ab3b97df96ca43b6 Mon Sep 17 00:00:00 2001 From: ruibaby Date: Sat, 29 Sep 2018 22:49:12 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E7=A7=BB=E9=99=A4Apache=20common=20Lan?= =?UTF-8?q?g3=E5=8C=85=EF=BC=8C=E6=94=B9=E7=94=A8Hutool?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README-en-US.md | 3 --- README.md | 3 --- pom.xml | 10 +-------- .../java/cc/ryanc/halo/config/MvcConfig.java | 10 +++++++++ .../cc/ryanc/halo/config/StartupConfig.java | 4 ++-- .../halo/service/impl/OptionsServiceImpl.java | 6 +++--- .../java/cc/ryanc/halo/utils/HaloUtils.java | 6 +++--- .../web/controller/admin/AdminController.java | 4 ++-- .../admin/AttachmentController.java | 4 ++-- .../controller/admin/BackupController.java | 18 ++++++++-------- .../controller/admin/CommentController.java | 10 ++++----- .../web/controller/admin/PageController.java | 6 +++--- .../web/controller/admin/PostController.java | 21 ++++++++++--------- .../web/controller/admin/ThemeController.java | 8 +++---- .../web/controller/api/ApiPostController.java | 4 ++-- .../controller/core/InstallController.java | 8 +++---- .../front/FrontArchiveController.java | 6 +++--- .../front/FrontCategoryController.java | 4 ++-- .../front/FrontCommentController.java | 18 ++++++++-------- .../front/FrontIndexController.java | 6 +++--- .../front/FrontOthersController.java | 4 ++-- .../controller/front/FrontPageController.java | 6 +++--- .../controller/front/FrontTagController.java | 4 ++-- .../halo/web/interceptor/ApiInterceptor.java | 4 ++-- .../web/interceptor/InstallInterceptor.java | 4 ++-- .../web/interceptor/LocaleInterceptor.java | 4 ++-- .../resources/templates/common/install.ftl | 13 +++++++++--- 27 files changed, 101 insertions(+), 97 deletions(-) diff --git a/README-en-US.md b/README-en-US.md index 8da44c007..e7b19a999 100755 --- a/README-en-US.md +++ b/README-en-US.md @@ -108,15 +108,12 @@ The birth of Halo is inseparable from the following projects: - [Spring-data-jpa](https://github.com/spring-projects/spring-data-jpa.git):Do not need to write a sql script persistence layer framework. - [Ehcache](http://www.ehcache.org/):Cache framework. - [Lombok](https://www.projectlombok.org/):Make the code simpler. -- [Apache Commons](http://commons.apache.org/):Very easy to use Java tool library. - [oh-my-email](https://github.com/biezhi/oh-my-email):Probably the smallest Java mailing library, support for CC, attachments, templates, etc. - [Hutool](https://github.com/looly/hutool):A Java base tool library. - [Thumbnailator](https://github.com/coobird/thumbnailator):Thumbnail generation library. - [AdminLTE](https://github.com/almasaeed2010/AdminLTE):Background template based on Bootstrap. - [Bootstrap](https://github.com/twbs/bootstrap.git):Use the most extensive front-end ui framework. - [Animate](https://github.com/daneden/animate.css.git):Very easy to use css motion library. -- [Editor.md](https://github.com/pandao/editor.md.git):Markdown front-end editor, sorry for the author abandoned. -- [Editor.md](https://github.com/hawtim/editor.md):Editor.md, the version that hawtim took over to maintain. - [SimpleMDE - Markdown Editor](https://github.com/sparksuite/simplemde-markdown-editor):Simple, functional, and lightweight Markdown editor. - [Bootstrap-FileInput](https://github.com/kartik-v/bootstrap-fileinput.git):Personally think that the best upload component. - [Font-awesome](https://github.com/FortAwesome/Font-Awesome.git):The most widely used font icon library. diff --git a/README.md b/README.md index b80cc6e0d..e0e135c05 100755 --- a/README.md +++ b/README.md @@ -110,15 +110,12 @@ Halo的诞生离不开下面这些项目: - [Spring-data-jpa](https://github.com/spring-projects/spring-data-jpa.git):不需要写sql语句的持久层框架 - [Ehcache](http://www.ehcache.org/):缓存框架 - [Lombok](https://www.projectlombok.org/):让代码更简洁 -- [Apache Commons](http://commons.apache.org/):非常好用的Java工具库 - [oh-my-email](https://github.com/biezhi/oh-my-email):可能是最小的Java邮件发送库了,支持抄送、附件、模板等 - [Hutool](https://github.com/looly/hutool):一个Java基础工具类库 - [Thumbnailator](https://github.com/coobird/thumbnailator):缩略图生成库 - [AdminLTE](https://github.com/almasaeed2010/AdminLTE):基于Bootstrap的后台模板 - [Bootstrap](https://github.com/twbs/bootstrap.git):使用最广泛的前端ui框架 - [Animate](https://github.com/daneden/animate.css.git):非常好用的css动效库 -- [Editor.md](https://github.com/pandao/editor.md.git):Markdown前端编辑器,遗憾作者弃坑了 -- [Editor.md](https://github.com/hawtim/editor.md):Editor.md,hawtim接过来维护的版本 - [SimpleMDE - Markdown Editor](https://github.com/sparksuite/simplemde-markdown-editor):简洁,功能够用,且轻量级的Markdown编辑器 - [Bootstrap-FileInput](https://github.com/kartik-v/bootstrap-fileinput.git):个人认为最好用的上传组件,没有之一 - [Font-awesome](https://github.com/FortAwesome/Font-Awesome.git):使用最广泛的字体图标库 diff --git a/pom.xml b/pom.xml index a5feece52..f24bd022f 100755 --- a/pom.xml +++ b/pom.xml @@ -36,8 +36,7 @@ 1.18.2 3.6.0 1.0 - 3.8 - 4.1.13 + 4.1.14 4.0.1 7.2.14 0.4.8 @@ -136,13 +135,6 @@ ${rome.version} - - - org.apache.commons - commons-lang3 - ${commons-lang3.version} - - cn.hutool diff --git a/src/main/java/cc/ryanc/halo/config/MvcConfig.java b/src/main/java/cc/ryanc/halo/config/MvcConfig.java index 5993fb080..0be5174aa 100644 --- a/src/main/java/cc/ryanc/halo/config/MvcConfig.java +++ b/src/main/java/cc/ryanc/halo/config/MvcConfig.java @@ -12,6 +12,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import org.springframework.web.servlet.LocaleResolver; import org.springframework.web.servlet.config.annotation.*; +import org.springframework.web.servlet.i18n.LocaleChangeInterceptor; import org.springframework.web.servlet.i18n.SessionLocaleResolver; import java.util.Locale; @@ -66,6 +67,8 @@ public class MvcConfig implements WebMvcConfigurer { registry.addInterceptor(localeInterceptor) .addPathPatterns("/admin/**") .addPathPatterns("/install"); + registry.addInterceptor(localeChangeInterceptor()) + .addPathPatterns("/install"); } /** @@ -103,4 +106,11 @@ public class MvcConfig implements WebMvcConfigurer { slr.setDefaultLocale(Locale.CHINA); return slr; } + + @Bean + public LocaleChangeInterceptor localeChangeInterceptor() { + LocaleChangeInterceptor lci = new LocaleChangeInterceptor(); + lci.setParamName("lang"); + return lci; + } } diff --git a/src/main/java/cc/ryanc/halo/config/StartupConfig.java b/src/main/java/cc/ryanc/halo/config/StartupConfig.java index 802d19196..a42c61ac0 100755 --- a/src/main/java/cc/ryanc/halo/config/StartupConfig.java +++ b/src/main/java/cc/ryanc/halo/config/StartupConfig.java @@ -6,10 +6,10 @@ import cc.ryanc.halo.model.enums.BlogPropertiesEnum; import cc.ryanc.halo.service.OptionsService; import cc.ryanc.halo.utils.HaloUtils; import cc.ryanc.halo.web.controller.core.BaseController; +import cn.hutool.core.util.StrUtil; import cn.hutool.cron.CronUtil; import freemarker.template.TemplateModelException; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.event.ApplicationStartedEvent; import org.springframework.context.ApplicationListener; @@ -57,7 +57,7 @@ public class StartupConfig implements ApplicationListener attachments = attachmentService.findAllAttachments(pageable); model.addAttribute("attachments", attachments); model.addAttribute("id", id); - if (StringUtils.equals(type, PostTypeEnum.POST_TYPE_POST.getDesc())) { + if (StrUtil.equals(type, PostTypeEnum.POST_TYPE_POST.getDesc())) { return "admin/widget/_attachment-select-post"; } return "admin/widget/_attachment-select"; diff --git a/src/main/java/cc/ryanc/halo/web/controller/admin/BackupController.java b/src/main/java/cc/ryanc/halo/web/controller/admin/BackupController.java index cdd000554..1592ddab8 100644 --- a/src/main/java/cc/ryanc/halo/web/controller/admin/BackupController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/admin/BackupController.java @@ -12,9 +12,9 @@ import cc.ryanc.halo.utils.HaloUtils; import cc.ryanc.halo.utils.LocaleMessageUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.ZipUtil; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -63,11 +63,11 @@ public class BackupController { @GetMapping public String backup(@RequestParam(value = "type", defaultValue = "resources") String type, Model model) { List backups = null; - if (StringUtils.equals(type, BackupTypeEnum.RESOURCES.getDesc())) { + if (StrUtil.equals(type, BackupTypeEnum.RESOURCES.getDesc())) { backups = HaloUtils.getBackUps(BackupTypeEnum.RESOURCES.getDesc()); - } else if (StringUtils.equals(type, BackupTypeEnum.DATABASES.getDesc())) { + } else if (StrUtil.equals(type, BackupTypeEnum.DATABASES.getDesc())) { backups = HaloUtils.getBackUps(BackupTypeEnum.DATABASES.getDesc()); - } else if (StringUtils.equals(type, BackupTypeEnum.POSTS.getDesc())) { + } else if (StrUtil.equals(type, BackupTypeEnum.POSTS.getDesc())) { backups = HaloUtils.getBackUps(BackupTypeEnum.POSTS.getDesc()); } else { backups = new ArrayList<>(); @@ -86,11 +86,11 @@ public class BackupController { @GetMapping(value = "doBackup") @ResponseBody public JsonResult doBackup(@RequestParam("type") String type) { - if (StringUtils.equals(BackupTypeEnum.RESOURCES.getDesc(), type)) { + if (StrUtil.equals(BackupTypeEnum.RESOURCES.getDesc(), type)) { return this.backupResources(); - } else if (StringUtils.equals(BackupTypeEnum.DATABASES.getDesc(), type)) { + } else if (StrUtil.equals(BackupTypeEnum.DATABASES.getDesc(), type)) { return this.backupDatabase(); - } else if (StringUtils.equals(BackupTypeEnum.POSTS.getDesc(), type)) { + } else if (StrUtil.equals(BackupTypeEnum.POSTS.getDesc(), type)) { return this.backupPosts(); } else { return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.backup.backup-failed")); @@ -205,10 +205,10 @@ public class BackupController { HttpSession session) { String srcPath = System.getProperties().getProperty("user.home") + "/halo/backup/" + type + "/" + fileName; User user = (User) session.getAttribute(HaloConst.USER_SESSION_KEY); - if (null == user.getUserEmail() || StringUtils.equals(user.getUserEmail(), "")) { + if (null == user.getUserEmail() || StrUtil.equals(user.getUserEmail(), "")) { return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.backup.no-email")); } - if (StringUtils.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.FALSE.getDesc())) { + if (StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.FALSE.getDesc())) { return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.common.no-post")); } new EmailToAdmin(srcPath, user).start(); diff --git a/src/main/java/cc/ryanc/halo/web/controller/admin/CommentController.java b/src/main/java/cc/ryanc/halo/web/controller/admin/CommentController.java index d813c947c..8851dbc82 100755 --- a/src/main/java/cc/ryanc/halo/web/controller/admin/CommentController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/admin/CommentController.java @@ -15,11 +15,11 @@ import cc.ryanc.halo.utils.OwoUtil; import cc.ryanc.halo.web.controller.core.BaseController; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Validator; +import cn.hutool.core.util.StrUtil; import cn.hutool.crypto.SecureUtil; import cn.hutool.extra.servlet.ServletUtil; import cn.hutool.http.HtmlUtil; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -218,13 +218,13 @@ public class CommentController extends BaseController { @Override public void run() { - if (StringUtils.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getDesc()) && StringUtils.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.COMMENT_REPLY_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) { + 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 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()); - if (StringUtils.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) { + if (StrUtil.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) { map.put("pageUrl", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/archives/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId()); } else { map.put("pageUrl", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/p/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId()); @@ -259,11 +259,11 @@ public class CommentController extends BaseController { @Override public void run() { - if (StringUtils.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getDesc()) && StringUtils.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.COMMENT_REPLY_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) { + 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 map = new HashMap<>(6); - if (StringUtils.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) { + if (StrUtil.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) { map.put("pageUrl", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/archives/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId()); } else { map.put("pageUrl", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/p/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId()); diff --git a/src/main/java/cc/ryanc/halo/web/controller/admin/PageController.java b/src/main/java/cc/ryanc/halo/web/controller/admin/PageController.java index 286e2f4c2..c2de7d947 100755 --- a/src/main/java/cc/ryanc/halo/web/controller/admin/PageController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/admin/PageController.java @@ -14,9 +14,9 @@ import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.utils.LocaleMessageUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.RandomUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.extra.servlet.ServletUtil; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -159,7 +159,7 @@ public class PageController { @PostMapping(value = "/gallery/save") public String saveGallery(@ModelAttribute Gallery gallery) { try { - if (StringUtils.isEmpty(gallery.getGalleryThumbnailUrl())) { + if (StrUtil.isEmpty(gallery.getGalleryThumbnailUrl())) { gallery.setGalleryThumbnailUrl(gallery.getGalleryUrl()); } galleryService.saveByGallery(gallery); @@ -238,7 +238,7 @@ public class PageController { post.setPostUpdate(DateUtil.date()); } //当没有选择文章缩略图的时候,自动分配一张内置的缩略图 - if (StringUtils.equals(post.getPostThumbnail(), BlogPropertiesEnum.DEFAULT_THUMBNAIL.getProp())) { + if (StrUtil.equals(post.getPostThumbnail(), BlogPropertiesEnum.DEFAULT_THUMBNAIL.getProp())) { post.setPostThumbnail("/static/images/thumbnail/thumbnail-" + RandomUtil.randomInt(1, 10) + ".jpg"); } postService.saveByPost(post); diff --git a/src/main/java/cc/ryanc/halo/web/controller/admin/PostController.java b/src/main/java/cc/ryanc/halo/web/controller/admin/PostController.java index ab62cd791..6872a2308 100755 --- a/src/main/java/cc/ryanc/halo/web/controller/admin/PostController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/admin/PostController.java @@ -17,10 +17,11 @@ import cc.ryanc.halo.utils.LocaleMessageUtil; import cc.ryanc.halo.web.controller.core.BaseController; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.RandomUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.extra.servlet.ServletUtil; import cn.hutool.http.HtmlUtil; +import com.alibaba.druid.util.StringUtils; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -80,7 +81,7 @@ public class PostController extends BaseController { return url.substring(0, url.lastIndexOf(".")); } } - return StringUtils.replaceAll(url, " ", "-"); + return StrUtil.replace(url, " ", "-"); } /** @@ -172,7 +173,7 @@ public class PostController extends BaseController { try { //提取摘要 int postSummary = 50; - if (StringUtils.isNotEmpty(HaloConst.OPTIONS.get(BlogPropertiesEnum.POST_SUMMARY.getProp()))) { + if (StrUtil.isNotEmpty(HaloConst.OPTIONS.get(BlogPropertiesEnum.POST_SUMMARY.getProp()))) { postSummary = Integer.parseInt(HaloConst.OPTIONS.get(BlogPropertiesEnum.POST_SUMMARY.getProp())); } //文章摘要 @@ -197,13 +198,13 @@ public class PostController extends BaseController { post.setUser(user); List categories = categoryService.strListToCateList(cateList); post.setCategories(categories); - if (StringUtils.isNotEmpty(tagList)) { - List tags = tagService.strListToTagList(StringUtils.deleteWhitespace(tagList)); + if (StrUtil.isNotEmpty(tagList)) { + List tags = tagService.strListToTagList(StrUtil.trim(tagList)); post.setTags(tags); } post.setPostUrl(urlFilter(post.getPostUrl())); //当没有选择文章缩略图的时候,自动分配一张内置的缩略图 - if (StringUtils.equals(post.getPostThumbnail(), BlogPropertiesEnum.DEFAULT_THUMBNAIL.getProp())) { + if (StrUtil.equals(post.getPostThumbnail(), BlogPropertiesEnum.DEFAULT_THUMBNAIL.getProp())) { post.setPostThumbnail("/static/images/thumbnail/thumbnail-" + RandomUtil.randomInt(1, 10) + ".jpg"); } postService.saveByPost(post); @@ -243,13 +244,13 @@ public class PostController extends BaseController { post = postService.findByPostId(postId).get(); } try { - if (StringUtils.isEmpty(postTitle)) { + if (StrUtil.isBlank(postTitle)) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); post.setPostTitle("草稿:" + dateFormat.format(DateUtil.date())); } else { post.setPostTitle(postTitle); } - if (StringUtils.isEmpty(postUrl)) { + if (StrUtil.isBlank(postUrl)) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); post.setPostUrl(dateFormat.format(DateUtil.date())); } else { @@ -320,7 +321,7 @@ public class PostController extends BaseController { } catch (Exception e) { log.error("删除文章失败:{}", e.getMessage()); } - if (StringUtils.equals(PostTypeEnum.POST_TYPE_POST.getDesc(), postType)) { + if (StrUtil.equals(PostTypeEnum.POST_TYPE_POST.getDesc(), postType)) { return "redirect:/admin/posts?status=2"; } return "redirect:/admin/page"; @@ -385,7 +386,7 @@ public class PostController extends BaseController { @GetMapping(value = "/pushAllToBaidu") @ResponseBody public JsonResult pushAllToBaidu(@RequestParam("baiduToken") String baiduToken) { - if (StringUtils.isEmpty(baiduToken)) { + if (StrUtil.isBlank(baiduToken)) { return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.post.no-baidu-token")); } String blogUrl = HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()); diff --git a/src/main/java/cc/ryanc/halo/web/controller/admin/ThemeController.java b/src/main/java/cc/ryanc/halo/web/controller/admin/ThemeController.java index 38ab40666..57831c900 100755 --- a/src/main/java/cc/ryanc/halo/web/controller/admin/ThemeController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/admin/ThemeController.java @@ -17,11 +17,11 @@ import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.file.FileReader; import cn.hutool.core.io.file.FileWriter; import cn.hutool.core.util.RuntimeUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.ZipUtil; import cn.hutool.extra.servlet.ServletUtil; import freemarker.template.Configuration; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.annotation.CacheEvict; import org.springframework.stereotype.Controller; @@ -185,7 +185,7 @@ public class ThemeController extends BaseController { @ResponseBody public JsonResult cloneFromRemote(@RequestParam(value = "remoteAddr") String remoteAddr, @RequestParam(value = "themeName") String themeName) { - if (StringUtils.isBlank(remoteAddr) || StringUtils.isBlank(themeName)) { + if (StrUtil.isBlank(remoteAddr) || StrUtil.isBlank(themeName)) { return new JsonResult(0, localeMessageUtil.getMessage("code.admin.common.info-no-complete")); } try { @@ -239,7 +239,7 @@ public class ThemeController extends BaseController { @RequestParam("theme") String theme, @RequestParam("hasUpdate") String hasUpdate) { model.addAttribute("themeDir", theme); - if (StringUtils.equals(hasUpdate, TrueFalseEnum.TRUE.getDesc())) { + if (StrUtil.equals(hasUpdate, TrueFalseEnum.TRUE.getDesc())) { model.addAttribute("hasUpdate", true); } else { model.addAttribute("hasUpdate", false); @@ -294,7 +294,7 @@ public class ThemeController extends BaseController { @ResponseBody public JsonResult saveTpl(@RequestParam("tplName") String tplName, @RequestParam("tplContent") String tplContent) { - if (StringUtils.isBlank(tplContent)) { + if (StrUtil.isBlank(tplContent)) { return new JsonResult(ResultCodeEnum.FAIL.getCode(), localeMessageUtil.getMessage("code.admin.theme.edit.no-content")); } try { diff --git a/src/main/java/cc/ryanc/halo/web/controller/api/ApiPostController.java b/src/main/java/cc/ryanc/halo/web/controller/api/ApiPostController.java index 1e66da75a..29cf3fb30 100644 --- a/src/main/java/cc/ryanc/halo/web/controller/api/ApiPostController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/api/ApiPostController.java @@ -8,7 +8,7 @@ import cc.ryanc.halo.model.enums.PostStatusEnum; import cc.ryanc.halo.model.enums.PostTypeEnum; import cc.ryanc.halo.model.enums.ResponseStatusEnum; import cc.ryanc.halo.service.PostService; -import org.apache.commons.lang3.StringUtils; +import cn.hutool.core.util.StrUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -46,7 +46,7 @@ public class ApiPostController { public JsonResult posts(@PathVariable(value = "page") Integer page) { Sort sort = new Sort(Sort.Direction.DESC, "postDate"); Integer size = 10; - if (!StringUtils.isBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()))) { + if (StrUtil.isNotBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()))) { size = Integer.parseInt(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp())); } Pageable pageable = PageRequest.of(page - 1, size, sort); diff --git a/src/main/java/cc/ryanc/halo/web/controller/core/InstallController.java b/src/main/java/cc/ryanc/halo/web/controller/core/InstallController.java index f29999019..7b4eb60fc 100644 --- a/src/main/java/cc/ryanc/halo/web/controller/core/InstallController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/core/InstallController.java @@ -9,11 +9,11 @@ import cc.ryanc.halo.model.enums.TrueFalseEnum; import cc.ryanc.halo.service.*; import cc.ryanc.halo.utils.HaloUtils; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.StrUtil; import cn.hutool.crypto.SecureUtil; import cn.hutool.extra.servlet.ServletUtil; import freemarker.template.Configuration; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -69,7 +69,7 @@ public class InstallController { @GetMapping public String install(Model model) { try { - if (StringUtils.equals(TrueFalseEnum.TRUE.getDesc(), HaloConst.OPTIONS.get(BlogPropertiesEnum.IS_INSTALL.getProp()))) { + if (StrUtil.equals(TrueFalseEnum.TRUE.getDesc(), HaloConst.OPTIONS.get(BlogPropertiesEnum.IS_INSTALL.getProp()))) { model.addAttribute("isInstall", true); } else { model.addAttribute("isInstall", false); @@ -104,13 +104,13 @@ public class InstallController { @RequestParam("userPwd") String userPwd, HttpServletRequest request) { try { - if (StringUtils.equals(TrueFalseEnum.TRUE.getDesc(), HaloConst.OPTIONS.get(BlogPropertiesEnum.IS_INSTALL.getProp()))) { + if (StrUtil.equals(TrueFalseEnum.TRUE.getDesc(), HaloConst.OPTIONS.get(BlogPropertiesEnum.IS_INSTALL.getProp()))) { return false; } //创建新的用户 User user = new User(); user.setUserName(userName); - if (StringUtils.isBlank(userDisplayName)) { + if (StrUtil.isBlank(userDisplayName)) { userDisplayName = userName; } user.setUserDisplayName(userDisplayName); diff --git a/src/main/java/cc/ryanc/halo/web/controller/front/FrontArchiveController.java b/src/main/java/cc/ryanc/halo/web/controller/front/FrontArchiveController.java index a8c1c5da6..8af254e9b 100644 --- a/src/main/java/cc/ryanc/halo/web/controller/front/FrontArchiveController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/front/FrontArchiveController.java @@ -12,8 +12,8 @@ import cc.ryanc.halo.utils.CommentUtil; import cc.ryanc.halo.web.controller.core.BaseController; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.PageUtil; +import cn.hutool.core.util.StrUtil; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -133,7 +133,7 @@ public class FrontArchiveController extends BaseController { model.addAttribute("afterPost", afterPosts.get(afterPosts.size() - 1)); } List comments = null; - if (StringUtils.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NEED_CHECK.getProp()), TrueFalseEnum.TRUE.getDesc()) || HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NEED_CHECK.getProp()) == null) { + if (StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NEED_CHECK.getProp()), TrueFalseEnum.TRUE.getDesc()) || HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NEED_CHECK.getProp()) == null) { comments = commentService.findCommentsByPostAndCommentStatus(post, CommentStatusEnum.PUBLISHED.getCode()); } else { comments = commentService.findCommentsByPostAndCommentStatusNot(post, CommentStatusEnum.RECYCLE.getCode()); @@ -149,7 +149,7 @@ public class FrontArchiveController extends BaseController { //默认显示10条 Integer size = 10; //获取每页评论条数 - if (!StringUtils.isBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_COMMENTS.getProp()))) { + if (StrUtil.isNotBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_COMMENTS.getProp()))) { size = Integer.parseInt(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_COMMENTS.getProp())); } //评论分页 diff --git a/src/main/java/cc/ryanc/halo/web/controller/front/FrontCategoryController.java b/src/main/java/cc/ryanc/halo/web/controller/front/FrontCategoryController.java index b3c5e5dc0..e3a288cb3 100644 --- a/src/main/java/cc/ryanc/halo/web/controller/front/FrontCategoryController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/front/FrontCategoryController.java @@ -8,7 +8,7 @@ import cc.ryanc.halo.service.CategoryService; import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.web.controller.core.BaseController; import cn.hutool.core.util.PageUtil; -import org.apache.commons.lang3.StringUtils; +import cn.hutool.core.util.StrUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -84,7 +84,7 @@ public class FrontCategoryController extends BaseController { } Sort sort = new Sort(Sort.Direction.DESC, "postDate"); Integer size = 10; - if (!StringUtils.isBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()))) { + if (StrUtil.isNotBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()))) { size = Integer.parseInt(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp())); } Pageable pageable = PageRequest.of(page - 1, size, sort); diff --git a/src/main/java/cc/ryanc/halo/web/controller/front/FrontCommentController.java b/src/main/java/cc/ryanc/halo/web/controller/front/FrontCommentController.java index 930e7d5a0..a9a628e92 100644 --- a/src/main/java/cc/ryanc/halo/web/controller/front/FrontCommentController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/front/FrontCommentController.java @@ -13,12 +13,12 @@ import cc.ryanc.halo.utils.CommentUtil; import cc.ryanc.halo.utils.OwoUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.core.lang.Validator; +import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.URLUtil; import cn.hutool.crypto.SecureUtil; import cn.hutool.extra.servlet.ServletUtil; import cn.hutool.http.HtmlUtil; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -121,18 +121,18 @@ public class FrontCommentController { comment.setCommentAuthorIp(ServletUtil.getClientIP(request)); comment.setIsAdmin(0); comment.setCommentAuthor(HtmlUtil.escape(comment.getCommentAuthor())); - if(StringUtils.isNotBlank(comment.getCommentAuthorEmail())) { + if (StrUtil.isNotBlank(comment.getCommentAuthorEmail())) { comment.setCommentAuthorAvatarMd5(SecureUtil.md5(comment.getCommentAuthorEmail())); } if (comment.getCommentParent() > 0) { lastComment = commentService.findCommentById(comment.getCommentParent()).get(); String lastContent = "@" + lastComment.getCommentAuthor() + ""; - comment.setCommentContent(lastContent + StringUtils.substringAfter(OwoUtil.markToImg(HtmlUtil.escape(comment.getCommentContent())), ":")); + comment.setCommentContent(lastContent + StrUtil.subAfter(OwoUtil.markToImg(HtmlUtil.escape(comment.getCommentContent())), ":", true)); } else { //将评论内容的字符专为安全字符 comment.setCommentContent(OwoUtil.markToImg(HtmlUtil.escape(comment.getCommentContent()))); } - if (StringUtils.isNotEmpty(comment.getCommentAuthorUrl())) { + if (StrUtil.isNotEmpty(comment.getCommentAuthorUrl())) { comment.setCommentAuthorUrl(URLUtil.formatUrl(comment.getCommentAuthorUrl())); } commentService.saveByComment(comment); @@ -142,7 +142,7 @@ public class FrontCommentController { } else { new EmailToAdmin(comment, post).start(); } - if (StringUtils.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NEED_CHECK.getProp()), TrueFalseEnum.TRUE.getDesc()) || HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NEED_CHECK.getProp()) == null) { + if (StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NEED_CHECK.getProp()), TrueFalseEnum.TRUE.getDesc()) || HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NEED_CHECK.getProp()) == null) { return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), "你的评论已经提交,待博主审核之后可显示。"); } else { return new JsonResult(ResultCodeEnum.SUCCESS.getCode(), "你的评论已经提交,刷新后即可显示。"); @@ -166,13 +166,13 @@ public class FrontCommentController { @Override public void run() { - if (StringUtils.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getDesc()) && StringUtils.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) { + 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 map = new HashMap<>(5); map.put("author", userService.findUser().getUserDisplayName()); map.put("pageName", post.getPostTitle()); - if (StringUtils.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) { + if (StrUtil.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) { map.put("pageUrl", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/archives/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId()); } else { map.put("pageUrl", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/p/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId()); @@ -204,13 +204,13 @@ public class FrontCommentController { @Override public void run() { //发送通知给对方 - if (StringUtils.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.SMTP_EMAIL_ENABLE.getProp()), TrueFalseEnum.TRUE.getDesc()) && StringUtils.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NOTICE.getProp()), TrueFalseEnum.TRUE.getDesc())) { + 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 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()); - if (StringUtils.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) { + if (StrUtil.equals(post.getPostType(), PostTypeEnum.POST_TYPE_POST.getDesc())) { map.put("pageUrl", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/archives/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId()); } else { map.put("pageUrl", HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_URL.getProp()) + "/p/" + post.getPostUrl() + "#comment-id-" + comment.getCommentId()); diff --git a/src/main/java/cc/ryanc/halo/web/controller/front/FrontIndexController.java b/src/main/java/cc/ryanc/halo/web/controller/front/FrontIndexController.java index 980397a17..309adecab 100644 --- a/src/main/java/cc/ryanc/halo/web/controller/front/FrontIndexController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/front/FrontIndexController.java @@ -6,8 +6,8 @@ import cc.ryanc.halo.model.enums.BlogPropertiesEnum; import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.web.controller.core.BaseController; import cn.hutool.core.util.PageUtil; +import cn.hutool.core.util.StrUtil; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -63,7 +63,7 @@ public class FrontIndexController extends BaseController { //默认显示10条 Integer size = 10; //尝试加载设置选项,用于设置显示条数 - if (!StringUtils.isBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()))) { + if (StrUtil.isNotBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()))) { size = Integer.parseInt(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp())); } //所有文章数据,分页 @@ -92,7 +92,7 @@ public class FrontIndexController extends BaseController { //默认显示10条 Integer size = 10; //尝试加载设置选项,用于设置显示条数 - if (!StringUtils.isBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()))) { + if (StrUtil.isNotBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()))) { size = Integer.parseInt(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp())); } diff --git a/src/main/java/cc/ryanc/halo/web/controller/front/FrontOthersController.java b/src/main/java/cc/ryanc/halo/web/controller/front/FrontOthersController.java index 7cdd76ecc..385cb1fbe 100644 --- a/src/main/java/cc/ryanc/halo/web/controller/front/FrontOthersController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/front/FrontOthersController.java @@ -5,7 +5,7 @@ import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.model.enums.BlogPropertiesEnum; import cc.ryanc.halo.model.enums.PostTypeEnum; import cc.ryanc.halo.service.PostService; -import org.apache.commons.lang3.StringUtils; +import cn.hutool.core.util.StrUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -40,7 +40,7 @@ public class FrontOthersController { @ResponseBody public String feed() { String rssPosts = HaloConst.OPTIONS.get(BlogPropertiesEnum.RSS_POSTS.getProp()); - if (StringUtils.isBlank(rssPosts)) { + if (StrUtil.isBlank(rssPosts)) { rssPosts = "20"; } //获取文章列表并根据时间排序 diff --git a/src/main/java/cc/ryanc/halo/web/controller/front/FrontPageController.java b/src/main/java/cc/ryanc/halo/web/controller/front/FrontPageController.java index cacc58a3c..00f545739 100644 --- a/src/main/java/cc/ryanc/halo/web/controller/front/FrontPageController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/front/FrontPageController.java @@ -15,7 +15,7 @@ import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.utils.CommentUtil; import cc.ryanc.halo.web.controller.core.BaseController; import cn.hutool.core.util.PageUtil; -import org.apache.commons.lang3.StringUtils; +import cn.hutool.core.util.StrUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -83,7 +83,7 @@ public class FrontPageController extends BaseController { return this.renderNotFound(); } List comments = null; - if (StringUtils.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NEED_CHECK.getProp()), TrueFalseEnum.TRUE.getDesc()) || HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NEED_CHECK.getProp()) == null) { + if (StrUtil.equals(HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NEED_CHECK.getProp()), TrueFalseEnum.TRUE.getDesc()) || HaloConst.OPTIONS.get(BlogPropertiesEnum.NEW_COMMENT_NEED_CHECK.getProp()) == null) { comments = commentService.findCommentsByPostAndCommentStatus(post, CommentStatusEnum.PUBLISHED.getCode()); } else { comments = commentService.findCommentsByPostAndCommentStatusNot(post, CommentStatusEnum.RECYCLE.getCode()); @@ -91,7 +91,7 @@ public class FrontPageController extends BaseController { //默认显示10条 Integer size = 10; //获取每页评论条数 - if (!StringUtils.isBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_COMMENTS.getProp()))) { + if (StrUtil.isNotBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_COMMENTS.getProp()))) { size = Integer.parseInt(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_COMMENTS.getProp())); } //评论分页 diff --git a/src/main/java/cc/ryanc/halo/web/controller/front/FrontTagController.java b/src/main/java/cc/ryanc/halo/web/controller/front/FrontTagController.java index 01291555c..e38e8ee1f 100644 --- a/src/main/java/cc/ryanc/halo/web/controller/front/FrontTagController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/front/FrontTagController.java @@ -8,7 +8,7 @@ import cc.ryanc.halo.service.PostService; import cc.ryanc.halo.service.TagService; import cc.ryanc.halo.web.controller.core.BaseController; import cn.hutool.core.util.PageUtil; -import org.apache.commons.lang3.StringUtils; +import cn.hutool.core.util.StrUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -79,7 +79,7 @@ public class FrontTagController extends BaseController { } Sort sort = new Sort(Sort.Direction.DESC, "postDate"); Integer size = 10; - if (!StringUtils.isBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()))) { + if (StrUtil.isNotBlank(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp()))) { size = Integer.parseInt(HaloConst.OPTIONS.get(BlogPropertiesEnum.INDEX_POSTS.getProp())); } Pageable pageable = PageRequest.of(page - 1, size, sort); diff --git a/src/main/java/cc/ryanc/halo/web/interceptor/ApiInterceptor.java b/src/main/java/cc/ryanc/halo/web/interceptor/ApiInterceptor.java index 437a37cf3..431eaecf5 100644 --- a/src/main/java/cc/ryanc/halo/web/interceptor/ApiInterceptor.java +++ b/src/main/java/cc/ryanc/halo/web/interceptor/ApiInterceptor.java @@ -3,7 +3,7 @@ package cc.ryanc.halo.web.interceptor; import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.model.enums.BlogPropertiesEnum; import cc.ryanc.halo.model.enums.TrueFalseEnum; -import org.apache.commons.lang3.StringUtils; +import cn.hutool.core.util.StrUtil; import org.springframework.stereotype.Component; import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.ModelAndView; @@ -24,7 +24,7 @@ public class ApiInterceptor implements HandlerInterceptor { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { - if (StringUtils.equals(TrueFalseEnum.TRUE.getDesc(), HaloConst.OPTIONS.get(BlogPropertiesEnum.API_STATUS.getProp()))) { + if (StrUtil.equals(TrueFalseEnum.TRUE.getDesc(), HaloConst.OPTIONS.get(BlogPropertiesEnum.API_STATUS.getProp()))) { return true; } response.sendRedirect("/404"); diff --git a/src/main/java/cc/ryanc/halo/web/interceptor/InstallInterceptor.java b/src/main/java/cc/ryanc/halo/web/interceptor/InstallInterceptor.java index f75ac8434..d69166598 100644 --- a/src/main/java/cc/ryanc/halo/web/interceptor/InstallInterceptor.java +++ b/src/main/java/cc/ryanc/halo/web/interceptor/InstallInterceptor.java @@ -3,7 +3,7 @@ package cc.ryanc.halo.web.interceptor; import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.model.enums.BlogPropertiesEnum; import cc.ryanc.halo.model.enums.TrueFalseEnum; -import org.apache.commons.lang3.StringUtils; +import cn.hutool.core.util.StrUtil; import org.springframework.stereotype.Component; import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.ModelAndView; @@ -24,7 +24,7 @@ public class InstallInterceptor implements HandlerInterceptor { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws Exception { - if (StringUtils.equals(TrueFalseEnum.TRUE.getDesc(), HaloConst.OPTIONS.get(BlogPropertiesEnum.IS_INSTALL.getProp()))) { + if (StrUtil.equals(TrueFalseEnum.TRUE.getDesc(), HaloConst.OPTIONS.get(BlogPropertiesEnum.IS_INSTALL.getProp()))) { return true; } response.sendRedirect("/install"); diff --git a/src/main/java/cc/ryanc/halo/web/interceptor/LocaleInterceptor.java b/src/main/java/cc/ryanc/halo/web/interceptor/LocaleInterceptor.java index 0ab94b1fa..bae4a1dc8 100644 --- a/src/main/java/cc/ryanc/halo/web/interceptor/LocaleInterceptor.java +++ b/src/main/java/cc/ryanc/halo/web/interceptor/LocaleInterceptor.java @@ -3,7 +3,7 @@ package cc.ryanc.halo.web.interceptor; import cc.ryanc.halo.model.dto.HaloConst; import cc.ryanc.halo.model.enums.BlogPropertiesEnum; import cc.ryanc.halo.model.enums.LocaleEnum; -import org.apache.commons.lang3.StringUtils; +import cn.hutool.core.util.StrUtil; import org.springframework.stereotype.Component; import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.ModelAndView; @@ -23,7 +23,7 @@ public class LocaleInterceptor implements HandlerInterceptor { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { - if (StringUtils.equals(LocaleEnum.EN_US.getValue(), HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_LOCALE.getProp()))) { + if (StrUtil.equals(LocaleEnum.EN_US.getValue(), HaloConst.OPTIONS.get(BlogPropertiesEnum.BLOG_LOCALE.getProp()))) { request.getSession().setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME, new Locale("en", "US")); } else { request.getSession().setAttribute(SessionLocaleResolver.LOCALE_SESSION_ATTRIBUTE_NAME, new Locale("zh", "CN")); diff --git a/src/main/resources/templates/common/install.ftl b/src/main/resources/templates/common/install.ftl index e414a9411..995d14897 100644 --- a/src/main/resources/templates/common/install.ftl +++ b/src/main/resources/templates/common/install.ftl @@ -35,6 +35,9 @@ Halo<@spring.message code='install.page.title'/> <#if isInstall==false> + <#if RequestParameters['lang']??> + <#assign lang ="${RequestParameters['lang']}"> +
@@ -42,8 +45,8 @@
@@ -309,8 +312,12 @@ },'json'); }); }); + $('#blogLocale').on('change',function(){ + var lang = $(this).val(); + window.location.href="/install?lang="+lang; + }); <#else> - \ No newline at end of file +