2 // System.Web.UI.WebControls.XmlDataSource
5 // Ben Maurer (bmaurer@users.sourceforge.net)
6 // Chris Toshok (toshok@ximian.com)
9 // (C) 2005 Novell, Inc (http://www.novell.com)
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
34 using System.Collections;
35 using System.Collections.Specialized;
39 using System.ComponentModel;
41 using System.Security.Permissions;
43 namespace System.Web.UI.WebControls {
46 [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
47 [AspNetHostingPermission (SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
49 [DesignerAttribute ("System.Web.UI.Design.WebControls.XmlDataSourceDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
50 [DefaultProperty ("DataFile")]
51 [DefaultEvent ("Transforming")]
52 [ParseChildren (true)]
53 [PersistChildren (false)]
54 [WebSysDescription ("Connect to an XML file.")]
55 // [WebSysDisplayName ("XML file")]
56 public class XmlDataSource : HierarchicalDataSourceControl, IDataSource, IListSource {
59 event EventHandler IDataSource.DataSourceChanged {
60 add { ((IHierarchicalDataSource)this).DataSourceChanged += value; }
61 remove { ((IHierarchicalDataSource)this).DataSourceChanged -= value; }
64 static object EventTransforming = new object ();
65 public event EventHandler Transforming {
66 add { Events.AddHandler (EventTransforming, value); }
67 remove { Events.RemoveHandler (EventTransforming, value); }
70 protected virtual void OnTransforming (EventArgs e)
72 EventHandler eh = Events [EventTransforming] as EventHandler;
77 XmlDocument xmlDocument;
78 public XmlDocument GetXmlDocument ()
80 if (xmlDocument == null) {
81 xmlDocument = new XmlDocument ();
82 LoadXmlDocument (xmlDocument);
87 [MonoTODO ("XSLT, schema")]
88 void LoadXmlDocument (XmlDocument document)
90 if (Transform == "" && TransformFile == "") {
92 document.Load (MapPathSecure (DataFile));
94 document.LoadXml (Data);
96 throw new NotImplementedException ("XSLT transform not implemented");
103 throw new InvalidOperationException ();
105 xmlDocument.Save (MapPathSecure (DataFile));
110 return Transform == "" && TransformFile == "" && DataFile != "";
114 protected override HierarchicalDataSourceView GetHierarchicalView (string viewPath)
116 XmlNode doc = this.GetXmlDocument ();
117 XmlNodeList ret = null;
119 if (viewPath != "") {
120 XmlNode n = doc.SelectSingleNode (viewPath);
123 } else if (XPath != "") {
124 ret = doc.SelectNodes (XPath);
126 ret = doc.ChildNodes;
129 return new XmlHierarchicalDataSourceView (ret);
132 IList IListSource.GetList ()
134 return ListSourceHelper.GetList (this);
137 bool IListSource.ContainsListCollection {
138 get { return ListSourceHelper.ContainsListCollection (this); }
141 DataSourceView IDataSource.GetView (string viewName)
144 viewName = "DefaultView";
146 return new XmlDataSourceView (this, viewName);
149 ICollection IDataSource.GetViewNames ()
151 return new string [] { "DefaultView" };
155 //[TypeConverter (typeof(DataSourceCacheDurationConverter))]
157 public virtual int CacheDuration {
159 throw new NotImplementedException ();
162 throw new NotImplementedException ();
166 [DefaultValue (DataSourceCacheExpiry.Absolute)]
168 public virtual DataSourceCacheExpiry CacheExpirationPolicy {
170 throw new NotImplementedException ();
173 throw new NotImplementedException ();
179 public virtual string CacheKeyDependency {
181 throw new NotImplementedException ();
184 throw new NotImplementedException ();
188 [DefaultValue (true)]
190 public virtual bool EnableCaching {
192 throw new NotImplementedException ();
195 throw new NotImplementedException ();
200 [PersistenceMode (PersistenceMode.InnerProperty)]
201 [WebSysDescription ("Inline XML data.")]
202 [WebCategory ("Data")]
203 [EditorAttribute ("System.ComponentModel.Design.MultilineStringEditor," + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
204 // [TypeConverter (typeof(MultilineStringConverter))]
205 public virtual string Data {
207 string ret = ViewState ["Data"] as string;
208 return ret != null ? ret : "";
212 ViewState ["Data"] = value;
214 OnDataSourceChanged(EventArgs.Empty);
219 [DefaultValueAttribute ("")]
220 [EditorAttribute ("System.Web.UI.Design.XmlDataFileEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
221 public virtual string DataFile {
223 string ret = ViewState ["DataFile"] as string;
224 return ret != null ? ret : "";
227 if (DataFile != value) {
228 ViewState ["DataFile"] = value;
230 OnDataSourceChanged(EventArgs.Empty);
235 XsltArgumentList transformArgumentList;
237 [BrowsableAttribute (false)]
238 public virtual XsltArgumentList TransformArgumentList {
239 get { return transformArgumentList; }
240 set { transformArgumentList = value; }
243 [PersistenceModeAttribute (PersistenceMode.InnerProperty)]
244 [EditorAttribute ("System.ComponentModel.Design.MultilineStringEditor," + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
245 [DefaultValueAttribute ("")]
246 // [TypeConverterAttribute (typeof(System.ComponentModel.MultilineStringConverter))]
247 public virtual string Transform {
249 string ret = ViewState ["Transform"] as string;
250 return ret != null ? ret : "";
253 if (Transform != value) {
254 ViewState ["Transform"] = value;
256 OnDataSourceChanged(EventArgs.Empty);
261 [EditorAttribute ("System.Web.UI.Design.XslTransformFileEditor, " + Consts.AssemblySystem_Design, "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
262 [DefaultValueAttribute ("")]
263 public virtual string TransformFile {
265 string ret = ViewState ["TransformFile"] as string;
266 return ret != null ? ret : "";
269 if (TransformFile != value) {
270 ViewState ["TransformFile"] = value;
272 OnDataSourceChanged(EventArgs.Empty);
277 [DefaultValueAttribute ("")]
278 public virtual string XPath {
280 string ret = ViewState ["XPath"] as string;
281 return ret != null ? ret : "";
284 if (XPath != value) {
285 ViewState ["XPath"] = value;
286 OnDataSourceChanged(EventArgs.Empty);