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
5d18e447
Commit
5d18e447
authored
Dec 13, 2017
by
woshiduanmu
Committed by
klboke
Dec 14, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加properties文件预览支持
parent
1dfc1f67
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
75 additions
and
45 deletions
+75
-45
DownloadUtils.java
src/main/java/com/yudianbank/utils/DownloadUtils.java
+4
-0
OfficeToPdf.java
src/main/java/com/yudianbank/utils/OfficeToPdf.java
+0
-18
ShedulerClean.java
src/main/java/com/yudianbank/utils/ShedulerClean.java
+1
-1
SimTextUtil.java
src/main/java/com/yudianbank/utils/SimTextUtil.java
+24
-0
OnlinePreviewController.java
...om/yudianbank/web/controller/OnlinePreviewController.java
+24
-19
application.properties
src/main/resources/application.properties
+4
-2
compress.ftl
src/main/resources/web/compress.ftl
+16
-3
picture.ftl
src/main/resources/web/picture.ftl
+2
-2
No files found.
src/main/java/com/yudianbank/utils/DownloadUtils.java
View file @
5d18e447
...
@@ -48,6 +48,8 @@ public class DownloadUtils {
...
@@ -48,6 +48,8 @@ public class DownloadUtils {
UUID
uuid
=
UUID
.
randomUUID
();
UUID
uuid
=
UUID
.
randomUUID
();
if
(
null
==
fileName
)
{
if
(
null
==
fileName
)
{
fileName
=
uuid
+
"."
+
type
;
fileName
=
uuid
+
"."
+
type
;
}
else
{
// 文件后缀不一致时,以type为准(针对simText【将类txt文件转为txt】)
fileName
=
fileName
.
replace
(
fileName
.
substring
(
fileName
.
lastIndexOf
(
"."
)
+
1
),
type
);
}
}
String
realPath
=
fileDir
+
fileName
;
String
realPath
=
fileDir
+
fileName
;
File
dirFile
=
new
File
(
fileDir
);
File
dirFile
=
new
File
(
fileDir
);
...
@@ -67,6 +69,8 @@ public class DownloadUtils {
...
@@ -67,6 +69,8 @@ public class DownloadUtils {
os
.
close
();
os
.
close
();
in
.
close
();
in
.
close
();
response
.
setContent
(
realPath
);
response
.
setContent
(
realPath
);
// 同样针对类txt文件,如果成功msg包含的是转换后的文件名
response
.
setMsg
(
fileName
);
return
response
;
return
response
;
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
...
...
src/main/java/com/yudianbank/utils/OfficeToPdf.java
View file @
5d18e447
...
@@ -22,24 +22,6 @@ public class OfficeToPdf {
...
@@ -22,24 +22,6 @@ public class OfficeToPdf {
return
office2pdf
(
inputFilePath
,
outputFilePath
);
return
office2pdf
(
inputFilePath
,
outputFilePath
);
}
}
/**
* 连接OpenOffice.org 并且启动OpenOffice.org
*
* @return
*/
/*public OfficeManager getOfficeManager() {
DefaultOfficeManagerConfiguration config = new DefaultOfficeManagerConfiguration();
// 获取OpenOffice.org 3的安装目录
String officeHome = openOfficePath;
config.setOfficeHome(officeHome);
// 启动OpenOffice的服务
OfficeManager officeManager = config.buildOfficeManager();
officeManager.start();
return officeManager;
}*/
/**
/**
* 转换文件
* 转换文件
*
*
...
...
src/main/java/com/yudianbank/utils/ShedulerClean.java
View file @
5d18e447
...
@@ -11,7 +11,7 @@ public class ShedulerClean {
...
@@ -11,7 +11,7 @@ public class ShedulerClean {
@Value
(
"${file.dir}"
)
@Value
(
"${file.dir}"
)
String
fileDir
;
String
fileDir
;
@Scheduled
(
cron
=
"0 0 23 * * ?"
)
//每晚23点执行一次
//
@Scheduled(cron = "0 0 23 * * ?") //每晚23点执行一次
public
void
clean
(){
public
void
clean
(){
System
.
out
.
println
(
"执行一次清空文件夹"
);
System
.
out
.
println
(
"执行一次清空文件夹"
);
DeleteFileUtil
.
deleteDirectory
(
fileDir
);
DeleteFileUtil
.
deleteDirectory
(
fileDir
);
...
...
src/main/java/com/yudianbank/utils/SimTextUtil.java
0 → 100644
View file @
5d18e447
package
com
.
yudianbank
.
utils
;
import
com.yudianbank.param.ReturnResponse
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
/**
* 读取类文本文件
* @author yudian-it
* @date 2017/12/13
*/
@Component
public
class
SimTextUtil
{
@Value
(
"${file.dir}"
)
String
fileDir
;
@Autowired
DownloadUtils
downloadUtils
;
public
ReturnResponse
<
String
>
readSimText
(
String
url
,
String
fileName
,
String
needEncode
){
ReturnResponse
<
String
>
response
=
downloadUtils
.
downLoad
(
url
,
"txt"
,
fileName
,
needEncode
);
return
response
;
}
}
src/main/java/com/yudianbank/web/controller/OnlinePreviewController.java
View file @
5d18e447
package
com
.
yudianbank
.
web
.
controller
;
package
com
.
yudianbank
.
web
.
controller
;
import
com.
fasterxml.jackson.core.JsonProcessingException
;
import
com.
ctrip.framework.apollo.Config
;
import
com.
fasterxml.jackson.databind.ObjectMapper
;
import
com.
ctrip.framework.apollo.spring.annotation.ApolloConfig
;
import
com.yudianbank.param.ReturnResponse
;
import
com.yudianbank.param.ReturnResponse
;
import
com.yudianbank.utils.DownloadUtils
;
import
com.yudianbank.utils.*
;
import
com.yudianbank.utils.FileUtils
;
import
com.yudianbank.utils.OfficeToPdf
;
import
com.yudianbank.utils.ZipReader
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.stereotype.Controller
;
...
@@ -15,10 +12,10 @@ import org.springframework.util.StringUtils;
...
@@ -15,10 +12,10 @@ import org.springframework.util.StringUtils;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
org.springframework.web.bind.annotation.RequestMethod
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.File
;
import
java.io.File
;
import
java.io.UnsupportedEncodingException
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLDecoder
;
import
java.net.URLDecoder
;
import
java.util.Arrays
;
/**
/**
* @author yudian-it
* @author yudian-it
...
@@ -33,6 +30,10 @@ public class OnlinePreviewController {
...
@@ -33,6 +30,10 @@ public class OnlinePreviewController {
DownloadUtils
downloadUtils
;
DownloadUtils
downloadUtils
;
@Autowired
@Autowired
ZipReader
zipReader
;
ZipReader
zipReader
;
@Autowired
SimTextUtil
simTextUtil
;
@ApolloConfig
Config
config
;
@Value
(
"${file.dir}"
)
@Value
(
"${file.dir}"
)
String
fileDir
;
String
fileDir
;
...
@@ -49,31 +50,32 @@ public class OnlinePreviewController {
...
@@ -49,31 +50,32 @@ public class OnlinePreviewController {
@RequestMapping
(
value
=
"onlinePreview"
,
method
=
RequestMethod
.
GET
)
@RequestMapping
(
value
=
"onlinePreview"
,
method
=
RequestMethod
.
GET
)
public
String
onlinePreview
(
String
url
,
String
needEncode
,
Model
model
)
throws
UnsupportedEncodingException
{
public
String
onlinePreview
(
String
url
,
String
needEncode
,
Model
model
)
throws
UnsupportedEncodingException
{
// 路径转码
// 路径转码
u
rl
=
URLDecoder
.
decode
(
url
,
"utf-8"
);
String
decodedU
rl
=
URLDecoder
.
decode
(
url
,
"utf-8"
);
String
type
=
typeFromUrl
(
url
);
String
type
=
typeFromUrl
(
url
);
String
suffix
=
suffixFromUrl
(
url
);
String
suffix
=
suffixFromUrl
(
url
);
// 抽取文件并返回文件列表
String
fileName
=
fileUtils
.
getFileNameFromURL
(
decodedUrl
);
model
.
addAttribute
(
"fileType"
,
suffix
);
model
.
addAttribute
(
"fileType"
,
suffix
);
if
(
type
.
equalsIgnoreCase
(
"picture"
))
{
if
(
type
.
equalsIgnoreCase
(
"picture"
))
{
model
.
addAttribute
(
"imgurl"
,
url
);
model
.
addAttribute
(
"imgurl"
,
url
);
return
"picture"
;
return
"picture"
;
}
else
if
(
type
.
equalsIgnoreCase
(
"
txt"
)
}
else
if
(
type
.
equalsIgnoreCase
(
"
simText"
)){
||
type
.
equalsIgnoreCase
(
"html"
)
ReturnResponse
<
String
>
response
=
simTextUtil
.
readSimText
(
decodedUrl
,
fileName
,
needEncode
);
||
type
.
equalsIgnoreCase
(
"xml"
)
if
(
0
!=
response
.
getCode
())
{
||
type
.
equalsIgnoreCase
(
"java"
)
model
.
addAttribute
(
"msg"
,
response
.
getMsg
());
||
type
.
equalsIgnoreCase
(
"properties"
)
return
"fileNotSupported"
;
||
type
.
equalsIgnoreCase
(
"mp3"
)){
}
model
.
addAttribute
(
"ordinaryUrl"
,
url
);
model
.
addAttribute
(
"ordinaryUrl"
,
response
.
getMsg
()
);
return
"txt"
;
return
"txt"
;
}
else
if
(
type
.
equalsIgnoreCase
(
"pdf"
)){
}
else
if
(
type
.
equalsIgnoreCase
(
"pdf"
)){
model
.
addAttribute
(
"pdfUrl"
,
url
);
model
.
addAttribute
(
"pdfUrl"
,
url
);
return
"pdf"
;
return
"pdf"
;
}
else
if
(
type
.
equalsIgnoreCase
(
"compress"
)){
}
else
if
(
type
.
equalsIgnoreCase
(
"compress"
)){
// 抽取文件并返回文件列表
// 抽取文件并返回文件列表
String
fileName
=
fileUtils
.
getFileNameFromURL
(
url
);
String
fileTree
=
null
;
String
fileTree
=
null
;
// 判断文件名是否存在(redis缓存读取)
// 判断文件名是否存在(redis缓存读取)
if
(!
StringUtils
.
hasText
(
fileUtils
.
getConvertedFile
(
fileName
)))
{
if
(!
StringUtils
.
hasText
(
fileUtils
.
getConvertedFile
(
fileName
)))
{
ReturnResponse
<
String
>
response
=
downloadUtils
.
downLoad
(
u
rl
,
suffix
,
fileName
,
needEncode
);
ReturnResponse
<
String
>
response
=
downloadUtils
.
downLoad
(
decodedU
rl
,
suffix
,
fileName
,
needEncode
);
if
(
0
!=
response
.
getCode
())
{
if
(
0
!=
response
.
getCode
())
{
model
.
addAttribute
(
"msg"
,
response
.
getMsg
());
model
.
addAttribute
(
"msg"
,
response
.
getMsg
());
return
"fileNotSupported"
;
return
"fileNotSupported"
;
...
@@ -99,7 +101,6 @@ public class OnlinePreviewController {
...
@@ -99,7 +101,6 @@ public class OnlinePreviewController {
return
"fileNotSupported"
;
return
"fileNotSupported"
;
}
}
}
else
if
(
"office"
.
equalsIgnoreCase
(
type
))
{
}
else
if
(
"office"
.
equalsIgnoreCase
(
type
))
{
String
fileName
=
fileUtils
.
getFileNameFromURL
(
url
);
String
pdfName
=
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
"."
)
+
1
)
String
pdfName
=
fileName
.
substring
(
0
,
fileName
.
lastIndexOf
(
"."
)
+
1
)
+
((
suffix
.
equalsIgnoreCase
(
"xls"
)
||
suffix
.
equalsIgnoreCase
(
"xlsx"
))
?
+
((
suffix
.
equalsIgnoreCase
(
"xls"
)
||
suffix
.
equalsIgnoreCase
(
"xlsx"
))
?
"html"
:
"pdf"
);
"html"
:
"pdf"
);
...
@@ -107,7 +108,7 @@ public class OnlinePreviewController {
...
@@ -107,7 +108,7 @@ public class OnlinePreviewController {
if
(!
fileUtils
.
listConvertedFiles
().
containsKey
(
pdfName
))
{
if
(!
fileUtils
.
listConvertedFiles
().
containsKey
(
pdfName
))
{
String
filePath
=
fileDir
+
fileName
;
String
filePath
=
fileDir
+
fileName
;
if
(!
new
File
(
filePath
).
exists
())
{
if
(!
new
File
(
filePath
).
exists
())
{
ReturnResponse
<
String
>
response
=
downloadUtils
.
downLoad
(
u
rl
,
suffix
,
null
,
needEncode
);
ReturnResponse
<
String
>
response
=
downloadUtils
.
downLoad
(
decodedU
rl
,
suffix
,
null
,
needEncode
);
if
(
0
!=
response
.
getCode
())
{
if
(
0
!=
response
.
getCode
())
{
model
.
addAttribute
(
"msg"
,
response
.
getMsg
());
model
.
addAttribute
(
"msg"
,
response
.
getMsg
());
return
"fileNotSupported"
;
return
"fileNotSupported"
;
...
@@ -163,6 +164,10 @@ public class OnlinePreviewController {
...
@@ -163,6 +164,10 @@ public class OnlinePreviewController {
if
(
fileUtils
.
listOfficeTypes
().
contains
(
fileType
.
toLowerCase
()))
{
if
(
fileUtils
.
listOfficeTypes
().
contains
(
fileType
.
toLowerCase
()))
{
fileType
=
"office"
;
fileType
=
"office"
;
}
}
if
(
Arrays
.
asList
(
config
.
getArrayProperty
(
"simText"
,
","
,
new
String
[]{}))
.
contains
(
fileType
.
toLowerCase
()))
{
fileType
=
"simText"
;
}
return
fileType
;
return
fileType
;
}
}
...
...
src/main/resources/application.properties
View file @
5d18e447
...
@@ -20,4 +20,6 @@ office.home = C:\\Program Files (x86)\\OpenOffice 4
...
@@ -20,4 +20,6 @@ office.home = C:\\Program Files (x86)\\OpenOffice 4
server.tomcat.uri-encoding
=
UTF-8
server.tomcat.uri-encoding
=
UTF-8
converted.file.charset
=
GBK
converted.file.charset
=
GBK
#======================================#文件上传限制#======================================#
#======================================#文件上传限制#======================================#
spring.http.multipart.max-file-size
=
100MB
spring.http.multipart.max-file-size
=
100MB
\ No newline at end of file
## 支持的类文本格式的文件类型
simText
=
txt,html,xml,java,properties,mp3,mp4,sql
\ No newline at end of file
src/main/resources/web/compress.ftl
View file @
5d18e447
...
@@ -55,9 +55,22 @@
...
@@ -55,9 +55,22 @@
},
},
onClick
:
function
(
event
,
treeId
,
treeNode
)
{
onClick
:
function
(
event
,
treeId
,
treeNode
)
{
if
(
!
treeNode
.
directory
)
{
if
(
!
treeNode
.
directory
)
{
var
winHeight
=
window
.
document
.
documentElement
.
clientHeight
-
10
;
/**实现窗口最大化**/
window
.
open
(
env_config
.
server_preview_url
+
encodeURIComponent
(
env_config
.
server_base_url
+
treeNode
.
fileName
)
+
"&needEncode=1"
,
var
fulls
=
"left=0,screenX=0,top=0,screenY=0,scrollbars=1"
;
//定义弹出窗口的参数
"_blank"
,
"height="
+
winHeight
+
",top=80,left=80,toolbar=no, menubar=no, scrollbars=yes, resizable=yes"
);
if
(
window
.
screen
)
{
var
ah
=
screen
.
availHeight
-
30
;
var
aw
=
(
screen
.
availWidth
-
10
)
/
2
;
fulls
+=
",height="
+
ah
;
fulls
+=
",innerHeight="
+
ah
;
fulls
+=
",width="
+
aw
;
fulls
+=
",innerWidth="
+
aw
;
fulls
+=
",resizable"
}
else
{
fulls
+=
",resizable"
;
// 对于不支持screen属性的浏览器,可以手工进行最大化。 manually
}
window
.
open
(
env_config
.
server_preview_url
+
encodeURIComponent
(
env_config
.
server_base_url
+
treeNode
.
fileName
)
+
"&needEncode=1"
,
"_blank"
,
fulls
);
}
}
}
}
}
}
...
...
src/main/resources/web/picture.ftl
View file @
5d18e447
...
@@ -15,8 +15,7 @@
...
@@ -15,8 +15,7 @@
<h1>
如果图片质量很好,首次加载图片时间可能会有点长,请耐心等待
</h1>
<h1>
如果图片质量很好,首次加载图片时间可能会有点长,请耐心等待
</h1>
<ul
id=
"dowebok"
>
<ul
id=
"dowebok"
>
<li><img
id=
"Imgbox"
src=
"#"
width=
"800px"
height=
"550px"
></li>
<li><img
id=
"Imgbox"
src=
"#"
width=
"800px"
height=
"auto"
></li>
</ul>
</ul>
<script
src=
"js/viewer.min.js"
></script>
<script
src=
"js/viewer.min.js"
></script>
<script>
<script>
...
@@ -26,6 +25,7 @@
...
@@ -26,6 +25,7 @@
document
.
getElementById
(
"Imgbox"
).
src
=
document
.
getElementById
(
"url"
).
value
;
document
.
getElementById
(
"Imgbox"
).
src
=
document
.
getElementById
(
"url"
).
value
;
}
}
var
viewer
=
new
Viewer
(
document
.
getElementById
(
'dowebok'
),
{
url
:
'src'
});
var
viewer
=
new
Viewer
(
document
.
getElementById
(
'dowebok'
),
{
url
:
'src'
});
viewer
.
show
();
</script>
</script>
<input
name=
"url"
value=
"${imgurl}"
type=
"hidden"
id=
"url"
>
<input
name=
"url"
value=
"${imgurl}"
type=
"hidden"
id=
"url"
>
</body>
</body>
...
...
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