Skip to content

Commit 55537d3

Browse files
gitchenjhklboke
authored andcommitted
Windows下集成OpenOffice
1 parent 02e116f commit 55537d3

3,613 files changed

Lines changed: 672523 additions & 22 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,16 @@ public static File getDefaultOfficeHome() {
6666
}
6767
if (PlatformUtils.isWindows()) {
6868
// %ProgramFiles(x86)% on 64-bit machines; %ProgramFiles% on 32-bit ones
69+
String separator = File.separator;
70+
String officeHome = OfficeUtils.getHomePath() + separator + "office";
6971
String programFiles = System.getenv("ProgramFiles(x86)");
7072
if (programFiles == null) {
7173
programFiles = System.getenv("ProgramFiles");
7274
}
7375
return findOfficeHome(
7476
programFiles + File.separator + "OpenOffice 4",
75-
programFiles + File.separator + "LibreOffice 4"
77+
programFiles + File.separator + "LibreOffice 4",
78+
officeHome + File.separator + "OpenOffice 4"
7679
);
7780
} else if (PlatformUtils.isMac()) {
7881
return findOfficeHome(
@@ -108,4 +111,18 @@ public static File getOfficeExecutable(File officeHome) {
108111
}
109112
}
110113

114+
public static String getHomePath() {
115+
String userDir = System.getenv("KKFILEVIEW_BIN_FOLDER");
116+
if (userDir == null) {
117+
userDir = System.getProperty("user.dir");
118+
}
119+
if (userDir.endsWith("bin")) {
120+
userDir = userDir.substring(0, userDir.length() - 4);
121+
} else {
122+
String separator = File.separator;
123+
userDir = userDir + separator + "jodconverter-web" + separator + "src" + separator + "main";
124+
}
125+
return userDir;
126+
}
127+
111128
}

jodconverter-web/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@
164164
</includes>
165165
<filtering>true</filtering>
166166
</resource>
167+
<resource>
168+
<directory>src/main/conf</directory>
169+
<excludes>
170+
<exclude></exclude>
171+
</excludes>
172+
</resource>
167173
</resources>
168174
<plugins>
169175
<plugin>

jodconverter-web/src/main/conf/application.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ spring.freemarker.suffix = .ftl
1515
##资源映射路径
1616
file.dir = D:\\kkFileview\\
1717
spring.resources.static-locations = classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,file:${file.dir}
18-
## openoffice home路径
19-
office.home = C:\\Program Files (x86)\\OpenOffice 4
18+
##openoffice home路径
19+
#office.home = C:\\Program Files (x86)\\OpenOffice 4
2020
server.tomcat.uri-encoding = UTF-8
2121
#文件上传限制
2222
spring.http.multipart.max-file-size=100MB

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

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package cn.keking.config;
22

