/// <summary>
        /// Converts FB2 Stanza element into XHTML representation
        /// </summary>
        /// <param name="stanzaItem">item to convert</param>
        /// <param name="stanzaConverterParams"></param>
        /// <returns>XHTML representation</returns>
        public IHTMLItem Convert(StanzaItem stanzaItem, StanzaConverterParamsV3 stanzaConverterParams)
        {
            if (stanzaItem == null)
            {
                throw new ArgumentNullException("stanzaItem");
            }
            var stanzaSection = new Div(HTMLElementType.HTML5);

            if (stanzaItem.Title != null)
            {
                var titleConverter = new TitleConverterV3();
                stanzaSection.Add(titleConverter.Convert(stanzaItem.Title, new TitleConverterParamsV3 { TitleLevel = stanzaConverterParams.Level, Settings = stanzaConverterParams.Settings }));
            }

            if (stanzaItem.SubTitle != null)
            {
                var subtitleConverter = new SubtitleConverterV3();
                stanzaSection.Add(subtitleConverter.Convert(stanzaItem.SubTitle, new SubtitleConverterParamsV3 { Settings = stanzaConverterParams.Settings }));
            }

            foreach (var line in stanzaItem.Lines)
            {
                var vElementConverter = new VElementConverterV3();
                stanzaSection.Add(vElementConverter.Convert(line, new VElementConverterParamsV3 { Settings = stanzaConverterParams.Settings }));
            }

            if (stanzaItem.Lang != null)
            {
                stanzaSection.GlobalAttributes.Language.Value = stanzaItem.Lang;
            }

            SetClassType(stanzaSection, ElementStylesV3.Stanza);
            return stanzaSection;
        }
Beispiel #2
0
        internal void Load(XElement xPoem)
        {
            if (xPoem == null)
            {
                throw new ArgumentNullException("xPoem");
            }

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

            Title = null;
            Date = null;
            epigraphs.Clear();
            content.Clear();
            authors.Clear();

            IEnumerable<XElement> xElements = xPoem.Elements();
            foreach (var xElement in xElements)
            {
                if (xElement.Name == (XName)(xPoem.Name.Namespace + StanzaItem.Fb2StanzaElementName))
                {
                    StanzaItem stanza = new StanzaItem();
                    try
                    {
                        stanza.Load(xElement);
                        content.Add(stanza);
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
                else if (xElement.Name == (XName)(xPoem.Name.Namespace + SubTitleItem.Fb2SubtitleElementName))
                {
                    SubTitleItem subtitle = new SubTitleItem();
                    try
                    {
                        subtitle.Load(xElement);
                        content.Add(subtitle);
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
                else if (xElement.Name == (XName)(xPoem.Name.Namespace + TitleItem.Fb2TitleElementName) && Title == null) // only one title
                {
                        Title = new TitleItem();
                        Title.Load(xElement);
                }
                else if (xElement.Name == (XName)(xPoem.Name.Namespace + EpigraphItem.Fb2EpigraphElementName))
                {
                    EpigraphItem epigraphItem = new EpigraphItem();
                    try
                    {
                        epigraphItem.Load(xElement);
                        epigraphs.Add(epigraphItem);
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
                else if (xElement.Name == (XName)(xPoem.Name.Namespace + TextAuthorItem.Fb2TextAuthorElementName))
                {
                    TextAuthorItem author = new TextAuthorItem();
                    try
                    {
                        author.Load(xElement);
                        authors.Add(author);
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
                else if (xElement.Name == (XName)(xPoem.Name.Namespace + DateItem.Fb2DateElementName) && Date == null) // only one date
                {
                    Date = new DateItem();
                    try
                    {
                        Date.Load(xElement);
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
            }

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

            Lang = null;
            XAttribute xLang = xPoem.Attribute(XNamespace.Xml + "lang");
            if ((xLang != null) && (xLang.Value != null))
            {
                Lang = xLang.Value;
            }
        }
Beispiel #3
0
        internal void Load(XElement xPoem)
        {
            if (xPoem == null)
            {
                throw new ArgumentNullException("xPoem");
            }

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

            Title = null;
            Date  = null;
            epigraphs.Clear();
            content.Clear();
            authors.Clear();

            IEnumerable <XElement> xElements = xPoem.Elements();

            foreach (var xElement in xElements)
            {
                if (xElement.Name == (XName)(xPoem.Name.Namespace + StanzaItem.Fb2StanzaElementName))
                {
                    StanzaItem stanza = new StanzaItem();
                    try
                    {
                        stanza.Load(xElement);
                        content.Add(stanza);
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
                else if (xElement.Name == (XName)(xPoem.Name.Namespace + SubTitleItem.Fb2SubtitleElementName))
                {
                    SubTitleItem subtitle = new SubTitleItem();
                    try
                    {
                        subtitle.Load(xElement);
                        content.Add(subtitle);
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
                else if (xElement.Name == (XName)(xPoem.Name.Namespace + TitleItem.Fb2TitleElementName) && Title == null) // only one title
                {
                    Title = new TitleItem();
                    Title.Load(xElement);
                }
                else if (xElement.Name == (XName)(xPoem.Name.Namespace + EpigraphItem.Fb2EpigraphElementName))
                {
                    EpigraphItem epigraphItem = new EpigraphItem();
                    try
                    {
                        epigraphItem.Load(xElement);
                        epigraphs.Add(epigraphItem);
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
                else if (xElement.Name == (XName)(xPoem.Name.Namespace + TextAuthorItem.Fb2TextAuthorElementName))
                {
                    TextAuthorItem author = new TextAuthorItem();
                    try
                    {
                        author.Load(xElement);
                        authors.Add(author);
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
                else if (xElement.Name == (XName)(xPoem.Name.Namespace + DateItem.Fb2DateElementName) && Date == null) // only one date
                {
                    Date = new DateItem();
                    try
                    {
                        Date.Load(xElement);
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
            }

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

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

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

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