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
c1802b24
Commit
c1802b24
authored
Dec 25, 2020
by
kl
Committed by
kl
Dec 25, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
预览逻辑重构
parent
d4b11a40
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
119 additions
and
50 deletions
+119
-50
FileAttribute.java
...rter-web/src/main/java/cn/keking/model/FileAttribute.java
+20
-0
FileConvertQueueTask.java
...src/main/java/cn/keking/service/FileConvertQueueTask.java
+1
-1
FilePreview.java
...rter-web/src/main/java/cn/keking/service/FilePreview.java
+5
-0
MarkdownFilePreviewImpl.java
.../java/cn/keking/service/impl/MarkdownFilePreviewImpl.java
+1
-1
PdfFilePreviewImpl.java
.../main/java/cn/keking/service/impl/PdfFilePreviewImpl.java
+1
-1
SimTextFilePreviewImpl.java
...n/java/cn/keking/service/impl/SimTextFilePreviewImpl.java
+4
-0
XmlFilePreviewImpl.java
.../main/java/cn/keking/service/impl/XmlFilePreviewImpl.java
+1
-1
FileUtils.java
...onverter-web/src/main/java/cn/keking/utils/FileUtils.java
+61
-38
OnlinePreviewController.java
...ava/cn/keking/web/controller/OnlinePreviewController.java
+1
-5
AttributeSetFilter.java
...rc/main/java/cn/keking/web/filter/AttributeSetFilter.java
+23
-2
FilterConfiguration.java
...c/main/java/cn/keking/web/filter/FilterConfiguration.java
+1
-1
No files found.
jodconverter-web/src/main/java/cn/keking/model/FileAttribute.java
View file @
c1802b24
package
cn
.
keking
.
model
;
package
cn
.
keking
.
model
;
import
cn.keking.config.ConfigConstants
;
/**
/**
* Created by kl on 2018/1/17.
* Created by kl on 2018/1/17.
* Content :
* Content :
...
@@ -14,6 +16,8 @@ public class FileAttribute {
...
@@ -14,6 +16,8 @@ public class FileAttribute {
private
String
url
;
private
String
url
;
private
String
officePreviewType
=
ConfigConstants
.
getOfficePreviewType
();
public
FileAttribute
()
{
public
FileAttribute
()
{
}
}
...
@@ -24,6 +28,22 @@ public class FileAttribute {
...
@@ -24,6 +28,22 @@ public class FileAttribute {
this
.
url
=
url
;
this
.
url
=
url
;
}
}
public
FileAttribute
(
FileType
type
,
String
suffix
,
String
name
,
String
url
,
String
officePreviewType
)
{
this
.
type
=
type
;
this
.
suffix
=
suffix
;
this
.
name
=
name
;
this
.
url
=
url
;
this
.
officePreviewType
=
officePreviewType
;
}
public
String
getOfficePreviewType
()
{
return
officePreviewType
;
}
public
void
setOfficePreviewType
(
String
officePreviewType
)
{
this
.
officePreviewType
=
officePreviewType
;
}
public
FileType
getType
()
{
public
FileType
getType
()
{
return
type
;
return
type
;
}
}
...
...
jodconverter-web/src/main/java/cn/keking/service/FileConvertQueueTask.java
View file @
c1802b24
...
@@ -67,7 +67,7 @@ public class FileConvertQueueTask {
...
@@ -67,7 +67,7 @@ public class FileConvertQueueTask {
try
{
try
{
url
=
cacheService
.
takeQueueTask
();
url
=
cacheService
.
takeQueueTask
();
if
(
url
!=
null
){
if
(
url
!=
null
){
FileAttribute
fileAttribute
=
fileUtils
.
getFileAttribute
(
url
);
FileAttribute
fileAttribute
=
fileUtils
.
getFileAttribute
(
url
,
null
);
FileType
fileType
=
fileAttribute
.
getType
();
FileType
fileType
=
fileAttribute
.
getType
();
logger
.
info
(
"正在处理预览转换任务,url:{},预览类型:{}"
,
url
,
fileType
);
logger
.
info
(
"正在处理预览转换任务,url:{},预览类型:{}"
,
url
,
fileType
);
if
(
fileType
.
equals
(
FileType
.
compress
)
||
fileType
.
equals
(
FileType
.
office
)
||
fileType
.
equals
(
FileType
.
cad
))
{
if
(
fileType
.
equals
(
FileType
.
compress
)
||
fileType
.
equals
(
FileType
.
office
)
||
fileType
.
equals
(
FileType
.
cad
))
{
...
...
jodconverter-web/src/main/java/cn/keking/service/FilePreview.java
View file @
c1802b24
package
cn
.
keking
.
service
;
package
cn
.
keking
.
service
;
import
cn.keking.config.ConfigConstants
;
import
cn.keking.model.FileAttribute
;
import
cn.keking.model.FileAttribute
;
import
org.springframework.ui.Model
;
import
org.springframework.ui.Model
;
...
@@ -8,5 +9,9 @@ import org.springframework.ui.Model;
...
@@ -8,5 +9,9 @@ import org.springframework.ui.Model;
* Content :
* Content :
*/
*/
public
interface
FilePreview
{
public
interface
FilePreview
{
String
TEXT_TYPE
=
"textType"
;
String
DEFAULT_TEXT_TYPE
=
"simText"
;
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
);
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
);
}
}
jodconverter-web/src/main/java/cn/keking/service/impl/MarkdownFilePreviewImpl.java
View file @
c1802b24
...
@@ -21,7 +21,7 @@ public class MarkdownFilePreviewImpl implements FilePreview {
...
@@ -21,7 +21,7 @@ public class MarkdownFilePreviewImpl implements FilePreview {
@Override
@Override
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
model
.
addAttribute
(
"textType"
,
"markdown"
);
model
.
addAttribute
(
TEXT_TYPE
,
"markdown"
);
return
simTextFilePreview
.
filePreviewHandle
(
url
,
model
,
fileAttribute
);
return
simTextFilePreview
.
filePreviewHandle
(
url
,
model
,
fileAttribute
);
}
}
}
}
jodconverter-web/src/main/java/cn/keking/service/impl/PdfFilePreviewImpl.java
View file @
c1802b24
...
@@ -40,7 +40,7 @@ public class PdfFilePreviewImpl implements FilePreview {
...
@@ -40,7 +40,7 @@ public class PdfFilePreviewImpl implements FilePreview {
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
String
suffix
=
fileAttribute
.
getSuffix
();
String
suffix
=
fileAttribute
.
getSuffix
();
String
fileName
=
fileAttribute
.
getName
();
String
fileName
=
fileAttribute
.
getName
();
String
officePreviewType
=
model
.
asMap
().
get
(
"officePreviewType"
)
==
null
?
ConfigConstants
.
getOfficePreviewType
()
:
model
.
asMap
().
get
(
"officePreviewType"
).
toString
();
String
officePreviewType
=
fileAttribute
.
getOfficePreviewType
();
String
baseUrl
=
BaseUrlFilter
.
getBaseUrl
();
String
baseUrl
=
BaseUrlFilter
.
getBaseUrl
();
String
pdfName
=
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
"."
)
+
1
)
+
"pdf"
;
String
pdfName
=
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
"."
)
+
1
)
+
"pdf"
;
String
outFilePath
=
FILE_DIR
+
pdfName
;
String
outFilePath
=
FILE_DIR
+
pdfName
;
...
...
jodconverter-web/src/main/java/cn/keking/service/impl/SimTextFilePreviewImpl.java
View file @
c1802b24
...
@@ -24,6 +24,7 @@ public class SimTextFilePreviewImpl implements FilePreview {
...
@@ -24,6 +24,7 @@ public class SimTextFilePreviewImpl implements FilePreview {
private
final
DownloadUtils
downloadUtils
;
private
final
DownloadUtils
downloadUtils
;
public
SimTextFilePreviewImpl
(
DownloadUtils
downloadUtils
)
{
public
SimTextFilePreviewImpl
(
DownloadUtils
downloadUtils
)
{
this
.
downloadUtils
=
downloadUtils
;
this
.
downloadUtils
=
downloadUtils
;
}
}
...
@@ -46,6 +47,9 @@ public class SimTextFilePreviewImpl implements FilePreview {
...
@@ -46,6 +47,9 @@ public class SimTextFilePreviewImpl implements FilePreview {
model
.
addAttribute
(
"fileType"
,
fileAttribute
.
getSuffix
());
model
.
addAttribute
(
"fileType"
,
fileAttribute
.
getSuffix
());
return
"fileNotSupported"
;
return
"fileNotSupported"
;
}
}
if
(!
model
.
containsAttribute
(
TEXT_TYPE
))
{
model
.
addAttribute
(
TEXT_TYPE
,
DEFAULT_TEXT_TYPE
);
}
return
"txt"
;
return
"txt"
;
}
}
...
...
jodconverter-web/src/main/java/cn/keking/service/impl/XmlFilePreviewImpl.java
View file @
c1802b24
...
@@ -21,7 +21,7 @@ public class XmlFilePreviewImpl implements FilePreview {
...
@@ -21,7 +21,7 @@ public class XmlFilePreviewImpl implements FilePreview {
@Override
@Override
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
model
.
addAttribute
(
"textType"
,
"xml"
);
model
.
addAttribute
(
TEXT_TYPE
,
"xml"
);
return
simTextFilePreview
.
filePreviewHandle
(
url
,
model
,
fileAttribute
);
return
simTextFilePreview
.
filePreviewHandle
(
url
,
model
,
fileAttribute
);
}
}
}
}
jodconverter-web/src/main/java/cn/keking/utils/FileUtils.java
View file @
c1802b24
...
@@ -8,6 +8,7 @@ import com.google.common.collect.Lists;
...
@@ -8,6 +8,7 @@ import com.google.common.collect.Lists;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.*
;
import
java.io.*
;
import
java.nio.charset.Charset
;
import
java.nio.charset.Charset
;
import
java.nio.charset.StandardCharsets
;
import
java.nio.charset.StandardCharsets
;
...
@@ -17,7 +18,6 @@ import java.util.List;
...
@@ -17,7 +18,6 @@ import java.util.List;
import
java.util.Map
;
import
java.util.Map
;
/**
/**
*
* @author yudian-it
* @author yudian-it
* @date 2017/11/13
* @date 2017/11/13
*/
*/
...
@@ -80,10 +80,10 @@ public class FileUtils {
...
@@ -80,10 +80,10 @@ public class FileUtils {
if
(
listOfficeTypes
().
contains
(
fileType
.
toLowerCase
()))
{
if
(
listOfficeTypes
().
contains
(
fileType
.
toLowerCase
()))
{
return
FileType
.
office
;
return
FileType
.
office
;
}
}
if
(
"md"
.
equalsIgnoreCase
(
fileType
))
{
if
(
"md"
.
equalsIgnoreCase
(
fileType
))
{
return
FileType
.
markdown
;
return
FileType
.
markdown
;
}
}
if
(
"xml"
.
equalsIgnoreCase
(
fileType
))
{
if
(
"xml"
.
equalsIgnoreCase
(
fileType
))
{
return
FileType
.
xml
;
return
FileType
.
xml
;
}
}
if
(
Arrays
.
asList
(
simText
).
contains
(
fileType
.
toLowerCase
()))
{
if
(
Arrays
.
asList
(
simText
).
contains
(
fileType
.
toLowerCase
()))
{
...
@@ -100,30 +100,31 @@ public class FileUtils {
...
@@ -100,30 +100,31 @@ public class FileUtils {
}
}
return
FileType
.
other
;
return
FileType
.
other
;
}
}
/**
/**
* 从url中剥离出文件名
* 从url中剥离出文件名
*
@param url
*
*
格式如:http://keking.ufile.ucloud.com.cn/20171113164107_月度绩效表模板(新).xls?UCloudPublicKey=ucloudtangshd@weifenf.com14355492830001993909323&Expires=&Signature=I D1NOFtAJSPT16E6imv6JWuq0k=
*
@param url
格式如:http://keking.ufile.ucloud.com.cn/20171113164107_月度绩效表模板(新).xls?UCloudPublicKey=ucloudtangshd@weifenf.com14355492830001993909323&Expires=&Signature=I D1NOFtAJSPT16E6imv6JWuq0k=
* @return 文件名
* @return 文件名
*/
*/
public
String
getFileNameFromURL
(
String
url
)
{
public
String
getFileNameFromURL
(
String
url
)
{
// 因为url的参数中可能会存在/的情况,所以直接url.lastIndexOf("/")会有问题
// 因为url的参数中可能会存在/的情况,所以直接url.lastIndexOf("/")会有问题
// 所以先从?处将url截断,然后运用url.lastIndexOf("/")获取文件名
// 所以先从?处将url截断,然后运用url.lastIndexOf("/")获取文件名
String
noQueryUrl
=
url
.
substring
(
0
,
url
.
contains
(
"?"
)
?
url
.
indexOf
(
"?"
):
url
.
length
());
String
noQueryUrl
=
url
.
substring
(
0
,
url
.
contains
(
"?"
)
?
url
.
indexOf
(
"?"
)
:
url
.
length
());
return
noQueryUrl
.
substring
(
noQueryUrl
.
lastIndexOf
(
"/"
)
+
1
);
return
noQueryUrl
.
substring
(
noQueryUrl
.
lastIndexOf
(
"/"
)
+
1
);
}
}
/**
/**
* 从路径中获取文件负
* 从路径中获取文件负
*
@param path
*
*
类似这种:C:\Users\yudian-it\Downloads
*
@param path
类似这种:C:\Users\yudian-it\Downloads
* @return 文件名
* @return 文件名
*/
*/
public
String
getFileNameFromPath
(
String
path
)
{
public
String
getFileNameFromPath
(
String
path
)
{
return
path
.
substring
(
path
.
lastIndexOf
(
File
.
separator
)
+
1
);
return
path
.
substring
(
path
.
lastIndexOf
(
File
.
separator
)
+
1
);
}
}
public
List
<
String
>
listPictureTypes
(){
public
List
<
String
>
listPictureTypes
()
{
List
<
String
>
list
=
Lists
.
newArrayList
();
List
<
String
>
list
=
Lists
.
newArrayList
();
list
.
add
(
"jpg"
);
list
.
add
(
"jpg"
);
list
.
add
(
"jpeg"
);
list
.
add
(
"jpeg"
);
...
@@ -135,7 +136,7 @@ public class FileUtils {
...
@@ -135,7 +136,7 @@ public class FileUtils {
return
list
;
return
list
;
}
}
public
List
<
String
>
listArchiveTypes
(){
public
List
<
String
>
listArchiveTypes
()
{
List
<
String
>
list
=
Lists
.
newArrayList
();
List
<
String
>
list
=
Lists
.
newArrayList
();
list
.
add
(
"rar"
);
list
.
add
(
"rar"
);
list
.
add
(
"zip"
);
list
.
add
(
"zip"
);
...
@@ -160,6 +161,7 @@ public class FileUtils {
...
@@ -160,6 +161,7 @@ public class FileUtils {
/**
/**
* 获取相对路径
* 获取相对路径
*
* @param absolutePath 绝对路径
* @param absolutePath 绝对路径
* @return 相对路径
* @return 相对路径
*/
*/
...
@@ -169,45 +171,51 @@ public class FileUtils {
...
@@ -169,45 +171,51 @@ public class FileUtils {
/**
/**
* 添加转换后PDF缓存
* 添加转换后PDF缓存
*
* @param fileName pdf文件名
* @param fileName pdf文件名
* @param value 缓存相对路径
* @param value
缓存相对路径
*/
*/
public
void
addConvertedFile
(
String
fileName
,
String
value
){
public
void
addConvertedFile
(
String
fileName
,
String
value
)
{
cacheService
.
putPDFCache
(
fileName
,
value
);
cacheService
.
putPDFCache
(
fileName
,
value
);
}
}
/**
/**
* 添加转换后图片组缓存
* 添加转换后图片组缓存
*
* @param pdfFilePath pdf文件绝对路径
* @param pdfFilePath pdf文件绝对路径
* @param num 图片张数
* @param num
图片张数
*/
*/
public
void
addConvertedPdfImage
(
String
pdfFilePath
,
int
num
){
public
void
addConvertedPdfImage
(
String
pdfFilePath
,
int
num
)
{
cacheService
.
putPdfImageCache
(
pdfFilePath
,
num
);
cacheService
.
putPdfImageCache
(
pdfFilePath
,
num
);
}
}
/**
/**
* 获取redis中压缩包内图片文件
* 获取redis中压缩包内图片文件
*
* @param fileKey fileKey
* @param fileKey fileKey
* @return 图片文件访问url列表
* @return 图片文件访问url列表
*/
*/
public
List
<
String
>
getImgCache
(
String
fileKey
){
public
List
<
String
>
getImgCache
(
String
fileKey
)
{
return
cacheService
.
getImgCache
(
fileKey
);
return
cacheService
.
getImgCache
(
fileKey
);
}
}
/**
/**
* 设置redis中压缩包内图片文件
* 设置redis中压缩包内图片文件
*
* @param fileKey fileKey
* @param fileKey fileKey
* @param imgs 图片文件访问url列表
* @param imgs
图片文件访问url列表
*/
*/
public
void
putImgCache
(
String
fileKey
,
List
<
String
>
imgs
)
{
public
void
putImgCache
(
String
fileKey
,
List
<
String
>
imgs
)
{
cacheService
.
putImgCache
(
fileKey
,
imgs
);
cacheService
.
putImgCache
(
fileKey
,
imgs
);
}
}
/**
/**
* 判断文件编码格式
* 判断文件编码格式
*
* @param path 绝对路径
* @param path 绝对路径
* @return 编码格式
* @return 编码格式
*/
*/
public
String
getFileEncodeUTFGBK
(
String
path
){
public
String
getFileEncodeUTFGBK
(
String
path
)
{
String
enc
=
Charset
.
forName
(
"GBK"
).
name
();
String
enc
=
Charset
.
forName
(
"GBK"
).
name
();
File
file
=
new
File
(
path
);
File
file
=
new
File
(
path
);
InputStream
in
;
InputStream
in
;
...
@@ -228,14 +236,15 @@ public class FileUtils {
...
@@ -228,14 +236,15 @@ public class FileUtils {
/**
/**
* 对转换后的文件进行操作(改变编码方式)
* 对转换后的文件进行操作(改变编码方式)
*
* @param outFilePath 文件绝对路径
* @param outFilePath 文件绝对路径
*/
*/
public
void
doActionConvertedFile
(
String
outFilePath
)
{
public
void
doActionConvertedFile
(
String
outFilePath
)
{
StringBuilder
sb
=
new
StringBuilder
();
StringBuilder
sb
=
new
StringBuilder
();
try
(
InputStream
inputStream
=
new
FileInputStream
(
outFilePath
);
try
(
InputStream
inputStream
=
new
FileInputStream
(
outFilePath
);
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
inputStream
,
DEFAULT_CONVERTER_CHARSET
)))
{
BufferedReader
reader
=
new
BufferedReader
(
new
InputStreamReader
(
inputStream
,
DEFAULT_CONVERTER_CHARSET
)))
{
String
line
;
String
line
;
while
(
null
!=
(
line
=
reader
.
readLine
()))
{
while
(
null
!=
(
line
=
reader
.
readLine
()))
{
if
(
line
.
contains
(
"charset=gb2312"
))
{
if
(
line
.
contains
(
"charset=gb2312"
))
{
line
=
line
.
replace
(
"charset=gb2312"
,
"charset=utf-8"
);
line
=
line
.
replace
(
"charset=gb2312"
,
"charset=utf-8"
);
}
}
...
@@ -249,15 +258,17 @@ public class FileUtils {
...
@@ -249,15 +258,17 @@ public class FileUtils {
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
// 重新写入文件
// 重新写入文件
try
(
FileOutputStream
fos
=
new
FileOutputStream
(
outFilePath
);
try
(
FileOutputStream
fos
=
new
FileOutputStream
(
outFilePath
);
BufferedWriter
writer
=
new
BufferedWriter
(
new
OutputStreamWriter
(
fos
,
StandardCharsets
.
UTF_8
)))
{
BufferedWriter
writer
=
new
BufferedWriter
(
new
OutputStreamWriter
(
fos
,
StandardCharsets
.
UTF_8
)))
{
writer
.
write
(
sb
.
toString
());
writer
.
write
(
sb
.
toString
());
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
}
}
/**
/**
* 获取文件后缀
* 获取文件后缀
*
* @param url url
* @param url url
* @return 文件后缀
* @return 文件后缀
*/
*/
...
@@ -273,7 +284,8 @@ public class FileUtils {
...
@@ -273,7 +284,8 @@ public class FileUtils {
/**
/**
* 获取url中的参数
* 获取url中的参数
* @param url url
*
* @param url url
* @param name 参数名
* @param name 参数名
* @return 参数值
* @return 参数值
*/
*/
...
@@ -285,10 +297,10 @@ public class FileUtils {
...
@@ -285,10 +297,10 @@ public class FileUtils {
}
}
//每个键值为一组
//每个键值为一组
String
[]
arrSplit
=
strUrlParam
.
split
(
"[&]"
);
String
[]
arrSplit
=
strUrlParam
.
split
(
"[&]"
);
for
(
String
strSplit
:
arrSplit
)
{
for
(
String
strSplit
:
arrSplit
)
{
String
[]
arrSplitEqual
=
strSplit
.
split
(
"[=]"
);
String
[]
arrSplitEqual
=
strSplit
.
split
(
"[=]"
);
//解析出键值
//解析出键值
if
(
arrSplitEqual
.
length
>
1
)
{
if
(
arrSplitEqual
.
length
>
1
)
{
//正确解析
//正确解析
mapRequest
.
put
(
arrSplitEqual
[
0
],
arrSplitEqual
[
1
]);
mapRequest
.
put
(
arrSplitEqual
[
0
],
arrSplitEqual
[
1
]);
}
else
if
(!
arrSplitEqual
[
0
].
equals
(
""
))
{
}
else
if
(!
arrSplitEqual
[
0
].
equals
(
""
))
{
...
@@ -301,6 +313,7 @@ public class FileUtils {
...
@@ -301,6 +313,7 @@ public class FileUtils {
/**
/**
* 去掉url中的路径,留下请求参数部分
* 去掉url中的路径,留下请求参数部分
*
* @param strURL url地址
* @param strURL url地址
* @return url请求参数部分
* @return url请求参数部分
*/
*/
...
@@ -308,10 +321,10 @@ public class FileUtils {
...
@@ -308,10 +321,10 @@ public class FileUtils {
String
strAllParam
=
null
;
String
strAllParam
=
null
;
strURL
=
strURL
.
trim
();
strURL
=
strURL
.
trim
();
String
[]
arrSplit
=
strURL
.
split
(
"[?]"
);
String
[]
arrSplit
=
strURL
.
split
(
"[?]"
);
if
(
strURL
.
length
()
>
1
)
{
if
(
strURL
.
length
()
>
1
)
{
if
(
arrSplit
.
length
>
1
)
{
if
(
arrSplit
.
length
>
1
)
{
if
(
arrSplit
[
1
]
!=
null
)
{
if
(
arrSplit
[
1
]
!=
null
)
{
strAllParam
=
arrSplit
[
1
];
strAllParam
=
arrSplit
[
1
];
}
}
}
}
}
}
...
@@ -320,23 +333,33 @@ public class FileUtils {
...
@@ -320,23 +333,33 @@ public class FileUtils {
/**
/**
* 获取文件属性
* 获取文件属性
*
* @param url url
* @param url url
* @return 文件属性
* @return 文件属性
*/
*/
public
FileAttribute
getFileAttribute
(
String
url
)
{
public
FileAttribute
getFileAttribute
(
String
url
,
HttpServletRequest
req
)
{
String
fileName
;
FileAttribute
attribute
=
new
FileAttribute
();
FileType
type
;
String
suffix
;
String
suffix
;
String
fullFileName
=
getUrlParameterReg
(
url
,
"fullfilename"
);
String
fullFileName
=
getUrlParameterReg
(
url
,
"fullfilename"
);
if
(
StringUtils
.
hasText
(
fullFileName
))
{
if
(
StringUtils
.
hasText
(
fullFileName
))
{
fileName
=
fullFileName
;
attribute
.
setName
(
fullFileName
);
type
=
typeFromFileName
(
fileName
);
FileType
type
=
typeFromFileName
(
fullFileName
);
suffix
=
suffixFromFileName
(
fileName
);
attribute
.
setType
(
type
);
suffix
=
suffixFromFileName
(
fullFileName
);
}
else
{
}
else
{
fileName
=
getFileNameFromURL
(
url
);
type
=
typeFromUrl
(
url
);
String
fileName
=
getFileNameFromURL
(
url
);
FileType
type
=
typeFromUrl
(
url
);
attribute
.
setName
(
fileName
);
attribute
.
setType
(
type
);
suffix
=
suffixFromUrl
(
url
);
suffix
=
suffixFromUrl
(
url
);
}
}
return
new
FileAttribute
(
type
,
suffix
,
fileName
,
url
);
attribute
.
setSuffix
(
suffix
);
if
(
req
!=
null
)
{
String
officePreviewType
=
req
.
getParameter
(
"officePreviewType"
);
attribute
.
setOfficePreviewType
(
officePreviewType
);
}
return
attribute
;
}
}
}
}
jodconverter-web/src/main/java/cn/keking/web/controller/OnlinePreviewController.java
View file @
c1802b24
package
cn
.
keking
.
web
.
controller
;
package
cn
.
keking
.
web
.
controller
;
import
cn.keking.config.ConfigConstants
;
import
cn.keking.model.FileAttribute
;
import
cn.keking.model.FileAttribute
;
import
cn.keking.service.FilePreview
;
import
cn.keking.service.FilePreview
;
import
cn.keking.service.FilePreviewFactory
;
import
cn.keking.service.FilePreviewFactory
;
...
@@ -49,10 +48,7 @@ public class OnlinePreviewController {
...
@@ -49,10 +48,7 @@ public class OnlinePreviewController {
@RequestMapping
(
value
=
"/onlinePreview"
)
@RequestMapping
(
value
=
"/onlinePreview"
)
public
String
onlinePreview
(
String
url
,
Model
model
,
HttpServletRequest
req
)
{
public
String
onlinePreview
(
String
url
,
Model
model
,
HttpServletRequest
req
)
{
FileAttribute
fileAttribute
=
fileUtils
.
getFileAttribute
(
url
);
FileAttribute
fileAttribute
=
fileUtils
.
getFileAttribute
(
url
,
req
);
req
.
setAttribute
(
"fileKey"
,
req
.
getParameter
(
"fileKey"
));
model
.
addAttribute
(
"pdfDownloadDisable"
,
ConfigConstants
.
getPdfDownloadDisable
());
model
.
addAttribute
(
"officePreviewType"
,
req
.
getParameter
(
"officePreviewType"
));
FilePreview
filePreview
=
previewFactory
.
get
(
fileAttribute
);
FilePreview
filePreview
=
previewFactory
.
get
(
fileAttribute
);
logger
.
info
(
"预览文件url:{},previewType:{}"
,
url
,
fileAttribute
.
getType
());
logger
.
info
(
"预览文件url:{},previewType:{}"
,
url
,
fileAttribute
.
getType
());
return
filePreview
.
filePreviewHandle
(
url
,
model
,
fileAttribute
);
return
filePreview
.
filePreviewHandle
(
url
,
model
,
fileAttribute
);
...
...
jodconverter-web/src/main/java/cn/keking/web/filter/
WatermarkConfig
Filter.java
→
jodconverter-web/src/main/java/cn/keking/web/filter/
AttributeSet
Filter.java
View file @
c1802b24
package
cn
.
keking
.
web
.
filter
;
package
cn
.
keking
.
web
.
filter
;
import
cn.keking.config.ConfigConstants
;
import
cn.keking.config.WatermarkConfigConstants
;
import
cn.keking.config.WatermarkConfigConstants
;
import
javax.servlet.*
;
import
javax.servlet.*
;
import
javax.servlet.http.HttpServletRequest
;
import
java.io.IOException
;
import
java.io.IOException
;
/**
/**
* @author chenjh
* @author chenjh
* @since 2020/5/13 18:34
* @since 2020/5/13 18:34
*/
*/
public
class
WatermarkConfig
Filter
implements
Filter
{
public
class
AttributeSet
Filter
implements
Filter
{
@Override
@Override
public
void
init
(
FilterConfig
filterConfig
)
{
public
void
init
(
FilterConfig
filterConfig
)
{
...
@@ -18,6 +20,26 @@ public class WatermarkConfigFilter implements Filter {
...
@@ -18,6 +20,26 @@ public class WatermarkConfigFilter implements Filter {
@Override
@Override
public
void
doFilter
(
ServletRequest
request
,
ServletResponse
response
,
FilterChain
filterChain
)
throws
IOException
,
ServletException
{
public
void
doFilter
(
ServletRequest
request
,
ServletResponse
response
,
FilterChain
filterChain
)
throws
IOException
,
ServletException
{
this
.
setWatermarkAttribute
(
request
);
this
.
setFileAttribute
(
request
);
filterChain
.
doFilter
(
request
,
response
);
}
/**
* 设置办公文具预览逻辑需要的属性
* @param request request
*/
private
void
setFileAttribute
(
ServletRequest
request
){
HttpServletRequest
httpRequest
=
(
HttpServletRequest
)
request
;
request
.
setAttribute
(
"pdfDownloadDisable"
,
ConfigConstants
.
getPdfDownloadDisable
());
request
.
setAttribute
(
"fileKey"
,
httpRequest
.
getParameter
(
"fileKey"
));
}
/**
* 设置水印属性
* @param request request
*/
private
void
setWatermarkAttribute
(
ServletRequest
request
)
{
String
watermarkTxt
=
request
.
getParameter
(
"watermarkTxt"
);
String
watermarkTxt
=
request
.
getParameter
(
"watermarkTxt"
);
request
.
setAttribute
(
"watermarkTxt"
,
watermarkTxt
!=
null
?
watermarkTxt
:
WatermarkConfigConstants
.
getWatermarkTxt
());
request
.
setAttribute
(
"watermarkTxt"
,
watermarkTxt
!=
null
?
watermarkTxt
:
WatermarkConfigConstants
.
getWatermarkTxt
());
request
.
setAttribute
(
"watermarkXSpace"
,
WatermarkConfigConstants
.
getWatermarkXSpace
());
request
.
setAttribute
(
"watermarkXSpace"
,
WatermarkConfigConstants
.
getWatermarkXSpace
());
...
@@ -29,7 +51,6 @@ public class WatermarkConfigFilter implements Filter {
...
@@ -29,7 +51,6 @@ public class WatermarkConfigFilter implements Filter {
request
.
setAttribute
(
"watermarkWidth"
,
WatermarkConfigConstants
.
getWatermarkWidth
());
request
.
setAttribute
(
"watermarkWidth"
,
WatermarkConfigConstants
.
getWatermarkWidth
());
request
.
setAttribute
(
"watermarkHeight"
,
WatermarkConfigConstants
.
getWatermarkHeight
());
request
.
setAttribute
(
"watermarkHeight"
,
WatermarkConfigConstants
.
getWatermarkHeight
());
request
.
setAttribute
(
"watermarkAngle"
,
WatermarkConfigConstants
.
getWatermarkAngle
());
request
.
setAttribute
(
"watermarkAngle"
,
WatermarkConfigConstants
.
getWatermarkAngle
());
filterChain
.
doFilter
(
request
,
response
);
}
}
@Override
@Override
...
...
jodconverter-web/src/main/java/cn/keking/web/filter/FilterConfiguration.java
View file @
c1802b24
...
@@ -57,7 +57,7 @@ public class FilterConfiguration {
...
@@ -57,7 +57,7 @@ public class FilterConfiguration {
Set
<
String
>
filterUri
=
new
HashSet
<>();
Set
<
String
>
filterUri
=
new
HashSet
<>();
filterUri
.
add
(
"/onlinePreview"
);
filterUri
.
add
(
"/onlinePreview"
);
filterUri
.
add
(
"/picturesPreview"
);
filterUri
.
add
(
"/picturesPreview"
);
WatermarkConfigFilter
filter
=
new
WatermarkConfig
Filter
();
AttributeSetFilter
filter
=
new
AttributeSet
Filter
();
FilterRegistrationBean
registrationBean
=
new
FilterRegistrationBean
();
FilterRegistrationBean
registrationBean
=
new
FilterRegistrationBean
();
registrationBean
.
setFilter
(
filter
);
registrationBean
.
setFilter
(
filter
);
registrationBean
.
setUrlPatterns
(
filterUri
);
registrationBean
.
setUrlPatterns
(
filterUri
);
...
...
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