2 // System.Web.XmlSiteMapProvider
5 // Ben Maurer (bmaurer@users.sourceforge.net)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System
.Collections
;
33 using System
.Collections
.Specialized
;
34 using System
.Configuration
;
37 using System
.Web
.Util
;
40 namespace System
.Web
{
41 public class XmlSiteMapProvider
: SiteMapProvider
, IDisposable
{
42 static readonly char [] seperators
= { ';', ',' }
;
45 public override SiteMapNode
BuildSiteMap ()
49 // Whenever you call AddNode, it tries to find dups, and will call this method
50 // Is this a bug in MS??
58 XmlDocument d
= new XmlDocument ();
61 root
= BuildSiteMapRecursive (d
.SelectSingleNode ("/siteMap/siteMapNode"));
68 string GetNonEmptyOptionalAttribute (XmlNode n
, string name
)
70 return System
.Web
.Configuration
.HandlersUtil
.ExtractAttributeValue (name
, n
, true);
73 string GetOptionalAttribute (XmlNode n
, string name
)
75 return System
.Web
.Configuration
.HandlersUtil
.ExtractAttributeValue (name
, n
, true, true);
79 SiteMapNode
BuildSiteMapRecursive (XmlNode xmlNode
)
82 if (xmlNode
.Name
!= "siteMapNode")
83 throw new ConfigurationException ("incorrect element name", xmlNode
);
85 string provider
= GetNonEmptyOptionalAttribute (xmlNode
, "provider");
86 string siteMapFile
= GetNonEmptyOptionalAttribute (xmlNode
, "siteMapFile");
88 if (provider
!= null) {
89 throw new NotImplementedException ();
90 } else if (siteMapFile
!= null) {
91 throw new NotImplementedException ();
94 string url
= GetOptionalAttribute (xmlNode
, "url");
95 string title
= GetOptionalAttribute (xmlNode
, "title");
96 string description
= GetOptionalAttribute (xmlNode
, "description");
97 string keywords
= GetOptionalAttribute (xmlNode
, "keywords");
98 string roles
= GetOptionalAttribute (xmlNode
, "roles");
100 ArrayList keywordsList
= new ArrayList ();
101 if (keywords
!= null) {
102 foreach (string s
in keywords
.Split (seperators
)) {
103 string ss
= s
.Trim ();
105 keywordsList
.Add (ss
);
109 ArrayList rolesList
= new ArrayList ();
111 foreach (string s
in roles
.Split (seperators
)) {
112 string ss
= s
.Trim ();
118 SiteMapNode node
= new SiteMapNode (this, url
, title
, description
,
119 ArrayList
.ReadOnly (keywordsList
), ArrayList
.ReadOnly (rolesList
),
120 null); // TODO what do they want for attributes
122 foreach (XmlNode child
in xmlNode
.ChildNodes
) {
123 if (child
.NodeType
!= XmlNodeType
.Element
)
125 AddNode (BuildSiteMapRecursive (child
), node
);
132 protected override void Clear ()
139 public void Dispose ()
145 public override SiteMapNode
FindSiteMapNode (string rawUrl
)
147 return base.FindSiteMapNode (rawUrl
); // why did they override this method!?
150 public override void Initialize (string name
, NameValueCollection attributes
)
153 base.Initialize (name
, attributes
);
154 file
= attributes
["siteMapFile"];
156 if (file
== null && file
.Length
== 0)
157 throw new ArgumentException ("you must provide a file");
159 if (UrlUtils
.IsRelativeUrl (file
))
160 file
= Path
.Combine(HttpRuntime
.AppDomainAppPath
, file
);
162 file
= UrlUtils
.ResolvePhysicalPathFromAppAbsolute (file
);
165 public override SiteMapNode RootNode
{
173 SiteMapNode root
= null;