提交 fdc9ef98 authored 作者: lizhuo's avatar lizhuo

--no commit message

上级 cba3487d
......@@ -50,6 +50,7 @@ public class EpubResolve {
/**
* 将html文件解析成Document对象
*
* @param spineReference
* @return
*/
......@@ -101,8 +102,6 @@ public class EpubResolve {
return allid;
}
// **********************************************************************************
// ***************************** 图书信息 *****************************
// **********************************************************************************
......@@ -144,7 +143,8 @@ public class EpubResolve {
String editor = "";
if (i == 1 && StringUtils.anyContains(ptext, "著,编著,编,主编,改编,译,编译,绘,摄,书")) {
if (ptext.contains("—") || ptext.contains("-")) {
editor = ptext.substring(0, ptext.lastIndexOf("—") > 0 ? ptext.lastIndexOf("—") : ptext.lastIndexOf("-"));
editor = ptext.substring(0,
ptext.lastIndexOf("—") > 0 ? ptext.lastIndexOf("—") : ptext.lastIndexOf("-"));
} else {
editor = ptext.substring(0, StringUtils.containsMaxIndex(ptext, "著,编") + 1);
editor = editor.length() > 90 ? "" : editor;
......@@ -156,7 +156,8 @@ public class EpubResolve {
String clcnumberCode = "";
if (ptext.contains("Ⅳ.")) {
if (ptext.lastIndexOf("Ⅳ.") > 0) {
clcnumberCode = ptext.substring(ptext.lastIndexOf("Ⅳ.") + 2).replaceAll("[\u2460-\u2469 ]+", "");
clcnumberCode = ptext.substring(ptext.lastIndexOf("Ⅳ.") + 2)
.replaceAll("[\u2460-\u2469 ]+", "");
}
}
// book.setClcnumberCode(clcnumberCode);
......@@ -164,9 +165,11 @@ public class EpubResolve {
// 图书字数15
String wordNumber = "";
if (ptext.contains("字数") && ptext.contains("千")) {
wordNumber = ptext.substring(ptext.indexOf("字数") + 2, ptext.indexOf("千")).replace("千", "").replaceAll("[\u4e00-\u9fa5a-zA-Z/ //::]", "");
wordNumber = ptext.substring(ptext.indexOf("字数") + 2, ptext.indexOf("千")).replace("千", "")
.replaceAll("[\u4e00-\u9fa5a-zA-Z/ //::]", "");
} else if (!ptext.contains("字数") && ptext.contains("千字")) {
wordNumber = ptext.substring(ptext.indexOf("千") - 4, ptext.indexOf("千")).replace("千", "").replaceAll("[\u4e00-\u9fa5a-zA-Z/ //::]", "");
wordNumber = ptext.substring(ptext.indexOf("千") - 4, ptext.indexOf("千")).replace("千", "")
.replaceAll("[\u4e00-\u9fa5a-zA-Z/ //::]", "");
}
if (!wordNumber.equals("")) {
// book.setWordNumber(wordNumber);
......@@ -183,9 +186,14 @@ public class EpubResolve {
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/ //::]", ""));
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/ //::]", ""));
if (price == null || price == 0f) {
// book.setStatus(SysConstant.CHECK_NOTPASS);
}
......@@ -206,14 +214,16 @@ public class EpubResolve {
Ebook ebook = new Ebook();
String intro = "暂无简介";
if (StringUtils.anyContains(spineReference.getTitle().replaceAll("[  ]", ""), "序,序言,前言,摘要,内容简介")) {
String doc = getDocument(spineReference).select("h1,h2,h3,h4,h5,p,div,img").text().replace(spineReference.getTitle(), spineReference.getTitle() + "  ");
String doc = getDocument(spineReference).select("h1,h2,h3,h4,h5,p,div,img").text()
.replace(spineReference.getTitle(), spineReference.getTitle() + "  ");
intro = doc.substring(0, doc.length() < 500 ? doc.length() : 500);
ebook.setBookIntro(intro);
} else {
if (spineReference.getTitle().replaceAll("[  ]", "").contains("目录")) {
TOCReference reference = listReferences.get(index + 1);
String doc = getDocument(reference).select("h1,h2,h3,h4,h5,p,div,img").text().replace(spineReference.getTitle(), spineReference.getTitle() + "  ");
String doc = getDocument(reference).select("h1,h2,h3,h4,h5,p,div,img").text()
.replace(spineReference.getTitle(), spineReference.getTitle() + "  ");
intro = doc.substring(0, doc.length() < 500 ? doc.length() : 500);
ebook.setBookCatalog(intro);
}
......@@ -239,9 +249,9 @@ public class EpubResolve {
* @author 刘自耀
* @date 2015-7-1 上午10:15:18
*/
public String getCoverImage(EpubUtil epubUtil,String rootPath, String bookFolderPath) {
public String getCoverImage(EpubUtil epubUtil, String rootPath, String bookFolderPath) {
// 保存封面在内的所有图片到磁盘上
List<FileInfo> entity = getImages(epubUtil,rootPath, bookFolderPath);
List<FileInfo> entity = getImages(epubUtil, rootPath, bookFolderPath);
// 封面图片的href
Resource cover = epubUtil.getCover();
......@@ -272,7 +282,8 @@ public class EpubResolve {
* @param book
* @date 2015-7-1 下午3:34:41
*/
public Set<ChapterLibrary> setChapter(List<TOCReference> listReferences, TOCReference refe, Integer level, Ebook ebook, Set<ChapterLibrary> chapterSet) {
public Set<ChapterLibrary> setChapter(List<TOCReference> listReferences, TOCReference refe, Integer level,
Ebook ebook, Set<ChapterLibrary> chapterSet) {
ChapterLibrary chapter = null;
// ================================ 遍历目录方式一
......@@ -354,24 +365,19 @@ public class EpubResolve {
/**
*
* @Description: TODO
* @param @param
* listReferences
* @param @param
* contentSet
* @param @param
* book
* @param @param
* imgtzMap
* @param @param
* data
* @param @param listReferences
* @param @param contentSet
* @param @param book
* @param @param imgtzMap
* @param @param data
* @param @return
* @return Object[]
* @throws @author
* 李禚
* @throws @author 李禚
* @date 2016年5月26日
*/
@SuppressWarnings("unchecked")
public Object[] setContent(List<TOCReference> listReferences, Set<ArticleLibrary> contentSet, Ebook ebook, Map<String, String> imgtzMap, Object[] data) {
public Object[] setContent(List<TOCReference> listReferences, Set<ArticleLibrary> contentSet, Ebook ebook,
Map<String, String> imgtzMap, Object[] data) {
// 遍历章节的内容
Map<String, TOCReference> titles1 = null;
Map<String, TOCReference> ids1 = null;
......@@ -429,9 +435,11 @@ public class EpubResolve {
if (e.nextElementSibling() != null) {
after = e.nextElementSibling().attr("class");
}
if (StringUtils.anyEquals(before, "picture_figure_note,picture_table_note,picture_table_title,picture_figure_title,tableCaption")) {
if (StringUtils.anyEquals(before,
"picture_figure_note,picture_table_note,picture_table_title,picture_figure_title,tableCaption")) {
imgtz = e.previousElementSibling().text();
} else if (StringUtils.anyEquals(after, "picture_figure_note,picture_table_note,picture_table_title,picture_figure_title,tableCaption")) {
} else if (StringUtils.anyEquals(after,
"picture_figure_note,picture_table_note,picture_table_title,picture_figure_title,tableCaption")) {
imgtz = e.nextElementSibling().text();
}
imgtzMap.put(imgsrc, imgtz);
......@@ -487,10 +495,12 @@ public class EpubResolve {
// 1.xxx
// 2.xxx
// 二.xxxx
List<Element> subchapter = elements.subList(elements.indexOf(hlabel1), hlabel2 == null ? elements.size() : elements.indexOf(hlabel2));
List<Element> subchapter = elements.subList(elements.indexOf(hlabel1),
hlabel2 == null ? elements.size() : elements.indexOf(hlabel2));
es = new Elements();
// markid
String markid = ebook.getBookId() + "-" + (hlabel1.attr("id").equals("") ? resourceId : hlabel1.attr("id"));
String markid = ebook.getBookId() + "-"
+ (hlabel1.attr("id").equals("") ? resourceId : hlabel1.attr("id"));
for (Element element : subchapter) {
es.add(element);
}
......@@ -507,7 +517,8 @@ public class EpubResolve {
// 内容相关信息,为正文时才去设置关键字,预览,简介(3)
if (!StringUtils.anyEquals(hlabel1.text(), "封面,版权页,目录")) {
content.setIntro(filterText.toString().substring(0, filterText.length() > 300 ? 200 : filterText.length()));
content.setIntro(filterText.toString().substring(0,
filterText.length() > 300 ? 200 : filterText.length()));
}
// 设置公共信息(6)
setContentCommInfo(content, ebook, es);
......@@ -522,7 +533,8 @@ public class EpubResolve {
// =============递归 遍历子章节内容============
if (spineReference.getChildren().size() > 0) {
if (spineReference.getChildren().get(0).getFragmentId().contains("_")) {
String spchild = spineReference.getChildren().get(0).getFragmentId().substring(0, spineReference.getChildren().get(0).getFragmentId().indexOf("_"));
String spchild = spineReference.getChildren().get(0).getFragmentId().substring(0,
spineReference.getChildren().get(0).getFragmentId().indexOf("_"));
if (!spineReference.getFragmentId().contains(spchild))
setContent(spineReference.getChildren(), contentSet, ebook, imgtzMap, data);
} else {
......@@ -573,20 +585,16 @@ public class EpubResolve {
// 原图片资源路径
oldImg = img.toString();
// 修改替换图片路径
if (!imgSrc.contains("/resource")) {
img.attr("src", bookPath + imgSrc);
// 新的图片资源路径
newImg = img.toString();
content.setText(content.getText().replace(oldImg, newImg));
}
}
}
return content;
}
/**
* 获取css样式文件
*
......@@ -594,24 +602,25 @@ public class EpubResolve {
* @param bookPath
* @return
*/
public FileInfo getCss(EpubUtil epubUtil,String rootPath, String bookPath) {
public FileInfo getCss(EpubUtil epubUtil, String rootPath, String bookPath) {
Resource cssRes = epubUtil.getCssResource();
FileInfo entity = new FileInfo();
if (cssRes == null) {
return entity;
}
String cssPath=cssRes.getHref().substring(0, cssRes.getHref().contains("/") ? cssRes.getHref().lastIndexOf("/") : 0);
String cssName =cssRes.getHref().substring(cssRes.getHref().lastIndexOf("/")+1);
String cssPath = cssRes.getHref().substring(0,
cssRes.getHref().contains("/") ? cssRes.getHref().lastIndexOf("/") : 0);
String cssName = cssRes.getHref().substring(cssRes.getHref().lastIndexOf("/") + 1);
// 写入文件中
InputStream inputStream = null;
File css = new File(rootPath+ bookPath +"/"+ cssPath);
File css = new File(rootPath + bookPath + "/" + cssPath);
if (!css.exists()) {
css.mkdirs();
}
try {
inputStream = cssRes.getInputStream();
MultipartFile multipartFile = new MockMultipartFile(cssName,cssName,"text/css", inputStream);
entity = this.uploadFile(multipartFile,rootPath, bookPath +"/"+ cssPath);
MultipartFile multipartFile = new MockMultipartFile(cssName, cssName, "text/css", inputStream);
entity = this.uploadFile(multipartFile, rootPath, bookPath + "/" + cssPath);
} catch (Exception e) {
e.printStackTrace();
......@@ -621,19 +630,20 @@ public class EpubResolve {
/**
* 获取图书中所有图片资源
*
* @param epubUtil
* @param bookFolderPath
* @return
*/
public List<FileInfo> getImages(EpubUtil epubUtil,String rootPath, String bookFolderPath) {
public List<FileInfo> getImages(EpubUtil epubUtil, String rootPath, String bookFolderPath) {
List<Resource> imgs = epubUtil.getImagesResources();
List<FileInfo> entityList = new ArrayList<FileInfo>();
String imagePath=imgs.get(0).getHref().substring(0, imgs.get(0).getHref().lastIndexOf("/"));
String imagePath = imgs.get(0).getHref().substring(0, imgs.get(0).getHref().lastIndexOf("/"));
// 创建图书中的图片的保存文件夹
File imageRes = null;
if (imgs.size() != 0) {
imageRes = new File(bookFolderPath +"/"+ imagePath);
imageRes = new File(bookFolderPath + "/" + imagePath);
if (!imageRes.exists()) {
imageRes.mkdirs();
}
......@@ -641,15 +651,15 @@ public class EpubResolve {
InputStream in = null;
try {
for (Resource img : imgs) {
String imgName=img.getHref().substring(img.getHref().lastIndexOf("/")+1);
String imgName = img.getHref().substring(img.getHref().lastIndexOf("/") + 1);
in = img.getInputStream();
MultipartFile multipartFile = new MockMultipartFile(imgName,imgName,"image/jpeg", in);
FileInfo entity = this.uploadFile(multipartFile,rootPath, imageRes.getPath());
MultipartFile multipartFile = new MockMultipartFile(imgName, imgName, "image/jpeg", in);
FileInfo entity = this.uploadFile(multipartFile, rootPath, imageRes.getPath());
entityList.add(entity);
}
// 多线程处理图片生成缩略图
new Thread(()->ImageUtil.createThumbnailToThread(imgs, bookFolderPath+"/")).start();
new Thread(() -> ImageUtil.createThumbnailToThread(imgs, bookFolderPath + "/")).start();
} catch (IOException e) {
e.printStackTrace();
try {
......@@ -662,7 +672,6 @@ public class EpubResolve {
return entityList;
}
public FileInfo uploadFile(MultipartFile file, String rootPath, String path) {
String contentType = file.getContentType();
// 获取文件名
......@@ -672,7 +681,7 @@ public class EpubResolve {
// 解决中文问题,liunx下中文路径,图片显示问题
String uuid = UUIDUtil.getUUID();
String filePath = rootPath+ path + "/";
String filePath = rootPath + path + "/";
File targetFile = new File(filePath);
if (!targetFile.exists()) {
targetFile.mkdirs();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论