3+
import cn.keking.utils.HomePathUtils;
34
import org.slf4j.Logger;
45
import org.slf4j.LoggerFactory;
56
import org.springframework.stereotype.Component;
@@ -32,24 +33,14 @@ class ConfigRefreshThread implements Runnable {
3233
public void run() {
3334
try {
3435
Properties properties = new Properties();
35-
String userDir = System.getenv("KKFILEVIEW_BIN_FOLDER");
36-
if (userDir == null) {
37-
System.getProperty("user.dir");
38-
}
39-
if (userDir.endsWith("bin")) {
40-
userDir = userDir.substring(0, userDir.length() - 4);
41-
}
36+
String text;
37+
String media;
38+
String convertedFileCharset;
39+
String[] textArray ;
40+
String[] mediaArray;
41+
String homePath = HomePathUtils.getHomePath();
4242
String separator = java.io.File.separator;
43-
String configFilePath = userDir + separator + "conf" + separator + "application.properties";
44-
File file = new File(configFilePath);
45-
if (!file.exists()) {
46-
configFilePath = userDir + separator + "jodconverter-web" + separator + "src" + separator + "main" + separator + "conf" + separator + "application.properties";
47-
}
48-
String text = null;
49-
String media = null;
50-
String convertedFileCharset = null;
51-
String[] textArray = {};
52-
String[] mediaArray = {};
43+
String configFilePath = homePath + separator + "conf" + separator + "application.properties";
5344
while (true) {
5445
BufferedReader bufferedReader = new BufferedReader(new FileReader(configFilePath));
5546
properties.load(bufferedReader);

jodconverter-web/src/main/java/cn/keking/utils/ConverterUtils.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.artofsolving.jodconverter.OfficeDocumentConverter;
66
import org.artofsolving.jodconverter.office.DefaultOfficeManagerConfiguration;
77
import org.artofsolving.jodconverter.office.OfficeManager;
8+
import org.artofsolving.jodconverter.office.OfficeUtils;
89
import org.springframework.beans.factory.annotation.Value;
910
import org.springframework.stereotype.Component;
1011

@@ -23,15 +24,16 @@
2324
@Component
2425
public class ConverterUtils {
2526

26-
@Value("${office.home}")
27-
String officeHome;
27+
// @Value("${office.home}")
28+
// String officeHome;
2829
// OpenOfficeConnection connection;
2930
OfficeManager officeManager;
3031

3132
@PostConstruct
3233
public void initOfficeManager() {
3334
//// connection = new SocketOpenOfficeConnection(host,8100);
3435
//// connection.connect();
36+
String officeHome = OfficeUtils.getDefaultOfficeHome().getAbsolutePath();
3537
DefaultOfficeManagerConfiguration configuration = new DefaultOfficeManagerConfiguration();
3638
configuration.setOfficeHome(officeHome);
3739
configuration.setPortNumber(8100);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package cn.keking.utils;
2+
3+
import java.io.File;
4+
5+
/**
6+
* @auther: chenjh
7+
* @time: 2019/4/15 9:11
8+
* @description
9+
*/
10+
public class HomePathUtils {
11+
12+
public static String getHomePath() {
13+
String userDir = System.getenv("KKFILEVIEW_BIN_FOLDER");
14+
if (userDir == null) {
15+
userDir = System.getProperty("user.dir");
16+
}
17+
if (userDir.endsWith("bin")) {
18+
userDir = userDir.substring(0, userDir.length() - 4);
19+
} else {
20+
String separator = File.separator;
21+
userDir = userDir + separator + "jodconverter-web" + separator + "src" + separator + "main";
22+
}
23+
return userDir;
24+
}
25+
26+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<!--***********************************************************
2+
*
3+
* Licensed to the Apache Software Foundation (ASF) under one
4+
* or more contributor license agreements. See the NOTICE file
5+
* distributed with this work for additional information
6+
* regarding copyright ownership. The ASF licenses this file
7+
* to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance
9+
* with the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing,
14+
* software distributed under the License is distributed on an
15+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
* KIND, either express or implied. See the License for the
17+
* specific language governing permissions and limitations
18+
* under the License.
19+
*
20+
***********************************************************-->
21+
<xsl:stylesheet version="1.0" encoding="UTF-8"
22+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
23+
xmlns:office="http://openoffice.org/2000/office"
24+
xmlns:style="http://openoffice.org/2000/style"
25+
xmlns:table="http://openoffice.org/2000/table"
26+
xmlns:draw="http://openoffice.org/2000/drawing"
27+
xmlns:fo="http://www.w3.org/1999/XSL/Format"
28+
xmlns:xlink="http://www.w3.org/1999/xlink"
29+
xmlns:dc="http://purl.org/dc/elements/1.1/"
30+
xmlns:meta="http://openoffice.org/2000/meta"
31+
xmlns:number="http://openoffice.org/2000/datastyle"
32+
xmlns:svg="http://www.w3.org/2000/svg"
33+
xmlns:chart="http://openoffice.org/2000/chart"
34+
xmlns:help="http://openoffice.org/2000/help"
35+
xmlns:index="http://sun.com/2000/XMLSearch"
36+
xmlns:text="http://openoffice.org/2000/text">
37+
38+
<xsl:param name="Language" select="'en-US'"/>
39+
<xsl:output method="text" encoding="UTF-8"/>
40+
41+
<xsl:template match="/">
42+
<xsl:apply-templates select="//title" mode="include"/>
43+
<xsl:apply-templates select="//paragraph[@role='heading']" mode="include"/>
44+
</xsl:template>
45+
46+
<xsl:template match="*" mode="include">
47+
<xsl:value-of select="."/>
48+
<xsl:text>&#xA;</xsl:text>
49+
</xsl:template>
50+
51+
<xsl:template match="*"/>
52+
53+
</xsl:stylesheet>
54+
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<!--***********************************************************
2+
*
3+
* Licensed to the Apache Software Foundation (ASF) under one
4+
* or more contributor license agreements. See the NOTICE file
5+
* distributed with this work for additional information
6+
* regarding copyright ownership. The ASF licenses this file
7+
* to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance
9+
* with the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing,
14+
* software distributed under the License is distributed on an
15+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
* KIND, either express or implied. See the License for the
17+
* specific language governing permissions and limitations
18+
* under the License.
19+
*
20+
***********************************************************-->
21+
<xsl:stylesheet version="1.0" encoding="UTF-8"
22+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
23+
xmlns:office="http://openoffice.org/2000/office"
24+
xmlns:style="http://openoffice.org/2000/style"
25+
xmlns:table="http://openoffice.org/2000/table"
26+
xmlns:draw="http://openoffice.org/2000/drawing"
27+
xmlns:fo="http://www.w3.org/1999/XSL/Format"
28+
xmlns:xlink="http://www.w3.org/1999/xlink"
29+
xmlns:dc="http://purl.org/dc/elements/1.1/"
30+
xmlns:meta="http://openoffice.org/2000/meta"
31+
xmlns:number="http://openoffice.org/2000/datastyle"
32+
xmlns:svg="http://www.w3.org/2000/svg"
33+
xmlns:chart="http://openoffice.org/2000/chart"
34+
xmlns:help="http://openoffice.org/2000/help"
35+
xmlns:index="http://sun.com/2000/XMLSearch"
36+
xmlns:text="http://openoffice.org/2000/text">
37+
38+
<xsl:param name="Language" select="'en-US'"/>
39+
<xsl:output method="text" encoding="UTF-8"/>
40+
41+
<xsl:template match="helpdocument|body">
42+
<xsl:choose>
43+
<xsl:when test="meta/topic[@indexer='exclude']"/>
44+
<xsl:otherwise>
45+
<xsl:apply-templates/>
46+
</xsl:otherwise>
47+
</xsl:choose>
48+
</xsl:template>
49+
50+
<xsl:template match="title">
51+
<xsl:value-of select="."/>
52+
<xsl:text>&#xA;</xsl:text>
53+
</xsl:template>
54+
55+
<xsl:template match="table">
56+
<xsl:apply-templates/>
57+
<xsl:text>&#xA;</xsl:text>
58+
</xsl:template>
59+
60+
<xsl:template match="tablecell">
61+
<xsl:apply-templates/>
62+
<xsl:text>&#xA;</xsl:text>
63+
</xsl:template>
64+
65+
<xsl:template match="tablerow">
66+
<xsl:apply-templates/>
67+
<xsl:text>&#xA;</xsl:text>
68+
</xsl:template>
69+
70+
<xsl:template match="list">
71+
<xsl:apply-templates/>
72+
<xsl:text>&#xA;</xsl:text>
73+
</xsl:template>
74+
75+
<xsl:template match="listitem">
76+
<xsl:apply-templates/>
77+
<xsl:text>&#xA;</xsl:text>
78+
</xsl:template>
79+
80+
<xsl:template match="item">
81+
<xsl:apply-templates/>
82+
<xsl:text>&#xA;</xsl:text>
83+
</xsl:template>
84+
85+
<xsl:template match="emph">
86+
<xsl:apply-templates/>
87+
<xsl:text>&#xA;</xsl:text>
88+
</xsl:template>
89+
90+
<xsl:template match="paragraph">
91+
<xsl:value-of select="."/>
92+
<xsl:text>&#xA;</xsl:text>
93+
</xsl:template>
94+
95+
<xsl:template match="section">
96+
<xsl:apply-templates/>
97+
<xsl:text>&#xA;</xsl:text>
98+
</xsl:template>
99+
100+
<xsl:template match="bookmark">
101+
<xsl:apply-templates/>
102+
<xsl:text>&#xA;</xsl:text>
103+
</xsl:template>
104+
105+
<xsl:template match="bookmark_value">
106+
<xsl:apply-templates/>
107+
<xsl:text>&#xA;</xsl:text>
108+
</xsl:template>
109+
110+
<xsl:template match="link">
111+
<xsl:apply-templates/>
112+
<xsl:text>&#xA;</xsl:text>
113+
</xsl:template>
114+
115+
<xsl:template match="ahelp[@visibility='visible']">
116+
<xsl:value-of select="."/>
117+
<xsl:text>&#xA;</xsl:text>
118+
</xsl:template>
119+
120+
<xsl:template match="*"/>
121+
122+
</xsl:stylesheet>
123+
124+

0 commit comments

Comments
 (0)