Merge pull request #2098 from evincarofautumn/fix-gchandle-assert
[mono.git] / mcs / class / System.Web / System.Web / SiteMapNode.cs
index 107a856205dfb2dc1b2cb0d9ff3e47986f272655..b1660b8752c2365c8ff4981c3682921cafbd764c 100644 (file)
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
-#if NET_2_0
 using System.Collections;
 using System.Collections.Specialized;
 using System.Text;
 using System.Web.UI;
 using System.Web.UI.WebControls;
 using System.ComponentModel;
+using System.Resources;
+using System.Security.Principal;
 
 namespace System.Web {
        public class SiteMapNode : IHierarchyData, INavigateUIData, ICloneable {
        
-               private SiteMapNode () {}
+               SiteMapNode () {}
                
                public SiteMapNode (SiteMapProvider provider, string key)
                        : this (provider, key, null, null, null, null, null, null, null) {}
@@ -67,7 +68,7 @@ namespace System.Web {
                        this.roles = roles;
                        this.attributes = attributes;
                        this.resourceKeys = explicitResourceKeys;
-                       this.implicitResourceKey = implicitResourceKey;
+                       this.resourceKey = implicitResourceKey;
                }
 
                public SiteMapDataSourceView GetDataSourceView (SiteMapDataSource owner, string viewName)
@@ -91,7 +92,10 @@ namespace System.Web {
                }
 
                public virtual bool HasChildNodes {
-                       get { return ChildNodes != null && ChildNodes.Count != 0; }
+                       get {
+                               SiteMapNodeCollection childNodes = ChildNodes;
+                               return childNodes != null && childNodes.Count > 0;
+                       }
                }
 
                public SiteMapNodeCollection GetAllNodes ()
@@ -106,9 +110,9 @@ namespace System.Web {
                void GetAllNodesRecursive(SiteMapNodeCollection c)
                {
                        SiteMapNodeCollection childNodes = this.ChildNodes;
-                       
-                       if (childNodes.Count > 0) {
-                               childNodes.AddRange (childNodes);
+
+                       if (childNodes != null && childNodes.Count > 0) {
+                               c.AddRange (childNodes);
                                foreach (SiteMapNode n in childNodes)
                                        n.GetAllNodesRecursive (c);
                        }
@@ -171,14 +175,23 @@ namespace System.Web {
                                parent = value;
                        }
                }
-               
+
                public virtual SiteMapNodeCollection ChildNodes {
                        get {
-                               if (childNodes != null) return childNodes;
-                               return provider.GetChildNodes (this);
+                               if (provider.SecurityTrimmingEnabled) {
+                                       IPrincipal p = HttpContext.Current.User;
+                                       if ((user == null && user != p) || user != null && user != p) {
+                                               user = p;
+                                               childNodes = provider.GetChildNodes (this);
+                                       }
+                               } else if (childNodes == null) {
+                                       childNodes = provider.GetChildNodes (this);
+                               }
+                               return childNodes;
                        } 
                        set {
                                CheckWritable ();
+                               user = null;
                                childNodes = value;
                        }
                }
@@ -206,14 +219,15 @@ namespace System.Web {
                                                object o = HttpContext.GetGlobalResourceObject (values [0], values [1]);
                                                if (o is string)
                                                        return (string) o;
-                                       } catch (Exception) {
                                        }
+                                       catch (MissingManifestResourceException) {
+                                       }
+
+                                       if (throwIfNotFound && defaultValue == null)
+                                               throw new InvalidOperationException (String.Format ("The resource object with classname '{0}' and key '{1}' was not found.", values [0], values [1]));
                                }
                        }
 
-                       if (throwIfNotFound && defaultValue == null)
-                               throw new InvalidOperationException ();
-
                        return defaultValue;
                }
 
@@ -222,20 +236,15 @@ namespace System.Web {
                        if (attributeName == null)
                                throw new ArgumentNullException ("attributeName");
 
-                       if (String.IsNullOrEmpty (implicitResourceKey))
+                       string resourceKey = ResourceKey;
+                       if (String.IsNullOrEmpty (resourceKey))
                                return null;
 
                        try {
-                               string reskey = provider.ResourceKey;
-
-                               if (!String.IsNullOrEmpty (reskey))
-                                       reskey = String.Format ("{0}.{1}.{2}", reskey, implicitResourceKey, attributeName);
-                               else
-                                       reskey = String.Format ("{0}.{1}", implicitResourceKey, attributeName);
-                               object o = HttpContext.GetGlobalResourceObject ("Web.sitemap", reskey);
+                               object o = HttpContext.GetGlobalResourceObject (provider.ResourceKey, resourceKey + "." + attributeName);
                                if (o is string)
                                        return (string) o;
-                       } catch (Exception) {
+                       } catch (MissingManifestResourceException) {
                        }
                        
                        return null;
@@ -244,13 +253,13 @@ namespace System.Web {
                public virtual string this [string key]
                {
                        get {
-                               string val = null;
                                if (provider.EnableLocalization) {
-                                       val = GetImplicitResourceString (key);
+                                       string val = GetImplicitResourceString (key);
                                        if (val == null)
                                                val = GetExplicitResourceString (key, null, true);
+                                       if (val != null)
+                                               return val;
                                }
-                               if (val != null) return null;
                                if (attributes != null) return attributes [key];
                                return null;
                        }
@@ -395,7 +404,11 @@ namespace System.Web {
                
                public string ResourceKey {
                        get { return resourceKey; }
-                       set { resourceKey = value; }
+                       set {
+                               if (ReadOnly)
+                                       throw new InvalidOperationException ("The node is read-only.");
+                               resourceKey = value;
+                       }
                }
                
                public string Key { get { return key; } }
@@ -434,11 +447,11 @@ namespace System.Web {
                bool readOnly;
                string resourceKey;
                SiteMapNode parent;
-               string implicitResourceKey;
                SiteMapNodeCollection childNodes;
+               IPrincipal user;
                #endregion
                
        }
 }
-#endif
+