|
@@ -2,21 +2,24 @@ package com.zd.base.files.ueditor;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import org.springframework.core.io.ClassPathResource;
|
|
|
|
|
|
|
|
import java.io.*;
|
|
import java.io.*;
|
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
public class ConfigManager {
|
|
public class ConfigManager {
|
|
|
- private String rootPath;
|
|
|
|
|
private String localPath;
|
|
private String localPath;
|
|
|
private JSONObject jsonConfig;
|
|
private JSONObject jsonConfig;
|
|
|
|
|
|
|
|
private ConfigManager(String localPath) throws IOException {
|
|
private ConfigManager(String localPath) throws IOException {
|
|
|
- this.rootPath = this.getClass().getClassLoader().getResource("ueditor").getPath();
|
|
|
|
|
|
|
+
|
|
|
|
|
+ String result = new BufferedReader(new InputStreamReader(new ClassPathResource("ueditor/config.json").getInputStream()))
|
|
|
|
|
+ .lines().collect(Collectors.joining(System.lineSeparator()));
|
|
|
|
|
+ jsonConfig = JSONObject.parseObject(result);
|
|
|
|
|
|
|
|
this.localPath = localPath;
|
|
this.localPath = localPath;
|
|
|
- this.initEnv();
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public static ConfigManager getInstance(String realPath) {
|
|
public static ConfigManager getInstance(String realPath) {
|
|
@@ -97,20 +100,6 @@ public class ConfigManager {
|
|
|
return conf;
|
|
return conf;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private void initEnv() throws IOException {
|
|
|
|
|
- String configContent = this.readFile(this.getConfigPath());
|
|
|
|
|
- try {
|
|
|
|
|
- JSONObject jsonConfig = JSONObject.parseObject(configContent);
|
|
|
|
|
- this.jsonConfig = jsonConfig;
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- this.jsonConfig = null;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private String getConfigPath() {
|
|
|
|
|
- return this.rootPath + File.separator + "config.json";
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
private String[] getArray(String key) {
|
|
private String[] getArray(String key) {
|
|
|
JSONArray jsonArray = this.jsonConfig.getJSONArray(key);
|
|
JSONArray jsonArray = this.jsonConfig.getJSONArray(key);
|
|
|
String[] result = new String[jsonArray.size()];
|
|
String[] result = new String[jsonArray.size()];
|