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;
35 using System.Xml.XPath;
36 using System.Collections;
38 namespace System.Web.UI.WebControls {
41 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
42 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
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;
55 XslTransform xsl_transform;
56 XsltArgumentList transform_arguments;
57 string transform_file;
63 [EditorBrowsable (EditorBrowsableState.Never)]
64 [MonoTODO ("Anything else?")]
65 public override string ClientID
72 [MonoTODO ("Anything else?")]
73 [EditorBrowsable (EditorBrowsableState.Never)]
74 public override ControlCollection Controls
83 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
84 [Obsolete ("Use the XPathNavigator property instead by creating an XPathDocument and calling CreateNavigator().")]
85 public XmlDocument Document {
98 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
99 public string DocumentContent {
101 return (xml_content != null)? xml_content : "";
116 [Editor ("System.Web.UI.Design.XmlUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
117 [WebSysDescription ("")]
118 [WebCategory ("Behavior")]
119 [MonoLimitation ("Absolute path to the file system is not supported; use a relative URI instead.")]
120 public string DocumentSource {
122 if (xml_file == null)
135 [EditorBrowsable (EditorBrowsableState.Never)]
137 [DefaultValue (false)]
138 public override bool EnableTheming
140 get { return false; }
141 set { throw new NotSupportedException (); }
145 [EditorBrowsable (EditorBrowsableState.Never)]
147 public override string SkinID
149 // MSDN: Always returns an empty string (""). This property is not supported.
150 get { return String.Empty; }
151 // MSDN: Any attempt to set the value of this property throws a NotSupportedException exception.
152 set { throw new NotSupportedException ("SkinID is not supported on Xml control"); }
157 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
158 [WebSysDescription ("")]
159 [WebCategory ("Behavior")]
160 public XslTransform Transform {
162 return xsl_transform;
166 transform_file = null;
167 xsl_transform = value;
172 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
173 [WebSysDescription ("")]
174 [WebCategory ("Behavior")]
175 public XsltArgumentList TransformArgumentList {
177 return transform_arguments;
181 transform_arguments = value;
189 [Editor ("System.Web.UI.Design.XslUrlEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
190 [MonoLimitation ("Absolute path to the file system is not supported; use a relative URI instead.")]
191 public string TransformSource {
193 if (transform_file == null)
195 return transform_file;
199 transform_file = value;
200 xsl_transform = null;
204 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
206 public XPathNavigator XPathNavigator
208 get { return xpath_navigator; }
209 set { xpath_navigator = value; }
212 [EditorBrowsable (EditorBrowsableState.Never)]
213 public override Control FindControl (string id)
218 [EditorBrowsable (EditorBrowsableState.Never)]
219 public override void Focus ()
221 throw new NotSupportedException ();
224 [EditorBrowsable (EditorBrowsableState.Never)]
225 public override bool HasControls ()
231 override void Render (HtmlTextWriter output)
233 XmlDocument xml_doc = null;
235 if (xpath_navigator == null) {
236 if (xml_document != null)
237 xml_doc = xml_document;
239 if (xml_content != null) {
240 xml_doc = new XmlDocument ();
241 xml_doc.LoadXml (xml_content);
243 else if (xml_file != null) {
244 xml_doc = new XmlDocument ();
245 xml_doc.Load (MapPathSecure (xml_file));
252 XslTransform t = xsl_transform;
253 if (transform_file != null){
254 t = new XslTransform ();
255 t.Load (MapPathSecure (transform_file));
259 if (xpath_navigator != null) {
260 t.Transform(xpath_navigator, transform_arguments, output);
263 t.Transform (xml_doc, transform_arguments, output, null);
268 XmlTextWriter xmlwriter = new XmlTextWriter (output);
269 xmlwriter.Formatting = Formatting.None;
270 if (xpath_navigator != null) {
271 xmlwriter.WriteStartDocument ();
272 xpath_navigator.WriteSubtree (xmlwriter);
275 xml_doc.Save (xmlwriter);
279 protected override void AddParsedSubObject (object obj)
281 LiteralControl lc = obj as LiteralControl;
284 xml_document = new XmlDocument ();
285 xml_document.LoadXml (lc.Text);
287 throw new HttpException (
288 String.Format ("Objects of type {0} are not supported as children of the Xml control",
293 protected override ControlCollection CreateControlCollection ()
295 return new EmptyControlCollection (this);
298 [MonoTODO("Always returns null")]
299 protected override IDictionary GetDesignModeState ()