Exemple #1
0
 public EpubStructure(
     XmlStructureFile opf,
     XmlStructureFile container,
     IZip zip)
 {
     Opf       = opf;
     Container = container;
     Zip       = zip;
 }
        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());
        }
Exemple #3
0
        public IEnumerable <ManifestItem> ExtractManifestItems(XmlStructureFile opf)
        {
            var rootItem     = opf.Doc.Root;
            var manifestItem = rootItem
                               .Elements().Single(e => e.Name.Equals(XmlNamespaces.Opf + OpfXmlNames.ManifestElementName));

            return(manifestItem
                   .Elements().Where(e => e.Name.Equals(XmlNamespaces.Opf + OpfXmlNames.ItemElementName))
                   .Select(CreateFromXElement));
        }
Exemple #4
0
        public Task <XmlStructureFile> LoadNcx(
            IEnumerable <ManifestItem> manifestItems, string relativeFilePathsAnchor, IEnumerable <File> files)
        {
            var ncxRelativePath = manifestItems
                                  .Single(item => item.ContentType == ContentType.Ncx).Href !;
            var ncxPath = EpubPathHelper.ExpandPath(
                EpubPathHelper.GetDirectoryName(relativeFilePathsAnchor), ncxRelativePath);

            return(XmlStructureFile.LoadFromBytesAsync(
                       ncxPath, files.Single(f => f.Path.EqualsIgnoreCaseWithNull(ncxPath)).Content));
        }
Exemple #5
0
        public Task <XmlStructureFile> LoadXHtmlToc(
            IEnumerable <ManifestItem> manifestItems, string relativeFilePathsAnchor, IEnumerable <File> files)
        {
            var xHtmlTocRelativePath = manifestItems.Single(
                i => OpfXmlNames.NavPropertiesAttributeValue.EqualsIgnoreCaseWithNull(i.Properties)).Href !;
            var xHtmlTocPath = EpubPathHelper.ExpandPath(
                EpubPathHelper.GetDirectoryName(relativeFilePathsAnchor), xHtmlTocRelativePath);

            return(XmlStructureFile.LoadFromBytesAsync(
                       xHtmlTocPath, files.Single(f => f.Path.EqualsIgnoreCaseWithNull(xHtmlTocPath)).Content));
        }
        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));
        }
Exemple #7
0
        public string ExtractOpfPath(XmlStructureFile container)
        {
            var rootElement = container.Doc.Root;

            var rootFiles = rootElement.Elements()
                            .Single(element => element.Name.LocalName.EqualsIgnoreCaseWithNull(ContainerXmlNames.RootFilesElementName));

            var rootFile = rootFiles
                           .Elements()
                           .Where(element => element.Name.LocalName.EqualsIgnoreCaseWithNull(ContainerXmlNames.RootFileElementName))
                           .Single(e => ContainerXmlNames.OpfMediaType
                                   .EqualsIgnoreCaseWithNull(e.GetAttributeValueOrNull(ContainerXmlNames.MediaTypeAttributeName)))
            ;

            return(rootFile.GetAttributeValueOrNull(ContainerXmlNames.FullPathAttributeName) !);
        }
Exemple #8
0
        public MetaData ExtractMeta(XmlStructureFile opf)
        {
            var root     = opf.Doc.Root;
            var metaData = root.Elements().Single(
                element => element.Name.Equals(XmlNamespaces.Opf + OpfXmlNames.MetaDataElementName));

            return(new MetaData(
                       GetPropertyValueOrNull(metaData, OpfXmlNames.IdentifierElementName),
                       GetPropertyValueOrNull(metaData, OpfXmlNames.TitleElementName),
                       GetPropertyValueOrNull(metaData, OpfXmlNames.LanguageElementName),
                       GetPropertyValueOrNull(metaData, OpfXmlNames.PublisherElementName),
                       GetPropertyValueOrNull(metaData, OpfXmlNames.DescriptionElementName),
                       GetPropertyValueOrNull(metaData, OpfXmlNames.DateElementName),
                       GetPropertyValueOrNull(metaData, OpfXmlNames.CreatorElementName),
                       GetPropertyValueOrNull(metaData, OpfXmlNames.RightsElementName)));
        }
Exemple #9
0
        private Task <XmlStructureFile> GetOpfAsync(IZip zip, XmlStructureFile container)
        {
            var opfXmlPath = opfPathExtractor.ExtractOpfPath(container);

            return(XmlStructureFile.LoadFromZipAsync(opfXmlPath, zip));
        }
Exemple #10
0
 private Task <XmlStructureFile> GetContainerAsync(IZip zip)
 {
     return(XmlStructureFile.LoadFromZipAsync(containerXmlPath, zip));
 }
Exemple #11
0
 public Task <File[]> ExtractFiles(
     XmlStructureFile opf, IEnumerable <ManifestItem> manifestItems, IZip zip)
 {
     return(Task.WhenAll(manifestItems.Select(
                             item => CreateFileFromManifestItem(item, EpubPathHelper.GetDirectoryName(opf.Path), zip))));
 }