/// <summary> /// Reads the manifest containing the resource ids, hrefs and mediatypes. /// </summary> /// <param>book</param> /// <param>resourcesByHref</param> /// <param>a Map with resources, with their id's as key.</param> /// <param name="packageDocument"></param> /// <param name="packageHref"></param> /// <param name="epubReader"></param> /// <param name="resources"></param> /// <param name="idMapping"></param> private static Resources readManifest(XElement packageDocument, String packageHref, EpubReader epubReader, Resources resources, Dictionary<String, String> idMapping) { XElement manifestElement = DOMUtil.getFirstElementByTagNameNS(packageDocument, NAMESPACE_OPF, OPFTags.manifest); Resources result = new Resources(); if (manifestElement == null) { return result; } var itemElements = packageDocument.Elements(NAMESPACE_OPF + OPFTags.item).Elements<XElement>(); foreach (XElement itemElement in (from e in itemElements where e.Value.Trim() != string.Empty select e)) { String id = DOMUtil.getAttribute(itemElement, OPFAttributes.id); String href = DOMUtil.getAttribute(itemElement, OPFAttributes.href); try { href = System.Web.HttpUtility.UrlDecode(href, System.Text.Encoding.GetEncoding(Constants.ENCODING)); } catch (Exception e) { //log.error(e.getMessage()); } String mediaTypeName = DOMUtil.getAttribute(itemElement, OPFAttributes.media_type); Resource resource = resources.remove(href); if (resource == null) { //log.error("resource with href '" + href + "' not found"); continue; } resource.setId(id); MediaType mediaType = MediatypeService.getMediaTypeByName(mediaTypeName); if (mediaType != null) { resource.setMediaType(mediaType); } result.add(resource); idMapping.Add(id, resource.getId()); } return result; }
/// /// <param name="result"></param> /// <param name="resources"></param> private void handleMimeType(Book result, Resources resources) { resources.remove("mimetype"); }
/// /// <param name="packageResourceHref"></param> /// <param name="book"></param> /// <param name="resources"></param> private Resource processPackageResource(String packageResourceHref, Book book, Resources resources) { Resource packageResource = resources.remove(packageResourceHref); try { PackageDocumentReader.read(packageResource, this, book, resources); } catch (Exception e) { //log.error(e.getMessage(), e); } return packageResource; }
/// /// <param name="resources"></param> private String getPackageResourceHref(Resources resources) { String defaultResult = "OEBPS/content.opf"; String result = defaultResult; Resource containerResource = resources.remove("META-INF/container.xml"); if (containerResource == null) { return result; } try { XElement xElement = XElement.Load(containerResource.getInputStream()); XNamespace ns = (xElement.Attribute("xmlns") != null) ? xElement.Attribute("xmlns").Value : XNamespace.None; return xElement.Descendants(ns + "rootfile").FirstOrDefault((XElement p) => p.Attribute("media-type") != null && p.Attribute("media-type").Value.Equals("application/oebps-package+xml", System.StringComparison.InvariantCultureIgnoreCase)).Attribute("full-path").Value; } catch (Exception e) { //log.error(e.getMessage(), e); } if (StringUtil.isBlank(result)) { result = defaultResult; } return result; return ""; }