com.go.teaservlet
Interface HttpContext

All Superinterfaces:
Context, OutputReceiver, UtilityContext
All Known Subinterfaces:
AdminHttpContext

public interface HttpContext
extends UtilityContext

The context that is used by the template to return its data. This class provides some additional HTTP-specific template functions.

Version:
41 , 00/12/12
Author:
Reece Wilton, Brian S O'Neill

Inner Class Summary
static interface HttpContext.Attributes
          The Attributes interface provides access to the request attributes.
static interface HttpContext.Cookies
          The Cookies interface provides access to the request cookies.
static interface HttpContext.Header
          The Header interface provides access to a request header value.
static interface HttpContext.Headers
          The Headers interface provides access to the request headers.
static interface HttpContext.Parameter
          The Parameter interface provides access to a request parameter value.
static interface HttpContext.Parameters
          The Parameters interface provides access to the request parameters.
static interface HttpContext.ParameterValues
          The ParameterValues interface provides access to the request parameter values.
static interface HttpContext.Request
          The Request interface provides access to the data that is passed to an HTTP servlet.
static class HttpContext.StringArrayList
          An ArrayList of Strings.
 
Method Summary
 java.lang.String encodeParameter(java.lang.String str)
          Encodes the given string so that it can be safely used in a URL.
 boolean fileExists(java.lang.String path)
          Tests if a file at the given path exists.
 HttpContext.Request getRequest()
          Gets an object that contains all the request information from the client.
 HttpContext.Request getRequest(java.lang.String encoding)
          Gets an object that contains all the request information from the client and all the parameters are converted using the specified character encoding.
 void insertFile(java.lang.String path)
          Inserts the contents of the given file into the page output or not at all if the file does not exist or cannot be read.
 void insertURL(java.lang.String URL)
          Inserts the contents of the resource at the given URL into the page output.
 java.lang.String readFile(java.lang.String path)
          Reads and returns the contents of the given file.
 java.lang.String readFile(java.lang.String path, java.lang.String encoding)
          Reads and returns the contents of the given file.
 java.lang.String readURL(java.lang.String URL)
          Reads and returns the contents of the given URL.
 java.lang.String readURL(java.lang.String URL, java.lang.String encoding)
          Reads and returns the contents of the given URL.
 void sendError(int code)
          Causes an error page to be generated using the given status code.
 void sendError(int code, java.lang.String message)
          Causes an error page to be generated using the given status code and message.
 void sendRedirect(java.lang.String url)
          Creates a response that forces the client to redirect to the given URL.
 void setContentType(java.lang.String type)
          Sets the MIME type of the page, like "text/html" or "text/plain".
 void setHeader(java.lang.String name, java.util.Date value)
          An advanced function that sets the date value of an arbitrary HTTP response header.
 void setHeader(java.lang.String name, int value)
          An advanced function that sets the integer value of an arbitrary HTTP response header.
 void setHeader(java.lang.String name, java.lang.String value)
          An advanced function that sets the string value of an arbitrary HTTP response header.
 void setStatus(int code)
          Sets the response's HTTP status code, like 200 for OK or 404 for not found.
 void setURLTimeout(long timeout)
          Requests to check, insert, or read URLs will timeout if the remote hosts doesn't respond in time.
 boolean URLExists(java.lang.String URL)
          Tests if a resource at the given URL exists.
 
Methods inherited from interface com.go.tea.runtime.UtilityContext
cardinal, cardinal, currentDate, endsWith, find, find, findFirst, findFirst, findLast, findLast, ordinal, ordinal, replace, replace, replace, replaceFirst, replaceFirst, replaceLast, replaceLast, shortOrdinal, shortOrdinal, startsWith, substring, substring, toLowerCase, toUpperCase, trim, trimLeading, trimTrailing
 
Methods inherited from interface com.go.tea.runtime.Context
dateFormat, dateFormat, getAvailableLocales, getAvailableTimeZones, getDateFormat, getDateFormatTimeZone, getLocale, getNullFormat, getNumberFormat, getNumberFormatInfinity, getNumberFormatNaN, nullFormat, numberFormat, numberFormat, print, print, print, print, print, print, print, setLocale, setLocale, setLocale, toString, toString, toString, toString, toString, toString, toString, toString
 

Method Detail

getRequest

public HttpContext.Request getRequest()
Gets an object that contains all the request information from the client.

getRequest

public HttpContext.Request getRequest(java.lang.String encoding)
Gets an object that contains all the request information from the client and all the parameters are converted using the specified character encoding.
Parameters:
encoding - the character encoding

setStatus

public void setStatus(int code)
Sets the response's HTTP status code, like 200 for OK or 404 for not found.
Parameters:
code - the status code int

sendError

public void sendError(int code)
               throws AbortTemplateException,
                      java.io.IOException
Causes an error page to be generated using the given status code. Further template processing is aborted and any output already provided by the template is not sent.
Parameters:
code - the error code int

sendError

public void sendError(int code,
                      java.lang.String message)
               throws AbortTemplateException,
                      java.io.IOException
Causes an error page to be generated using the given status code and message. Further template processing is aborted and any output already provided by the template is not sent.
Parameters:
code - the error code int
message - the error message

