TableOfContent represent a table of contents.
Inheritance: IContent, IContentContainer, IHtml
示例#1
0
		public void TableOfContentsTest()
		{
		//Create new Document
		TextDocument textDocument		= new TextDocument();
		textDocument.New();
		//Create a new Table of contents
		TableOfContents tableOfContents	= new TableOfContents(
			textDocument, "Table_Of_Contents", false, false, "Table of Contents");
		//Add the toc
		textDocument.Content.Add(tableOfContents);
		//Create a new heading, there's no need of the chapter number
		string sHeading					= "A first headline";
		//The corresponding text entry, here you need to set the
		//chapter number
		string sTocEntry				= "1. A first headline";
		Header header					= new Header(
			textDocument, Headings.Heading_20_1);
		header.OutLineLevel				= "1";
		header.TextContent.Add(new SimpleText(textDocument,  sHeading));
		//add the header to the content
		textDocument.Content.Add(header);
		//add the toc entry text as entry to the Table of contents
		tableOfContents.InsertEntry(sTocEntry, 1);
		//Add some text to this chapter
		Paragraph paragraph				= ParagraphBuilder.CreateStandardTextParagraph(textDocument);
		paragraph.TextContent.Add(new SimpleText(textDocument, "I'm the text for the first chapter!"));
		textDocument.Content.Add(paragraph);
		//Add a sub header to the first chapter
		//Create a new heading, there's no need of the chapter number
		sHeading						= "A first sub headline";
		//The corresponding text entry, here you need to set the
		//chapter number
		sTocEntry						= "1.1. A first sub headline";
		header							= new Header(
			textDocument, Headings.Heading_20_2);
		header.OutLineLevel				= "2";
		header.TextContent.Add(new SimpleText(textDocument,  sHeading));
		//add the header to the content
		textDocument.Content.Add(header);
		//add the toc entry text as entry to the Table of contents
		tableOfContents.InsertEntry(sTocEntry, 2);
		//Add some text to this sub chapter
			paragraph				= ParagraphBuilder.CreateStandardTextParagraph(textDocument);
			paragraph.TextContent.Add(new SimpleText(textDocument, "I'm the text for the subchapter chapter!"));
		textDocument.Content.Add(paragraph);
//		ListStyle listStyle				= new ListStyle(textDocument, "TOC_LIST");
//		listStyle.AutomaticAddListLevelStyles(ListStyles.Number);
//		textDocument.Styles.Add(listStyle);
		//Save it
		textDocument.SaveTo(AARunMeFirstAndOnce.outPutFolder+"toc.odt");
		}
		/// <summary>
		/// Creates the table of contents.
		/// </summary>
		/// <param name="tocNode">The toc node.</param>
		/// <returns></returns>
		private TableOfContents CreateTableOfContents(XmlNode tocNode)
		{
			try
			{
				if (this._document is TextDocument)
				{
					//Create the TableOfContents object
					TableOfContents tableOfContents		= new TableOfContents(
						((TextDocument)this._document), tocNode);
					//Recieve the Section style
					IStyle sectionStyle					= this._document.Styles.GetStyleByName(tableOfContents.StyleName);

					if (sectionStyle != null)
						tableOfContents.Style				= sectionStyle;
					else
					{
						OnWarning(new AODLWarning("A SectionStyle for the TableOfContents object wasn't found.", tocNode));
					}
					
					//Create the text entries
					XmlNodeList paragraphNodeList	= tocNode.SelectNodes(
						"text:index-body/text:p", this._document.NamespaceManager);
					XmlNode indexBodyNode			= tocNode.SelectSingleNode("text:index-body",
					                                                   this._document.NamespaceManager);
					tableOfContents.IndexBodyNode	= indexBodyNode;
					ContentCollection pCollection	= new ContentCollection();

					foreach(XmlNode paragraphnode in paragraphNodeList)
					{
						Paragraph paragraph			= this.CreateParagraph(paragraphnode);
						if (indexBodyNode != null)
							indexBodyNode.RemoveChild(paragraphnode);
						//pCollection.Add(paragraph);
						AddToCollection(paragraph, pCollection);
					}

					foreach(IContent content in pCollection)
						AddToCollection(content, tableOfContents.Content);
					//tableOfContents.Content.Add(content);

					return tableOfContents;
				}

				return null;
			}
			catch(Exception ex)
			{
				throw new AODLException("Exception while trying to create a TableOfContents.", ex);
			}
		}
