Xml.cs 4.2 KB

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