Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
slm-fileview
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
梁杰芳
slm-fileview
Commits
180e7bcb
Commit
180e7bcb
authored
May 15, 2020
by
陈精华
Committed by
kl
May 18, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化:重构大量代码,修复异常
parent
8a524506
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
35 changed files
with
367 additions
and
501 deletions
+367
-501
application.properties
jodconverter-web/src/main/config/application.properties
+1
-1
ConfigConstants.java
...r-web/src/main/java/cn/keking/config/ConfigConstants.java
+65
-20
ConfigRefreshComponent.java
...rc/main/java/cn/keking/config/ConfigRefreshComponent.java
+12
-12
WebConfig.java
...nverter-web/src/main/java/cn/keking/config/WebConfig.java
+2
-3
ControlDocumentFormatRegistry.java
.../java/cn/keking/extend/ControlDocumentFormatRegistry.java
+4
-58
FileAttribute.java
...rter-web/src/main/java/cn/keking/model/FileAttribute.java
+1
-12
FileType.java
jodconverter-web/src/main/java/cn/keking/model/FileType.java
+2
-4
FileConvertQueueTask.java
...src/main/java/cn/keking/service/FileConvertQueueTask.java
+23
-16
FilePreviewFactory.java
...b/src/main/java/cn/keking/service/FilePreviewFactory.java
+4
-6
CacheService.java
...b/src/main/java/cn/keking/service/cache/CacheService.java
+9
-13
CacheServiceJDKImpl.java
...ava/cn/keking/service/cache/impl/CacheServiceJDKImpl.java
+2
-3
CacheServiceRedisImpl.java
...a/cn/keking/service/cache/impl/CacheServiceRedisImpl.java
+14
-20
CacheServiceRocksDBImpl.java
...cn/keking/service/cache/impl/CacheServiceRocksDBImpl.java
+22
-22
CadFilePreviewImpl.java
.../main/java/cn/keking/service/impl/CadFilePreviewImpl.java
+3
-15
OfficeFilePreviewImpl.java
...in/java/cn/keking/service/impl/OfficeFilePreviewImpl.java
+17
-13
PictureFilePreviewImpl.java
...n/java/cn/keking/service/impl/PictureFilePreviewImpl.java
+1
-2
SimTextFilePreviewImpl.java
...n/java/cn/keking/service/impl/SimTextFilePreviewImpl.java
+8
-11
CadToPdf.java
jodconverter-web/src/main/java/cn/keking/utils/CadToPdf.java
+1
-1
ConverterUtils.java
...ter-web/src/main/java/cn/keking/utils/ConverterUtils.java
+14
-17
DeleteFileUtil.java
...ter-web/src/main/java/cn/keking/utils/DeleteFileUtil.java
+9
-8
DownloadUtils.java
...rter-web/src/main/java/cn/keking/utils/DownloadUtils.java
+66
-33
FileUtils.java
...onverter-web/src/main/java/cn/keking/utils/FileUtils.java
+0
-0
FtpUtils.java
jodconverter-web/src/main/java/cn/keking/utils/FtpUtils.java
+2
-1
OfficeToPdf.java
...verter-web/src/main/java/cn/keking/utils/OfficeToPdf.java
+19
-67
PdfUtils.java
jodconverter-web/src/main/java/cn/keking/utils/PdfUtils.java
+19
-5
ShedulerClean.java
...rter-web/src/main/java/cn/keking/utils/ShedulerClean.java
+6
-4
SimTextUtil.java
...verter-web/src/main/java/cn/keking/utils/SimTextUtil.java
+0
-26
ZipReader.java
...onverter-web/src/main/java/cn/keking/utils/ZipReader.java
+0
-0
FileController.java
...rc/main/java/cn/keking/web/controller/FileController.java
+12
-35
IndexController.java
...c/main/java/cn/keking/web/controller/IndexController.java
+1
-1
OnlinePreviewController.java
...ava/cn/keking/web/controller/OnlinePreviewController.java
+22
-35
BaseUrlFilter.java
...web/src/main/java/cn/keking/web/filter/BaseUrlFilter.java
+1
-1
ChinesePathFilter.java
...src/main/java/cn/keking/web/filter/ChinesePathFilter.java
+1
-32
TrustHostFilter.java
...b/src/main/java/cn/keking/web/filter/TrustHostFilter.java
+3
-3
WatermarkConfigFilter.java
...main/java/cn/keking/web/filter/WatermarkConfigFilter.java
+1
-1
No files found.
jodconverter-web/src/main/config/application.properties
View file @
180e7bcb
...
...
@@ -48,7 +48,7 @@ trust.host = ${KK_TRUST_HOST:default}
cache.enabled
=
${KK_CACHE_ENABLED:true}
#文本类型,默认如下,可自定义添加
simText
=
${KK_SIMTEXT:txt,html,htm,asp,jsp,xml,json,properties,md,gitignore,,java,py,c,cpp,sql,sh,bat,m,bas,prg,cmd}
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}
#多媒体类型,默认如下,可自定义添加
media
=
${KK_MEDIA:mp3,wav,mp4,flv}
#office类型文档(word ppt)样式,默认为图片(image),可配置为pdf(预览时也有按钮切换)
...
...
jodconverter-web/src/main/java/cn/keking/config/ConfigConstants.java
View file @
180e7bcb
...
...
@@ -10,9 +10,8 @@ import java.util.concurrent.CopyOnWriteArraySet;
import
java.util.Set
;
/**
* @auther: chenjh
* @time: 2019/4/10 17:22
* @description
* @author: chenjh
* @since: 2019/4/10 17:22
*/
@Component
public
class
ConfigConstants
{
...
...
@@ -30,7 +29,7 @@ public class ConfigConstants {
private
static
String
PDF_DOWNLOAD_DISABLE
;
public
static
final
String
DEFAULT_CACHE_ENABLED
=
"true"
;
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"
;
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"
;
public
static
final
String
DEFAULT_MEDIA_TYPE
=
"mp3,wav,mp4,flv"
;
public
static
final
String
DEFAULT_OFFICE_PREVIEW_TYPE
=
"image"
;
public
static
final
String
DEFAULT_FTP_USERNAME
=
null
;
...
...
@@ -45,7 +44,12 @@ public class ConfigConstants {
return
CACHE_ENABLED
;
}
public
static
void
setCacheEnabled
(
Boolean
cacheEnabled
)
{
@Value
(
"${cache.enabled:true}"
)
public
static
void
setCacheEnabled
(
String
cacheEnabled
)
{
setCacheEnabledValueValue
(
Boolean
.
parseBoolean
(
cacheEnabled
));
}
public
static
void
setCacheEnabledValueValue
(
Boolean
cacheEnabled
)
{
CACHE_ENABLED
=
cacheEnabled
;
}
...
...
@@ -53,7 +57,13 @@ public class ConfigConstants {
return
SIM_TEXT
;
}
public
static
void
setSimText
(
String
[]
simText
)
{
@Value
(
"${simText:txt,html,htm,asp,jsp,xml,json,properties,md,gitignore,log,java,py,c,cpp,sql,sh,bat,m,bas,prg,cmd}"
)
public
void
setSimText
(
String
simText
)
{
String
[]
simTextArr
=
simText
.
split
(
","
);
setSimTextValue
(
simTextArr
);
}
public
static
void
setSimTextValue
(
String
[]
simText
)
{
SIM_TEXT
=
simText
;
}
...
...
@@ -61,15 +71,26 @@ public class ConfigConstants {
return
MEDIA
;
}
public
static
void
setMedia
(
String
[]
Media
)
{
ConfigConstants
.
MEDIA
=
Media
;
@Value
(
"${media:mp3,wav,mp4,flv}"
)
public
void
setMedia
(
String
media
)
{
String
[]
mediaArr
=
media
.
split
(
","
);
setMediaValue
(
mediaArr
);
}
public
static
void
setMediaValue
(
String
[]
Media
)
{
MEDIA
=
Media
;
}
public
static
String
getOfficePreviewType
()
{
return
OFFICE_PREVIEW_TYPE
;
}
public
static
void
setOfficePreviewType
(
String
officePreviewType
)
{
@Value
(
"${office.preview.type:image}"
)
public
void
setOfficePreviewType
(
String
officePreviewType
)
{
setOfficePreviewTypeValue
(
officePreviewType
);
}
public
static
void
setOfficePreviewTypeValue
(
String
officePreviewType
)
{
OFFICE_PREVIEW_TYPE
=
officePreviewType
;
}
...
...
@@ -77,7 +98,12 @@ public class ConfigConstants {
return
FTP_USERNAME
;
}
public
static
void
setFtpUsername
(
String
ftpUsername
)
{
@Value
(
"${ftp.username:}"
)
public
void
setFtpUsername
(
String
ftpUsername
)
{
setFtpUsernameValue
(
ftpUsername
);
}
public
static
void
setFtpUsernameValue
(
String
ftpUsername
)
{
FTP_USERNAME
=
ftpUsername
;
}
...
...
@@ -85,7 +111,12 @@ public class ConfigConstants {
return
FTP_PASSWORD
;
}
public
static
void
setFtpPassword
(
String
ftpPassword
)
{
@Value
(
"${ftp.password:}"
)
public
void
setFtpPassword
(
String
ftpPassword
)
{
setFtpPasswordValue
(
ftpPassword
);
}
public
static
void
setFtpPasswordValue
(
String
ftpPassword
)
{
FTP_PASSWORD
=
ftpPassword
;
}
...
...
@@ -93,7 +124,12 @@ public class ConfigConstants {
return
FTP_CONTROL_ENCODING
;
}
public
static
void
setFtpControlEncoding
(
String
ftpControlEncoding
)
{
@Value
(
"${ftp.control.encoding:UTF-8}"
)
public
void
setFtpControlEncoding
(
String
ftpControlEncoding
)
{
setFtpControlEncodingValue
(
ftpControlEncoding
);
}
public
static
void
setFtpControlEncodingValue
(
String
ftpControlEncoding
)
{
FTP_CONTROL_ENCODING
=
ftpControlEncoding
;
}
...
...
@@ -101,7 +137,12 @@ public class ConfigConstants {
return
BASE_URL
;
}
public
static
void
setBaseUrl
(
String
baseUrl
)
{
@Value
(
"${base.url:default}"
)
public
void
setBaseUrl
(
String
baseUrl
)
{
setBaseUrlValue
(
baseUrl
);
}
public
static
void
setBaseUrlValue
(
String
baseUrl
)
{
BASE_URL
=
baseUrl
;
}
...
...
@@ -111,6 +152,10 @@ public class ConfigConstants {
@Value
(
"${file.dir:default}"
)
public
void
setFileDir
(
String
fileDir
)
{
setFileDirValue
(
fileDir
);
}
public
static
void
setFileDirValue
(
String
fileDir
)
{
if
(!
DEFAULT_FILE_DIR_VALUE
.
equals
(
fileDir
.
toLowerCase
()))
{
if
(!
fileDir
.
endsWith
(
File
.
separator
))
{
fileDir
=
fileDir
+
File
.
separator
;
...
...
@@ -120,11 +165,11 @@ public class ConfigConstants {
}
@Value
(
"${trust.host:default}"
)
public
void
setTrustHost
Str
(
String
trustHost
)
{
setTrustHost
(
trustHost
);
public
void
setTrustHost
(
String
trustHost
)
{
setTrustHost
Value
(
trustHost
);
}
public
static
void
setTrustHost
(
String
trustHost
)
{
public
static
void
setTrustHost
Value
(
String
trustHost
)
{
CopyOnWriteArraySet
<
String
>
trustHostSet
;
if
(
DEFAULT_TRUST_HOST
.
equals
(
trustHost
.
toLowerCase
()))
{
trustHostSet
=
new
CopyOnWriteArraySet
<>();
...
...
@@ -144,17 +189,17 @@ public class ConfigConstants {
ConfigConstants
.
TRUST_HOST_SET
=
trustHostSet
;
}
public
static
String
getPdfDownloadDisable
()
{
return
PDF_DOWNLOAD_DISABLE
;
}
public
static
void
setPdfDownloadDisableValue
(
String
pdfDownloadDisable
)
{
PDF_DOWNLOAD_DISABLE
=
pdfDownloadDisable
;
}
@Value
(
"${pdf.download.disable:true}"
)
public
void
setPdfDownloadDisable
(
String
pdfDownloadDisable
)
{
setPdfDownloadDisableValue
(
pdfDownloadDisable
);
}
public
static
void
setPdfDownloadDisableValue
(
String
pdfDownloadDisable
)
{
PDF_DOWNLOAD_DISABLE
=
pdfDownloadDisable
;
}
}
jodconverter-web/src/main/java/cn/keking/config/ConfigRefreshComponent.java
View file @
180e7bcb
...
...
@@ -27,14 +27,14 @@ public class ConfigRefreshComponent {
configRefreshThread
.
start
();
}
class
ConfigRefreshThread
implements
Runnable
{
static
class
ConfigRefreshThread
implements
Runnable
{
@Override
public
void
run
()
{
try
{
Properties
properties
=
new
Properties
();
String
text
;
String
media
;
B
oolean
cacheEnabled
;
b
oolean
cacheEnabled
;
String
[]
textArray
;
String
[]
mediaArray
;
String
officePreviewType
;
...
...
@@ -50,7 +50,7 @@ public class ConfigRefreshComponent {
BufferedReader
bufferedReader
=
new
BufferedReader
(
fileReader
);
properties
.
load
(
bufferedReader
);
OfficeUtils
.
restorePropertiesFromEnvFormat
(
properties
);
cacheEnabled
=
new
Boolean
(
properties
.
getProperty
(
"cache.enabled"
,
ConfigConstants
.
DEFAULT_CACHE_ENABLED
));
cacheEnabled
=
Boolean
.
parse
Boolean
(
properties
.
getProperty
(
"cache.enabled"
,
ConfigConstants
.
DEFAULT_CACHE_ENABLED
));
text
=
properties
.
getProperty
(
"simText"
,
ConfigConstants
.
DEFAULT_TXT_TYPE
);
media
=
properties
.
getProperty
(
"media"
,
ConfigConstants
.
DEFAULT_MEDIA_TYPE
);
officePreviewType
=
properties
.
getProperty
(
"office.preview.type"
,
ConfigConstants
.
DEFAULT_OFFICE_PREVIEW_TYPE
);
...
...
@@ -62,15 +62,15 @@ public class ConfigRefreshComponent {
baseUrl
=
properties
.
getProperty
(
"base.url"
,
ConfigConstants
.
DEFAULT_BASE_URL
);
trustHost
=
properties
.
getProperty
(
"trust.host"
,
ConfigConstants
.
DEFAULT_TRUST_HOST
);
pdfDownloadDisable
=
properties
.
getProperty
(
"pdf.download.disable"
,
ConfigConstants
.
DEFAULT_PDF_DOWNLOAD_DISABLE
);
ConfigConstants
.
setCacheEnabled
(
cacheEnabled
);
ConfigConstants
.
setSimText
(
textArray
);
ConfigConstants
.
setMedia
(
mediaArray
);
ConfigConstants
.
setOfficePreviewType
(
officePreviewType
);
ConfigConstants
.
setFtpUsername
(
ftpUsername
);
ConfigConstants
.
setFtpPassword
(
ftpPassword
);
ConfigConstants
.
setFtpControlEncoding
(
ftpControlEncoding
);
ConfigConstants
.
setBaseUrl
(
baseUrl
);
ConfigConstants
.
setTrustHost
(
trustHost
);
ConfigConstants
.
setCacheEnabled
ValueValue
(
cacheEnabled
);
ConfigConstants
.
setSimText
Value
(
textArray
);
ConfigConstants
.
setMedia
Value
(
mediaArray
);
ConfigConstants
.
setOfficePreviewType
Value
(
officePreviewType
);
ConfigConstants
.
setFtpUsername
Value
(
ftpUsername
);
ConfigConstants
.
setFtpPassword
Value
(
ftpPassword
);
ConfigConstants
.
setFtpControlEncoding
Value
(
ftpControlEncoding
);
ConfigConstants
.
setBaseUrl
Value
(
baseUrl
);
ConfigConstants
.
setTrustHost
Value
(
trustHost
);
ConfigConstants
.
setPdfDownloadDisableValue
(
pdfDownloadDisable
);
setWatermarkConfig
(
properties
);
bufferedReader
.
close
();
...
...
jodconverter-web/src/main/java/cn/keking/config/WebConfig.java
View file @
180e7bcb
...
...
@@ -7,9 +7,8 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
;
/**
* @auther: chenjh
* @time: 2019/4/16 20:04
* @description
* @author: chenjh
* @since: 2019/4/16 20:04
*/
@Configuration
public
class
WebConfig
extends
WebMvcConfigurerAdapter
{
...
...
jodconverter-web/src/main/java/cn/keking/extend/ControlDocumentFormatRegistry.java
View file @
180e7bcb
package
cn
.
keking
.
extend
;
import
com.google.common.collect.Maps
;
import
com.sun.star.beans.PropertyValue
;
import
org.artofsolving.jodconverter.document.DocumentFamily
;
import
org.artofsolving.jodconverter.document.DocumentFormat
;
import
org.artofsolving.jodconverter.document.SimpleDocumentFormatRegistry
;
...
...
@@ -42,7 +40,7 @@ public class ControlDocumentFormatRegistry extends SimpleDocumentFormatRegistry
// available for exporting Spreadsheet and Presentation formats
html
.
setInputFamily
(
DocumentFamily
.
TEXT
);
html
.
setStoreProperties
(
DocumentFamily
.
TEXT
,
Collections
.
singletonMap
(
"FilterName"
,
"HTML (StarWriter)"
));
Map
<
String
,
Object
>
htmlLoadAndStoreProperties
=
new
LinkedHashMap
<
String
,
Object
>();
Map
<
String
,
Object
>
htmlLoadAndStoreProperties
=
new
LinkedHashMap
<>();
htmlLoadAndStoreProperties
.
put
(
"FilterName"
,
"HTML (StarCalc)"
);
htmlLoadAndStoreProperties
.
put
(
"FilterOptions"
,
"utf8"
);
html
.
setStoreProperties
(
DocumentFamily
.
SPREADSHEET
,
htmlLoadAndStoreProperties
);
...
...
@@ -79,7 +77,7 @@ public class ControlDocumentFormatRegistry extends SimpleDocumentFormatRegistry
DocumentFormat
txt
=
new
DocumentFormat
(
"Plain Text"
,
"txt"
,
"text/plain"
);
txt
.
setInputFamily
(
DocumentFamily
.
TEXT
);
Map
<
String
,
Object
>
txtLoadAndStoreProperties
=
new
LinkedHashMap
<
String
,
Object
>();
Map
<
String
,
Object
>
txtLoadAndStoreProperties
=
new
LinkedHashMap
<>();
txtLoadAndStoreProperties
.
put
(
"FilterName"
,
"Text (encoded)"
);
txtLoadAndStoreProperties
.
put
(
"FilterOptions"
,
"utf8"
);
txt
.
setLoadProperties
(
txtLoadAndStoreProperties
);
...
...
@@ -111,7 +109,7 @@ public class ControlDocumentFormatRegistry extends SimpleDocumentFormatRegistry
DocumentFormat
csv
=
new
DocumentFormat
(
"Comma Separated Values"
,
"csv"
,
"text/csv"
);
csv
.
setInputFamily
(
DocumentFamily
.
SPREADSHEET
);
Map
<
String
,
Object
>
csvLoadAndStoreProperties
=
new
LinkedHashMap
<
String
,
Object
>();
Map
<
String
,
Object
>
csvLoadAndStoreProperties
=
new
LinkedHashMap
<>();
csvLoadAndStoreProperties
.
put
(
"FilterName"
,
"Text - txt - csv (StarCalc)"
);
csvLoadAndStoreProperties
.
put
(
"FilterOptions"
,
"44,34,0"
);
// Field Separator: ','; Text Delimiter: '"'
csv
.
setLoadProperties
(
csvLoadAndStoreProperties
);
...
...
@@ -120,7 +118,7 @@ public class ControlDocumentFormatRegistry extends SimpleDocumentFormatRegistry
DocumentFormat
tsv
=
new
DocumentFormat
(
"Tab Separated Values"
,
"tsv"
,
"text/tab-separated-values"
);
tsv
.
setInputFamily
(
DocumentFamily
.
SPREADSHEET
);
Map
<
String
,
Object
>
tsvLoadAndStoreProperties
=
new
LinkedHashMap
<
String
,
Object
>();
Map
<
String
,
Object
>
tsvLoadAndStoreProperties
=
new
LinkedHashMap
<>();
tsvLoadAndStoreProperties
.
put
(
"FilterName"
,
"Text - txt - csv (StarCalc)"
);
tsvLoadAndStoreProperties
.
put
(
"FilterOptions"
,
"9,34,0"
);
// Field Separator: '\t'; Text Delimiter: '"'
tsv
.
setLoadProperties
(
tsvLoadAndStoreProperties
);
...
...
@@ -156,56 +154,4 @@ public class ControlDocumentFormatRegistry extends SimpleDocumentFormatRegistry
addFormat
(
svg
);
}
/**
* 创建默认的导出属性
* @return
*/
private
PropertyValue
[]
getCommonPropertyValue
()
{
PropertyValue
[]
aFilterData
=
new
PropertyValue
[
11
];
// 不显示文档标题
aFilterData
[
0
]
=
new
PropertyValue
();
aFilterData
[
0
].
Name
=
"DisplayPDFDocumentTitle"
;
aFilterData
[
0
].
Value
=
true
;
// 导出文件编码方式
aFilterData
[
1
]
=
new
PropertyValue
();
aFilterData
[
1
].
Name
=
"Encoding"
;
aFilterData
[
1
].
Value
=
"UTF-8"
;
// 隐藏工具条
aFilterData
[
2
]
=
new
PropertyValue
();
aFilterData
[
2
].
Name
=
"HideViewerToolbar"
;
aFilterData
[
2
].
Value
=
false
;
// 隐藏窗口控制条
aFilterData
[
3
]
=
new
PropertyValue
();
aFilterData
[
3
].
Name
=
"HideViewerWindowControls"
;
aFilterData
[
3
].
Value
=
true
;
// 全屏展示
aFilterData
[
4
]
=
new
PropertyValue
();
aFilterData
[
4
].
Name
=
"OpenInFullScreenMode"
;
aFilterData
[
4
].
Value
=
false
;
// 第一页左边展示
aFilterData
[
5
]
=
new
PropertyValue
();
aFilterData
[
5
].
Name
=
"MathToMathType"
;
aFilterData
[
5
].
Value
=
true
;
// 文档标题内容
aFilterData
[
6
]
=
new
PropertyValue
();
aFilterData
[
6
].
Name
=
"Watermark"
;
aFilterData
[
6
].
Value
=
"KEKING.CN"
;
// 导出文件编码方式
aFilterData
[
7
]
=
new
PropertyValue
();
aFilterData
[
7
].
Name
=
"CharacterSet"
;
aFilterData
[
7
].
Value
=
"UTF-8"
;
// 导出文件编码方式
aFilterData
[
8
]
=
new
PropertyValue
();
aFilterData
[
8
].
Name
=
"Encoding"
;
aFilterData
[
8
].
Value
=
"UTF-8"
;
// 导出文件编码方式
aFilterData
[
9
]
=
new
PropertyValue
();
aFilterData
[
9
].
Name
=
"CharSet"
;
aFilterData
[
9
].
Value
=
"UTF-8"
;
// 导出文件编码方式
aFilterData
[
10
]
=
new
PropertyValue
();
aFilterData
[
10
].
Name
=
"charset"
;
aFilterData
[
10
].
Value
=
"UTF-8"
;
return
aFilterData
;
}
}
jodconverter-web/src/main/java/cn/keking/model/FileAttribute.java
View file @
180e7bcb
...
...
@@ -14,17 +14,14 @@ public class FileAttribute {
private
String
url
;
private
String
decodedUrl
;
public
FileAttribute
()
{
}
public
FileAttribute
(
FileType
type
,
String
suffix
,
String
name
,
String
url
,
String
decodedUrl
)
{
public
FileAttribute
(
FileType
type
,
String
suffix
,
String
name
,
String
url
)
{
this
.
type
=
type
;
this
.
suffix
=
suffix
;
this
.
name
=
name
;
this
.
url
=
url
;
this
.
decodedUrl
=
decodedUrl
;
}
public
FileType
getType
()
{
...
...
@@ -58,12 +55,4 @@ public class FileAttribute {
public
void
setUrl
(
String
url
)
{
this
.
url
=
url
;
}
public
String
getDecodedUrl
()
{
return
decodedUrl
;
}
public
void
setDecodedUrl
(
String
decodedUrl
)
{
this
.
decodedUrl
=
decodedUrl
;
}
}
jodconverter-web/src/main/java/cn/keking/model/FileType.java
View file @
180e7bcb
...
...
@@ -14,7 +14,8 @@ public enum FileType {
media
(
"mediaFilePreviewImpl"
),
cad
(
"cadFilePreviewImpl"
);
private
String
instanceName
;
private
final
String
instanceName
;
FileType
(
String
instanceName
){
this
.
instanceName
=
instanceName
;
}
...
...
@@ -23,7 +24,4 @@ public enum FileType {
return
instanceName
;
}
public
void
setInstanceName
(
String
instanceName
)
{
this
.
instanceName
=
instanceName
;
}
}
jodconverter-web/src/main/java/cn/keking/service/FileConverQueueTask.java
→
jodconverter-web/src/main/java/cn/keking/service/FileConver
t
QueueTask.java
View file @
180e7bcb
...
...
@@ -6,7 +6,6 @@ import cn.keking.service.cache.CacheService;
import
cn.keking.utils.FileUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.ui.ExtendedModelMap
;
import
javax.annotation.PostConstruct
;
...
...
@@ -18,36 +17,44 @@ import java.util.concurrent.Executors;
* Content :消费队列中的转换文件
*/
@Service
public
class
FileConverQueueTask
{
public
class
FileConver
t
QueueTask
{
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
public
static
final
String
queueTaskName
=
"FileConverQueueTask"
;
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
getClass
());
@Autowired
FilePreviewFactory
previewFactory
;
private
final
FilePreviewFactory
previewFactory
;
@Autowired
CacheService
cacheService
;
private
final
CacheService
cacheService
;
@Autowired
FileUtils
fileUtils
;
private
final
FileUtils
fileUtils
;
public
FileConvertQueueTask
(
FilePreviewFactory
previewFactory
,
CacheService
cacheService
,
FileUtils
fileUtils
)
{
this
.
previewFactory
=
previewFactory
;
this
.
cacheService
=
cacheService
;
this
.
fileUtils
=
fileUtils
;
}
@PostConstruct
public
void
startTask
(){
ExecutorService
executorService
=
Executors
.
newFixedThreadPool
(
3
);
executorService
.
submit
(
new
ConverTask
(
previewFactory
,
cacheService
,
fileUtils
));
executorService
.
submit
(
new
Conver
t
Task
(
previewFactory
,
cacheService
,
fileUtils
));
logger
.
info
(
"队列处理文件转换任务启动完成 "
);
}
class
ConverTask
implements
Runnable
{
class
ConvertTask
implements
Runnable
{
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ConvertTask
.
class
);
FilePreviewFactory
previewFactory
;
private
final
FilePreviewFactory
previewFactory
;
CacheService
cacheService
;
private
final
CacheService
cacheService
;
FileUtils
fileUtils
;
private
final
FileUtils
fileUtils
;
public
ConverTask
(
FilePreviewFactory
previewFactory
,
CacheService
cacheService
,
FileUtils
fileUtils
)
{
public
ConvertTask
(
FilePreviewFactory
previewFactory
,
CacheService
cacheService
,
FileUtils
fileUtils
)
{
this
.
previewFactory
=
previewFactory
;
this
.
cacheService
=
cacheService
;
this
.
fileUtils
=
fileUtils
;
...
...
jodconverter-web/src/main/java/cn/keking/service/FilePreviewFactory.java
View file @
180e7bcb
package
cn
.
keking
.
service
;
import
cn.keking.model.FileAttribute
;
import
cn.keking.utils.FileUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.stereotype.Service
;
...
...
@@ -15,11 +13,11 @@ import java.util.Map;
@Service
public
class
FilePreviewFactory
{
@Autowired
FileUtils
fileUtils
;
private
final
ApplicationContext
context
;
@Autowired
ApplicationContext
context
;
public
FilePreviewFactory
(
ApplicationContext
context
)
{
this
.
context
=
context
;
}
public
FilePreview
get
(
FileAttribute
fileAttribute
)
{
Map
<
String
,
FilePreview
>
filePreviewMap
=
context
.
getBeansOfType
(
FilePreview
.
class
);
...
...
jodconverter-web/src/main/java/cn/keking/service/cache/CacheService.java
View file @
180e7bcb
...
...
@@ -4,19 +4,19 @@ import java.util.List;
import
java.util.Map
;
/**
* @auther: chenjh
* @time: 2019/4/2 16:45
* @description
* @author: chenjh
* @since: 2019/4/2 16:45
*/
public
interface
CacheService
{
final
String
REDIS_FILE_PREVIEW_PDF_KEY
=
"converted-preview-pdf-file"
;
final
String
REDIS_FILE_PREVIEW_IMGS_KEY
=
"converted-preview-imgs-file"
;
//压缩包内图片文件集合
final
String
REDIS_FILE_PREVIEW_PDF_IMGS_KEY
=
"converted-preview-pdfimgs-file"
;
String
FILE_PREVIEW_PDF_KEY
=
"converted-preview-pdf-file"
;
String
FILE_PREVIEW_IMGS_KEY
=
"converted-preview-imgs-file"
;
//压缩包内图片文件集合
String
FILE_PREVIEW_PDF_IMGS_KEY
=
"converted-preview-pdfimgs-file"
;
String
TASK_QUEUE_NAME
=
"convert-task"
;
final
Integer
DEFAULT_PDF_CAPACITY
=
500000
;
final
Integer
DEFAULT_IMG_CAPACITY
=
500000
;
final
Integer
DEFAULT_PDFIMG_CAPACITY
=
500000
;
Integer
DEFAULT_PDF_CAPACITY
=
500000
;
Integer
DEFAULT_IMG_CAPACITY
=
500000
;
Integer
DEFAULT_PDFIMG_CAPACITY
=
500000
;
void
initPDFCachePool
(
Integer
capacity
);
void
initIMGCachePool
(
Integer
capacity
);
...
...
@@ -29,12 +29,8 @@ public interface CacheService {
List
<
String
>
getImgCache
(
String
key
);
Integer
getPdfImageCache
(
String
key
);
void
putPdfImageCache
(
String
pdfFilePath
,
int
num
);
void
cleanCache
();
void
addQueueTask
(
String
url
);
String
takeQueueTask
()
throws
InterruptedException
;
}
jodconverter-web/src/main/java/cn/keking/service/cache/impl/CacheServiceJDKImpl.java
View file @
180e7bcb
...
...
@@ -3,7 +3,6 @@ package cn.keking.service.cache.impl;
import
cn.keking.service.cache.CacheService
;
import
com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap
;
import
com.googlecode.concurrentlinkedhashmap.Weighers
;
import
org.rocksdb.RocksDB
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
;
import
org.springframework.stereotype.Service
;
...
...
@@ -29,7 +28,7 @@ public class CacheServiceJDKImpl implements CacheService {
private
static
final
int
QUEUE_SIZE
=
500000
;
private
BlockingQueue
blockingQueue
=
new
ArrayBlockingQueue
(
QUEUE_SIZE
);
private
final
BlockingQueue
<
String
>
blockingQueue
=
new
ArrayBlockingQueue
<>
(
QUEUE_SIZE
);
@Override
public
void
initPDFCachePool
(
Integer
capacity
)
{
...
...
@@ -130,6 +129,6 @@ public class CacheServiceJDKImpl implements CacheService {
@Override
public
String
takeQueueTask
()
throws
InterruptedException
{
return
String
.
valueOf
(
blockingQueue
.
take
()
);
return
blockingQueue
.
take
(
);
}
}
jodconverter-web/src/main/java/cn/keking/service/cache/impl/CacheServiceRedisImpl.java
View file @
180e7bcb
package
cn
.
keking
.
service
.
cache
.
impl
;
import
cn.keking.service.FileConverQueueTask
;
import
cn.keking.service.cache.CacheService
;
import
org.redisson.Redisson
;
import
org.redisson.api.RBlockingQueue
;
import
org.redisson.api.RMapCache
;
import
org.redisson.api.RedissonClient
;
import
org.redisson.config.Config
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
;
import
org.springframework.stereotype.Service
;
...
...
@@ -23,16 +21,12 @@ import java.util.Map;
@Service
public
class
CacheServiceRedisImpl
implements
CacheService
{
private
Config
config
;
private
final
RedissonClient
redissonClient
;
@Autowired
public
CacheServiceRedisImpl
(
Config
config
)
{
this
.
config
=
config
;
this
.
redissonClient
=
Redisson
.
create
(
config
);
}
private
RedissonClient
redissonClient
;
@Override
public
void
initPDFCachePool
(
Integer
capacity
)
{
...
...
@@ -50,47 +44,47 @@ public class CacheServiceRedisImpl implements CacheService {
@Override
public
void
putPDFCache
(
String
key
,
String
value
)
{
RMapCache
<
String
,
String
>
convertedList
=
redissonClient
.
getMapCache
(
REDIS_
FILE_PREVIEW_PDF_KEY
);
RMapCache
<
String
,
String
>
convertedList
=
redissonClient
.
getMapCache
(
FILE_PREVIEW_PDF_KEY
);
convertedList
.
fastPut
(
key
,
value
);
}
@Override
public
void
putImgCache
(
String
key
,
List
<
String
>
value
)
{
RMapCache
<
String
,
List
<
String
>>
convertedList
=
redissonClient
.
getMapCache
(
REDIS_
FILE_PREVIEW_IMGS_KEY
);
RMapCache
<
String
,
List
<
String
>>
convertedList
=
redissonClient
.
getMapCache
(
FILE_PREVIEW_IMGS_KEY
);
convertedList
.
fastPut
(
key
,
value
);
}
@Override
public
Map
<
String
,
String
>
getPDFCache
()
{
return
redissonClient
.
getMapCache
(
REDIS_
FILE_PREVIEW_PDF_KEY
);
return
redissonClient
.
getMapCache
(
FILE_PREVIEW_PDF_KEY
);
}
@Override
public
String
getPDFCache
(
String
key
)
{
RMapCache
<
String
,
String
>
convertedList
=
redissonClient
.
getMapCache
(
REDIS_
FILE_PREVIEW_PDF_KEY
);
RMapCache
<
String
,
String
>
convertedList
=
redissonClient
.
getMapCache
(
FILE_PREVIEW_PDF_KEY
);
return
convertedList
.
get
(
key
);
}
@Override
public
Map
<
String
,
List
<
String
>>
getImgCache
()
{
return
redissonClient
.
getMapCache
(
REDIS_
FILE_PREVIEW_IMGS_KEY
);
return
redissonClient
.
getMapCache
(
FILE_PREVIEW_IMGS_KEY
);
}
@Override
public
List
<
String
>
getImgCache
(
String
key
)
{
RMapCache
<
String
,
List
<
String
>>
convertedList
=
redissonClient
.
getMapCache
(
REDIS_
FILE_PREVIEW_IMGS_KEY
);
RMapCache
<
String
,
List
<
String
>>
convertedList
=
redissonClient
.
getMapCache
(
FILE_PREVIEW_IMGS_KEY
);
return
convertedList
.
get
(
key
);
}
@Override
public
Integer
getPdfImageCache
(
String
key
)
{
RMapCache
<
String
,
Integer
>
convertedList
=
redissonClient
.
getMapCache
(
REDIS_
FILE_PREVIEW_PDF_IMGS_KEY
);
RMapCache
<
String
,
Integer
>
convertedList
=
redissonClient
.
getMapCache
(
FILE_PREVIEW_PDF_IMGS_KEY
);
return
convertedList
.
get
(
key
);
}
@Override
public
void
putPdfImageCache
(
String
pdfFilePath
,
int
num
)
{
RMapCache
<
String
,
Integer
>
convertedList
=
redissonClient
.
getMapCache
(
REDIS_
FILE_PREVIEW_PDF_IMGS_KEY
);
RMapCache
<
String
,
Integer
>
convertedList
=
redissonClient
.
getMapCache
(
FILE_PREVIEW_PDF_IMGS_KEY
);
convertedList
.
fastPut
(
pdfFilePath
,
num
);
}
...
...
@@ -103,28 +97,28 @@ public class CacheServiceRedisImpl implements CacheService {
@Override
public
void
addQueueTask
(
String
url
)
{
RBlockingQueue
<
String
>
queue
=
redissonClient
.
getBlockingQueue
(
FileConverQueueTask
.
queueTaskName
);
RBlockingQueue
<
String
>
queue
=
redissonClient
.
getBlockingQueue
(
TASK_QUEUE_NAME
);
queue
.
addAsync
(
url
);
}
@Override
public
String
takeQueueTask
()
throws
InterruptedException
{
RBlockingQueue
<
String
>
queue
=
redissonClient
.
getBlockingQueue
(
FileConverQueueTask
.
queueTaskName
);
RBlockingQueue
<
String
>
queue
=
redissonClient
.
getBlockingQueue
(
TASK_QUEUE_NAME
);
return
queue
.
take
();
}
private
void
cleanPdfCache
()
{
RMapCache
<
String
,
String
>
pdfCache
=
redissonClient
.
getMapCache
(
REDIS_
FILE_PREVIEW_PDF_KEY
);
RMapCache
<
String
,
String
>
pdfCache
=
redissonClient
.
getMapCache
(
FILE_PREVIEW_PDF_KEY
);
pdfCache
.
clear
();
}
private
void
cleanImgCache
()
{
RMapCache
<
String
,
List
<
String
>>
imgCache
=
redissonClient
.
getMapCache
(
REDIS_
FILE_PREVIEW_IMGS_KEY
);
RMapCache
<
String
,
List
<
String
>>
imgCache
=
redissonClient
.
getMapCache
(
FILE_PREVIEW_IMGS_KEY
);
imgCache
.
clear
();
}
private
void
cleanPdfImgCache
()
{
RMapCache
<
String
,
Integer
>
pdfImg
=
redissonClient
.
getMapCache
(
REDIS_
FILE_PREVIEW_PDF_IMGS_KEY
);
RMapCache
<
String
,
Integer
>
pdfImg
=
redissonClient
.
getMapCache
(
FILE_PREVIEW_PDF_IMGS_KEY
);
pdfImg
.
clear
();
}
}
jodconverter-web/src/main/java/cn/keking/service/cache/impl/CacheServiceRocksDBImpl.java
View file @
180e7bcb
...
...
@@ -36,24 +36,24 @@ public class CacheServiceRocksDBImpl implements CacheService {
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
CacheServiceRocksDBImpl
.
class
);
private
BlockingQueue
blockingQueue
=
new
ArrayBlockingQueue
(
QUEUE_SIZE
);
private
final
BlockingQueue
<
String
>
blockingQueue
=
new
ArrayBlockingQueue
<>
(
QUEUE_SIZE
);
private
RocksDB
db
;
{
try
{
db
=
RocksDB
.
open
(
DB_PATH
);
if
(
db
.
get
(
REDIS_
FILE_PREVIEW_PDF_KEY
.
getBytes
())
==
null
)
{
if
(
db
.
get
(
FILE_PREVIEW_PDF_KEY
.
getBytes
())
==
null
)
{
Map
<
String
,
String
>
initPDFCache
=
new
HashMap
<>();
db
.
put
(
REDIS_
FILE_PREVIEW_PDF_KEY
.
getBytes
(),
toByteArray
(
initPDFCache
));
db
.
put
(
FILE_PREVIEW_PDF_KEY
.
getBytes
(),
toByteArray
(
initPDFCache
));
}
if
(
db
.
get
(
REDIS_
FILE_PREVIEW_IMGS_KEY
.
getBytes
())
==
null
)
{
if
(
db
.
get
(
FILE_PREVIEW_IMGS_KEY
.
getBytes
())
==
null
)
{
Map
<
String
,
List
<
String
>>
initIMGCache
=
new
HashMap
<>();
db
.
put
(
REDIS_
FILE_PREVIEW_IMGS_KEY
.
getBytes
(),
toByteArray
(
initIMGCache
));
db
.
put
(
FILE_PREVIEW_IMGS_KEY
.
getBytes
(),
toByteArray
(
initIMGCache
));
}
if
(
db
.
get
(
REDIS_
FILE_PREVIEW_PDF_IMGS_KEY
.
getBytes
())
==
null
)
{
if
(
db
.
get
(
FILE_PREVIEW_PDF_IMGS_KEY
.
getBytes
())
==
null
)
{
Map
<
String
,
Integer
>
initPDFIMGCache
=
new
HashMap
<>();
db
.
put
(
REDIS_
FILE_PREVIEW_PDF_IMGS_KEY
.
getBytes
(),
toByteArray
(
initPDFIMGCache
));
db
.
put
(
FILE_PREVIEW_PDF_IMGS_KEY
.
getBytes
(),
toByteArray
(
initPDFIMGCache
));
}
}
catch
(
RocksDBException
|
IOException
e
)
{
LOGGER
.
error
(
"Uable to init RocksDB"
+
e
);
...
...
@@ -81,7 +81,7 @@ public class CacheServiceRocksDBImpl implements CacheService {
try
{
Map
<
String
,
String
>
pdfCacheItem
=
getPDFCache
();
pdfCacheItem
.
put
(
key
,
value
);
db
.
put
(
REDIS_
FILE_PREVIEW_PDF_KEY
.
getBytes
(),
toByteArray
(
pdfCacheItem
));
db
.
put
(
FILE_PREVIEW_PDF_KEY
.
getBytes
(),
toByteArray
(
pdfCacheItem
));
}
catch
(
RocksDBException
|
IOException
e
)
{
LOGGER
.
error
(
"Put into RocksDB Exception"
+
e
);
}
...
...
@@ -92,7 +92,7 @@ public class CacheServiceRocksDBImpl implements CacheService {
try
{
Map
<
String
,
List
<
String
>>
imgCacheItem
=
getImgCache
();
imgCacheItem
.
put
(
key
,
value
);
db
.
put
(
REDIS_
FILE_PREVIEW_IMGS_KEY
.
getBytes
(),
toByteArray
(
imgCacheItem
));
db
.
put
(
FILE_PREVIEW_IMGS_KEY
.
getBytes
(),
toByteArray
(
imgCacheItem
));
}
catch
(
RocksDBException
|
IOException
e
)
{
LOGGER
.
error
(
"Put into RocksDB Exception"
+
e
);
}
...
...
@@ -102,7 +102,7 @@ public class CacheServiceRocksDBImpl implements CacheService {
public
Map
<
String
,
String
>
getPDFCache
()
{
Map
<
String
,
String
>
result
=
new
HashMap
<>();
try
{
result
=
(
Map
<
String
,
String
>)
toObject
(
db
.
get
(
REDIS_
FILE_PREVIEW_PDF_KEY
.
getBytes
()));
result
=
(
Map
<
String
,
String
>)
toObject
(
db
.
get
(
FILE_PREVIEW_PDF_KEY
.
getBytes
()));
}
catch
(
RocksDBException
|
IOException
|
ClassNotFoundException
e
)
{
LOGGER
.
error
(
"Get from RocksDB Exception"
+
e
);
}
...
...
@@ -113,7 +113,7 @@ public class CacheServiceRocksDBImpl implements CacheService {
public
String
getPDFCache
(
String
key
)
{
String
result
=
""
;
try
{
Map
<
String
,
String
>
map
=
(
Map
<
String
,
String
>)
toObject
(
db
.
get
(
REDIS_
FILE_PREVIEW_PDF_KEY
.
getBytes
()));
Map
<
String
,
String
>
map
=
(
Map
<
String
,
String
>)
toObject
(
db
.
get
(
FILE_PREVIEW_PDF_KEY
.
getBytes
()));
result
=
map
.
get
(
key
);
}
catch
(
RocksDBException
|
IOException
|
ClassNotFoundException
e
)
{
LOGGER
.
error
(
"Get from RocksDB Exception"
+
e
);
...
...
@@ -125,7 +125,7 @@ public class CacheServiceRocksDBImpl implements CacheService {
public
Map
<
String
,
List
<
String
>>
getImgCache
()
{
Map
<
String
,
List
<
String
>>
result
=
new
HashMap
<>();
try
{
result
=
(
Map
<
String
,
List
<
String
>>)
toObject
(
db
.
get
(
REDIS_
FILE_PREVIEW_IMGS_KEY
.
getBytes
()));
result
=
(
Map
<
String
,
List
<
String
>>)
toObject
(
db
.
get
(
FILE_PREVIEW_IMGS_KEY
.
getBytes
()));
}
catch
(
RocksDBException
|
IOException
|
ClassNotFoundException
e
)
{
LOGGER
.
error
(
"Get from RocksDB Exception"
+
e
);
}
...
...
@@ -137,7 +137,7 @@ public class CacheServiceRocksDBImpl implements CacheService {
List
<
String
>
result
=
new
ArrayList
<>();
Map
<
String
,
List
<
String
>>
map
;
try
{
map
=
(
Map
<
String
,
List
<
String
>>)
toObject
(
db
.
get
(
REDIS_
FILE_PREVIEW_IMGS_KEY
.
getBytes
()));
map
=
(
Map
<
String
,
List
<
String
>>)
toObject
(
db
.
get
(
FILE_PREVIEW_IMGS_KEY
.
getBytes
()));
result
=
map
.
get
(
key
);
}
catch
(
RocksDBException
|
IOException
|
ClassNotFoundException
e
)
{
LOGGER
.
error
(
"Get from RocksDB Exception"
+
e
);
...
...
@@ -148,7 +148,7 @@ public class CacheServiceRocksDBImpl implements CacheService {
public
Map
<
String
,
Integer
>
getPdfImageCaches
()
{
Map
<
String
,
Integer
>
map
=
new
HashMap
<>();
try
{
map
=
(
Map
<
String
,
Integer
>)
toObject
(
db
.
get
(
REDIS_
FILE_PREVIEW_PDF_IMGS_KEY
.
getBytes
()));
map
=
(
Map
<
String
,
Integer
>)
toObject
(
db
.
get
(
FILE_PREVIEW_PDF_IMGS_KEY
.
getBytes
()));
}
catch
(
RocksDBException
|
IOException
|
ClassNotFoundException
e
)
{
LOGGER
.
error
(
"Get from RocksDB Exception"
+
e
);
}
...
...
@@ -160,7 +160,7 @@ public class CacheServiceRocksDBImpl implements CacheService {
Integer
result
=
0
;
Map
<
String
,
Integer
>
map
;
try
{
map
=
(
Map
<
String
,
Integer
>)
toObject
(
db
.
get
(
REDIS_
FILE_PREVIEW_PDF_IMGS_KEY
.
getBytes
()));
map
=
(
Map
<
String
,
Integer
>)
toObject
(
db
.
get
(
FILE_PREVIEW_PDF_IMGS_KEY
.
getBytes
()));
result
=
map
.
get
(
key
);
}
catch
(
RocksDBException
|
IOException
|
ClassNotFoundException
e
)
{
LOGGER
.
error
(
"Get from RocksDB Exception"
+
e
);
...
...
@@ -173,7 +173,7 @@ public class CacheServiceRocksDBImpl implements CacheService {
try
{
Map
<
String
,
Integer
>
pdfImageCacheItem
=
getPdfImageCaches
();
pdfImageCacheItem
.
put
(
pdfFilePath
,
num
);
db
.
put
(
REDIS_
FILE_PREVIEW_PDF_IMGS_KEY
.
getBytes
(),
toByteArray
(
pdfImageCacheItem
));
db
.
put
(
FILE_PREVIEW_PDF_IMGS_KEY
.
getBytes
(),
toByteArray
(
pdfImageCacheItem
));
}
catch
(
RocksDBException
|
IOException
e
)
{
LOGGER
.
error
(
"Put into RocksDB Exception"
+
e
);
}
...
...
@@ -197,11 +197,11 @@ public class CacheServiceRocksDBImpl implements CacheService {
@Override
public
String
takeQueueTask
()
throws
InterruptedException
{
return
String
.
valueOf
(
blockingQueue
.
take
()
);
return
blockingQueue
.
take
(
);
}
private
byte
[]
toByteArray
(
Object
obj
)
throws
IOException
{
byte
[]
bytes
=
null
;
byte
[]
bytes
;
ByteArrayOutputStream
bos
=
new
ByteArrayOutputStream
();
ObjectOutputStream
oos
=
new
ObjectOutputStream
(
bos
);
oos
.
writeObject
(
obj
);
...
...
@@ -213,7 +213,7 @@ public class CacheServiceRocksDBImpl implements CacheService {
}
private
Object
toObject
(
byte
[]
bytes
)
throws
IOException
,
ClassNotFoundException
{
Object
obj
=
null
;
Object
obj
;
ByteArrayInputStream
bis
=
new
ByteArrayInputStream
(
bytes
);
ObjectInputStream
ois
=
new
ObjectInputStream
(
bis
);
obj
=
ois
.
readObject
();
...
...
@@ -224,16 +224,16 @@ public class CacheServiceRocksDBImpl implements CacheService {
private
void
cleanPdfCache
()
throws
IOException
,
RocksDBException
{
Map
<
String
,
String
>
initPDFCache
=
new
HashMap
<>();
db
.
put
(
REDIS_
FILE_PREVIEW_PDF_KEY
.
getBytes
(),
toByteArray
(
initPDFCache
));
db
.
put
(
FILE_PREVIEW_PDF_KEY
.
getBytes
(),
toByteArray
(
initPDFCache
));
}
private
void
cleanImgCache
()
throws
IOException
,
RocksDBException
{
Map
<
String
,
List
<
String
>>
initIMGCache
=
new
HashMap
<>();
db
.
put
(
REDIS_
FILE_PREVIEW_IMGS_KEY
.
getBytes
(),
toByteArray
(
initIMGCache
));
db
.
put
(
FILE_PREVIEW_IMGS_KEY
.
getBytes
(),
toByteArray
(
initIMGCache
));
}
private
void
cleanPdfImgCache
()
throws
IOException
,
RocksDBException
{
Map
<
String
,
Integer
>
initPDFIMGCache
=
new
HashMap
<>();
db
.
put
(
REDIS_
FILE_PREVIEW_PDF_IMGS_KEY
.
getBytes
(),
toByteArray
(
initPDFIMGCache
));
db
.
put
(
FILE_PREVIEW_PDF_IMGS_KEY
.
getBytes
(),
toByteArray
(
initPDFIMGCache
));
}
}
jodconverter-web/src/main/java/cn/keking/service/impl/CadFilePreviewImpl.java
View file @
180e7bcb
...
...
@@ -14,7 +14,7 @@ import org.springframework.stereotype.Service;
import
org.springframework.ui.Model
;
import
org.springframework.util.StringUtils
;
import
java.util.List
;
import
static
cn
.
keking
.
service
.
impl
.
OfficeFilePreviewImpl
.
getPreviewType
;
/**
* @author chenjh
...
...
@@ -52,7 +52,7 @@ public class CadFilePreviewImpl implements FilePreview {
String
outFilePath
=
fileDir
+
pdfName
;
// 判断之前是否已转换过,如果转换过,直接返回,否则执行转换
if
(!
fileUtils
.
listConvertedFiles
().
containsKey
(
pdfName
)
||
!
ConfigConstants
.
isCacheEnabled
())
{
String
filePath
=
fileDir
+
fileName
;
String
filePath
;
ReturnResponse
<
String
>
response
=
downloadUtils
.
downLoad
(
fileAttribute
,
null
);
if
(
0
!=
response
.
getCode
())
{
model
.
addAttribute
(
"fileType"
,
suffix
);
...
...
@@ -74,19 +74,7 @@ public class CadFilePreviewImpl implements FilePreview {
}
}
if
(
baseUrl
!=
null
&&
(
OFFICE_PREVIEW_TYPE_IMAGE
.
equals
(
officePreviewType
)
||
OFFICE_PREVIEW_TYPE_ALLIMAGES
.
equals
(
officePreviewType
)))
{
List
<
String
>
imageUrls
=
pdfUtils
.
pdf2jpg
(
outFilePath
,
pdfName
,
baseUrl
);
if
(
imageUrls
==
null
||
imageUrls
.
size
()
<
1
)
{
model
.
addAttribute
(
"msg"
,
"office转图片异常,请联系管理员"
);
model
.
addAttribute
(
"fileType"
,
fileAttribute
.
getSuffix
());
return
"fileNotSupported"
;
}
model
.
addAttribute
(
"imgurls"
,
imageUrls
);
model
.
addAttribute
(
"currentUrl"
,
imageUrls
.
get
(
0
));
if
(
OFFICE_PREVIEW_TYPE_IMAGE
.
equals
(
officePreviewType
))
{
return
"officePicture"
;
}
else
{
return
"picture"
;
}
return
getPreviewType
(
model
,
fileAttribute
,
officePreviewType
,
baseUrl
,
pdfName
,
outFilePath
,
pdfUtils
,
OFFICE_PREVIEW_TYPE_IMAGE
);
}
model
.
addAttribute
(
"pdfUrl"
,
pdfName
);
return
"pdf"
;
...
...
jodconverter-web/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java
View file @
180e7bcb
...
...
@@ -74,21 +74,25 @@ public class OfficeFilePreviewImpl implements FilePreview {
}
}
if
(!
isHtml
&&
baseUrl
!=
null
&&
(
OFFICE_PREVIEW_TYPE_IMAGE
.
equals
(
officePreviewType
)
||
OFFICE_PREVIEW_TYPE_ALLIMAGES
.
equals
(
officePreviewType
)))
{
List
<
String
>
imageUrls
=
pdfUtils
.
pdf2jpg
(
outFilePath
,
pdfName
,
baseUrl
);
if
(
imageUrls
==
null
||
imageUrls
.
size
()
<
1
)
{
model
.
addAttribute
(
"msg"
,
"office转图片异常,请联系管理员"
);
model
.
addAttribute
(
"fileType"
,
fileAttribute
.
getSuffix
());
return
"fileNotSupported"
;
}
model
.
addAttribute
(
"imgurls"
,
imageUrls
);
model
.
addAttribute
(
"currentUrl"
,
imageUrls
.
get
(
0
));
if
(
OFFICE_PREVIEW_TYPE_IMAGE
.
equals
(
officePreviewType
))
{
return
"officePicture"
;
}
else
{
return
"picture"
;
}
return
getPreviewType
(
model
,
fileAttribute
,
officePreviewType
,
baseUrl
,
pdfName
,
outFilePath
,
pdfUtils
,
OFFICE_PREVIEW_TYPE_IMAGE
);
}
model
.
addAttribute
(
"pdfUrl"
,
pdfName
);
return
isHtml
?
"html"
:
"pdf"
;
}
static
String
getPreviewType
(
Model
model
,
FileAttribute
fileAttribute
,
String
officePreviewType
,
String
baseUrl
,
String
pdfName
,
String
outFilePath
,
PdfUtils
pdfUtils
,
String
officePreviewTypeImage
)
{
List
<
String
>
imageUrls
=
pdfUtils
.
pdf2jpg
(
outFilePath
,
pdfName
,
baseUrl
);
if
(
imageUrls
==
null
||
imageUrls
.
size
()
<
1
)
{
model
.
addAttribute
(
"msg"
,
"office转图片异常,请联系管理员"
);
model
.
addAttribute
(
"fileType"
,
fileAttribute
.
getSuffix
());
return
"fileNotSupported"
;
}
model
.
addAttribute
(
"imgurls"
,
imageUrls
);
model
.
addAttribute
(
"currentUrl"
,
imageUrls
.
get
(
0
));
if
(
officePreviewTypeImage
.
equals
(
officePreviewType
))
{
return
"officePicture"
;
}
else
{
return
"picture"
;
}
}
}
jodconverter-web/src/main/java/cn/keking/service/impl/PictureFilePreviewImpl.java
View file @
180e7bcb
package
cn
.
keking
.
service
.
impl
;
import
cn.keking.config.ConfigConstants
;
import
cn.keking.model.FileAttribute
;
import
cn.keking.model.ReturnResponse
;
import
cn.keking.service.FilePreview
;
...
...
@@ -30,7 +29,7 @@ public class PictureFilePreviewImpl implements FilePreview {
@Override
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
String
fileKey
=
(
String
)
RequestContextHolder
.
currentRequestAttributes
().
getAttribute
(
"fileKey"
,
0
);
List
imgUrls
=
Lists
.
newArrayList
(
url
);
List
<
String
>
imgUrls
=
Lists
.
newArrayList
(
url
);
try
{
imgUrls
.
clear
();
imgUrls
.
addAll
(
fileUtils
.
getImgCache
(
fileKey
));
...
...
jodconverter-web/src/main/java/cn/keking/service/impl/SimTextFilePreviewImpl.java
View file @
180e7bcb
...
...
@@ -3,9 +3,7 @@ package cn.keking.service.impl;
import
cn.keking.model.FileAttribute
;
import
cn.keking.model.ReturnResponse
;
import
cn.keking.service.FilePreview
;
import
cn.keking.utils.FileUtils
;
import
cn.keking.utils.SimTextUtil
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
cn.keking.utils.DownloadUtils
;
import
org.springframework.stereotype.Service
;
import
org.springframework.ui.Model
;
...
...
@@ -18,19 +16,18 @@ import java.nio.file.Files;
* Content :处理文本文件
*/
@Service
public
class
SimTextFilePreviewImpl
implements
FilePreview
{
public
class
SimTextFilePreviewImpl
implements
FilePreview
{
@Autowired
SimTextUtil
simTextUtil
;
private
final
DownloadUtils
downloadUtils
;
@Autowired
FileUtils
fileUtils
;
public
SimTextFilePreviewImpl
(
DownloadUtils
downloadUtils
)
{
this
.
downloadUtils
=
downloadUtils
;
}
@Override
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
){
String
decodedUrl
=
fileAttribute
.
getDecodedUrl
();
String
fileName
=
fileAttribute
.
getName
();
ReturnResponse
<
String
>
response
=
simTextUtil
.
readSimText
(
decodedUrl
,
fileName
);
String
fileName
=
fileAttribute
.
getName
();
ReturnResponse
<
String
>
response
=
downloadUtils
.
downLoad
(
fileAttribute
,
fileName
);
if
(
0
!=
response
.
getCode
())
{
model
.
addAttribute
(
"msg"
,
response
.
getMsg
());
model
.
addAttribute
(
"fileType"
,
fileAttribute
.
getSuffix
());
...
...
jodconverter-web/src/main/java/cn/keking/utils/CadToPdf.java
View file @
180e7bcb
...
...
@@ -36,7 +36,7 @@ public class CadToPdf {
PdfOptions
pdfOptions
=
new
PdfOptions
();
pdfOptions
.
setVectorRasterizationOptions
(
cadRasterizationOptions
);
File
outputFile
=
new
File
(
outputFilePath
);
OutputStream
stream
=
null
;
OutputStream
stream
;
try
{
stream
=
new
FileOutputStream
(
outputFile
);
cadImage
.
save
(
stream
,
pdfOptions
);
...
...
jodconverter-web/src/main/java/cn/keking/utils/ConverterUtils.java
View file @
180e7bcb
...
...
@@ -9,15 +9,15 @@ import org.artofsolving.jodconverter.office.OfficeManager;
import
org.artofsolving.jodconverter.office.OfficeUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
javax.annotation.PostConstruct
;
import
javax.annotation.PreDestroy
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.nio.charset.
Charset
;
import
java.nio.charset.
StandardCharsets
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Properties
;
...
...
@@ -37,11 +37,12 @@ public class ConverterUtils {
@PostConstruct
public
void
initOfficeManager
()
{
String
officeHome
=
OfficeUtils
.
getDefaultOfficeHome
().
getAbsolutePath
();
File
officeHome
;
officeHome
=
OfficeUtils
.
getDefaultOfficeHome
();
if
(
officeHome
==
null
)
{
throw
new
RuntimeException
(
"找不到office组件,请确认'office.home'配置是否有误"
);
}
boolean
killOffice
=
killProcess
(
"soffice.bin"
);
boolean
killOffice
=
killProcess
();
if
(
killOffice
)
{
logger
.
warn
(
"检测到有正在运行的office进程,已自动结束该进程"
);
}
...
...
@@ -72,11 +73,11 @@ public class ConverterUtils {
loadProperties
.
put
(
"Hidden"
,
true
);
loadProperties
.
put
(
"ReadOnly"
,
true
);
loadProperties
.
put
(
"UpdateDocMode"
,
UpdateDocMode
.
QUIET_UPDATE
);
loadProperties
.
put
(
"CharacterSet"
,
Charset
.
forName
(
"UTF-8"
)
.
name
());
loadProperties
.
put
(
"CharacterSet"
,
StandardCharsets
.
UTF_8
.
name
());
return
loadProperties
;
}
private
boolean
killProcess
(
String
processName
)
{
private
boolean
killProcess
()
{
boolean
flag
=
false
;
Properties
props
=
System
.
getProperties
();
try
{
...
...
@@ -84,32 +85,28 @@ public class ConverterUtils {
Process
p
=
Runtime
.
getRuntime
().
exec
(
"cmd /c tasklist "
);
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
InputStream
os
=
p
.
getInputStream
();
byte
b
[]
=
new
byte
[
256
];
byte
[]
b
=
new
byte
[
256
];
while
(
os
.
read
(
b
)
>
0
)
{
baos
.
write
(
b
);
}
String
s
=
baos
.
toString
();
if
(
s
.
indexOf
(
processName
)
>=
0
)
{
Runtime
.
getRuntime
().
exec
(
"taskkill /im "
+
processName
+
" /f"
);
if
(
s
.
contains
(
"soffice.bin"
)
)
{
Runtime
.
getRuntime
().
exec
(
"taskkill /im "
+
"soffice.bin"
+
" /f"
);
flag
=
true
;
}
else
{
flag
=
false
;
}
}
else
{
Process
p
=
Runtime
.
getRuntime
().
exec
(
new
String
[]{
"sh"
,
"-c"
,
"ps -ef | grep "
+
processName
});
Process
p
=
Runtime
.
getRuntime
().
exec
(
new
String
[]{
"sh"
,
"-c"
,
"ps -ef | grep "
+
"soffice.bin"
});
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
InputStream
os
=
p
.
getInputStream
();
byte
b
[]
=
new
byte
[
256
];
byte
[]
b
=
new
byte
[
256
];
while
(
os
.
read
(
b
)
>
0
)
{
baos
.
write
(
b
);
}
String
s
=
baos
.
toString
();
if
(
StringUtils
.
ordinalIndexOf
(
s
,
processName
,
3
)
>
0
)
{
String
[]
cmd
={
"sh"
,
"-c"
,
"kill -15 `ps -ef|grep "
+
processName
+
"|awk 'NR==1{print $2}'`"
};
if
(
StringUtils
.
ordinalIndexOf
(
s
,
"soffice.bin"
,
3
)
>
0
)
{
String
[]
cmd
={
"sh"
,
"-c"
,
"kill -15 `ps -ef|grep "
+
"soffice.bin"
+
"|awk 'NR==1{print $2}'`"
};
Runtime
.
getRuntime
().
exec
(
cmd
);
flag
=
true
;
}
else
{
flag
=
false
;
}
}
}
catch
(
IOException
e
)
{
...
...
jodconverter-web/src/main/java/cn/keking/utils/DeleteFileUtil.java
View file @
180e7bcb
...
...
@@ -4,6 +4,7 @@ import org.slf4j.Logger;
import
org.slf4j.LoggerFactory
;
import
java.io.File
;
import
java.util.Objects
;
public
class
DeleteFileUtil
{
...
...
@@ -55,19 +56,19 @@ public class DeleteFileUtil {
boolean
flag
=
true
;
// 删除文件夹中的所有文件包括子目录
File
[]
files
=
dirFile
.
listFiles
();
for
(
int
i
=
0
;
i
<
files
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
Objects
.
requireNonNull
(
files
)
.
length
;
i
++)
{
// 删除子文件
if
(
files
[
i
].
isFile
())
{
flag
=
DeleteFileUtil
.
deleteFile
(
files
[
i
].
getAbsolutePath
());
if
(!
flag
)
if
(!
flag
)
{
break
;
}
// 删除子目录
else
if
(
files
[
i
].
isDirectory
())
{
flag
=
DeleteFileUtil
.
deleteDirectory
(
files
[
i
]
.
getAbsolutePath
());
if
(!
flag
)
}
}
else
if
(
files
[
i
].
isDirectory
())
{
// 删除子目录
flag
=
DeleteFileUtil
.
deleteDirectory
(
files
[
i
].
getAbsolutePath
());
if
(!
flag
)
{
break
;
}
}
}
dirFile
.
delete
();
...
...
jodconverter-web/src/main/java/cn/keking/utils/DownloadUtils.java
View file @
180e7bcb
...
...
@@ -3,13 +3,15 @@ package cn.keking.utils;
import
cn.keking.config.ConfigConstants
;
import
cn.keking.hutool.URLUtil
;
import
cn.keking.model.FileAttribute
;
import
cn.keking.model.FileType
;
import
cn.keking.model.ReturnResponse
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
java.io.*
;
import
java.net.*
;
import
java.nio.charset.StandardCharsets
;
import
java.util.UUID
;
/**
...
...
@@ -18,32 +20,29 @@ import java.util.UUID;
@Component
public
class
DownloadUtils
{
private
static
final
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
DownloadUtils
.
class
);
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
DownloadUtils
.
class
);
private
final
String
fileDir
=
ConfigConstants
.
getFileDir
();
private
String
fileDir
=
ConfigConstants
.
getFileDir
()
;
private
final
FileUtils
fileUtils
;
@Autowired
private
FileUtils
fileUtils
;
public
DownloadUtils
(
FileUtils
fileUtils
)
{
this
.
fileUtils
=
fileUtils
;
}
private
static
final
String
URL_PARAM_FTP_USERNAME
=
"ftp.username"
;
private
static
final
String
URL_PARAM_FTP_PASSWORD
=
"ftp.password"
;
private
static
final
String
URL_PARAM_FTP_CONTROL_ENCODING
=
"ftp.control.encoding"
;
/**
* @param fileAttribute
* @return
* @param fileAttribute fileAttribute
* @param fileName 文件名
* @return 本地文件绝对路径
*/
public
ReturnResponse
<
String
>
downLoad
(
FileAttribute
fileAttribute
,
String
fileName
)
{
String
url
Address
=
fileAttribute
.
getDecoded
Url
();
String
url
Str
=
fileAttribute
.
get
Url
();
String
type
=
fileAttribute
.
getSuffix
();
ReturnResponse
<
String
>
response
=
new
ReturnResponse
<>(
0
,
"下载成功!!!"
,
""
);
URL
url
=
null
;
try
{
urlAddress
=
URLUtil
.
normalize
(
urlAddress
,
true
);
url
=
new
URL
(
urlAddress
);
}
catch
(
MalformedURLException
e
)
{
e
.
printStackTrace
();
}
UUID
uuid
=
UUID
.
randomUUID
();
if
(
null
==
fileName
)
{
fileName
=
uuid
+
"."
+
type
;
...
...
@@ -56,35 +55,28 @@ public class DownloadUtils {
dirFile
.
mkdirs
();
}
try
{
if
(
"ftp"
.
equals
(
url
.
getProtocol
()))
{
URL
url
=
new
URL
(
urlStr
);
OutputStream
os
=
new
FileOutputStream
(
new
File
(
realPath
));
if
(
url
.
getProtocol
()
!=
null
&&
url
.
getProtocol
().
toLowerCase
().
startsWith
(
"http"
))
{
saveToOutputStreamFormUrl
(
urlStr
,
os
);
}
else
if
(
url
.
getProtocol
()
!=
null
&&
"ftp"
.
equals
(
url
.
getProtocol
().
toLowerCase
()))
{
String
ftpUsername
=
fileUtils
.
getUrlParameterReg
(
fileAttribute
.
getUrl
(),
URL_PARAM_FTP_USERNAME
);
String
ftpPassword
=
fileUtils
.
getUrlParameterReg
(
fileAttribute
.
getUrl
(),
URL_PARAM_FTP_PASSWORD
);
String
ftpControlEncoding
=
fileUtils
.
getUrlParameterReg
(
fileAttribute
.
getUrl
(),
URL_PARAM_FTP_CONTROL_ENCODING
);
FtpUtils
.
download
(
fileAttribute
.
getUrl
(),
realPath
,
ftpUsername
,
ftpPassword
,
ftpControlEncoding
);
}
else
{
URLConnection
connection
=
url
.
openConnection
();
InputStream
in
=
connection
.
getInputStream
();
FileOutputStream
os
=
new
FileOutputStream
(
realPath
);
byte
[]
buffer
=
new
byte
[
4
*
1024
];
int
read
;
while
((
read
=
in
.
read
(
buffer
))
>
0
)
{
os
.
write
(
buffer
,
0
,
read
);
}
os
.
close
();
in
.
close
();
response
.
setCode
(
1
);
response
.
setContent
(
null
);
response
.
setMsg
(
"url不能识别url"
+
urlStr
);
}
response
.
setContent
(
realPath
);
// 同样针对类txt文件,如果成功msg包含的是转换后的文件名
response
.
setMsg
(
fileName
);
// txt转换文件编码为utf8
if
(
"txt"
.
equals
(
type
)){
if
(
FileType
.
simText
.
equals
(
fileAttribute
.
getType
())){
convertTextPlainFileCharsetToUtf8
(
realPath
);
}
return
response
;
}
catch
(
IOException
e
)
{
LOGGER
.
error
(
"文件下载失败,url:{}"
,
urlAddress
,
e
);
logger
.
error
(
"文件下载失败,url:{}"
,
urlStr
,
e
);
response
.
setCode
(
1
);
response
.
setContent
(
null
);
if
(
e
instanceof
FileNotFoundException
)
{
...
...
@@ -96,6 +88,47 @@ public class DownloadUtils {
}
}
public
boolean
saveToOutputStreamFormUrl
(
String
urlStr
,
OutputStream
os
)
throws
IOException
{
InputStream
is
=
getInputStreamFromUrl
(
urlStr
);
if
(
is
!=
null
)
{
copyStream
(
is
,
os
);
}
else
{
urlStr
=
URLUtil
.
normalize
(
urlStr
,
true
);
is
=
getInputStreamFromUrl
(
urlStr
);
if
(
is
!=
null
)
{
copyStream
(
is
,
os
);
}
else
{
os
.
close
();
return
false
;
}
}
return
true
;
}
private
InputStream
getInputStreamFromUrl
(
String
urlStr
)
{
try
{
URL
url
=
new
URL
(
urlStr
);
URLConnection
connection
=
url
.
openConnection
();
if
(
connection
instanceof
HttpURLConnection
)
{
connection
.
setRequestProperty
(
"User-Agent"
,
"Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"
);
}
return
connection
.
getInputStream
();
}
catch
(
IOException
e
)
{
logger
.
warn
(
"连接url异常:url:{}"
,
urlStr
);
return
null
;
}
}
private
void
copyStream
(
InputStream
is
,
OutputStream
os
)
throws
IOException
{
byte
[]
bs
=
new
byte
[
1024
];
int
len
;
while
(-
1
!=
(
len
=
is
.
read
(
bs
)))
{
os
.
write
(
bs
,
0
,
len
);
}
is
.
close
();
os
.
close
();
}
/**
* 转换文本文件编码为utf8
* 探测源文件编码,探测到编码切不为utf8则进行转码
...
...
@@ -117,7 +150,7 @@ public class DownloadUtils {
if
(
encoding
!=
null
&&
!
"UTF-8"
.
equals
(
encoding
)){
// 不为utf8,进行转码
File
tmpUtf8File
=
new
File
(
filePath
+
".utf8"
);
Writer
writer
=
new
OutputStreamWriter
(
new
FileOutputStream
(
tmpUtf8File
),
"UTF-8"
);
Writer
writer
=
new
OutputStreamWriter
(
new
FileOutputStream
(
tmpUtf8File
),
StandardCharsets
.
UTF_8
);
Reader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
new
FileInputStream
(
sourceFile
),
encoding
));
char
[]
buf
=
new
char
[
1024
];
int
read
;
...
...
jodconverter-web/src/main/java/cn/keking/utils/FileUtils.java
View file @
180e7bcb
This diff is collapsed.
Click to expand it.
jodconverter-web/src/main/java/cn/keking/utils/FtpUtils.java
View file @
180e7bcb
...
...
@@ -11,6 +11,7 @@ import java.io.FileOutputStream;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.net.URL
;
import
java.nio.charset.StandardCharsets
;
/**
* @auther: chenjh
...
...
@@ -47,7 +48,7 @@ public class FtpUtils {
FTPClient
ftpClient
=
connect
(
host
,
port
,
username
,
password
,
controlEncoding
);
OutputStream
outputStream
=
new
FileOutputStream
(
localFilePath
);
ftpClient
.
enterLocalPassiveMode
();
boolean
downloadResult
=
ftpClient
.
retrieveFile
(
new
String
(
remoteFilePath
.
getBytes
(
controlEncoding
),
"ISO-8859-1"
),
outputStream
);
boolean
downloadResult
=
ftpClient
.
retrieveFile
(
new
String
(
remoteFilePath
.
getBytes
(
controlEncoding
),
StandardCharsets
.
ISO_8859_1
),
outputStream
);
LOGGER
.
debug
(
"FTP download result {}"
,
downloadResult
);
outputStream
.
flush
();
outputStream
.
close
();
...
...
jodconverter-web/src/main/java/cn/keking/utils/OfficeToPdf.java
View file @
180e7bcb
package
cn
.
keking
.
utils
;
import
org.artofsolving.jodconverter.OfficeDocumentConverter
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
java.io.File
;
/**
...
...
@@ -9,38 +10,18 @@ import java.io.File;
*/
@Component
public
class
OfficeToPdf
{
/**
* 获取OpenOffice.org 3的安装目录
*
* @return OpenOffice.org 3的安装目录
*/
@Autowired
ConverterUtils
converterUtils
;
/**
* 使Office2003-2007全部格式的文档(.doc|.docx|.xls|.xlsx|.ppt|.pptx) 转化为pdf文件<br>
*
* @param inputFilePath
* 源文件路径,如:"e:/test.docx"
* @param outputFilePath
* 目标文件路径,如:"e:/test_docx.pdf"
* @return
*/
public
boolean
openOfficeToPDF
(
String
inputFilePath
,
String
outputFilePath
)
{
return
office2pdf
(
inputFilePath
,
outputFilePath
);
private
final
ConverterUtils
converterUtils
;
public
OfficeToPdf
(
ConverterUtils
converterUtils
)
{
this
.
converterUtils
=
converterUtils
;
}
public
void
openOfficeToPDF
(
String
inputFilePath
,
String
outputFilePath
)
{
office2pdf
(
inputFilePath
,
outputFilePath
);
}
/**
* 转换文件
*
* @param inputFile
* @param outputFilePath_end
* @param inputFilePath
* @param outputFilePath
* @param converter
*/
public
static
void
converterFile
(
File
inputFile
,
String
outputFilePath_end
,
String
inputFilePath
,
String
outputFilePath
,
OfficeDocumentConverter
converter
)
{
File
outputFile
=
new
File
(
outputFilePath_end
);
// 假如目标路径不存在,则新建该路径
...
...
@@ -50,17 +31,8 @@ public class OfficeToPdf {
converter
.
convert
(
inputFile
,
outputFile
);
}
/**
* 使Office2003-2007全部格式的文档(.doc|.docx|.xls|.xlsx|.ppt|.pptx) 转化为pdf文件
*
* @param inputFilePath
* 源文件路径,如:"e:/test.docx"
* @param outputFilePath
* 目标文件路径,如:"e:/test_docx.pdf"
* @return
*/
public
boolean
office2pdf
(
String
inputFilePath
,
String
outputFilePath
)
{
boolean
flag
=
false
;
public
void
office2pdf
(
String
inputFilePath
,
String
outputFilePath
)
{
OfficeDocumentConverter
converter
=
converterUtils
.
getDocumentConverter
();
if
(
null
!=
inputFilePath
)
{
File
inputFile
=
new
File
(
inputFilePath
);
...
...
@@ -68,43 +40,23 @@ public class OfficeToPdf {
if
(
null
==
outputFilePath
)
{
// 转换后的文件路径
String
outputFilePath_end
=
getOutputFilePath
(
inputFilePath
);
if
(
inputFile
.
exists
())
{
// 找不到源文件, 则返回
converterFile
(
inputFile
,
outputFilePath_end
,
inputFilePath
,
outputFilePath
,
converter
);
flag
=
true
;
if
(
inputFile
.
exists
())
{
// 找不到源文件, 则返回
converterFile
(
inputFile
,
outputFilePath_end
,
converter
);
}
}
else
{
if
(
inputFile
.
exists
())
{
// 找不到源文件, 则返回
converterFile
(
inputFile
,
outputFilePath
,
inputFilePath
,
outputFilePath
,
converter
);
flag
=
true
;
if
(
inputFile
.
exists
())
{
// 找不到源文件, 则返回
converterFile
(
inputFile
,
outputFilePath
,
converter
);
}
}
// officeManager.stop();
}
else
{
flag
=
false
;
}
return
flag
;
}
/**
* 获取输出文件
*
* @param inputFilePath
* @return
*/
public
static
String
getOutputFilePath
(
String
inputFilePath
)
{
String
outputFilePath
=
inputFilePath
.
replaceAll
(
"."
+
getPostfix
(
inputFilePath
),
".pdf"
);
return
outputFilePath
;
return
inputFilePath
.
replaceAll
(
"."
+
getPostfix
(
inputFilePath
),
".pdf"
);
}
/**
* 获取inputFilePath的后缀名,如:"e:/test.pptx"的后缀名为:"pptx"
*
* @param inputFilePath
* @return
*/
public
static
String
getPostfix
(
String
inputFilePath
)
{
return
inputFilePath
.
substring
(
inputFilePath
.
lastIndexOf
(
"."
)
+
1
);
}
...
...
jodconverter-web/src/main/java/cn/keking/utils/PdfUtils.java
View file @
180e7bcb
...
...
@@ -6,12 +6,14 @@ import org.apache.pdfbox.rendering.PDFRenderer;
import
org.apache.pdfbox.tools.imageio.ImageIOUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.
Autowired
;
import
org.springframework.beans.factory.annotation.
Value
;
import
org.springframework.stereotype.Component
;
import
java.awt.image.BufferedImage
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -20,16 +22,28 @@ public class PdfUtils {
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
PdfUtils
.
class
);
@Autowired
FileUtils
fileUtils
;
private
final
FileUtils
fileUtils
;
@Value
(
"${server.tomcat.uri-encoding:UTF-8}"
)
private
String
uriEncoding
;
public
PdfUtils
(
FileUtils
fileUtils
)
{
this
.
fileUtils
=
fileUtils
;
}
public
List
<
String
>
pdf2jpg
(
String
pdfFilePath
,
String
pdfName
,
String
baseUrl
)
{
List
<
String
>
imageUrls
=
new
ArrayList
<>();
Integer
imageCount
=
fileUtils
.
getConvertedPdfImage
(
pdfFilePath
);
String
imageFileSuffix
=
".jpg"
;
String
pdfFolder
=
pdfName
.
substring
(
0
,
pdfName
.
length
()
-
4
);
String
urlPrefix
=
baseUrl
+
pdfFolder
;
if
(
imageCount
!=
null
&&
imageCount
.
intValue
()
>
0
)
{
String
urlPrefix
=
null
;
try
{
urlPrefix
=
baseUrl
+
URLEncoder
.
encode
(
URLEncoder
.
encode
(
pdfFolder
,
uriEncoding
),
uriEncoding
);
}
catch
(
UnsupportedEncodingException
e
)
{
logger
.
error
(
"UnsupportedEncodingException"
,
e
);
urlPrefix
=
baseUrl
+
pdfFolder
;
}
if
(
imageCount
!=
null
&&
imageCount
>
0
)
{
for
(
int
i
=
0
;
i
<
imageCount
;
i
++)
imageUrls
.
add
(
urlPrefix
+
"/"
+
i
+
imageFileSuffix
);
return
imageUrls
;
...
...
jodconverter-web/src/main/java/cn/keking/utils/ShedulerClean.java
View file @
180e7bcb
...
...
@@ -4,7 +4,6 @@ import cn.keking.config.ConfigConstants;
import
cn.keking.service.cache.CacheService
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
...
...
@@ -19,10 +18,13 @@ public class ShedulerClean {
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
ShedulerClean
.
class
);
@Autowired
private
CacheService
cacheService
;
private
final
CacheService
cacheService
;
private
String
fileDir
=
ConfigConstants
.
getFileDir
();
public
ShedulerClean
(
CacheService
cacheService
)
{
this
.
cacheService
=
cacheService
;
}
private
final
String
fileDir
=
ConfigConstants
.
getFileDir
();
//默认每晚3点执行一次
@Scheduled
(
cron
=
"${cache.clean.cron:0 0 3 * * ?}"
)
...
...
jodconverter-web/src/main/java/cn/keking/utils/SimTextUtil.java
deleted
100644 → 0
View file @
8a524506
package
cn
.
keking
.
utils
;
import
cn.keking.config.ConfigConstants
;
import
cn.keking.model.FileAttribute
;
import
cn.keking.model.ReturnResponse
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
/**
* 读取类文本文件
* @author yudian-it
* @date 2017/12/13
*/
@Component
public
class
SimTextUtil
{
@Autowired
private
FileUtils
fileUtils
;
@Autowired
private
DownloadUtils
downloadUtils
;
public
ReturnResponse
<
String
>
readSimText
(
String
url
,
String
fileName
){
FileAttribute
fileAttribute
=
fileUtils
.
getFileAttribute
(
url
);
ReturnResponse
<
String
>
response
=
downloadUtils
.
downLoad
(
fileAttribute
,
fileName
);
return
response
;
}
}
jodconverter-web/src/main/java/cn/keking/utils/ZipReader.java
View file @
180e7bcb
This diff is collapsed.
Click to expand it.
jodconverter-web/src/main/java/cn/keking/web/controller/FileController.java
View file @
180e7bcb
...
...
@@ -6,22 +6,20 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import
com.google.common.collect.ImmutableMap
;
import
com.google.common.collect.Lists
;
import
cn.keking.model.ReturnResponse
;
import
cn.keking.utils.FileUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.
beans.factory.annotation.Autowired
;
import
org.springframework.
util.StreamUtils
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.*
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.
UUID
;
import
java.util.
Objects
;
/**
*
...
...
@@ -33,11 +31,11 @@ public class FileController {
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
FileController
.
class
);
private
String
fileDir
=
ConfigConstants
.
getFileDir
();
@Autowired
private
FileUtils
fileUtils
;
private
String
demoDir
=
"demo"
;
private
String
demoPath
=
demoDir
+
File
.
separator
;
private
final
String
fileDir
=
ConfigConstants
.
getFileDir
();
private
final
String
demoDir
=
"demo"
;
private
final
String
demoPath
=
demoDir
+
File
.
separator
;
@RequestMapping
(
value
=
"fileUpload"
,
method
=
RequestMethod
.
POST
)
public
String
fileUpload
(
@RequestParam
(
"file"
)
MultipartFile
file
)
throws
JsonProcessingException
{
...
...
@@ -49,7 +47,7 @@ public class FileController {
// Check for Windows-style path
int
winSep
=
fileName
.
lastIndexOf
(
'\\'
);
// Cut off at latest possible point
int
pos
=
(
winSep
>
unixSep
?
winSep
:
unixSep
);
int
pos
=
(
Math
.
max
(
winSep
,
unixSep
)
);
if
(
pos
!=
-
1
)
{
fileName
=
fileName
.
substring
(
pos
+
1
);
}
...
...
@@ -62,13 +60,8 @@ public class FileController {
outFile
.
mkdirs
();
}
logger
.
info
(
"上传文件:{}"
,
outFile
.
getAbsolutePath
());
try
(
InputStream
in
=
file
.
getInputStream
();
OutputStream
ot
=
new
FileOutputStream
(
fileDir
+
demoPath
+
fileName
)){
byte
[]
buffer
=
new
byte
[
1024
];
int
len
;
while
((-
1
!=
(
len
=
in
.
read
(
buffer
))))
{
ot
.
write
(
buffer
,
0
,
len
);
}
try
(
InputStream
in
=
file
.
getInputStream
();
OutputStream
out
=
new
FileOutputStream
(
fileDir
+
demoPath
+
fileName
))
{
StreamUtils
.
copy
(
in
,
out
);
return
new
ObjectMapper
().
writeValueAsString
(
new
ReturnResponse
<
String
>(
0
,
"SUCCESS"
,
null
));
}
catch
(
IOException
e
)
{
logger
.
error
(
"文件上传失败"
,
e
);
...
...
@@ -94,29 +87,13 @@ public class FileController {
List
<
Map
<
String
,
String
>>
list
=
Lists
.
newArrayList
();
File
file
=
new
File
(
fileDir
+
demoPath
);
if
(
file
.
exists
())
{
Arrays
.
stream
(
file
.
listFiles
(
)).
forEach
(
file1
->
list
.
add
(
ImmutableMap
.
of
(
"fileName"
,
demoDir
+
"/"
+
file1
.
getName
())));
Arrays
.
stream
(
Objects
.
requireNonNull
(
file
.
listFiles
()
)).
forEach
(
file1
->
list
.
add
(
ImmutableMap
.
of
(
"fileName"
,
demoDir
+
"/"
+
file1
.
getName
())));
}
return
new
ObjectMapper
().
writeValueAsString
(
list
);
}
private
String
getFileName
(
String
name
)
{
String
suffix
=
name
.
substring
(
name
.
lastIndexOf
(
"."
));
String
nameNoSuffix
=
name
.
substring
(
0
,
name
.
lastIndexOf
(
"."
));
String
uuid
=
UUID
.
randomUUID
().
toString
();
return
uuid
+
"-"
+
nameNoSuffix
+
suffix
;
}
/**
* 是否存在该类型的文件
* @return
* @param fileName
*/
private
boolean
existsFile
(
String
fileName
)
{
boolean
result
=
false
;
File
file
=
new
File
(
fileDir
+
demoPath
+
fileName
);
if
(
file
.
exists
())
{
return
true
;
}
return
result
;
return
file
.
exists
();
}
}
jodconverter-web/src/main/java/cn/keking/web/controller/IndexController.java
View file @
180e7bcb
...
...
@@ -12,7 +12,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public
class
IndexController
{
@RequestMapping
(
value
=
"index"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"
/
index"
,
method
=
RequestMethod
.
GET
)
public
String
go2Index
(){
return
"index"
;
}
...
...
jodconverter-web/src/main/java/cn/keking/web/controller/OnlinePreviewController.java
View file @
180e7bcb
package
cn
.
keking
.
web
.
controller
;
import
cn.keking.config.ConfigConstants
;
import
cn.keking.hutool.URLUtil
;
import
cn.keking.model.FileAttribute
;
import
cn.keking.service.FilePreview
;
import
cn.keking.service.FilePreviewFactory
;
import
cn.keking.service.cache.CacheService
;
import
cn.keking.utils.DownloadUtils
;
import
cn.keking.utils.FileUtils
;
import
org.apache.commons.io.IOUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.GetMapping
;
...
...
@@ -22,7 +20,6 @@ import org.springframework.web.bind.annotation.ResponseBody;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.*
;
import
java.net.*
;
import
java.util.Arrays
;
import
java.util.List
;
...
...
@@ -34,20 +31,25 @@ public class OnlinePreviewController {
private
final
Logger
logger
=
LoggerFactory
.
getLogger
(
OnlinePreviewController
.
class
);
@Autowired
private
FilePreviewFactory
previewFactory
;
private
final
FilePreviewFactory
previewFactory
;
@Autowired
private
CacheService
cacheService
;
private
final
CacheService
cacheService
;
private
final
FileUtils
fileUtils
;
private
final
DownloadUtils
downloadUtils
;
public
OnlinePreviewController
(
FilePreviewFactory
filePreviewFactory
,
FileUtils
fileUtils
,
CacheService
cacheService
,
DownloadUtils
downloadUtils
)
{
this
.
previewFactory
=
filePreviewFactory
;
this
.
fileUtils
=
fileUtils
;
this
.
cacheService
=
cacheService
;
this
.
downloadUtils
=
downloadUtils
;
}
@Autowired
private
FileUtils
fileUtils
;
/**
* @param url
* @param model
* @return
*/
@RequestMapping
(
value
=
"/onlinePreview"
,
method
=
RequestMethod
.
GET
)
public
String
onlinePreview
(
String
url
,
Model
model
,
HttpServletRequest
req
)
{
FileAttribute
fileAttribute
=
fileUtils
.
getFileAttribute
(
url
);
...
...
@@ -66,7 +68,7 @@ public class OnlinePreviewController {
String
currentUrl
=
req
.
getParameter
(
"currentUrl"
);
logger
.
info
(
"预览文件url:{},urls:{}"
,
currentUrl
,
urls
);
String
[]
imgs
=
urls
.
split
(
"\\|"
);
List
imgurls
=
Arrays
.
asList
(
imgs
);
List
<
String
>
imgurls
=
Arrays
.
asList
(
imgs
);
model
.
addAttribute
(
"imgurls"
,
imgurls
);
model
.
addAttribute
(
"currentUrl"
,
currentUrl
);
return
"picture"
;
...
...
@@ -75,31 +77,16 @@ public class OnlinePreviewController {
* 根据url获取文件内容
* 当pdfjs读取存在跨域问题的文件时将通过此接口读取
*
* @param urlPath
* @param resp
* @param urlPath
url
* @param resp
onse response
*/
@RequestMapping
(
value
=
"/getCorsFile"
,
method
=
RequestMethod
.
GET
)
public
void
getCorsFile
(
String
urlPath
,
HttpServletResponse
resp
)
{
InputStream
inputStream
=
null
;
public
void
getCorsFile
(
String
urlPath
,
HttpServletResponse
response
)
{
logger
.
info
(
"下载跨域pdf文件url:{}"
,
urlPath
);
try
{
URL
url
=
new
URL
(
URLUtil
.
normalize
(
urlPath
,
true
));
//打开请求连接
URLConnection
connection
=
url
.
openConnection
();
HttpURLConnection
httpURLConnection
=
(
HttpURLConnection
)
connection
;
httpURLConnection
.
setRequestProperty
(
"User-Agent"
,
"Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"
);
inputStream
=
httpURLConnection
.
getInputStream
();
byte
[]
bs
=
new
byte
[
1024
];
int
len
;
while
(-
1
!=
(
len
=
inputStream
.
read
(
bs
)))
{
resp
.
getOutputStream
().
write
(
bs
,
0
,
len
);
}
downloadUtils
.
saveToOutputStreamFormUrl
(
urlPath
,
response
.
getOutputStream
());
}
catch
(
IOException
e
)
{
logger
.
error
(
"下载跨域pdf文件异常,url:{}"
,
urlPath
,
e
);
}
finally
{
if
(
inputStream
!=
null
)
{
IOUtils
.
closeQuietly
(
inputStream
);
}
}
}
...
...
jodconverter-web/src/main/java/cn/keking/web/filter/BaseUrlFilter.java
View file @
180e7bcb
...
...
@@ -27,7 +27,7 @@ public class BaseUrlFilter implements Filter {
@Override
public
void
init
(
FilterConfig
filterConfig
)
throws
ServletException
{
public
void
init
(
FilterConfig
filterConfig
)
{
}
...
...
jodconverter-web/src/main/java/cn/keking/web/filter/ChinesePathFilter.java
View file @
180e7bcb
package
cn
.
keking
.
web
.
filter
;
import
cn.keking.config.ConfigConstants
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
javax.servlet.*
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.IOException
;
/**
...
...
@@ -15,40 +12,12 @@ import java.io.IOException;
public
class
ChinesePathFilter
implements
Filter
{
@Override
public
void
init
(
FilterConfig
filterConfig
)
throws
ServletException
{
public
void
init
(
FilterConfig
filterConfig
)
{
}
private
static
String
BASE_URL
;
public
static
String
getBaseUrl
()
{
String
baseUrl
;
try
{
baseUrl
=
(
String
)
RequestContextHolder
.
currentRequestAttributes
().
getAttribute
(
"baseUrl"
,
0
);
}
catch
(
Exception
e
)
{
baseUrl
=
BASE_URL
;
}
return
baseUrl
;
}
@Override
public
void
doFilter
(
ServletRequest
request
,
ServletResponse
response
,
FilterChain
chain
)
throws
IOException
,
ServletException
{
request
.
setCharacterEncoding
(
"UTF-8"
);
response
.
setCharacterEncoding
(
"UTF-8"
);
String
baseUrl
;
StringBuilder
pathBuilder
=
new
StringBuilder
();
pathBuilder
.
append
(
request
.
getScheme
()).
append
(
"://"
).
append
(
request
.
getServerName
()).
append
(
":"
)
.
append
(
request
.
getServerPort
()).
append
(((
HttpServletRequest
)
request
).
getContextPath
()).
append
(
"/"
);
String
baseUrlTmp
=
ConfigConstants
.
getBaseUrl
();
if
(
baseUrlTmp
!=
null
&&
!
ConfigConstants
.
DEFAULT_BASE_URL
.
equals
(
baseUrlTmp
.
toLowerCase
()))
{
if
(!
baseUrlTmp
.
endsWith
(
"/"
))
{
baseUrlTmp
=
baseUrlTmp
.
concat
(
"/"
);
}
baseUrl
=
baseUrlTmp
;
}
else
{
baseUrl
=
pathBuilder
.
toString
();
}
BASE_URL
=
baseUrl
;
request
.
setAttribute
(
"baseUrl"
,
baseUrl
);
chain
.
doFilter
(
request
,
response
);
}
...
...
jodconverter-web/src/main/java/cn/keking/web/filter/TrustHostFilter.java
View file @
180e7bcb
...
...
@@ -20,7 +20,7 @@ public class TrustHostFilter implements Filter {
private
String
notTrustHost
;
@Override
public
void
init
(
FilterConfig
filterConfig
)
throws
ServletException
{
public
void
init
(
FilterConfig
filterConfig
)
{
ClassPathResource
classPathResource
=
new
ClassPathResource
(
"web/notTrustHost.html"
);
try
{
classPathResource
.
getInputStream
();
...
...
@@ -35,7 +35,7 @@ public class TrustHostFilter implements Filter {
public
void
doFilter
(
ServletRequest
request
,
ServletResponse
response
,
FilterChain
chain
)
throws
IOException
,
ServletException
{
String
url
=
getSourceUrl
(
request
);
String
host
=
getHost
(
url
);
if
(!
ConfigConstants
.
getTrustHostSet
().
isEmpty
()
&&
!
ConfigConstants
.
getTrustHostSet
().
contains
(
host
))
{
if
(
host
!=
null
&&
!
ConfigConstants
.
getTrustHostSet
().
isEmpty
()
&&
!
ConfigConstants
.
getTrustHostSet
().
contains
(
host
))
{
String
html
=
this
.
notTrustHost
.
replace
(
"${current_host}"
,
host
);
response
.
getWriter
().
write
(
html
);
response
.
getWriter
().
close
();
...
...
@@ -68,7 +68,7 @@ public class TrustHostFilter implements Filter {
try
{
URL
url
=
new
URL
(
urlStr
);
return
url
.
getHost
().
toLowerCase
();
}
catch
(
MalformedURLException
e
)
{
}
catch
(
MalformedURLException
ignored
)
{
}
return
null
;
}
...
...
jodconverter-web/src/main/java/cn/keking/web/filter/WatermarkConfigFilter.java
View file @
180e7bcb
...
...
@@ -12,7 +12,7 @@ import java.io.IOException;
public
class
WatermarkConfigFilter
implements
Filter
{
@Override
public
void
init
(
FilterConfig
filterConfig
)
throws
ServletException
{
public
void
init
(
FilterConfig
filterConfig
)
{
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment