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
jenkins
slm-fileview
Commits
d4b11a40
Commit
d4b11a40
authored
Dec 25, 2020
by
kl
Committed by
kl
Dec 25, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化文本类型预览逻辑
parent
da155392
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
28 deletions
+13
-28
freemarker_implicit.ftl
jodconverter-web/src/main/config/freemarker_implicit.ftl
+1
-0
SimTextFilePreviewImpl.java
...n/java/cn/keking/service/impl/SimTextFilePreviewImpl.java
+5
-14
txt.ftl
jodconverter-web/src/main/resources/web/txt.ftl
+7
-14
No files found.
jodconverter-web/src/main/config/freemarker_implicit.ftl
View file @
d4b11a40
[#ftl]
[#-- @implicitly included --]
[#-- @ftlvariable name="textData" type="java.lang.String" --]
[#-- @ftlvariable name="xmlContent" type="java.lang.String" --]
[#-- @ftlvariable name="textContent" type="java.lang.String" --]
[#-- @ftlvariable name="textType" type="java.lang.String" --]
...
...
jodconverter-web/src/main/java/cn/keking/service/impl/SimTextFilePreviewImpl.java
View file @
d4b11a40
...
...
@@ -29,32 +29,23 @@ public class SimTextFilePreviewImpl implements FilePreview {
}
@Override
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
){
public
String
filePreviewHandle
(
String
url
,
Model
model
,
FileAttribute
fileAttribute
)
{
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
());
model
.
addAttribute
(
"fileType"
,
fileAttribute
.
getSuffix
());
return
"fileNotSupported"
;
}
try
{
File
originFile
=
new
File
(
response
.
getContent
());
File
previewFile
=
new
File
(
response
.
getContent
()
+
".txt"
);
if
(
previewFile
.
exists
())
{
previewFile
.
delete
();
}
Files
.
copy
(
originFile
.
toPath
(),
previewFile
.
toPath
());
if
(
fileAttribute
.
getType
().
equals
(
FileType
.
xml
)){
String
xmlString
=
FileUtils
.
readFileToString
(
previewFile
,
StandardCharsets
.
UTF_8
);
model
.
addAttribute
(
"xmlContent"
,
Base64Utils
.
encodeToString
(
xmlString
.
getBytes
()));
}
String
xmlString
=
FileUtils
.
readFileToString
(
originFile
,
StandardCharsets
.
UTF_8
);
model
.
addAttribute
(
"textData"
,
Base64Utils
.
encodeToString
(
xmlString
.
getBytes
()));
}
catch
(
IOException
e
)
{
model
.
addAttribute
(
"msg"
,
e
.
getLocalizedMessage
());
model
.
addAttribute
(
"fileType"
,
fileAttribute
.
getSuffix
());
model
.
addAttribute
(
"fileType"
,
fileAttribute
.
getSuffix
());
return
"fileNotSupported"
;
}
model
.
addAttribute
(
"ordinaryUrl"
,
response
.
getMsg
());
return
"txt"
;
}
...
...
jodconverter-web/src/main/resources/web/txt.ftl
View file @
d4b11a40
...
...
@@ -7,6 +7,7 @@
</head>
<body>
<input
hidden
id=
"textType"
value=
"${textType}"
>
<input
hidden
id=
"textData"
value=
"${textData}"
>
<div
class=
"container"
>
<
#
if
textType
??
&&
textType =
=
"
markdown
"
>
...
...
@@ -16,7 +17,6 @@
</p>
<div
id=
"markdown"
style=
"padding: 18px;"
></div>
<
#
elseif
textType
??
&&
textType =
=
"
xml
"
>
<input
hidden
id=
"xmlContent"
value=
"${xmlContent}"
>
<div
id=
"xml"
style=
"padding: 18px;"
></div>
<
#
else
>
<div
id=
"text"
></div>
...
...
@@ -42,6 +42,9 @@
$
(
"#markdown_btn"
).
hide
()
initWaterMark
();
fetchData
();
loadText
();
loadXmlData
()
loadMarkdown
();
}
/**
...
...
@@ -73,17 +76,8 @@
* 获取文本数据
*/
function
fetchData
()
{
$
.
ajax
({
type
:
'GET'
,
url
:
'${ordinaryUrl}'
,
success
:
function
(
data
)
{
window
.
textData
=
data
;
window
.
textPreData
=
"<pre>"
+
data
+
"</pre>"
;
loadText
();
loadXmlData
()
loadMarkdown
();
}
});
window
.
textData
=
Base64
.
decode
(
$
(
"#textData"
).
val
())
window
.
textPreData
=
"<pre>"
+
window
.
textData
+
"</pre>"
;
}
/**
...
...
@@ -108,8 +102,7 @@
*/
function
loadXmlData
()
{
if
(
$
(
"#textType"
).
val
()
===
"xml"
)
{
var
xmlStr
=
Base64
.
decode
(
$
(
"#xmlContent"
).
val
());
var
xmlNode
=
xmlTreeViewer
.
parseXML
(
xmlStr
);
var
xmlNode
=
xmlTreeViewer
.
parseXML
(
window
.
textData
);
var
retNode
=
xmlTreeViewer
.
getXMLViewerNode
(
xmlNode
.
xml
);
$
(
"#xml"
).
html
(
retNode
);
}
...
...
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