2 // (C) 2005 Mainsoft Corporation (http://www.mainsoft.com)
\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
14 // The above copyright notice and this permission notice shall be
\r
15 // included in all copies or substantial portions of the Software.
\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
27 using System.Web.Util;
\r
29 using vmw.@internal.io;
\r
32 using javax.servlet;
\r
34 using Mainsoft.Web.Hosting;
\r
35 using System.Diagnostics;
\r
37 namespace Mainsoft.Web
\r
39 internal static class J2EEUtils
\r
41 //public static string GetInitParameterByHierarchy(ServletConfig config, string name)
\r
43 // if (config == null)
\r
44 // throw new ArgumentNullException("config");
\r
46 // string value = config.getInitParameter(name);
\r
47 // if (value != null)
\r
50 // return config.getServletContext().getInitParameter(name);
\r
53 public static string GetApplicationRealPath (ServletContext context) {
\r
54 return GetApplicationRealPath (context, "/");
\r
57 public static string GetApplicationRealPath (ServletContext context, string appVirtualPath)
\r
59 string realFs = context.getInitParameter (J2EEConsts.FILESYSTEM_ACCESS);
\r
60 if (realFs == null || realFs == J2EEConsts.ACCESS_FULL) {
\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
72 catch (Exception e) {
\r
73 Trace.WriteLine (e.ToString());
\r
76 return IAppDomainConfig.WAR_ROOT_SYMBOL + appVirtualPath;
\r
79 public static string GetApplicationPhysicalPath (ServletContext context) {
\r
80 string path = String.Empty;
\r
82 string appDir = context.getInitParameter(IAppDomainConfig.APP_DIR_NAME);
\r
83 if (appDir != null) {
\r
85 if (Directory.Exists(appDir))
\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
93 if (path.Length == 0)
\r
94 path = GetApplicationRealPath (context);
\r
99 static internal BaseWorkerRequest GetWorkerRequest (HttpContext context) {
\r
100 IServiceProvider sp = (IServiceProvider) context;
\r
101 return (BaseWorkerRequest) sp.GetService (typeof (HttpWorkerRequest));
\r