コード例 #1
0
ファイル: CoverPage.cs プロジェクト: rajeshwarn/fb2converters
        internal void Load(XElement xCoverpage)
        {
            if (xCoverpage == null)
            {
                throw new ArgumentNullException("xCoverpage");
            }

            if (xCoverpage.Name.LocalName != GetElementName())
            {
                throw new ArgumentException("Element of wrong type passed", "xCoverpage");
            }

            coverimages.Clear();
            IEnumerable<XElement> xImages = xCoverpage.Elements(fileNameSpace +InlineImageItem.Fb2InlineImageElementName);
            foreach (var xImage in xImages)
            {
                InlineImageItem image = new InlineImageItem();
                try
                {
                    image.Load(xImage);
                    coverimages.Add(image);
                }
                catch (Exception)
                {
                }

            }
        }
コード例 #2
0
ファイル: InternalLinkItem.cs プロジェクト: wcoder/FB2Library
        internal void Load(XElement xLink)
        {
            if (xLink == null)
            {
                throw new ArgumentNullException(nameof(xLink));
            }
            if (xLink.Name.LocalName != Fb2InternalLinkElementName)
            {
                throw new ArgumentException("Element of wrong type passed", nameof(xLink));
            }

            if (xLink.HasElements)
            {
                IEnumerable <XNode> childElements = xLink.Nodes();
                foreach (var element in childElements)
                {
                    if ((element.NodeType == XmlNodeType.Element) && !IsSimpleText(element))
                    {
                        XElement xElement = (XElement)element;
                        if (xElement.Name.LocalName == InlineImageItem.Fb2InlineImageElementName)
                        {
                            InlineImageItem image = new InlineImageItem();
                            try
                            {
                                image.Load(xElement);
                                _linkData.Add(image);
                            }
                            catch (Exception)
                            {
                                // ignored
                            }
                        }
                        else if (xElement.Name.LocalName == StyleItem.StyleItemName)
                        {
                            StyleItem styleItem = new StyleItem();
                            try
                            {
                                styleItem.Load(xElement);
                                _linkData.Add(styleItem);
                            }
                            catch (Exception)
                            {
                                // ignored
                            }
                        }
                    }
                    else
                    {
                        SimpleText text = new SimpleText();
                        try
                        {
                            text.Load(element);
                            _linkData.Add(text);
                        }
                        catch (Exception)
                        {
                            // ignored
                        }
                    }
                }
            }
            else if (!string.IsNullOrEmpty(xLink.Value))
            {
                SimpleText text = new SimpleText();
                text.Load(xLink);
                _linkData.Add(text);
            }

            XAttribute xTypeAttr = xLink.Attribute("type");

            if (xTypeAttr != null && xTypeAttr.Value != null)
            {
                Type = xTypeAttr.Value;
            }

            XAttribute xHRefAttr = xLink.Attribute(lNamespace + "href");

            if (xHRefAttr != null && xHRefAttr.Value != null)
            {
                HRef = xHRefAttr.Value;
            }
        }
