Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
Z
zzfszzy
Project
Project
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
Graph
比较
统计图
议题
0
议题
0
列表
看板
标记
Milestones
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
注册表
注册表
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
svn
zzfszzy
Commits
51ba2e6e
提交
51ba2e6e
authored
6月 17, 2020
作者:
xinjunguo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
--no commit message
上级
1e9a9826
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
274 行增加
和
170 行删除
+274
-170
BookUtil.java
com.zrqx.file/src/main/java/com/zrqx/file/util/BookUtil.java
+31
-10
EpubResolve.java
...qx.file/src/main/java/com/zrqx/file/util/EpubResolve.java
+0
-107
EpubUtil.java
com.zrqx.file/src/main/java/com/zrqx/file/util/EpubUtil.java
+243
-53
没有找到文件。
com.zrqx.file/src/main/java/com/zrqx/file/util/BookUtil.java
浏览文件 @
51ba2e6e
...
...
@@ -67,26 +67,47 @@ public class BookUtil {
ev
.
setBook
(
book
);
ev
.
setEbook
(
ebook
);
/*ev.setBookgoods(bookgoods);
ev.setBookissued(bookissued);*/
//isbn
book
.
setIsbn
(
epubUtil
.
getISBN
());
ev
=
er
.
setBookInfo
(
epubUtil
,
ev
);
/**
* 保存元数据相关内容
*/
// 名称
book
.
setName
(
epubUtil
.
get
BookTitl
e
());
book
.
setName
(
epubUtil
.
get
Nam
e
());
// 作者
book
.
setAuthor
(
epubUtil
.
getAuthor
());
book
.
setPublisher
(
epubUtil
.
getPublisher
());
book
.
setExecutiveEditor
(
epubUtil
.
getAuthor
());
// 出版时间
book
.
setPublishTime
(
DateUtils
.
dateTimeToStrYMD
(
epubUtil
.
getPublishDate
()));
// 关键字(图书的名字)20
ebook
.
setKeywords
(
epubUtil
.
getBookTitle
());
// 出版单位
book
.
setPublisher
(
epubUtil
.
getPublisher
());
// 字数
book
.
setFontCount
(
epubUtil
.
getFontCount
());
// 版次
book
.
setRevision
(
epubUtil
.
getRevision
());
// 关键字
ebook
.
setKeywords
(
epubUtil
.
getKeywords
());
// 开本
book
.
setFormat
(
epubUtil
.
getFormat
());
// 印张
book
.
setPrintCount
(
epubUtil
.
getPrintCount
());
// 页数
book
.
setTotalPages
(
epubUtil
.
getTotalPages
());
//印次
book
.
setPrintNo
(
epubUtil
.
getPrintNo
());
//中图分类
book
.
setMidpicid
(
epubUtil
.
getMidpicid
());
//邮编
book
.
setZipCode
(
epubUtil
.
getZipcode
());
//CIP
book
.
setCIP
(
epubUtil
.
getCIP
());
//承印
book
.
setPrint
(
epubUtil
.
getPrint
());
//定价
ebook
.
setPrice
(
epubUtil
.
getPrice
());
ebook
.
setPriceOption
(
1
);
//售价
ebook
.
setRealPrice
(
epubUtil
.
getPrice
());
// 保存封面
if
(
epubUtil
.
getCover
()
!=
null
){
String
imgName
=
epubUtil
.
getCover
().
getHref
().
substring
(
epubUtil
.
getCover
().
getHref
().
lastIndexOf
(
"/"
)
+
1
);
...
...
com.zrqx.file/src/main/java/com/zrqx/file/util/EpubResolve.java
浏览文件 @
51ba2e6e
...
...
@@ -110,113 +110,6 @@ public class EpubResolve {
int
index
=
0
;
for
(;
index
<
listReferences
.
size
();
index
++)
{
TOCReference
spineReference
=
listReferences
.
get
(
index
);
// 判断只获取版权页的内容
if
(
spineReference
.
getTitle
().
contains
(
"版权"
))
{
// dom选择器,获取doc中的所有<p>标签
Elements
ps
=
getDocument
(
spineReference
).
select
(
"p"
);
// 遍历Elements 中的元素
int
i
=
0
;
for
(
Element
p
:
ps
)
{
// 文本内容
String
ptext
=
p
.
text
().
replaceAll
(
"\\s*"
,
""
).
replace
(
" "
,
""
).
replace
(
" "
,
""
);
if
(
ptext
!=
null
&&
!
ptext
.
equals
(
""
))
{
// 著作方式(著,编著,编,主编,改编,译,编译,绘,摄,书)
/*
* if (i == 1 && StringUtils.anyContains(ptext, "著,编著,编,主编,改编,译,编译,绘,摄,书")) {
* String editor = ""; if (ptext.contains("—") || ptext.contains("-")) { editor
* = ptext.substring(0, ptext.lastIndexOf("—") > 0 ? ptext.lastIndexOf("—") :
* ptext.lastIndexOf("-")); } else { editor = ptext.substring(0,
* StringUtils.containsMaxIndex(ptext, "著,编") + 1); editor = editor.length() >
* 30 ? "" : editor; } ev.getBook().setEditor(editor); }
*/
// 责任编辑
/*if (StringUtils.anyContains(ptext, "责任编辑")) {
String executiveEditor = ptext.replace("executiveEditor", "");
ev.getBook().setExecutiveEditor(executiveEditor);
}*/
// 图书字数
if
(
StringUtils
.
anyContains
(
ptext
,
"字数"
))
{
String
wordCount
=
ptext
.
replace
(
"字数"
,
""
).
replace
(
"千字"
,
""
);
ev
.
getBook
().
setFontCount
(
wordCount
);
}
// 出版发行
if
(
StringUtils
.
anyContains
(
ptext
,
"出版者"
))
{
ptext
=
ptext
.
replace
(
"出版者"
,
""
);
String
publisher
=
ptext
.
replace
(
"出版者"
,
""
);
ev
.
getBook
().
setPublisher
(
publisher
);
}
// 图书版次,(印次加工不标准暂不使用)
if
(
StringUtils
.
anyContains
(
ptext
,
"版次"
))
{
String
edition
=
ptext
.
replace
(
"版次"
,
""
);
ev
.
getBook
().
setRevision
(
edition
);
}
// 图书开本
if
(
StringUtils
.
anyContains
(
ptext
,
"开本"
))
{
String
format
=
ptext
.
replace
(
"开本"
,
""
);
ev
.
getBook
().
setFormat
(
format
);
}
// 印张
if
(
StringUtils
.
anyContains
(
ptext
,
"印张"
))
{
String
sela
=
ptext
.
replace
(
"印张"
,
""
);
ev
.
getBook
().
setPrintCount
(
sela
);
}
// 印次
if
(
StringUtils
.
anyContains
(
ptext
,
"印次"
))
{
String
printNo
=
ptext
.
replace
(
"印次"
,
""
);
ev
.
getBook
().
setPrintNo
(
printNo
);
}
// 邮编
if
(
StringUtils
.
anyContains
(
ptext
,
"邮编"
)
||
StringUtils
.
anyContains
(
ptext
,
"邮政编码"
))
{
int
start
=
ptext
.
indexOf
(
"邮编"
);
String
result
=
null
;
if
(
start
<
0
)
{
start
=
ptext
.
indexOf
(
"邮政编码"
);
result
=
ptext
.
substring
(
start
+
4
,
start
+
10
);
}
else
{
result
=
ptext
.
substring
(
start
+
2
,
start
+
8
);
}
ev
.
getBook
().
setZipCode
(
result
);
}
// isbn
if
(
ev
.
getBook
().
getIsbn
()
==
null
||
""
.
equals
(
ev
.
getBook
().
getIsbn
())){
if
(
StringUtils
.
anyContains
(
ptext
,
"ISBN"
))
{
String
isbn
=
ptext
.
replace
(
"ISBN"
,
""
).
replace
(
"-"
,
""
);
ev
.
getBook
().
setIsbn
(
isbn
);
}
}
// 中图分类
/* if (StringUtils.anyContains(ptext, "Ⅰ.①")) {
String midpicid = ptext.substring(ptext.length()-8, ptext.length());
ev.getBook().setMidpicid(midpicid);
}*/
if
(
StringUtils
.
anyContains
(
ptext
,
"定价"
))
{
Float
price
=
0.0f
;
try
{
Float
.
parseFloat
(
ptext
.
substring
(
ptext
.
indexOf
(
"价"
)
+
1
,
ptext
.
indexOf
(
"元"
)
>
0
?
ptext
.
indexOf
(
"元"
)
:
ptext
.
length
())
.
replace
(
"元"
,
""
));
price
=
Float
.
parseFloat
(
ptext
.
substring
(
ptext
.
indexOf
(
"价"
)
+
1
,
ptext
.
indexOf
(
"元"
)
>
0
?
ptext
.
indexOf
(
"元"
)
:
ptext
.
length
())
.
replace
(
"元"
,
""
).
replaceAll
(
"[\u4e00-\u9fa5a-zA-Z/ //::]"
,
""
));
ev
.
getEbook
().
setPrice
(
new
BigDecimal
(((
Number
)
price
).
toString
()));
ev
.
getEbook
().
setRealPrice
(
new
BigDecimal
(((
Number
)
price
).
toString
()));
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"价格信息异常:"
+
ptext
);
continue
;
}
}
}
i
++;
}
}
if
(
StringUtils
.
anyContains
(
spineReference
.
getTitle
().
replaceAll
(
"[ ]"
,
""
),
"序,序言,前言,摘要,内容简介"
))
{
String
doc
=
getDocument
(
spineReference
).
select
(
"body"
).
html
().
replace
(
spineReference
.
getTitle
(),
spineReference
.
getTitle
()
+
" "
);
...
...
com.zrqx.file/src/main/java/com/zrqx/file/util/EpubUtil.java
浏览文件 @
51ba2e6e
...
...
@@ -6,11 +6,14 @@ import java.io.FileInputStream;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.math.BigDecimal
;
import
java.text.ParseException
;
import
java.text.SimpleDateFormat
;
import
java.util.List
;
import
java.util.zip.ZipInputStream
;
import
org.apache.commons.lang3.StringUtils
;
import
nl.siegmann.epublib.domain.Author
;
import
nl.siegmann.epublib.domain.Book
;
import
nl.siegmann.epublib.domain.Date
;
...
...
@@ -221,111 +224,298 @@ public class EpubUtil {
* @throws Exception
*/
public
String
getISBN
()
throws
Exception
{
String
isbn
=
null
;
List
<
Identifier
>
identifiers
=
getMetadata
().
getIdentifiers
();
for
(
Identifier
identifier:
identifiers
){
String
value
=
identifier
.
getValue
().
replace
(
"-"
,
""
);
if
(
value
.
matches
(
"^97[8|9]\\d{10}$"
)
){
//新版isbn号格式
// if(value.contains("-")){
value
=
value
.
replace
(
"-"
,
""
);
isbn
=
value
;
break
;
String
isbn
=
null
;
try
{
for
(
Identifier
identifier
:
getMetadata
().
getIdentifiers
()){
if
(
identifier
.
getScheme
().
equals
(
"bookid"
)){
isbn
=
identifier
.
getValue
();
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
isbn
;
}
/**
* 获取图书作者
* 获取图书名称
* @throws Exception
*/
public
String
get
Author
()
{
List
<
Author
>
authors
=
null
;
public
String
get
Name
()
throws
Exception
{
String
name
=
null
;
try
{
authors
=
getMetadata
().
getAuthors
();
for
(
Identifier
identifier
:
getMetadata
().
getIdentifiers
()){
if
(
identifier
.
getScheme
().
equals
(
"title"
)){
name
=
identifier
.
getValue
();
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
String
author
=
""
;
if
(
authors
.
size
()>
0
){
author
=
authors
.
get
(
0
).
getFirstname
()+
authors
.
get
(
0
).
getLastname
();
author
=
author
.
replaceAll
(
"[\\[\\],]"
,
" "
);
return
name
;
}
return
author
;
/**
* 获取图书作者
* @throws Exception
*/
public
String
getAuthor
()
throws
Exception
{
String
author
=
null
;
try
{
for
(
Identifier
identifier
:
getMetadata
().
getIdentifiers
()){
if
(
identifier
.
getScheme
().
equals
(
"creator"
)){
author
=
identifier
.
getValue
();
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
author
;
}
/**
* 获取出版日期
*/
public
java
.
util
.
Date
getPublishDate
(){
List
<
Date
>
dates
=
null
;
java
.
util
.
Date
publicDate
=
null
;
String
date
=
null
;
try
{
dates
=
getMetadata
().
getDates
();
for
(
Identifier
identifier
:
getMetadata
().
getIdentifiers
()){
if
(
identifier
.
getScheme
().
equals
(
"date"
)){
date
=
identifier
.
getValue
();
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyyy-MM"
);
publicDate
=
sdf
.
parse
(
date
);
}
}
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"日期转换错误!"
);
e
.
printStackTrace
();
}
SimpleDateFormat
sdf
=
new
SimpleDateFormat
(
"yyy"
);
String
tempDate
=
""
;
if
(
dates
.
size
()>
0
){
if
(
dates
.
get
(
0
).
toString
().
contains
(
"."
)){
sdf
=
new
SimpleDateFormat
(
"yyy.MM"
);
return
publicDate
;
}
/**
* 出版单位
*/
public
String
getPublisher
()
throws
Exception
{
String
publisher
=
null
;
try
{
for
(
Identifier
identifier
:
getMetadata
().
getIdentifiers
()){
if
(
identifier
.
getScheme
().
equals
(
"publisher"
)){
publisher
=
identifier
.
getValue
();
}
if
(
dates
.
get
(
0
).
toString
().
contains
(
"-"
)){
sdf
=
new
SimpleDateFormat
(
"yyy-MM"
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
publisher
;
}
/**
* 获取图书的字数
*/
public
String
getFontCount
(){
String
fontCount
=
null
;
try
{
for
(
Identifier
identifier
:
getMetadata
().
getIdentifiers
()){
if
(
identifier
.
getScheme
().
equals
(
"words"
)){
fontCount
=
identifier
.
getValue
();
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
fontCount
;
}
tempDate
=
dates
.
get
(
0
).
toString
();
/**
* 获取图书的版次
*/
public
String
getRevision
(){
String
revision
=
null
;
try
{
for
(
Identifier
identifier
:
getMetadata
().
getIdentifiers
()){
if
(
identifier
.
getScheme
().
equals
(
"version"
)){
revision
=
identifier
.
getValue
();
}
java
.
util
.
Date
publicDate
=
null
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
revision
;
}
/**
* 获取图书的关键词
*/
public
String
getKeywords
(){
String
keywords
=
null
;
try
{
if
(
tempDate
!=
null
&&
!
tempDate
.
equals
(
""
)){
publicDate
=
sdf
.
parse
(
tempDate
);
for
(
Identifier
identifier
:
getMetadata
().
getIdentifiers
()){
if
(
identifier
.
getScheme
().
equals
(
"keywords"
)){
keywords
=
identifier
.
getValue
();
}
}
catch
(
ParseException
e
)
{
System
.
out
.
println
(
"日期转换错误!"
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
keywords
;
}
return
publicDate
;
/**
* 获取图书的开本
*/
public
String
getFormat
(){
String
format
=
null
;
try
{
for
(
Identifier
identifier
:
getMetadata
().
getIdentifiers
()){
if
(
identifier
.
getScheme
().
equals
(
"format"
)){
format
=
identifier
.
getValue
();
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
format
;
}
/**
*
出版单位
*
获取图书的印张
*/
public
String
getPublisher
(){
String
publisher
=
""
;
List
<
String
>
publishers
;
public
String
getPrintCount
(){
String
printcount
=
null
;
try
{
publishers
=
getMetadata
().
getPublishers
();
for
(
String
p
:
publishers
){
if
(
p
.
contains
(
"-"
)){
publisher
=
publisher
+
"、"
+
p
;
break
;
}
else
{
publisher
=
p
;
for
(
Identifier
identifier
:
getMetadata
().
getIdentifiers
()){
if
(
identifier
.
getScheme
().
equals
(
"pagenumber"
)){
printcount
=
identifier
.
getValue
();
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
printcount
;
}
return
publisher
;
/**
* 获取图书的页数
*/
public
String
getTotalPages
(){
String
totalPages
=
null
;
try
{
for
(
Identifier
identifier
:
getMetadata
().
getIdentifiers
()){
if
(
identifier
.
getScheme
().
equals
(
"pagenumber"
)){
totalPages
=
identifier
.
getValue
();
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
totalPages
;
}
/**
* 获取图书的印次
*/
public
String
getPrintNo
(){
String
printNo
=
null
;
try
{
for
(
Identifier
identifier
:
getMetadata
().
getIdentifiers
()){
if
(
identifier
.
getScheme
().
equals
(
"printno"
)){
printNo
=
identifier
.
getValue
();
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
printNo
;
}
/**
* 获取图书的
名字
* 获取图书的
中图分类
*/
public
String
getBookTitle
(){
String
bookTitle
=
""
;
//List<String> bookTitle2 = null;
public
String
getMidpicid
(){
String
midpicid
=
null
;
try
{
bookTitle
=
getMetadata
().
getFirstTitle
();
//bookTitle2 = getMetadata().getTitles();
for
(
Identifier
identifier
:
getMetadata
().
getIdentifiers
()){
if
(
identifier
.
getScheme
().
equals
(
"clcnumber"
)){
midpicid
=
identifier
.
getValue
();
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
bookTitle
;
return
midpicid
;
}
/**
* 获取图书的邮编
*/
public
String
getZipcode
(){
String
zipcode
=
null
;
try
{
for
(
Identifier
identifier
:
getMetadata
().
getIdentifiers
()){
if
(
identifier
.
getScheme
().
equals
(
"zipcode"
)){
zipcode
=
identifier
.
getValue
();
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
zipcode
;
}
/**
* 获取图书的CIP
*/
public
String
getCIP
(){
String
CIP
=
null
;
try
{
for
(
Identifier
identifier
:
getMetadata
().
getIdentifiers
()){
if
(
identifier
.
getScheme
().
equals
(
"CIP"
)){
CIP
=
identifier
.
getValue
();
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
CIP
;
}
/**
* 获取图书的承印
*/
public
String
getPrint
(){
String
print
=
null
;
try
{
for
(
Identifier
identifier
:
getMetadata
().
getIdentifiers
()){
if
(
identifier
.
getScheme
().
equals
(
"printcompany"
)){
print
=
identifier
.
getValue
();
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
print
;
}
/**
* 获取图书的定价
*/
public
BigDecimal
getPrice
(){
String
price
=
null
;
BigDecimal
p
=
null
;
try
{
for
(
Identifier
identifier
:
getMetadata
().
getIdentifiers
()){
if
(
identifier
.
getScheme
().
equals
(
"price"
)){
price
=
identifier
.
getValue
();
if
(
StringUtils
.
isNotBlank
(
price
)){
p
=
new
BigDecimal
(
price
);
}
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
return
p
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论