ListItem represent a list item which is used within a list.
Inheritance: IContent, IContentContainer, IHtml
Ejemplo n.º 1
0
        /// <summary>
        /// Creates sublists for nested lists.
        /// </summary>
        /// <param name="firstItem">The item to start the list with.</param>
        /// <param name="document">The document to which the sublist belongs.</param>
        /// <param name="currentIndex">The index of the item.</param>
        /// <returns>An ODF list</returns>
        protected AODL.Document.Content.Text.List GetODFSublist(ListItem firstItem, IDocument document, AODL.Document.Content.Text.List parentList, ref int currentIndex)
        {
            //Create a list
            AODL.Document.Content.Text.List list = new AODL.Document.Content.Text.List(document, parentList);

            //Set the level of the list
            int currentLevel = firstItem.Level;

            //Create a new list item
            AODL.Document.Content.Text.ListItem listItem = null;
            //Loop through the items
            while (currentIndex < Items.Count)
            {
                if (Items[currentIndex].Level > currentLevel)
                {
                    //Start a new list and append items.
                    listItem.Content.Add(GetODFSublist(Items[currentIndex], document, list, ref currentIndex));
                    continue;
                }
                if (Items[currentIndex].Level < currentLevel)
                {
                    //Stop this list.
                    break;
                }
                if (Items[currentIndex].Level == currentLevel)
                {
                    //Create a new list item
                    listItem = new AODL.Document.Content.Text.ListItem(document);
                    //Create a paragraph
                    var paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);
                    //Add the text
                    foreach (var formatedText in CommonDocumentFunctions.ParseParagraphForODF(document, Items[currentIndex].Text))
                    {
                        paragraph.TextContent.Add(formatedText);
                    }

                    //Add paragraph to the list item
                    listItem.Content.Add(paragraph);

                    //Add the list item
                    list.Content.Add(listItem);

                    currentIndex++;
                }
            }

            return(list);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets a list in ODF format.
        /// </summary>
        /// <param name="document">The document to which the list belongs.</param>
        /// <returns>The list as an IContent document</returns>
        public override IContent GetODFList(IDocument document)
        {
            //Create a list
            AODL.Document.Content.Text.List list = new AODL.Document.Content.Text.List(document, "NL1", ListStyles.Number, "NL1P1");

            //Set the list level to 0 as this is the top of the list
            int currentLevel = 0;

            //Create a new list item
            AODL.Document.Content.Text.ListItem listItem = null;
            //Loop through the items
            for (int currentIndex = 0; currentIndex < Items.Count; currentIndex++)
            {
                if (Items[currentIndex].Level > currentLevel)
                {
                    //Start a new list and append items.
                    if (listItem == null)
                    {
                        listItem = new AODL.Document.Content.Text.ListItem(document);
                    }
                    listItem.Content.Add(GetODFSublist(Items[currentIndex], document, list, ref currentIndex));
                    currentIndex--;
                    //Skip the rest of the routine
                    continue;
                }
                if (Items[currentIndex].Level == currentLevel)
                {
                    //Create a new list item
                    listItem = new AODL.Document.Content.Text.ListItem(document);
                    //Create a paragraph
                    var paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);
                    //Add the text
                    foreach (var formatedText in CommonDocumentFunctions.ParseParagraphForODF(document, Items[currentIndex].Text))
                    {
                        paragraph.TextContent.Add(formatedText);
                    }

                    //Add paragraph to the list item
                    listItem.Content.Add(paragraph);

                    //Add the list item
                    list.Content.Add(listItem);
                }
            }

            return(list);
        }
Ejemplo n.º 3
0
		/// <summary>
		/// Creates the list item.
		/// </summary>
		/// <param name="node">The node.</param>
		/// <returns></returns>
		private ListItem CreateListItem(XmlNode node)
		{
			try
			{

				ListItem listItem			= new ListItem(this._document);
				ContentCollection iColl	= new ContentCollection();
				listItem.Node				= node;

				foreach(XmlNode nodeChild in listItem.Node.ChildNodes)
				{
					IContent iContent		= this.CreateContent(nodeChild);
					if (iContent != null)
						AddToCollection(iContent, iColl);
					//iColl.Add(iContent);
					else
					{
						this.OnWarning(new AODLWarning("Couldn't create a IContent object for a ListItem.", nodeChild));
					}
				}

				listItem.Node.InnerXml		= "";

				foreach(IContent iContent in iColl)
					//listItem.Content.Add(iContent);
					AddToCollection(iContent,listItem.Content);

				return listItem;
			}
			catch(Exception ex)
			{
				throw new AODLException("Exception while trying to create a ListItem.", ex);
			}
		}
		/// <summary>
		/// Gets the list item as HTML.
		/// </summary>
		/// <param name="listItem">The list item.</param>
		/// <returns></returns>
		public string GetListItemAsHtml(ListItem listItem)
		{
			string html					= "<li>\n";

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

			if (!html.Equals("<li>\n"))
				html				+= "</li>\n";
			else
				html				= "";

			return html;
		}
