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
7ea70bf4
Commit
7ea70bf4
authored
Oct 31, 2019
by
陈精华
Committed by
kl
Nov 06, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化:图片模式下图片url使用baseUrl
parent
b1fdbd26
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
14 additions
and
37 deletions
+14
-37
ConfigRefreshComponent.java
...rc/main/java/cn/keking/config/ConfigRefreshComponent.java
+3
-3
OfficeFilePreviewImpl.java
...in/java/cn/keking/service/impl/OfficeFilePreviewImpl.java
+4
-4
PdfFilePreviewImpl.java
.../main/java/cn/keking/service/impl/PdfFilePreviewImpl.java
+3
-3
PdfUtils.java
jodconverter-web/src/main/java/cn/keking/utils/PdfUtils.java
+2
-4
OnlinePreviewController.java
...ava/cn/keking/web/controller/OnlinePreviewController.java
+2
-23
No files found.
jodconverter-web/src/main/java/cn/keking/config/ConfigRefreshComponent.java
View file @
7ea70bf4
...
@@ -52,7 +52,7 @@ public class ConfigRefreshComponent {
...
@@ -52,7 +52,7 @@ public class ConfigRefreshComponent {
String
ftpPassword
;
String
ftpPassword
;
String
ftpControlEncoding
;
String
ftpControlEncoding
;
String
configFilePath
=
OfficeUtils
.
getCustomizedConfigPath
();
String
configFilePath
=
OfficeUtils
.
getCustomizedConfigPath
();
String
baseU
lr
;
String
baseU
rl
;
while
(
true
)
{
while
(
true
)
{
FileReader
fileReader
=
new
FileReader
(
configFilePath
);
FileReader
fileReader
=
new
FileReader
(
configFilePath
);
BufferedReader
bufferedReader
=
new
BufferedReader
(
fileReader
);
BufferedReader
bufferedReader
=
new
BufferedReader
(
fileReader
);
...
@@ -67,7 +67,7 @@ public class ConfigRefreshComponent {
...
@@ -67,7 +67,7 @@ public class ConfigRefreshComponent {
ftpControlEncoding
=
properties
.
getProperty
(
"ftp.control.encoding"
,
DEFAULT_FTP_CONTROL_ENCODING
);
ftpControlEncoding
=
properties
.
getProperty
(
"ftp.control.encoding"
,
DEFAULT_FTP_CONTROL_ENCODING
);
textArray
=
text
.
split
(
","
);
textArray
=
text
.
split
(
","
);
mediaArray
=
media
.
split
(
","
);
mediaArray
=
media
.
split
(
","
);
baseU
lr
=
properties
.
getProperty
(
"base.url"
,
DEFAULT_BASE_URL
);
baseU
rl
=
properties
.
getProperty
(
"base.url"
,
DEFAULT_BASE_URL
);
ConfigConstants
.
setCacheEnabled
(
cacheEnabled
);
ConfigConstants
.
setCacheEnabled
(
cacheEnabled
);
ConfigConstants
.
setSimText
(
textArray
);
ConfigConstants
.
setSimText
(
textArray
);
ConfigConstants
.
setMedia
(
mediaArray
);
ConfigConstants
.
setMedia
(
mediaArray
);
...
@@ -75,7 +75,7 @@ public class ConfigRefreshComponent {
...
@@ -75,7 +75,7 @@ public class ConfigRefreshComponent {
ConfigConstants
.
setFtpUsername
(
ftpUsername
);
ConfigConstants
.
setFtpUsername
(
ftpUsername
);
ConfigConstants
.
setFtpPassword
(
ftpPassword
);
ConfigConstants
.
setFtpPassword
(
ftpPassword
);
ConfigConstants
.
setFtpControlEncoding
(
ftpControlEncoding
);
ConfigConstants
.
setFtpControlEncoding
(
ftpControlEncoding
);
ConfigConstants
.
setBaseUrl
(
baseU
lr
);
ConfigConstants
.
setBaseUrl
(
baseU
rl
);
bufferedReader
.
close
();
bufferedReader
.
close
();
fileReader
.
close
();
fileReader
.
close
();
Thread
.
sleep
(
1000L
);
Thread
.
sleep
(
1000L
);
...
...
jodconverter-web/src/main/java/cn/keking/service/impl/OfficeFilePreviewImpl.java
View file @
7ea70bf4
...
@@ -12,8 +12,8 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -12,8 +12,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.ui.Model
;
import
org.springframework.ui.Model
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
java.io.File
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -45,7 +45,7 @@ public class OfficeFilePreviewImpl implements FilePreview {
...
@@ -45,7 +45,7 @@ public class OfficeFilePreviewImpl implements FilePreview {
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
// 预览Type,参数传了就取参数的,没传取系统默认
// 预览Type,参数传了就取参数的,没传取系统默认
String
officePreviewType
=
model
.
asMap
().
get
(
"officePreviewType"
)
==
null
?
ConfigConstants
.
getOfficePreviewType
()
:
model
.
asMap
().
get
(
"officePreviewType"
).
toString
();
String
officePreviewType
=
model
.
asMap
().
get
(
"officePreviewType"
)
==
null
?
ConfigConstants
.
getOfficePreviewType
()
:
model
.
asMap
().
get
(
"officePreviewType"
).
toString
();
String
originUrl
=
(
String
)
model
.
asMap
().
get
(
"originUrl"
);
String
baseUrl
=
(
String
)
RequestContextHolder
.
currentRequestAttributes
().
getAttribute
(
"baseUrl"
,
0
);
String
suffix
=
fileAttribute
.
getSuffix
();
String
suffix
=
fileAttribute
.
getSuffix
();
String
fileName
=
fileAttribute
.
getName
();
String
fileName
=
fileAttribute
.
getName
();
boolean
isHtml
=
suffix
.
equalsIgnoreCase
(
"xls"
)
||
suffix
.
equalsIgnoreCase
(
"xlsx"
);
boolean
isHtml
=
suffix
.
equalsIgnoreCase
(
"xls"
)
||
suffix
.
equalsIgnoreCase
(
"xlsx"
);
...
@@ -73,8 +73,8 @@ public class OfficeFilePreviewImpl implements FilePreview {
...
@@ -73,8 +73,8 @@ public class OfficeFilePreviewImpl implements FilePreview {
}
}
}
}
}
}
if
(!
isHtml
&&
origin
Url
!=
null
&&
(
OFFICE_PREVIEW_TYPE_IMAGE
.
equals
(
officePreviewType
)
||
OFFICE_PREVIEW_TYPE_ALLIMAGES
.
equals
(
officePreviewType
)))
{
if
(!
isHtml
&&
base
Url
!=
null
&&
(
OFFICE_PREVIEW_TYPE_IMAGE
.
equals
(
officePreviewType
)
||
OFFICE_PREVIEW_TYPE_ALLIMAGES
.
equals
(
officePreviewType
)))
{
List
<
String
>
imageUrls
=
pdfUtils
.
pdf2jpg
(
outFilePath
,
pdfName
,
origin
Url
);
List
<
String
>
imageUrls
=
pdfUtils
.
pdf2jpg
(
outFilePath
,
pdfName
,
base
Url
);
if
(
imageUrls
==
null
||
imageUrls
.
size
()
<
1
)
{
if
(
imageUrls
==
null
||
imageUrls
.
size
()
<
1
)
{
model
.
addAttribute
(
"msg"
,
"office转图片异常,请联系管理员"
);
model
.
addAttribute
(
"msg"
,
"office转图片异常,请联系管理员"
);
model
.
addAttribute
(
"fileType"
,
fileAttribute
.
getSuffix
());
model
.
addAttribute
(
"fileType"
,
fileAttribute
.
getSuffix
());
...
...
jodconverter-web/src/main/java/cn/keking/service/impl/PdfFilePreviewImpl.java
View file @
7ea70bf4
...
@@ -10,8 +10,8 @@ import cn.keking.utils.PdfUtils;
...
@@ -10,8 +10,8 @@ import cn.keking.utils.PdfUtils;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.ui.Model
;
import
org.springframework.ui.Model
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
java.io.File
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -38,7 +38,7 @@ public class PdfFilePreviewImpl implements FilePreview{
...
@@ -38,7 +38,7 @@ public class PdfFilePreviewImpl implements FilePreview{
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
=
model
.
asMap
().
get
(
"officePreviewType"
)
==
null
?
ConfigConstants
.
getOfficePreviewType
()
:
model
.
asMap
().
get
(
"officePreviewType"
).
toString
();
String
originUrl
=
model
.
asMap
().
get
(
"originUrl"
).
toString
(
);
String
baseUrl
=
(
String
)
RequestContextHolder
.
currentRequestAttributes
().
getAttribute
(
"baseUrl"
,
0
);
model
.
addAttribute
(
"pdfUrl"
,
url
);
model
.
addAttribute
(
"pdfUrl"
,
url
);
String
pdfName
=
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
"."
)
+
1
)
+
"pdf"
;
String
pdfName
=
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
"."
)
+
1
)
+
"pdf"
;
String
outFilePath
=
fileDir
+
pdfName
;
String
outFilePath
=
fileDir
+
pdfName
;
...
@@ -51,7 +51,7 @@ public class PdfFilePreviewImpl implements FilePreview{
...
@@ -51,7 +51,7 @@ public class PdfFilePreviewImpl implements FilePreview{
return
"fileNotSupported"
;
return
"fileNotSupported"
;
}
}
outFilePath
=
response
.
getContent
();
outFilePath
=
response
.
getContent
();
List
<
String
>
imageUrls
=
pdfUtils
.
pdf2jpg
(
outFilePath
,
pdfName
,
origin
Url
);
List
<
String
>
imageUrls
=
pdfUtils
.
pdf2jpg
(
outFilePath
,
pdfName
,
base
Url
);
if
(
imageUrls
==
null
||
imageUrls
.
size
()
<
1
)
{
if
(
imageUrls
==
null
||
imageUrls
.
size
()
<
1
)
{
model
.
addAttribute
(
"msg"
,
"pdf转图片异常,请联系管理员"
);
model
.
addAttribute
(
"msg"
,
"pdf转图片异常,请联系管理员"
);
model
.
addAttribute
(
"fileType"
,
fileAttribute
.
getSuffix
());
model
.
addAttribute
(
"fileType"
,
fileAttribute
.
getSuffix
());
...
...
jodconverter-web/src/main/java/cn/keking/utils/PdfUtils.java
View file @
7ea70bf4
...
@@ -23,14 +23,12 @@ public class PdfUtils {
...
@@ -23,14 +23,12 @@ public class PdfUtils {
@Autowired
@Autowired
FileUtils
fileUtils
;
FileUtils
fileUtils
;
public
List
<
String
>
pdf2jpg
(
String
pdfFilePath
,
String
pdfName
,
String
u
rl
)
{
public
List
<
String
>
pdf2jpg
(
String
pdfFilePath
,
String
pdfName
,
String
baseU
rl
)
{
List
<
String
>
imageUrls
=
new
ArrayList
<>();
List
<
String
>
imageUrls
=
new
ArrayList
<>();
Integer
imageCount
=
fileUtils
.
getConvertedPdfImage
(
pdfFilePath
);
Integer
imageCount
=
fileUtils
.
getConvertedPdfImage
(
pdfFilePath
);
String
imageFileSuffix
=
".jpg"
;
String
imageFileSuffix
=
".jpg"
;
// https://8个字符 http://7个字符 从这后面开始出现的第一个/就是当前file.Dir下的根目录
int
index1
=
url
.
indexOf
(
"/"
,
8
);
String
pdfFolder
=
pdfName
.
substring
(
0
,
pdfName
.
length
()
-
4
);
String
pdfFolder
=
pdfName
.
substring
(
0
,
pdfName
.
length
()
-
4
);
String
urlPrefix
=
url
.
substring
(
0
,
index1
+
1
)
+
pdfFolder
;
String
urlPrefix
=
baseUrl
+
pdfFolder
;
if
(
imageCount
!=
null
&&
imageCount
.
intValue
()
>
0
)
{
if
(
imageCount
!=
null
&&
imageCount
.
intValue
()
>
0
)
{
for
(
int
i
=
0
;
i
<
imageCount
;
i
++)
for
(
int
i
=
0
;
i
<
imageCount
;
i
++)
imageUrls
.
add
(
urlPrefix
+
"/"
+
i
+
imageFileSuffix
);
imageUrls
.
add
(
urlPrefix
+
"/"
+
i
+
imageFileSuffix
);
...
...
jodconverter-web/src/main/java/cn/keking/web/controller/OnlinePreviewController.java
View file @
7ea70bf4
...
@@ -49,38 +49,17 @@ public class OnlinePreviewController {
...
@@ -49,38 +49,17 @@ public class OnlinePreviewController {
* @param model
* @param model
* @return
* @return
*/
*/
@RequestMapping
(
value
=
"onlinePreview"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"
/
onlinePreview"
,
method
=
RequestMethod
.
GET
)
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
.
setAttribute
(
"fileKey"
,
req
.
getParameter
(
"fileKey"
));
req
.
setAttribute
(
"fileKey"
,
req
.
getParameter
(
"fileKey"
));
model
.
addAttribute
(
"officePreviewType"
,
req
.
getParameter
(
"officePreviewType"
));
model
.
addAttribute
(
"officePreviewType"
,
req
.
getParameter
(
"officePreviewType"
));
model
.
addAttribute
(
"originUrl"
,
req
.
getRequestURL
().
toString
());
FilePreview
filePreview
=
previewFactory
.
get
(
fileAttribute
);
FilePreview
filePreview
=
previewFactory
.
get
(
fileAttribute
);
return
filePreview
.
filePreviewHandle
(
url
,
model
,
fileAttribute
);
return
filePreview
.
filePreviewHandle
(
url
,
model
,
fileAttribute
);
}
}
/**
* 多图片切换预览
*
* @param model
* @param req
* @return
* @throws UnsupportedEncodingException
*/
@RequestMapping
(
value
=
"picturesPreview"
,
method
=
RequestMethod
.
GET
)
public
String
picturesPreview
(
String
urls
,
String
currentUrl
,
Model
model
,
HttpServletRequest
req
)
throws
UnsupportedEncodingException
{
// 路径转码
String
decodedUrl
=
URLDecoder
.
decode
(
urls
,
"utf-8"
);
String
decodedCurrentUrl
=
URLDecoder
.
decode
(
currentUrl
,
"utf-8"
);
// 抽取文件并返回文件列表
String
[]
imgs
=
decodedUrl
.
split
(
"\\|"
);
List
imgurls
=
Arrays
.
asList
(
imgs
);
model
.
addAttribute
(
"imgurls"
,
imgurls
);
model
.
addAttribute
(
"currentUrl"
,
decodedCurrentUrl
);
return
"picture"
;
}
@RequestMapping
(
value
=
"
picturesPreview"
,
method
=
RequestMethod
.
POST
)
@RequestMapping
(
value
=
"
/picturesPreview"
)
public
String
picturesPreview
(
Model
model
,
HttpServletRequest
req
)
throws
UnsupportedEncodingException
{
public
String
picturesPreview
(
Model
model
,
HttpServletRequest
req
)
throws
UnsupportedEncodingException
{
String
urls
=
req
.
getParameter
(
"urls"
);
String
urls
=
req
.
getParameter
(
"urls"
);
String
currentUrl
=
req
.
getParameter
(
"currentUrl"
);
String
currentUrl
=
req
.
getParameter
(
"currentUrl"
);
...
...
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