3 Used to determine Browser Capabilities by the Browsers UserAgent String and related
4 Browser supplied Headers.
5 Copyright (C) 2002-Present Owen Brady (Ocean at owenbrady dot net)
6 and Dean Brettle (dean at brettle dot com)
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is furnished
13 to do so, subject to the following conditions:
15 The above copyright notice and this permission notice shall be included in all
16 copies or substantial portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
19 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
20 PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 namespace System.Web.Configuration
28 using System.Collections;
29 using System.Collections.Generic;
31 using System.Reflection;
34 internal class CapabilitiesResult : System.Web.HttpBrowserCapabilities
37 /// Initializes a new instance of the Result class.
39 /// <param name="items">
40 /// This is the data which this class will be handle request made though this class.
42 internal CapabilitiesResult(System.Collections.IDictionary items)
45 base.Capabilities = items;
46 Capabilities ["browsers"] = new ArrayList ();
52 /// <param name="name"></param>
53 /// <param name="value"></param>
54 internal void AddCapabilities(string name, string value)
56 this.Capabilities[name] = value;
59 internal void AddMatchingBrowserId (string id)
61 ArrayList al = Capabilities ["browsers"] as ArrayList;
62 if (al != null && !al.Contains (id))
66 internal virtual string Replace(string item)
68 if (item.IndexOf('$') > -1)
70 //nasty hack to convert regular expression replacement text into Capability item
71 //which we can use to replace with the actual values they are looking for.
72 System.Text.RegularExpressions.MatchCollection regxmatch;
73 regxmatch = System.Text.RegularExpressions.Regex.Matches(item, @"\$\{(?'Capability'\w*)\}");
74 if (regxmatch.Count == 0)
78 for (int i = 0;i <= regxmatch.Count - 1;i++)
80 if (regxmatch[i].Success == true)
82 string c = regxmatch[i].Result("${Capability}");
83 item = item.Replace("${" + c + "}", this[c]);
87 if (item.IndexOf('%') > -1)
89 //nasty hack to convert regular expression replacement text into Capability item
90 //which we can use to replace with the actual values they are looking for.
91 System.Text.RegularExpressions.MatchCollection regxmatch;
92 regxmatch = System.Text.RegularExpressions.Regex.Matches(item, @"\%\{(?'Capability'\w*)\}");
93 if (regxmatch.Count == 0)
97 for (int i = 0;i <= regxmatch.Count - 1;i++)
99 if (regxmatch[i].Success == true)
101 string c = regxmatch[i].Result("${Capability}");
102 item = item.Replace("%{" + c + "}", this[c]);
109 /// Gets the keys returned from processing.
111 public System.Collections.Specialized.StringCollection Keys
115 string[] a = new string[this.Capabilities.Keys.Count];
116 this.Capabilities.Keys.CopyTo(a, 0);
117 System.Array.Sort(a);
118 System.Collections.Specialized.StringCollection l;
119 l = new System.Collections.Specialized.StringCollection();
124 public string UserAgent