PageRenderTime 60ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/AODL/Document/Export/Html/HTMLContentBuilder.cs

https://bitbucket.org/chrisc/aodl
C# | 1599 lines | 1148 code | 164 blank | 287 comment | 395 complexity | babd730d719449f7632c488355863455 MD5 | raw file
  1. /*************************************************************************
  2. *
  3. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
  4. *
  5. * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
  6. *
  7. * Use is subject to license terms.
  8. *
  9. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  10. * use this file except in compliance with the License. You may obtain a copy
  11. * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
  12. * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  16. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. *
  18. * See the License for the specific language governing permissions and
  19. * limitations under the License.
  20. *
  21. ************************************************************************/
  22. using System;
  23. using System.Linq;
  24. using System.Xml;
  25. using System.Collections.Generic;
  26. using System.Diagnostics;
  27. using System.Xml.Linq;
  28. using AODL.Document;
  29. using AODL.Document.Exceptions;
  30. using AODL.Document.Content;
  31. using AODL.Document.Content.Fields;
  32. using AODL.Document.Helper;
  33. using AODL.Document.Styles;
  34. using AODL.Document.Styles.Properties;
  35. using AODL.Document.Content.Text;
  36. using AODL.Document.Content.Tables;
  37. using AODL.Document.Content.Draw;
  38. using AODL.Document.Content.Text.Indexes;
  39. using AODL.Document.Content.Text.TextControl;
  40. using AODL.Document.Forms;
  41. using AODL.Document.Forms.Controls;
  42. using AODL.Document.TextDocuments;
  43. namespace AODL.Document.Export.Html
  44. {
  45. /// <summary>
  46. /// HTMLContentBuilder offer public methods
  47. /// to build HTML element string from AODL
  48. /// OpenDocument objects.
  49. /// </summary>
  50. public class HTMLContentBuilder
  51. {
  52. /// <summary>
  53. /// Warning delegate
  54. /// </summary>
  55. public delegate void Warning(AODLWarning warning);
  56. /// <summary>
  57. /// OnWarning event fired if something unexpected
  58. /// occour.
  59. /// </summary>
  60. [Obsolete]
  61. public event Warning OnWarning;
  62. private HTMLStyleBuilder _hTMLStyleBuilder;
  63. /// <summary>
  64. /// Gets or sets the HTML style builder.
  65. /// </summary>
  66. /// <value>The HTML style builder.</value>
  67. public HTMLStyleBuilder HTMLStyleBuilder
  68. {
  69. get { return this._hTMLStyleBuilder; }
  70. set { this._hTMLStyleBuilder = value; }
  71. }
  72. private string _graphicTargetFolder;
  73. /// <summary>
  74. /// Gets or sets the graphic target folder.
  75. /// </summary>
  76. /// <value>The graphic target folder.</value>
  77. public string GraphicTargetFolder
  78. {
  79. get { return this._graphicTargetFolder; }
  80. set { this._graphicTargetFolder = value; }
  81. }
  82. /// <summary>
  83. /// The next image map name. A frame will check if it contain
  84. /// a image map and will set the name which will be used
  85. /// by the next graphic and image map.
  86. /// </summary>
  87. private string _nextImageMapName;
  88. /// <summary>
  89. /// Initializes a new instance of the <see cref="HTMLContentBuilder"/> class.
  90. /// </summary>
  91. public HTMLContentBuilder()
  92. {
  93. this.HTMLStyleBuilder = new HTMLStyleBuilder();
  94. }
  95. /// <summary>
  96. /// Initializes a new instance of the <see cref="HTMLContentBuilder"/> class.
  97. /// </summary>
  98. /// <param name="graphicTargetFolder">The graphic target folder.</param>
  99. public HTMLContentBuilder(string graphicTargetFolder)
  100. {
  101. this.GraphicTargetFolder = graphicTargetFolder;
  102. this.HTMLStyleBuilder = new HTMLStyleBuilder();
  103. }
  104. /// <summary>
  105. /// Gets the I content collection as HTML.
  106. /// </summary>
  107. /// <param name="iContentCollection">The i content collection.</param>
  108. /// <returns></returns>
  109. public string GetIContentCollectionAsHtml(ContentCollection iContentCollection)
  110. {
  111. string html = "";
  112. try
  113. {
  114. if (iContentCollection != null)
  115. {
  116. foreach(IContent iContent in iContentCollection)
  117. {
  118. //determine type
  119. if (iContent is Table)
  120. html += this.GetTableAsHtml(iContent as Table);
  121. else if (iContent is ODFControlRef)
  122. html += this.GetODFControlAsHtml(iContent as ODFControlRef);
  123. else if (iContent is Field)
  124. html += this.GetFieldAsHtml(iContent as Field);
  125. else if (iContent is Paragraph)
  126. html += this.GetParagraphAsHtml(iContent as Paragraph);
  127. else if (iContent is List)
  128. html += this.GetListAsHtml(iContent as List);
  129. else if (iContent is Frame)
  130. html += this.GetDrawFrameAsHtml(iContent as Frame);
  131. else if (iContent is DrawTextBox)
  132. html += this.GetDrawTextBoxAsHtml(iContent as DrawTextBox);
  133. else if (iContent is Graphic)
  134. html += this.GetGraphicAsHtml(iContent as Graphic);
  135. else if (iContent is ListItem)
  136. html += this.GetListItemAsHtml(iContent as ListItem);
  137. else if (iContent is Header)
  138. html += this.GetHeadingAsHtml(iContent as Header);
  139. else if (iContent is TableOfContents)
  140. html += this.GetTableOfContentsAsHtml(iContent as TableOfContents);
  141. else if (iContent is UnknownContent)
  142. html += this.GetUnknowContentAsHtml(iContent as UnknownContent);
  143. else if (iContent is ImageMap)
  144. html += this.GetImageMapAsHtml(iContent as ImageMap);
  145. else if (iContent is DrawArea)
  146. html += this.GetDrawAreaAsHtml(iContent as DrawArea);
  147. else
  148. //this should never happens, because all not implemented elements
  149. //are unknwon content
  150. if (OnWarning != null)
  151. {
  152. AODLWarning warning = new AODLWarning("Finding total unknown content. This should (could) never happen.");
  153. //warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true));
  154. OnWarning(warning);
  155. }
  156. }
  157. }
  158. }
  159. catch(Exception ex)
  160. {
  161. throw new AODLException("Exception while trying to build a HTML string from an IContentCollection.", ex);
  162. }
  163. return html;
  164. }
  165. /// <summary>
  166. /// Gets the I text collection as HTML.
  167. /// </summary>
  168. /// <param name="iTextCollection">The i text collection.</param>
  169. /// <param name="paragraphStyle">The paragraph style.</param>
  170. /// <returns></returns>
  171. public string GetITextCollectionAsHtml(ITextCollection iTextCollection, ParagraphStyle paragraphStyle)
  172. {
  173. string html = "";
  174. int tabStopCnt = 0;
  175. try
  176. {
  177. if (iTextCollection != null)
  178. {
  179. foreach(IText iText in iTextCollection)
  180. {
  181. //determine type
  182. if (iText is SimpleText)
  183. {
  184. string textContent = ((XText)iText.Node).Value;
  185. html += this.ReplaceControlNodes(textContent);
  186. }
  187. else if (iText is FormatedText)
  188. html += this.GetFormatedTextAsHtml(iText as FormatedText);
  189. else if (iText is WhiteSpace)
  190. html += this.GetWhiteSpacesAsHtml(iText as WhiteSpace);
  191. else if (iText is TabStop)
  192. {
  193. html += this.GetTabStopAsHtml(iText as TabStop, tabStopCnt, html, paragraphStyle);
  194. tabStopCnt++;
  195. }
  196. else if (iText is XLink)
  197. html += this.GetXLinkAsHtml(iText as XLink);
  198. else if (iText is LineBreak)
  199. html += this.GetLineBreakAsHtml();
  200. else if (iText is UnknownTextContent)
  201. html += this.GetUnknowTextContentAsHtml(iText as UnknownTextContent);
  202. else
  203. //this should never happens, because all not implemented elements
  204. //are unknwon content
  205. if (OnWarning != null)
  206. {
  207. AODLWarning warning = new AODLWarning("Finding total unknown text content. This should (could) never happen.");
  208. //warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true));
  209. OnWarning(warning);
  210. }
  211. }
  212. }
  213. }
  214. catch(Exception ex)
  215. {
  216. throw new AODLException("Exception while trying to build a HTML string from an ITextCollection.", ex);
  217. }
  218. return html;
  219. }
  220. /// <summary>
  221. /// Gets the mixed content as HTML.
  222. /// </summary>
  223. /// <param name="mixedContent">list of objects. The objects could be
  224. /// IContent or IText.</param>
  225. /// <param name="paragraphStyle">The paragraph style.</param>
  226. /// <returns></returns>
  227. public string GetMixedContentAsHTML(IList<IContent> mixedContent, ParagraphStyle paragraphStyle)
  228. {
  229. string html = "";
  230. int tabStopCnt = 0;
  231. try
  232. {
  233. if (mixedContent != null)
  234. {
  235. foreach(IContent ob in mixedContent)
  236. {
  237. //determine type text content types
  238. if (ob is SimpleText)
  239. {
  240. html += this.ReplaceControlNodes(((XText)((IText)ob).Node).Value);
  241. }
  242. else if (ob is FormatedText)
  243. html += this.GetFormatedTextAsHtml(ob as FormatedText);
  244. else if (ob is WhiteSpace)
  245. html += this.GetWhiteSpacesAsHtml(ob as WhiteSpace);
  246. else if (ob is TabStop)
  247. {
  248. html += this.GetTabStopAsHtml(ob as TabStop, tabStopCnt, html, paragraphStyle);
  249. tabStopCnt++;
  250. }
  251. else if (ob is XLink)
  252. html += this.GetXLinkAsHtml(ob as XLink);
  253. else if (ob is LineBreak)
  254. html += this.GetLineBreakAsHtml();
  255. else if (ob is UnknownTextContent)
  256. html += this.GetUnknowTextContentAsHtml(ob as UnknownTextContent);
  257. //determine type
  258. else if (ob is Table)
  259. html += this.GetTableAsHtml(ob as Table);
  260. else if (ob is Paragraph)
  261. html += this.GetParagraphAsHtml(ob as Paragraph);
  262. else if (ob is List)
  263. html += this.GetListAsHtml(ob as List);
  264. else if (ob is Frame)
  265. html += this.GetDrawFrameAsHtml(ob as Frame);
  266. else if (ob is Graphic)
  267. html += this.GetGraphicAsHtml(ob as Graphic);
  268. else if (ob is ListItem)
  269. html += this.GetListItemAsHtml(ob as ListItem);
  270. else if (ob is Field)
  271. html += this.GetFieldAsHtml(ob as Field);
  272. else if (ob is ODFControlRef)
  273. html += this.GetODFControlAsHtml(ob as ODFControlRef);
  274. else if (ob is Header)
  275. html += this.GetHeadingAsHtml(ob as Header);
  276. else if (ob is UnknownContent)
  277. html += this.GetUnknowContentAsHtml(ob as UnknownContent);
  278. else
  279. //this should never happens, because all not implemented elements
  280. //are unknwon content
  281. if (OnWarning != null)
  282. {
  283. AODLWarning warning = new AODLWarning("Finding total unknown content in mixed content. This should (could) never happen.");
  284. //warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true));
  285. OnWarning(warning);
  286. }
  287. }
  288. }
  289. }
  290. catch(Exception ex)
  291. {
  292. throw new AODLException("Exception while trying to build a HTML string from an ITextCollection.", ex);
  293. }
  294. return html;
  295. }
  296. /// <summary>
  297. /// Gets the table of contents as HTML.
  298. /// </summary>
  299. /// <param name="tableOfContents">The table of contents.</param>
  300. /// <returns></returns>
  301. public string GetTableOfContentsAsHtml(TableOfContents tableOfContents)
  302. {
  303. string html = "";
  304. try
  305. {
  306. if (tableOfContents != null)
  307. {
  308. XElement nodeTitle = tableOfContents.Node
  309. .Elements(Ns.Text + "index-body")
  310. .Elements(Ns.Text + "index-title")
  311. .Elements(Ns.Text + "p")
  312. .FirstOrDefault();
  313. if (nodeTitle != null)
  314. {
  315. html += "<p "+this.HTMLStyleBuilder.HeaderHtmlStyles[0]+">\n";
  316. html += nodeTitle.Value;
  317. html += "\n</p>\n";
  318. }
  319. if (tableOfContents.Content != null)
  320. html += this.GetIContentCollectionAsHtml(tableOfContents.Content);
  321. }
  322. }
  323. catch(Exception ex)
  324. {
  325. throw new AODLException("Exception while trying to build a HTML string from a TableOfContents.", ex);
  326. }
  327. return html;
  328. }
  329. /// <summary>
  330. /// Gets the table as HTML.
  331. /// </summary>
  332. /// <param name="table">The table.</param>
  333. /// <returns></returns>
  334. public string GetTableAsHtml(Table table)
  335. {
  336. //TODO: Implement table border algo
  337. string html = "<table border=\"1\" ";
  338. try
  339. {
  340. if (table != null)
  341. {
  342. string style = this.HTMLStyleBuilder.GetTableStyleAsHtml(table.TableStyle);
  343. if (style.Length > 0)
  344. {
  345. html += style;
  346. html += ">\n";
  347. }
  348. if (table.Rows != null)
  349. foreach(Row row in table.Rows)
  350. html += this.GetRowAsHtml(row);
  351. }
  352. }
  353. catch(Exception ex)
  354. {
  355. throw new AODLException("Exception while trying to build a HTML string from a Table object.", ex);
  356. }
  357. if (!html.Equals("<table border=\"1\" "))
  358. html += "</table>\n";
  359. else
  360. html = "";
  361. return html;
  362. }
  363. /// <summary>
  364. /// Gets the row as HTML.
  365. /// </summary>
  366. /// <param name="row">The row.</param>
  367. /// <returns></returns>
  368. public string GetRowAsHtml(Row row)
  369. {
  370. string html = "<tr>\n";
  371. try
  372. {
  373. if (row != null)
  374. {
  375. if (row.Cells != null)
  376. {
  377. foreach(Cell cell in row.Cells)
  378. html += this.GetCellAsHtml(cell);
  379. }
  380. }
  381. }
  382. catch(Exception ex)
  383. {
  384. throw new AODLException("Exception while trying to build a HTML string from a Row object.", ex);
  385. }
  386. if (!html.Equals("<tr>\n"))
  387. html += "</tr>\n";
  388. else
  389. html = "";
  390. return html;
  391. }
  392. /// <summary>
  393. /// Gets the cell as HTML.
  394. /// </summary>
  395. /// <param name="cell">The cell.</param>
  396. /// <returns></returns>
  397. public string GetCellAsHtml(Cell cell)
  398. {
  399. string html = "<td ";
  400. try
  401. {
  402. if (cell != null)
  403. {
  404. if (cell.ColumnRepeating != null)
  405. html += "columnspan=\""+cell.ColumnRepeating+"\" ";
  406. string cellStyle = this.HTMLStyleBuilder.GetCellStyleAsHtml(cell.CellStyle);
  407. if (cellStyle.Length > 0)
  408. html += cellStyle;
  409. int cellIndex = -1;
  410. if (cell.Row != null)
  411. cellIndex = cell.Row.GetCellIndex(cell);
  412. ColumnStyle colStyle = null;
  413. if (cellIndex != -1 && cell.Row!= null && cell.Row.Table != null)
  414. if (cell.Row.Table.ColumnCollection != null)
  415. if (cell.Row.Table.ColumnCollection.Count > cellIndex)
  416. if (cell.Row.Table.ColumnCollection[cellIndex].ColumnStyle != null)
  417. colStyle = cell.Row.Table.ColumnCollection[cellIndex].ColumnStyle;
  418. string colHtmlStyle = this.HTMLStyleBuilder.GetColumnStyleAsHtml(colStyle);
  419. if (colHtmlStyle.Length > 0)
  420. html += colHtmlStyle;
  421. html += ">\n";
  422. string contentHtml = this.GetIContentCollectionAsHtml(cell.Content);
  423. if (contentHtml.Length > 0)
  424. html += contentHtml;
  425. }
  426. }
  427. catch(Exception ex)
  428. {
  429. throw new AODLException("Exception while trying to build a HTML string from a Cell object.", ex);
  430. }
  431. if (!html.Equals("<td "))
  432. html += "</td>\n";
  433. else
  434. html = "";
  435. return html;
  436. }
  437. /// <summary>
  438. /// Gets the paragraph as HTML.
  439. /// </summary>
  440. /// <param name="paragraph">The paragraph.</param>
  441. /// <returns></returns>
  442. public string GetParagraphAsHtml(Paragraph paragraph)
  443. {
  444. string html = "<p ";
  445. try
  446. {
  447. if (paragraph != null)
  448. {
  449. if (paragraph.StyleName != null)
  450. if (paragraph.StyleName != "Text_20_body"
  451. && paragraph.StyleName != "standard"
  452. && paragraph.StyleName != "Table_20_body")
  453. {
  454. string style = this.HTMLStyleBuilder.GetParagraphStyleAsHtml(paragraph.ParagraphStyle);
  455. if (style.Length > 0)
  456. html += style;//+">\n";
  457. else
  458. {
  459. //Check against a possible common style
  460. IStyle iStyle = paragraph.Document.CommonStyles.GetStyleByName(paragraph.StyleName);
  461. string commonStyle = "";
  462. if (iStyle != null && iStyle is ParagraphStyle)
  463. {
  464. commonStyle = this.HTMLStyleBuilder.GetParagraphStyleAsHtml(iStyle as ParagraphStyle);
  465. if (commonStyle.Length > 0)
  466. html += commonStyle;
  467. else
  468. html = html.Replace(" ", "");
  469. }
  470. else
  471. html = html.Replace(" ", "");
  472. }
  473. }
  474. else
  475. {
  476. html = html.Replace(" ", "");
  477. }
  478. html += ">\n";
  479. string txtstyle = "<span ";
  480. bool useTextStyle = false;
  481. if (paragraph.ParagraphStyle != null)
  482. {
  483. string tstyle = this.HTMLStyleBuilder.GetTextStyleAsHtml(paragraph.ParagraphStyle.TextProperties);
  484. if (txtstyle.Length > 0)
  485. {
  486. txtstyle += tstyle+">\n";
  487. html += txtstyle;
  488. useTextStyle = true;
  489. }
  490. }
  491. else
  492. {
  493. //Check again a possible common style
  494. string commonstyle = "";
  495. IStyle iStyle = paragraph.Document.CommonStyles.GetStyleByName(paragraph.StyleName);
  496. if (iStyle != null && iStyle is ParagraphStyle)
  497. {
  498. commonstyle = this.HTMLStyleBuilder.GetTextStyleAsHtml(((ParagraphStyle)iStyle).TextProperties);
  499. if (commonstyle.Length > 0)
  500. {
  501. txtstyle += commonstyle+">\n";
  502. html += txtstyle;
  503. useTextStyle = true;
  504. }
  505. }
  506. }
  507. ////
  508. string mixedCont = this.GetMixedContentAsHTML(paragraph.MixedContent, paragraph.ParagraphStyle);
  509. ////
  510. if (mixedCont.Length > 0)
  511. html += mixedCont+"&nbsp;";
  512. else
  513. html += "&nbsp;";
  514. if (!html.Equals("<p "))
  515. if (useTextStyle)
  516. html += "</span>\n</p>\n";
  517. else
  518. html += "</p>\n";
  519. else
  520. html = "";
  521. if (html.Equals("<p >"))
  522. html = "";
  523. }
  524. }
  525. catch(Exception ex)
  526. {
  527. throw new AODLException("Exception while trying to build a HTML string from a Heading object.", ex);
  528. }
  529. return html;
  530. }
  531. /// <summary>
  532. /// Gets the heading as HTML.
  533. /// </summary>
  534. /// <param name="heading">The heading.</param>
  535. /// <returns></returns>
  536. public string GetHeadingAsHtml(Header heading)
  537. {
  538. string html = "<p ";
  539. try
  540. {
  541. if (heading != null)
  542. {
  543. string style = this.HTMLStyleBuilder.GetHeadingStyleAsHtml(heading);
  544. if (style.Length > 0)
  545. {
  546. html += style;
  547. html += ">\n";
  548. }
  549. else
  550. html = html.Replace(" ", "")+">\n";
  551. string headerText = "";
  552. string outlineLevel = this.GetOutlineString(heading);
  553. string textContent = this.GetITextCollectionAsHtml(heading.TextContent, null);
  554. if (textContent.Length > 0)
  555. headerText += textContent;
  556. //create an anchor
  557. html += "<a name=\""+headerText+"\">\n"+outlineLevel+" "+headerText+"\n</a>\n";
  558. }
  559. }
  560. catch(Exception ex)
  561. {
  562. throw new AODLException("Exception while trying to build a HTML string from a Heading object.", ex);
  563. }
  564. if (!html.Equals("<p "))
  565. html += "</p>\n";
  566. else
  567. html = "";
  568. return html;
  569. }
  570. /// <summary>
  571. /// Gets the outline string.
  572. /// </summary>
  573. /// <param name="header">The header.</param>
  574. /// <returns></returns>
  575. private string GetOutlineString(Header header)
  576. {
  577. try
  578. {
  579. int outline1 = 0;
  580. int outline2 = 0;
  581. int outline3 = 0;
  582. int outline4 = 0;
  583. int outline5 = 0;
  584. int outline6 = 0;
  585. if (header.Document != null)
  586. {
  587. if (header.Document is TextDocuments.TextDocument && header.Document.Content != null)
  588. {
  589. foreach(IContent content in header.Document.Content)
  590. if (content is Header)
  591. if (((Header)content).OutLineLevel != null)
  592. {
  593. int no = Convert.ToInt32(((Header)content).OutLineLevel);
  594. if (no == 1)
  595. {
  596. outline1++;
  597. outline2 = 0;
  598. outline3 = 0;
  599. outline4 = 0;
  600. outline5 = 0;
  601. outline6 = 0;
  602. }
  603. else if (no == 2)
  604. outline2++;
  605. else if (no == 3)
  606. outline3++;
  607. else if (no == 4)
  608. outline4++;
  609. else if (no == 5)
  610. outline5++;
  611. else if (no == 6)
  612. outline6++;
  613. if (content == header)
  614. {
  615. string sNumber = outline1.ToString()+".";
  616. string sNumber1 = "";
  617. if (outline6 != 0)
  618. sNumber1 = "."+outline6.ToString()+".";
  619. if (outline5 != 0)
  620. sNumber1 = sNumber1+"."+outline5.ToString()+".";
  621. if (outline4 != 0)
  622. sNumber1 = sNumber1+"."+outline4.ToString()+".";
  623. if (outline3 != 0)
  624. sNumber1 = sNumber1+"."+outline3.ToString()+".";
  625. if (outline2 != 0)
  626. sNumber1 = sNumber1+"."+outline2.ToString()+".";
  627. sNumber += sNumber1;
  628. return sNumber.Replace("..",".");
  629. }
  630. }
  631. }
  632. }
  633. }
  634. catch(Exception ex)
  635. {
  636. if (OnWarning != null)
  637. {
  638. AODLWarning warning = new AODLWarning("Exception while trying to get a outline string for a heading.", ex);
  639. //warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true));
  640. //warning.OriginalException = ex;
  641. warning.Node = header.Node;
  642. OnWarning(warning);
  643. }
  644. }
  645. return null;
  646. }
  647. /// <summary>
  648. /// Gets the list as HTML.
  649. /// </summary>
  650. /// <param name="list">The list.</param>
  651. /// <returns></returns>
  652. public string GetListAsHtml(List list)
  653. {
  654. string html = "<";
  655. try
  656. {
  657. if (list != null)
  658. {
  659. if (list.ListType == ListStyles.Number)
  660. html += "ol>\n";
  661. else
  662. html += "ul>\n";
  663. if (list.Content != null)
  664. {
  665. foreach(IContent iContent in list.Content)
  666. html += this.GetIContentCollectionAsHtml(list.Content);
  667. }
  668. }
  669. }
  670. catch(Exception ex)
  671. {
  672. throw new AODLException("Exception while trying to build a HTML string from a List object.", ex);
  673. }
  674. if (html.StartsWith("<ol"))
  675. html += "</ol>\n";
  676. else if (html.StartsWith("<ul"))
  677. html += "</ul>\n";
  678. else
  679. html = "";
  680. return html;
  681. }
  682. /// <summary>
  683. /// Gets a Field as HTML.
  684. /// </summary>
  685. /// <param name="list">The field reference.</param>
  686. /// <returns></returns>
  687. public string GetFieldAsHtml(Field f)
  688. {
  689. string html = "";
  690. if (f.Document is TextDocument)
  691. {
  692. try
  693. {
  694. if (f != null)
  695. html = f.Value;
  696. }
  697. catch(Exception ex)
  698. {
  699. throw new AODLException("Exception while trying to build a HTML string from a Field object.", ex);
  700. }
  701. return html;
  702. }
  703. else return "";
  704. }
  705. /// <summary>
  706. /// Gets a ODFControlRef as HTML.
  707. /// </summary>
  708. /// <param name="list">The control reference.</param>
  709. /// <returns></returns>
  710. public string GetODFControlAsHtml(ODFControlRef reference)
  711. {
  712. if (reference.Document is TextDocument)
  713. {
  714. string html = "";
  715. try
  716. {
  717. if (reference == null) return "";
  718. TextDocument td = reference.Document as TextDocument;
  719. if (td == null)
  720. return "";
  721. ODFFormControl control = td.FindControlById(reference.DrawControl);
  722. if (control is ODFButton)
  723. {
  724. html += "<form ";
  725. ODFButton butt = control as ODFButton;
  726. if (butt.ParentForm.Method == Method.Post)
  727. html += "method='post' ";
  728. if (butt.ParentForm.Href != "")
  729. html +=String.Format("action='{0}' ", butt.ParentForm.Href);
  730. if (butt.ParentForm.Name != "")
  731. html +=String.Format("name='{0}'>\n", butt.ParentForm.Name);
  732. html +=String.Format("<input type='submit' style='float: left; width: {0}; height: {1};'", butt.Width, butt.Height);
  733. if (butt.Name!="")
  734. html +=String.Format("name='{0}' ", butt.Name);
  735. if (butt.Label!="")
  736. html +=String.Format("value='{0}' ", butt.Label);
  737. html +="/>\n</form>\n";
  738. }
  739. if (control is ODFCheckBox)
  740. {
  741. html += "<form ";
  742. ODFCheckBox cb = control as ODFCheckBox;
  743. if (cb.ParentForm.Method == Method.Post)
  744. html += "method='post' ";
  745. if (cb.ParentForm.Href != "")
  746. html +=String.Format("action='{0}' ", cb.ParentForm.Href);
  747. if (cb.ParentForm.Name != "")
  748. html +=String.Format("name='{0}'>\n", cb.ParentForm.Name);
  749. string is_checked = "";
  750. if (cb.CurrentState == State.Checked) is_checked = " checked ";
  751. html +=String.Format("<input type='checkbox' style='float: left; margin: 0px; width: {0}; height: {1};'", cb.Width, cb.Height);
  752. if (cb.Name!="")
  753. html +=String.Format("name='{0}' ", cb.Name);
  754. if (cb.Value!="")
  755. html +=String.Format("value='{0}' ", cb.Value);
  756. html +=is_checked;
  757. html +="/>\n</form>\n";
  758. }
  759. if (control is ODFListBox)
  760. {
  761. html += "<form ";
  762. ODFListBox lb = control as ODFListBox;
  763. if (lb.ParentForm.Method == Method.Post)
  764. html += "method='post' ";
  765. if (lb.ParentForm.Href != "")
  766. html +=String.Format("action='{0}' ", lb.ParentForm.Href);
  767. if (lb.ParentForm.Name != "")
  768. html +=String.Format("name='{0}'>\n", lb.ParentForm.Name);
  769. html +=String.Format("<select style='float: left; margin: 0px; width: {0}; height: {1};'", lb.Width, lb.Height);
  770. if (lb.Name!="")
  771. html +=String.Format("name='{0}' ", lb.Name);
  772. if (lb.Size!=0)
  773. html +=String.Format("size='{0}' ",lb.Size);
  774. html +="/>\n";
  775. foreach (ODFOption o in lb.Options)
  776. {
  777. string selected = "";
  778. if (o.Selected.HasValue && o.Selected.Value) selected = " selected";
  779. html += String.Format("<option{0}>{1}</option>", selected, o.Label);
  780. }
  781. html+="</form>\n";
  782. }
  783. if (control is ODFComboBox)
  784. {
  785. html += "<form ";
  786. ODFComboBox lb = control as ODFComboBox;
  787. if (lb.ParentForm.Method == Method.Post)
  788. html += "method='post' ";
  789. if (lb.ParentForm.Href != "")
  790. html +=String.Format("action='{0}' ", lb.ParentForm.Href);
  791. if (lb.ParentForm.Name != "")
  792. html +=String.Format("name='{0}'>\n", lb.ParentForm.Name);
  793. html +=String.Format("<select style='float: left; margin: 0px; width: {0}; height: {1};'", lb.Width, lb.Height);
  794. if (lb.Name!="")
  795. html +=String.Format("name='{0}' ", lb.Name);
  796. if (lb.Size!=0)
  797. html +=String.Format("size='{0}' ",lb.Size);
  798. html +="/>\n";
  799. foreach (ODFItem o in lb.Items)
  800. {
  801. string selected = "";
  802. if (o.Label == lb.CurrentValue) selected = " selected";
  803. html += String.Format("<option{0}>{1}</option>", selected, o.Label);
  804. }
  805. html+="</form>\n";
  806. }
  807. if (control is ODFFile)
  808. {
  809. html += "<form ";
  810. ODFFile file = control as ODFFile;
  811. if (file.ParentForm.Method == Method.Post)
  812. html += "method='post' ";
  813. if (file.ParentForm.Href != "")
  814. html +=String.Format("action='{0}' ", file.ParentForm.Href);
  815. if (file.ParentForm.Name != "")
  816. html +=String.Format("name='{0}'>\n", file.ParentForm.Name);
  817. html +=String.Format("<input type='file' style='float: left; width: {0}; height: {1};'", file.Width, file.Height);
  818. if (file.Name!="")
  819. html +=String.Format("name='{0}' ", file.Name);
  820. if (file.CurrentValue!="")
  821. html +=String.Format("value='{0}' ", file.CurrentValue);
  822. html +="/>\n</form>\n";
  823. }
  824. if (control is ODFHidden)
  825. {
  826. html += "<form ";
  827. ODFHidden hid = control as ODFHidden;
  828. if (hid.ParentForm.Method == Method.Post)
  829. html += "method='post' ";
  830. if (hid.ParentForm.Href != "")
  831. html +=String.Format("action='{0}' ", hid.ParentForm.Href);
  832. if (hid.ParentForm.Name != "")
  833. html +=String.Format("name='{0}'>\n", hid.ParentForm.Name);
  834. html +=String.Format("<input type='file' style='float: left; width: {0}; height: {1};'", hid.Width, hid.Height);
  835. if (hid.Name!="")
  836. html +=String.Format("name='{0}' ", hid.Name);
  837. if (hid.Value!="")
  838. html +=String.Format("value='{0}' ", hid.Value);
  839. html +="/>\n</form>\n";
  840. }
  841. if (control is ODFFormattedText)
  842. {
  843. html += "<form ";
  844. ODFFormattedText ft = control as ODFFormattedText;
  845. if (ft.ParentForm.Method == Method.Post)
  846. html += "method='post' ";
  847. if (ft.ParentForm.Href != "")
  848. html +=String.Format("action='{0}' ", ft.ParentForm.Href);
  849. if (ft.ParentForm.Name != "")
  850. html +=String.Format("name='{0}'>\n", ft.ParentForm.Name);
  851. html +=String.Format("<input type='text' style='float: left; width: {0}; height: {1};'", ft.Width, ft.Height);
  852. if (ft.Name!="")
  853. html +=String.Format("name='{0}' ", ft.Name);
  854. if (ft.CurrentValue!="")
  855. html +=String.Format("value='{0}' ", ft.CurrentValue);
  856. html +="/>\n</form>\n";
  857. }
  858. if (control is ODFTextArea)
  859. {
  860. html += "<form ";
  861. ODFTextArea ta = control as ODFTextArea;
  862. if (ta.ParentForm.Method == Method.Post)
  863. html += "method='post' ";
  864. if (ta.ParentForm.Href != "")
  865. html +=String.Format("action='{0}' ", ta.ParentForm.Href);
  866. if (ta.ParentForm.Name != "")
  867. html +=String.Format("name='{0}'>\n", ta.ParentForm.Name);
  868. html +=String.Format("<textarea style='float: left; width: {0}; height: {1};'", ta.Width, ta.Height);
  869. if (ta.Name!="")
  870. html +=String.Format("name='{0}' ", ta.Name);
  871. html +="/>";
  872. html+= ta.CurrentValue;
  873. html+= "\n</form>\n";
  874. }
  875. }
  876. catch(Exception ex)
  877. {
  878. throw new AODLException("Exception while trying to build a HTML string from an ODF Form.", ex);
  879. }
  880. return html;
  881. }
  882. else return "";
  883. }
  884. /// <summary>
  885. /// Gets the list item as HTML.
  886. /// </summary>
  887. /// <param name="listItem">The list item.</param>
  888. /// <returns></returns>
  889. public string GetListItemAsHtml(ListItem listItem)
  890. {
  891. string html = "<li>\n";
  892. try
  893. {
  894. if (listItem != null)
  895. {
  896. if (listItem.Content != null)
  897. {
  898. html += this.GetIContentCollectionAsHtml(listItem.Content);
  899. }
  900. }
  901. }
  902. catch(Exception ex)
  903. {
  904. throw new AODLException("Exception while trying to build a HTML string from a ListItem object.", ex);
  905. }
  906. if (!html.Equals("<li>\n"))
  907. html += "</li>\n";
  908. else
  909. html = "";
  910. return html;
  911. }
  912. /// <summary>
  913. /// Gets the draw frame as HTML.
  914. /// </summary>
  915. /// <param name="frame">The frame.</param>
  916. /// <returns></returns>
  917. public string GetDrawFrameAsHtml(Frame frame)
  918. {
  919. string html = "<p>\n";
  920. try
  921. {
  922. if (frame != null)
  923. {
  924. if (frame.Content != null)
  925. {
  926. //Check for possible Image Map
  927. bool containsImageMap = false;
  928. foreach(IContent iContent in frame.Content)
  929. if (iContent is ImageMap)
  930. {
  931. this._nextImageMapName = Guid.NewGuid().ToString();
  932. containsImageMap = true;
  933. break;
  934. }
  935. if (!containsImageMap)
  936. this._nextImageMapName = null;
  937. html += this.GetIContentCollectionAsHtml(frame.Content);
  938. }
  939. }
  940. }
  941. catch(Exception ex)
  942. {
  943. throw new AODLException("Exception while trying to build a HTML string from a Frame object.", ex);
  944. }
  945. if (!html.Equals("<p>\n"))
  946. html += "</p>\n";
  947. else
  948. html = "";
  949. return html;
  950. }
  951. /// <summary>
  952. /// Gets the draw text box as HTML.
  953. /// </summary>
  954. /// <param name="drawTextBox">The draw text box.</param>
  955. /// <returns></returns>
  956. public string GetDrawTextBoxAsHtml(DrawTextBox drawTextBox)
  957. {
  958. string html = "";
  959. try
  960. {
  961. if (drawTextBox != null)
  962. {
  963. if (drawTextBox.Content != null)
  964. {
  965. html += this.GetIContentCollectionAsHtml(drawTextBox.Content);
  966. }
  967. }
  968. html += "\n";
  969. }
  970. catch(Exception ex)
  971. {
  972. throw new AODLException("Exception while trying to build a HTML string from a ImageMap object.", ex);
  973. }
  974. return html;
  975. }
  976. /// <summary>
  977. /// Gets the image map as HTML.
  978. /// </summary>
  979. /// <param name="imageMap">The image map.</param>
  980. /// <returns></returns>
  981. public string GetImageMapAsHtml(ImageMap imageMap)
  982. {
  983. string html = "<div>\n<map name=\""+this._nextImageMapName+"\">\n";
  984. try
  985. {
  986. if (imageMap != null)
  987. {
  988. if (imageMap.Content != null)
  989. {
  990. html += this.GetIContentCollectionAsHtml(imageMap.Content);
  991. }
  992. }
  993. html += "</map>\n</div>\n";
  994. }
  995. catch(Exception ex)
  996. {
  997. throw new AODLException("Exception while trying to build a HTML string from a ImageMap object.", ex);
  998. }
  999. return html;
  1000. }
  1001. /// <summary>
  1002. /// Gets the draw rectangle as HTML.
  1003. /// </summary>
  1004. /// <param name="drawArea">The draw area.</param>
  1005. /// <returns></returns>
  1006. public string GetDrawAreaAsHtml(DrawArea drawArea)
  1007. {
  1008. string html = "<area shape=\"#type#\" coords=\"#coords#\" href=\"#link#\" target=\"_top\">\n";
  1009. string coords = null;
  1010. int cx, cy, cxx, cyy, r = 0;
  1011. try
  1012. {
  1013. if (drawArea != null)
  1014. {
  1015. if (drawArea is DrawAreaRectangle)
  1016. {
  1017. html = html.Replace("#link#", ((DrawAreaRectangle)drawArea).Href);
  1018. cx = SizeConverter.GetPixelFromAnOfficeSizeValue(
  1019. ((DrawAreaRectangle)drawArea).X);
  1020. cy = SizeConverter.GetPixelFromAnOfficeSizeValue(
  1021. ((DrawAreaRectangle)drawArea).Y);
  1022. int w = SizeConverter.GetPixelFromAnOfficeSizeValue(
  1023. ((DrawAreaRectangle)drawArea).Width);
  1024. int h = SizeConverter.GetPixelFromAnOfficeSizeValue(
  1025. ((DrawAreaRectangle)drawArea).Height);
  1026. cxx = cx+w;
  1027. cyy = cy+h;
  1028. coords = cx.ToString()+","+cy.ToString()+","+cxx.ToString()+","+cyy.ToString();
  1029. html = html.Replace("#coords#", coords);
  1030. html = html.Replace("#type#", "rect");
  1031. }
  1032. else if (drawArea is DrawAreaCircle)
  1033. {
  1034. html = html.Replace("#link#", ((DrawAreaCircle)drawArea).Href);
  1035. cx = SizeConverter.GetPixelFromAnOfficeSizeValue(
  1036. ((DrawAreaCircle)drawArea).CX);
  1037. cy = SizeConverter.GetPixelFromAnOfficeSizeValue(
  1038. ((DrawAreaCircle)drawArea).CY);
  1039. r = SizeConverter.GetPixelFromAnOfficeSizeValue(
  1040. ((DrawAreaCircle)drawArea).Radius);
  1041. coords = cx.ToString()+","+cy.ToString()+","+r.ToString();
  1042. html = html.Replace("#coords#", coords);
  1043. html = html.Replace("#type#", "circle");
  1044. }
  1045. }
  1046. }
  1047. catch(Exception ex)
  1048. {
  1049. throw new AODLException("Exception while trying to build a HTML string from a ImageMap object.", ex);
  1050. }
  1051. return html;
  1052. }
  1053. /// <summary>
  1054. /// Gets the graphic as HTML.
  1055. /// </summary>
  1056. /// <param name="graphic">The graphic.</param>
  1057. /// <returns></returns>
  1058. public string GetGraphicAsHtml(Graphic graphic)
  1059. {
  1060. //standard space around 12px
  1061. string html = "<img hspace=\"12\" vspace=\"12\" ";
  1062. try
  1063. {
  1064. if (graphic != null)
  1065. {
  1066. if (graphic.HRef != null)
  1067. html += "src=\""+this.GraphicTargetFolder+"/"+graphic.HRef+"\" ";
  1068. string graphStyle = "";
  1069. if (graphic.Frame != null)
  1070. graphStyle = this.HTMLStyleBuilder.GetFrameStyleAsHtml(graphic.Frame);
  1071. if (graphStyle.Length > 0)
  1072. html += graphStyle+" ";
  1073. //Image map?
  1074. if (this._nextImageMapName != null)
  1075. html += "usemap=\"#"+this._nextImageMapName+"\"";
  1076. html += ">\n";
  1077. }
  1078. }
  1079. catch(Exception ex)
  1080. {
  1081. throw new AODLException("Exception while trying to build a HTML string from a Graphic object.", ex);
  1082. }
  1083. if (!html.Equals("<img "))
  1084. html += "</img>\n";
  1085. else
  1086. html = "";
  1087. return html;
  1088. }
  1089. /// <summary>
  1090. /// Gets the unknow content as HTML.
  1091. /// AODL will try to search inside the node of the UnknownContent
  1092. /// object for content this could be displayed.
  1093. /// </summary>
  1094. /// <param name="unknownContent">Content of the unknown.</param>
  1095. /// <returns></returns>
  1096. public string GetUnknowContentAsHtml(UnknownContent unknownContent)
  1097. {
  1098. string html = "<span>\n";
  1099. try
  1100. {
  1101. if (unknownContent != null)
  1102. {
  1103. if (unknownContent.Node != null)
  1104. {
  1105. foreach(XElement node in ((XElement)unknownContent.Node).Elements())
  1106. if (node.Value != null)
  1107. html += this.ReplaceControlNodes(node.Value+" ");
  1108. }
  1109. }
  1110. }
  1111. catch(Exception ex)
  1112. {
  1113. throw new AODLException("Exception while trying to build a HTML string from a UnknownContent object.", ex);
  1114. }
  1115. if (!html.Equals("<span>\n"))
  1116. html += "</span>\n";
  1117. else
  1118. html = "";
  1119. return html;
  1120. }
  1121. /// <summary>
  1122. /// Gets the formated text as HTML.
  1123. /// </summary>
  1124. /// <param name="formatedText">The formated text.</param>
  1125. /// <returns></returns>
  1126. public string GetFormatedTextAsHtml(FormatedText formatedText)
  1127. {
  1128. string html = "<span ";
  1129. try
  1130. {
  1131. if (formatedText.TextContent != null)
  1132. {
  1133. string textStyle = "";
  1134. if (formatedText.TextStyle != null)
  1135. textStyle = this.HTMLStyleBuilder.GetTextStyleAsHtml(formatedText.TextStyle.TextProperties);
  1136. if (textStyle.Length > 0)
  1137. {
  1138. html += textStyle;
  1139. }
  1140. else
  1141. {
  1142. //Check again a possible common style
  1143. string commonstyle = "";
  1144. IStyle iStyle = formatedText.Document.CommonStyles.GetStyleByName(formatedText.StyleName);
  1145. if (iStyle != null && iStyle is TextStyle)
  1146. {
  1147. commonstyle = this.HTMLStyleBuilder.GetTextStyleAsHtml(((TextStyle)iStyle).TextProperties);
  1148. if (commonstyle.Length > 0)
  1149. html += commonstyle;
  1150. }
  1151. }
  1152. html += ">\n";
  1153. string textContent = this.GetITextCollectionAsHtml(formatedText.TextContent, null);
  1154. if (textContent.Length > 0)
  1155. {
  1156. // textContent = textContent.Replace("<", "&lt;");
  1157. // textContent = textContent.Replace(">", "&gt;");
  1158. html += textContent;
  1159. }
  1160. }
  1161. }
  1162. catch(Exception ex)
  1163. {
  1164. throw new AODLException("Exception while trying to build a HTML string from a FormatedText object.", ex);
  1165. }
  1166. if (!html.Equals("<span "))
  1167. html += "</span>\n";
  1168. else
  1169. html = "";
  1170. return html;
  1171. }
  1172. /// <summary>
  1173. /// Gets the X link as HTML.
  1174. /// </summary>
  1175. /// <param name="xLink">The x link.</param>
  1176. /// <returns></returns>
  1177. public string GetXLinkAsHtml(XLink xLink)
  1178. {
  1179. string html = "<a ";
  1180. try
  1181. {
  1182. if (xLink != null)
  1183. {
  1184. if (xLink.Href != null)
  1185. if (xLink.Href.ToLower().IndexOf("|outline") == -1)
  1186. html += "href=\""+xLink.Href+"\" ";
  1187. else
  1188. {
  1189. string anchor = this.GetAnchorLink(xLink.Href, xLink);
  1190. if (anchor != null)
  1191. html += "href=\"#"+anchor+"\" ";
  1192. else
  1193. html += "href=\""+xLink.Href+"\" ";
  1194. }
  1195. if (xLink.TargetFrameName != null)
  1196. html += "target=\""+xLink.TargetFrameName+"\">\n";
  1197. if (!html.EndsWith(">\n"))
  1198. html += ">\n";
  1199. string textContent = this.GetITextCollectionAsHtml(xLink.TextContent, null);
  1200. if (textContent.Length > 0)
  1201. html += textContent;
  1202. }
  1203. }
  1204. catch(Exception ex)
  1205. {
  1206. throw new AODLException("Exception while trying to build a HTML string from a XLink object.", ex);
  1207. }
  1208. if (!html.Equals("<a "))
  1209. html += "</a>\n";
  1210. else
  1211. html = "";
  1212. return html;
  1213. }
  1214. /// <summary>
  1215. /// Gets the anchor link.
  1216. /// </summary>
  1217. /// <param name="outlineLinkTarget">The outline link target.</param>
  1218. /// <param name="xLink">The x link.</param>
  1219. /// <returns></returns>
  1220. private string GetAnchorLink(string outlineLinkTarget, XLink xLink)
  1221. {
  1222. try
  1223. {
  1224. string replaceMent = "|outline";
  1225. outlineLinkTarget = outlineLinkTarget.Replace(replaceMent, "");
  1226. //Get only the last part of the target and try to match a header
  1227. //beginning afer char index 6 should be a good decision
  1228. //TODO: Build the outline numbering via the outline element from the global styles
  1229. outlineLinkTarget = outlineLinkTarget.Substring(6);
  1230. if (xLink.Document != null)
  1231. if (xLink.Document.Content != null)
  1232. foreach(IContent iContent in xLink.Document.Content)
  1233. if (iContent is Header)
  1234. if (((Header)iContent).OutLineLevel != null)
  1235. {
  1236. string headerText = "";
  1237. //Get text only
  1238. foreach(IText iText in ((Header)iContent).TextContent)
  1239. if (iText.Text != null)
  1240. headerText += iText.Text;
  1241. if (headerText.EndsWith(outlineLinkTarget))
  1242. return headerText;
  1243. }
  1244. }
  1245. catch(Exception ex)
  1246. {
  1247. if (OnWarning != null)
  1248. {
  1249. AODLWarning warning = new AODLWarning("Exception while trying to get an anchor string from a XLink object.", ex);
  1250. //warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true));
  1251. //warning.OriginalException = ex;
  1252. warning.Node = xLink.Node;
  1253. OnWarning(warning);
  1254. }
  1255. }
  1256. return null;
  1257. }
  1258. /// <summary>
  1259. /// Gets the unknow text content as HTML.
  1260. /// Maybe it's a bibliographic index or something else.
  1261. /// The method will try to find text that could be displayed.
  1262. /// </summary>
  1263. /// <param name="unknownTextContent">Content of the unknown text.</param>
  1264. /// <returns></returns>
  1265. public string GetUnknowTextContentAsHtml(UnknownTextContent unknownTextContent)
  1266. {
  1267. string html = "";
  1268. try
  1269. {
  1270. if (unknownTextContent != null)
  1271. {
  1272. if (unknownTextContent.Node != null)
  1273. html += this.ReplaceControlNodes(unknownTextContent.Node.Value);
  1274. }
  1275. }
  1276. catch(Exception ex)
  1277. {
  1278. throw new AODLException("Error rendering unknown text content as html", ex);
  1279. }
  1280. return html;
  1281. }
  1282. /// <summary>
  1283. /// Gets the tab stop as HTML.
  1284. /// Because of the fact that no tabstop html element exist,
  1285. /// AODL will try to simulate this with a the non breaking
  1286. /// line entity.
  1287. /// </summary>
  1288. /// <param name="tabStop">The tab stop.</param>
  1289. /// <param name="tabStopIndex">The tab stop position from all tabstops from the textcollectio,
  1290. /// where this tabstop belongs to.</param>
  1291. /// <param name="htmlStringBefore">The complete html string before this tabstop.</param>
  1292. /// <param name="paragraphStyle">The paragraph style from the enclosing paragraph.</param>
  1293. /// <returns></returns>
  1294. public string GetTabStopAsHtml(TabStop tabStop, int tabStopIndex, string htmlStringBefore, ParagraphStyle paragraphStyle)
  1295. {
  1296. //simulate a tabstop in html
  1297. string htmlTab = "&nbsp;&nbsp;&nbsp;&nbsp;";
  1298. string html = "";
  1299. try
  1300. {
  1301. if (paragraphStyle != null)
  1302. if (paragraphStyle.ParagraphProperties != null)
  1303. if (paragraphStyle.ParagraphProperties.TabStopStyleCollection != null)
  1304. if (paragraphStyle.ParagraphProperties.TabStopStyleCollection.Count-1 <= tabStopIndex)
  1305. {
  1306. TabStopStyle tabStopStyle = paragraphStyle.ParagraphProperties.TabStopStyleCollection[tabStopIndex];
  1307. string leadingChar = "&nbsp;";
  1308. if (tabStopStyle.LeaderText != null)
  1309. leadingChar = tabStopStyle.LeaderText;
  1310. string[] grabInt = tabStopStyle.Position.Split('.');
  1311. if (grabInt.Length == 2)
  1312. {
  1313. double position = Convert.ToDouble(grabInt[0]);
  1314. //expecting that one displaying character will ~ .5cm
  1315. if (htmlStringBefore != null)
  1316. {
  1317. for(int i=0; i<htmlStringBefore.Length; i++)
  1318. position -= 0.5;
  1319. }
  1320. if (position > 0.5)
  1321. for(double i=0; i<position; i+=0.25)
  1322. html += leadingChar;
  1323. }
  1324. }
  1325. }
  1326. catch(Exception ex)
  1327. {
  1328. if (OnWarning != null)
  1329. {
  1330. AODLWarning warning = new AODLWarning("Exception while trying to build a simulated html tabstop.", ex);
  1331. //warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true));
  1332. //warning.OriginalException = ex;
  1333. OnWarning(warning);
  1334. }
  1335. }
  1336. if (html.Length == 0)
  1337. html = htmlTab;
  1338. return html;
  1339. }
  1340. /// <summary>
  1341. /// Gets the white spaces as HTML.
  1342. /// </summary>
  1343. /// <param name="whiteSpace">The white space.</param>
  1344. /// <returns></returns>
  1345. public string GetWhiteSpacesAsHtml(WhiteSpace whiteSpace)
  1346. {
  1347. string html = "";
  1348. int count = 0;
  1349. try
  1350. {
  1351. if (whiteSpace.Count != null)
  1352. count = Convert.ToInt32(whiteSpace.Count);
  1353. for(int i=0; i<count; i++)
  1354. html += "&nbsp;";
  1355. }
  1356. catch(Exception ex)
  1357. {
  1358. //send warning
  1359. if (OnWarning != null)
  1360. {
  1361. AODLWarning warning = new AODLWarning("Exception while trying to build HTML whitespaces.", ex);
  1362. //warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true));
  1363. //warning.OriginalException = ex;
  1364. OnWarning(warning);
  1365. }
  1366. }
  1367. return html;
  1368. }
  1369. /// <summary>
  1370. /// Gets the line break as HTML.
  1371. /// </summary>
  1372. /// <returns></returns>
  1373. public string GetLineBreakAsHtml()
  1374. {
  1375. return "<br>\n";
  1376. }
  1377. /// <summary>
  1378. /// Replaces the control nodes.
  1379. /// </summary>
  1380. /// <param name="text">The text.</param>
  1381. /// <returns>The cleaned text</returns>
  1382. private string ReplaceControlNodes(string text)
  1383. {
  1384. try
  1385. {
  1386. text = text.Replace("<", "&lt;");
  1387. text = text.Replace(">", "&gt;");
  1388. }
  1389. catch(Exception)
  1390. {
  1391. //unhandled, only some textnodes will be left
  1392. }
  1393. return text;
  1394. }
  1395. }
  1396. }
  1397. /*
  1398. * $Log: HTMLContentBuilder.cs,v $
  1399. * Revision 1.8 2008/04/29 15:39:48 mt
  1400. * new copyright header
  1401. *
  1402. * Revision 1.7 2007/07/15 09:30:06 yegorov
  1403. * Issue number:
  1404. * Submitted by:
  1405. * Reviewed by:
  1406. *
  1407. * Revision 1.5 2007/06/20 17:37:18 yegorov
  1408. * Issue number:
  1409. * Submitted by:
  1410. * Reviewed by:
  1411. *
  1412. * Revision 1.2 2007/04/08 16:51:30 larsbehr
  1413. * - finished master pages and styles for text documents
  1414. * - several bug fixes
  1415. *
  1416. * Revision 1.1 2007/02/25 08:58:43 larsbehr
  1417. * initial checkin, import from Sourceforge.net to OpenOffice.org
  1418. *
  1419. * Revision 1.4 2006/02/21 19:34:55 larsbm
  1420. * - Fixed Bug text that contains a xml tag will be imported as UnknowText and not correct displayed if document is exported as HTML.
  1421. * - Fixed Bug [ 1436080 ] Common styles
  1422. *
  1423. * Revision 1.3 2006/02/05 20:03:32 larsbm
  1424. * - Fixed several bugs
  1425. * - clean up some messy code
  1426. *
  1427. * Revision 1.2 2006/01/29 18:52:14 larsbm
  1428. * - Added support for common styles (style templates in OpenOffice)
  1429. * - Draw TextBox import and export
  1430. * - DrawTextBox html export
  1431. *
  1432. * Revision 1.1 2006/01/29 11:28:23 larsbm
  1433. * - Changes for the new version. 1.2. see next changelog for details
  1434. *
  1435. */