Эх сурвалжийг харах

优先使用自定义office.home

陈精华 6 жил өмнө
parent
commit
f989fbf9c9

+ 18 - 2
jodconverter-core/src/main/java/org/artofsolving/jodconverter/office/OfficeUtils.java

@@ -12,8 +12,11 @@
 //
 package org.artofsolving.jodconverter.office;
 
+import java.io.BufferedReader;
 import java.io.File;
+import java.io.FileReader;
 import java.util.Map;
+import java.util.Properties;
 
 import org.artofsolving.jodconverter.util.PlatformUtils;
 
@@ -61,8 +64,14 @@ public class OfficeUtils {
     }
 
     public static File getDefaultOfficeHome() {
-        if (System.getProperty("office.home") != null) {
-            return new File(System.getProperty("office.home"));
+        Properties properties = new Properties();
+        String customizedConfigPath = getCustomizedConfigPath();
+        try {
+            BufferedReader bufferedReader = new BufferedReader(new FileReader(customizedConfigPath));
+            properties.load(bufferedReader);
+        } catch (Exception e) {}
+        if (properties.getProperty("office.home") != null) {
+            return new File(properties.getProperty("office.home"));
         }
         if (PlatformUtils.isWindows()) {
             // %ProgramFiles(x86)% on 64-bit machines; %ProgramFiles% on 32-bit ones
@@ -127,4 +136,11 @@ public class OfficeUtils {
         return userDir;
     }
 
+    public static String getCustomizedConfigPath() {
+        String homePath = OfficeUtils.getHomePath();
+        String separator = java.io.File.separator;
+        String configFilePath = homePath + separator + "conf" + separator + "application.properties";
+        return configFilePath;
+    }
+
 }

+ 1 - 3
jodconverter-web/src/main/java/cn/keking/config/ConfigRefreshComponent.java

@@ -42,9 +42,7 @@ public class ConfigRefreshComponent {
                 String convertedFileCharset = sysProperties.getProperty("sun.jnu.encoding");
                 String[] textArray ;
                 String[] mediaArray;
-                String homePath = OfficeUtils.getHomePath();
-                String separator = java.io.File.separator;
-                String configFilePath = homePath + separator + "conf" + separator + "application.properties";
+                String configFilePath = OfficeUtils.getCustomizedConfigPath();
                 while (true) {
                     BufferedReader bufferedReader = new BufferedReader(new FileReader(configFilePath));
                     properties.load(bufferedReader);