// Authors:
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
//
-// (c) 2003 Novell, Inc. (http://www.novell.com)
+// (c) 2003-2009 Novell, Inc. (http://www.novell.com)
//
//
using System.IO;
using System.Text.RegularExpressions;
using System.Web.Configuration;
+using System.Web.Util;
namespace System.Web
{
BrowserData parent;
string text;
string pattern;
-#if TARGET_JVM
- java.util.regex.Pattern regex;
-#else
Regex regex;
-#endif
ListDictionary data;
public BrowserData (string pattern)
((ArrayList) tbl ["browsers"]).Add (tbl["browser"]);
foreach (string key in data.Keys)
- tbl [key.ToLower (CultureInfo.InvariantCulture).Trim ()] = data [key];
+ tbl [key.ToLower (Helpers.InvariantCulture).Trim ()] = data [key];
return tbl;
}
if (text [0] != expression [0] ||
String.Compare (text, 1, expression, 1,
text.Length - 1, false,
- CultureInfo.InvariantCulture) != 0) {
+ Helpers.InvariantCulture) != 0) {
return false;
}
expression = expression.Substring (text.Length);
lock (this_lock) {
if (regex == null)
-#if TARGET_JVM
- regex = java.util.regex.Pattern.compile (pattern);
-#else
regex = new Regex (pattern);
-#endif
}
-#if TARGET_JVM
- return regex.matcher ((java.lang.CharSequence) (object) expression).matches ();
-#else
return regex.Match (expression).Success;
-#endif
}
}
static Hashtable defaultCaps;
static readonly object lockobj = new object ();
-#if TARGET_JVM
- static bool loaded {
- get {
- return alldata != null;
- }
- set {
- if (alldata == null)
- alldata = new ArrayList ();
- }
- }
-
- const string alldataKey = "System.Web.CapabilitiesLoader.alldata";
- static ICollection alldata {
- get {
- return (ICollection) AppDomain.CurrentDomain.GetData (alldataKey);
- }
- set {
- AppDomain.CurrentDomain.SetData (alldataKey, value);
- }
- }
-
- const string userAgentsCacheKey = "System.Web.CapabilitiesLoader.userAgentsCache";
- static Hashtable userAgentsCache {
- get {
- lock (typeof (CapabilitiesLoader)) {
- Hashtable agentsCache = (Hashtable) AppDomain.CurrentDomain.GetData (userAgentsCacheKey);
- if (agentsCache == null) {
- agentsCache = Hashtable.Synchronized (new Hashtable (userAgentsCacheSize + 10));
- AppDomain.CurrentDomain.SetData (userAgentsCacheKey, agentsCache);
- }
-
- return agentsCache;
- }
- }
- }
-#else
static volatile bool loaded;
static ICollection alldata;
static Hashtable userAgentsCache = Hashtable.Synchronized(new Hashtable(userAgentsCacheSize+10));
-#endif
CapabilitiesLoader () {}
static CapabilitiesLoader ()
{
- defaultCaps = new Hashtable ();
+ defaultCaps = new Hashtable (StringComparer.OrdinalIgnoreCase);
defaultCaps.Add ("activexcontrols", "False");
defaultCaps.Add ("alpha", "False");
defaultCaps.Add ("aol", "False");
defaultCaps.Add ("win16", "False");
defaultCaps.Add ("win32", "False");
defaultCaps.Add ("win64", "False");
-
-#if NET_2_0
defaultCaps.Add ("adapters", new Hashtable ());
defaultCaps.Add ("cancombineformsindeck", "False");
defaultCaps.Add ("caninitiatevoicecall", "False");
defaultCaps.Add ("supportsuncheck", "True");
defaultCaps.Add ("supportsxmlhttp", "False");
defaultCaps.Add ("type", "Unknown");
-#endif
}
public static Hashtable GetCapabilities (string userAgent)
foreach (BrowserData bd in alldata) {
if (bd.IsMatch (userAgent)) {
Hashtable tbl;
- tbl = new Hashtable (defaultCaps);
+ tbl = new Hashtable (defaultCaps, StringComparer.OrdinalIgnoreCase);
userBrowserCaps = bd.GetProperties (tbl);
break;
}
lock (lockobj) {
if (loaded)
return;
-#if TARGET_J2EE
- string filepath = "browscap.ini";
-#else
string dir = HttpRuntime.MachineConfigurationDirectory;
string filepath = Path.Combine (dir, "browscap.ini");
if (!File.Exists (filepath)) {
dir = Path.GetDirectoryName (dir);
filepath = Path.Combine (dir, "browscap.ini");
}
-#endif
try {
LoadFile (filepath);
} catch (Exception) {}
}
}
-#if TARGET_J2EE
- static TextReader GetJavaTextReader(string filename)
- {
- try
- {
- java.lang.ClassLoader cl = (java.lang.ClassLoader)
- AppDomain.CurrentDomain.GetData("GH_ContextClassLoader");
- if (cl == null)
- return null;
-
- string custom = String.Concat("browscap/", filename);
-
- java.io.InputStream inputStream = cl.getResourceAsStream(custom);
- if (inputStream == null)
- inputStream = cl.getResourceAsStream(filename);
-
- if (inputStream == null)
- return null;
-
- return new StreamReader (new System.Web.J2EE.J2EEUtils.InputStreamWrapper (inputStream));
- }
- catch (Exception e)
- {
- return null;
- }
- }
-#endif
static void LoadFile (string filename)
{
-#if TARGET_J2EE
- TextReader input = GetJavaTextReader(filename);
- if(input == null)
- return;
-#else
if (!File.Exists (filename))
return;
TextReader input = new StreamReader (File.OpenRead (filename));
-#endif
using (input) {
string str;
- Hashtable allhash = new Hashtable ();
+ Hashtable allhash = new Hashtable (StringComparer.OrdinalIgnoreCase);
int aux = 0;
ArrayList browserData = new ArrayList ();
while ((str = input.ReadLine ()) != null) {
while ((str = input.ReadLine ()) != null && str.Length != 0) {
keyvalue = str.Split (eq, 2);
- key = keyvalue [0].ToLower (CultureInfo.InvariantCulture).Trim ();
+ key = keyvalue [0].ToLower (Helpers.InvariantCulture).Trim ();
if (key.Length == 0)
continue;
data.Add (key, keyvalue [1]);