Don't ignore drives with type "aufs" or "overlay" (Xamarin-31021)
[mono.git] / mcs / class / Mainsoft.Web / Mainsoft.Web / J2EEUtils.cs
1 //\r
2 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)\r
3 //\r
4 \r
5 //\r
6 // Permission is hereby granted, free of charge, to any person obtaining\r
7 // a copy of this software and associated documentation files (the\r
8 // "Software"), to deal in the Software without restriction, including\r
9 // without limitation the rights to use, copy, modify, merge, publish,\r
10 // distribute, sublicense, and/or sell copies of the Software, and to\r
11 // permit persons to whom the Software is furnished to do so, subject to\r
12 // the following conditions:\r
13 //\r
14 // The above copyright notice and this permission notice shall be\r
15 // included in all copies or substantial portions of the Software.\r
16 //\r
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
18 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
19 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
20 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
21 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
22 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
23 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
24 //\r
25 \r
26 using System;\r
27 using System.Web.Util;\r
28 using System.IO;\r
29 using vmw.@internal.io;\r
30 using vmw.common;\r
31 \r
32 using javax.servlet;\r
33 using System.Web;\r
34 using Mainsoft.Web.Hosting;\r
35 using System.Diagnostics;\r
36 \r
37 namespace Mainsoft.Web\r
38 {\r
39         internal static class J2EEUtils\r
40         {\r
41                 //public static string GetInitParameterByHierarchy(ServletConfig config, string name)\r
42                 //{\r
43                 //    if (config == null)\r
44                 //        throw new ArgumentNullException("config");\r
45 \r
46                 //    string value = config.getInitParameter(name);\r
47                 //    if (value != null)\r
48                 //        return value;\r
49 \r
50                 //    return config.getServletContext().getInitParameter(name);\r
51                 //}\r
52 \r
53                 public static string GetApplicationRealPath (ServletContext context) {\r
54                         return GetApplicationRealPath (context, "/");\r
55                 }\r
56 \r
57                 public static string GetApplicationRealPath (ServletContext context, string appVirtualPath)\r
58                 {\r
59                         string realFs = context.getInitParameter (J2EEConsts.FILESYSTEM_ACCESS);\r
60                         if (realFs == null || realFs == J2EEConsts.ACCESS_FULL) {\r
61                                 try {\r
62                                         string realPath = context.getRealPath (appVirtualPath);\r
63                                         if (!String.IsNullOrEmpty (realPath)) {\r
64                                                 if (!String.IsNullOrEmpty (appVirtualPath) &&\r
65                                                         appVirtualPath [appVirtualPath.Length - 1] == '/')\r
66                                                         if (realPath [realPath.Length - 1] != Path.DirectorySeparatorChar)\r
67                                                                 realPath += Path.DirectorySeparatorChar;\r
68 \r
69                                                 return realPath;\r
70                                         }\r
71                                 }\r
72                                 catch (Exception e) {\r
73                                         Trace.WriteLine (e.ToString());\r
74                                 }\r
75                         }\r
76                         return IAppDomainConfig.WAR_ROOT_SYMBOL + appVirtualPath;\r
77                 }\r
78 \r
79                 public static string GetApplicationPhysicalPath (ServletContext context) {\r
80                         string path = String.Empty;\r
81 \r
82                         string appDir = context.getInitParameter(IAppDomainConfig.APP_DIR_NAME);\r
83                         if (appDir != null) {\r
84                                 try {\r
85                                         if (Directory.Exists(appDir))\r
86                                                 path = appDir;\r
87                                 }\r
88                                 catch (Exception e) {\r
89                                         Trace.WriteLine (e.Message + appDir + "is invalid or unaccessible." +\r
90                                                 " If " + appDir + " really exists, check your security permissions");\r
91                                 }\r
92                         }\r
93                         if (path.Length == 0)\r
94                                 path = GetApplicationRealPath (context);\r
95 \r
96                         return path;\r
97                 }\r
98 \r
99                 static internal BaseWorkerRequest GetWorkerRequest (HttpContext context) {\r
100                         IServiceProvider sp = (IServiceProvider) context;\r
101                         return (BaseWorkerRequest) sp.GetService (typeof (HttpWorkerRequest));\r
102                 }\r
103         }\r
104 }\r