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

--no commit message

上级 45428d05
......@@ -341,115 +341,7 @@ public class EpubResolve {
return alltitle;
}
/**
*
* @Description: TODO
* @param @param listReferences
* @param @param contentSet
* @param @param book
* @param @param imgtzMap
* @param @param data
* @param @return
* @return Object[]
* @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) { // 遍历章节的内容 Map<String, TOCReference>
* titles1 = null; Map<String, TOCReference> ids1 = null; for (TOCReference
* spineReference : listReferences) { titles1 = new LinkedMap(); ids1 = new
* LinkedMap(); // 获取所有id Map<String, TOCReference> tmapid =
* getAllId(spineReference, ids1, 0);
*
* // 顶级目录 用resourceId 标识 String resourceId = ""; if
* (spineReference.getFragmentId() != null &&
* !spineReference.getFragmentId().equals("")) { resourceId =
* spineReference.getFragmentId(); } else { resourceId =
* spineReference.getResourceId(); } // jsoup解析,生成dom对象 Document doc =
* getDocument(spineReference); Elements elements =
* doc.select("h1,h2,h3,h4,h5,h6,ul,hr,p,div"); //
* ###################去重复的标题########################### Elements titles = new
* Elements(); Set<String> keys = tmapid.keySet(); for (String key : keys) {
* Element str; try { str = doc.getElementById(key); if (str != null)
* titles.add(str); } catch (Exception e) { continue; }
*
* } // 图注: // Elements select = elements.select("p,img"); for (Element elmt :
* elements) { if (elmt.toString().contains("<img")) { for (Element e :
* elmt.children()) { if (e.toString().contains("<img")) { String imgsrc =
* e.attr("src"); if (imgsrc.contains("../")) { imgsrc = imgsrc.replace("../",
* ""); e.attr("src", imgsrc); } // 将带上一层目录的取消 imgsrc =
* imgsrc.substring(imgsrc.lastIndexOf("/") + 1); String imgtz = "";
*
* String before = ""; String after = ""; if (e.previousElementSibling() !=
* null) { before = e.previousElementSibling().attr("class"); }
*
* 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"
* )) { imgtz = e.previousElementSibling().text(); } 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); }
* } } } // 不包含,h标签,直接存储 boolean anyEquals = false; if (titles.size() > 0) {
* anyEquals = StringUtils.anyEquals(titles.get(0).text().replaceAll("[  ]",
* ""), "序,总序,序言,前言,摘要"); } if (!titles.toString().contains("<h") || anyEquals)
* { // 不包含h标签的直接整体存入 ArticleLibrary content = new ArticleLibrary(); // 当前章节标题
* String title = spineReference.getTitle();//
* elements.get(0).toString().contains("<h")?elements.get(0).text():
* content.setName(title);// 标题
*
* // markid content.setMarkid(ebook.getId() + "-" + resourceId); int num = 1;
* content.setText(elements.toString()); // 设置公共信息 setContentCommInfo(content,
* ebook, elements); // content.setAuthor(ebook.getAuthor()); //
* **********将章节内容存入Set集合********* contentSet.add(content); } else if
* (!anyEquals) { Elements es = null; for (int i = 0, tlen = titles.size(); i <
* tlen; i++) {
*
*//**
* 如果属于章节,则保存。 否则直接跳过
*//*
* String str =titles.get(i).text().replaceAll(" ", ""); if
* (chapterList.contains(str)) { // h标签 Element hlabel1 = titles.get(i); Element
* hlabel2 = null; if (i != titles.size() - 1) {
*
* for (int j = i + 1; j < titles.size(); j++) { if
* (chapterList.contains(titles.get(j).text().replaceAll(" ", ""))) { hlabel2 =
* titles.get(j); i = j - 1; break; } } }
*
* // 截取整个大章节中的每个小章节 // 一.xxxx // 1.xxx // 2.xxx // 二.xxxx List<Element>
* subchapter = elements.subList(elements.indexOf(hlabel1), hlabel2 == null ?
* elements.size() : elements.indexOf(hlabel2)); es = new Elements(); // markid
* String markid = ebook.getId() + "-" + (hlabel1.attr("id").equals("") ?
* resourceId : hlabel1.attr("id")); for (Element element : subchapter) { if
* (!element.toString().contains("<h")) { es.add(element); }
*
* }
*
* ArticleLibrary content = new ArticleLibrary(); // 内容信息(6)
* content.setName(hlabel1.text());
*
* // 章节内容 content.setText(es.toString());// 内容 String filterText = es.text();
*
* content.setMarkid(markid);
*
* // 内容相关信息,为正文时才去设置关键字,预览,简介(3) if (!StringUtils.anyEquals(hlabel1.text(),
* "封面,版权页,目录")) { content.setSynopsis(filterText.toString().substring(0,
* filterText.length() > 300 ? 200 : filterText.length())); } // 设置公共信息(6)
* setContentCommInfo(content, ebook, es);
*
* // *********将章节内容存入Set集合**************** //
* content.setAuthor(ebook.getAuthor()); contentSet.add(content); }
*
* } }
*
* } // for循环结束
*
* data[0] = contentSet; data[1] = imgtzMap; return data;
*
* }
*/
/**
* 规则改版解析章节
......@@ -711,13 +603,7 @@ public class EpubResolve {
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);
if (!imageRes.exists()) {
imageRes.mkdirs();
}
// 将图片保存到磁盘中
InputStream in = null;
try {
......@@ -725,7 +611,7 @@ public class EpubResolve {
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());
FileInfo entity = this.uploadFile(multipartFile, rootPath, bookFolderPath + "/" + imagePath);
entityList.add(entity);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论