HTMLUtil.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Text;
  30. namespace OpenSim.Region.UserStatistics
  31. {
  32. public static class HTMLUtil
  33. {
  34. public static void TR_O(ref StringBuilder o, string pclass)
  35. {
  36. o.Append("<tr");
  37. if (pclass.Length > 0)
  38. {
  39. GenericClass(ref o, pclass);
  40. }
  41. o.Append(">\n\t");
  42. }
  43. public static void TR_C(ref StringBuilder o)
  44. {
  45. o.Append("</tr>\n");
  46. }
  47. public static void TD_O(ref StringBuilder o, string pclass)
  48. {
  49. TD_O(ref o, pclass, 0, 0);
  50. }
  51. public static void TD_O(ref StringBuilder o, string pclass, int rowspan, int colspan)
  52. {
  53. o.Append("<td");
  54. if (pclass.Length > 0)
  55. {
  56. GenericClass(ref o, pclass);
  57. }
  58. if (rowspan > 1)
  59. {
  60. o.Append(" rowspan=\"");
  61. o.Append(rowspan);
  62. o.Append("\"");
  63. }
  64. if (colspan > 1)
  65. {
  66. o.Append(" colspan=\"");
  67. o.Append(colspan);
  68. o.Append("\"");
  69. }
  70. o.Append(">");
  71. }
  72. public static void TD_C(ref StringBuilder o)
  73. {
  74. o.Append("</td>");
  75. }
  76. public static void TABLE_O(ref StringBuilder o, string pclass)
  77. {
  78. o.Append("<table");
  79. if (pclass.Length > 0)
  80. {
  81. GenericClass(ref o, pclass);
  82. }
  83. o.Append(">\n\t");
  84. }
  85. public static void TABLE_C(ref StringBuilder o)
  86. {
  87. o.Append("</table>\n");
  88. }
  89. public static void BLOCKQUOTE_O(ref StringBuilder o, string pclass)
  90. {
  91. o.Append("<blockquote");
  92. if (pclass.Length > 0)
  93. {
  94. GenericClass(ref o, pclass);
  95. }
  96. o.Append(" />\n");
  97. }
  98. public static void BLOCKQUOTE_C(ref StringBuilder o)
  99. {
  100. o.Append("</blockquote>\n");
  101. }
  102. public static void BR(ref StringBuilder o)
  103. {
  104. o.Append("<br />\n");
  105. }
  106. public static void HR(ref StringBuilder o, string pclass)
  107. {
  108. o.Append("<hr");
  109. if (pclass.Length > 0)
  110. {
  111. GenericClass(ref o, pclass);
  112. }
  113. o.Append(" />\n");
  114. }
  115. public static void UL_O(ref StringBuilder o, string pclass)
  116. {
  117. o.Append("<ul");
  118. if (pclass.Length > 0)
  119. {
  120. GenericClass(ref o, pclass);
  121. }
  122. o.Append(" />\n");
  123. }
  124. public static void UL_C(ref StringBuilder o)
  125. {
  126. o.Append("</ul>\n");
  127. }
  128. public static void OL_O(ref StringBuilder o, string pclass)
  129. {
  130. o.Append("<ol");
  131. if (pclass.Length > 0)
  132. {
  133. GenericClass(ref o, pclass);
  134. }
  135. o.Append(" />\n");
  136. }
  137. public static void OL_C(ref StringBuilder o)
  138. {
  139. o.Append("</ol>\n");
  140. }
  141. public static void LI_O(ref StringBuilder o, string pclass)
  142. {
  143. o.Append("<li");
  144. if (pclass.Length > 0)
  145. {
  146. GenericClass(ref o, pclass);
  147. }
  148. o.Append(" />\n");
  149. }
  150. public static void LI_C(ref StringBuilder o)
  151. {
  152. o.Append("</li>\n");
  153. }
  154. public static void GenericClass(ref StringBuilder o, string pclass)
  155. {
  156. o.Append(" class=\"");
  157. o.Append(pclass);
  158. o.Append("\"");
  159. }
  160. public static void InsertProtoTypeAJAX(ref StringBuilder o)
  161. {
  162. o.Append("<script type=\"text/javascript\" src=\"prototype.js\"></script>\n");
  163. o.Append("<script type=\"text/javascript\" src=\"updater.js\"></script>\n");
  164. }
  165. public static void InsertPeriodicUpdaters(ref StringBuilder o, string[] divID, int[] seconds, string[] reportfrag)
  166. {
  167. o.Append("<script type=\"text/javascript\">\n");
  168. o.Append(
  169. @"
  170. // <![CDATA[
  171. document.observe('dom:loaded', function() {
  172. /*
  173. first arg : div to update
  174. second arg : interval to poll in seconds
  175. third arg : file to get data
  176. */
  177. ");
  178. for (int i = 0; i < divID.Length; i++)
  179. {
  180. o.Append("new updater('");
  181. o.Append(divID[i]);
  182. o.Append("', ");
  183. o.Append(seconds[i]);
  184. o.Append(", '");
  185. o.Append(reportfrag[i]);
  186. o.Append("');\n");
  187. }
  188. o.Append(@"
  189. });
  190. // ]]>
  191. </script>");
  192. }
  193. public static void HtmlHeaders_O ( ref StringBuilder o)
  194. {
  195. o.Append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n");
  196. o.Append("<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"nl\">");
  197. o.Append("<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />");
  198. }
  199. public static void HtmlHeaders_C ( ref StringBuilder o)
  200. {
  201. o.Append("</HEAD>");
  202. o.Append("<BODY>");
  203. }
  204. public static void AddReportLinks( ref StringBuilder o, Dictionary<string, IStatsController> reports, string pClass)
  205. {
  206. int repcount = 0;
  207. foreach (string str in reports.Keys)
  208. {
  209. if (reports[str].ReportName.Length > 0)
  210. {
  211. if (repcount > 0)
  212. {
  213. o.Append("|&nbsp;&nbsp;");
  214. }
  215. A(ref o, reports[str].ReportName, str, pClass);
  216. o.Append("&nbsp;&nbsp;");
  217. repcount++;
  218. }
  219. }
  220. }
  221. public static void A( ref StringBuilder o, string linktext, string linkhref, string pClass)
  222. {
  223. o.Append("<A");
  224. if (pClass.Length > 0)
  225. {
  226. GenericClass(ref o, pClass);
  227. }
  228. o.Append(" href=\"");
  229. o.Append(linkhref);
  230. o.Append("\">");
  231. o.Append(linktext);
  232. o.Append("</A>");
  233. }
  234. }
  235. }