提交 51ba2e6e authored 作者: xinjunguo's avatar xinjunguo

--no commit message

上级 1e9a9826
...@@ -67,26 +67,47 @@ public class BookUtil { ...@@ -67,26 +67,47 @@ public class BookUtil {
ev.setBook(book); ev.setBook(book);
ev.setEbook(ebook); ev.setEbook(ebook);
/*ev.setBookgoods(bookgoods); //isbn
ev.setBookissued(bookissued);*/
book.setIsbn(epubUtil.getISBN()); book.setIsbn(epubUtil.getISBN());
ev = er.setBookInfo(epubUtil, ev); ev = er.setBookInfo(epubUtil, ev);
/** /**
* 保存元数据相关内容 * 保存元数据相关内容
*/ */
// 名称 // 名称
book.setName(epubUtil.getBookTitle()); book.setName(epubUtil.getName());
// 作者 // 作者
book.setAuthor(epubUtil.getAuthor()); book.setAuthor(epubUtil.getAuthor());
book.setPublisher(epubUtil.getPublisher());
book.setExecutiveEditor(epubUtil.getAuthor());
// 出版时间 // 出版时间
book.setPublishTime(DateUtils.dateTimeToStrYMD(epubUtil.getPublishDate())); book.setPublishTime(DateUtils.dateTimeToStrYMD(epubUtil.getPublishDate()));
// 出版单位
// 关键字(图书的名字)20 book.setPublisher(epubUtil.getPublisher());
ebook.setKeywords(epubUtil.getBookTitle()); // 字数
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){ if(epubUtil.getCover() != null){
String imgName = epubUtil.getCover().getHref().substring(epubUtil.getCover().getHref().lastIndexOf("/") + 1); String imgName = epubUtil.getCover().getHref().substring(epubUtil.getCover().getHref().lastIndexOf("/") + 1);
......
...@@ -110,113 +110,6 @@ public class EpubResolve { ...@@ -110,113 +110,6 @@ public class EpubResolve {
int index = 0; int index = 0;
for (; index < listReferences.size(); index++) { for (; index < listReferences.size(); index++) {
TOCReference spineReference = listReferences.get(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("[  ]", ""), "序,序言,前言,摘要,内容简介")) { if (StringUtils.anyContains(spineReference.getTitle().replaceAll("[  ]", ""), "序,序言,前言,摘要,内容简介")) {
String doc = getDocument(spineReference).select("body").html().replace(spineReference.getTitle(), String doc = getDocument(spineReference).select("body").html().replace(spineReference.getTitle(),
spineReference.getTitle() + "  "); spineReference.getTitle() + "  ");
......
...@@ -6,11 +6,14 @@ import java.io.FileInputStream; ...@@ -6,11 +6,14 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.math.BigDecimal;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.List; import java.util.List;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
import org.apache.commons.lang3.StringUtils;
import nl.siegmann.epublib.domain.Author; import nl.siegmann.epublib.domain.Author;
import nl.siegmann.epublib.domain.Book; import nl.siegmann.epublib.domain.Book;
import nl.siegmann.epublib.domain.Date; import nl.siegmann.epublib.domain.Date;
...@@ -221,111 +224,298 @@ public class EpubUtil { ...@@ -221,111 +224,298 @@ public class EpubUtil {
* @throws Exception * @throws Exception
*/ */
public String getISBN() throws Exception{ public String getISBN() throws Exception{
String isbn=null; String isbn = null;
List<Identifier> identifiers=getMetadata().getIdentifiers(); try {
for(Identifier identifier:identifiers){ for(Identifier identifier : getMetadata().getIdentifiers()){
String value=identifier.getValue().replace("-", ""); if(identifier.getScheme().equals("bookid")){
if(value.matches("^97[8|9]\\d{10}$") ){//新版isbn号格式 isbn = identifier.getValue();
// if(value.contains("-")){ }
value=value.replace("-", "");
isbn=value;
break;
} }
} catch (Exception e) {
e.printStackTrace();
} }
return isbn; return isbn;
} }
/** /**
* 获取图书作者 * 获取图书名称
* @throws Exception
*/ */
public String getAuthor(){ public String getName() throws Exception{
List<Author> authors = null; String name = null;
try { try {
authors = getMetadata().getAuthors(); for(Identifier identifier : getMetadata().getIdentifiers()){
if(identifier.getScheme().equals("title")){
name = identifier.getValue();
}
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
String author = ""; return name;
if(authors.size()>0){
author = authors.get(0).getFirstname()+authors.get(0).getLastname();
author = author.replaceAll("[\\[\\],]"," ");
} }
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(){ public java.util.Date getPublishDate(){
List<Date> dates = null; java.util.Date publicDate = null;
String date = null;
try { 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) { } catch (Exception e) {
System.out.println("日期转换错误!");
e.printStackTrace(); e.printStackTrace();
} }
SimpleDateFormat sdf = new SimpleDateFormat("yyy"); return publicDate;
String tempDate = ""; }
if(dates.size()>0){
if(dates.get(0).toString().contains(".")){ /**
sdf= new SimpleDateFormat("yyy.MM"); * 出版单位
*/
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 { try {
if(tempDate!=null && !tempDate.equals("")){ for(Identifier identifier : getMetadata().getIdentifiers()){
publicDate = sdf.parse(tempDate); if(identifier.getScheme().equals("keywords")){
keywords = identifier.getValue();
} }
} catch (ParseException e) { }
System.out.println("日期转换错误!"); } catch (Exception e) {
e.printStackTrace(); 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(){ public String getPrintCount(){
String publisher = ""; String printcount = null;
List<String> publishers;
try { try {
publishers = getMetadata().getPublishers(); for(Identifier identifier : getMetadata().getIdentifiers()){
for(String p : publishers){ if(identifier.getScheme().equals("pagenumber")){
if(p.contains("-")){ printcount = identifier.getValue();
publisher = publisher + "、" + p;
break;
}else {
publisher = p;
} }
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); 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(){ public String getMidpicid(){
String bookTitle = ""; String midpicid = null;
//List<String> bookTitle2 = null;
try { try {
bookTitle = getMetadata().getFirstTitle(); for(Identifier identifier : getMetadata().getIdentifiers()){
//bookTitle2 = getMetadata().getTitles(); if(identifier.getScheme().equals("clcnumber")){
midpicid = identifier.getValue();
}
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); 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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论