Class CGIplus

java.lang.Object
   |
   +----CGIplus

public class CGIplus
extends Object
This class allows CGI scripting to be supported relatively simply using Java. Relies on the WASD HTTPd CGIplus environment providing the CGI variables in a data stream rather than as process environment variables.

Hence scripts must be activated via mapping rules that execute them within the CGIplus environment, although the scripts themselves do not have to "persist" in the usual CGIplus script manner, just "System.exit(0)" when finished processing (at the slight cost of destroying the subprocess).

Currently supports GET and "x-www-form-urlencoded" POST HTTP method scripts. Will be expanded to more fully support POST processing as time permits.

Version:
1.0.0, 09-DEC-97
Author:
MGD

Constructor Index

 o CGIplus()

Method Index

 o begin()
Begin script processing, and synchronize persistant (CGIplus) scripts.
 o dumpBody()
Output all lines in request body (for debugging POSTed requests, etc.)
 o dumpCgiVar()
Output all CGI variable 'name=value' pairs (for debugging, etc.)
 o dumpForm()
Output all form 'field=value' pairs (for debugging, etc).
 o end()
Conclude the response.
 o getCgiVar(String)
Return the value of the specified CGI variable name.
 o getCgiVarCount()
Return the number of CGI variables available.
 o getContentLength()
Returns the content-length of the body for a POSTed request.
 o getContentType()
Returns the MIME content-type of the body of a POSTed request.
 o getFormField(String)
Return the value of the specified form field name.
 o getFormFieldCount()
Return the number of form fields.
 o getUsageCount()
Return the number of times the script has been used.
 o isPOSTedForm()
Tests whether the request is POSTed and "www-form-urlencoded".
 o nextCgiVar()
Successive calls return each CGI variable 'name=value' pair.
 o nextFormField()
Successive calls return each form field 'name=value' pair.
 o readBodyLine()
Read a line from the body of the request (for POSTed requests).
 o urlDecode(String)
Decode the supplied URL-encoded string.

Constructors

 o CGIplus
 public CGIplus()

Methods

 o begin
 public void begin()
Begin script processing, and synchronize persistant (CGIplus) scripts. For the first call checks for the CGIPLUSEOF string (if not available reports it as an error and exits), then opens the CGIPLUSIN stream. Wait for a request to become available (first record read and discarded). Then read series of records up until the first empty record (indicates end of CGI variables), placing each of these records into a vector object for later search and retrieval.

Returns:
none
 o end
 public void end()
Conclude the response. Write the CGIplus end-of-output value to the server. Release any resources not relevant to next request (if CGIplus).

Returns:
none
 o getUsageCount
 public int getUsageCount()
Return the number of times the script has been used. Relevant only when behaving as a persistant, CGIplus script.

Returns:
none
 o getCgiVar
 public String getCgiVar(String varName)
Return the value of the specified CGI variable name. It is less expensive but not mandatory to supply the the "WWW_" prefix. Returns null if the specified variable name does not exist.

Parameters:
varName - the name of the CGI variable
Returns:
the CGI variable string
 o nextCgiVar
 public String nextCgiVar()
Successive calls return each CGI variable 'name=value' pair. Returns null and resets when the CGI variables are exhausted.

Returns:
the 'name=value' string
 o getCgiVarCount
 public int getCgiVarCount()
Return the number of CGI variables available.

Returns:
count of CGI variables
 o dumpCgiVar
 public void dumpCgiVar()
Output all CGI variable 'name=value' pairs (for debugging, etc.)

Returns:
none
 o getContentType
 public String getContentType()
Returns the MIME content-type of the body of a POSTed request.

Returns:
body content-type
 o isPOSTedForm
 public boolean isPOSTedForm()
Tests whether the request is POSTed and "www-form-urlencoded".

Returns:
true or false
 o getContentLength
 public int getContentLength()
Returns the content-length of the body for a POSTed request.

Returns:
length of POSTed body
 o readBodyLine
 public String readBodyLine()
Read a line from the body of the request (for POSTed requests).

Returns:
the line (or null if body exhausted)
 o dumpBody
 public void dumpBody()
Output all lines in request body (for debugging POSTed requests, etc.)

Returns:
none
 o dumpForm
 public void dumpForm()
Output all form 'field=value' pairs (for debugging, etc). For a 'x-www-form-urlencoded', POSTed request.

Returns:
the 'name=value' string
 o getFormField
 public String getFormField(String fieldName)
Return the value of the specified form field name. Returns null if the specified field name does not exist. For a 'x-www-form-urlencoded', POSTed request.

Parameters:
fieldName - the name of the field
Returns:
the (URL-decoded) field value
 o nextFormField
 public String nextFormField()
Successive calls return each form field 'name=value' pair. Returns null and resets when the form fields are exhausted. For a 'x-www-form-urlencoded', POSTed request.

Returns:
the 'name=value' string
 o getFormFieldCount
 public int getFormFieldCount()
Return the number of form fields. For a 'x-www-form-urlencoded', POSTed request.

Returns:
count of fields in request
 o urlDecode
 public String urlDecode(String estr)
Decode the supplied URL-encoded string. Converts '+' into ' ' and "%nn" hex-encoded values into their ASCII characters.

Parameters:
estr - the url-encoded string
Returns:
the decoded string