Ejemplo n.º 5
0
 public void ListItemTest()
 {
     //Create a new text document
     var document					= new TextDocument();
     document.New();
     //Create a numbered list
     var li									= new AODL.Document.Content.Text.List(document, "L1", ListStyles.Bullet, "L1P1");
     //Create a new list item
     var lit							= new ListItem(li);
     Assert.IsNotNull(lit.Content, "Content object must exist!");
     //Create a paragraph
     var paragraph						= ParagraphBuilder.CreateStandardTextParagraph(document);
     //Add some text
     paragraph.TextContent.Add(new SimpleText(document, "First item"));
     //Add paragraph to the list item
     lit.Content.Add(paragraph);
     //Add the list item
     li.Content.Add(lit);
     //Add the list
     document.Content.Add(li);
     //Save document
     document.SaveTo(AARunMeFirstAndOnce.outPutFolder+"list.odt");
 }
Ejemplo n.º 6
0
 public void SimpleTableWithList()
 {
     //Create a new text document
     var document = new TextDocument();
     document.New();
     //Create a table for a text document using the TableBuilder
     var table = TableBuilder.CreateTextDocumentTable(
         document,
         "table1",
         "table1",
         3,
         3,
         16.99,
         false,
         false);
     //Create a bullet list
     var list = new AODL.Document.Content.Text.List(document, "L1", ListStyles.Bullet, "L1P1");
     //Create a list item
     var lit = new ListItem(list);
     //Create a standard paragraph
     var paragraph = ParagraphBuilder.CreateStandardTextParagraph(document);
     //Add some simple text
     paragraph.TextContent.Add(new SimpleText(document, "List item text"));
     //Add paragraph to the list item
     lit.Content.Add(paragraph);
     //Add item to the list
     list.Content.Add(lit);
     //Insert paragraph into the first cell
     table.RowCollection[0].CellCollection[0].Content.Add(list);
     //Add table to the document
     document.Content.Add(table);
     //Save the document
     document.SaveTo(AARunMeFirstAndOnce.outPutFolder + "simpleTableWithList.odt");
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates the list item.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <returns></returns>
        private ListItem CreateListItem(XmlNode node)
        {
            try
            {

                ListItem listItem			= new ListItem(this._document);
                IContentCollection iColl	= new IContentCollection();
                listItem.Node				= node;

                foreach(XmlNode nodeChild in listItem.Node.ChildNodes)
                {
                    IContent iContent		= this.CreateContent(nodeChild);
                    if(iContent != null)
                        iColl.Add(iContent);
                    else
                    {
                        if(this.OnWarning != null)
                        {
                            AODLWarning warning			= new AODLWarning("Couldn't create a IContent object for a ListItem.");
                            warning.InMethod			= AODLException.GetExceptionSourceInfo(new StackFrame(1, true));
                            warning.Node				= nodeChild;
                            this.OnWarning(warning);
                        }
                    }
                }

                listItem.Node.InnerXml		= "";

                foreach(IContent iContent in iColl)
                    listItem.Content.Add(iContent);

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

                throw exception;
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets the list item as HTML.
        /// </summary>
        /// <param name="listItem">The list item.</param>
        /// <returns></returns>
        public string GetListItemAsHtml(ListItem listItem)
        {
            string html					= "<li>\n";

            try
            {
                if(listItem != null)
                {
                    if(listItem.Content != null)
                    {
                        html			+= this.GetIContentCollectionAsHtml(listItem.Content);
                    }
                }
            }
            catch(Exception ex)
            {
                AODLException exception		= new AODLException("Exception while trying to build a HTML string from a ListItem object.");
                exception.InMethod			= AODLException.GetExceptionSourceInfo(new StackFrame(1, true));
                exception.OriginalException	= ex;

                throw exception;
            }

            if(!html.Equals("<li>\n"))
                html				+= "</li>\n";
            else
                html				= "";

            return html;
        }