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 : "";
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 {
119 if (xml_file == null)
132 [EditorBrowsable (EditorBrowsableState.Never)]
134 [DefaultValue (false)]
135 public override bool EnableTheming
137 get { return false; }
138 set { throw new NotSupportedException (); }
142 [EditorBrowsable (EditorBrowsableState.Never)]
144 public override string SkinID
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"); }
154 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
155 [WebSysDescription ("")]
156 [WebCategory ("Behavior")]
157 public XslTransform Transform {
159 return xsl_transform;
163 transform_file = null;
164 xsl_transform = value;
169 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
170 [WebSysDescription ("")]
171 [WebCategory ("Behavior")]
172 public XsltArgumentList TransformArgumentList {
174 return transform_arguments;
178 transform_arguments = value;
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 {
187 if (transform_file == null)
189 return transform_file;
193 transform_file = value;
194 xsl_transform = null;
198 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
200 public XPathNavigator XPathNavigator
202 get { return xpath_navigator; }
203 set { xpath_navigator = value; }
206 [EditorBrowsable (EditorBrowsableState.Never)]
207 public override Control FindControl (string id)
212 [EditorBrowsable (EditorBrowsableState.Never)]
213 public override void Focus ()
215 throw new NotSupportedException ();
218 [EditorBrowsable (EditorBrowsableState.Never)]
219 public override bool HasControls ()
225 override void Render (HtmlTextWriter output)
227 XmlDocument xml_doc = null;
229 if (xpath_navigator == null) {
230 if (xml_document != null)
231 xml_doc = xml_document;
233 if (xml_content != null) {
234 xml_doc = new XmlDocument ();
235 xml_doc.LoadXml (xml_content);
237 else if (xml_file != null) {
238 xml_doc = new XmlDocument ();
239 xml_doc.Load (MapPathSecure (xml_file));
246 XslTransform t = xsl_transform;
247 if (transform_file != null){
248 t = new XslTransform ();
249 t.Load (MapPathSecure (transform_file));
253 if (xpath_navigator != null) {
254 t.Transform(xpath_navigator, transform_arguments, output);
257 t.Transform (xml_doc, transform_arguments, output, null);
262 XmlTextWriter xmlwriter = new XmlTextWriter (output);
263 xmlwriter.Formatting = Formatting.None;
264 if (xpath_navigator != null) {
265 xmlwriter.WriteStartDocument ();
266 xpath_navigator.WriteSubtree (xmlwriter);
269 xml_doc.Save (xmlwriter);
273 protected override void AddParsedSubObject (object obj)
275 LiteralControl lc = obj as LiteralControl;
278 xml_document = new XmlDocument ();
279 xml_document.LoadXml (lc.Text);
281 throw new HttpException (
282 String.Format ("Objects of type {0} are not supported as children of the Xml control",
287 protected override ControlCollection CreateControlCollection ()
289 return new EmptyControlCollection (this);
292 [MonoTODO("Always returns null")]
293 protected override IDictionary GetDesignModeState ()