/// <summary>
        /// Converts FB2 poem  author element
        /// </summary>
        /// <param name="paragraphItem">item to convert</param>
        /// <param name="poemAuthorConverterParams"></param>
        /// <returns>XHTML representation</returns>
        public IHTMLItem Convert(ParagraphItem paragraphItem,PoemAuthorConverterParamsV2 poemAuthorConverterParams)
        {
            if (paragraphItem == null)
            {
                throw new ArgumentNullException("paragraphItem");
            }

            var paragraphConverter = new ParagraphConverterV2();
            var item = paragraphConverter.Convert(paragraphItem,  new ParagraphConverterParamsV2 { ResultType = ParagraphConvTargetEnumV2.Paragraph, StartSection = false, Settings = poemAuthorConverterParams .Settings});

            SetClassType(item, ElementStylesV2.PoemAuthor);
            return item;
        }
Ejemplo n.º 2
0
        internal void Load(XElement xTitle)
        {
            titleData.Clear();
            if (xTitle == null)
            {
                throw new ArgumentNullException("xTitle");
            }

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


            IEnumerable <XElement> subElements = xTitle.Elements();

            foreach (var element in subElements)
            {
                switch (element.Name.LocalName)
                {
                case EmptyLineItem.Fb2EmptyLineElementName:
                    titleData.Add(new EmptyLineItem());
                    break;

                case ParagraphItem.Fb2ParagraphElementName:
                    ParagraphItem paragraph = new ParagraphItem();
                    try
                    {
                        paragraph.Load(element);
                        titleData.Add(paragraph);
                    }
                    catch (Exception ex)
                    {
                        Debug.Fail(string.Format("Failed to load paragraph: {0}.", ex.Message));
                    }
                    break;

                default:
                    Debug.Fail(string.Format("TitleItem:Load - invalid element <{0}> encountered in title ."), element.Name.LocalName);
                    break;
                }
            }

            LangAttribute = null;
            XAttribute xLang = xTitle.Attribute(XNamespace.Xml + "lang");

            if ((xLang != null) && !string.IsNullOrEmpty(xLang.Value))
            {
                LangAttribute = xLang.Value;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Converts FB2 citation author element
        /// </summary>
        /// <param name="paragraphItem">item to convert</param>
        /// <param name="citationAuthorConverterParams"></param>
        /// <returns>XHTML representation</returns>
        public IHTMLItem Convert(ParagraphItem paragraphItem, CitationAuthorConverterParamsV2 citationAuthorConverterParams)
        {
            if (paragraphItem == null)
            {
                throw new ArgumentNullException("paragraphItem");
            }
            var cite = new Div(HTMLElementType.XHTML11);

            var paragraphConverter = new ParagraphConverterV2();
            cite.Add(paragraphConverter.Convert(paragraphItem,
                new ParagraphConverterParamsV2 {Settings =citationAuthorConverterParams.Settings, ResultType = ParagraphConvTargetEnumV2.Paragraph, StartSection = false}));

            SetClassType(cite, ElementStylesV2.CitationAuthor);
            return cite;
        }
Ejemplo n.º 4
0
        internal void Load(XElement xTitle)
        {
            titleData.Clear();
            if (xTitle == null)
            {
                throw new ArgumentNullException("xTitle");
            }

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


            IEnumerable<XElement> subElements = xTitle.Elements();
            foreach (var element in subElements)
            {
                switch (element.Name.LocalName)
                {
                    case EmptyLineItem.Fb2EmptyLineElementName:
                        titleData.Add(new EmptyLineItem());
                        break;
                    case ParagraphItem.Fb2ParagraphElementName:
                        ParagraphItem paragraph = new ParagraphItem();
                        try
                        {
                            paragraph.Load(element);
                            titleData.Add(paragraph);
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(string.Format("Failed to load paragraph: {0}.",ex.Message));
                        }
                        break;
                    default:
                        Debug.WriteLine(string.Format("TitleItem:Load - invalid element <{0}> encountered in title ."), element.Name.LocalName);
                        break;
                }

            }

            LangAttribute = null;
            XAttribute xLang = xTitle.Attribute(XNamespace.Xml + "lang");
            if ((xLang != null) && !string.IsNullOrEmpty(xLang.Value))
            {
                LangAttribute = xLang.Value;
            }
        }
Ejemplo n.º 5
0
        internal void Load(XElement xSection)
        {
            ClearAll();
            if (xSection == null)
            {
                throw new ArgumentNullException("xSection");
            }

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

            XElement xTitle = xSection.Element(xSection.Name.Namespace + TitleItem.Fb2TitleElementName);
            if (xTitle != null)
            {
                Title = new TitleItem();
                try
                {
                    Title.Load(xTitle);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(string.Format("Failed to load section title : {0}.", ex.Message));
                }
            }
            
            IEnumerable<XElement> xEpigraphs =
                xSection.Elements(xSection.Name.Namespace + EpigraphItem.Fb2EpigraphElementName);
            foreach (var xEpigraph in xEpigraphs)
            {
                EpigraphItem epigraph = new EpigraphItem();
                try
                {
                    epigraph.Load(xEpigraph);
                    _epigraphs.Add(epigraph);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(string.Format("Failed to load section epigraph : {0}.", ex.Message));
                }
            }

            XElement xAnnotation = xSection.Element(xSection.Name.Namespace + AnnotationItem.Fb2AnnotationItemName);
            if (xAnnotation != null)
            {
                Annotation  = new AnnotationItem();
                try
                {
                    Annotation.Load(xAnnotation);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(string.Format("Failed to load section annotation : {0}.", ex.Message));
                }
            }

            IEnumerable<XElement> xElements = xSection.Elements();
            foreach (var xElement in xElements)
            {
                switch (xElement.Name.LocalName)
                {
                    case ParagraphItem.Fb2ParagraphElementName:
                        ParagraphItem paragraph = new ParagraphItem();
                        try
                        {
                            paragraph.Load(xElement);
                            _content.Add(paragraph);
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(string.Format("Failed to load section paragraph : {0}.", ex.Message));
                        }
                        break;
                    case PoemItem.Fb2PoemElementName:
                        PoemItem poem = new PoemItem();
                        try
                        {
                            poem.Load(xElement);
                            _content.Add(poem);
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(string.Format("Failed to load section poem : {0}.", ex.Message));
                        }
                        break;
                    case ImageItem.Fb2ImageElementName:
                        ImageItem image = new ImageItem();
                        try
                        {
                            image.Load(xElement);
                            AddImage(image);
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(string.Format("Failed to load section image : {0}.", ex.Message));
                        }
                        break;
                    case SubTitleItem.Fb2SubtitleElementName:
                        SubTitleItem subtitle = new SubTitleItem();
                        try
                        {
                            subtitle.Load(xElement);
                            _content.Add(subtitle);
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(string.Format("Failed to load section subtitle : {0}.", ex.Message));
                        }
                        break;
                    case CiteItem.Fb2CiteElementName:
                        CiteItem cite = new CiteItem();
                        try
                        {
                            cite.Load(xElement);
                            _content.Add(cite);
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(string.Format("Failed to load section citation : {0}.", ex.Message));
                        }
                        break;
                    case EmptyLineItem.Fb2EmptyLineElementName:
                        EmptyLineItem eline = new EmptyLineItem();
                        _content.Add(eline);
                        break;
                    case TableItem.Fb2TableElementName:
                        TableItem table = new TableItem();
                        try
                        {
                            table.Load(xElement);
                            _content.Add(table);
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(string.Format("Failed to load section emptly line : {0}.", ex.Message));
                        }
                        break;
                    case Fb2TextSectionElementName: // internal <section> read recurive
                        SectionItem section = new SectionItem();
                        try
                        {
                            section.Load(xElement);
                            AddSection(section);
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(string.Format("Failed to load sub-section : {0}.", ex.Message));
                        }
                        break;
                    case AnnotationItem.Fb2AnnotationItemName: // already processed
                        break; 
                    case TitleItem.Fb2TitleElementName: // already processed
                        break;
                    case EpigraphItem.Fb2EpigraphElementName: // already processed
                        break;
                    default:
                        if (!string.IsNullOrEmpty(xElement.Value))
                        {
                            ParagraphItem tempParagraph = new ParagraphItem();
                            try
                            {
                                SimpleText text = new SimpleText {Text = xElement.Value};
                                tempParagraph.ParagraphData.Add(text);
                                _content.Add(tempParagraph);
                            }
                            catch
                            {
                                // ignored
                            }
                        }
                        Debug.WriteLine("AnnotationItem:Load - invalid element <{0}> encountered in title .", xElement.Name.LocalName);
                        break;
                }
            }

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

            Lang = null;
            XAttribute xLang = xSection.Attribute(XNamespace.Xml + "lang");
            if ((xLang != null))
            {
                Lang = xLang.Value;
            }
        }
Ejemplo n.º 6
0
        internal void Load(XElement xEpigraph)
        {
            epigraphData.Clear();
            if (xEpigraph == null)
            {
                throw new ArgumentNullException("xEpigraph");
            }

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

            IEnumerable<XElement> xItems = xEpigraph.Elements();
            textAuthors.Clear();
            foreach (var element in xItems)
            {
                switch (element.Name.LocalName)
                {
                    case ParagraphItem.Fb2ParagraphElementName:
                        ParagraphItem paragraph = new ParagraphItem();
                        try
                        {
                            paragraph.Load(element);
                            epigraphData.Add(paragraph);
                        }
                        catch (Exception ex)
                        {
                            Debug.Fail(string.Format("Failed to load paragraph: {0}.", ex.Message));
                        }
                        break;
                    case PoemItem.Fb2PoemElementName:
                        PoemItem poem = new PoemItem();
                        try
                        {
                            poem.Load(element);
                            epigraphData.Add(poem);
                        }
                        catch (Exception ex)
                        {
                            Debug.Fail(string.Format("Failed to load poem: {0}.", ex.Message));
                        }
                        break;
                    case CiteItem.Fb2CiteElementName:
                        CiteItem cite = new CiteItem();
                        try
                        {
                            cite.Load(element);
                            epigraphData.Add(cite);
                        }
                        catch (Exception ex)
                        {
                            Debug.Fail(string.Format("Failed to load citation: {0}.", ex.Message));
                        }
                        break;
                    case EmptyLineItem.Fb2EmptyLineElementName:
                        EmptyLineItem emptyLine = new EmptyLineItem();
                        try
                        {
                            epigraphData.Add(emptyLine);
                        }
                        catch (Exception ex)
                        {
                            Debug.Fail(string.Format("Failed to load empty line: {0}.", ex.Message));
                        }
                        break;
                    case TextAuthorItem.Fb2TextAuthorElementName:
                        TextAuthorItem author = new TextAuthorItem();
                        //SimpleText author = new SimpleText();
                        try
                        {
                            author.Load(element);
                            textAuthors.Add(author);
                        }
                        catch (Exception ex)
                        {
                            Debug.Fail(string.Format("Failed to load text author: {0}.", ex.Message));
                        }
                        break;
                    default:
                        Debug.Fail(string.Format("EpigraphItem:Load - invalid element <{0}> encountered in title ."), element.Name.LocalName);
                        break;
                }
            }

            XAttribute xID = xEpigraph.Attribute("id");
            if ((xID != null) &&(xID.Value != null))
            {
                ID = xID.Value;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Converts FB2 Paragraph to EPUB paragraph
        /// </summary>
        /// <param name="paragraphItem">item to convert</param>
        /// <param name="paragraphConverterParams"></param>
        /// <returns></returns>
        public HTMLItem Convert(ParagraphItem paragraphItem, ParagraphConverterParamsV3 paragraphConverterParams)
        {
            if (paragraphItem == null)
            {
                throw new ArgumentNullException("paragraphItem");
            }
            var paragraph = CreateBlock(paragraphConverterParams.ResultType);
            bool needToInsertDrop = paragraphConverterParams.Settings.CapitalDrop && paragraphConverterParams.StartSection;

            foreach (var item in paragraphItem.ParagraphData)
            {
                if (item is SimpleText)
                {
                    var textConverter = new SimpleTextElementConverterV3();
                    foreach (var s in textConverter.Convert(item,
                        new SimpleTextElementConverterParamsV3 { Settings = paragraphConverterParams.Settings, NeedToInsertDrop = needToInsertDrop }))
                    {
                        if (needToInsertDrop)
                        {
                            needToInsertDrop = false;
                            SetClassType(paragraph, ElementStylesV3.CapitalDrop);
                        }
                        paragraph.Add(s);
                    }
                }
                else if (item is InlineImageItem)
                {
                    // if no image data - do not insert link
                    if (paragraphConverterParams.Settings.Images.HasRealImages())
                    {
                        var inlineItem = item as InlineImageItem;
                        if (paragraphConverterParams.Settings.Images.IsImageIdReal(inlineItem.HRef))
                        {
                            var inlineImageConverter = new InlineImageConverterV3();
                            paragraph.Add(inlineImageConverter.Convert(inlineItem, new InlineImageConverterParamsV3 { Settings = paragraphConverterParams.Settings }));
                            paragraphConverterParams.Settings.Images.ImageIdUsed(inlineItem.HRef);
                        }
                        if (needToInsertDrop) // in case this is "drop" image - no need to create a drop
                        {
                            needToInsertDrop = false;
                        }
                    }
                }
                else if (item is InternalLinkItem)
                {
                    var internalLinkConverter = new InternalLinkConverterV3();
                    foreach (var s in internalLinkConverter.Convert(item as InternalLinkItem,
                        new InternalLinkConverterParamsV3 { Settings = paragraphConverterParams.Settings, NeedToInsertDrop = needToInsertDrop }))
                    {
                        if (needToInsertDrop)
                        {
                            needToInsertDrop = false;
                            SetClassType(paragraph, ElementStylesV3.CapitalDrop);
                        }
                        paragraph.Add(s);
                    }
                }
            }

            //SetClassType(paragraph);
            paragraph.GlobalAttributes.ID.Value =
                paragraphConverterParams.Settings.ReferencesManager.AddIdUsed(paragraphItem.ID, paragraph);

            return paragraph;
        }
Ejemplo n.º 8
0
        internal void Load(XElement xEpigraph)
        {
            epigraphData.Clear();
            if (xEpigraph == null)
            {
                throw new ArgumentNullException("xEpigraph");
            }


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

            IEnumerable <XElement> xItems = xEpigraph.Elements();

            textAuthors.Clear();
            foreach (var element in xItems)
            {
                switch (element.Name.LocalName)
                {
                case ParagraphItem.Fb2ParagraphElementName:
                    ParagraphItem paragraph = new ParagraphItem();
                    try
                    {
                        paragraph.Load(element);
                        epigraphData.Add(paragraph);
                    }
                    catch (Exception ex)
                    {
                        Debug.Fail(string.Format("Failed to load paragraph: {0}.", ex.Message));
                    }
                    break;

                case PoemItem.Fb2PoemElementName:
                    PoemItem poem = new PoemItem();
                    try
                    {
                        poem.Load(element);
                        epigraphData.Add(poem);
                    }
                    catch (Exception ex)
                    {
                        Debug.Fail(string.Format("Failed to load poem: {0}.", ex.Message));
                    }
                    break;

                case CiteItem.Fb2CiteElementName:
                    CiteItem cite = new CiteItem();
                    try
                    {
                        cite.Load(element);
                        epigraphData.Add(cite);
                    }
                    catch (Exception ex)
                    {
                        Debug.Fail(string.Format("Failed to load citation: {0}.", ex.Message));
                    }
                    break;

                case EmptyLineItem.Fb2EmptyLineElementName:
                    EmptyLineItem emptyLine = new EmptyLineItem();
                    try
                    {
                        epigraphData.Add(emptyLine);
                    }
                    catch (Exception ex)
                    {
                        Debug.Fail(string.Format("Failed to load empty line: {0}.", ex.Message));
                    }
                    break;

                case TextAuthorItem.Fb2TextAuthorElementName:
                    TextAuthorItem author = new TextAuthorItem();
                    //SimpleText author = new SimpleText();
                    try
                    {
                        author.Load(element);
                        textAuthors.Add(author);
                    }
                    catch (Exception ex)
                    {
                        Debug.Fail(string.Format("Failed to load text author: {0}.", ex.Message));
                    }
                    break;

                default:
                    Debug.Fail(string.Format("EpigraphItem:Load - invalid element <{0}> encountered in title ."), element.Name.LocalName);
                    break;
                }
            }

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

            if ((xID != null) && (xID.Value != null))
            {
                ID = xID.Value;
            }
        }
Ejemplo n.º 9
0
 private static void AppendParagraphItem(List<AbstractTextPart> appendTo, ParagraphItem paragraphItem)
 {
     foreach (StyleType styleType in paragraphItem.ParagraphData)
     {
         AppendStyleType(styleType, appendTo);
     }
 }
Ejemplo n.º 10
0
        internal void Load(XElement xSection)
        {
            ClearAll();
            if (xSection == null)
            {
                throw new ArgumentNullException("xSection");
            }

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

            XElement xTitle = xSection.Element(xSection.Name.Namespace + TitleItem.Fb2TitleElementName);

            if (xTitle != null)
            {
                Title = new TitleItem();
                try
                {
                    Title.Load(xTitle);
                }
                catch (Exception ex)
                {
                    Debug.Fail(string.Format("Failed to load section title : {0}.", ex.Message));
                }
            }

            IEnumerable <XElement> xEpigraphs =
                xSection.Elements(xSection.Name.Namespace + EpigraphItem.Fb2EpigraphElementName);

            foreach (var xEpigraph in xEpigraphs)
            {
                EpigraphItem epigraph = new EpigraphItem();
                try
                {
                    epigraph.Load(xEpigraph);
                    _epigraphs.Add(epigraph);
                }
                catch (Exception ex)
                {
                    Debug.Fail(string.Format("Failed to load section epigraph : {0}.", ex.Message));
                }
            }

            XElement xAnnotation = xSection.Element(xSection.Name.Namespace + AnnotationItem.Fb2AnnotationItemName);

            if (xAnnotation != null)
            {
                Annotation = new AnnotationItem();
                try
                {
                    Annotation.Load(xAnnotation);
                }
                catch (Exception ex)
                {
                    Debug.Fail(string.Format("Failed to load section annotation : {0}.", ex.Message));
                }
            }

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

            foreach (var xElement in xElements)
            {
                switch (xElement.Name.LocalName)
                {
                case ParagraphItem.Fb2ParagraphElementName:
                    ParagraphItem paragraph = new ParagraphItem();
                    try
                    {
                        paragraph.Load(xElement);
                        _content.Add(paragraph);
                    }
                    catch (Exception ex)
                    {
                        Debug.Fail(string.Format("Failed to load section paragraph : {0}.", ex.Message));
                    }
                    break;

                case PoemItem.Fb2PoemElementName:
                    PoemItem poem = new PoemItem();
                    try
                    {
                        poem.Load(xElement);
                        _content.Add(poem);
                    }
                    catch (Exception ex)
                    {
                        Debug.Fail(string.Format("Failed to load section poem : {0}.", ex.Message));
                    }
                    break;

                case ImageItem.Fb2ImageElementName:
                    ImageItem image = new ImageItem();
                    try
                    {
                        image.Load(xElement);
                        AddImage(image);
                    }
                    catch (Exception ex)
                    {
                        Debug.Fail(string.Format("Failed to load section image : {0}.", ex.Message));
                    }
                    break;

                case SubTitleItem.Fb2SubtitleElementName:
                    SubTitleItem subtitle = new SubTitleItem();
                    try
                    {
                        subtitle.Load(xElement);
                        _content.Add(subtitle);
                    }
                    catch (Exception ex)
                    {
                        Debug.Fail(string.Format("Failed to load section subtitle : {0}.", ex.Message));
                    }
                    break;

                case CiteItem.Fb2CiteElementName:
                    CiteItem cite = new CiteItem();
                    try
                    {
                        cite.Load(xElement);
                        _content.Add(cite);
                    }
                    catch (Exception ex)
                    {
                        Debug.Fail(string.Format("Failed to load section citation : {0}.", ex.Message));
                    }
                    break;

                case EmptyLineItem.Fb2EmptyLineElementName:
                    EmptyLineItem eline = new EmptyLineItem();
                    _content.Add(eline);
                    break;

                case TableItem.Fb2TableElementName:
                    TableItem table = new TableItem();
                    try
                    {
                        table.Load(xElement);
                        _content.Add(table);
                    }
                    catch (Exception ex)
                    {
                        Debug.Fail(string.Format("Failed to load section emptly line : {0}.", ex.Message));
                    }
                    break;

                case Fb2TextSectionElementName:     // internal <section> read recurive
                    SectionItem section = new SectionItem();
                    try
                    {
                        section.Load(xElement);
                        AddSection(section);
                    }
                    catch (Exception ex)
                    {
                        Debug.Fail(string.Format("Failed to load sub-section : {0}.", ex.Message));
                    }
                    break;

                case AnnotationItem.Fb2AnnotationItemName:     // already processed
                    break;

                case TitleItem.Fb2TitleElementName:     // already processed
                    break;

                case EpigraphItem.Fb2EpigraphElementName:     // already processed
                    break;

                default:
                    if (!string.IsNullOrEmpty(xElement.Value))
                    {
                        ParagraphItem tempParagraph = new ParagraphItem();
                        try
                        {
                            SimpleText text = new SimpleText {
                                Text = xElement.Value
                            };
                            tempParagraph.ParagraphData.Add(text);
                            _content.Add(tempParagraph);
                        }
                        catch
                        {
                            // ignored
                        }
                    }
                    Debug.Print("AnnotationItem:Load - invalid element <{0}> encountered in title .", xElement.Name.LocalName);
                    break;
                }
            }

            ID = null;
            XAttribute xID = xSection.Attribute("id");

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

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

            if ((xLang != null))
            {
                Lang = xLang.Value;
            }
        }
Ejemplo n.º 11
0
        internal void Load(XElement xAnnotation)
        {
            if (xAnnotation == null)
            {
                throw new ArgumentNullException(nameof(xAnnotation));
            }

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

            _content.Clear();
            IEnumerable <XElement> xItems = xAnnotation.Elements();

            foreach (var xItem in xItems)
            {
                switch (xItem.Name.LocalName)
                {
                case ParagraphItem.Fb2ParagraphElementName:
                    ParagraphItem paragraph = new ParagraphItem();
                    try
                    {
                        paragraph.Load(xItem);
                        _content.Add(paragraph);
                    }
                    catch (Exception)
                    {
                    }
                    break;

                case PoemItem.Fb2PoemElementName:
                    PoemItem poem = new PoemItem();
                    try
                    {
                        poem.Load(xItem);
                        _content.Add(poem);
                    }
                    catch (Exception)
                    {
                    }
                    break;

                case CiteItem.Fb2CiteElementName:
                    CiteItem cite = new CiteItem();
                    try
                    {
                        cite.Load(xItem);
                        _content.Add(cite);
                    }
                    catch (Exception)
                    {
                    }
                    break;

                case SubTitleItem.Fb2SubtitleElementName:
                    SubTitleItem subtitle = new SubTitleItem();
                    try
                    {
                        subtitle.Load(xItem);
                        _content.Add(subtitle);
                    }
                    catch (Exception)
                    {
                    }
                    break;

                case TableItem.Fb2TableElementName:
                    TableItem table = new TableItem();
                    try
                    {
                        table.Load(xItem);
                        _content.Add(table);
                    }
                    catch (Exception)
                    {
                    }
                    break;

                case EmptyLineItem.Fb2EmptyLineElementName:
                    EmptyLineItem eline = new EmptyLineItem();
                    _content.Add(eline);
                    break;

                default:
                    Debug.WriteLine(string.Format("AnnotationItem:Load - invalid element <{0}> encountered in annotation ."), xItem.Name.LocalName);
                    break;
                }
            }

            ID = null;
            XAttribute xID = xAnnotation.Attribute("id");

            if ((xID != null) && (xID.Value != null))
            {
                ID = xID.Value;
            }
        }
Ejemplo n.º 12
0
        internal void Load(XElement xCite)
        {
            citeData.Clear();
            if (xCite == null)
            {
                throw new ArgumentNullException("xCite");
            }

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

            textAuthors.Clear();
            IEnumerable <XElement> xItems = xCite.Elements();

            foreach (var element in xItems)
            {
                switch (element.Name.LocalName)
                {
                case ParagraphItem.Fb2ParagraphElementName:
                    ParagraphItem paragraph = new ParagraphItem();
                    try
                    {
                        paragraph.Load(element);
                        citeData.Add(paragraph);
                    }
                    catch (Exception)
                    {
                    }
                    break;

                case PoemItem.Fb2PoemElementName:
                    PoemItem poem = new PoemItem();
                    try
                    {
                        poem.Load(element);
                        citeData.Add(poem);
                    }
                    catch (Exception)
                    {
                    }
                    break;

                case EmptyLineItem.Fb2EmptyLineElementName:
                    EmptyLineItem emptyLine = new EmptyLineItem();
                    try
                    {
                        citeData.Add(emptyLine);
                    }
                    catch (Exception)
                    {
                    }
                    break;

                case SubTitleItem.Fb2SubtitleElementName:
                    SubTitleItem subtitle = new SubTitleItem();
                    try
                    {
                        subtitle.Load(element);
                        citeData.Add(subtitle);
                    }
                    catch (Exception)
                    {
                    }
                    break;

                case TableItem.Fb2TableElementName:
                    TableItem table = new TableItem();
                    try
                    {
                        table.Load(element);
                        citeData.Add(table);
                    }
                    catch (Exception)
                    {
                    }
                    break;

                case TextAuthorItem.Fb2TextAuthorElementName:
                    //ParagraphItem author = new ParagraphItem();
                    TextAuthorItem author = new TextAuthorItem();
                    try
                    {
                        author.Load(element);
                        textAuthors.Add(author);
                    }
                    catch (Exception)
                    {
                    }
                    break;

                default:
                    Debug.Fail(string.Format("CiteItem:Load - invalid element <{0}> encountered in title ."), element.Name.LocalName);
                    break;
                }
            }

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

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

            ID = null;
            XAttribute xID = xCite.Attribute("id");

            if ((xID != null) && (xID.Value != null))
            {
                ID = xID.Value;
            }
        }
Ejemplo n.º 13
0
        internal void Load(XElement xCite)
        {
            citeData.Clear();
            if (xCite == null)
            {
                throw new ArgumentNullException("xCite");
            }

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

            textAuthors.Clear();
            IEnumerable<XElement> xItems = xCite.Elements();
            foreach (var element in xItems)
            {
                switch (element.Name.LocalName)
                {
                    case ParagraphItem.Fb2ParagraphElementName:
                        ParagraphItem paragraph = new ParagraphItem();
                        try
                        {
                            paragraph.Load(element);
                            citeData.Add(paragraph);
                        }
                        catch (Exception)
                        {
                        }
                        break;
                    case PoemItem.Fb2PoemElementName:
                        PoemItem poem = new PoemItem();
                        try
                        {
                            poem.Load(element);
                            citeData.Add(poem);
                        }
                        catch (Exception)
                        {
                        }
                        break;
                    case EmptyLineItem.Fb2EmptyLineElementName:
                        EmptyLineItem emptyLine = new EmptyLineItem();
                        try
                        {
                            citeData.Add(emptyLine);
                        }
                        catch (Exception)
                        {
                        }
                        break;
                    case SubTitleItem.Fb2SubtitleElementName:
                        SubTitleItem subtitle = new SubTitleItem();
                        try
                        {
                            subtitle.Load(element);
                            citeData.Add(subtitle);
                        }
                        catch (Exception)
                        {
                        }
                        break;
                    case TableItem.Fb2TableElementName:
                        TableItem table = new TableItem();
                        try
                        {
                            table.Load(element);
                            citeData.Add(table);

                        }
                        catch (Exception)
                        {
                        }
                        break;
                    case TextAuthorItem.Fb2TextAuthorElementName:
                        //ParagraphItem author = new ParagraphItem();
                        TextAuthorItem author = new TextAuthorItem();
                        try
                        {
                            author.Load(element);
                            textAuthors.Add(author);
                        }
                        catch (Exception)
                        {
                        }
                        break;
                    default:
                        Debug.Fail(string.Format("CiteItem:Load - invalid element <{0}> encountered in title ."), element.Name.LocalName);
                        break;
                }
            }

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

            ID = null;
            XAttribute xID = xCite.Attribute("id");
            if ((xID != null) && (xID.Value != null))
            {
                ID = xID.Value;
            }
        }
Ejemplo n.º 14
0
        internal void Load(XElement xAnnotation)
        {
            if (xAnnotation == null)
            {
                throw new ArgumentNullException("xAnnotation");
            }

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

            content.Clear();
            IEnumerable<XElement> xItems = xAnnotation.Elements();
            foreach (var xItem in xItems)
            {
                switch (xItem.Name.LocalName)
                {
                    case ParagraphItem.Fb2ParagraphElementName:
                        ParagraphItem paragraph = new ParagraphItem();
                        try
                        {
                            paragraph.Load(xItem);
                            content.Add(paragraph);
                        }
                        catch (Exception)
                        {
                        }
                        break;
                    case PoemItem.Fb2PoemElementName:
                        PoemItem poem = new PoemItem();
                        try
                        {
                            poem.Load(xItem);
                            content.Add(poem);
                        }
                        catch (Exception)
                        {
                        }
                        break;
                    case CiteItem.Fb2CiteElementName:
                        CiteItem cite = new CiteItem();
                        try
                        {
                            cite.Load(xItem);
                            content.Add(cite);
                        }
                        catch (Exception)
                        {
                        }
                        break;
                    case SubTitleItem.Fb2SubtitleElementName:
                        SubTitleItem subtitle = new SubTitleItem();
                        try
                        {
                            subtitle.Load(xItem);
                            content.Add(subtitle);
                        }
                        catch (Exception)
                        {
                        }
                        break;
                    case TableItem.Fb2TableElementName:
                        TableItem table = new TableItem();
                        try
                        {
                            table.Load(xItem);
                            content.Add(table);
                        }
                        catch (Exception)
                        {
                        }
                        break;
                    case EmptyLineItem.Fb2EmptyLineElementName:
                        EmptyLineItem eline = new EmptyLineItem();
                        content.Add(eline);
                        break;
                    default:
                        Debug.Fail(string.Format("AnnotationItem:Load - invalid element <{0}> encountered in annotation ."), xItem.Name.LocalName);
                        break;
                }
            }

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