2003-11-08 Ben Maurer <bmaurer@users.sourceforge.net>
authorBen Maurer <benm@mono-cvs.ximian.com>
Sun, 9 Nov 2003 00:48:37 +0000 (00:48 -0000)
committerBen Maurer <benm@mono-cvs.ximian.com>
Sun, 9 Nov 2003 00:48:37 +0000 (00:48 -0000)
* UrlUtils.cs: new function to do the app mapping, but make
it return a physical path.

2003-11-08 Ben Maurer  <bmaurer@users.sourceforge.net>

* SiteMap.cs (Init): implement a hack that doesnt need the config
stuff. Should do that later.
* SiteMapNodeCollection (OnValidate): Fix recursion.
* SiteMapProvider.cs: We dont implement some culture stuff work
around it. Fix typo.
* XmlSiteMapProvider.cs: Added.

svn path=/trunk/mcs/; revision=19749

mcs/class/System.Web/System.Web.Util/ChangeLog
mcs/class/System.Web/System.Web.Util/UrlUtils.cs
mcs/class/System.Web/System.Web.dll.sources
mcs/class/System.Web/System.Web/ChangeLog
mcs/class/System.Web/System.Web/SiteMap.cs
mcs/class/System.Web/System.Web/SiteMapNodeCollection.cs
mcs/class/System.Web/System.Web/SiteMapProvider.cs
mcs/class/System.Web/System.Web/XmlSiteMapProvider.cs [new file with mode: 0644]

index a7d6d3c616e911f3e5b4b0e003acbd64cc44a8aa..0bf1d2b008fa44b25168747858f543c71d51522e 100644 (file)
@@ -1,3 +1,8 @@
+2003-11-08 Ben Maurer  <bmaurer@users.sourceforge.net>
+
+       * UrlUtils.cs: new function to do the app mapping, but make
+       it return a physical path.
+
 2003-11-07 Ben Maurer  <bmaurer@users.sourceforge.net>
 
        * UrlUtils.cs: add a new function for mapping app absolute
index b0043753a53994d070eb2c65c0162af0038a6ca0..35eb7e0dca4387f651db278d65b204df1c719efa 100644 (file)
@@ -281,6 +281,22 @@ namespace System.Web.Util
                                return "/" + path.Substring (2);
                        }
                        return path;    
+               }
+               
+               public static string ResolvePhysicalPathFromAppAbsolute (string path)
+               {
+                       if (path [0] != '~') return path;
+                               
+                       if (path.Length == 1)
+                               return HttpRuntime.AppDomainAppPath;
+                       
+                       if (path [1] == '/' || path [1] == '\\') {
+                               string appPath = HttpRuntime.AppDomainAppPath;
+                               if (appPath.Length > 1)
+                                       return appPath + "/" + path.Substring (2);
+                               return "/" + path.Substring (2);
+                       }
+                       return path;    
                }\r
        }\r
 }\r
index 69649d74a0e9895dbcec443c1812277fd4b3035c..fd3425b7a920119dbb4522b409506fcf515fc137 100755 (executable)
@@ -448,3 +448,4 @@ System.Web/SiteMapNode.cs
 System.Web/SiteMapNodeCollection.cs
 System.Web/SiteMapProvider.cs
 System.Web/SiteMapProviderCollection.cs
+System.Web/XmlSiteMapProvider.cs
index e95b809f751605823198e7aa2ac3ded6f2baeca3..c5a91ba3850e97ea0152bd083031a085a8703add 100644 (file)
@@ -1,3 +1,12 @@
+2003-11-08 Ben Maurer  <bmaurer@users.sourceforge.net>
+
+       * SiteMap.cs (Init): implement a hack that doesnt need the config
+       stuff. Should do that later.
+       * SiteMapNodeCollection (OnValidate): Fix recursion.
+       * SiteMapProvider.cs: We dont implement some culture stuff work
+       around it. Fix typo.
+       * XmlSiteMapProvider.cs: Added.
+       
 2003-11-07 Ben Maurer  <bmaurer@users.sourceforge.net>
 
        * ISiteMapProvider.cs:
