Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        private static Epub2NcxNavigationLabel ReadNavigationLabel(XElement navigationLabelNode)
        {
            Epub2NcxNavigationLabel result   = new Epub2NcxNavigationLabel();
            XElement navigationLabelTextNode = navigationLabelNode.Element(navigationLabelNode.Name.Namespace + "text");

            if (navigationLabelTextNode == null)
            {
                throw new Exception("Incorrect EPUB navigation label: label text element is missing.");
            }
            result.Text = navigationLabelTextNode.Value;
            return(result);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        private static Epub2NcxNavigationList ReadNavigationList(XElement navigationListNode)
        {
            Epub2NcxNavigationList result = new Epub2NcxNavigationList();

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

                case "class":
                    result.Class = attributeValue;
                    break;
                }
            }
            foreach (XElement navigationListChildNode in navigationListNode.Elements())
            {
                switch (navigationListChildNode.GetLowerCaseLocalName())
                {
                case "navlabel":
                    Epub2NcxNavigationLabel navigationLabel = ReadNavigationLabel(navigationListChildNode);
                    result.NavigationLabels.Add(navigationLabel);
                    break;

                case "navTarget":
                    Epub2NcxNavigationTarget navigationTarget = ReadNavigationTarget(navigationListChildNode);
                    result.NavigationTargets.Add(navigationTarget);
                    break;
                }
            }
            if (!result.NavigationLabels.Any())
            {
                throw new Exception("Incorrect EPUB navigation page target: at least one navLabel element is required.");
            }
            return(result);
        }
Esempio n. 5
0
        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);
        }