2 // System.Web.UI.WebControls.Xml.cs
5 // Miguel de Icaza (miguel@novell.com)
7 // (C) 2005 Novell, Inc (http://www.novell.com)
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
30 using System.ComponentModel;
31 using System.Security.Permissions;
36 using System.Xml.XPath;
37 using System.Collections;
40 namespace System.Web.UI.WebControls {
43 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
44 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
46 [DefaultProperty ("DocumentSource")]
47 [Designer ("System.Web.UI.Design.WebControls.XmlDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
49 [PersistChildren (true)]
51 [PersistChildren (false)]
53 [ControlBuilder (typeof (XmlBuilder))]
54 public class Xml : Control {
55 // Property set variables
56 XmlDocument xml_document;
58 XPathNavigator xpath_navigator;
63 XslTransform xsl_transform;
64 XsltArgumentList transform_arguments;
65 string transform_file;
72 [EditorBrowsable (EditorBrowsableState.Never)]
73 [MonoTODO ("Anything else?")]
74 public override string ClientID
81 [MonoTODO ("Anything else?")]
82 [EditorBrowsable (EditorBrowsableState.Never)]
83 public override ControlCollection Controls
93 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
95 [Obsolete ("Use the XPathNavigator property instead by creating an XPathDocument and calling CreateNavigator().")]
97 public XmlDocument Document {
105 xml_document = value;
110 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
111 public string DocumentContent {
114 return (xml_content != null)? xml_content : "";
133 [Editor ("System.Web.UI.Design.XmlUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
135 [Editor ("System.Web.UI.Design.XmlUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
137 [WebSysDescription ("")]
138 [WebCategory ("Behavior")]
139 [MonoLimitation ("Absolute path to the file system is not supported; use a relative URI instead.")]
140 public string DocumentSource {
142 if (xml_file == null)
156 [EditorBrowsable (EditorBrowsableState.Never)]
158 [DefaultValue (false)]
159 public override bool EnableTheming
161 get { return false; }
162 set { throw new NotSupportedException (); }
166 [EditorBrowsable (EditorBrowsableState.Never)]
168 public override string SkinID
170 // MSDN: Always returns an empty string (""). This property is not supported.
171 get { return String.Empty; }
172 // MSDN: Any attempt to set the value of this property throws a NotSupportedException exception.
173 set { throw new NotSupportedException ("SkinID is not supported on Xml control"); }
179 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
180 [WebSysDescription ("")]
181 [WebCategory ("Behavior")]
182 public XslTransform Transform {
184 return xsl_transform;
188 transform_file = null;
189 xsl_transform = value;
194 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
195 [WebSysDescription ("")]
196 [WebCategory ("Behavior")]
197 public XsltArgumentList TransformArgumentList {
199 return transform_arguments;
203 transform_arguments = value;
212 [Editor ("System.Web.UI.Design.XslUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
214 [Editor ("System.Web.UI.Design.XslUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
216 [MonoLimitation ("Absolute path to the file system is not supported; use a relative URI instead.")]
217 public string TransformSource {
219 if (transform_file == null)
221 return transform_file;
225 transform_file = value;
226 xsl_transform = null;
231 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
233 public XPathNavigator XPathNavigator
235 get { return xpath_navigator; }
236 set { xpath_navigator = value; }
239 [EditorBrowsable (EditorBrowsableState.Never)]
240 public override Control FindControl (string id)
245 [EditorBrowsable (EditorBrowsableState.Never)]
246 public override void Focus ()
248 throw new NotSupportedException ();
251 [EditorBrowsable (EditorBrowsableState.Never)]
252 public override bool HasControls ()
263 override void Render (HtmlTextWriter output)
265 XmlDocument xml_doc = null;
268 if (xpath_navigator == null) {
270 if (xml_document != null)
271 xml_doc = xml_document;
273 if (xml_content != null) {
274 xml_doc = new XmlDocument ();
275 xml_doc.LoadXml (xml_content);
277 else if (xml_file != null) {
278 xml_doc = new XmlDocument ();
279 xml_doc.Load (MapPathSecure (xml_file));
288 XslTransform t = xsl_transform;
289 if (transform_file != null){
290 t = new XslTransform ();
291 t.Load (MapPathSecure (transform_file));
296 if (xpath_navigator != null) {
297 t.Transform(xpath_navigator, transform_arguments, output);
301 t.Transform (xml_doc, transform_arguments, output, null);
308 XmlTextWriter xmlwriter = new XmlTextWriter (output);
309 xmlwriter.Formatting = Formatting.None;
311 if (xpath_navigator != null) {
312 xmlwriter.WriteStartDocument ();
313 xpath_navigator.WriteSubtree (xmlwriter);
317 xml_doc.Save (xmlwriter);
323 protected override void AddParsedSubObject (object obj)
325 LiteralControl lc = obj as LiteralControl;
328 xml_document = new XmlDocument ();
329 xml_document.LoadXml (lc.Text);
331 throw new HttpException (
332 String.Format ("Objects of type {0} are not supported as children of the Xml control",
338 protected override ControlCollection CreateControlCollection ()
340 return new EmptyControlCollection (this);
343 [MonoTODO("Always returns null")]
344 protected override IDictionary GetDesignModeState ()