示例#1
0
 public IEnumerable <NavigationPoint> ProcessOrderedListRecursive(
     XElement element, NavigationOrderProcessor navigationOrderProcessor, string basePath, IEnumerable <File> files)
 {
     return(element.Elements()
            .Where(e => e.Name.Equals(XmlNamespaces.XHtml + XHtmlTocXmlNames.ListItemElementName))
            .Select(e => ProcessListItemRecursive(e, navigationOrderProcessor, basePath, files)));
 }
示例#2
0
 private IEnumerable <NavigationPoint> FilterAndSelectChildNavPoints(
     XElement element, NavigationOrderProcessor orderProcessor, string basePath, IEnumerable <File> files)
 {
     return(element.Elements()
            .Where(e => e.Name.Equals(XmlNamespaces.Ncx + NcxXmlNames.NavPointElementName))
            .Select(e => ProcessNavPoint(e, orderProcessor, basePath, files))
            .ToArray());
 }
示例#3
0
        public IEnumerable <NavigationPoint> ExtractNavigationPoints(
            XmlStructureFile xHtmlToc, IEnumerable <File> files)
        {
            var navigationOrderProcessor = NavigationOrderProcessor.Create();
            var navElement = GetRootOrderedList(xHtmlToc.Doc);

            return(ProcessOrderedListRecursive(
                       navElement, navigationOrderProcessor, EpubPathHelper.GetDirectoryName(xHtmlToc.Path), files).ToArray());
        }
示例#4
0
        public IEnumerable <NavigationPoint> ExtractNavigationPoints(XmlStructureFile ncx, IEnumerable <File> files)
        {
            var root     = ncx.Doc.Root;
            var basePath = EpubPathHelper.GetDirectoryName(ncx.Path);

            var navMap = root.Elements()
                         .Single(element => element.Name.Equals(XmlNamespaces.Ncx + NcxXmlNames.NavMapElementName));
            var orderProcessor = NavigationOrderProcessor.Create(navMap);

            return(FilterAndSelectChildNavPoints(navMap, orderProcessor, basePath, files));
        }
示例#5
0
        private NavigationPoint ProcessNavPoint(
            XElement element, NavigationOrderProcessor orderProcessor, string basePath, IEnumerable <File> files)
        {
            var title = element.Elements()
                        .Single(e => e.Name.Equals(XmlNamespaces.Ncx + NcxXmlNames.NavLabelElementName))
                        .Elements().Single(e => e.Name.Equals(XmlNamespaces.Ncx + NcxXmlNames.TextElementName))
                        .Value;

            var contentText = element.Elements()
                              .Single(e => e.Name.Equals(XmlNamespaces.Ncx + NcxXmlNames.ContentElementName))
                              .GetAttributeValueOrNull(NcxXmlNames.SrcAttributeName) !;
            var filePath  = SrcTextSplitter.GetFileName(contentText);
            var elementId = SrcTextSplitter.GetElementId(contentText);

            var fileFullPath = EpubPathHelper.ExpandPath(basePath, filePath);
            var file         = files.Single(f => f.Path.EqualsIgnoreCaseWithNull(fileFullPath));

            var order = orderProcessor.GetOrder(element);

            var children = FilterAndSelectChildNavPoints(element, orderProcessor, basePath, files);

            return(new NavigationPoint(title, file, elementId, order, children));
        }
示例#6
0
        private NavigationPoint ProcessListItemRecursive(
            XElement listItem, NavigationOrderProcessor navigationOrderProcessor, string basePath, IEnumerable <File> files)
        {
            var linkElement = listItem.Elements()
                              .Single(element => element.Name.Equals(XmlNamespaces.XHtml + XHtmlTocXmlNames.LinkElementName));

            var title     = linkElement.Value;
            var srcPath   = linkElement.GetAttributeValueOrNull(XHtmlTocXmlNames.HrefAttributeName) !;
            var filePath  = SrcTextSplitter.GetFileName(srcPath);
            var elementId = SrcTextSplitter.GetElementId(srcPath);
            var order     = navigationOrderProcessor.GetOrder(listItem);

            var fileFullPath = EpubPathHelper.ExpandPath(basePath, filePath);
            var file         = files.Single(f => f.Path.EqualsIgnoreCaseWithNull(fileFullPath));

            var childOrderedList = listItem.Elements()
                                   .Cast <XElement?>().SingleOrDefault(
                e => e !.Name.Equals(XmlNamespaces.XHtml + XHtmlTocXmlNames.OrderedListElementName));
            var children = childOrderedList != null
                ? ProcessOrderedListRecursive(childOrderedList, navigationOrderProcessor, basePath, files).ToArray()
                : Array.Empty <NavigationPoint>();

            return(new NavigationPoint(title, file, elementId, order, children));
        }