Xml.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. //
  2. // System.Web.UI.WebControls.Xml.cs
  3. //
  4. // Authors:
  5. // Miguel de Icaza ([email protected])
  6. //
  7. // (C) 2005 Novell, Inc (http://www.novell.com)
  8. //
  9. //
  10. // Permission is hereby granted, free of charge, to any person obtaining
  11. // a copy of this software and associated documentation files (the
  12. // "Software"), to deal in the Software without restriction, including
  13. // without limitation the rights to use, copy, modify, merge, publish,
  14. // distribute, sublicense, and/or sell copies of the Software, and to
  15. // permit persons to whom the Software is furnished to do so, subject to
  16. // the following conditions:
  17. //
  18. // The above copyright notice and this permission notice shall be
  19. // included in all copies or substantial portions of the Software.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  22. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  23. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  24. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  25. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  26. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  27. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  28. //
  29. using System;
  30. using System.Xml;
  31. using System.Xml.Xsl;
  32. using System.Web;
  33. using System.Web.UI;
  34. using System.ComponentModel;
  35. #if NET_2_0
  36. using System.Xml.XPath;
  37. using System.Collections;
  38. #endif
  39. namespace System.Web.UI.WebControls {
  40. [DefaultProperty ("DocumentSource")]
  41. [Designer ("System.Web.UI.Design.WebControls.XmlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
  42. [PersistChildren (false)]
  43. [ControlBuilder (typeof (XmlBuilder))]
  44. public class Xml : Control {
  45. // Property set variables
  46. XmlDocument xml_document;
  47. string xml_content;
  48. string xml_file;
  49. XslTransform xsl_transform;
  50. XsltArgumentList transform_arguments;
  51. string transform_file;
  52. public Xml ()
  53. {
  54. }
  55. #if NET_2_0
  56. [EditorBrowsable (EditorBrowsableState.Never)]
  57. [MonoTODO]
  58. public override string ClientID
  59. {
  60. get {
  61. throw new NotImplementedException ();
  62. }
  63. }
  64. [EditorBrowsable (EditorBrowsableState.Never)]
  65. [MonoTODO]
  66. public override ControlCollection Controls
  67. {
  68. get {
  69. throw new NotImplementedException ();
  70. }
  71. }
  72. #endif
  73. [Browsable(false)]
  74. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  75. #if NET_2_0
  76. [Obsolete ("Use the XPathNavigator property instead by creating an XPathDocument and calling CreateNavigator().")]
  77. #endif
  78. public XmlDocument Document {
  79. get {
  80. return xml_document;
  81. }
  82. set {
  83. xml_content = null;
  84. xml_file = null;
  85. xml_document = value;
  86. }
  87. }
  88. [Browsable(false)]
  89. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  90. public string DocumentContent {
  91. get {
  92. return "";
  93. }
  94. set {
  95. xml_content = value;
  96. xml_file = null;
  97. xml_document = null;
  98. }
  99. }
  100. #if ONLY_1_1
  101. [Bindable (true)]
  102. #endif
  103. [DefaultValue ("")]
  104. #if NET_2_0
  105. [UrlProperty]
  106. [Editor ("System.Web.UI.Design.XmlUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  107. #else
  108. [Editor ("System.Web.UI.Design.XmlUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
  109. #endif
  110. [WebSysDescription ("")]
  111. [WebCategory ("Behavior")]
  112. public string DocumentSource {
  113. get {
  114. if (xml_file == null)
  115. return "";
  116. return xml_file;
  117. }
  118. set {
  119. xml_content = null;
  120. xml_file = value;
  121. xml_document = null;
  122. }
  123. }
  124. #if NET_2_0
  125. [EditorBrowsable (EditorBrowsableState.Never)]
  126. [Browsable (false)]
  127. [DefaultValue (false)]
  128. [MonoTODO]
  129. public override bool EnableTheming
  130. {
  131. get {
  132. throw new NotImplementedException ();
  133. }
  134. set {
  135. throw new NotImplementedException ();
  136. }
  137. }
  138. [DefaultValue ("")]
  139. [EditorBrowsable (EditorBrowsableState.Never)]
  140. [Browsable (false)]
  141. [MonoTODO]
  142. public override string SkinID
  143. {
  144. get {
  145. throw new NotImplementedException ();
  146. }
  147. set {
  148. throw new NotImplementedException ();
  149. }
  150. }
  151. #endif
  152. [Browsable (false)]
  153. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  154. [WebSysDescription ("")]
  155. [WebCategory ("Behavior")]
  156. public XslTransform Transform {
  157. get {
  158. return xsl_transform;
  159. }
  160. set {
  161. transform_file = null;
  162. xsl_transform = value;
  163. }
  164. }
  165. [Browsable (false)]
  166. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  167. [WebSysDescription ("")]
  168. [WebCategory ("Behavior")]
  169. public XsltArgumentList TransformArgumentList {
  170. get {
  171. return transform_arguments;
  172. }
  173. set {
  174. transform_arguments = value;
  175. }
  176. }
  177. #if ONLY_1_1
  178. [Bindable (true)]
  179. #endif
  180. [DefaultValue ("")]
  181. #if NET_2_0
  182. [Editor ("System.Web.UI.Design.XslUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  183. #else
  184. [Editor ("System.Web.UI.Design.XslUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
  185. #endif
  186. public string TransformSource {
  187. get {
  188. if (transform_file == null)
  189. return "";
  190. return transform_file;
  191. }
  192. set {
  193. transform_file = value;
  194. xsl_transform = null;
  195. }
  196. }
  197. #if NET_2_0
  198. [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
  199. [Browsable (false)]
  200. [MonoTODO]
  201. public XPathNavigator XPathNavigator
  202. {
  203. get {
  204. throw new NotImplementedException ();
  205. }
  206. set {
  207. throw new NotImplementedException ();
  208. }
  209. }
  210. [EditorBrowsable (EditorBrowsableState.Never)]
  211. [MonoTODO]
  212. public override Control FindControl (string id)
  213. {
  214. throw new NotImplementedException ();
  215. }
  216. [EditorBrowsable (EditorBrowsableState.Never)]
  217. [MonoTODO]
  218. public override void Focus ()
  219. {
  220. throw new NotImplementedException ();
  221. }
  222. [EditorBrowsable (EditorBrowsableState.Never)]
  223. [MonoTODO]
  224. public override bool HasControls ()
  225. {
  226. throw new NotImplementedException ();
  227. }
  228. #endif
  229. #if NET_2_0
  230. protected internal
  231. #else
  232. protected
  233. #endif
  234. override void Render (HtmlTextWriter output)
  235. {
  236. XmlDocument xml_doc;
  237. if (xml_document != null)
  238. xml_doc = xml_document;
  239. else {
  240. if (xml_content != null){
  241. xml_doc = new XmlDocument ();
  242. xml_doc.LoadXml (xml_content);
  243. } else if (xml_file != null){
  244. xml_doc = new XmlDocument ();
  245. xml_doc.Load (MapPathSecure (xml_file));
  246. } else
  247. return;
  248. }
  249. XslTransform t = xsl_transform;
  250. if (transform_file != null){
  251. t = new XslTransform ();
  252. t.Load (MapPathSecure (transform_file));
  253. }
  254. if (t != null){
  255. t.Transform (xml_doc, transform_arguments, output, null);
  256. return;
  257. }
  258. XmlTextWriter xmlwriter = new XmlTextWriter (output);
  259. xmlwriter.Formatting = Formatting.None;
  260. xml_doc.Save (xmlwriter);
  261. }
  262. protected override void AddParsedSubObject (object obj)
  263. {
  264. LiteralControl lc = obj as LiteralControl;
  265. if (lc != null){
  266. xml_document = new XmlDocument ();
  267. xml_document.LoadXml (lc.Text);
  268. } else {
  269. throw new HttpException (
  270. String.Format ("Objects of type {0} are not supported as children of the Xml control",
  271. obj.GetType ()));
  272. }
  273. }
  274. #if NET_2_0
  275. [MonoTODO]
  276. protected override ControlCollection CreateControlCollection ()
  277. {
  278. throw new NotImplementedException ();
  279. }
  280. [MonoTODO]
  281. protected override IDictionary GetDesignModeState ()
  282. {
  283. throw new NotImplementedException ();
  284. }
  285. #endif
  286. }
  287. }