コード例 #1
0
        private static EpubManifest ReadManifest(XmlNode manifestNode)
        {
            EpubManifest result = new EpubManifest();

            foreach (XmlNode manifestItemNode in manifestNode.ChildNodes)
            {
                if (String.Compare(manifestItemNode.LocalName, "item", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    EpubManifestItem manifestItem = new EpubManifestItem();
                    foreach (XmlAttribute manifestItemNodeAttribute in manifestItemNode.Attributes)
                    {
                        string attributeValue = manifestItemNodeAttribute.Value;
                        switch (manifestItemNodeAttribute.Name.ToLowerInvariant())
                        {
                        case "id":
                            manifestItem.Id = attributeValue;
                            break;

                        case "href":
                            manifestItem.Href = attributeValue;
                            break;

                        case "media-type":
                            manifestItem.MediaType = attributeValue;
                            break;

                        case "required-namespace":
                            manifestItem.RequiredNamespace = attributeValue;
                            break;

                        case "required-modules":
                            manifestItem.RequiredModules = attributeValue;
                            break;

                        case "fallback":
                            manifestItem.Fallback = attributeValue;
                            break;

                        case "fallback-style":
                            manifestItem.FallbackStyle = attributeValue;
                            break;
                        }
                    }
                    if (String.IsNullOrWhiteSpace(manifestItem.Id))
                    {
                        throw new Exception("Incorrect EPUB manifest: item ID is missing");
                    }
                    if (String.IsNullOrWhiteSpace(manifestItem.Href))
                    {
                        throw new Exception("Incorrect EPUB manifest: item href is missing");
                    }
                    if (String.IsNullOrWhiteSpace(manifestItem.MediaType))
                    {
                        throw new Exception("Incorrect EPUB manifest: item media type is missing");
                    }
                    result.Add(manifestItem);
                }
            }
            return(result);
        }
コード例 #2
0
        private static async System.Threading.Tasks.Task<EpubManifest> ReadManifestAsync(XmlReader reader)
        {
            EpubManifest result = new EpubManifest();
            
            bool isManifestFound = await reader.ReadToFollowingAsync("manifest", "http://www.idpf.org/2007/opf");
            if (!isManifestFound)
                throw new Exception("EPUB parsing error: manifest declarations not found in the package.");

            while (await reader.ReadAsync() && !(reader.NodeType == XmlNodeType.EndElement && reader.LocalName == "manifest"))
            {
                if (!String.IsNullOrWhiteSpace(reader.LocalName))
                {
                    EpubManifestItem manifestItem = new EpubManifestItem();
                    switch (reader.LocalName.ToLowerInvariant())
                    {
                        case "item":
                            while (reader.MoveToNextAttribute())
                            {
                                switch (reader.LocalName.ToLowerInvariant())
                                {
                                    case "id":
                                        manifestItem.Id = reader.Value;
                                        break;
                                    case "href":
                                        manifestItem.Href = reader.Value;
                                        break;
                                    case "media-type":
                                        manifestItem.MediaType = reader.Value;
                                        break;
                                    case "required-namespace":
                                        manifestItem.RequiredNamespace = reader.Value;
                                        break;
                                    case "required-modules":
                                        manifestItem.RequiredModules = reader.Value;
                                        break;
                                    case "fallback":
                                        manifestItem.Fallback = reader.Value;
                                        break;
                                    case "fallback-style":
                                        manifestItem.FallbackStyle = reader.Value;
                                        break;
                                }
                            }
                            break;
                    }
                    if (String.IsNullOrWhiteSpace(manifestItem.Id))
                        throw new Exception("Incorrect EPUB manifest: item ID is missing");
                    if (String.IsNullOrWhiteSpace(manifestItem.Href))
                        throw new Exception("Incorrect EPUB manifest: item href is missing");
                    if (String.IsNullOrWhiteSpace(manifestItem.MediaType))
                        throw new Exception("Incorrect EPUB manifest: item media type is missing");
                    result.Add(manifestItem);
                }
            }
            return result;
        }
コード例 #3
0
        private static EpubManifest ReadManifest(XElement manifestNode)
        {
            EpubManifest result = new EpubManifest();

            foreach (XElement manifestItemNode in manifestNode.Elements())
            {
                if (manifestItemNode.CompareNameTo("item"))
                {
                    EpubManifestItem manifestItem = new EpubManifestItem();
                    foreach (XAttribute manifestItemNodeAttribute in manifestItemNode.Attributes())
                    {
                        string attributeValue = manifestItemNodeAttribute.Value;
                        switch (manifestItemNodeAttribute.GetLowerCaseLocalName())
                        {
                        case "id":
                            manifestItem.Id = attributeValue;
                            break;

                        case "href":
                            manifestItem.Href = Uri.UnescapeDataString(attributeValue);
                            break;

                        case "media-type":
                            manifestItem.MediaType = attributeValue;
                            break;

                        case "required-namespace":
                            manifestItem.RequiredNamespace = attributeValue;
                            break;

                        case "required-modules":
                            manifestItem.RequiredModules = attributeValue;
                            break;

                        case "fallback":
                            manifestItem.Fallback = attributeValue;
                            break;

                        case "fallback-style":
                            manifestItem.FallbackStyle = attributeValue;
                            break;

                        case "properties":
                            manifestItem.Properties = ReadManifestProperties(attributeValue);
                            break;
                        }
                    }
                    if (String.IsNullOrWhiteSpace(manifestItem.Id))
                    {
                        throw new Exception("Incorrect EPUB manifest: item ID is missing");
                    }
                    if (String.IsNullOrWhiteSpace(manifestItem.Href))
                    {
                        throw new Exception("Incorrect EPUB manifest: item href is missing");
                    }
                    if (String.IsNullOrWhiteSpace(manifestItem.MediaType))
                    {
                        throw new Exception("Incorrect EPUB manifest: item media type is missing");
                    }
                    result.Add(manifestItem);
                }
            }
            return(result);
        }
コード例 #4
0
ファイル: PackageReader.cs プロジェクト: gareiz/EpubReader
 private static EpubManifest ReadManifest(XmlNode manifestNode)
 {
     EpubManifest result = new EpubManifest();
     foreach (XmlNode manifestItemNode in manifestNode.ChildNodes)
         if (String.Compare(manifestItemNode.LocalName, "item", StringComparison.OrdinalIgnoreCase) == 0)
         {
             EpubManifestItem manifestItem = new EpubManifestItem();
             foreach (XmlAttribute manifestItemNodeAttribute in manifestItemNode.Attributes)
             {
                 string attributeValue = manifestItemNodeAttribute.Value;
                 switch (manifestItemNodeAttribute.Name.ToLowerInvariant())
                 {
                     case "id":
                         manifestItem.Id = attributeValue;
                         break;
                     case "href":
                         manifestItem.Href = attributeValue;
                         break;
                     case "media-type":
                         manifestItem.MediaType = attributeValue;
                         break;
                     case "required-namespace":
                         manifestItem.RequiredNamespace = attributeValue;
                         break;
                     case "required-modules":
                         manifestItem.RequiredModules = attributeValue;
                         break;
                     case "fallback":
                         manifestItem.Fallback = attributeValue;
                         break;
                     case "fallback-style":
                         manifestItem.FallbackStyle = attributeValue;
                         break;
                 }
             }
             if (String.IsNullOrWhiteSpace(manifestItem.Id))
                 throw new Exception("Incorrect EPUB manifest: item ID is missing");
             if (String.IsNullOrWhiteSpace(manifestItem.Href))
                 throw new Exception("Incorrect EPUB manifest: item href is missing");
             if (String.IsNullOrWhiteSpace(manifestItem.MediaType))
                 throw new Exception("Incorrect EPUB manifest: item media type is missing");
             result.Add(manifestItem);
         }
     return result;
 }
コード例 #5
0
        private static async System.Threading.Tasks.Task <EpubManifest> ReadManifestAsync(XmlReader reader)
        {
            EpubManifest result = new EpubManifest();

            bool isManifestFound = await reader.ReadToFollowingAsync("manifest", "http://www.idpf.org/2007/opf");

            if (!isManifestFound)
            {
                throw new Exception("EPUB parsing error: manifest declarations not found in the package.");
            }

            while (await reader.ReadAsync() && !(reader.NodeType == XmlNodeType.EndElement && reader.LocalName == "manifest"))
            {
                if (!String.IsNullOrWhiteSpace(reader.LocalName))
                {
                    EpubManifestItem manifestItem = new EpubManifestItem();
                    switch (reader.LocalName.ToLowerInvariant())
                    {
                    case "item":
                        while (reader.MoveToNextAttribute())
                        {
                            switch (reader.LocalName.ToLowerInvariant())
                            {
                            case "id":
                                manifestItem.Id = reader.Value;
                                break;

                            case "href":
                                manifestItem.Href = reader.Value;
                                break;

                            case "media-type":
                                manifestItem.MediaType = reader.Value;
                                break;

                            case "required-namespace":
                                manifestItem.RequiredNamespace = reader.Value;
                                break;

                            case "required-modules":
                                manifestItem.RequiredModules = reader.Value;
                                break;

                            case "fallback":
                                manifestItem.Fallback = reader.Value;
                                break;

                            case "fallback-style":
                                manifestItem.FallbackStyle = reader.Value;
                                break;
                            }
                        }
                        break;
                    }
                    if (String.IsNullOrWhiteSpace(manifestItem.Id))
                    {
                        throw new Exception("Incorrect EPUB manifest: item ID is missing");
                    }
                    if (String.IsNullOrWhiteSpace(manifestItem.Href))
                    {
                        throw new Exception("Incorrect EPUB manifest: item href is missing");
                    }
                    if (String.IsNullOrWhiteSpace(manifestItem.MediaType))
                    {
                        throw new Exception("Incorrect EPUB manifest: item media type is missing");
                    }
                    result.Add(manifestItem);
                }
            }
            return(result);
        }