5 // Ben Maurer (bmaurer@users.sourceforge.net)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Collections;
33 using System.Collections.Specialized;
35 using System.Configuration.Provider;
36 using System.Configuration;
37 using System.Web.Configuration;
39 namespace System.Web {
40 public abstract class SiteMap {
46 private static void Init ()
49 if (provider == null) {
50 System.Configuration.Configuration conf = WebConfigurationManager.OpenWebConfiguration ("/");
51 SiteMapSection section = (SiteMapSection) conf.GetSection ("system.web/siteMap");
52 providers = new SiteMapProviderCollection ();
54 if (section.Enabled) {
55 foreach (ProviderSettings prov in section.Providers) {
56 Type t = Type.GetType (prov.Type);
58 throw new ConfigurationException ("Cannot find type: " + prov.Type);
59 if (!typeof(SiteMapProvider).IsAssignableFrom (t))
60 throw new ConfigurationException ("The provided type is not a SiteMapProvider subclass: " + prov.Type);
62 SiteMapProvider pr = (SiteMapProvider) Activator.CreateInstance (t);
63 pr.Initialize (prov.Name, prov.Parameters);
65 if (provider == null || prov.Name == section.DefaultProvider)
72 if (providers.Count == 0) {
73 provider = new XmlSiteMapProvider ();
74 NameValueCollection attributes = new NameValueCollection ();
75 attributes.Add ("siteMapFile", "Web.sitemap");
76 provider.Initialize ("AspNetXmlSiteMapProvider", attributes);
77 providers.Add (provider);
83 public static SiteMapNode CurrentNode {
84 get { return Provider.CurrentNode; }
86 public static SiteMapNode RootNode {
87 get { return Provider.RootNode; }
90 public static SiteMapProvider Provider {
96 public static SiteMapProviderCollection Providers {
103 public event SiteMapResolveEventHandler SiteMapResolve {
104 add { Provider.SiteMapResolve += value; }
105 remove { Provider.SiteMapResolve -= value; }
108 static SiteMapProvider provider;
109 static SiteMapProviderCollection providers;
110 static object locker = new object ();