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