@Override protected List<Tome> parseTomes(Document htmlDocument, Serie parent) { Date today = new Date(); List<Tome> tomes = new LinkedList<>(); Elements divChapters = htmlDocument.select("div.detail_list"); if (!divChapters.isEmpty()) { Elements spansLeft = divChapters.first().select("span.left"); if (!spansLeft.isEmpty()) { for (Element span : spansLeft) { Elements tomeNumberElements = span.select("span.mr6"); final String tomeNumberString = StringUtils.substringAfter(tomeNumberElements.first().text(), "Vol "); int tomeNumber = 0; if (tomeNumberString != null && !tomeNumberString.isEmpty()) { Integer.parseInt(tomeNumberString); } Tome foundTome = null; for (Tome tome : tomes) { if (tomeNumber == tome.getNumber()) { foundTome = tome; break; } } if (foundTome == null) { Tome tome = new Tome(); tome.setNumber(tomeNumber); tome.setName("Tome " + tomeNumber); tome.setMustBeSaved(true); tome.setValidityDate(today); tome.setSerie(parent); tomes.add(tome); foundTome = tome; } Element link = span.select("a").first(); Chapter chapter = new Chapter(); chapter.setMustBeSaved(true); chapter.setUrl(link.attr("href")); String chapterNumberToParse = link.text(); String tempNumber = StringUtils.substringAfterLast(chapterNumberToParse, " "); chapter.setNumber(Float.parseFloat(tempNumber)); chapter.setName(span.text()); chapter.setTome(foundTome); foundTome.addChapter(chapter); } } } parent.setValidityDate(today); return tomes; }
public static Chapter decodeToChapter(Map m) throws GeneralException { String cid = TypeEncoder.getString(MessageFieldNames.chapterid, m); String cname = TypeEncoder.getString(MessageFieldNames.name, m); String ctext = TypeEncoder.getString(MessageFieldNames.text, m, false); String cver = TypeEncoder.getString(MessageFieldNames.version, m); String cm = TypeEncoder.getString(MessageFieldNames.markup, m, false); Chapter c = new Chapter(); c.setId(cid); c.setName(cname); c.setText(ctext); c.setMarkup(cm); c.setVersion(cver); return c; }
public static Note decodeToNote(Map m) throws GeneralException { String chid = TypeEncoder.getString(MessageFieldNames.chapterid, m); String chver = TypeEncoder.getString(MessageFieldNames.chapterversion, m); String cname = TypeEncoder.getString(MessageFieldNames.chaptername, m, false); // Create a fake chapter to hold the id/version. Chapter c = new Chapter(); c.setId(chid); c.setVersion(chver); c.setName(cname); String cid = TypeEncoder.getString(MessageFieldNames.commentid, m); String text = TypeEncoder.getString(MessageFieldNames.text, m); Note n = new Note(); n.setChapter(c); n.setDescription(text); // Need to also setup the summary. n.setSummaryFromDescription(); n.setId(cid); n.setDealtWith(TypeEncoder.getDate(MessageFieldNames.date, m, false)); n.setPosition(TypeEncoder.getInt(MessageFieldNames.start, m)); int end = TypeEncoder.getInt(MessageFieldNames.end, m, false); if (end > -1) { n.setEndPosition(end); } return n; }