From 6e53b0fa764946dbf8a1103b419393eecf424159 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Sat, 20 Apr 2024 12:17:23 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E4=B8=BA=E6=94=AF?= =?UTF-8?q?=E6=8C=81neatlogic-springboot=E6=A8=A1=E5=9D=97=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E5=81=9A=E4=B8=80=E4=BA=9B=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1138992907517952]为支持neatlogic-springboot模块启动做一些调整 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1138992907517952 --- .../bootstrap/ModuleInitializer.java | 13 ++++++--- .../ReloadableJsonBundleMessageSource.java | 27 +++++++++++++++---- .../DocumentOnlineInitializeIndexHandler.java | 6 +++-- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/main/java/neatlogic/framework/bootstrap/ModuleInitializer.java b/src/main/java/neatlogic/framework/bootstrap/ModuleInitializer.java index 78f39dbc0..8ac642263 100644 --- a/src/main/java/neatlogic/framework/bootstrap/ModuleInitializer.java +++ b/src/main/java/neatlogic/framework/bootstrap/ModuleInitializer.java @@ -129,7 +129,8 @@ public class ModuleInitializer implements WebApplicationInitializer { Resource[] resources = resolver.getResources("classpath*:neatlogic/**/*-servlet-context.xml"); for (Resource resource : resources) { String path = resource.getURL().getPath(); - path = path.substring(path.indexOf("!") + 1); +// path = path.substring(path.indexOf("!") + 1); + path = path.substring(path.lastIndexOf("/neatlogic/") + 1); SAXReader reader = new SAXReader(); Document document = reader.read(resource.getURL()); Element rootE = document.getRootElement(); @@ -291,18 +292,22 @@ public class ModuleInitializer implements WebApplicationInitializer { List errorList = new ArrayList<>(); Map> moduleVersionListMap = new HashMap<>(); //检查changelog下合法版本 - Resource[] resources = resolver.getResources("classpath*:neatlogic/resources/*/changelog/*/"); + Resource[] resources = resolver.getResources("classpath*:neatlogic/resources/*/changelog/*/*"); for (Resource resource : resources) { //目前 String fileName = resource.getURL().getPath().substring(0, resource.getURL().getPath().lastIndexOf("/")); String version = fileName.substring(fileName.lastIndexOf("/") + 1); if (!Objects.equals("changelog", version) && StringUtils.isNotBlank(version)) { String path = resource.getURL().getPath(); - path = path.substring(path.indexOf("!") + 1); +// path = path.substring(path.indexOf("!") + 1); + path = path.substring(path.lastIndexOf("/neatlogic/resources/")); if (StringUtils.isNotBlank(path)) { String moduleId = path.split("/")[3]; if (version.matches("\\d{4}-\\d{2}-\\d{2}(-\\d{2})?")) { - moduleVersionListMap.computeIfAbsent(moduleId, k -> new ArrayList<>()).add(version); + List list = moduleVersionListMap.computeIfAbsent(moduleId, k -> new ArrayList<>()); + if (!list.contains(version)) { + list.add(version); + } } else { errorList.add(path); } diff --git a/src/main/java/neatlogic/framework/i18n/ReloadableJsonBundleMessageSource.java b/src/main/java/neatlogic/framework/i18n/ReloadableJsonBundleMessageSource.java index 5c178160f..cd4122862 100644 --- a/src/main/java/neatlogic/framework/i18n/ReloadableJsonBundleMessageSource.java +++ b/src/main/java/neatlogic/framework/i18n/ReloadableJsonBundleMessageSource.java @@ -28,8 +28,10 @@ import org.springframework.lang.Nullable; import org.springframework.util.PropertiesPersister; import org.springframework.util.StringUtils; +import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.text.MessageFormat; import java.util.*; import java.util.concurrent.ConcurrentHashMap; @@ -481,11 +483,26 @@ public class ReloadableJsonBundleMessageSource extends AbstractResourceBasedMess } private Map readJsonFile(Resource resource) throws IOException { - try (InputStream inputStream = resource.getInputStream()) { - byte[] bytes = new byte[inputStream.available()]; - inputStream.read(bytes); - String json = new String(bytes); - JSONObject rawJsonObject = JSON.parseObject(json); +// try (InputStream inputStream = resource.getInputStream()) { +// byte[] bytes = new byte[inputStream.available()]; +// inputStream.read(bytes); +// String json = new String(bytes); +// JSONObject rawJsonObject = JSON.parseObject(json); +// Map flattenedMap = new HashMap<>(); +// flattenMap("", rawJsonObject, flattenedMap); +// return flattenedMap; +// } + try ( + InputStream inputStream = resource.getInputStream(); + InputStreamReader inputStreamReader = new InputStreamReader(inputStream); + BufferedReader bufferedReader = new BufferedReader(inputStreamReader); + ) { + StringBuilder stringBuilder = new StringBuilder(); + String line = null; + while((line = bufferedReader.readLine()) != null) { + stringBuilder.append(line); + } + JSONObject rawJsonObject = JSON.parseObject(stringBuilder.toString()); Map flattenedMap = new HashMap<>(); flattenMap("", rawJsonObject, flattenedMap); return flattenedMap; diff --git a/src/main/java/neatlogic/module/framework/startup/DocumentOnlineInitializeIndexHandler.java b/src/main/java/neatlogic/module/framework/startup/DocumentOnlineInitializeIndexHandler.java index 3da0a5f48..355b20c89 100644 --- a/src/main/java/neatlogic/module/framework/startup/DocumentOnlineInitializeIndexHandler.java +++ b/src/main/java/neatlogic/module/framework/startup/DocumentOnlineInitializeIndexHandler.java @@ -158,8 +158,10 @@ public class DocumentOnlineInitializeIndexHandler extends StartupBase { } } String path = resource.getURL().getPath(); - int separatorIndex = path.indexOf("!/"); - String filePath = path.substring(separatorIndex + 2); +// int separatorIndex = path.indexOf("!/"); +// String filePath = path.substring(separatorIndex + 2); + int separatorIndex = path.lastIndexOf("/neatlogic/resources/"); + String filePath = path.substring(separatorIndex + 1); if (existingFilePathList.contains(filePath)) { logger.error($.t("nmfs.documentonlineinitializeindexhandler.executeforalltenant.error", filePath)); System.exit(1); -- Gitee