Call SetEndOfSendNotification
[mono.git] / mcs / class / System.Web / System.Web / SiteMapNode.cs
index d8a42c54f6a7fb686534605ae1b9155faffedd53..e1fb52011f9f6017f96a3eb4f6ee86fbda1e9d2f 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;
 
 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 +67,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 +91,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 +109,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,11 +174,12 @@ namespace System.Web {
                                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 ();
@@ -187,28 +198,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 +346,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 +393,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 +438,10 @@ namespace System.Web {
                bool readOnly;
                string resourceKey;
                SiteMapNode parent;
-               string implicitResourceKey;
                SiteMapNodeCollection childNodes;
                #endregion
                
        }
 }
-#endif
+