コード例 #3
0
 public void Load(XNode xText)
 {
     subtext.Clear();
     if (xText == null)
     {
         throw new ArgumentNullException("xText");
     }
     switch (xText.NodeType)
     {
         case XmlNodeType.Text:
             XText textNode = (XText) xText;
             if (!string.IsNullOrEmpty(textNode.Value))
             {
                 Text = textNode.Value;
                 style = TextStyles.Normal;
             }
             break;
         case XmlNodeType.Element:
             XElement xTextElement = (XElement)xText;
             if (xTextElement.HasElements)
             {
                 Text = string.Empty;
                 style = GetStyle(xTextElement.Name.LocalName);
                 IEnumerable<XNode> childElements = xTextElement.Nodes();
                 foreach (var node in childElements)
                 {
                     if (node.NodeType == XmlNodeType.Element)
                     {
                         XElement element = (XElement) node;
                         switch (element.Name.LocalName)
                         {
                             case InternalLinkItem.Fb2InternalLinkElementName:
                                 InternalLinkItem link = new InternalLinkItem();
                                 try
                                 {
                                     link.Load(element);
                                     subtext.Add(link);
                                 }
                                 catch (Exception)
                                 {
                                     continue;
                                 }
                                 break;
                             case InlineImageItem.Fb2InlineImageElementName:
                                 InlineImageItem image = new InlineImageItem();
                                 try
                                 {
                                     image.Load(element);
                                     subtext.Add(image);
                                 }
                                 catch (Exception)
                                 {
                                     continue;
                                 }
                                 break;
                             default:
                                 SimpleText text = new SimpleText();
                                 try
                                 {
                                     text.Load(element);
                                     subtext.Add(text);
                                 }
                                 catch (Exception)
                                 {
                                     continue;
                                 }
                                 break;
                         }
                     }
                     else
                     {
                         SimpleText text = new SimpleText();
                         try
                         {
                             text.Load(node);
                             subtext.Add(text);
                         }
                         catch (Exception)
                         {
                             continue;
                         }
                     }
                 }
             }
             else
             {
                 style = GetStyle(xTextElement.Name.LocalName);
                 Text = xTextElement.Value;
                 //switch (xTextElement.Name.LocalName)
                 //{
                 //    case "strong":
                 //        Text = xTextElement.Value;
                 //        break;
                 //    case "emphasis":
                 //        Text = xTextElement.Value;
                 //        break;
                 //    case "code":
                 //        Text = xTextElement.Value;
                 //        break;
                 //    case "sub":
                 //        Text = xTextElement.Value;
                 //        break;
                 //    case "sup":
                 //        Text = xTextElement.Value;
                 //        break;
                 //    case "strikethrough":
                 //        Text = xTextElement.Value;
                 //        break;
                 //    default:
                 //        Text = xTextElement.Value;
                 //        break;
                 //}
             }
             break;
     }
 }
