/// <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); } }
/// <summary> /// Creates a spine out of all resources in the resources. The generated spine /// consists of all XHTML pages in order of their href. /// </summary> /// <param name="resources"></param> private static Spine generateSpineFromResources(Resources resources) { Spine result = new Spine(); List<String> resourceHrefs = new List<String>(resources.getAllHrefs()); foreach (String resourceHref in resourceHrefs) { Resource resource = resources.getByHref(resourceHref); if (resource.getMediaType() == MediatypeService.NCX) { result.setTocResource(resource); } else if (resource.getMediaType() == MediatypeService.XHTML) { result.addSpineReference(new SpineReference(resource)); } } return result; }