Xml.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /**
  2. * Namespace: System.Web.UI.WebControls
  3. * Class: Xml
  4. *
  5. * Author: Gaurav Vaish
  6. * Maintainer: [email protected]
  7. * Contact: <[email protected]>, <[email protected]>
  8. * Implementation: yes
  9. * Status: 75%
  10. *
  11. * (C) Gaurav Vaish (2002)
  12. */
  13. using System;
  14. using System.IO;
  15. using System.Xml;
  16. using System.Xml.Xsl;
  17. using System.Xml.XPath;
  18. using System.Web;
  19. using System.Web.UI;
  20. namespace System.Web.UI.WebControls
  21. {
  22. public class Xml : Control
  23. {
  24. private XmlDocument document;
  25. private string documentContent;
  26. private string documentSource;
  27. private XslTransform transform;
  28. private XsltArgumentList transformArgumentList;
  29. private string transformSource;
  30. private XPathDocument xpathDoc;
  31. private static XslTransform defaultTransform;
  32. static Xml()
  33. {
  34. XmlTextReader reader = new XmlTextReader(new StringReader("<xsl:stylesheet version='1.0' " +
  35. "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>" +
  36. "<xsl:template match=\"\">" +
  37. "<xsl:copy-of select=\".\"/>" +
  38. "</xsl:template>" +
  39. "</xsl:stylesheet>"));
  40. defaultTransform = new XslTransform();
  41. defaultTransform.Load(reader);
  42. }
  43. public Xml(): base()
  44. {
  45. }
  46. [MonoTODO("Initialize_Document")]
  47. private void LoadXmlDoc()
  48. {
  49. throw new NotImplementedException();
  50. }
  51. public XmlDocument Document
  52. {
  53. get
  54. {
  55. if(document == null)
  56. LoadXmlDoc();
  57. return document;
  58. }
  59. set
  60. {
  61. documentSource = null;
  62. documentContent = null;
  63. xpathDoc = null;
  64. document = value;
  65. }
  66. }
  67. public string DocumentContent
  68. {
  69. get
  70. {
  71. return String.Empty;
  72. }
  73. set
  74. {
  75. document = null;
  76. xpathDoc = null;
  77. documentContent = value;
  78. }
  79. }
  80. public string DocumentSource
  81. {
  82. get
  83. {
  84. if(documentSource != null)
  85. return documentSource;
  86. return String.Empty;
  87. }
  88. set
  89. {
  90. document = null;
  91. documentContent = null;
  92. xpathDoc = null;
  93. documentSource = value;
  94. }
  95. }
  96. public XslTransform Transform
  97. {
  98. get
  99. {
  100. return transform;
  101. }
  102. set
  103. {
  104. transformSource = null;
  105. transform = value;
  106. }
  107. }
  108. public string TransformSource
  109. {
  110. get
  111. {
  112. if(transformSource != null)
  113. return transformSource;
  114. return String.Empty;
  115. }
  116. set
  117. {
  118. transform = null;
  119. transformSource = value;
  120. }
  121. }
  122. public XsltArgumentList TransformArgumentList
  123. {
  124. get
  125. {
  126. return transformArgumentList;
  127. }
  128. set
  129. {
  130. transformArgumentList = value;
  131. }
  132. }
  133. protected override void AddParsedSubObject(object obj)
  134. {
  135. if(obj is LiteralControl)
  136. {
  137. DocumentContent = ((LiteralControl)obj).Text;
  138. return;
  139. }
  140. throw new HttpException(HttpRuntime.FormatResourceString("Cannot_Have_Children_of_Type", "Xml", GetType().Name.ToString()));
  141. }
  142. [MonoTODO("Initialize_xpathDocument")]
  143. private void LoadXpathDoc()
  144. {
  145. if(documentContent != null && documentContent.Length > 0)
  146. {
  147. xpathDoc = new XPathDocument(new StringReader(documentContent));
  148. return;
  149. }
  150. if(documentSource == null || documentSource.Length == 0)
  151. {
  152. return;
  153. }
  154. throw new NotImplementedException();
  155. }
  156. [MonoTODO("Initialize_Transform")]
  157. private void LoadTransform()
  158. {
  159. throw new ArgumentException();
  160. }
  161. [MonoTODO]
  162. protected override void Render(HtmlTextWriter output)
  163. {
  164. if(document == null)
  165. {
  166. LoadXpathDoc();
  167. }
  168. LoadTransform();
  169. if(document == null || xpathDoc == null)
  170. {
  171. return;
  172. }
  173. if(transform == null)
  174. {
  175. transform = defaultTransform;
  176. }
  177. if(document != null)
  178. {
  179. Transform.Transform(document, transformArgumentList, output);
  180. return;
  181. }
  182. Transform.Transform(xpathDoc, transformArgumentList, output);
  183. }
  184. }
  185. }