示例#3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TableOfContentsSource"/> class.
 /// </summary>
 /// <param name="tableOfContents">Content of the table of.</param>
 public TableOfContentsSource(TableOfContents tableOfContents)
 {
     this._tableOfContents = tableOfContents;
     this.TableOfContentsIndexTemplateCollection = new TableOfContentsIndexTemplateCollection();
     this.NewXmlNode();
 }
		/// <summary>
		/// Gets the table of contents as HTML.
		/// </summary>
		/// <param name="tableOfContents">The table of contents.</param>
		/// <returns></returns>
		public string GetTableOfContentsAsHtml(TableOfContents tableOfContents)
		{
			string html					= "";

			try
			{
				if (tableOfContents != null)
				{
					XmlNode nodeTitle	= tableOfContents.Node.SelectSingleNode(
						"text:index-body/text:index-title/text:p",
						tableOfContents.Document.NamespaceManager);
					if (nodeTitle != null)
					{
						html			+= "<p "+this.HTMLStyleBuilder.HeaderHtmlStyles[0]+">\n";
						html			+= nodeTitle.InnerText;
						html			+= "\n</p>\n";
					}

					if (tableOfContents.Content != null)
						html			+= this.GetIContentCollectionAsHtml(tableOfContents.Content);
				}
			}
			catch(Exception ex)
			{
				throw new AODLException("Exception while trying to build a HTML string from a TableOfContents.", ex);
			}

			return html;
		}
示例#5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TableOfContentsIndexTemplate"/> class.
 /// </summary>
 /// <param name="tableOfContents">Content of the table of.</param>
 /// <param name="outlineLevel">For which outline level this template should be used.</param>
 /// <param name="styleName">Style name.</param>
 public TableOfContentsIndexTemplate(TableOfContents tableOfContents, int outlineLevel, string styleName)
 {
     this.TableOfContents = tableOfContents;
     this.NewXmlNode(outlineLevel, styleName);
 }
        /// <summary>
        /// Creates the table of contents.
        /// </summary>
        /// <param name="tocNode">The toc node.</param>
        /// <returns></returns>
        private TableOfContents CreateTableOfContents(XmlNode tocNode)
        {
            try
            {
                if(this._document is TextDocument)
                {
                    //Create the TableOfContents object
                    TableOfContents tableOfContents		= new TableOfContents(
                        ((TextDocument)this._document), tocNode);
                    //Recieve the Section style
                    IStyle sectionStyle					= this._document.Styles.GetStyleByName(tableOfContents.StyleName);

                    if(sectionStyle != null)
                        tableOfContents.Style				= sectionStyle;
                    else
                    {
                        if(this.OnWarning != null)
                        {
                            AODLWarning warning			= new AODLWarning("A SectionStyle for the TableOfContents object wasn't found.");
                            warning.InMethod			= AODLException.GetExceptionSourceInfo(new StackFrame(1, true));
                            warning.Node				= tocNode;
                            this.OnWarning(warning);
                        }
                    }

                    //Create the text entries
                    XmlNodeList paragraphNodeList	= tocNode.SelectNodes(
                        "text:index-body/text:p", this._document.NamespaceManager);
                    XmlNode indexBodyNode			= tocNode.SelectSingleNode("text:index-body",
                        this._document.NamespaceManager);
                    tableOfContents._indexBodyNode	= indexBodyNode;
                    IContentCollection pCollection	= new IContentCollection();

                    foreach(XmlNode paragraphnode in paragraphNodeList)
                    {
                        Paragraph paragraph			= this.CreateParagraph(paragraphnode);
                        if(indexBodyNode != null)
                            indexBodyNode.RemoveChild(paragraphnode);
                        pCollection.Add(paragraph);
                    }

                    foreach(IContent content in pCollection)
                        tableOfContents.Content.Add(content);

                    return tableOfContents;
                }

                return null;
            }
            catch(Exception ex)
            {
                AODLException exception		= new AODLException("Exception while trying to create a TableOfContents.");
                exception.InMethod			= AODLException.GetExceptionSourceInfo(new StackFrame(1, true));
                exception.Node				= tocNode;
                exception.OriginalException	= ex;

                throw exception;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="TableOfContentSource"/> class.
 /// </summary>
 /// <param name="tableOfContents">Content of the table of.</param>
 public TableOfContentsSource(TableOfContents tableOfContents)
 {
     this._tableOfContents			= tableOfContents;
     this.TableOfContentsIndexTemplateCollection = new TableOfContentsIndexTemplateCollection();
     this.NewXmlNode();
 }
		/// <summary>
		/// Initializes a new instance of the <see cref="TableOfContentsIndexTemplate"/> class.
		/// </summary>
		/// <param name="tableOfContents">Content of the table of.</param>
		/// <param name="outlineLevel">For which outline level this template should be used.</param>
		/// <param name="styleName">Style name.</param>
		public TableOfContentsIndexTemplate(TableOfContents tableOfContents, int outlineLevel, string styleName)
		{
			this.TableOfContents			= tableOfContents;
			this.NewXmlNode(outlineLevel, styleName);
		}