org.apache.catalina.util

Class ProcessEnvironment

Known Direct Subclasses:
CGIProcessEnvironment

public class ProcessEnvironment
extends java.lang.Object

Encapsulates the Process environment and rules to derive that environment from the servlet container and request information.

Version:
$Revision: 1.4 $, $Date: 2004/05/26 16:21:04 $

Author:
Martin Dengler [root@martindengler.com]

Since:
Tomcat 4.0

Field Summary

protected String
command
command to be invoked
protected int
debug
the debugging detail level for this instance.
protected Hashtable
env
derived process environment
protected String
pathInfo
pathInfo for the current request
protected boolean
valid
whether or not this object is valid or not
protected File
workingDirectory
process' desired working directory

Constructor Summary

ProcessEnvironment(HttpServletRequest req, ServletContext context)
Creates a ProcessEnvironment and derives the necessary environment, working directory, command, etc.
ProcessEnvironment(HttpServletRequest req, ServletContext context, int debug)
Creates a ProcessEnvironment and derives the necessary environment, working directory, command, etc.

Method Summary

protected String
blanksToString(String couldBeBlank, String subForBlanks)
Converts blank strings to another string
protected boolean
deriveProcessEnvironment(HttpServletRequest req)
Constructs the Process environment to be supplied to the invoked process.
String
getCommand()
Gets derived command string
ServletContext
getContext()
String
getContextPath()
Hashtable
getEnvironment()
Gets process' environment
String
getServletPath()
String
getWebAppRootDir()
Gets the root directory of the web application to which this process\ belongs
File
getWorkingDirectory()
Gets this process' derived working directory
boolean
isValid()
Gets validity status
protected void
log(String s)
protected String
nullsToBlanks(String s)
Converts null strings to blank strings ("")
protected String
nullsToString(String couldBeNull, String subForNulls)
Converts null strings to another string
protected String
setCommand(String command)
Sets the desired command string
Hashtable
setEnvironment(Hashtable env)
Sets process' environment
protected void
setupFromContext(ServletContext context)
Uses the ServletContext to set some process variables
protected void
setupFromRequest(HttpServletRequest req)
Uses the HttpServletRequest to set most process variables
String
toString()
Print important process environment information in an easy-to-read HTML table

Field Details

command

protected String command
command to be invoked


debug

protected int debug
the debugging detail level for this instance.


env

protected Hashtable env
derived process environment


pathInfo

protected String pathInfo
pathInfo for the current request


valid

protected boolean valid
whether or not this object is valid or not


workingDirectory

protected File workingDirectory
process' desired working directory

Constructor Details

ProcessEnvironment

public ProcessEnvironment(HttpServletRequest req,
                          ServletContext context)
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


ProcessEnvironment

public ProcessEnvironment(HttpServletRequest req,
                          ServletContext context,
                          int 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 Details

blanksToString

protected String blanksToString(String couldBeBlank,
                                String subForBlanks)
Converts blank strings to another string

Parameters:
couldBeBlank - string to be converted if necessary
subForBlanks - string to return instead of a blank string

Returns:
a non-null string, either the original or the substitute string if the original was null or empty ("")


deriveProcessEnvironment

protected boolean deriveProcessEnvironment(HttpServletRequest req)
Constructs the Process environment to be supplied to the invoked process. Defines an environment no environment variables.

Should be overriden by subclasses to perform useful setup.

Parameters:
req - request associated with the Process' invocation

Returns:
true if environment was set OK, false if there was a problem and no environment was set


getCommand

public String getCommand()
Gets derived command string

Returns:
command string


getContext

public ServletContext getContext()


getContextPath

public String getContextPath()


getEnvironment

public Hashtable getEnvironment()
Gets process' environment

Returns:
process' environment


getServletPath

public String getServletPath()


getWebAppRootDir

public String getWebAppRootDir()
Gets the root directory of the web application to which this process\ belongs

Returns:
root directory


getWorkingDirectory

public File getWorkingDirectory()
Gets this process' derived working directory

Returns:
working directory


isValid

public boolean isValid()
Gets validity status

Returns:
true if this environment is valid, false otherwise


log

protected void log(String s)


nullsToBlanks

protected String nullsToBlanks(String s)
Converts null strings to blank strings ("")

Parameters:
s - string to be converted if necessary

Returns:
a non-null string, either the original or the empty string ("") if the original was null


nullsToString

protected String nullsToString(String couldBeNull,
                               String subForNulls)
Converts null strings to another string

Parameters:
couldBeNull - string to be converted if necessary
subForNulls - string to return instead of a null string

Returns:
a non-null string, either the original or the substitute string if the original was null


setCommand

protected String setCommand(String command)
Sets the desired command string

Parameters:
command - String command as desired

Returns:
command string


setEnvironment

public Hashtable setEnvironment(Hashtable env)
Sets process' environment

Parameters:
env - process' environment

Returns:
Hashtable to which the process' environment was set


setupFromContext

protected void setupFromContext(ServletContext context)
Uses the ServletContext to set some process variables

Parameters:
context - ServletContext for information provided by the Servlet API


setupFromRequest

protected void setupFromRequest(HttpServletRequest req)
Uses the HttpServletRequest to set most process variables

Parameters:
req - HttpServletRequest for information provided by the Servlet API


toString

public String toString()
Print important process environment information in an easy-to-read HTML table

Returns:
HTML string containing process environment info


Copyright B) 2000-2003 Apache Software Foundation. All Rights Reserved.