Merge pull request #5002 from BrzVlad/feature-sgen-modes
[mono.git] / mcs / class / System.Web / System.Web.Configuration_2.0 / WebConfigurationHost.cs
index 8c4f3fcd9358fc8285f11587b52995ffd8bb5ed9..85942d311a41401ea76c73d6ac30d9fde70dd1c4 100644 (file)
@@ -27,7 +27,6 @@
 // Copyright (C) 2005-2009 Novell, Inc (http://www.novell.com)
 //
 
-#if NET_2_0
 
 using System;
 using System.Collections;
@@ -139,23 +138,7 @@ namespace System.Web.Configuration
                                string mdir;
 
                                if (map == null)
-#if TARGET_J2EE
-                               {
-                                       // check META-INF/web.config exists
-                                       java.lang.ClassLoader cl = (java.lang.ClassLoader) AppDomain.CurrentDomain.GetData ("GH_ContextClassLoader");
-                                       if (cl == null)
-                                               return null;
-                                       java.io.InputStream wcs = cl.getResourceAsStream ("META-INF/web.config");
-                                       if (wcs == null)
-                                               return null;
-
-                                       wcs.close ();
-
-                                       return "/META-INF/web.config";
-                               }
-#else
                                        mdir = Path.GetDirectoryName (System.Runtime.InteropServices.RuntimeEnvironment.SystemConfigurationFile);
-#endif
                                else
                                        mdir = Path.GetDirectoryName (map.MachineConfigFilename);
 
@@ -191,7 +174,11 @@ namespace System.Web.Configuration
                {
                        string fullPath = (string) hostInitConfigurationParams [1];
                        map = (WebConfigurationFileMap) hostInitConfigurationParams [0];
-                       bool inAnotherApp = (bool) hostInitConfigurationParams [7];
+                       bool inAnotherApp = false;
+
+                       if ((hostInitConfigurationParams.Length > 7)
+                               && (hostInitConfigurationParams[7] is bool))
+                               inAnotherApp = (bool) hostInitConfigurationParams[7];
 
                        if (inAnotherApp)
                                appVirtualPath = fullPath;
@@ -302,28 +289,12 @@ namespace System.Web.Configuration
 
                internal static string GetWebConfigFileName (string dir)
                {
-#if TARGET_J2EE
-                       DirectoryInfo d = GetCaseSensitiveExistingDirectory (new DirectoryInfo (dir));
-                       if (d == null)
-                               return null;
-
-                       FileInfo file = (FileInfo) FindByName ("web.config", d.GetFiles ("W*"));
-                       if (file == null)
-                               file = (FileInfo) FindByName ("web.config", d.GetFiles ("w*"));
-
-                       if (file != null)
-                               return file.FullName;
-#else
                        AppDomain domain = AppDomain.CurrentDomain;
                        bool hosted = (domain.GetData (ApplicationHost.MonoHostedDataKey) as string) == "yes";
 
-                       if (hosted) {
-                               foreach (string fn in ApplicationHost.WebConfigFileNames) {
-                                       string file = Path.Combine (dir, fn);
-                                       if (File.Exists (file))
-                                               return file;
-                               }
-                       } else {
+                       if (hosted)
+                               return ApplicationHost.FindWebConfig (dir);
+                       else {
                                Assembly asm = Assembly.GetEntryAssembly () ?? Assembly.GetCallingAssembly ();
                                string name = Path.GetFileName (asm.Location);
                                string[] fileNames = new string[] {name + ".config", name + ".Config"};
@@ -336,35 +307,11 @@ namespace System.Web.Configuration
                                                return file;
                                }
                        }
-#endif                 
-                       return null;
-               }
-#if TARGET_J2EE
-               static DirectoryInfo GetCaseSensitiveExistingDirectory (DirectoryInfo dir) {
-                       if (dir == null)
-                               return null;
-                       if (dir.Exists)
-                               return dir;
-
-                       DirectoryInfo parent = GetCaseSensitiveExistingDirectory (dir.Parent);
-                       if (parent == null)
-                               return null;
-
-                       return (DirectoryInfo) FindByName (dir.Name, parent.GetDirectories ());
-               }
-               
-               static FileSystemInfo FindByName (string name, FileSystemInfo [] infos)
-               {
-                       for (int i = 0; i < infos.Length; i++) {
-                               if (String.Compare (name, infos [i].Name, StringComparison.OrdinalIgnoreCase) == 0)
-                                       return infos [i];
-                       }
                        return null;
                }
-#endif
                public virtual bool IsAboveApplication (string configPath)
                {
-                       throw new NotImplementedException ();
+                       return !configPath.Contains (HttpRuntime.AppDomainAppPath);
                }
                
                public virtual bool IsConfigRecordRequired (string configPath)
@@ -389,16 +336,25 @@ namespace System.Web.Configuration
                                        else
                                                normalized = configPath;
                                        
-                                       return (String.Compare (normalized, MachinePath, StringComparison.Ordinal) == 0) ||
-                                               (String.Compare (normalized, MachineWebPath, StringComparison.Ordinal) == 0) ||
-                                               (String.Compare (normalized, "/", StringComparison.Ordinal) == 0) ||
-                                               (String.Compare (normalized, "~", StringComparison.Ordinal) == 0) ||
-                                               (String.Compare (normalized, appVirtualPath) == 0);
+                                       if ((String.Compare (normalized, MachinePath, StringComparison.Ordinal) == 0) ||
+                                               (String.Compare (normalized, MachineWebPath, StringComparison.Ordinal) == 0))
+                                                       return true;
+                               
+                                       if ((String.Compare (normalized, appVirtualPath) != 0))
+                                               return IsApplication (normalized);
+                               
+                                       return true;
                                default:
                                        return true;
                        }
                }
                
