Skip to content

Commit 180e7bc

Browse files
gitchenjhklboke
authored andcommitted
优化:重构大量代码,修复异常
1 parent 8a52450 commit 180e7bc

35 files changed

Lines changed: 465 additions & 700 deletions

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ trust.host = ${KK_TRUST_HOST:default}
4848
cache.enabled = ${KK_CACHE_ENABLED:true}
4949

5050
#文本类型,默认如下,可自定义添加
51-
simText = ${KK_SIMTEXT:txt,html,htm,asp,jsp,xml,json,properties,md,gitignore,,java,py,c,cpp,sql,sh,bat,m,bas,prg,cmd}
51+
simText = ${KK_SIMTEXT:txt,html,htm,asp,jsp,xml,json,properties,md,gitignore,log,java,py,c,cpp,sql,sh,bat,m,bas,prg,cmd}
5252
#多媒体类型,默认如下,可自定义添加
5353
media = ${KK_MEDIA:mp3,wav,mp4,flv}
5454
#office类型文档(word ppt)样式,默认为图片(image),可配置为pdf(预览时也有按钮切换)

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

Lines changed: 65 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
import java.util.Set;
1111

1212
/**
13-
* @auther: chenjh
14-
* @time: 2019/4/10 17:22
15-
* @description
13+
* @author: chenjh
14+
* @since: 2019/4/10 17:22
1615
*/
1716
@Component
1817
public class ConfigConstants {
@@ -30,7 +29,7 @@ public class ConfigConstants {
3029
private static String PDF_DOWNLOAD_DISABLE;
3130

3231
public static final String DEFAULT_CACHE_ENABLED = "true";
33-
public static final String DEFAULT_TXT_TYPE = "txt,html,htm,asp,jsp,xml,json,properties,md,gitignore,,java,py,c,cpp,sql,sh,bat,m,bas,prg,cmd";
32+
public static final String DEFAULT_TXT_TYPE = "txt,html,htm,asp,jsp,xml,json,properties,md,gitignore,log,java,py,c,cpp,sql,sh,bat,m,bas,prg,cmd";
3433
public static final String DEFAULT_MEDIA_TYPE = "mp3,wav,mp4,flv";
3534
public static final String DEFAULT_OFFICE_PREVIEW_TYPE = "image";
3635
public static final String DEFAULT_FTP_USERNAME = null;
@@ -45,63 +44,105 @@ public static Boolean isCacheEnabled() {
4544
return CACHE_ENABLED;
4645
}
4746

48-
public static void setCacheEnabled(Boolean cacheEnabled) {
47+
@Value("${cache.enabled:true}")
48+
public static void setCacheEnabled(String cacheEnabled) {
49+
setCacheEnabledValueValue(Boolean.parseBoolean(cacheEnabled));
50+
}
51+
52+
public static void setCacheEnabledValueValue(Boolean cacheEnabled) {
4953
CACHE_ENABLED = cacheEnabled;
5054
}
5155

5256
public static String[] getSimText() {
5357
return SIM_TEXT;
5458
}
5559

56-
public static void setSimText(String[] simText) {
60+
@Value("${simText:txt,html,htm,asp,jsp,xml,json,properties,md,gitignore,log,java,py,c,cpp,sql,sh,bat,m,bas,prg,cmd}")
61+
public void setSimText(String simText) {
62+
String[] simTextArr = simText.split(",");
63+
setSimTextValue(simTextArr);
64+
}
65+
66+
public static void setSimTextValue(String[] simText) {
5767
SIM_TEXT = simText;
5868
}
5969

6070
public static String[] getMedia() {
6171
return MEDIA;
6272
}
6373

64-
public static void setMedia(String[] Media) {
65-
ConfigConstants.MEDIA = Media;
74+
@Value("${media:mp3,wav,mp4,flv}")
75+
public void setMedia(String media) {
76+
String[] mediaArr = media.split(",");
77+
setMediaValue(mediaArr);
78+
}
79+
80+
public static void setMediaValue(String[] Media) {
81+
MEDIA = Media;
6682
}
6783

6884
public static String getOfficePreviewType() {
6985
return OFFICE_PREVIEW_TYPE;
7086
}
7187

72-
public static void setOfficePreviewType(String officePreviewType) {
88+
@Value("${office.preview.type:image}")
89+
public void setOfficePreviewType(String officePreviewType) {
90+
setOfficePreviewTypeValue(officePreviewType);
91+
}
92+
93+
public static void setOfficePreviewTypeValue(String officePreviewType) {
7394
OFFICE_PREVIEW_TYPE = officePreviewType;
7495
}
7596

7697
public static String getFtpUsername() {
7798
return FTP_USERNAME;
7899
}
79100

80-
public static void setFtpUsername(String ftpUsername) {
101+
@Value("${ftp.username:}")
102+
public void setFtpUsername(String ftpUsername) {
103+
setFtpUsernameValue(ftpUsername);
104+
}
105+
106+
public static void setFtpUsernameValue(String ftpUsername) {
81107
FTP_USERNAME = ftpUsername;
82108
}
83109

84110
public static String getFtpPassword() {
85111
return FTP_PASSWORD;
86112
}
87113

88-
public static void setFtpPassword(String ftpPassword) {
114+
@Value("${ftp.password:}")
115+
public void setFtpPassword(String ftpPassword) {
116+
setFtpPasswordValue(ftpPassword);
117+
}
118+
119+
public static void setFtpPasswordValue(String ftpPassword) {
89120
FTP_PASSWORD = ftpPassword;
90121
}
91122

92123
public static String getFtpControlEncoding() {
93124
return FTP_CONTROL_ENCODING;
94125
}
95126

96-
public static void setFtpControlEncoding(String ftpControlEncoding) {
127+
@Value("${ftp.control.encoding:UTF-8}")
128+
public void setFtpControlEncoding(String ftpControlEncoding) {
129+
setFtpControlEncodingValue(ftpControlEncoding);
130+
}
131+
132+
public static void setFtpControlEncodingValue(String ftpControlEncoding) {
97133
FTP_CONTROL_ENCODING = ftpControlEncoding;
98134
}
99135

100136
public static String getBaseUrl() {
101137
return BASE_URL;
102138
}
103139

104-
public static void setBaseUrl(String baseUrl) {
140+
@Value("${base.url:default}")
141+
public void setBaseUrl(String baseUrl) {
142+
setBaseUrlValue(baseUrl);
143+
}
144+
145+
public static void setBaseUrlValue(String baseUrl) {
105146
BASE_URL = baseUrl;
106147
}
107148

@@ -111,6 +152,10 @@ public static String getFileDir() {
111152

112153
@Value("${file.dir:default}")
113154
public void setFileDir(String fileDir) {
155+
setFileDirValue(fileDir);
156+
}
157+
158+
public static void setFileDirValue(String fileDir) {
114159
if (!DEFAULT_FILE_DIR_VALUE.equals(fileDir.toLowerCase())) {
115160
if (!fileDir.endsWith(File.separator)) {
116161
fileDir = fileDir + File.separator;
@@ -120,11 +165,11 @@ public void setFileDir(String fileDir) {
120165
}
121166

122167
@Value("${trust.host:default}")
123-
public void setTrustHostStr(String trustHost) {
124-
setTrustHost(trustHost);
168+
public void setTrustHost(String trustHost) {
169+
setTrustHostValue(trustHost);
125170
}
126171

127-
public static void setTrustHost(String trustHost) {
172+
public static void setTrustHostValue(String trustHost) {
128173
CopyOnWriteArraySet<String> trustHostSet;
129174
if (DEFAULT_TRUST_HOST.equals(trustHost.toLowerCase())) {
130175
trustHostSet = new CopyOnWriteArraySet<>();
@@ -144,17 +189,17 @@ private static void setTrustHostSet(CopyOnWriteArraySet<String> trustHostSet) {
144189
ConfigConstants.TRUST_HOST_SET = trustHostSet;
145190
}
146191

147-
148192
public static String getPdfDownloadDisable() {
149193
return PDF_DOWNLOAD_DISABLE;
150194
}
151195

152-
public static void setPdfDownloadDisableValue(String pdfDownloadDisable) {
153-
PDF_DOWNLOAD_DISABLE = pdfDownloadDisable;
154-
}
155196

156197
@Value("${pdf.download.disable:true}")
157198
public void setPdfDownloadDisable(String pdfDownloadDisable) {
199+
setPdfDownloadDisableValue(pdfDownloadDisable);
200+
}
201+
public static void setPdfDownloadDisableValue(String pdfDownloadDisable) {
158202
PDF_DOWNLOAD_DISABLE = pdfDownloadDisable;
159203
}
204+
160205
}

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ void refresh() {
2727
configRefreshThread.start();
2828
}
2929

30-
class ConfigRefreshThread implements Runnable {
30+
static class ConfigRefreshThread implements Runnable {
3131
@Override
3232
public void run() {
3333
try {
3434
Properties properties = new Properties();
3535
String text;
3636
String media;
37-
Boolean cacheEnabled;
37+
boolean cacheEnabled;
3838
String[] textArray;
3939
String[] mediaArray;
4040
String officePreviewType;
@@ -50,7 +50,7 @@ public void run() {
5050
BufferedReader bufferedReader = new BufferedReader(fileReader);
5151
properties.load(bufferedReader);
5252
OfficeUtils.restorePropertiesFromEnvFormat(properties);
53-
cacheEnabled = new Boolean(properties.getProperty("cache.enabled", ConfigConstants.DEFAULT_CACHE_ENABLED));
53+
cacheEnabled = Boolean.parseBoolean(properties.getProperty("cache.enabled", ConfigConstants.DEFAULT_CACHE_ENABLED));
5454
text = properties.getProperty("simText", ConfigConstants.DEFAULT_TXT_TYPE);
5555
media = properties.getProperty("media", ConfigConstants.DEFAULT_MEDIA_TYPE);
5656
officePreviewType = properties.getProperty("office.preview.type", ConfigConstants.DEFAULT_OFFICE_PREVIEW_TYPE);
@@ -62,15 +62,15 @@ public void run() {
6262
baseUrl = properties.getProperty("base.url", ConfigConstants.DEFAULT_BASE_URL);
6363
trustHost = properties.getProperty("trust.host", ConfigConstants.DEFAULT_TRUST_HOST);
6464
pdfDownloadDisable = properties.getProperty("pdf.download.disable", ConfigConstants.DEFAULT_PDF_DOWNLOAD_DISABLE);
65-
ConfigConstants.setCacheEnabled(cacheEnabled);
66-
ConfigConstants.setSimText(textArray);
67-
ConfigConstants.setMedia(mediaArray);
68-
ConfigConstants.setOfficePreviewType(officePreviewType);
69-
ConfigConstants.setFtpUsername(ftpUsername);
70-
ConfigConstants.setFtpPassword(ftpPassword);
71-
ConfigConstants.setFtpControlEncoding(ftpControlEncoding);
72-
ConfigConstants.setBaseUrl(baseUrl);
73-
ConfigConstants.setTrustHost(trustHost);
65+
ConfigConstants.setCacheEnabledValueValue(cacheEnabled);
66+
ConfigConstants.setSimTextValue(textArray);
67+
ConfigConstants.setMediaValue(mediaArray);
68+
ConfigConstants.setOfficePreviewTypeValue(officePreviewType);
69+
ConfigConstants.setFtpUsernameValue(ftpUsername);
70+
ConfigConstants.setFtpPasswordValue(ftpPassword);
71+
ConfigConstants.setFtpControlEncodingValue(ftpControlEncoding);
72+
ConfigConstants.setBaseUrlValue(baseUrl);
73+
ConfigConstants.setTrustHostValue(trustHost);
7474
ConfigConstants.setPdfDownloadDisableValue(pdfDownloadDisable);
7575
setWatermarkConfig(properties);
7676
bufferedReader.close();

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
88

99
/**
10-
* @auther: chenjh
11-
* @time: 2019/4/16 20:04
12-
* @description
10+
* @author: chenjh
11+
* @since: 2019/4/16 20:04
1312
*/
1413
@Configuration
1514
public class WebConfig extends WebMvcConfigurerAdapter {

jodconverter-web/src/main/java/cn/keking/extend/ControlDocumentFormatRegistry.java

Lines changed: 4 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package cn.keking.extend;
22

3-
import com.google.common.collect.Maps;
4-
import com.sun.star.beans.PropertyValue;
53
import org.artofsolving.jodconverter.document.DocumentFamily;
64
import org.artofsolving.jodconverter.document.DocumentFormat;
75
import org.artofsolving.jodconverter.document.SimpleDocumentFormatRegistry;
@@ -42,7 +40,7 @@ public ControlDocumentFormatRegistry() {
4240
// available for exporting Spreadsheet and Presentation formats
4341
html.setInputFamily(DocumentFamily.TEXT);
4442
html.setStoreProperties(DocumentFamily.TEXT, Collections.singletonMap("FilterName", "HTML (StarWriter)"));
45-
Map<String,Object> htmlLoadAndStoreProperties = new LinkedHashMap<String,Object>();
43+
Map<String,Object> htmlLoadAndStoreProperties = new LinkedHashMap<>();
4644
htmlLoadAndStoreProperties.put("FilterName", "HTML (StarCalc)");
4745
htmlLoadAndStoreProperties.put("FilterOptions", "utf8");
4846
html.setStoreProperties(DocumentFamily.SPREADSHEET, htmlLoadAndStoreProperties);
@@ -79,7 +77,7 @@ public ControlDocumentFormatRegistry() {
7977

8078
DocumentFormat txt = new DocumentFormat("Plain Text", "txt", "text/plain");
8179
txt.setInputFamily(DocumentFamily.TEXT);
82-
Map<String,Object> txtLoadAndStoreProperties = new LinkedHashMap<String,Object>();
80+
Map<String,Object> txtLoadAndStoreProperties = new LinkedHashMap<>();
8381
txtLoadAndStoreProperties.put("FilterName", "Text (encoded)");
8482
txtLoadAndStoreProperties.put("FilterOptions", "utf8");
8583
txt.setLoadProperties(txtLoadAndStoreProperties);
@@ -111,7 +109,7 @@ public ControlDocumentFormatRegistry() {
111109

112110
DocumentFormat csv = new DocumentFormat("Comma Separated Values", "csv", "text/csv");
113111
csv.setInputFamily(DocumentFamily.SPREADSHEET);
114-
Map<String,Object> csvLoadAndStoreProperties = new LinkedHashMap<String,Object>();
112+
Map<String,Object> csvLoadAndStoreProperties = new LinkedHashMap<>();
115113
csvLoadAndStoreProperties.put("FilterName", "Text - txt - csv (StarCalc)");
116114
csvLoadAndStoreProperties.put("FilterOptions", "44,34,0"); // Field Separator: ','; Text Delimiter: '"'
117115
csv.setLoadProperties(csvLoadAndStoreProperties);
@@ -120,7 +118,7 @@ public ControlDocumentFormatRegistry() {
120118

121119
DocumentFormat tsv = new DocumentFormat("Tab Separated Values", "tsv", "text/tab-separated-values");
122120
tsv.setInputFamily(DocumentFamily.SPREADSHEET);
123-
Map<String,Object> tsvLoadAndStoreProperties = new LinkedHashMap<String,Object>();
121+
Map<String,Object> tsvLoadAndStoreProperties = new LinkedHashMap<>();
124122
tsvLoadAndStoreProperties.put("FilterName", "Text - txt - csv (StarCalc)");
125123
tsvLoadAndStoreProperties.put("FilterOptions", "9,34,0"); // Field Separator: '\t'; Text Delimiter: '"'
126124
tsv.setLoadProperties(tsvLoadAndStoreProperties);
@@ -156,56 +154,4 @@ public ControlDocumentFormatRegistry() {
156154
addFormat(svg);
157155
}
158156

159-
/**
160-
* 创建默认的导出属性
161-
* @return
162-
*/
163-
private PropertyValue[] getCommonPropertyValue() {
164-
PropertyValue[] aFilterData = new PropertyValue[11];
165-
// 不显示文档标题
166-
aFilterData[0] = new PropertyValue();
167-
aFilterData[0].Name = "DisplayPDFDocumentTitle";
168-
aFilterData[0].Value= true;
169-
// 导出文件编码方式
170-
aFilterData[1] = new PropertyValue();
171-
aFilterData[1].Name = "Encoding";
172-
aFilterData[1].Value= "UTF-8";
173-
// 隐藏工具条
174-
aFilterData[2] = new PropertyValue();
175-
aFilterData[2].Name = "HideViewerToolbar";
176-
aFilterData[2].Value= false;
177-
// 隐藏窗口控制条
178-
aFilterData[3] = new PropertyValue();
179-
aFilterData[3].Name = "HideViewerWindowControls";
180-
aFilterData[3].Value= true;
181-
// 全屏展示
182-
aFilterData[4] = new PropertyValue();
183-
aFilterData[4].Name = "OpenInFullScreenMode";
184-
aFilterData[4].Value= false;
185-
// 第一页左边展示
186-
aFilterData[5] = new PropertyValue();
187-
aFilterData[5].Name = "MathToMathType";
188-
aFilterData[5].Value= true;
189-
// 文档标题内容
190-
aFilterData[6] = new PropertyValue();
191-
aFilterData[6].Name = "Watermark";
192-
aFilterData[6].Value= "KEKING.CN";
193-
// 导出文件编码方式
194-
aFilterData[7] = new PropertyValue();
195-
aFilterData[7].Name = "CharacterSet";
196-
aFilterData[7].Value= "UTF-8";
197-
// 导出文件编码方式
198-
aFilterData[8] = new PropertyValue();
199-
aFilterData[8].Name = "Encoding";
200-
aFilterData[8].Value= "UTF-8";
201-
// 导出文件编码方式
202-
aFilterData[9] = new PropertyValue();
203-
aFilterData[9].Name = "CharSet";
204-
aFilterData[9].Value= "UTF-8";
205-
// 导出文件编码方式
206-
aFilterData[10] = new PropertyValue();
207-
aFilterData[10].Name = "charset";
208-
aFilterData[10].Value= "UTF-8";
209-
return aFilterData;
210-
}
211157
}

jodconverter-web/src/main/java/cn/keking/model/FileAttribute.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,14 @@ public class FileAttribute {
1414

1515
private String url;
1616

17-
private String decodedUrl;
18-
1917
public FileAttribute() {
2018
}
2119

22-
public FileAttribute(FileType type, String suffix, String name, String url, String decodedUrl) {
20+
public FileAttribute(FileType type, String suffix, String name, String url) {
2321
this.type = type;
2422
this.suffix = suffix;
2523
this.name = name;
2624
this.url = url;
27-
this.decodedUrl = decodedUrl;
2825
}
2926

3027
public FileType getType() {
@@ -58,12 +55,4 @@ public String getUrl() {
5855
public void setUrl(String url) {
5956
this.url = url;
6057
}
61-
62-
public String getDecodedUrl() {
63-
return decodedUrl;
64-
}
65-
66-
public void setDecodedUrl(String decodedUrl) {
67-
this.decodedUrl = decodedUrl;
68-
}
6958
}

0 commit comments

Comments
 (0)