/// <summary> /// Create a deep clone of this XLink object. /// </summary> /// <remarks>A possible Attached Style wouldn't be cloned!</remarks> /// <returns> /// A clone of this object. /// </returns> public object Clone() { XLink xLinkClone = null; if (Document != null && Node != null) { TextContentProcessor tcp = new TextContentProcessor(); xLinkClone = tcp.CreateXLink(Document, new XElement(Node)); } return(xLinkClone); }
/// <summary> /// Create a deep clone of this XLink object. /// </summary> /// <remarks>A possible Attached Style wouldn't be cloned!</remarks> /// <returns> /// A clone of this object. /// </returns> public object Clone() { XLink xLinkClone = null; if (this.Document != null && this.Node != null) { TextContentProcessor tcp = new TextContentProcessor(); xLinkClone = tcp.CreateXLink(this.Document, this.Node.CloneNode(true)); } return(xLinkClone); }
void Example12() { //Create new TextDocument TextDocument document = new TextDocument(); document.New(); //Create a new Paragraph Paragraph para = new Paragraph(document, "P1"); //Create some simple text SimpleText stext = new SimpleText(document, "Some simple text "); //Create a XLink XLink xlink = new XLink(document, "http://www.OpenOffice.org", "OpenOffice.org"); //Add the textcontent para.TextContent.Add(stext); para.TextContent.Add(xlink); //Add paragraph to the document content document.Content.Add(para); //Save document.SaveTo("example12_XLink.odt"); }
/// <summary> /// Gets the anchor link. /// </summary> /// <param name="outlineLinkTarget">The outline link target.</param> /// <param name="xLink">The x link.</param> /// <returns></returns> private string GetAnchorLink(string outlineLinkTarget, XLink xLink) { try { string replaceMent = "|outline"; outlineLinkTarget = outlineLinkTarget.Replace(replaceMent, ""); //Get only the last part of the target and try to match a header //beginning afer char index 6 should be a good decision //TODO: Build the outline numbering via the outline element from the global styles outlineLinkTarget = outlineLinkTarget.Substring(6); if (xLink.Document != null) if (xLink.Document.Content != null) foreach(IContent iContent in xLink.Document.Content) if (iContent is Header) if (((Header)iContent).OutLineLevel != null) { string headerText = ""; //Get text only foreach(IText iText in ((Header)iContent).TextContent) if (iText.Text != null) headerText += iText.Text; if (headerText.EndsWith(outlineLinkTarget)) return headerText; } } catch(Exception ex) { if (OnWarning != null) { AODLWarning warning = new AODLWarning("Exception while trying to get an anchor string from a XLink object.", ex); //warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); //warning.OriginalException = ex; warning.Node = xLink.Node; OnWarning(warning); } } return null; }
/// <summary> /// Gets the X link as HTML. /// </summary> /// <param name="xLink">The x link.</param> /// <returns></returns> public string GetXLinkAsHtml(XLink xLink) { string html = "<a "; try { if (xLink != null) { if (xLink.Href != null) if (xLink.Href.ToLower().IndexOf("|outline") == -1) html += "href=\""+xLink.Href+"\" "; else { string anchor = this.GetAnchorLink(xLink.Href, xLink); if (anchor != null) html += "href=\"#"+anchor+"\" "; else html += "href=\""+xLink.Href+"\" "; } if (xLink.TargetFrameName != null) html += "target=\""+xLink.TargetFrameName+"\">\n"; if (!html.EndsWith(">\n")) html += ">\n"; string textContent = this.GetITextCollectionAsHtml(xLink.TextContent, null); if (textContent.Length > 0) html += textContent; } } catch(Exception ex) { throw new AODLException("Exception while trying to build a HTML string from a XLink object.", ex); } if (!html.Equals("<a ")) html += "</a>\n"; else html = ""; return html; }
public void XLinkTest() { //Create new TextDocument var document = new TextDocument(); document.New(); //Create a new Paragraph var para = new Paragraph(document, "P1"); //Create some simple text var stext = new SimpleText(document, "Some simple text "); //Create a XLink var xlink = new XLink(document, "http://www.sourceforge.net", "Sourceforge"); //Add the textcontent para.TextContent.Add(stext); para.TextContent.Add(xlink); //Add paragraph to the document content document.Content.Add(para); //Save document.SaveTo(AARunMeFirstAndOnce.outPutFolder+"XLink.odt"); }
/// <summary> /// Insert the given text as an Table of contents entry. /// e.g. You just insert a Headline 1. My headline to /// the document and want this text also as an Table of /// contents entry, so you can simply add the text using /// this method. /// </summary> /// <param name="textEntry">The text entry.</param> /// <param name="outLineLevel">The outline level possible 1-10.</param> public void InsertEntry(string textEntry, int outLineLevel) { Paragraph paragraph = new Paragraph( ((TextDocument)this.Document), "P1_Toc_Entry"+outLineLevel.ToString()); ((ParagraphStyle)paragraph.Style).ParentStyle = this._contentStyleName+outLineLevel.ToString(); if(this.UseHyperlinks) { int firstWhiteSpace = textEntry.IndexOf(" "); System.Text.StringBuilder sb = new System.Text.StringBuilder(textEntry); sb = sb.Remove(firstWhiteSpace, 1); string link = "#"+sb.ToString()+"|outline"; XLink xlink = new XLink(this.Document, link, textEntry); xlink.XLinkType = "simple"; paragraph.TextContent.Add(xlink); paragraph.TextContent.Add(new TabStop(this.Document)); paragraph.TextContent.Add(new SimpleText(this.Document, "1")); } else { //add the tabstop and the page number, the number is //always set to 1, but will be updated by the most //word processors immediately to the correct page number. paragraph.TextContent.Add(new SimpleText(this.Document, textEntry)); paragraph.TextContent.Add(new TabStop(this.Document)); paragraph.TextContent.Add(new SimpleText(this.Document, "1")); } //There is a bug which deny to add new simple ta // this.TitleParagraph.ParagraphStyle.ParagraphProperties.TabStopStyleCollection = // this.GetTabStopStyle(TabStopLeaderStyles.Dotted, ".", 16.999); paragraph.ParagraphStyle.ParagraphProperties.TabStopStyleCollection = this.GetTabStopStyle(TabStopLeaderStyles.Dotted, ".", 16.999); this.Content.Add(paragraph); }
/// <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) { throw new AODLException("Exception while trying to create a XLink.", ex); } }
/// <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; } }