Exemplo n.º 1
0
        /// <summary>
        /// parses a given Flat ODT file
        /// </summary>
        /// <param name="filename">the path to the FODT file</param>
        /// <returns>a book object containing the FODT's information</returns>
        public Book Parse(string filename)
        {
            XElement document = this.loadXML(filename);

            var styles = this.getStyles(document);

            var paragraphs = this.getParagraphs(document);

            var book = new Book();

            Chapter lastChapter = new Chapter() { Title = "DUMMY" };
            Chapter currentChapter = new Chapter() { Title = "DUMMY" };
            foreach (var paragraph in paragraphs)
            {
                paragraph.Style = this.getStyle(styles, paragraph);
                var styleType = paragraph.Style.StyleType;

                if (styleType == StyleType.Title)
                {
                    lastChapter = currentChapter;

                    currentChapter = new Chapter();
                    book.Chapters.Add(currentChapter);

                    currentChapter.PrecedingChapter = lastChapter;
                    lastChapter.SucceedingChapter = currentChapter;

                    currentChapter.Title = paragraph.Content;
                    currentChapter.RevisionStatus = this.getRevisionStatus(paragraph.Style);
                }
                else if (styleType == StyleType.Successor)
                {
                    currentChapter.SucceedingChapterReferences.Add(paragraph.Content);
                }
                else if (styleType == StyleType.Precessor)
                {
                    currentChapter.PrecedingChapterReferences.Add(paragraph.Content);
                }
                else if (styleType == StyleType.Summary)
                {
                    currentChapter.Summary.Add(paragraph.Content);
                }
                else if (styleType == StyleType.Comment)
                {
                    currentChapter.Comment.Add(paragraph.Content);
                }
                else if (styleType == StyleType.Content)
                {
                    currentChapter.Text.Add(paragraph.Content);
                }
                else
                {

                }
            }

            this.checkChaptersErrors(book.Chapters);

            return book;
        }
Exemplo n.º 2
0
        private Boolean checkTitle(Chapter chapter)
        {
            if (String.IsNullOrWhiteSpace(chapter.Title))
            {
                Trace.TraceInformation("Chapter between '" + chapter.PrecedingChapter.Title + "' and '" + chapter.SucceedingChapter.Title + "' has no name.");
                chapter.DebugInformation.Add(new KeyValuePair<DebugInformationType, object>(DebugInformationType.EmptyTitle, null));

                return false;
            }

            return true;
        }
Exemplo n.º 3
0
        private Boolean checkReferences(IEnumerable<Chapter> chapters, Chapter chapter)
        {
            bool failed = false;

            foreach (var sibling in chapter.PrecedingChapterReferences.Concat(chapter.SucceedingChapterReferences))
            {
                bool exists = chapters.Any(x => x.Title == sibling);
                if (exists == false)
                {
                    failed = true;
                    Trace.TraceInformation("Chapter '" + sibling + "' by '" + chapter.Title + "' referenced but does not exist.");
                    chapter.DebugInformation.Add(new KeyValuePair<DebugInformationType, object>(DebugInformationType.MissingReference, sibling));
                }
            }

            return failed;
        }
Exemplo n.º 4
0
        private Boolean checkSummary(Chapter chapter)
        {
            var success = chapter.Summary.Any(p => String.IsNullOrWhiteSpace(p) == false);

            if (success == false)
            {
                Trace.TraceInformation("Chapter '"+chapter.Title+"' has no summary");
                chapter.DebugInformation.Add(new KeyValuePair<DebugInformationType,object>(DebugInformationType.EmptySummary, null));
            }

            return !success;
        }
Exemplo n.º 5
0
 private void checkChapterErrors(IEnumerable<Chapter> chapters, Chapter chapter)
 {
     this.checkReferences(chapters, chapter);
     this.checkTitle(chapter);
     this.checkSummary(chapter);
 }