Exemplo n.º 1
0
        private static Epub2NcxPageList ReadNavigationPageList(XElement navigationPageListNode)
        {
            Epub2NcxPageList result = new Epub2NcxPageList();

            foreach (XElement pageTargetNode in navigationPageListNode.Elements())
            {
                if (pageTargetNode.CompareNameTo("pageTarget"))
                {
                    Epub2NcxPageTarget pageTarget = ReadNavigationPageTarget(pageTargetNode);
                    result.Add(pageTarget);
                }
            }
            return(result);
        }
Exemplo n.º 2
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);
        }