コード例 #4
0
ファイル: StyleItem.cs プロジェクト: wcoder/FB2Library
        /// <summary>
        /// Load element data from the node
        /// </summary>
        /// <param name="xStyle"></param>
        public void Load(XElement xStyle)
        {
            if (xStyle == null)
            {
                throw new ArgumentNullException("style");
            }
            if (xStyle.Name.LocalName != StyleItemName)
            {
                throw new ArgumentException(string.Format("The element is of type {0} while StyleItem accepts only {1} types", xStyle.Name.LocalName, StyleItemName));
            }

            Lang = null;
            XAttribute xLang = xStyle.Attribute(XNamespace.Xml + "lang");

            if (xLang != null)
            {
                Lang = xLang.Value;
            }

            Name = string.Empty;
            XAttribute xName = xStyle.Attribute("name");

            if (xName != null && xName.Value != null)
            {
                Name = xName.Value;
            }

            if (xStyle.HasElements)
            {
                IEnumerable <XNode> childElements = xStyle.Nodes();
                foreach (var element in childElements)
                {
                    if ((element.NodeType == XmlNodeType.Element) && !IsSimpleText(element))
                    {
                        XElement xElement = (XElement)element;
                        if (xElement.Name.LocalName == InlineImageItem.Fb2InlineImageElementName)
                        {
                            InlineImageItem image = new InlineImageItem();
                            try
                            {
                                image.Load(xElement);
                                StyleData.Add(image);
                            }
                            catch (Exception)
                            {
                            }
                        }
                        else if (xElement.Name.LocalName == InternalLinkItem.Fb2InternalLinkElementName)
                        {
                            InternalLinkItem linkItem = new InternalLinkItem();
                            try
                            {
                                linkItem.Load(xElement);
                                StyleData.Add(linkItem);
                            }
                            catch (Exception)
                            {
                            }
                        }
                        else if (xElement.Name.LocalName == StyleItemName)
                        {
                            StyleItem styleItem = new StyleItem();
                            try
                            {
                                styleItem.Load(xElement);
                                StyleData.Add(styleItem);
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                    else
                    {
                        SimpleText text = new SimpleText();
                        try
                        {
                            text.Load(element);
                            StyleData.Add(text);
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
            }
            else if (!string.IsNullOrEmpty(xStyle.Value))
            {
                SimpleText text = new SimpleText();
                text.Load(xStyle);
                StyleData.Add(text);
            }
        }
コード例 #5
0
ファイル: SimpleText.cs プロジェクト: padarits/fb2librarynet
        public void Load(XNode xText)
        {
            subtext.Clear();
            if (xText == null)
            {
                throw new ArgumentNullException("xText");
            }
            switch (xText.NodeType)
            {
            case XmlNodeType.Text:
                XText textNode = (XText)xText;
                if (!string.IsNullOrEmpty(textNode.Value))
                {
                    Text  = textNode.Value;
                    style = TextStyles.Normal;
                }
                break;

            case XmlNodeType.Element:
                XElement xTextElement = (XElement)xText;
                if (xTextElement.HasElements)
                {
                    Text  = string.Empty;
                    style = GetStyle(xTextElement.Name.LocalName);
                    IEnumerable <XNode> childElements = xTextElement.Nodes();
                    foreach (var node in childElements)
                    {
                        if (node.NodeType == XmlNodeType.Element)
                        {
                            XElement element = (XElement)node;
                            switch (element.Name.LocalName)
                            {
                            case InternalLinkItem.Fb2InternalLinkElementName:
                                InternalLinkItem link = new InternalLinkItem();
                                try
                                {
                                    link.Load(element);
                                    subtext.Add(link);
                                }
                                catch (Exception)
                                {
                                    continue;
                                }
                                break;

                            case InlineImageItem.Fb2InlineImageElementName:
                                InlineImageItem image = new InlineImageItem();
                                try
                                {
                                    image.Load(element);
                                    subtext.Add(image);
                                }
                                catch (Exception)
                                {
                                    continue;
                                }
                                break;

                            default:
                                SimpleText text = new SimpleText();
                                try
                                {
                                    text.Load(element);
                                    subtext.Add(text);
                                }
                                catch (Exception)
                                {
                                    continue;
                                }
                                break;
                            }
                        }
                        else
                        {
                            SimpleText text = new SimpleText();
                            try
                            {
                                text.Load(node);
                                subtext.Add(text);
                            }
                            catch (Exception)
                            {
                                continue;
                            }
                        }
                    }
                }
                else
                {
                    style = GetStyle(xTextElement.Name.LocalName);
                    Text  = xTextElement.Value;
                    //switch (xTextElement.Name.LocalName)
                    //{
                    //    case "strong":
                    //        Text = xTextElement.Value;
                    //        break;
                    //    case "emphasis":
                    //        Text = xTextElement.Value;
                    //        break;
                    //    case "code":
                    //        Text = xTextElement.Value;
                    //        break;
                    //    case "sub":
                    //        Text = xTextElement.Value;
                    //        break;
                    //    case "sup":
                    //        Text = xTextElement.Value;
                    //        break;
                    //    case "strikethrough":
                    //        Text = xTextElement.Value;
                    //        break;
                    //    default:
                    //        Text = xTextElement.Value;
                    //        break;
                    //}
                }
                break;
            }
        }
コード例 #6
0
ファイル: ParagraphItem.cs プロジェクト: wcoder/FB2Library
        protected void LoadData(XElement xParagraph)
        {
            if (xParagraph.HasElements)
            {
                IEnumerable <XNode> childElements = xParagraph.Nodes();
                foreach (var element in childElements)
                {
                    if ((element.NodeType == XmlNodeType.Element) && !IsSimpleText(element))
                    {
                        XElement xElement = (XElement)element;
                        if (xElement.Name.LocalName == InlineImageItem.Fb2InlineImageElementName)
                        {
                            InlineImageItem image = new InlineImageItem();
                            try
                            {
                                image.Load(xElement);
                                paragraphData.Add(image);
                            }
                            catch (Exception)
                            {
                            }
                        }
                        else if (xElement.Name.LocalName == InternalLinkItem.Fb2InternalLinkElementName)
                        {
                            InternalLinkItem linkItem = new InternalLinkItem();
                            try
                            {
                                linkItem.Load(xElement);
                                paragraphData.Add(linkItem);
                            }
                            catch (Exception)
                            {
                            }
                        }
                        else if (xElement.Name.LocalName == StyleItem.StyleItemName)
                        {
                            StyleItem styleItem = new StyleItem();
                            try
                            {
                                styleItem.Load(xElement);
                                paragraphData.Add(styleItem);
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }
                    else //if ( element.NodeType != XmlNodeType.Whitespace)
                    {
                        SimpleText text = new SimpleText();
                        try
                        {
                            text.Load(element);
                            paragraphData.Add(text);
                        }
                        catch (Exception)
                        {
                            continue;
                        }
                    }
                }
            }
            else if (!string.IsNullOrEmpty(xParagraph.Value))
            {
                SimpleText text = new SimpleText();
                text.Load(xParagraph);
                paragraphData.Add(text);
            }

            XAttribute xID = xParagraph.Attribute("id");

            if ((xID != null) && (xID.Value != null))
            {
                ID = xID.Value;
            }

            XAttribute xStyle = xParagraph.Attribute("style");

            if ((xStyle != null) && (xStyle.Value != null))
            {
                Style = xStyle.Value;
            }

            Lang = null;
            XAttribute xLang = xParagraph.Attribute(XNamespace.Xml + "lang");

            if ((xLang != null) && (xLang.Value != null))
            {
                Lang = xLang.Value;
            }
        }
コード例 #7
0
ファイル: ParagraphItem.cs プロジェクト: npuBug/fb2librarynet
        protected void LoadData(XElement xParagraph)
        {
            if (xParagraph.HasElements)
            {
                IEnumerable<XNode> childElements = xParagraph.Nodes();
                foreach (var element in childElements)
                {
                    if ((element.NodeType == XmlNodeType.Element) && !IsSimpleText(element))
                    {
                        XElement xElement = (XElement) element;
                        if (xElement.Name.LocalName == InlineImageItem.Fb2InlineImageElementName)
                        {
                            InlineImageItem image = new InlineImageItem();
                            try
                            {
                                image.Load(xElement);
                                paragraphData.Add(image);

                            }
                            catch (Exception)
                            {
                            }
                        }
                        else if (xElement.Name.LocalName == InternalLinkItem.Fb2InternalLinkElementName)
                        {
                            InternalLinkItem linkItem = new InternalLinkItem();
                            try
                            {
                                linkItem.Load(xElement);
                                paragraphData.Add(linkItem);

                            }
                            catch (Exception)
                            {
                            }                            
                        }
                    }
                    else //if ( element.NodeType != XmlNodeType.Whitespace)
                    {
                            SimpleText text = new SimpleText();
                            try
                            {
                                text.Load(element);
                                paragraphData.Add(text);
                            }
                            catch (Exception)
                            {
                                continue;
                            }
                    }
                }
               
            }
            else if (!string.IsNullOrEmpty(xParagraph.Value))
            {
                SimpleText text = new SimpleText();
                text.Load(xParagraph);
                paragraphData.Add(text);
            }

            XAttribute xID = xParagraph.Attribute("id");
            if ((xID != null) && (xID.Value != null))
            {
                ID = xID.Value;
            }

            XAttribute xStyle = xParagraph.Attribute("style");
            if ((xStyle != null) && (xStyle.Value != null))
            {
                Style = xStyle.Value;
            }

            Lang = null;
            XAttribute xLang = xParagraph.Attribute(XNamespace.Xml + "lang");
            if ((xLang != null) && (xLang.Value != null))
            {
                Lang = xLang.Value;
            }
            
        }