// 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;
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");
this.roles = roles;
this.attributes = attributes;
this.resourceKeys = explicitResourceKeys;
- this.implicitResourceKey = implicitResourceKey;
+ this.resourceKey = implicitResourceKey;
}
public SiteMapDataSourceView GetDataSourceView (SiteMapDataSource owner, string viewName)
}
public virtual bool HasChildNodes {
- get { return ChildNodes != null && ChildNodes.Count != 0; }
+ get {
+ SiteMapNodeCollection childNodes = ChildNodes;
+ return childNodes != null && childNodes.Count > 0;
+ }
}
public SiteMapNodeCollection GetAllNodes ()
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);
}
parent = value;
}
}
-
+
public virtual SiteMapNodeCollection ChildNodes {
get {
- if (childNodes != null) return childNodes;
- return provider.GetChildNodes (this);
+ if (childNodes == null)
+ childNodes = provider.GetChildNodes (this);
+ return childNodes;
}
set {
CheckWritable ();
}
}
- [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;
}
[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 { 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; } }
bool readOnly;
string resourceKey;
SiteMapNode parent;
- string implicitResourceKey;
SiteMapNodeCollection childNodes;
#endregion
}
}
-#endif
+