org.apache.catalina.servlets

Class CGIServlet.CGIEnvironment

protected class CGIServlet.CGIEnvironment extends Object

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

Since: Tomcat 4.0

Version: $Revision: 896371 $, $Date: 2010-01-06 11:30:07 +0100 (Wed, 06 Jan 2010) $

Constructor Summary
protected CGIEnvironment(HttpServletRequest req, ServletContext context)
Creates a CGIEnvironment and derives the necessary environment, query parameters, working directory, cgi command, etc.
Method Summary
protected StringblanksToString(String couldBeBlank, String subForBlanks)
Converts blank strings to another string
protected voidexpandCGIScript()
Extracts requested resource from web app archive to context work directory to enable CGI script to be executed.
protected String[]findCGI(String pathInfo, String webAppRootDir, String contextPath, String servletPath, String cgiPathPrefix)
Resolves core information about the cgi script.
protected StringgetCommand()
Gets derived command string
protected HashtablegetEnvironment()
Gets derived CGI environment
protected ArrayListgetParameters()
Gets derived CGI query parameters
protected FilegetWorkingDirectory()
Gets derived CGI working directory
protected booleanisValid()
Gets validity status
protected StringnullsToBlanks(String s)
Converts null strings to blank strings ("")
protected StringnullsToString(String couldBeNull, String subForNulls)
Converts null strings to another string
protected booleansetCGIEnvironment(HttpServletRequest req)
Constructs the CGI environment to be supplied to the invoked CGI script; relies heavliy on Servlet API methods and findCGI
protected voidsetupFromContext(ServletContext context)
Uses the ServletContext to set some CGI variables
protected voidsetupFromRequest(HttpServletRequest req)
Uses the HttpServletRequest to set most CGI variables
StringtoString()
Print important CGI environment information in a easy-to-read HTML table

Constructor Detail

CGIEnvironment

protected CGIEnvironment(HttpServletRequest req, ServletContext context)
Creates a CGIEnvironment and derives the necessary environment, query parameters, working directory, cgi command, etc.

Parameters: req HttpServletRequest for information provided by the Servlet API context ServletContext for information provided by the Servlet API

Method Detail

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 ("")

expandCGIScript

protected void expandCGIScript()
Extracts requested resource from web app archive to context work directory to enable CGI script to be executed.

findCGI

protected String[] findCGI(String pathInfo, String webAppRootDir, String contextPath, String servletPath, String cgiPathPrefix)
Resolves core information about the cgi script.

Example URI:

 /servlet/cgigateway/dir1/realCGIscript/pathinfo1 

CGI search algorithm: search the real path below <my-webapp-root> and find the first non-directory in the getPathTranslated("/"), reading/searching from left-to-right.

The CGI search path will start at webAppRootDir + File.separator + cgiPathPrefix (or webAppRootDir alone if cgiPathPrefix is null).

cgiPathPrefix is defined by setting this servlet's cgiPathPrefix init parameter

Parameters: pathInfo String from HttpServletRequest.getPathInfo() webAppRootDir String from context.getRealPath("/") contextPath String as from HttpServletRequest.getContextPath() servletPath String as from HttpServletRequest.getServletPath() cgiPathPrefix subdirectory of webAppRootDir below which the web app's CGIs may be stored; can be null. The CGI search path will start at webAppRootDir + File.separator + cgiPathPrefix (or webAppRootDir alone if cgiPathPrefix is null). cgiPathPrefix is defined by setting the servlet's cgiPathPrefix init parameter.

Returns:

Since: Tomcat 4.0

getCommand

protected String getCommand()
Gets derived command string

Returns: command string

getEnvironment

protected Hashtable getEnvironment()
Gets derived CGI environment

Returns: CGI environment

getParameters

protected ArrayList getParameters()
Gets derived CGI query parameters

Returns: CGI query parameters

getWorkingDirectory

protected File getWorkingDirectory()
Gets derived CGI working directory

Returns: working directory

isValid

protected boolean isValid()
Gets validity status

Returns: true if this environment is valid, false otherwise

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

setCGIEnvironment

protected boolean setCGIEnvironment(HttpServletRequest req)
Constructs the CGI environment to be supplied to the invoked CGI script; relies heavliy on Servlet API methods and findCGI

Parameters: req request associated with the CGI invokation

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

setupFromContext

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

Parameters: context ServletContext for information provided by the Servlet API

setupFromRequest

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

Parameters: req HttpServletRequest for information provided by the Servlet API

Throws: UnsupportedEncodingException

toString

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

Returns: HTML string containing CGI environment info

Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.