1 /* 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) 6 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: 13 14 The above copyright notice and this permission notice shall be included in all 15 copies or substantial portions of the Software. 16 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. 23 */ 24 namespace System.Web.Configuration 25 { 26 using System; 27 using System.Collections; 28 using System.Collections.Generic; 29 using System.Text; 30 using System.Reflection; 31 using System.IO; 32 33 internal class CapabilitiesResult : System.Web.HttpBrowserCapabilities 34 { 35 /// <summary> 36 /// Initializes a new instance of the Result class. 37 /// </summary> 38 /// <param name="items"> 39 /// This is the data which this class will be handle request made though this class. 40 /// </param> CapabilitiesResult(System.Collections.IDictionary items)41 internal CapabilitiesResult(System.Collections.IDictionary items) 42 : base() 43 { 44 base.Capabilities = items; 45 Capabilities ["browsers"] = new ArrayList (); 46 } 47 48 /// <summary> 49 /// 50 /// </summary> 51 /// <param name="name"></param> 52 /// <param name="value"></param> AddCapabilities(string name, string value)53 internal void AddCapabilities(string name, string value) 54 { 55 this.Capabilities[name] = value; 56 } 57 AddMatchingBrowserId(string id)58 internal void AddMatchingBrowserId (string id) 59 { 60 ArrayList al = Capabilities ["browsers"] as ArrayList; 61 if (al != null && !al.Contains (id)) 62 al.Add (id); 63 } 64 Replace(string item)65 internal virtual string Replace(string item) 66 { 67 if (item.IndexOf('$') > -1) 68 { 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) 74 { 75 return item; 76 } 77 for (int i = 0;i <= regxmatch.Count - 1;i++) 78 { 79 if (regxmatch[i].Success == true) 80 { 81 string c = regxmatch[i].Result("${Capability}"); 82 item = item.Replace("${" + c + "}", this[c]); 83 } 84 } 85 } 86 if (item.IndexOf('%') > -1) 87 { 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) 93 { 94 return item; 95 } 96 for (int i = 0;i <= regxmatch.Count - 1;i++) 97 { 98 if (regxmatch[i].Success == true) 99 { 100 string c = regxmatch[i].Result("${Capability}"); 101 item = item.Replace("%{" + c + "}", this[c]); 102 } 103 } 104 } 105 return item; 106 } 107 /// <summary> 108 /// Gets the keys returned from processing. 109 /// </summary> 110 public System.Collections.Specialized.StringCollection Keys 111 { 112 get 113 { 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(); 119 l.AddRange(a); 120 return l; 121 } 122 } 123 public string UserAgent 124 { 125 get 126 { 127 return this[""]; 128 } 129 } 130 } 131 } 132