From 7060cc8046e68e61368635d2365792a8b2abbcc3 Mon Sep 17 00:00:00 2001 From: ruibaby Date: Tue, 26 Mar 2019 15:24:44 +0800 Subject: [PATCH] Fix errors caused by ThemeService --- .../java/cc/ryanc/halo/listener/StartedListener.java | 7 +++++-- .../web/controller/admin/base/BaseController.java | 7 +++++-- .../halo/web/controller/core/CommonController.java | 11 +++++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/java/cc/ryanc/halo/listener/StartedListener.java b/src/main/java/cc/ryanc/halo/listener/StartedListener.java index 5727b2965..10800c675 100644 --- a/src/main/java/cc/ryanc/halo/listener/StartedListener.java +++ b/src/main/java/cc/ryanc/halo/listener/StartedListener.java @@ -5,8 +5,8 @@ import cc.ryanc.halo.model.enums.BlogProperties; import cc.ryanc.halo.model.support.HaloConst; import cc.ryanc.halo.model.support.Theme; import cc.ryanc.halo.service.OptionService; +import cc.ryanc.halo.service.ThemeService; import cc.ryanc.halo.utils.HaloUtils; -import cc.ryanc.halo.utils.ThemeUtils; import cc.ryanc.halo.web.controller.content.base.BaseContentController; import cn.hutool.core.util.StrUtil; import com.fasterxml.jackson.databind.ObjectMapper; @@ -53,6 +53,9 @@ public class StartedListener implements ApplicationListener themes = ThemeUtils.getThemes(); + final List themes = themeService.getThemes(); if (null != themes) { HaloConst.THEMES = themes; } diff --git a/src/main/java/cc/ryanc/halo/web/controller/admin/base/BaseController.java b/src/main/java/cc/ryanc/halo/web/controller/admin/base/BaseController.java index 7ff499794..47d0c074a 100644 --- a/src/main/java/cc/ryanc/halo/web/controller/admin/base/BaseController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/admin/base/BaseController.java @@ -1,7 +1,7 @@ package cc.ryanc.halo.web.controller.admin.base; import cc.ryanc.halo.service.OptionService; -import cc.ryanc.halo.utils.ThemeUtils; +import cc.ryanc.halo.service.ThemeService; import freemarker.template.Configuration; import freemarker.template.TemplateModelException; import org.springframework.beans.factory.annotation.Autowired; @@ -22,13 +22,16 @@ public abstract class BaseController { @Autowired public OptionService optionService; + @Autowired + public ThemeService themeService; + /** * Clear all caches */ public void refreshCache() { try { THEMES.clear(); - THEMES = ThemeUtils.getThemes(); + THEMES = themeService.getThemes(); configuration.setSharedVariable("options", optionService.listOptions()); } catch (TemplateModelException e) { e.printStackTrace(); diff --git a/src/main/java/cc/ryanc/halo/web/controller/core/CommonController.java b/src/main/java/cc/ryanc/halo/web/controller/core/CommonController.java index 01b41ae41..78706d79e 100644 --- a/src/main/java/cc/ryanc/halo/web/controller/core/CommonController.java +++ b/src/main/java/cc/ryanc/halo/web/controller/core/CommonController.java @@ -3,10 +3,10 @@ package cc.ryanc.halo.web.controller.core; import cc.ryanc.halo.logging.Logger; import cc.ryanc.halo.model.entity.User; import cc.ryanc.halo.model.support.HaloConst; -import cc.ryanc.halo.utils.ThemeUtils; +import cc.ryanc.halo.service.ThemeService; import cc.ryanc.halo.web.controller.content.base.BaseContentController; import cn.hutool.core.text.StrBuilder; -import cn.hutool.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.servlet.error.ErrorController; import org.springframework.stereotype.Controller; import org.springframework.util.StringUtils; @@ -35,6 +35,9 @@ public class CommonController implements ErrorController { private final Logger log = Logger.getLogger(getClass()); + @Autowired + private ThemeService themeService; + /** * Handle error * @@ -101,7 +104,7 @@ public class CommonController implements ErrorController { */ @GetMapping(value = "/404") public String contentNotFround() throws FileNotFoundException { - if (!ThemeUtils.isTemplateExist(NOT_FROUND_TEMPLATE)) { + if (!themeService.isTemplateExist(NOT_FROUND_TEMPLATE)) { return "common/error/404"; } StrBuilder path = new StrBuilder("themes/"); @@ -117,7 +120,7 @@ public class CommonController implements ErrorController { */ @GetMapping(value = "/500") public String contentInternalError() throws FileNotFoundException { - if (!ThemeUtils.isTemplateExist(INTERNAL_ERROR_TEMPLATE)) { + if (!themeService.isTemplateExist(INTERNAL_ERROR_TEMPLATE)) { return "common/error/500"; } StrBuilder path = new StrBuilder("themes/");