コード例 #1
0
ファイル: Epub2NcxReader.cs プロジェクト: recr0ns/EpubReader
        private static Epub2NcxNavigationPoint ReadNavigationPoint(XElement navigationPointNode)
        {
            Epub2NcxNavigationPoint result = new Epub2NcxNavigationPoint();

            foreach (XAttribute navigationPointNodeAttribute in navigationPointNode.Attributes())
            {
                string attributeValue = navigationPointNodeAttribute.Value;
                switch (navigationPointNodeAttribute.GetLowerCaseLocalName())
                {
                case "id":
                    result.Id = attributeValue;
                    break;

                case "class":
                    result.Class = attributeValue;
                    break;

                case "playorder":
                    result.PlayOrder = attributeValue;
                    break;
                }
            }
            if (String.IsNullOrWhiteSpace(result.Id))
            {
                throw new Exception("Incorrect EPUB navigation point: point ID is missing.");
            }
            result.NavigationLabels      = new List <Epub2NcxNavigationLabel>();
            result.ChildNavigationPoints = new List <Epub2NcxNavigationPoint>();
            foreach (XElement navigationPointChildNode in navigationPointNode.Elements())
            {
                switch (navigationPointChildNode.GetLowerCaseLocalName())
                {
                case "navlabel":
                    Epub2NcxNavigationLabel navigationLabel = ReadNavigationLabel(navigationPointChildNode);
                    result.NavigationLabels.Add(navigationLabel);
                    break;

                case "content":
                    Epub2NcxContent content = ReadNavigationContent(navigationPointChildNode);
                    result.Content = content;
                    break;

                case "navpoint":
                    Epub2NcxNavigationPoint childNavigationPoint = ReadNavigationPoint(navigationPointChildNode);
                    result.ChildNavigationPoints.Add(childNavigationPoint);
                    break;
                }
            }
            if (!result.NavigationLabels.Any())
            {
                throw new Exception($"EPUB parsing error: navigation point {result.Id} should contain at least one navigation label.");
            }
            if (result.Content == null)
            {
                throw new Exception($"EPUB parsing error: navigation point {result.Id} should contain content.");
            }
            return(result);
        }
コード例 #2
0
ファイル: Epub2NcxReader.cs プロジェクト: recr0ns/EpubReader
        private static Epub2NcxNavigationTarget ReadNavigationTarget(XElement navigationTargetNode)
        {
            Epub2NcxNavigationTarget result = new Epub2NcxNavigationTarget();

            foreach (XAttribute navigationPageTargetNodeAttribute in navigationTargetNode.Attributes())
            {
                string attributeValue = navigationPageTargetNodeAttribute.Value;
                switch (navigationPageTargetNodeAttribute.GetLowerCaseLocalName())
                {
                case "id":
                    result.Id = attributeValue;
                    break;

                case "value":
                    result.Value = attributeValue;
                    break;

                case "class":
                    result.Class = attributeValue;
                    break;

                case "playorder":
                    result.PlayOrder = attributeValue;
                    break;
                }
            }
            if (String.IsNullOrWhiteSpace(result.Id))
            {
                throw new Exception("Incorrect EPUB navigation target: navigation target ID is missing.");
            }
            foreach (XElement navigationTargetChildNode in navigationTargetNode.Elements())
            {
                switch (navigationTargetChildNode.GetLowerCaseLocalName())
                {
                case "navlabel":
                    Epub2NcxNavigationLabel navigationLabel = ReadNavigationLabel(navigationTargetChildNode);
                    result.NavigationLabels.Add(navigationLabel);
                    break;

                case "content":
                    Epub2NcxContent content = ReadNavigationContent(navigationTargetChildNode);
                    result.Content = content;
                    break;
                }
            }
            if (!result.NavigationLabels.Any())
            {
                throw new Exception("Incorrect EPUB navigation target: at least one navLabel element is required.");
            }
            return(result);
        }
コード例 #3
0
ファイル: Epub2NcxReader.cs プロジェクト: recr0ns/EpubReader
        private static Epub2NcxContent ReadNavigationContent(XElement navigationContentNode)
        {
            Epub2NcxContent result = new Epub2NcxContent();

            foreach (XAttribute navigationContentNodeAttribute in navigationContentNode.Attributes())
            {
                string attributeValue = navigationContentNodeAttribute.Value;
                switch (navigationContentNodeAttribute.GetLowerCaseLocalName())
                {
                case "id":
                    result.Id = attributeValue;
                    break;

                case "src":
                    result.Source = attributeValue;
                    break;
                }
            }
            if (String.IsNullOrWhiteSpace(result.Source))
            {
                throw new Exception("Incorrect EPUB navigation content: content source is missing.");
            }
            return(result);
        }
コード例 #4
0
ファイル: Epub2NcxReader.cs プロジェクト: recr0ns/EpubReader
        private static Epub2NcxPageTarget ReadNavigationPageTarget(XElement navigationPageTargetNode)
        {
            Epub2NcxPageTarget result = new Epub2NcxPageTarget();

            foreach (XAttribute navigationPageTargetNodeAttribute in navigationPageTargetNode.Attributes())
            {
                string attributeValue = navigationPageTargetNodeAttribute.Value;
                switch (navigationPageTargetNodeAttribute.GetLowerCaseLocalName())
                {
                case "id":
                    result.Id = attributeValue;
                    break;

                case "value":
                    result.Value = attributeValue;
                    break;

                case "type":
                    Epub2NcxPageTargetType type;
                    if (Enum.TryParse(attributeValue, true, out type))
                    {
                        result.Type = type;
                    }
                    else
                    {
                        result.Type = Epub2NcxPageTargetType.UNKNOWN;
                    }
                    break;

                case "class":
                    result.Class = attributeValue;
                    break;

                case "playorder":
                    result.PlayOrder = attributeValue;
                    break;
                }
            }
            if (result.Type == default)
            {
                throw new Exception("Incorrect EPUB navigation page target: page target type is missing.");
            }
            result.NavigationLabels = new List <Epub2NcxNavigationLabel>();
            foreach (XElement navigationPageTargetChildNode in navigationPageTargetNode.Elements())
            {
                switch (navigationPageTargetChildNode.GetLowerCaseLocalName())
                {
                case "navlabel":
                    Epub2NcxNavigationLabel navigationLabel = ReadNavigationLabel(navigationPageTargetChildNode);
                    result.NavigationLabels.Add(navigationLabel);
                    break;

                case "content":
                    Epub2NcxContent content = ReadNavigationContent(navigationPageTargetChildNode);
                    result.Content = content;
                    break;
                }
            }
            if (!result.NavigationLabels.Any())
            {
                throw new Exception("Incorrect EPUB navigation page target: at least one navLabel element is required.");
            }
            return(result);
        }