Exemplo n.º 1
0
        private static EpubNavigationTarget ReadNavigationTarget(XElement navigationTargetNode)
        {
            var result = new EpubNavigationTarget();

            foreach (var navigationPageTargetNodeAttribute in navigationTargetNode.Attributes())
            {
                var attributeValue = navigationPageTargetNodeAttribute.Value;
                switch (navigationPageTargetNodeAttribute.Name.LocalName.ToLowerInvariant())
                {
                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 (var navigationTargetChildNode in navigationTargetNode.Elements())
            {
                switch (navigationTargetChildNode.Name.LocalName.ToLowerInvariant())
                {
                case "navlabel":
                    var navigationLabel = ReadNavigationLabel(navigationTargetChildNode);
                    result.NavigationLabels.Add(navigationLabel);
                    break;

                case "content":
                    var 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);
        }
Exemplo n.º 2
0
        private static EpubNavigationList ReadNavigationList(XElement navigationListNode)
        {
            EpubNavigationList result = new EpubNavigationList();

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

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

                case "navTarget":
                    EpubNavigationTarget 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);
        }