예제 #1
0
        public void generateSpineFromTableOfContents()
        {
            Spine spine = new Spine(tableOfContents);

            // in case the tocResource was already found and assigned
            spine.setTocResource(this.spine.getTocResource());

            this.spine = spine;
        }
예제 #2
0
        public void generateSpineFromTableOfContents()
        {
            Spine spine = new Spine(tableOfContents);

            // in case the tocResource was already found and assigned
            spine.setTocResource(this.spine.getTocResource());

            this.spine = spine;
        }
        /// <summary>
        /// Reads the document's spine, containing all sections in reading order.
        /// </summary>
        /// <param>book</param>
        /// <param>resourcesById</param>
        /// <param name="packageDocument"></param>
        /// <param name="epubReader"></param>
        /// <param name="resources"></param>
        /// <param name="idMapping"></param>
        private static Spine readSpine(XElement packageDocument, EpubReader epubReader, Resources resources, Dictionary<String, String> idMapping)
        {
            XElement spineElement = DOMUtil.getFirstElementByTagNameNS(packageDocument, NAMESPACE_OPF, OPFTags.spine);
            if (spineElement == null)
            {
                //log.error("Element " + OPFTags.spine + " not found in package document, generating one automatically");
                return generateSpineFromResources(resources);
            }
            Spine result = new Spine();
            result.setTocResource(findTableOfContentsResource(spineElement, resources));
            var spineNodes = packageDocument.Elements(NAMESPACE_OPF + OPFTags.itemref).Elements<XElement>();
            IEnumerator spineNode = spineNodes.GetEnumerator();
            List<SpineReference> spineReferences = new List<SpineReference>();
            while (spineNode.MoveNext())
            {
                XElement spineItem = (XElement)spineNode.Current;
                String itemref = DOMUtil.getAttribute(spineItem, OPFAttributes.idref);
                if (StringUtil.isBlank(itemref))
                {
                    //log.error("itemref with missing or empty idref"); // XXX
                    continue;
                }
                String id = idMapping[itemref];
                if (id == null)
                {
                    id = itemref;
                }
                Resource resource = resources.getByIdOrHref(id);
                if (resource == null)
                {
                    //log.error("resource with id \'" + id + "\' not found");
                    continue;
                }

                SpineReference spineReference = new SpineReference(resource);
                if (OPFValues.no.Equals(DOMUtil.getAttribute(spineItem, OPFAttributes.linear)))
                {
                    spineReference.setLinear(false);
                }
                spineReferences.Add(spineReference);
            }
            result.setSpineReferences(spineReferences);
            return result;
        }
 /// <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;
 }
예제 #5
0
 /// 
 /// <param name="spine"></param>
 public void setSpine(Spine spine)
 {
     this.spine = spine;
 }
예제 #6
0
 /// 
 /// <param name="spine"></param>
 public void setSpine(Spine spine)
 {
     this.spine = spine;
 }