| Constructor: |
public ProcessEnvironment(HttpServletRequest req,
ServletContext context) {
this(req, context, 0);
}
Creates a ProcessEnvironment and derives the necessary environment,
working directory, command, etc. Parameters:
req - HttpServletRequest for information provided by
the Servlet API
context - ServletContext for information provided by
the Servlet API
|
public ProcessEnvironment(HttpServletRequest req,
ServletContext context,
int debug) {
this.debug = debug;
setupFromContext(context);
setupFromRequest(req);
this.valid = deriveProcessEnvironment(req);
if (log.isDebugEnabled())
log.debug(this.getClass().getName() + "() ctor, debug level " +
debug);
}
Creates a ProcessEnvironment and derives the necessary environment,
working directory, command, etc. Parameters:
req - HttpServletRequest for information provided by
the Servlet API
context - ServletContext for information provided by
the Servlet API
debug - int debug level (0 == none, 4 == medium, 6 == lots)
|
| Method from org.apache.catalina.util.ProcessEnvironment Detail: |
protected String blanksToString(String couldBeBlank,
String subForBlanks) {
return (("".equals(couldBeBlank) || couldBeBlank == null) ?
subForBlanks : couldBeBlank);
}
Converts blank strings to another string |
protected boolean deriveProcessEnvironment(HttpServletRequest req) {
Hashtable envp = new Hashtable();
command = getCommand();
if (command != null) {
workingDirectory = new
File(command.substring(0,
command.lastIndexOf(File.separator)));
envp.put("X_TOMCAT_COMMAND_PATH", command); //for kicks
}
this.env = envp;
return true;
}
|
public String getCommand() {
return command;
}
Gets derived command string |
public ServletContext getContext() {
return context;
}
|
public String getContextPath() {
return contextPath;
}
|
public Hashtable getEnvironment() {
return env;
}
Gets process' environment |
public String getServletPath() {
return servletPath;
}
|
public String getWebAppRootDir() {
return webAppRootDir;
}
Gets the root directory of the web application to which this process\
belongs |
public File getWorkingDirectory() {
return workingDirectory;
}
Gets this process' derived working directory |
public boolean isValid() {
return valid;
}
|
protected String nullsToBlanks(String s) {
return nullsToString(s, "");
}
Converts null strings to blank strings ("") |
protected String nullsToString(String couldBeNull,
String subForNulls) {
return (couldBeNull == null ? subForNulls : couldBeNull);
}
Converts null strings to another string |
protected String setCommand(String command) {
return command;
}
Sets the desired command string |
public Hashtable setEnvironment(Hashtable env) {
this.env = env;
return this.env;
}
Sets process' environment |
protected void setupFromContext(ServletContext context) {
this.context = context;
this.webAppRootDir = context.getRealPath("/");
}
Uses the ServletContext to set some process variables |
protected void setupFromRequest(HttpServletRequest req) {
this.contextPath = req.getContextPath();
this.pathInfo = req.getPathInfo();
this.servletPath = req.getServletPath();
}
Uses the HttpServletRequest to set most process variables |
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("< TABLE border=2 >");
sb.append("< tr >< th colspan=2 bgcolor=grey >");
sb.append("ProcessEnvironment Info< /th >< /tr >");
sb.append("< tr >< td >Debug Level< /td >< td >");
sb.append(debug);
sb.append("< /td >< /tr >");
sb.append("< tr >< td >Validity:< /td >< td >");
sb.append(isValid());
sb.append("< /td >< /tr >");
if (isValid()) {
Enumeration envk = env.keys();
while (envk.hasMoreElements()) {
String s = (String)envk.nextElement();
sb.append("< tr >< td >");
sb.append(s);
sb.append("< /td >< td >");
sb.append(blanksToString((String)env.get(s),
"[will be set to blank]"));
sb.append("< /td >< /tr >");
}
}
sb.append("< tr >< td colspan=2 >< HR >< /td >< /tr >");
sb.append("< tr >< td >Derived Command< /td >< td >");
sb.append(nullsToBlanks(command));
sb.append("< /td >< /tr >");
sb.append("< tr >< td >Working Directory< /td >< td >");
if (workingDirectory != null) {
sb.append(workingDirectory.toString());
}
sb.append("< /td >< /tr >");
sb.append("< /TABLE >< p >end.");
return sb.toString();
}
Print important process environment information in an
easy-to-read HTML table |