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