(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / System.Web / System.Web / SiteMapProvider.cs
blob7d0d7a66f32fcc3740ea2f20753c2c2b7d91e82c
1 //
2 // System.Web.SiteMapProvider
3 //
4 // Authors:
5 // Ben Maurer (bmaurer@users.sourceforge.net)
6 //
7 // (C) 2003 Ben Maurer
8 //
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.
31 #if NET_2_0
32 using System.Collections;
33 using System.Collections.Specialized;
34 using System.Text;
35 using System.Configuration.Provider;
36 using System.Web.Util;
37 using System.Globalization;
39 namespace System.Web {
40 public abstract class SiteMapProvider : ISiteMapProvider, IProvider {
42 public void AddNode (SiteMapNode node)
44 AddNode (node, null);
47 public void AddNode (SiteMapNode node, SiteMapNode parentNode)
49 if (node == null)
50 throw new ArgumentNullException ("node");
52 lock (this) {
53 string url = node.Url;
54 if (url != null && url.Length > 0) {
57 if (UrlUtils.IsRelativeUrl (url))
58 url = UrlUtils.Combine (HttpRuntime.AppDomainAppVirtualPath, url);
59 else
60 url = UrlUtils.ResolveVirtualPathFromAppAbsolute (url);
62 if (FindSiteMapNode (url) != null)
63 throw new InvalidOperationException ();
65 UrlToNode [url] = node;
68 if (parentNode != null) {
69 NodeToParent [node] = parentNode;
70 if (NodeToChildren [parentNode] == null)
71 NodeToChildren [parentNode] = new SiteMapNodeCollection ();
73 ((SiteMapNodeCollection) NodeToChildren [parentNode]).Add (node);
78 Hashtable nodeToParent;
79 Hashtable NodeToParent {
80 get {
81 if (nodeToParent == null) {
82 lock (this) {
83 if (nodeToParent == null)
84 nodeToParent = new Hashtable ();
87 return nodeToParent;
91 Hashtable nodeToChildren;
92 Hashtable NodeToChildren {
93 get {
94 if (nodeToChildren == null) {
95 lock (this) {
96 if (nodeToChildren == null)
97 nodeToChildren = new Hashtable ();
100 return nodeToChildren;
104 Hashtable urlToNode;
105 Hashtable UrlToNode {
106 get {
107 if (urlToNode == null) {
108 lock (this) {
109 if (urlToNode == null) {
110 urlToNode = new Hashtable (
111 new CaseInsensitiveHashCodeProvider (),
112 new CaseInsensitiveComparer ()
117 return urlToNode;
121 protected virtual void Clear ()
123 lock (this) {
124 if (urlToNode != null)
125 urlToNode.Clear ();
126 if (nodeToChildren != null)
127 nodeToChildren.Clear ();
128 if (nodeToParent != null)
129 nodeToParent.Clear ();
133 public virtual SiteMapNode FindSiteMapNode (string rawUrl)
135 if (rawUrl == null)
136 throw new ArgumentNullException ("rawUrl");
138 if (rawUrl.Length > 0) {
139 this.BuildSiteMap();
140 rawUrl = UrlUtils.ResolveVirtualPathFromAppAbsolute (rawUrl);
141 return (SiteMapNode) UrlToNode [rawUrl];
143 return null;
146 public virtual SiteMapNodeCollection GetChildNodes (SiteMapNode node)
148 if (node == null)
149 throw new ArgumentNullException ("node");
151 this.BuildSiteMap();
152 SiteMapNodeCollection ret = (SiteMapNodeCollection) NodeToChildren [node];
154 if (ret != null)
155 return SiteMapNodeCollection.ReadOnly (ret);
157 return null;
160 public virtual SiteMapNode GetParentNode(SiteMapNode node) {
161 if (node == null)
162 throw new ArgumentNullException ("node");
163 this.BuildSiteMap();
164 return (SiteMapNode) NodeToParent [node];
167 public void RemoveNode (SiteMapNode node)
170 if (node == null)
171 throw new ArgumentNullException("node");
173 lock (this) {
174 SiteMapNode parent = (SiteMapNode) NodeToParent [node];
175 if (NodeToParent.Contains (node))
176 NodeToParent.Remove (node);
178 if (node.Url != null && node.Url.Length > 0 && UrlToNode.Contains (node.Url))
179 UrlToNode.Remove (node.Url);
181 if (parent != null) {
182 SiteMapNodeCollection siblings = (SiteMapNodeCollection) NodeToChildren [node];
183 if (siblings != null && siblings.Contains (node))
184 siblings.Remove (node);
189 public virtual void Initialize (string name, NameValueCollection attributes)
191 this.name = name;
192 if (attributes != null)
193 description = attributes ["description"];
197 public virtual SiteMapNode CurrentNode {
198 get {
199 SiteMapNode ret;
201 if (HttpContext.Current != null) {
202 ret = this.FindSiteMapNode (HttpContext.Current.Request.RawUrl);
203 if (ret == null)
204 ret = this.FindSiteMapNode (HttpContext.Current.Request.Path);
206 return ret;
209 return null;
213 string description;
214 public virtual string Description {
215 get { return description != null ? description : "SiteMapProvider"; }
218 string name;
219 public virtual string Name {
220 get { return name; }
223 ISiteMapProvider parentProvider;
224 public virtual ISiteMapProvider ParentProvider {
225 get { return parentProvider; }
226 set { parentProvider = value; }
229 ISiteMapProvider rootProviderCache;
230 public virtual ISiteMapProvider RootProvider {
231 get {
232 if (rootProviderCache == null) {
233 lock (this) {
234 if (rootProviderCache == null) {
235 ISiteMapProvider current = this;
236 while (current.ParentProvider != null)
237 current = current.ParentProvider;
239 rootProviderCache = current;
243 return rootProviderCache;
247 public abstract SiteMapNode BuildSiteMap ();
248 public abstract SiteMapNode RootNode { get; }
252 #endif