com.zenkey.net.prowser
Class Response

java.lang.Object
  extended by com.zenkey.net.prowser.Response

public class Response
extends Object

The Response class represents the data resulting from a web page request made by a Tab instance. A Response object is generated when a Tab executes a Request.

The data available in a Response object includes:

Response objects are only created by the Tab class; there are no public constructors for them.

A Response object is thread-safe. Once created, it cannot be altered.

Version:
$Revision: 1.2 $, $Date: 2006/02/21 19:37:18 $
See Also:
Tab, Request

Field Summary
static int ERR_GENERAL
          General error.
static int ERR_IO
          HTTP I/O (transport) error.
static int ERR_MAX_REDIRECTS
          Max HTTP redirects exceeded.
static int ERR_NO_LOCATION
          No "Location" field in header of redirection response.
static int ERR_NONE
          No error condition exists.
static int ERR_PROTOCOL
          HTTP protocol error.
static int ERR_TIMEOUT
          Request timed out.
static int ERR_URI
          URI error.
static int STATUS_NOT_OBTAINED
          The value returned by getStatus() when HTTP status information has not been obtained for the response.
 
Method Summary
 String getContentType()
          Returns the value of the HTTP Content-type header associated with this Response.
 long getDuration()
          Returns the number of milliseconds that it took to complete the request/response transaction that generated this Response.
 int getError()
          Returns a code indicating the error condition of the page request that generated this Response.
 String getErrorText()
          Returns text describing the error condition of the request that generated this Response.
 String getFilename()
          Returns the name of the web page file associated with this Response.
 byte[] getPageBytes()
          Returns the binary form of the retrieved web page associated with this Response.
 String getPageSource()
          Returns the textual form of the retrieved web page associated with this Response.
 Request getRequest()
          Returns the Request object that generated this Response.
 int getStatus()
          Returns the HTTP status code associated with this Response.
 String getStatusText()
          Returns the HTTP status text associated with this Response.
 String getStatusVersion()
          Returns the HTTP status version associated with this Response.
 Tab getTab()
          Returns the Tab that generated this Response.
 String getTitle()
          Returns the title of the web page associated with this Response, as specified in the <title> tag of the page's HTML source code.
 URI getUri()
          Returns the final URI of this Response.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERR_NONE

public static final int ERR_NONE
No error condition exists.

See Also:
getError(), getErrorText(), Constant Field Values

ERR_GENERAL

public static final int ERR_GENERAL
General error.

See Also:
getError(), getErrorText(), Constant Field Values

ERR_PROTOCOL

public static final int ERR_PROTOCOL
HTTP protocol error.

See Also:
getError(), getErrorText(), Constant Field Values

ERR_IO

public static final int ERR_IO
HTTP I/O (transport) error.

See Also:
getError(), getErrorText(), Constant Field Values

ERR_MAX_REDIRECTS

public static final int ERR_MAX_REDIRECTS
Max HTTP redirects exceeded.

See Also:
getError(), getErrorText(), Constant Field Values

ERR_NO_LOCATION

public static final int ERR_NO_LOCATION
No "Location" field in header of redirection response.

See Also:
getError(), getErrorText(), Constant Field Values

ERR_URI

public static final int ERR_URI
URI error.

See Also:
getError(), getErrorText(), Constant Field Values

ERR_TIMEOUT

public static final int ERR_TIMEOUT
Request timed out.

See Also:
getError(), getErrorText(), Constant Field Values

STATUS_NOT_OBTAINED

public static final int STATUS_NOT_OBTAINED
The value returned by getStatus() when HTTP status information has not been obtained for the response.

See Also:
getStatus(), getStatusText(), getError(), Constant Field Values
Method Detail

getContentType

public String getContentType()
Returns the value of the HTTP Content-type header associated with this Response.

Returns:
The value of the HTTP Content-type header associated with this Response.

getDuration

public long getDuration()
Returns the number of milliseconds that it took to complete the request/response transaction that generated this Response.

Returns:
The number of milliseconds that it took to complete the request that generated this response.

getError

public int getError()
Returns a code indicating the error condition of the page request that generated this Response. If no error condition exists, ERR_NONE is returned; otherwise, one of the other ERR_xxx values are returned.

Returns:
A code representing the error condition of this request that generated this Response.
See Also:
ERR_NONE, getErrorText()

getErrorText

public String getErrorText()
Returns text describing the error condition of the request that generated this Response.

Returns:
A String describing the error condition of the request that generated this Response, or null if no error condition exists (i.e., getError() returns ERR_NONE).
See Also:
getError(), ERR_NONE

getFilename

public String getFilename()
Returns the name of the web page file associated with this Response. If the URI did not contain a filename, then an empty string is returned.

Returns:
The name of the web page file associated with this Response, or an empty string if the URI did not contain a filename.

getPageBytes

public byte[] getPageBytes()
Returns the binary form of the retrieved web page associated with this Response.

Returns:
The web page as a byte array.
See Also:
getPageSource()

getPageSource

public String getPageSource()
Returns the textual form of the retrieved web page associated with this Response. The returned value is a String encoded with the character set specified in the response header. If no encoding was supplied, the default encoding is used.

Returns:
The web page as an encoded string.
See Also:
getPageBytes()

getRequest

public Request getRequest()
Returns the Request object that generated this Response.

Returns:
The Request object that generated this Response.
See Also:
Request, Tab

getStatus

public int getStatus()
Returns the HTTP status code associated with this Response. If the response was not completed due to an error during the request, STATUS_NOT_OBTAINED will be returned.

Returns:
The HTTP status code associated with this Response, or STATUS_NOT_OBTAINED if an error occurred during the request.
See Also:
getStatusText(), getStatusVersion(), getError()

getStatusText

public String getStatusText()
Returns the HTTP status text associated with this Response.

Returns:
The HTTP status text associated with this Response, or null if an error occurred during the request (i.e., getStatus() returns STATUS_NOT_OBTAINED).
See Also:
getStatus(), getStatusVersion(), getError()

getStatusVersion

public String getStatusVersion()
Returns the HTTP status version associated with this Response.

Returns:
The HTTP status version associated with this Response, or null if an error occurred during the request (i.e., getStatus() returns STATUS_NOT_OBTAINED).
See Also:
getStatus(), getStatusText(), getError()

getTab

public Tab getTab()
Returns the Tab that generated this Response.

Returns:
The Tab that generated this Response.

getTitle

public String getTitle()
Returns the title of the web page associated with this Response, as specified in the <title> tag of the page's HTML source code. If the page is not HTML source (i.e., it's a binary file), then the filename is returned instead.

Note that all leading and trailing whitespace is trimmed from the title string before it is returned.

Returns:
The title of the web page associated with this Response, or the filename of the retrieved page if it is not in the form of HTML source code.

getUri

public URI getUri()
Returns the final URI of this Response. Note that this can be different from the Request URI because of server-side redirects that can occur during request processing. Think of this value as the URI that appears in a web browser's address bar after the page has completed loading.

Returns:
The the final URI of this Response.