sendRedirect

public void sendRedirect(java.lang.String url)
                  throws AbortTemplateException,
                         java.io.IOException
Creates a response that forces the client to redirect to the given URL. Further template processing is aborted and any output already provided by the template is not sent.
Parameters:
url - the url to redirect to

setContentType

public void setContentType(java.lang.String type)
                    throws java.io.UnsupportedEncodingException,
                           java.io.IOException
Sets the MIME type of the page, like "text/html" or "text/plain". If another character encoding is desired, for internationalization, append charset property like this: "text/html; charset=iso-8859-1".
Parameters:
type - the MIME type of the page

setHeader

public void setHeader(java.lang.String name,
                      java.lang.String value)
An advanced function that sets the string value of an arbitrary HTTP response header.
Parameters:
name - the name of the header
value - the string value of the header

setHeader

public void setHeader(java.lang.String name,
                      int value)
An advanced function that sets the integer value of an arbitrary HTTP response header.
Parameters:
name - the name of the header
value - the int value of the header

setHeader

public void setHeader(java.lang.String name,
                      java.util.Date value)
An advanced function that sets the date value of an arbitrary HTTP response header.
Parameters:
name - the name of the header
value - the date value of the header

encodeParameter

public java.lang.String encodeParameter(java.lang.String str)
Encodes the given string so that it can be safely used in a URL. For example, '?' is encoded to '%3f'.
Parameters:
str - the string to encode

fileExists

public boolean fileExists(java.lang.String path)
                   throws java.io.IOException
Tests if a file at the given path exists. If the servlet that is running the template has a root directory, it is used to determine the physical file path. If the servlet does not have a root directory set, it is assumed to be the root of the file system. If the path given to this function does not lead with a slash, the path is relative to the pathInfo variable from the request.
Parameters:
path - the name of the file to test

insertFile

public void insertFile(java.lang.String path)
                throws java.io.IOException
Inserts the contents of the given file into the page output or not at all if the file does not exist or cannot be read. This function inserts the raw bytes from the file - no character conversion is applied. Consider using readFile in order to use character conversion.

If the servlet that is running the template has a root directory, it is used to determine the physical file path. If the servlet does not have a root directory set, it is assumed to be the root of the file system. If the path given to this function does not lead with a slash, the path is relative to the pathInfo variable from the request.

Parameters:
path - the name of the file to insert

readFile

public java.lang.String readFile(java.lang.String path)
                          throws java.io.IOException
Reads and returns the contents of the given file. If the file does not exist or cannot be read, an empty string is returned. This function differs from insertFile in that the character conversion is applied and the file's contents are returned.

If the servlet that is running the template has a root directory, it is used to determine the physical file path. If the servlet does not have a root directory set, it is assumed to be the root of the file system. If the path given to this function does not lead with a slash, the path is relative to the pathInfo variable from the request.

Parameters:
path - the name of the file to insert

readFile

public java.lang.String readFile(java.lang.String path,
                                 java.lang.String encoding)
                          throws java.io.IOException
Reads and returns the contents of the given file. If the file does not exist or cannot be read, an empty string is returned. This function differs from insertFile in that the character conversion is applied and the file's contents are returned.

If the servlet that is running the template has a root directory, it is used to determine the physical file path. If the servlet does not have a root directory set, it is assumed to be the root of the file system. If the path given to this function does not lead with a slash, the path is relative to the pathInfo variable from the request.

Parameters:
path - the name of the file to insert
encoding - character encoding

URLExists

public boolean URLExists(java.lang.String URL)
                  throws java.io.IOException
Tests if a resource at the given URL exists. If the URL has no protocol specified, then a relative lookup is performed. If the relative URL begins with a slash, the lookup is performed with an absolute path on the this server. If the relative URL does not begin with a slash, then the lookup is performed with a relative path.
Parameters:
url - the resource URL

insertURL

public void insertURL(java.lang.String URL)
               throws java.io.IOException
Inserts the contents of the resource at the given URL into the page output. If the resource does not exist or cannot be read, nothing is inserted. The given URL can be absolute or relative. This function inserts the raw bytes from the URL - no character conversion is applied. Consider using readURL in order to use character conversion.
Parameters:
url - the resource URL

readURL

public java.lang.String readURL(java.lang.String URL)
                         throws java.io.IOException
Reads and returns the contents of the given URL. If the URL does not exist or cannot be read, an empty string is returned. This function differs from insertURL in that the character conversion is applied and the resource's contents are returned.
Parameters:
path - the name of the file to insert

readURL

public java.lang.String readURL(java.lang.String URL,
                                java.lang.String encoding)
                         throws java.io.IOException
Reads and returns the contents of the given URL. If the URL does not exist or cannot be read, an empty string is returned. This function differs from insertURL in that the character conversion is applied and the resource's contents are returned.
Parameters:
path - the name of the file to insert
encoding - character encoding

setURLTimeout

public void setURLTimeout(long timeout)
Requests to check, insert, or read URLs will timeout if the remote hosts doesn't respond in time. Call this function to explicitly set the timeout value.
Parameters:
timeout - max time to wait for URL operation to complete, in milliseconds