index 2f261b9eb3be687cb3fae7e7817586b34083c075..852c740cd04de8d962b501143b40bf0e9ac3b19a 100644 (file)
 using System.Collections;
 using System.Collections.Specialized;
 using System.Text;
+using System.Configuration.Provider;
 
 namespace System.Web {
        public sealed class SiteMap {
                [MonoTODO ("Get everything from the config")]
                private static void Init ()
                {
-                       throw new NotImplementedException ();
+                       if (provider == null) {
+                               lock (typeof (SiteMap)) {
+                                       if (provider == null) {
+                                               providers = new SiteMapProviderCollection ();
+                                               provider = new XmlSiteMapProvider ();
+                                               NameValueCollection attributes = new NameValueCollection ();
+                                               attributes.Add ("siteMapFile", "app.sitemap");
+                                               ((IProvider)provider).Initialize ("AspNetXmlSiteMapProvider", attributes);
+                                               providers.Add ((IProvider)provider);
+                                       }
+                               }
+                       }
                }
                
                public static SiteMapNode CurrentNode { 
index e4bed581fd49cc3bd7ed01be1fd18f49791a55a6..2a47beb4a95812794e9522b28dced6ea0b27a2a9 100644 (file)
@@ -76,7 +76,7 @@ namespace System.Web {
                
                protected override void OnValidate (object value)
                {
-                       this.OnValidate (value);
+                       base.OnValidate (value);
                        if (value as SiteMapNode == null)
                                throw new ArgumentException ("Invalid type");
                }
index e63279c8c4303dd82b949830e922c0e5a113aeae..bc4a83043a39dd6c16ae6cbe13d2b55c9fa06600 100644 (file)
@@ -85,13 +85,13 @@ namespace System.Web {
                                        lock (this) {
                                                if (urlToNode == null) {
                                                        urlToNode = new Hashtable (
-                                                               new CaseInsensitiveHashCodeProvider (CultureInfo.InvariantCulture),
-                                                               new CaseInsensitiveComparer (CultureInfo.InvariantCulture)
+                                                               new CaseInsensitiveHashCodeProvider (),
+                                                               new CaseInsensitiveComparer ()
                                                        );
                                                }
                                        }
                                }
-                               return nodeToChildren;
+                               return urlToNode;
                        }
                }
                
diff --git a/mcs/class/System.Web/System.Web/XmlSiteMapProvider.cs b/mcs/class/System.Web/System.Web/XmlSiteMapProvider.cs
new file mode 100644 (file)
index 0000000..3cbc806
--- /dev/null
@@ -0,0 +1,164 @@
+//
+// System.Web.XmlSiteMapProvider
+//
+// Authors:
+//     Ben Maurer (bmaurer@users.sourceforge.net)
+//
+// (C) 2003 Ben Maurer
+//
+
+#if NET_1_2
+using System.Collections;
+using System.Collections.Specialized;
+using System.Configuration;
+using System.Text;
+using System.Xml;
+using System.Web.Util;
+using System.IO;
+
+namespace System.Web {
+       public class XmlSiteMapProvider : SiteMapProvider, IDisposable {
+               static readonly char [] seperators = { ';', ',' };
+               bool building;
+               
+               public override SiteMapNode BuildSiteMap ()
+               {
+                       if (root != null)
+                               return root;
+                       // Whenever you call AddNode, it tries to find dups, and will call this method
+                       // Is this a bug in MS??
+                       if (building)
+                               return null;
+                       
+                       lock (this) {
+                               building = true;
+                               if (root != null)
+                                       return root;
+                               XmlDocument d = new XmlDocument ();
+                               d.Load (file);
+                               
+                               root = BuildSiteMapRecursive (d.SelectSingleNode ("/siteMap/siteMapNode"));
+                               AddNode (root);
+                               building = false;
+                               return root;
+                       }
+               }
+               
+               string GetNonEmptyOptionalAttribute (XmlNode n, string name)
+               {
+                       return System.Web.Configuration.HandlersUtil.ExtractAttributeValue (name, n, true);
+               }
+               
+               string GetOptionalAttribute (XmlNode n, string name)
+               {
+                       return System.Web.Configuration.HandlersUtil.ExtractAttributeValue (name, n, true, true);
+               }
+               
+               [MonoTODO]
+               SiteMapNode BuildSiteMapRecursive (XmlNode xmlNode)
+               {
+
+                       if (xmlNode.Name != "siteMapNode")
+                               throw new ConfigurationException ("incorrect element name", xmlNode);
+                       
+                       string provider = GetNonEmptyOptionalAttribute (xmlNode, "provider");
+                       string siteMapFile = GetNonEmptyOptionalAttribute (xmlNode, "siteMapFile");
+                       
+                       if (provider != null) {
+                               throw new NotImplementedException ();
+                       } else if (siteMapFile != null) {
+                               throw new NotImplementedException ();
+                       } else {
+
+                               string url = GetOptionalAttribute (xmlNode, "url");
+                               string title = GetOptionalAttribute (xmlNode, "title");
+                               string description = GetOptionalAttribute (xmlNode, "description");
+                               string keywords = GetOptionalAttribute (xmlNode, "keywords");
+                               string roles = GetOptionalAttribute (xmlNode, "roles");
+                               
+                               ArrayList keywordsList = new ArrayList ();
+                               if (keywords != null) {
+                                       foreach (string s in keywords.Split (seperators)) {
+                                               string ss = s.Trim ();
+                                               if (ss.Length > 0)
+                                                       keywordsList.Add (ss);
+                                       }
+                               }
+                               
+                               ArrayList rolesList = new ArrayList ();
+                               if (roles != null) {
+                                       foreach (string s in roles.Split (seperators)) {
+                                               string ss = s.Trim ();
+                                               if (ss.Length > 0)
+                                                       rolesList.Add (ss);
+                                       }
+                               }
+                               
+                               if (url != null && url.Length > 0 && UrlUtils.IsRelativeUrl (url)) {
+                                       if (url [0] != '~')
+                                               url = HttpRuntime.AppDomainAppVirtualPath + '/' + url;
+                                       else
+                                               url = UrlUtils.ResolveVirtualPathFromAppAbsolute (url);
+                               }
+                               
+                               SiteMapNode node = new SiteMapNode (this, url, title, description,
+                                       ArrayList.ReadOnly (keywordsList), ArrayList.ReadOnly (rolesList),
+                                       null); // TODO what do they want for attributes
+                               
+                               foreach (XmlNode child in xmlNode.ChildNodes) {
+                                       if (child.NodeType != XmlNodeType.Element)
+                                               continue;
+                                       AddNode (BuildSiteMapRecursive (child), node);
+                               }
+                               
+                               return node;
+                       }
+               }
+
+               protected override void Clear ()
+               {
+                       base.Clear ();
+                       root = null;
+               }
+
+               [MonoTODO]
+               public void Dispose ()
+               {
+                       // what do i do?
+               }
+               
+               [MonoTODO]
+               public override SiteMapNode FindSiteMapNode (string rawUrl)
+               {
+                       return base.FindSiteMapNode (rawUrl); // why did they override this method!?
+               }
+
+               public override void Initialize (string name, NameValueCollection attributes)
+               {
+
+                       base.Initialize (name, attributes);
+                       file = attributes ["siteMapFile"];
+
+                       if (file == null && file.Length == 0)
+                               throw new ArgumentException ("you must provide a file");
+                       
+                       if (UrlUtils.IsRelativeUrl (file))
+                               file = Path.Combine(HttpRuntime.AppDomainAppPath, file);
+                       else
+                               file = UrlUtils.ResolvePhysicalPathFromAppAbsolute (file);
+               }
+
+               public override SiteMapNode RootNode {
+                       get {
+                               BuildSiteMap ();
+                               return root;
+                       }
+               }
+               
+               string file;
+               SiteMapNode root = null;
+       }
+
+}
+#endif
+