Merge pull request #2781 from alexanderkyte/inflated_method_header_leak
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / Xml.cs
1 //
2 // System.Web.UI.WebControls.Xml.cs
3 //
4 // Authors:
5 //      Miguel de Icaza (miguel@novell.com)
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
30 using System.ComponentModel;
31 using System.Security.Permissions;
32 using System.Xml;
33 using System.Xml.Xsl;
34
35 using System.Xml.XPath;
36 using System.Collections;
37
38 namespace System.Web.UI.WebControls {
39
40         // CAS
41         [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
42         [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
43         // attributes
44         [DefaultProperty ("DocumentSource")]
45         [Designer ("System.Web.UI.Design.WebControls.XmlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
46         [PersistChildren (true)]
47         [ControlBuilder (typeof (XmlBuilder))] 
48         public class Xml : Control {
49                 // Property set variables
50                 XmlDocument xml_document;
51                 XPathNavigator xpath_navigator;
52                 string xml_content;
53                 string xml_file;
54
55                 XslTransform xsl_transform;
56                 XsltArgumentList transform_arguments;
57                 string transform_file;
58
59                 public Xml ()
60                 {
61                 }
62
63                 [EditorBrowsable (EditorBrowsableState.Never)]
64                 [MonoTODO ("Anything else?")]
65                 public override string ClientID
66                 {
67                         get {
68                                 return base.ClientID;
69                         }
70                 }
71
72                 [MonoTODO ("Anything else?")]
73                 [EditorBrowsable (EditorBrowsableState.Never)]
74                 public override ControlCollection Controls 
75                 {
76                         get {
77                                 return base.Controls;
78                         }
79                 }
80                 
81
82                 [Browsable(false)]
83                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
84 [Obsolete ("Use the XPathNavigator property instead by creating an XPathDocument and calling CreateNavigator().")]
85                 public XmlDocument Document {
86                         get {
87                                 return xml_document;
88                         }
89
90                         set {
91                                 xml_content = null;
92                                 xml_file = null;
93                                 xml_document = value;
94                         }
95                 }
96
97                 [Browsable(false)]
98                 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
99                 public string DocumentContent {
100                         get {
101                                 return (xml_content != null)? xml_content : "";
102                         }
103
104                         set {
105                                 xml_content = value;
106                                 xml_file = null;
107                                 xml_document = null;
108                         }
109                 }
110
111                 [DefaultValue ("")]
112                 [UrlProperty]
113                 [Editor ("System.Web.UI.Design.XmlUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
114                 [WebSysDescription ("")]
115                 [WebCategory ("Behavior")]
116                 [MonoLimitation ("Absolute path to the file system is not supported; use a relative URI instead.")]
117                 public string DocumentSource {
118                         get {
119                                 if (xml_file == null)
120                                         return "";
121                                 
122                                 return xml_file;
123                         }
124
125                         set {
126                                 xml_content = null;
127                                 xml_file = value;
128                                 xml_document = null;
129                         }
130                 }
131
132                 [EditorBrowsable (EditorBrowsableState.Never)]
133                 [Browsable (false)]
134                 [DefaultValue (false)]
135                 public override bool EnableTheming 
136                 {
137                         get { return false; }
138                         set { throw new NotSupportedException (); }
139                 }
140
141                 [DefaultValue ("")]
142                 [EditorBrowsable (EditorBrowsableState.Never)]
143                 [Browsable (false)]
144                 public override string SkinID
145                 {
146                         // MSDN: Always returns an empty string (""). This property is not supported.
147                         get { return String.Empty; }
148                         // MSDN: Any attempt to set the value of this property throws a NotSupportedException exception.
149                         set { throw new NotSupportedException ("SkinID is not supported on Xml control"); }
150                 }
151                 
152
153                 [Browsable (false)]
154                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
155                 [WebSysDescription ("")]
156                 [WebCategory ("Behavior")]
157                 public XslTransform Transform {
158                         get {
159                                 return xsl_transform;
160                         }
161
162                         set {
163                                 transform_file = null;
164                                 xsl_transform = value;
165                         }
166                 }
167
168                 [Browsable (false)]
169                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
170                 [WebSysDescription ("")]
171                 [WebCategory ("Behavior")]
172                 public XsltArgumentList TransformArgumentList {
173                         get {
174                                 return transform_arguments;
175                         }
176
177                         set {
178                                 transform_arguments = value;
179                         }
180                 }
181
182                 [DefaultValue ("")]
183                 [Editor ("System.Web.UI.Design.XslUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
184                 [MonoLimitation ("Absolute path to the file system is not supported; use a relative URI instead.")]
185                 public string TransformSource {
186                         get {
187                                 if (transform_file == null)
188                                         return "";
189                                 return transform_file;
190                         }
191
192                         set {
193                                 transform_file = value;
194                                 xsl_transform = null;
195                         }
196                 }
197
198                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
199                 [Browsable (false)]
200                 public XPathNavigator XPathNavigator 
201                 {
202                         get { return xpath_navigator; }
203                         set { xpath_navigator = value; }
204                 }
205
206                 [EditorBrowsable (EditorBrowsableState.Never)]
207                 public override Control FindControl (string id) 
208                 {
209                         return null;
210                 }
211
212                 [EditorBrowsable (EditorBrowsableState.Never)]
213                 public override void Focus ()
214                 {
215                         throw new NotSupportedException ();
216                 }
217
218                 [EditorBrowsable (EditorBrowsableState.Never)]
219                 public override bool HasControls ()
220                 {
221                         return false;
222                 }
223
224                 protected internal
225                 override void Render (HtmlTextWriter output)
226                 {
227                         XmlDocument xml_doc = null;
228
229                         if (xpath_navigator == null) {
230                                 if (xml_document != null)
231                                         xml_doc = xml_document;
232                                 else {
233                                         if (xml_content != null) {
234                                                 xml_doc = new XmlDocument ();
235                                                 xml_doc.LoadXml (xml_content);
236                                         }
237                                         else if (xml_file != null) {
238                                                 xml_doc = new XmlDocument ();
239                                                 xml_doc.Load (MapPathSecure (xml_file));
240                                         }
241                                         else
242                                                 return;
243                                 }
244                         }
245
246                         XslTransform t = xsl_transform;
247                         if (transform_file != null){
248                                 t = new XslTransform ();
249                                 t.Load (MapPathSecure (transform_file));
250                         }
251
252                         if (t != null){
253                                 if (xpath_navigator != null) {
254                                         t.Transform(xpath_navigator, transform_arguments, output);
255                                 }
256                                 else {
257                                         t.Transform (xml_doc, transform_arguments, output, null);
258                                 }
259                                 return;
260                         }
261                                 
262                         XmlTextWriter xmlwriter = new XmlTextWriter (output);
263                         xmlwriter.Formatting = Formatting.None;
264                         if (xpath_navigator != null) {
265                                 xmlwriter.WriteStartDocument ();
266                                 xpath_navigator.WriteSubtree (xmlwriter);
267                         }
268                         else {
269                                 xml_doc.Save (xmlwriter);
270                         }
271                 }
272
273                 protected override void AddParsedSubObject (object obj)
274                 {
275                         LiteralControl lc = obj as LiteralControl;
276                         
277                         if (lc != null){
278                                 xml_document = new XmlDocument ();
279                                 xml_document.LoadXml (lc.Text);
280                         } else {
281                                 throw new HttpException (
282                                                          String.Format ("Objects of type {0} are not supported as children of the Xml control",
283                                                                         obj.GetType ()));
284                         }
285                 }
286
287                 protected override ControlCollection CreateControlCollection ()
288                 {
289                         return new EmptyControlCollection (this);
290                 }
291
292                 [MonoTODO("Always returns null")]
293                 protected override IDictionary GetDesignModeState ()
294                 {
295                         return null;
296                 }
297         }
298 }