Browse Source

Linux下集成OpenOffice

陈精华 6 năm trước cách đây
mục cha
commit
0db6b23bf7

+ 1 - 0
jodconverter-core/src/main/java/org/artofsolving/jodconverter/office/OfficeUtils.java

@@ -86,6 +86,7 @@ public class OfficeUtils {
             return findOfficeHome(
                 "/opt/openoffice.org3",
                 "/opt/libreoffice",
+                "/opt/openoffice4",
                 "/usr/lib/openoffice",
                 "/usr/lib/libreoffice"
             );

+ 24 - 2
jodconverter-web/src/main/bin/startup.sh

@@ -1,8 +1,30 @@
 #!/bin/bash
-KKFILEVIEW_BIN_FOLDER=$(cd "$(dirname "$0")";pwd)
+DIR_HOME=("/opt/openoffice.org3" "/opt/libreoffice" "/opt/openoffice4" "/usr/lib/openoffice" "/usr/lib/libreoffice")
+FLAG=
+OFFICE_HOME=
+KKFILEVIEW_BIN_FOLDER=$(cd "$(dirname "$0")";pwd)vim
 export KKFILEVIEW_BIN_FOLDER=$KKFILEVIEW_BIN_FOLDER
 cd $KKFILEVIEW_BIN_FOLDER
 echo "Using KKFILEVIEW_BIN_FOLDER $KKFILEVIEW_BIN_FOLDER"
+grep 'office\.home' ../conf/application.properties | grep '!^#'
+if [ $? -eq 0 ]; then
+  echo "Using customized office.home"
+else 
+ for i in ${DIR_HOME[@]}
+  do
+    if [ -f $i"/program/soffice.bin" ]; then
+      FLAG=true
+      OFFICE_HOME=${i}
+      break
+    fi
+  done
+  if [ ! -n "${FLAG}" ]; then
+    echo "Installing OpenOffice"
+    sh ../script/install.sh
+  else 
+    echo "Detected office component has been installed in $OFFICE_HOME"
+  fi
+fi
 echo "Starting kkFileView..."
 echo "Please check log file for more information"
-nohup java -Dspring.config.location=../conf/application.properties -jar kkFileView-0.1.jar ../log/kkFileView.log 2>&1 &
+nohup java -Dspring.config.location=../conf/application.properties -jar kkFileView-0.1.jar > ../log/kkFileView.log 2>&1 &

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

@@ -1,13 +1,12 @@
 package cn.keking.config;
 
-import cn.keking.utils.HomePathUtils;
+import org.artofsolving.jodconverter.office.OfficeUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.PostConstruct;
 import java.io.BufferedReader;
-import java.io.File;
 import java.io.FileReader;
 import java.io.IOException;
 import java.util.Properties;
@@ -38,7 +37,7 @@ public class ConfigRefreshComponent {
                 String convertedFileCharset;
                 String[] textArray ;
                 String[] mediaArray;
-                String homePath = HomePathUtils.getHomePath();
+                String homePath = OfficeUtils.getHomePath();
                 String separator = java.io.File.separator;
                 String configFilePath = homePath + separator + "conf" + separator + "application.properties";
                 while (true) {

+ 0 - 26
jodconverter-web/src/main/java/cn/keking/utils/HomePathUtils.java

@@ -1,26 +0,0 @@
-package cn.keking.utils;
-
-import java.io.File;
-
-/**
- * @auther: chenjh
- * @time: 2019/4/15 9:11
- * @description
- */
-public class HomePathUtils {
-
-    public static String getHomePath() {
-        String userDir = System.getenv("KKFILEVIEW_BIN_FOLDER");
-        if (userDir == null) {
-            userDir = System.getProperty("user.dir");
-        }
-        if (userDir.endsWith("bin")) {
-            userDir = userDir.substring(0, userDir.length() - 4);
-        } else {
-            String separator = File.separator;
-            userDir = userDir + separator + "jodconverter-web" + separator + "src" + separator +  "main";
-        }
-        return userDir;
-    }
-
-}

+ 5 - 0
jodconverter-web/src/main/resources/assembly.xml

@@ -20,6 +20,11 @@
             <outputDirectory>${file.separator}bin</outputDirectory>
             <fileMode>755</fileMode>
         </fileSet>
+        <fileSet>
+            <directory>src/main/script</directory>
+            <outputDirectory>${file.separator}script</outputDirectory>
+            <fileMode>755</fileMode>
+        </fileSet>
         <fileSet>
             <directory>src/main/log</directory>
             <outputDirectory>${file.separator}log</outputDirectory>

+ 0 - 18
jodconverter-web/src/main/resources/logback.xml

@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<configuration>
-    <property name="LOG_FILE" value="@logging.path@/app.log"></property>
-    <include resource="org/springframework/boot/logging/logback/base.xml"/>
-    <jmxConfigurator/>
-    <logger name="org.springframework.web" level="info"/>
-    <appender name="stash" class="net.logstash.logback.appender.LogstashSocketAppender">
-        <port>10800</port>
-        <host>192.168.1.109</host>
-        <includeCallerData>true</includeCallerData>
-        <customFields>{"app_name":"@appName@"}</customFields>
-    </appender>
-    <root level="INFO">
-        <!--<appender-ref ref="dailyRollingFile"/>
-        <appender-ref ref="consoleRolling"/>-->
-        <appender-ref ref="stash"/>
-    </root>
-</configuration>

+ 36 - 0
jodconverter-web/src/main/script/install.sh

@@ -0,0 +1,36 @@
+#!/bin/bash
+cd /tmp
+
+install_redhat() {
+    wget https://iweb.dl.sourceforge.net/project/openofficeorg.mirror/4.1.6/binaries/zh-CN/Apache_OpenOffice_4.1.6_Linux_x86-64_install-rpm_zh-CN.tar.gz -cO openoffice_rpm.tar.gz && tar zxf /tmp/openoffice_rpm.tar.gz && cd /tmp/zh-CN/RPMS
+   if [ $? -eq 0 ];then
+     rpm -Uvih *.rpm
+     echo 'install desktop service ...'
+     rpm -Uvih desktop-integration/openoffice4.1.6-redhat-menus-4.1.6-9790.noarch.rpm
+     echo 'install finshed...'
+   else
+     echo 'download package error...'
+   fi
+}
+
+install_ubuntu() {
+   wget  https://iweb.dl.sourceforge.net/project/openofficeorg.mirror/4.1.6/binaries/zh-CN/Apache_OpenOffice_4.1.6_Linux_x86-64_install-deb_zh-CN.tar.gz  -cO openoffice_deb.tar.gz && tar zxf /tmp/openoffice_deb.tar.gz && cd /tmp/zh-CN/DEBS
+   echo $?
+ if [ $? -eq 0 ];then
+     dpkg -i *.deb
+     echo 'install desktop service ...'
+     dpkg -i desktop-integration/openoffice4.1-debian-menus_4.1.6-9790_all.deb
+     echo 'install finshed...'
+  else
+    echo 'download package error...'
+ fi
+}
+
+
+if [ -f "/etc/redhat-release" ]; then
+  yum install wget
+  install_redhat
+else
+  apt-get install wget
+  install_ubuntu
+fi