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 namespace System.Web.J2EE
36 public class J2EEUtils
42 public static string GetApplicationRealPath(ServletConfig config)
44 string realFs = config.getInitParameter(J2EEConsts.FILESYSTEM_ACCESS);
45 if(realFs != null && realFs == J2EEConsts.ACCESS_FULL)
49 if(Path.IsPathRooted(config.getServletContext().getRealPath("")))
50 return config.getServletContext().getRealPath("").Replace("\\","/").TrimEnd('/');
52 catch (ArgumentException e)
54 Console.WriteLine(e.Message);
58 Console.WriteLine(e.Message);
61 return IAppDomainConfig.WAR_ROOT_SYMBOL;
64 public static string GetApplicationPhysicalPath(ServletConfig config) {
66 ServletContext context = config.getServletContext();
67 string appDir = config.getInitParameter(IAppDomainConfig.APP_DIR_NAME);
68 // Console.WriteLine("appdir = {0}", appDir);
73 java.io.File f = new java.io.File(appDir);
76 // Console.WriteLine("Physical path= {0}", appDir);
82 Console.WriteLine(e.Message + appDir + "is invalid or unaccessible." +
83 " If " + appDir + " really exists, check your security permissions");
88 path = GetApplicationRealPath(config);
91 if (!path.EndsWith ("/") && !path.EndsWith ("\\"))
94 // Console.WriteLine("Physical path= {0}", path);
98 public static int RunProc(string[] cmd)
100 java.lang.Runtime rt = java.lang.Runtime.getRuntime();
101 java.lang.Process proc = rt.exec(cmd);
103 StreamGobbler errorGobbler = new
104 StreamGobbler(proc.getErrorStream(), "ERROR");
106 StreamGobbler outputGobbler = new
107 StreamGobbler(proc.getInputStream(), "OUTPUT");
109 errorGobbler.start();
110 outputGobbler.start();
112 int exitVal = proc.waitFor();
117 public class StreamGobbler : java.lang.Thread
119 java.io.InputStream _is;
122 public StreamGobbler(java.io.InputStream ins, String type)
128 public override void run()
132 java.io.InputStreamReader isr = new java.io.InputStreamReader(_is);
133 java.io.BufferedReader br = new java.io.BufferedReader(isr);
135 while ( (line = br.readLine()) != null)
138 Console.WriteLine(_type + ">" + line);
145 Console.WriteLine(ex);
153 //stubs for CodeDom symbols
154 namespace System.CodeDom
156 public class CodeObject
158 protected CodeObject () { }
160 public System.Collections.IDictionary UserData { get { throw new NotSupportedException (); } }
163 public class CodeExpression : CodeObject
165 protected CodeExpression () { }