/// <summary> /// Reads the book's guide. Here some more attempts are made at finding the cover /// page. /// </summary> /// <param name="packageDocument"></param> /// <param name="epubReader"></param> /// <param name="book"></param> /// <param name="resources">resources</param> private static void readGuide(XElement packageDocument, EpubReader epubReader, Book book, Resources resources) { XElement guideElement = DOMUtil.getFirstElementByTagNameNS(packageDocument, NAMESPACE_OPF, OPFTags.guide); if (guideElement == null) { return; } Guide guide = book.getGuide(); var guideReferences = packageDocument.Elements(NAMESPACE_OPF + OPFTags.reference).Elements<XElement>(); foreach (XElement referenceElement in (from e in guideReferences where e.Value.Trim() != string.Empty select e)) { String resourceHref = DOMUtil.getAttribute(referenceElement, OPFAttributes.href); if (StringUtil.isBlank(resourceHref)) { continue; } Resource resource = resources.getByHref(StringUtil.substringBefore(resourceHref, Constants.FRAGMENT_SEPARATOR_CHAR)); if (resource == null) { //log.error("Guide is referencing resource with href " + resourceHref + " which could not be found"); continue; } String type = DOMUtil.getAttribute(referenceElement, OPFAttributes.type); if (StringUtil.isBlank(type)) { //log.error("Guide is referencing resource with href " + resourceHref + " which is missing the 'type' attribute"); continue; } String title = DOMUtil.getAttribute(referenceElement, OPFAttributes.title); if (GuideReference.COVER.Equals(type)) { continue; // cover is handled elsewhere } GuideReference reference = new GuideReference(resource, type, title, StringUtil.substringAfter(resourceHref, Constants.FRAGMENT_SEPARATOR_CHAR)); guide.addReference(reference); } }
/// /// <param name="reference"></param> public ResourceReference addReference(GuideReference reference) { references.Add(reference); uncheckCoverPage(); return reference; }
/// /// <param name="guideReference"></param> public int setCoverReference(GuideReference guideReference) { if (coverPageIndex >= 0) { references[coverPageIndex] = guideReference; } else { references.Add(guideReference); coverPageIndex = 0; } return coverPageIndex; }
/// /// <param name="coverPage"></param> public void setCoverPage(Resource coverPage) { GuideReference coverpageGuideReference = new GuideReference(coverPage, GuideReference.COVER, DEFAULT_COVER_TITLE); setCoverReference(coverpageGuideReference); }