2 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
6 // Permission is hereby granted, free of charge, to any person obtaining
7 // a copy of this software and associated documentation files (the
8 // "Software"), to deal in the Software without restriction, including
9 // without limitation the rights to use, copy, modify, merge, publish,
10 // distribute, sublicense, and/or sell copies of the Software, and to
11 // permit persons to whom the Software is furnished to do so, subject to
12 // the following conditions:
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the Software.
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 using System
.Web
.Util
;
29 using vmw
.@internal.io
;
34 using Mainsoft
.Web
.Hosting
;
35 using System
.Diagnostics
;
37 namespace Mainsoft
.Web
39 internal static class J2EEUtils
41 //public static string GetInitParameterByHierarchy(ServletConfig config, string name)
43 // if (config == null)
44 // throw new ArgumentNullException("config");
46 // string value = config.getInitParameter(name);
50 // return config.getServletContext().getInitParameter(name);
53 public static string GetApplicationRealPath (ServletContext context
) {
54 return GetApplicationRealPath (context
, "/");
57 public static string GetApplicationRealPath (ServletContext context
, string appVirtualPath
)
59 string realFs
= context
.getInitParameter (J2EEConsts
.FILESYSTEM_ACCESS
);
60 if (realFs
== null || realFs
== J2EEConsts
.ACCESS_FULL
) {
62 string realPath
= context
.getRealPath (appVirtualPath
);
63 if (!String
.IsNullOrEmpty (realPath
)) {
64 if (!String
.IsNullOrEmpty (appVirtualPath
) &&
65 appVirtualPath
[appVirtualPath
.Length
- 1] == '/')
66 if (realPath
[realPath
.Length
- 1] != Path
.DirectorySeparatorChar
)
67 realPath
+= Path
.DirectorySeparatorChar
;
73 Trace
.WriteLine (e
.ToString());
76 return IAppDomainConfig
.WAR_ROOT_SYMBOL
+ appVirtualPath
;
79 public static string GetApplicationPhysicalPath (ServletContext context
) {
80 string path
= String
.Empty
;
82 string appDir
= context
.getInitParameter(IAppDomainConfig
.APP_DIR_NAME
);
85 if (Directory
.Exists(appDir
))
89 Trace
.WriteLine (e
.Message
+ appDir
+ "is invalid or unaccessible." +
90 " If " + appDir
+ " really exists, check your security permissions");
94 path
= GetApplicationRealPath (context
);
99 static internal BaseWorkerRequest
GetWorkerRequest (HttpContext context
) {
100 IServiceProvider sp
= (IServiceProvider
) context
;
101 return (BaseWorkerRequest
) sp
.GetService (typeof (HttpWorkerRequest
));