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 namespace Mainsoft.Web
\r
36 internal static class J2EEUtils
\r
38 public static string GetInitParameterByHierarchy(ServletConfig config, string name)
\r
41 throw new ArgumentNullException("config");
\r
43 string value = config.getInitParameter(name);
\r
47 return config.getServletContext().getInitParameter(name);
\r
50 public static string GetApplicationRealPath (ServletConfig config)
\r
52 string realFs = GetInitParameterByHierarchy (config, J2EEConsts.FILESYSTEM_ACCESS);
\r
53 if (realFs == null || realFs == J2EEConsts.ACCESS_FULL) {
\r
55 if (Path.IsPathRooted (config.getServletContext ().getRealPath ("")))
\r
56 return config.getServletContext ().getRealPath ("").Replace ("\\", "/").TrimEnd ('/');
\r
58 catch (ArgumentException e) {
\r
59 Console.WriteLine (e.Message);
\r
61 catch (Exception e) {
\r
62 Console.WriteLine (e.Message);
\r
65 return IAppDomainConfig.WAR_ROOT_SYMBOL;
\r
68 public static string GetApplicationPhysicalPath (ServletConfig config) {
\r
70 ServletContext context = config.getServletContext ();
\r
71 string appDir = GetInitParameterByHierarchy (config, IAppDomainConfig.APP_DIR_NAME);
\r
72 // Console.WriteLine("appdir = {0}", appDir);
\r
73 if (appDir != null) {
\r
75 java.io.File f = new java.io.File (appDir);
\r
77 // Console.WriteLine("Physical path= {0}", appDir);
\r
81 catch (Exception e) {
\r
82 Console.WriteLine (e.Message + appDir + "is invalid or unaccessible." +
\r
83 " If " + appDir + " really exists, check your security permissions");
\r
87 path = GetApplicationRealPath (config);
\r
90 if (!path.EndsWith ("/") && !path.EndsWith ("\\"))
\r
93 // Console.WriteLine("Physical path= {0}", path);
\r