+               [MonoTODO("Should return false in case strPath points to the root of an application.")]
+               internal bool IsApplication(string strPath)
+               {
+                       return true;
+               }
+               
                public virtual bool IsFile (string streamName)
                {
                        throw new NotImplementedException ();
@@ -412,18 +368,6 @@ namespace System.Web.Configuration
                public virtual Stream OpenStreamForRead (string streamName)
                {
                        if (!File.Exists (streamName)) {
-#if TARGET_J2EE
-                               if (streamName != null && (streamName.EndsWith ("machine.config") ||
-                                                          streamName.EndsWith ("web.config"))) {
-                                       if (streamName.StartsWith ("/"))
-                                               streamName = streamName.Substring (1);
-                                       java.lang.ClassLoader cl = (java.lang.ClassLoader) AppDomain.CurrentDomain.GetData ("GH_ContextClassLoader");
-                                       if (cl != null) {
-                                               java.io.InputStream inputStream = cl.getResourceAsStream (streamName);
-                                               return new System.Web.J2EE.J2EEUtils.InputStreamWrapper (inputStream);
-                                       }
-                               }
-#endif
                                return null;
                        }
                                
@@ -438,9 +382,9 @@ namespace System.Web.Configuration
 
                public virtual Stream OpenStreamForWrite (string streamName, string templateStreamName, ref object writeContext)
                {
-                       string rootConfigPath = GetWebConfigFileName (HttpRuntime.AppDomainAppPath);
-                       if (String.Compare (streamName, rootConfigPath, StringComparison.OrdinalIgnoreCase) == 0)
+                       if (!IsAboveApplication (streamName))
                                WebConfigurationManager.SuppressAppReload (true);
+
                        return new FileStream (streamName, FileMode.Create, FileAccess.Write);
                }
 
@@ -498,8 +442,8 @@ namespace System.Web.Configuration
                        // FileSystemWatcher monitor might have already delivered the
                        // notification. If the stream has been open using OpenStreamForWrite then
                        // we're safe, though.
-                       string rootConfigPath = GetWebConfigFileName (HttpRuntime.AppDomainAppPath);
-                       if (String.Compare (streamName, rootConfigPath, StringComparison.OrdinalIgnoreCase) == 0)
+
+                       if (!IsAboveApplication (streamName))
                                WebConfigurationManager.SuppressAppReload (true);
                }
 
@@ -550,4 +494,3 @@ namespace System.Web.Configuration
        }
 }
 
-#endif