Merge pull request #3622 from rolfbjarne/remove-stray-file
[mono.git] / mcs / class / System.Web / System.Web / CapabilitiesLoader.cs
index b194770bd498593d4357790308127f6efe5c7e5f..4f82dfe0ae02a1bb6fa65a7cd208a7d1302e6951 100644 (file)
@@ -8,7 +8,7 @@
 // Authors:
 //   Gonzalo Paniagua Javier (gonzalo@ximian.com)
 //
-// (c) 2003 Novell, Inc. (http://www.novell.com)
+// (c) 2003-2009 Novell, Inc. (http://www.novell.com)
 //
 
 //
@@ -39,6 +39,7 @@ using System.Globalization;
 using System.IO;
 using System.Text.RegularExpressions;
 using System.Web.Configuration;
+using System.Web.Util;
 
 namespace System.Web
 {
@@ -50,11 +51,7 @@ 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)
@@ -109,7 +106,7 @@ namespace System.Web
                        ((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;
                }
@@ -141,7 +138,7 @@ namespace System.Web
                                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);
@@ -152,17 +149,9 @@ namespace System.Web
 
                        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
                }
        }
        
@@ -172,52 +161,15 @@ namespace System.Web
                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");
@@ -256,8 +208,6 @@ namespace System.Web
                        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");
@@ -340,7 +290,6 @@ namespace System.Web
                        defaultCaps.Add ("supportsuncheck", "True");
                        defaultCaps.Add ("supportsxmlhttp", "False");
                        defaultCaps.Add ("type", "Unknown");
-#endif
                }
                
                public static Hashtable GetCapabilities (string userAgent)
@@ -357,7 +306,7 @@ namespace System.Web
                                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;
                                        }
@@ -383,9 +332,6 @@ namespace System.Web
                        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)) {
@@ -393,7 +339,6 @@ namespace System.Web
                                        dir = Path.GetDirectoryName (dir);
                                        filepath = Path.Combine (dir, "browscap.ini");
                                }
-#endif
                                try {
                                        LoadFile (filepath);
                                } catch (Exception) {}
@@ -402,49 +347,16 @@ namespace System.Web
                        }
                }
 
-#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) {
@@ -488,7 +400,7 @@ namespace System.Web
                        
                        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]);