+++ /dev/null
-//\r
-// System.Web.XmlSiteMapProvider\r
-//\r
-// Authors:\r
-// Ben Maurer (bmaurer@users.sourceforge.net)\r
-// Lluis Sanchez Gual (lluis@novell.com)\r
-//\r
-// (C) 2003 Ben Maurer\r
-// (C) 2005 Novell, Inc (http://www.novell.com)\r
-//\r
-\r
-//\r
-// Permission is hereby granted, free of charge, to any person obtaining\r
-// a copy of this software and associated documentation files (the\r
-// "Software"), to deal in the Software without restriction, including\r
-// without limitation the rights to use, copy, modify, merge, publish,\r
-// distribute, sublicense, and/or sell copies of the Software, and to\r
-// permit persons to whom the Software is furnished to do so, subject to\r
-// the following conditions:\r
-// \r
-// The above copyright notice and this permission notice shall be\r
-// included in all copies or substantial portions of the Software.\r
-// \r
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
-// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
-// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
-// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
-//\r
-\r
-using System.Collections;\r
-using System.Collections.Specialized;\r
-using System.Configuration;\r
-using System.Text;\r
-using System.Xml;\r
-using System.Web.Util;\r
-using System.IO;\r
-using System.Web;\r
-using System;\r
-using Mainsoft.Web;\r
-using Mainsoft.Web.Configuration;\r
-using Mainsoft.Web.Util;\r
-\r
-namespace Mainsoft.Web.AspnetConfig\r
-{\r
- public class CustomXmlSiteMapProvider : StaticSiteMapProvider, IDisposable\r
- {\r
- static readonly char [] seperators = { ';', ',' };\r
- bool building;\r
- string file;\r
- SiteMapNode root = null;\r
-#if !TARGET_JVM // Java platform does not support file notifications\r
- FileSystemWatcher watcher;\r
-#endif\r
-\r
- protected override void AddNode (SiteMapNode node, SiteMapNode parentNode)\r
- {\r
- base.AddNode (node, parentNode);\r
- }\r
-\r
- protected virtual void AddProvider (string providerName, SiteMapNode parentNode)\r
- {\r
- throw new NotImplementedException ();\r
- }\r
-\r
- public override SiteMapNode BuildSiteMap ()\r
- {\r
- if (root != null)\r
- return root;\r
- // Whenever you call AddNode, it tries to find dups, and will call this method\r
- // Is this a bug in MS??\r
- if (building)\r
- return null;\r
- \r
- lock (this) {\r
- try {\r
- building = true;\r
- if (root != null)\r
- return root;\r
- XmlDocument d = new XmlDocument ();\r
- using (Stream source = GetType ().Assembly.GetManifestResourceStream ("Mainsoft.Web.AspnetConfig.aspnetconfig.Web.sitemap")) {
- if (source == null)
- throw new ArgumentException ("resource not found: ~/aspnetconfig/Web.sitemap");\r
- d.Load (source);\r
- }\r
-\r
- XmlNode nod = d.DocumentElement ["siteMapNode"];\r
- if (nod == null)\r
- throw new HttpException ("Invalid site map file: " + Path.GetFileName (file));\r
- \r
- root = BuildSiteMapRecursive (nod);\r
- \r
- AddNode (root);\r
- } finally {\r
- building = false;\r
- }\r
- return root;\r
- }\r
- }\r
- \r
- string GetNonEmptyOptionalAttribute (XmlNode n, string name)\r
- {\r
- return HandlersUtil.ExtractAttributeValue (name, n, true);\r
- }\r
- \r
- string GetOptionalAttribute (XmlNode n, string name)\r
- {\r
- return HandlersUtil.ExtractAttributeValue (name, n, true, true);\r
- }\r
- \r
- SiteMapNode BuildSiteMapRecursive (XmlNode xmlNode)\r
- {\r
- if (xmlNode.Name != "siteMapNode")\r
- throw new ConfigurationException ("incorrect element name", xmlNode);\r
- \r
- string provider = GetNonEmptyOptionalAttribute (xmlNode, "provider");\r
- string siteMapFile = GetNonEmptyOptionalAttribute (xmlNode, "siteMapFile");\r
- \r
- if (provider != null) {\r
- throw new NotImplementedException ();\r
- } else if (siteMapFile != null) {\r
- throw new NotImplementedException ();\r
- } else {\r
-\r
- string url = GetOptionalAttribute (xmlNode, "url");\r
- string title = GetOptionalAttribute (xmlNode, "title");\r
- string description = GetOptionalAttribute (xmlNode, "description");\r
- string keywords = GetOptionalAttribute (xmlNode, "keywords");\r
- string roles = GetOptionalAttribute (xmlNode, "roles");\r
- \r
- ArrayList keywordsList = new ArrayList ();\r
- if (keywords != null && keywords.Length > 0) {\r
- foreach (string s in keywords.Split (seperators)) {\r
- string ss = s.Trim ();\r
- if (ss.Length > 0)\r
- keywordsList.Add (ss);\r
- }\r
- }\r
- \r
- ArrayList rolesList = new ArrayList ();\r
- if (roles != null && roles.Length > 0) {\r
- foreach (string s in roles.Split (seperators)) {\r
- string ss = s.Trim ();\r
- if (ss.Length > 0)\r
- rolesList.Add (ss);\r
- }\r
- }\r
-\r
- if (!string.IsNullOrEmpty (url)) {\r
- if (UrlUtils.IsRelativeUrl (url))\r
- url = UrlUtils.Combine (HttpRuntime.AppDomainAppVirtualPath, url);\r
- }\r
- \r
- SiteMapNode node = new SiteMapNode (this, url, url, title, description,\r
- /*ArrayList.ReadOnly (keywordsList), */ArrayList.ReadOnly (rolesList), null,\r
- null, null); // TODO what do they want for attributes\r
- \r
- foreach (XmlNode child in xmlNode.ChildNodes) {\r
- if (child.NodeType != XmlNodeType.Element)\r
- continue;\r
- AddNode (BuildSiteMapRecursive (child), node);\r
- }\r
- \r
- return node;\r
- }\r
- }\r
-\r
- protected override void Clear ()\r
- {\r
- base.Clear ();\r
- root = null;\r
- }\r
-\r
- protected virtual void Dispose (bool disposing)\r
- {\r
-#if !TARGET_JVM // Java platform does not support file notifications\r
- if (disposing)\r
- watcher.Dispose ();\r
-#endif\r
- }\r
-\r
- public void Dispose ()\r
- {\r
- Dispose (true);\r
- }\r
- \r
- public override SiteMapNode FindSiteMapNode (string rawUrl)\r
- {\r
- return base.FindSiteMapNode (rawUrl); // why did they override this method!?\r
- }\r
-\r
- public override SiteMapNode FindSiteMapNodeFromKey (string key)\r
- {\r
- return base.FindSiteMapNodeFromKey (key); // why did they override this method!?\r
- }\r
-\r
- public override void Initialize (string name, NameValueCollection attributes)\r
- {\r
-\r
- base.Initialize (name, attributes);\r
- file = attributes ["siteMapFile"];\r
-\r
- if (file == null && file.Length == 0)\r
- throw new ArgumentException ("you must provide a file");\r
- \r
- if (UrlUtils.IsRelativeUrl (file))\r
- file = Path.Combine(HttpRuntime.AppDomainAppPath, file);\r
- else\r
- file = UrlUtils.ResolvePhysicalPathFromAppAbsolute (file);\r
-\r
-#if !TARGET_JVM // Java platform does not support file notifications\r
- if (File.Exists (file)) {\r
- watcher = new FileSystemWatcher ();\r
- watcher.Path = Path.GetFullPath (Path.GetDirectoryName (file));\r
- watcher.Filter = Path.GetFileName (file);\r
- watcher.Changed += new FileSystemEventHandler (OnFileChanged);\r
- watcher.EnableRaisingEvents = true;\r
- }\r
-#endif\r
- }\r
-\r
- protected override void RemoveNode (SiteMapNode node)\r
- {\r
- base.RemoveNode (node);\r
- }\r
-\r
- //[MonoTODO ("Not implemented")]\r
- protected virtual void RemoveProvider (string providerName)\r
- {\r
- throw new NotImplementedException ();\r
- }\r
-#if !TARGET_JVM\r
- void OnFileChanged (object sender, FileSystemEventArgs args)\r
- {\r
- Clear ();\r
- }\r
-#endif\r
- public override SiteMapNode RootNode {\r
- get {\r
- BuildSiteMap ();\r
- return root;\r
- }\r
- }\r
- \r
- protected override SiteMapNode GetRootNodeCore ()\r
- {\r
- return BuildSiteMap ();\r
- }\r
- }\r
-\r
-}\r
-\r
-\r