// /// <summary> // /// Cleans the up directory. // /// </summary> // /// <param name="directory">The directory.</param> // private void CleanUpDirectory(string directory) // { // string dirpics = Environment.CurrentDirectory+@"\PicturesRead\"; // // try // { // foreach(string d in this._directories) // Directory.Delete(directory+@"\"+d, true); // //// if(Directory.Exists(OpenDocumentTextImporter.dirpics)) //// Directory.Delete(OpenDocumentTextImporter.dirpics, true); // if(Directory.Exists(dirpics)) // Directory.Delete(dirpics, true); // // File.Delete(directory+DocumentMetadata.FileName); // File.Delete(directory+DocumentSetting.FileName); // File.Delete(directory+DocumentStyles.FileName); // File.Delete(directory+"content.xml"); // } // catch(Exception ex) // { // throw; // } // } #endregion /// <summary> /// Cleans the up read and write directories. /// </summary> internal static void CleanUpReadAndWriteDirectories() { try { if (Directory.Exists(OpenDocumentImporter.dir)) { Directory.Delete(OpenDocumentImporter.dir, true); } if (Directory.Exists(OpenDocumentImporter.dir)) { Directory.Delete(OpenDocumentImporter.dir, true); } if (Directory.Exists(OpenDocumentTextExporter.dir)) { Directory.Delete(OpenDocumentTextExporter.dir, true); } } catch (Exception ex) { AODLWarning aodlWarning = new AODLWarning("An exception ouccours while trying to remove the temp read directories."); aodlWarning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); aodlWarning.OriginalException = ex; throw ex; } }
/// <summary> /// Creates the formated text. /// </summary> /// <param name="document">The document.</param> /// <param name="node">The node.</param> /// <returns></returns> public FormatedText CreateFormatedText(IDocument document, XmlNode node) { try { //Create a new FormatedText object FormatedText formatedText = new FormatedText(document, node); ITextCollection iTextColl = new ITextCollection(); formatedText.Document = document; formatedText.Node = node; //Recieve a TextStyle IStyle textStyle = document.Styles.GetStyleByName(formatedText.StyleName); if (textStyle != null) { formatedText.Style = textStyle; } else { IStyle iStyle = document.CommonStyles.GetStyleByName(formatedText.StyleName); if (iStyle == null) { if (OnWarning != null) { AODLWarning warning = new AODLWarning("A TextStyle for the FormatedText object wasn't found."); warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); warning.Node = node; OnWarning(warning); } } } //Ceck for more IText object foreach (XmlNode iTextNode in node.ChildNodes) { IText iText = this.CreateTextObject(document, iTextNode.CloneNode(true)); if (iText != null) { iTextColl.Add(iText); } else { iTextColl.Add(new UnknownTextContent(document, iTextNode) as IText); } } formatedText.Node.InnerText = ""; foreach (IText iText in iTextColl) { formatedText.TextContent.Add(iText); } return(formatedText); } catch (Exception ex) { throw; } }
/// <summary> /// Gets the A global styl as HTML. /// </summary> /// <param name="document">The document.</param> /// <param name="styleName">Name of the style.</param> /// <returns></returns> public string GetAGlobalStylAsHtml(IDocument document, string styleName) { string style = "style=\""; try { if (document != null) { } } catch (Exception ex) { AODLException exception = new AODLException("Exception while trying to build a HTML style from a global style:" + styleName); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.OriginalException = ex; throw exception; } if (!style.EndsWith("; ")) { style = ""; } else { style += "\""; } return(style); }
/// <summary> /// Creates the bookmark. /// </summary> /// <param name="document">The document.</param> /// <param name="node">The node.</param> /// <param name="type">The type.</param> /// <returns></returns> public Bookmark CreateBookmark(IDocument document, XmlNode node, BookmarkType type) { try { Bookmark bookmark = null; if (type == BookmarkType.Standard) { bookmark = new Bookmark(document, BookmarkType.Standard, "noname"); } else if (type == BookmarkType.Start) { bookmark = new Bookmark(document, BookmarkType.Start, "noname"); } else { bookmark = new Bookmark(document, BookmarkType.End, "noname"); } bookmark.Node = node.CloneNode(true); return(bookmark); } catch (Exception ex) { AODLException exception = new AODLException("Exception while trying to create a Bookmark."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.Node = node; exception.OriginalException = ex; throw exception; } }
/// <summary> /// Creates the text sequence. /// </summary> /// <param name="document">The document.</param> /// <param name="node">The node.</param> /// <returns></returns> public TextSequence CreateTextSequence(IDocument document, XmlNode node) { try { TextSequence textSequence = new TextSequence(document, node); return(textSequence); } catch (Exception ex) { AODLException exception = new AODLException("Exception while trying to create a TextSequence."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.Node = node; exception.OriginalException = ex; throw exception; } }
/// <summary> /// Creates the tables. /// </summary> /// <param name="lines">The lines.</param> private void CreateTables(ArrayList lines) { string unicodeDelimiter = "\u00BF"; // turned question mark if (lines != null) { Table table = TableBuilder.CreateSpreadsheetTable( (SpreadsheetDocument)this._document, "Table1", "table1"); //First line must specify the used delimiter string delimiter = lines[0] as string; lines.RemoveAt(0); try { //Perform lines foreach (string line in lines) { string lineContent = line.Replace(delimiter, unicodeDelimiter); string[] cellContents = lineContent.Split(unicodeDelimiter.ToCharArray()); Row row = new Row(table); foreach (string cellContent in cellContents) { Cell cell = new Cell(table); Paragraph paragraph = ParagraphBuilder.CreateSpreadsheetParagraph(this._document); paragraph.TextContent.Add(new SimpleText(this._document, cellContent)); cell.Content.Add(paragraph); row.InsertCellAt(row.CellCollection.Count, cell); } table.RowCollection.Add(row); } } catch (Exception ex) { AODLException aodlExeception = new AODLException("Error while proccessing the csv file."); aodlExeception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); aodlExeception.OriginalException = ex; throw aodlExeception; } this._document.Content.Add(table); } }
/// <summary> /// Load internal and external importer. /// </summary> /// <returns></returns> private ArrayList LoadImporter() { try { ArrayList alImporter = new ArrayList(); alImporter.Add(new OpenDocumentImporter()); alImporter.Add(new PlainTextImporter()); alImporter.Add(new CsvImporter()); return(alImporter); } catch (Exception ex) { AODLException exception = new AODLException("Error while trying to load the importer."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.OriginalException = ex; throw exception; } }
/// <summary> /// Creates the footnote. /// </summary> /// <param name="document">The document.</param> /// <param name="node">The node.</param> /// <returns></returns> public Footnote CreateFootnote(IDocument document, XmlNode node) { try { Footnote fnote = new Footnote(document); fnote.Node = node.CloneNode(true); return(fnote); } catch (Exception ex) { AODLException exception = new AODLException("Exception while trying to create a Footnote."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.Node = node; exception.OriginalException = ex; throw exception; } }
/// <summary> /// Gets the heading style as HTML. /// </summary> /// <param name="header">The header.</param> /// <returns></returns> public string GetHeadingStyleAsHtml(Header header) { try { if (header != null) { if (header.StyleName != null) { if (header.StyleName.Equals(Headings.Heading_20_1.ToString())) { return(this.HeaderHtmlStyles[1]); } else if (header.StyleName.Equals(Headings.Heading_20_2.ToString())) { return(this.HeaderHtmlStyles[2]); } else { return(this.HeaderHtmlStyles[0]); } } } } catch (Exception ex) { AODLException exception = new AODLException("Exception while trying to build a HTML style string from a TextStyle."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.OriginalException = ex; if (header != null) { if (header.Node != null) { exception.Node = header.Node; } } throw exception; } return(this.HeaderHtmlStyles[0]); }
/// <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 tmpPath) { 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 cell style as HTML. /// </summary> /// <param name="cellStyle">The cell style.</param> /// <returns></returns> public string GetCellStyleAsHtml(CellStyle cellStyle) { string style = ""; try { if (cellStyle != null) { if (cellStyle.CellProperties != null) { if (cellStyle.CellProperties.BackgroundColor != null) { style += "bgcolor=\"" + cellStyle.CellProperties.BackgroundColor + "\" "; } } } } catch (Exception ex) { AODLException exception = new AODLException("Exception while trying to build a HTML style string from a CellStyle."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.OriginalException = ex; if (cellStyle != null) { if (cellStyle.Node != null) { exception.Node = cellStyle.Node; } } throw exception; } return(style); }
/// <summary> /// Creates the X link. /// </summary> /// <param name="document">The document.</param> /// <param name="node">The node.</param> /// <returns></returns> public XLink CreateXLink(IDocument document, XmlNode node) { try { XLink xlink = new XLink(document); xlink.Node = node.CloneNode(true); ITextCollection iTxtCol = new ITextCollection(); foreach (XmlNode nodeText in xlink.Node.ChildNodes) { IText iText = this.CreateTextObject(xlink.Document, nodeText); if (iText != null) { iTxtCol.Add(iText); } } xlink.Node.InnerXml = ""; foreach (IText iText in iTxtCol) { xlink.TextContent.Add(iText); } return(xlink); } catch (Exception ex) { AODLException exception = new AODLException("Exception while trying to create a XLink."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.Node = node; exception.OriginalException = ex; throw exception; } }
/// <summary> /// Gets the frame style as HTML. /// </summary> /// <param name="frame">The frame.</param> /// <returns></returns> public string GetFrameStyleAsHtml(Frame frame) { string style = ""; try { if (frame != null) { string width = frame.SvgWidth; if (width != null) { if (width.EndsWith("cm")) { width = width.Replace("cm", ""); } else if (width.EndsWith("in")) { width = width.Replace("in", ""); } } string height = frame.SvgHeight; if (height != null) { if (height.EndsWith("cm")) { height = height.Replace("cm", ""); } else if (height.EndsWith("in")) { height = height.Replace("in", ""); } } try { if (width != null) { double wd = Convert.ToDouble(width, System.Globalization.NumberFormatInfo.InvariantInfo); string wdPx = ""; if (frame.SvgWidth.EndsWith("cm")) { wdPx = SizeConverter.CmToPixelAsString(wd); } else if (frame.SvgWidth.EndsWith("in")) { wdPx = SizeConverter.InchToPixelAsString(wd); } if (wdPx.Length > 0) { style = "width=\"" + wdPx + "\" "; } } if (height != null) { double wd = Convert.ToDouble(height, System.Globalization.NumberFormatInfo.InvariantInfo); string wdPx = ""; if (frame.SvgHeight.EndsWith("cm")) { wdPx = SizeConverter.CmToPixelAsString(wd); } else if (frame.SvgHeight.EndsWith("in")) { wdPx = SizeConverter.InchToPixelAsString(wd); } if (wdPx.Length > 0) { style = "height=\"" + wdPx + "\" "; } } } catch (Exception ex) { if (this.OnWarning != null) { AODLWarning warning = new AODLWarning("Exception while trying to build a graphic width & height.: " + frame.SvgWidth + "/" + frame.SvgHeight); warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); warning.OriginalException = ex; OnWarning(warning); } } } } catch (Exception ex) { AODLException exception = new AODLException("Exception while trying to build a HTML style string from a FrameStyle."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.OriginalException = ex; if (frame != null) { if (frame.Node != null) { exception.Node = frame.Node; } } throw exception; } return(style); }
/// <summary> /// Gets the paragraph style as HTML. /// </summary> /// <param name="paragraphStyle">The paragraph style.</param> /// <returns></returns> public string GetParagraphStyleAsHtml(ParagraphStyle paragraphStyle) { string style = "style=\""; try { if (paragraphStyle != null) { if (paragraphStyle.ParagraphProperties != null) { if (paragraphStyle.ParagraphProperties.Alignment != null && paragraphStyle.ParagraphProperties.Alignment != "start") { style += "text-align: " + paragraphStyle.ParagraphProperties.Alignment + "; "; } if (paragraphStyle.ParagraphProperties.MarginLeft != null) { style += "text-indent: " + paragraphStyle.ParagraphProperties.MarginLeft + "; "; } if (paragraphStyle.ParagraphProperties.LineSpacing != null) { style += "line-height: " + paragraphStyle.ParagraphProperties.LineSpacing + "; "; } if (paragraphStyle.ParagraphProperties.Border != null && paragraphStyle.ParagraphProperties.Padding == null) { style += "border-width:1px; border-style:solid; padding: 0.5cm; "; } if (paragraphStyle.ParagraphProperties.Border != null && paragraphStyle.ParagraphProperties.Padding != null) { style += "border-width:1px; border-style:solid; padding:" + paragraphStyle.ParagraphProperties.Padding + "; "; } if (paragraphStyle.ParagraphProperties.BackgroundColor != null) { style += "background-color: " + paragraphStyle.ParagraphProperties.BackgroundColor + "; "; } } } } catch (Exception ex) { AODLException exception = new AODLException("Exception while trying to build a HTML style string from a ParagraphStyle."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.OriginalException = ex; if (paragraphStyle != null) { if (paragraphStyle.Node != null) { exception.Node = paragraphStyle.Node; } } throw exception; } if (!style.EndsWith("; ")) { style = ""; } else { style += "\""; } return(style); }
/// <summary> /// Gets the text style as HTML. /// </summary> /// <param name="textStyle">The text style.</param> /// <returns></returns> public string GetTextStyleAsHtml(TextProperties textStyle) { string style = "style=\""; try { if (textStyle != null) { if (textStyle.Italic != null) { if (textStyle.Italic != "normal") { style += "font-style: italic; "; } } if (textStyle.Bold != null) { style += "font-weight: " + textStyle.Bold + "; "; } if (textStyle.Underline != null) { style += "text-decoration: underline; "; } if (textStyle.TextLineThrough != null) { style += "text-decoration: line-through; "; } if (textStyle.FontName != null) { style += "font-family: " + FontFamilies.HtmlFont(textStyle.FontName) + "; "; } if (textStyle.FontSize != null) { style += "font-size: " + FontFamilies.PtToPx(textStyle.FontSize) + "; "; } if (textStyle.FontColor != null) { style += "color: " + textStyle.FontColor + "; "; } if (textStyle.BackgroundColor != null) { style += "background-color: " + textStyle.BackgroundColor + "; "; } } } catch (Exception ex) { AODLException exception = new AODLException("Exception while trying to build a HTML style string from a TextStyle."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.OriginalException = ex; if (textStyle != null) { if (textStyle.Node != null) { exception.Node = textStyle.Node; } } throw exception; } if (!style.EndsWith("; ")) { style = ""; } else { style += "\""; } return(style); }
/// <summary> /// Gets the table style as HTML. /// </summary> /// <param name="tableStyle">The table style.</param> /// <returns></returns> public string GetTableStyleAsHtml(TableStyle tableStyle) { string style = ""; try { if (tableStyle != null) { if (tableStyle.TableProperties != null) { if (tableStyle.TableProperties.Width != null) { string width = tableStyle.TableProperties.Width; if (width.EndsWith("cm")) { width = width.Replace("cm", ""); } else if (width.EndsWith("in")) { width = width.Replace("in", ""); } try { double wd = Convert.ToDouble(width, System.Globalization.NumberFormatInfo.InvariantInfo); string wdPx = ""; if (tableStyle.TableProperties.Width.EndsWith("cm")) { wdPx = SizeConverter.CmToPixelAsString(wd); } else if (tableStyle.TableProperties.Width.EndsWith("in")) { wdPx = SizeConverter.InchToPixelAsString(wd); } if (wdPx.Length > 0) { style = "width=\"" + wdPx.Replace("px", "") + "\" "; } } catch (Exception ex) { if (this.OnWarning != null) { AODLWarning warning = new AODLWarning("Exception while trying to build a table width width.: " + tableStyle.TableProperties.Width); warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); warning.OriginalException = ex; OnWarning(warning); } } } if (tableStyle.TableProperties.Align != null) { if (tableStyle.TableProperties.Align != "margin") { if (tableStyle.TableProperties.Align == "center") { style += "align=\"center\" "; } else if (tableStyle.TableProperties.Align == "right") { style += "align=\"center\" "; //Because display prob by some browser } } } } } } catch (Exception ex) { AODLException exception = new AODLException("Exception while trying to build a HTML style string from a TableStyle."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.OriginalException = ex; if (tableStyle != null) { if (tableStyle.Node != null) { exception.Node = tableStyle.Node; } } throw exception; } return(style); }
/// <summary> /// Gets the column style as HTML. /// </summary> /// <param name="columnStyle">The column style.</param> /// <returns></returns> public string GetColumnStyleAsHtml(ColumnStyle columnStyle) { string style = ""; try { if (columnStyle != null) { if (columnStyle.ColumnProperties != null) { if (columnStyle.ColumnProperties.Width != null) { string width = columnStyle.ColumnProperties.Width; if (width.EndsWith("cm")) { width = width.Replace("cm", ""); } else if (width.EndsWith("in")) { width = width.Replace("in", ""); } try { double wd = Convert.ToDouble(width, System.Globalization.NumberFormatInfo.InvariantInfo); string wdPx = ""; if (columnStyle.ColumnProperties.Width.EndsWith("cm")) { wdPx = SizeConverter.CmToPixelAsString(wd); } else if (columnStyle.ColumnProperties.Width.EndsWith("in")) { wdPx = SizeConverter.InchToPixelAsString(wd); } if (wdPx.Length > 0) { style = "width=\"" + wdPx + "\" "; } } catch (Exception ex) { if (this.OnWarning != null) { AODLWarning warning = new AODLWarning("Exception while trying to build a column width.: " + columnStyle.ColumnProperties.Width); warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); warning.OriginalException = ex; OnWarning(warning); } } } } } } catch (Exception ex) { AODLException exception = new AODLException("Exception while trying to build a HTML style string from a CellStyle."); exception.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); exception.OriginalException = ex; if (columnStyle != null) { if (columnStyle.Node != null) { exception.Node = columnStyle.Node; } } throw exception; } return(style); }