[System.Net] Add support for .pac proxy config scripts on mac
[mono.git] / mcs / class / System.Web / System.Web / SiteMap.cs
1 //
2 // System.Web.SiteMap
3 //
4 // Authors:
5 //      Ben Maurer (bmaurer@users.sourceforge.net)
6 //
7 // (C) 2003 Ben Maurer
8 //
9
10 //
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:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
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.
29 //
30
31 using System.Collections;
32 using System.Collections.Specialized;
33 using System.Text;
34 using System.Configuration.Provider;
35 using System.Configuration;
36 using System.Web.Configuration;
37
38 namespace System.Web
39 {
40         public static class SiteMap
41         {
42                 static void Init ()
43                 {
44                         lock (locker) {
45                                 if (provider == null) {
46                                         SiteMapSection section = (SiteMapSection) WebConfigurationManager.GetSection ("system.web/siteMap");
47
48                                         if (!section.Enabled)
49                                                 throw new InvalidOperationException ("This feature is currently disabled.  Please enable it in the system.web/siteMap section in the web.config file.");
50
51                                         providers = section.ProvidersInternal;
52                                         providers.SetReadOnly ();
53                                         provider = providers[section.DefaultProvider];
54
55                                         if (provider == null)
56                                                 throw new ConfigurationErrorsException (
57                                                         String.Format ("The default sitemap provider '{0}' does not exist in the provider collection.", section.DefaultProvider));
58                                 }
59                         }
60                 }
61                 
62                 public static SiteMapNode CurrentNode { 
63                         get { return Provider.CurrentNode; }
64                 }
65
66                 public static SiteMapNode RootNode { 
67                         get { return Provider.RootNode; }
68                 }
69
70                 
71                 public static SiteMapProvider Provider {
72                         get {
73                                 Init ();
74                                 return provider;
75                         }
76                 }
77                 public static SiteMapProviderCollection Providers {
78                         get {
79                                 Init ();
80                                 return providers;
81                         }
82                 }
83                 
84                 public static event SiteMapResolveEventHandler SiteMapResolve {
85                         add { Provider.SiteMapResolve += value; }
86                         remove { Provider.SiteMapResolve -= value; }
87                 }
88
89                 public static bool Enabled {
90                         get {
91                                 SiteMapSection section = (SiteMapSection) WebConfigurationManager.GetSection ("system.web/siteMap");
92                                 return section.Enabled;
93                         }
94                 }               
95
96 #if TARGET_JVM
97                 const string SiteMap_provider = "SiteMap_provider";
98                 const string SiteMap_providers = "SiteMap_providers";
99                 static SiteMapProvider provider
100                 {
101                         get { return (SiteMapProvider) AppDomain.CurrentDomain.GetData (SiteMap_provider); }
102                         set { AppDomain.CurrentDomain.SetData (SiteMap_provider, value); }
103                 }
104                 static SiteMapProviderCollection providers
105                 {
106                         get { return (SiteMapProviderCollection) AppDomain.CurrentDomain.GetData (SiteMap_providers); }
107                         set { AppDomain.CurrentDomain.SetData (SiteMap_providers, value); }
108                 }
109 #else
110                 static SiteMapProvider provider;
111                 static SiteMapProviderCollection providers;
112 #endif
113                 static object locker = new object ();
114         }
115 }
116
117