X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.Web%2FSystem.Web%2FSiteMapNode.cs;h=b1660b8752c2365c8ff4981c3682921cafbd764c;hb=a04b9a5d948e12a6864dcd25347fae41c337de96;hp=d8a42c54f6a7fb686534605ae1b9155faffedd53;hpb=669beaed8380fa592533c8755f72593b4422d01d;p=mono.git diff --git a/mcs/class/System.Web/System.Web/SiteMapNode.cs b/mcs/class/System.Web/System.Web/SiteMapNode.cs index d8a42c54f6a..b1660b8752c 100644 --- a/mcs/class/System.Web/System.Web/SiteMapNode.cs +++ b/mcs/class/System.Web/System.Web/SiteMapNode.cs @@ -28,24 +28,32 @@ // 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 () {} - - public SiteMapNode (SiteMapProvider provider, string key) : this (provider, key, null, null, null, null, null, null, null) {} - public SiteMapNode (SiteMapProvider provider, string key, string url) : this (provider, key, url, null, null, null, null, null, null) {} - public SiteMapNode (SiteMapProvider provider, string key, string url, string title) : this (provider, key, url, title, null, null, null, null, null) {} - public SiteMapNode (SiteMapProvider provider, string key, string url, string title, string description) : this (provider, key, url, title, description, null, null, null, null) {} - public SiteMapNode (SiteMapProvider provider, string key, string url, string title, string description, IList roles, NameValueCollection attributes, NameValueCollection explicitResourceKeys, string implicitResourceKey) + SiteMapNode () {} + + public SiteMapNode (SiteMapProvider provider, string key) + : this (provider, key, null, null, null, null, null, null, null) {} + public SiteMapNode (SiteMapProvider provider, string key, string url) + : this (provider, key, url, null, null, null, null, null, null) {} + public SiteMapNode (SiteMapProvider provider, string key, string url, string title) + : this (provider, key, url, title, null, null, null, null, null) {} + public SiteMapNode (SiteMapProvider provider, string key, string url, string title, string description) + : this (provider, key, url, title, description, null, null, null, null) {} + + public SiteMapNode (SiteMapProvider provider, string key, string url, string title, string description, + IList roles, NameValueCollection attributes, NameValueCollection explicitResourceKeys, + string implicitResourceKey) { if (provider == null) throw new ArgumentNullException ("provider"); @@ -60,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) @@ -84,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 () @@ -99,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); } @@ -164,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; } } @@ -187,28 +207,59 @@ namespace System.Web { } } - [MonoTODO] protected string GetExplicitResourceString (string attributeName, string defaultValue, bool throwIfNotFound) { - return null; + if (attributeName == null) + throw new ArgumentNullException ("attributeName"); + + if (resourceKeys != null){ + string[] values = resourceKeys.GetValues (attributeName); + if (values != null && values.Length == 2) { + try { + object o = HttpContext.GetGlobalResourceObject (values [0], values [1]); + if (o is string) + return (string) o; + } + 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])); + } + } + + return defaultValue; } - - [MonoTODO] + protected string GetImplicitResourceString (string attributeName) { + if (attributeName == null) + throw new ArgumentNullException ("attributeName"); + + string resourceKey = ResourceKey; + if (String.IsNullOrEmpty (resourceKey)) + return null; + + try { + object o = HttpContext.GetGlobalResourceObject (provider.ResourceKey, resourceKey + "." + attributeName); + if (o is string) + return (string) o; + } catch (MissingManifestResourceException) { + } + return null; } - [MonoTODO ("resource string?")] public virtual string this [string key] { get { - string val = null; if (provider.EnableLocalization) { - val = GetExplicitResourceString (key, null, true); - if (val == null) 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; } @@ -304,13 +355,35 @@ namespace System.Web { [Localizable (true)] public virtual string Description { - get { return description != null ? description : ""; } + get { + string ret = null; + + if (provider.EnableLocalization) { + ret = GetImplicitResourceString ("description"); + if (ret == null) + ret = GetExplicitResourceString ("description", description, true); + } else + ret = description; + + return ret != null ? ret : String.Empty; + } set { CheckWritable (); description = value; } } [LocalizableAttribute (true)] public virtual string Title { - get { return title != null ? title : ""; } + get { + string ret = null; + + if (provider.EnableLocalization) { + ret = GetImplicitResourceString ("title"); + if (ret == null) + ret = GetExplicitResourceString ("title", title, true); + } else + ret = title; + + return ret != null ? ret : String.Empty; + } set { CheckWritable (); title = value; } } @@ -329,10 +402,13 @@ namespace System.Web { set { readOnly = value; } } - [MonoTODO ("Do somethig with this")] 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; } } @@ -371,11 +447,11 @@ namespace System.Web { bool readOnly; string resourceKey; SiteMapNode parent; - string implicitResourceKey; SiteMapNodeCollection childNodes; + IPrincipal user; #endregion } } -#endif +