using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
+using System.Resources;
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)
+ 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");
return new SiteMapHierarchicalDataSourceView (this);
}
- public bool IsAccessibleToUser (System.Web.HttpContext ctx)
+ public virtual bool IsAccessibleToUser (System.Web.HttpContext ctx)
{
return provider.IsAccessibleToUser (ctx, this);
}
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);
}
}
}
- [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");
+
+ if (String.IsNullOrEmpty (implicitResourceKey))
+ 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);
+ if (o is string)
+ return (string) o;
+ }
+ catch (MissingManifestResourceException) {
+ }
+
return null;
}
- [MonoTODO ("resource string?")]
- public string this [string key]
+ 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;
}
node.url = url;
node.title = title;
node.description = description;
- node.roles = new ArrayList (roles);
- node.attributes = new NameValueCollection (attributes);
+ if (roles != null)
+ node.roles = new ArrayList (roles);
+ if (attributes != null)
+ node.attributes = new NameValueCollection (attributes);
if (cloneParentNodes && ParentNode != null)
node.parent = (SiteMapNode) ParentNode.Clone (true);
return node;
}
-
+
public override bool Equals (object ob)
{
SiteMapNode node = ob as SiteMapNode;
node.description != description) {
return false;
}
-
- if ((roles == null || node.roles == null) && (roles != node.roles)) return false;
- if (roles.Count != node.roles.Count) return false;
- foreach (object role in roles)
- if (!node.roles.Contains (role)) return false;
-
- if ((attributes == null || node.attributes == null) && (attributes != node.attributes)) return false;
- if (attributes.Count != node.attributes.Count) return false;
+ if (roles == null || node.roles == null) {
+ if (roles != node.roles)
+ return false;
+ }
+ else {
+ if (roles.Count != node.roles.Count)
+ return false;
- foreach (string k in attributes)
- if (attributes [k] != node.attributes [k]) return false;
+ foreach (object role in roles)
+ if (!node.roles.Contains (role)) return false;
+ }
+ if (attributes == null || node.attributes == null) {
+ if (attributes != node.attributes)
+ return false;
+ }
+ else {
+ if (attributes.Count != node.attributes.Count)
+ return false;
+ foreach (string k in attributes)
+ if (attributes[k] != node.attributes[k])
+ return false;
+ }
return true;
}
#region Field Accessors
- public virtual NameValueCollection Attributes {
+ protected NameValueCollection Attributes {
get { return attributes; }
set { CheckWritable (); attributes = value; }
}
[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; }
}
set { CheckWritable (); url = value; }
}
- public virtual IList Roles {
+ public IList Roles {
get { return roles; }
set { CheckWritable (); roles = value; }
}
set { readOnly = value; }
}
- [MonoTODO ("Do somethig with this")]
public string ResourceKey {
get { return resourceKey; }
set { resourceKey = value; }