2 // System.Web.UI.WebControls.Xml.cs
5 // Gaurav Vaish (gvaish@iitk.ac.in)
6 // Gonzalo Paniagua Javier (gonzalo@ximian.com)
7 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
9 // (c) 2002 Ximian, Inc. (http://www.ximian.com)
10 // (C) Gaurav Vaish (2002)
11 // (C) 2003 Andreas Nahr
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
36 using System.ComponentModel;
37 using System.ComponentModel.Design;
41 using System.Xml.XPath;
45 namespace System.Web.UI.WebControls
47 [DefaultProperty("DocumentSource")]
48 [PersistChildren(false)]
49 [ControlBuilder (typeof (XmlBuilder))]
50 [Designer ("System.Web.UI.Design.WebControls.XmlDesigner, " + Consts.AssemblySystem_Design, typeof (IDesigner))]
51 public class Xml : Control
53 static XslTransform defaultTransform;
56 string documentContent;
57 string documentSource;
58 XslTransform transform;
59 XsltArgumentList transformArgumentList;
60 string transformSource;
61 XPathDocument xpathDoc;
65 XmlTextReader reader = new XmlTextReader (new StringReader("<xsl:stylesheet version='1.0' " +
66 "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>" +
67 "<xsl:template match=\"*\">" +
68 "<xsl:copy-of select=\".\"/>" +
70 "</xsl:stylesheet>"));
72 defaultTransform = new XslTransform();
74 defaultTransform.Load (reader);
76 defaultTransform.Load (reader, null, null);
84 [MonoTODO("security")]
85 private void LoadXmlDoc ()
87 if (documentContent != null && documentContent.Length > 0) {
88 document = new XmlDocument ();
89 document.LoadXml (documentContent);
93 if (documentSource != null && documentSource.Length != 0) {
94 document = new XmlDocument ();
95 document.Load (documentSource);
99 [Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
100 [WebSysDescription ("This is the XML document that is used for the XML Webcontrol.")]
101 public XmlDocument Document {
103 if (document == null)
108 documentSource = null;
109 documentContent = null;
115 [Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
116 [WebSysDescription ("The XML content that is transformed for the XML Webcontrol.")]
117 public string DocumentContent {
119 return documentContent;
124 documentContent = value;
128 [DefaultValue (""), Bindable (true), WebCategory ("Behavior")]
129 [Editor ("System.Web.UI.Design.XmlUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
130 [WebSysDescription ("The URL or the source of the XML content that is transformed for the XML Webcontrol.")]
131 public string DocumentSource {
133 if (documentSource != null)
134 return documentSource;
139 documentContent = null;
141 documentSource = value;
145 [Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
146 [WebSysDescription ("The XSL transform that is applied to this XML Webcontrol.")]
147 public XslTransform Transform {
152 transformSource = null;
157 [DefaultValue (""), Bindable (true), WebCategory ("Behavior")]
158 [Editor ("System.Web.UI.Design.XmlUrlEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
159 [WebSysDescription ("An URL specifying the source that is used for the XSL transformation.")]
160 public string TransformSource {
162 if (transformSource != null)
163 return transformSource;
168 transformSource = value;
172 [Browsable (false), DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
173 [WebSysDescription ("Arguments that are used by the XSL Transform.")]
174 public XsltArgumentList TransformArgumentList {
175 get { return transformArgumentList; }
176 set { transformArgumentList = value; }
179 protected override void AddParsedSubObject (object obj)
181 if (obj is LiteralControl) {
182 DocumentContent = ((LiteralControl) obj).Text;
186 throw new HttpException (HttpRuntime.FormatResourceString (
187 "Cannot_Have_Children_of_Type",
192 private void LoadXpathDoc ()
194 if (documentContent != null && documentContent.Length > 0) {
195 xpathDoc = new XPathDocument (new StringReader (documentContent));
199 if (documentSource != null && documentSource.Length != 0) {
200 xpathDoc = new XPathDocument (MapPathSecure (documentSource));
205 private void LoadTransform ()
207 if (transform != null)
210 if (transformSource != null && transformSource.Length != 0) {
211 transform = new XslTransform ();
212 transform.Load (MapPathSecure (transformSource));
216 protected override void Render(HtmlTextWriter output)
218 if (document == null) {
223 if (document == null && xpathDoc == null) {
227 if (transform == null) {
228 transform = defaultTransform;
231 if (document != null) {
233 Transform.Transform(document, transformArgumentList, output);
235 Transform.Transform(document, transformArgumentList, output, null);
240 Transform.Transform(xpathDoc, transformArgumentList, output);
242 Transform.Transform(xpathDoc, transformArgumentList, output, null);