/// <summary> /// Gets the first importer that match the parameter criteria. /// </summary> /// <param name="documentType">Type of the document.</param> /// <param name="loadPath">The save path.</param> /// <returns></returns> public IImporter GetFirstImporter(DocumentTypes documentType, string loadPath) { string targetExtension = ExportHandler.GetExtension(loadPath); foreach(IImporter iImporter in this.LoadImporter()) { foreach(DocumentSupportInfo documentSupportInfo in iImporter.DocumentSupportInfos) if(documentSupportInfo.Extension.ToLower().Equals(targetExtension.ToLower())) if(documentSupportInfo.DocumentType == documentType) return iImporter; } AODLException exception = new AODLException("No importer available for type "+documentType.ToString()+" and extension "+targetExtension); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); throw exception; }
/// <summary> /// Gets the I text collection as HTML. /// </summary> /// <param name="iTextCollection">The i text collection.</param> /// <param name="paragraphStyle">The paragraph style.</param> /// <returns></returns> public string GetITextCollectionAsHtml(ITextCollection iTextCollection, ParagraphStyle paragraphStyle) { string html = ""; int tabStopCnt = 0; try { if(iTextCollection != null) { foreach(IText iText in iTextCollection) { //determine type if(iText is SimpleText) { string textContent = iText.Node.InnerText; html += this.ReplaceControlNodes(textContent); } else if(iText is FormatedText) html += this.GetFormatedTextAsHtml(iText as FormatedText); else if(iText is WhiteSpace) html += this.GetWhiteSpacesAsHtml(iText as WhiteSpace); else if(iText is TabStop) { html += this.GetTabStopAsHtml(iText as TabStop, tabStopCnt, html, paragraphStyle); tabStopCnt++; } else if(iText is XLink) html += this.GetXLinkAsHtml(iText as XLink); else if(iText is LineBreak) html += this.GetLineBreakAsHtml(); else if(iText is UnknownTextContent) html += this.GetUnknowTextContentAsHtml(iText as UnknownTextContent); else //this should never happens, because all not implemented elements //are unknwon content if(OnWarning != null) { AODLWarning warning = new AODLWarning("Finding total unknown text content. This should (could) never happen."); warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); OnWarning(warning); } } } } catch(Exception ex) { AODLException exception = new AODLException("Exception while trying to build a HTML string from an ITextCollection."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.OriginalException = ex; throw exception; } return html; }
/// <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. /// </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 graphic. /// </summary> /// <param name="graphicnode">The graphicnode.</param> /// <returns>The Graphic object</returns> private Graphic CreateGraphic(XmlNode graphicnode) { try { Graphic graphic = new Graphic(this._document, null, null); graphic.Node = graphicnode; graphic.GraphicRealPath = Path.Combine(OpenDocumentImporter.dir,graphic.HRef); return graphic; } catch(Exception ex) { AODLException exception = new AODLException("Exception while trying to create a Graphic."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.Node = graphicnode; 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 paragraph. /// </summary> /// <param name="paragraphNode">The paragraph node.</param> public Paragraph CreateParagraph(XmlNode paragraphNode) { try { //Create a new Paragraph Paragraph paragraph = new Paragraph(paragraphNode, this._document); //Recieve the ParagraphStyle IStyle paragraphStyle = this._document.Styles.GetStyleByName(paragraph.StyleName); if(paragraphStyle != null) { paragraph.Style = paragraphStyle; } else if(paragraph.StyleName != "Standard" && paragraph.StyleName != "Table_20_Contents" && paragraph.StyleName != "Text_20_body" && this._document is TextDocument) { //Check if it's a user defined style IStyle commonStyle = this._document.CommonStyles.GetStyleByName(paragraph.StyleName); if(commonStyle == null) { if(this.OnWarning != null) { AODLWarning warning = new AODLWarning("A ParagraphStyle wasn't found."); warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); warning.Node = paragraphNode; this.OnWarning(warning); } #region Old code Todo: delete // XmlNode styleNode = this._document.XmlDoc.SelectSingleNode( // "/office:document-content/office:automatic-styles/style:style[@style:name='"+p.Stylename+"']", // this._document.NamespaceManager); // // XmlNode styles = this._document.XmlDoc.SelectSingleNode( // "/office:document-content/office:automatic-styles", // this._document.NamespaceManager); // // if(styleNode != null) // { // ParagraphStyle pstyle = new ParagraphStyle(p, styleNode); // // XmlNode propertieNode = styleNode.SelectSingleNode("style:paragraph-properties", // this._document.NamespaceManager); // // XmlNode txtpropertieNode = styleNode.SelectSingleNode("style:text-properties", // this._document.NamespaceManager); // // ParagraphProperties pp = null; // // XmlNode tabstyles = null; // // if(propertieNode != null) // { // tabstyles = styleNode.SelectSingleNode("style:tab-stops", // this._document.NamespaceManager); // pp = new ParagraphProperties(pstyle, propertieNode); // } // else // pp = new ParagraphProperties(pstyle); // // pstyle.Properties = pp; // if(tabstyles != null) // pstyle.Properties.TabStopStyleCollection = this.GetTabStopStyles(tabstyles); // p.Style = pstyle; // // if(txtpropertieNode != null) // { // TextProperties tt = new TextProperties(p.Style); // tt.Node = txtpropertieNode; // ((ParagraphStyle)p.Style).Textproperties = tt; // } // } #endregion } } return this.ReadParagraphTextContent(paragraph); } catch(Exception ex) { AODLException exception = new AODLException("Exception while trying to create a Paragraph."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.Node = paragraphNode; exception.OriginalException = ex; throw exception; } }
/// <summary> /// Creates the header. /// </summary> /// <param name="headernode">The headernode.</param> /// <returns></returns> public Header CreateHeader(XmlNode headernode) { try { #region Old code Todo: delete // XmlNode node = headernode.SelectSingleNode("//@text:style-name", this._document.NamespaceManager); // if(node != null) // { // if(!node.InnerText.StartsWith("Heading")) // { // //Check if a the referenced paragraphstyle reference a heading as parentstyle // XmlNode stylenode = this._document.XmlDoc.SelectSingleNode("//style:style[@style:name='"+node.InnerText+"']", this._document.NamespaceManager); // if(stylenode != null) // { // XmlNode parentstyle = stylenode.SelectSingleNode("@style:parent-style-name", // this._document.NamespaceManager); // if(parentstyle != null) // if(parentstyle.InnerText.StartsWith("Heading")) // headernode.SelectSingleNode("@text:style-name", // this._document.NamespaceManager).InnerText = parentstyle.InnerText; // } // } // } #endregion if(this._debugMode) this.LogNode(headernode, "Log header node before"); //Create a new Header Header header = new Header(headernode, this._document); //Create a ITextCollection ITextCollection textColl = new ITextCollection(); //Recieve the HeaderStyle IStyle headerStyle = this._document.Styles.GetStyleByName(header.StyleName); if(headerStyle != null) header.Style = headerStyle; //Create the IText content foreach(XmlNode nodeChild in header.Node.ChildNodes) { TextContentProcessor tcp = new TextContentProcessor(); IText iText = tcp.CreateTextObject(this._document, nodeChild); if(iText != null) textColl.Add(iText); else { if(this.OnWarning != null) { AODLWarning warning = new AODLWarning("Couldn't create IText object from header child node!."); warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); warning.Node = nodeChild; this.OnWarning(warning); } } } //Remove all header.Node.InnerXml = ""; foreach(IText iText in textColl) { if(this._debugMode) this.LogNode(iText.Node, "Log IText node read from header"); header.TextContent.Add(iText); } return header; } catch(Exception ex) { AODLException exception = new AODLException("Exception while trying to create a Header."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.Node = headernode; exception.OriginalException = ex; throw exception; } return null; }
/// <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; } }
/// <summary> /// Gets the table as HTML. /// </summary> /// <param name="table">The table.</param> /// <returns></returns> public string GetTableAsHtml(Table table) { //TODO: Implement table border algo string html = "<table border=\"1\" "; try { if(table != null) { string style = this.HTMLStyleBuilder.GetTableStyleAsHtml(table.TableStyle); if(style.Length > 0) { html += style; html += ">\n"; } if(table.RowCollection != null) foreach(Row row in table.RowCollection) html += this.GetRowAsHtml(row); } } catch(Exception ex) { AODLException exception = new AODLException("Exception while trying to build a HTML string from a Table object."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.OriginalException = ex; throw exception; } if(!html.Equals("<table border=\"1\" ")) html += "</table>\n"; else html = ""; return html; }
/// <summary> /// Gets the row as HTML. /// </summary> /// <param name="row">The row.</param> /// <returns></returns> public string GetRowAsHtml(Row row) { string html = "<tr>\n"; try { if(row != null) { if(row.CellCollection != null) { foreach(Cell cell in row.CellCollection) html += this.GetCellAsHtml(cell); } } } catch(Exception ex) { AODLException exception = new AODLException("Exception while trying to build a HTML string from a Row object."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.OriginalException = ex; throw exception; } if(!html.Equals("<tr>\n")) html += "</tr>\n"; else html = ""; return html; }
/// <summary> /// Gets the paragraph as HTML. /// </summary> /// <param name="paragraph">The paragraph.</param> /// <returns></returns> public string GetParagraphAsHtml(Paragraph paragraph) { string html = "<p "; try { if(paragraph != null) { if(paragraph.StyleName != null) if(paragraph.StyleName != "Text_20_body" && paragraph.StyleName != "standard" && paragraph.StyleName != "Table_20_body") { string style = this.HTMLStyleBuilder.GetParagraphStyleAsHtml(paragraph.ParagraphStyle); if(style.Length > 0) html += style;//+">\n"; else { //Check against a possible common style IStyle iStyle = paragraph.Document.CommonStyles.GetStyleByName(paragraph.StyleName); string commonStyle = ""; if(iStyle != null && iStyle is ParagraphStyle) { commonStyle = this.HTMLStyleBuilder.GetParagraphStyleAsHtml(iStyle as ParagraphStyle); if(commonStyle.Length > 0) html += commonStyle; else html = html.Replace(" ", ""); } else html = html.Replace(" ", ""); } } else { html = html.Replace(" ", ""); } html += ">\n"; string txtstyle = "<span "; bool useTextStyle = false; if(paragraph.ParagraphStyle != null) { string tstyle = this.HTMLStyleBuilder.GetTextStyleAsHtml(paragraph.ParagraphStyle.TextProperties); if(txtstyle.Length > 0) { txtstyle += tstyle+">\n"; html += txtstyle; useTextStyle = true; } } else { //Check again a possible common style string commonstyle = ""; IStyle iStyle = paragraph.Document.CommonStyles.GetStyleByName(paragraph.StyleName); if(iStyle != null && iStyle is ParagraphStyle) { commonstyle = this.HTMLStyleBuilder.GetTextStyleAsHtml(((ParagraphStyle)iStyle).TextProperties); if(commonstyle.Length > 0) { txtstyle += commonstyle+">\n"; html += txtstyle; useTextStyle = true; } } } string mixedCont = this.GetMixedContentAsHTML(paragraph.MixedContent, paragraph.ParagraphStyle); if(mixedCont.Length > 0) html += mixedCont+" "; else html += " "; if(!html.Equals("<p ")) if(useTextStyle) html += "</span>\n</p>\n"; else html += "</p>\n"; else html = ""; if(html.Equals("<p >")) html = ""; } } catch(Exception ex) { AODLException exception = new AODLException("Exception while trying to build a HTML string from a Heading object."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.OriginalException = ex; throw exception; } return html; }
/// <summary> /// Gets the mixed content as HTML. /// </summary> /// <param name="mixedContent">ArrayList of objects. The objects could be /// IContent or IText.</param> /// <param name="paragraphStyle">The paragraph style.</param> /// <returns></returns> public string GetMixedContentAsHTML(ArrayList mixedContent, ParagraphStyle paragraphStyle) { string html = ""; int tabStopCnt = 0; try { if(mixedContent != null) { foreach(object ob in mixedContent) { //determine type text content types if(ob is SimpleText) { html += this.ReplaceControlNodes(((IText)ob).Node.InnerText); } else if(ob is FormatedText) html += this.GetFormatedTextAsHtml(ob as FormatedText); else if(ob is WhiteSpace) html += this.GetWhiteSpacesAsHtml(ob as WhiteSpace); else if(ob is TabStop) { html += this.GetTabStopAsHtml(ob as TabStop, tabStopCnt, html, paragraphStyle); tabStopCnt++; } else if(ob is XLink) html += this.GetXLinkAsHtml(ob as XLink); else if(ob is LineBreak) html += this.GetLineBreakAsHtml(); else if(ob is UnknownTextContent) html += this.GetUnknowTextContentAsHtml(ob as UnknownTextContent); //determine type else if(ob is Table) html += this.GetTableAsHtml(ob as Table); else if(ob is Paragraph) html += this.GetParagraphAsHtml(ob as Paragraph); else if(ob is List) html += this.GetListAsHtml(ob as List); else if(ob is Frame) html += this.GetDrawFrameAsHtml(ob as Frame); else if(ob is Graphic) html += this.GetGraphicAsHtml(ob as Graphic); else if(ob is ListItem) html += this.GetListItemAsHtml(ob as ListItem); else if(ob is Header) html += this.GetHeadingAsHtml(ob as Header); else if(ob is UnknownContent) html += this.GetUnknowContentAsHtml(ob as UnknownContent); else //this should never happens, because all not implemented elements //are unknwon content if(OnWarning != null) { AODLWarning warning = new AODLWarning("Finding total unknown content in mixed content. This should (could) never happen."); warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); OnWarning(warning); } } } } catch(Exception ex) { AODLException exception = new AODLException("Exception while trying to build a HTML string from an ITextCollection."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.OriginalException = ex; throw exception; } return html; }
/// <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; }
/// <summary> /// Gets the list as HTML. /// </summary> /// <param name="list">The list.</param> /// <returns></returns> public string GetListAsHtml(List list) { string html = "<"; try { if(list != null) { if(list.ListType == ListStyles.Number) html += "ol>\n"; else html += "ul>\n"; if(list.Content != null) { foreach(IContent iContent in list.Content) html += this.GetIContentCollectionAsHtml(list.Content); } } } catch(Exception ex) { AODLException exception = new AODLException("Exception while trying to build a HTML string from a List object."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.OriginalException = ex; throw exception; } if(html.StartsWith("<ol")) html += "</ol>\n"; else if(html.StartsWith("<ul")) html += "</ul>\n"; else html = ""; return html; }
/// <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 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 table cell span. /// </summary> /// <param name="node">The node.</param> /// <returns></returns> private CellSpan CreateTableCellSpan(XmlNode node) { try { //Create a new CellSpan CellSpan cellSpan = new CellSpan(this._document, node); //No need for a warnings or styles return cellSpan; } catch(Exception ex) { AODLException exception = new AODLException("Exception while trying to create a Table CellSpan."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.Node = node; exception.OriginalException = ex; throw exception; } }
/// <summary> /// Creates the content. /// </summary> /// <param name="node">The node.</param> public void CreateMainContent(XmlNode node) { try { foreach(XmlNode nodeChild in node.ChildNodes) { IContent iContent = this.CreateContent(nodeChild.CloneNode(true)); if(iContent != null) this._document.Content.Add(iContent); else { if(this.OnWarning != null) { AODLWarning warning = new AODLWarning("A couldn't create any content from an an first level node!."); warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); warning.Node = nodeChild; this.OnWarning(warning); } } } } catch(Exception ex) { AODLException exception = new AODLException("Exception while processing a content node."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.Node = node; exception.OriginalException = ex; throw exception; } }
/// <summary> /// Creates the table column. /// </summary> /// <param name="node">The node.</param> /// <returns></returns> private Column CreateTableColumn(XmlNode node) { try { //Create a new Row Column column = new Column(this._document, node); //Recieve RowStyle IStyle columnStyle = this._document.Styles.GetStyleByName(column.StyleName); if(columnStyle != null) column.Style = columnStyle; //No need for a warning return column; } catch(Exception ex) { AODLException exception = new AODLException("Exception while trying to create a Table Column."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.Node = node; exception.OriginalException = ex; throw exception; } }
/// <summary> /// Reads the content nodes. /// </summary> public void ReadContentNodes() { try { // this._document.XmlDoc = new XmlDocument(); // this._document.XmlDoc.Load(contentFile); XmlNode node = null; if(this._document is TextDocument) node = this._document.XmlDoc.SelectSingleNode(TextDocumentHelper.OfficeTextPath, this._document.NamespaceManager); else if(this._document is SpreadsheetDocument) node = this._document.XmlDoc.SelectSingleNode( "/office:document-content/office:body/office:spreadsheet", this._document.NamespaceManager); if(node != null) { this.CreateMainContent(node); } else { AODLException exception = new AODLException("Unknow content type."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); throw exception; } //Remove all existing content will be created new node.RemoveAll(); } catch(Exception ex) { AODLException exception = new AODLException("Error while trying to load the content file!"); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); 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 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 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 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> /// Reads the content of the paragraph text. /// </summary> /// <param name="paragraph">The paragraph.</param> /// <returns></returns> private Paragraph ReadParagraphTextContent(Paragraph paragraph) { try { if(this._debugMode) this.LogNode(paragraph.Node, "Log Paragraph node before"); ArrayList mixedContent = new ArrayList(); foreach(XmlNode nodeChild in paragraph.Node.ChildNodes) { //Check for IText content first TextContentProcessor tcp = new TextContentProcessor(); IText iText = tcp.CreateTextObject(this._document, nodeChild.CloneNode(true)); if(iText != null) mixedContent.Add(iText); else { //Check against IContent IContent iContent = this.CreateContent(nodeChild); if(iContent != null) mixedContent.Add(iContent); } } //Remove all paragraph.Node.InnerXml = ""; foreach(Object ob in mixedContent) { if(ob is IText) { if(this._debugMode) this.LogNode(((IText)ob).Node, "Log IText node read"); paragraph.TextContent.Add(ob as IText); } else if(ob is IContent) { if(this._debugMode) this.LogNode(((IContent)ob).Node, "Log IContent node read"); paragraph.Content.Add(ob as IContent); } else { if(this.OnWarning != null) { AODLWarning warning = new AODLWarning("Couldn't determine the type of a paragraph child node!."); warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); warning.Node = paragraph.Node; this.OnWarning(warning); } } } if(this._debugMode) this.LogNode(paragraph.Node, "Log Paragraph node after"); return paragraph; } catch(Exception ex) { AODLException exception = new AODLException("Exception while trying to create the Paragraph content."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.Node = paragraph.Node; 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> /// Gets the content. /// </summary> /// <param name="node">The node.</param> /// <returns></returns> public IContent CreateContent(XmlNode node) { try { switch(node.Name) { case "text:p": return CreateParagraph(node.CloneNode(true)); case "text:list": return CreateList(node.CloneNode(true)); case "text:list-item": return CreateListItem(node.CloneNode(true)); case "table:table": return CreateTable(node.CloneNode(true)); case "table:table-column": return CreateTableColumn(node.CloneNode(true)); case "table:table-row": return CreateTableRow(node.CloneNode(true)); case "table:table-header-rows": return CreateTableHeaderRow(node.CloneNode(true)); case "table:table-cell": return CreateTableCell(node.CloneNode(true)); case "table:covered-table-cell": return CreateTableCellSpan(node.CloneNode(true)); case "text:h": return CreateHeader(node.CloneNode(true)); case "text:table-of-content": //Possible? return CreateTableOfContents(node.CloneNode(true)); case "draw:frame": return CreateFrame(node.CloneNode(true)); case "draw:text-box": return CreateDrawTextBox(node.CloneNode(true)); case "draw:image": return CreateGraphic(node.CloneNode(true)); case "draw:area-rectangle": return CreateDrawAreaRectangle(node.CloneNode(true)); case "draw:area-circle": return CreateDrawAreaCircle(node.CloneNode(true)); case "draw:image-map": return CreateImageMap(node.CloneNode(true)); case "office:event-listeners": return CreateEventListeners(node.CloneNode(true)); case "script:event-listener": return CreateEventListeners(node.CloneNode(true)); default: return new UnknownContent(this._document, node.CloneNode(true)); } } catch(Exception ex) { AODLException exception = new AODLException("Exception while processing a content node."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.Node = node; exception.OriginalException = ex; throw exception; } }
/// <summary> /// Load internal and external exporter. /// </summary> /// <returns></returns> private ArrayList LoadExporter() { try { ArrayList alExporter = new ArrayList(); alExporter.Add(new OpenDocumentTextExporter()); alExporter.Add(new OpenDocumentHtmlExporter()); return alExporter; } catch(Exception ex) { AODLException exception = new AODLException("Error while trying to load the exporter."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.OriginalException = ex; throw exception; } }
/// <summary> /// Creates the event listener. /// </summary> /// <param name="eventListenerNode">The event listener node.</param> /// <returns></returns> public EventListener CreateEventListener(XmlNode eventListenerNode) { try { EventListener eventListener = new EventListener(this._document, eventListenerNode); return eventListener; } catch(Exception ex) { AODLException exception = new AODLException("Exception while trying to create a EventListener."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.Node = eventListenerNode; exception.OriginalException = ex; throw exception; } }