/// <summary> /// Creates a simple text content and adds it to the provided content collection. /// </summary> /// <param name="doc"></param> /// <param name="content"></param> /// <param name="value">The value to write. May be null.</param> protected static void CreateAddSimpleText(IDocument doc, IContentCollection content, object value) { Paragraph p = ParagraphBuilder.CreateStandardTextParagraph(doc); p.TextContent.Add(new SimpleText(doc, Convert.ToString(value ?? string.Empty))); content.Add(p); }
/// <summary> /// Creates the table. /// </summary> /// <param name="tableNode">The tablenode.</param> /// <returns></returns> private Table CreateTable(XmlNode tableNode) { try { //Create a new table Table table = new Table(this._document, tableNode); IContentCollection iColl = new IContentCollection(); //Recieve the table style IStyle tableStyle = this._document.Styles.GetStyleByName(table.StyleName); if(tableStyle != null) table.Style = tableStyle; else { if(this.OnWarning != null) { AODLWarning warning = new AODLWarning("Couldn't recieve a TableStyle."); warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); warning.Node = tableNode; this.OnWarning(warning); } } //Create the table content foreach(XmlNode nodeChild in table.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 IContent from a table node. Content is unknown table content!"); warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); warning.Node = iContent.Node; this.OnWarning(warning); } } } table.Node.InnerText = ""; foreach(IContent iContent in iColl) { if(iContent is Column) { ((Column)iContent).Table = table; table.ColumnCollection.Add(iContent as Column); } else if(iContent is Row) { ((Row)iContent).Table = table; table.RowCollection.Add(iContent as Row); } else if(iContent is RowHeader) { ((RowHeader)iContent).Table = table; table.RowHeader = iContent as RowHeader; } else { if(this.OnWarning != null) { AODLWarning warning = new AODLWarning("Couldn't create IContent from a table node."); warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); warning.Node = tableNode; this.OnWarning(warning); table.Node.AppendChild(iContent.Node); } } } return table; } catch(Exception ex) { AODLException exception = new AODLException("Exception while trying to create a Table."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.Node = tableNode; exception.OriginalException = ex; throw exception; } }
/// <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; } }
/// <summary> /// Creates the list. /// </summary> /// <param name="listNode">The list node.</param> /// <returns>The List object</returns> private List CreateList(XmlNode listNode) { try { #region Old code Todo: delete // string stylename = null; // XmlNode stylenode = null; // ListStyles liststyles = ListStyles.Bullet; //as default // string paragraphstylename = null; // // if(outerlist == null) // { // stylename = this.GetStyleName(listNode.OuterXml); // stylenode = this.GetAStyleNode("text:list-style", stylename); // liststyles = this.GetListStyle(listNode); // } // List list = null; // // if(listNode.ChildNodes.Count > 0) // { // try // { // paragraphstylename = this.GetAValueFromAnAttribute(listNode.ChildNodes.Item(0).ChildNodes.Item(0), "@style:style-name"); // } // catch(Exception ex) // { // paragraphstylename = "P1"; // } // } #endregion //Create a new List List list = new List(this._document, listNode); IContentCollection iColl = new IContentCollection(); //Revieve the ListStyle IStyle listStyle = this._document.Styles.GetStyleByName(list.StyleName); if(listStyle != null) list.Style = listStyle; foreach(XmlNode nodeChild in list.Node.ChildNodes) { IContent iContent = this.CreateContent(nodeChild); if(iContent != null) iColl.Add(iContent); } list.Node.InnerXml = ""; foreach(IContent iContent in iColl) list.Content.Add(iContent); return list; } catch(Exception ex) { AODLException exception = new AODLException("Exception while trying to create a List."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.Node = listNode; exception.OriginalException = ex; throw exception; } }
/// <summary> /// Creates the image map. /// </summary> /// <param name="imageMapNode">The image map node.</param> /// <returns></returns> private ImageMap CreateImageMap(XmlNode imageMapNode) { try { ImageMap imageMap = new ImageMap(this._document, imageMapNode); IContentCollection iCol = new IContentCollection(); if(imageMap.Node != null) foreach(XmlNode nodeChild in imageMap.Node.ChildNodes) { IContent iContent = this.CreateContent(nodeChild); if(iContent != null) iCol.Add(iContent); } imageMap.Node.InnerXml = ""; foreach(IContent iContent in iCol) imageMap.Content.Add(iContent); return imageMap; } catch(Exception ex) { AODLException exception = new AODLException("Exception while trying to create a ImageMap."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.Node = imageMapNode; exception.OriginalException = ex; throw exception; } }
/// <summary> /// Creates the draw text box. /// </summary> /// <param name="drawTextBoxNode">The draw text box node.</param> /// <returns></returns> private DrawTextBox CreateDrawTextBox(XmlNode drawTextBoxNode) { try { DrawTextBox drawTextBox = new DrawTextBox(this._document, drawTextBoxNode); IContentCollection iColl = new IContentCollection(); foreach(XmlNode nodeChild in drawTextBox.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 DrawTextBox."); warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); warning.Node = nodeChild; this.OnWarning(warning); } } } drawTextBox.Node.InnerXml = ""; foreach(IContent iContent in iColl) drawTextBox.Content.Add(iContent); return drawTextBox; } catch(Exception ex) { AODLException exception = new AODLException("Exception while trying to create a Graphic."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.Node = drawTextBoxNode; exception.OriginalException = ex; throw exception; } }
/// <summary> /// Creates the draw area rectangle. /// </summary> /// <param name="drawAreaRectangleNode">The draw area rectangle node.</param> /// <returns></returns> private DrawAreaRectangle CreateDrawAreaRectangle(XmlNode drawAreaRectangleNode) { try { DrawAreaRectangle dAreaRec = new DrawAreaRectangle(this._document, drawAreaRectangleNode); IContentCollection iCol = new IContentCollection(); if(dAreaRec.Node != null) foreach(XmlNode nodeChild in dAreaRec.Node.ChildNodes) { IContent iContent = this.CreateContent(nodeChild); if(iContent != null) iCol.Add(iContent); } dAreaRec.Node.InnerXml = ""; foreach(IContent iContent in iCol) dAreaRec.Content.Add(iContent); return dAreaRec; } catch(Exception ex) { AODLException exception = new AODLException("Exception while trying to create a DrawAreaRectangle."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.Node = drawAreaRectangleNode; exception.OriginalException = ex; throw exception; } }
/// <summary> /// Creates the frame. /// </summary> /// <param name="frameNode">The framenode.</param> /// <returns>The Frame object.</returns> public Frame CreateFrame(XmlNode frameNode) { try { #region Old code Todo: delete // Frame frame = null; // XmlNode graphicnode = null; // XmlNode graphicproperties = null; // string realgraphicname = ""; // string stylename = ""; // stylename = this.GetStyleName(framenode.OuterXml); // XmlNode stylenode = this.GetAStyleNode("style:style", stylename); // realgraphicname = this.GetAValueFromAnAttribute(framenode, "@draw:name"); // // //Console.WriteLine("frame: {0}", framenode.OuterXml); // // //Up to now, the only sopported, inner content of a frame is a graphic // if(framenode.ChildNodes.Count > 0) // if(framenode.ChildNodes.Item(0).OuterXml.StartsWith("<draw:image")) // graphicnode = framenode.ChildNodes.Item(0).CloneNode(true); // // //If not graphic, it could be text-box, ole or something else // //try to find graphic frame inside // if(graphicnode == null) // { // XmlNode child = framenode.SelectSingleNode("//draw:frame", this._document.NamespaceManager); // if(child != null) // frame = this.CreateFrame(child); // return frame; // } // // string graphicpath = this.GetAValueFromAnAttribute(graphicnode, "@xlink:href"); // // if(stylenode != null) // if(stylenode.ChildNodes.Count > 0) // if(stylenode.ChildNodes.Item(0).OuterXml.StartsWith("<style:graphic-properties")) // graphicproperties = stylenode.ChildNodes.Item(0).CloneNode(true); // // if(stylename.Length > 0 && stylenode != null && realgraphicname.Length > 0 // && graphicnode != null && graphicpath.Length > 0 && graphicproperties != null) // { // graphicpath = graphicpath.Replace("Pictures", ""); // graphicpath = OpenDocumentTextImporter.dirpics+graphicpath.Replace("/", @"\"); // // frame = new Frame(this._document, stylename, // realgraphicname, graphicpath); // // frame.Style.Node = stylenode; // frame.Graphic.Node = graphicnode; // ((FrameStyle)frame.Style).GraphicProperties.Node = graphicproperties; // // XmlNode nodeSize = framenode.SelectSingleNode("@svg:height", // this._document.NamespaceManager); // // if(nodeSize != null) // if(nodeSize.InnerText != null) // frame.GraphicHeight = nodeSize.InnerText; // // nodeSize = framenode.SelectSingleNode("@svg:width", // this._document.NamespaceManager); // // if(nodeSize != null) // if(nodeSize.InnerText != null) // frame.GraphicWidth = nodeSize.InnerText; // } #endregion //Create a new Frame Frame frame = new Frame(this._document, null); frame.Node = frameNode; IContentCollection iColl = new IContentCollection(); //Revieve the FrameStyle IStyle frameStyle = this._document.Styles.GetStyleByName(frame.StyleName); if(frameStyle != null) frame.Style = frameStyle; else { if(this.OnWarning != null) { AODLWarning warning = new AODLWarning("Couldn't recieve a FrameStyle."); warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); warning.Node = frameNode; this.OnWarning(warning); } } //Create the frame content foreach(XmlNode nodeChild in frame.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 frame."); warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); warning.Node = nodeChild; this.OnWarning(warning); } } } frame.Node.InnerXml = ""; foreach(IContent iContent in iColl) { frame.Content.Add(iContent); if(iContent is Graphic) { frame.LoadImageFromFile(((Graphic)iContent).GraphicRealPath); } } return frame; } catch(Exception ex) { AODLException exception = new AODLException("Exception while trying to create a Frame."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.Node = frameNode; exception.OriginalException = ex; throw exception; } }
/// <summary> /// Creates the event listeners. /// </summary> /// <param name="eventListenersNode">The event listeners node.</param> /// <returns></returns> public EventListeners CreateEventListeners(XmlNode eventListenersNode) { try { EventListeners eventList = new EventListeners(this._document, eventListenersNode); IContentCollection iCol = new IContentCollection(); if(eventList.Node != null) foreach(XmlNode nodeChild in eventList.Node.ChildNodes) { IContent iContent = this.CreateContent(nodeChild); if(iContent != null) iCol.Add(iContent); } eventList.Node.InnerXml = ""; foreach(IContent iContent in iCol) eventList.Content.Add(iContent); return eventList; } catch(Exception ex) { AODLException exception = new AODLException("Exception while trying to create a ImageMap."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.Node = eventListenersNode; exception.OriginalException = ex; throw exception; } }
/// <summary> /// Creates the table row. /// </summary> /// <param name="node">The node.</param> /// <returns></returns> private Row CreateTableRow(XmlNode node) { try { //Create a new Row Row row = new Row(this._document, node); IContentCollection iColl = new IContentCollection(); //Recieve RowStyle IStyle rowStyle = this._document.Styles.GetStyleByName(row.StyleName); if(rowStyle != null) row.Style = rowStyle; //No need for a warning //Create the cells foreach(XmlNode nodeChild in row.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 IContent from a table row."); warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); warning.Node = nodeChild; this.OnWarning(warning); } } } row.Node.InnerXml = ""; foreach(IContent iContent in iColl) { if(iContent is Cell) { ((Cell)iContent).Row = row; row.CellCollection.Add(iContent as Cell); } else if(iContent is CellSpan) { ((CellSpan)iContent).Row = row; row.CellSpanCollection.Add(iContent as CellSpan); } else { if(this.OnWarning != null) { AODLWarning warning = new AODLWarning("Couldn't create IContent from a row node. Content is unknown table row content!"); warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); warning.Node = iContent.Node; this.OnWarning(warning); } } } return row; } catch(Exception ex) { AODLException exception = new AODLException("Exception while trying to create a Table Row."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.Node = node; exception.OriginalException = ex; throw exception; } }
/// <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> /// Creates the table cell. /// </summary> /// <param name="node">The node.</param> /// <returns></returns> private Cell CreateTableCell(XmlNode node) { try { //Create a new Cel Cell cell = new Cell(this._document, node); IContentCollection iColl = new IContentCollection(); //Recieve CellStyle IStyle cellStyle = this._document.Styles.GetStyleByName(cell.StyleName); if(cellStyle != null) { int i=0; cell.Style = cellStyle; if(cellStyle.StyleName == "ce244") i=1; } //No need for a warning //Create the cells content foreach(XmlNode nodeChild in cell.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 IContent from a table cell."); warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); warning.Node = nodeChild; this.OnWarning(warning); } } } cell.Node.InnerXml = ""; foreach(IContent iContent in iColl) cell.Content.Add(iContent); return cell; } catch(Exception ex) { AODLException exception = new AODLException("Exception while trying to create a Table Row."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.Node = node; exception.OriginalException = ex; throw exception; } }