net.rim.device.api.browser.field2
Class BrowserFieldResponse

java.lang.Object
  extended by net.rim.device.api.browser.field2.BrowserFieldResponse
All Implemented Interfaces:
Connection, ContentConnection, HttpConnection, InputConnection, OutputConnection, StreamConnection

public class BrowserFieldResponse
extends Object
implements HttpConnection

This class can be used to create a static (simulated) response to be used by the BrowserField component to display web content. This is useful in scenarios where you want to simulate a http response without having to implement your own HttpConnection.

Since:
BlackBerry API 5.0.0

Field Summary
 
Fields inherited from interface javax.microedition.io.HttpConnection
GET, HEAD, HTTP_ACCEPTED, HTTP_BAD_GATEWAY, HTTP_BAD_METHOD, HTTP_BAD_REQUEST, HTTP_CLIENT_TIMEOUT, HTTP_CONFLICT, HTTP_CREATED, HTTP_ENTITY_TOO_LARGE, HTTP_EXPECT_FAILED, HTTP_FORBIDDEN, HTTP_GATEWAY_TIMEOUT, HTTP_GONE, HTTP_INTERNAL_ERROR, HTTP_LENGTH_REQUIRED, HTTP_MOVED_PERM, HTTP_MOVED_TEMP, HTTP_MULT_CHOICE, HTTP_NOT_ACCEPTABLE, HTTP_NOT_AUTHORITATIVE, HTTP_NOT_FOUND, HTTP_NOT_IMPLEMENTED, HTTP_NOT_MODIFIED, HTTP_NO_CONTENT, HTTP_OK, HTTP_PARTIAL, HTTP_PAYMENT_REQUIRED, HTTP_PRECON_FAILED, HTTP_PROXY_AUTH, HTTP_REQ_TOO_LONG, HTTP_RESET, HTTP_SEE_OTHER, HTTP_TEMP_REDIRECT, HTTP_UNAUTHORIZED, HTTP_UNAVAILABLE, HTTP_UNSUPPORTED_RANGE, HTTP_UNSUPPORTED_TYPE, HTTP_USE_PROXY, HTTP_VERSION, POST
 
Constructor Summary
BrowserFieldResponse(int responseCode, String responseMessage, String url, InputStream input, HttpHeaders responseHeaders)
          Creates a BrowserFieldResponse using the provided InputStream data.
BrowserFieldResponse(String url, byte[] data, String contentType)
          Creates a BrowserFieldResponse using the provided byte data and content type.
BrowserFieldResponse(String url, byte[] data, HttpHeaders responseHeaders)
          Creates a BrowserFieldResponse using the provided byte data.
BrowserFieldResponse(String url, InputStream input, String contentType)
          Creates a BrowserFieldResponse using the provided InputStream data and content type.
BrowserFieldResponse(String url, InputStream input, HttpHeaders responseHeaders)
          Creates a BrowserFieldResponse using the provided InputStream data.
 
Method Summary
 void close()
          Close the connection.
 long getDate()
          Returns the value of the date header field.
 String getEncoding()
          Returns a string describing the encoding of the content which the resource connected to is providing.
 long getExpiration()
          Returns the value of the expires header field.
 String getFile()
          Not implemented - will always return null unless overridden
 String getHeaderField(int n)
          Gets a header field value by index.
 String getHeaderField(String name)
          Returns the value of the named header field.
 long getHeaderFieldDate(String name, long def)
          Returns the value of the named field parsed as date.
 int getHeaderFieldInt(String name, int def)
          Returns the value of the named field parsed as a number.
 String getHeaderFieldKey(int n)
          Gets a header field key by index.
 String getHost()
          Returns the host information of the URL of this HttpConnection. e.g. host name or IPv4 address
 long getLastModified()
          Returns the value of the last-modified header field.
 long getLength()
          Returns the length of the content which is being provided.
 int getPort()
          Always returns 80
 String getProtocol()
          Always returns null
 String getQuery()
          Always returns null
 String getRef()
          Always returns null
 String getRequestMethod()
          Always returns null
 String getRequestProperty(String key)
          Always returns null
 int getResponseCode()
          Returns the HTTP response status code.
 String getResponseMessage()
          Gets the HTTP response message, if any, returned along with the response code from a server.
 String getType()
          Returns the type of content that the resource connected to is providing.
 String getURL()
          Return a string representation of the URL for this connection.
 DataInputStream openDataInputStream()
          Open and return a data input stream for a connection.
 DataOutputStream openDataOutputStream()
          Always returns null
 InputStream openInputStream()
          Open and return an input stream for a connection.
 OutputStream openOutputStream()
          Always returns null
 void setRequestMethod(String method)
          This method does nothing
 void setRequestProperty(String key, String value)
          This method does nothing
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 



Constructor Detail

BrowserFieldResponse

public BrowserFieldResponse(String url,
                            byte[] data,
                            String contentType)
Creates a BrowserFieldResponse using the provided byte data and content type. This response will appear as though it was received from the specified url.

Since:
BlackBerry API 5.0.0

BrowserFieldResponse

public BrowserFieldResponse(String url,
                            InputStream input,
                            String contentType)
Creates a BrowserFieldResponse using the provided InputStream data and content type. This response will appear as though it was received from the specified url.

Since:
BlackBerry API 5.0.0

BrowserFieldResponse

public BrowserFieldResponse(String url,
                            byte[] data,
                            HttpHeaders responseHeaders)
Creates a BrowserFieldResponse using the provided byte data. The content type for this data should be specified as a response header. This response will appear as though it was received from the specified url.

Since:
BlackBerry API 5.0.0

BrowserFieldResponse

public BrowserFieldResponse(String url,
                            InputStream input,
                            HttpHeaders responseHeaders)
Creates a BrowserFieldResponse using the provided InputStream data. The content type for this data should be specified as a response header. This response will appear as though it was received from the specified url.

Since:
BlackBerry API 5.0.0

BrowserFieldResponse

public BrowserFieldResponse(int responseCode,
                            String responseMessage,
                            String url,
                            InputStream input,
                            HttpHeaders responseHeaders)
Creates a BrowserFieldResponse using the provided InputStream data. The content type for this data should be specified as a response header. This response will appear as though it was received from the specified url.

This method also allows the HTTP response code/message to be specified.

Since:
BlackBerry API 5.0.0


Method Detail

getDate

public long getDate()
             throws IOException
Description copied from interface: HttpConnection
Returns the value of the date header field.

Specified by:
getDate in interface HttpConnection
Returns:
the sending date of the resource that the URL references, or 0 if not known. The value returned is the number of milliseconds since January 1, 1970 GMT.
Throws:
IOException - if an error occurred connecting to the server.
See Also:
HttpConnection.getDate()
Since:
BlackBerry API 5.0.0

getExpiration

public long getExpiration()
                   throws IOException
Description copied from interface: HttpConnection
Returns the value of the expires header field.

Specified by:
getExpiration in interface HttpConnection
Returns:
the expiration date of the resource that this URL references, or 0 if not known. The value is the number of milliseconds since January 1, 1970 GMT.
Throws:
IOException - if an error occurred connecting to the server.
See Also:
HttpConnection.getExpiration()
Since:
BlackBerry API 5.0.0

getFile

public String getFile()
Not implemented - will always return null unless overridden

Specified by:
getFile in interface HttpConnection
Returns:
the file portion of the URL of this HttpConnection. null is returned if there is no file.
Since:
BlackBerry API 5.0.0

getHeaderField

public String getHeaderField(int n)
                      throws IOException
Description copied from interface: HttpConnection
Gets a header field value by index.

Specified by:
getHeaderField in interface HttpConnection
Parameters:
n - the index of the header field
Returns:
the value of the nth header field or null if the array index is out of range. An empty String is returned if the field does not have a value.
Throws:
IOException - if an error occurred connecting to the server.
See Also:
HttpConnection.getHeaderField(int)
Since:
BlackBerry API 5.0.0

getHeaderField

public String getHeaderField(String name)
                      throws IOException
Description copied from interface: HttpConnection
Returns the value of the named header field.

Specified by:
getHeaderField in interface HttpConnection
Parameters:
name - of a header field.
Returns:
the value of the named header field, or null if there is no such field in the header.
Throws:
IOException - if an error occurred connecting to the server.
See Also:
HttpConnection.getHeaderField(String)
Since:
BlackBerry API 5.0.0

getHeaderFieldDate

public long getHeaderFieldDate(String name,
                               long def)
                        throws IOException
Description copied from interface: HttpConnection
Returns the value of the named field parsed as date. The result is the number of milliseconds since January 1, 1970 GMT represented by the named field.

This form of getHeaderField exists because some connection types (e.g., http-ng) have pre-parsed headers. Classes for that connection type can override this method and short-circuit the parsing.

Specified by:
getHeaderFieldDate in interface HttpConnection
Parameters:
name - the name of the header field.
def - a default value.
Returns:
the value of the field, parsed as a date. The value of the def argument is returned if the field is missing or malformed.
Throws:
IOException - if an error occurred connecting to the server.
See Also:
HttpConnection.getHeaderFieldDate(String,long)
Since:
BlackBerry API 5.0.0

getHeaderFieldInt

public int getHeaderFieldInt(String name,
                             int def)
                      throws IOException
Description copied from interface: HttpConnection
Returns the value of the named field parsed as a number.

This form of getHeaderField exists because some connection types (e.g., http-ng) have pre-parsed headers. Classes for that connection type can override this method and short-circuit the parsing.

Specified by:
getHeaderFieldInt in interface HttpConnection
Parameters:
name - the name of the header field.
def - the default value.
Returns:
the value of the named field, parsed as an integer. The def value is returned if the field is missing or malformed.
Throws:
IOException - if an error occurred connecting to the server.
See Also:
HttpConnection.getHeaderFieldInt(String,int)
Since:
BlackBerry API 5.0.0

getHeaderFieldKey

public String getHeaderFieldKey(int n)
                         throws IOException
Description copied from interface: HttpConnection
Gets a header field key by index.

Specified by:
getHeaderFieldKey in interface HttpConnection
Parameters:
n - the index of the header field
Returns:
the key of the nth header field or null if the array index is out of range.
Throws:
IOException - if an error occurred connecting to the server.
See Also:
HttpConnection.getHeaderFieldKey(int)
Since:
BlackBerry API 5.0.0

getHost

public String getHost()
Description copied from interface: HttpConnection
Returns the host information of the URL of this HttpConnection. e.g. host name or IPv4 address

Specified by:
getHost in interface HttpConnection
Returns:
the host information of the URL of this HttpConnection.
See Also:
HttpConnection.getHost()
Since:
BlackBerry API 5.0.0

getLastModified

public long getLastModified()
                     throws IOException
Description copied from interface: HttpConnection
Returns the value of the last-modified header field. The result is the number of milliseconds since January 1, 1970 GMT.

Specified by:
getLastModified in interface HttpConnection
Returns:
the date the resource referenced by this HttpConnection was last modified, or 0 if not known.
Throws:
IOException - if an error occurred connecting to the server.
See Also:
HttpConnection.getLastModified()
Since:
BlackBerry API 5.0.0

getPort

public int getPort()
Always returns 80

Specified by:
getPort in interface HttpConnection
Returns:
the network port number of the URL for this HttpConnection. The default HTTP port number (80) is returned if there was no port number in the string passed to Connector.open.
Since:
BlackBerry API 5.0.0

getProtocol

public String getProtocol()
Always returns null

Specified by:
getProtocol in interface HttpConnection
Returns:
the protocol of the URL of this HttpConnection.
Since:
BlackBerry API 5.0.0

getQuery

public String getQuery()
Always returns null

Specified by:
getQuery in interface HttpConnection
Returns:
the query portion of the URL of this HttpConnection. null is returned if there is no value.
Since:
BlackBerry API 5.0.0

getRef

public String getRef()
Always returns null

Specified by:
getRef in interface HttpConnection
Returns:
the ref portion of the URL of this HttpConnection. null is returned if there is no value.
Since:
BlackBerry API 5.0.0

getRequestMethod

public String getRequestMethod()
Always returns null

Specified by:
getRequestMethod in interface HttpConnection
Returns:
the HTTP request method
See Also:
HttpConnection.setRequestMethod(java.lang.String)
Since:
BlackBerry API 5.0.0

getRequestProperty

public String getRequestProperty(String key)
Always returns null

Specified by:
getRequestProperty in interface HttpConnection
Parameters:
key - the keyword by which the request property is known (e.g., "accept").
Returns:
the value of the named general request property for this connection. If there is no key with the specified name then null is returned.
See Also:
HttpConnection.setRequestProperty(java.lang.String, java.lang.String)
Since:
BlackBerry API 5.0.0

getResponseCode

public int getResponseCode()
                    throws IOException
Description copied from interface: HttpConnection
Returns the HTTP response status code. It parses responses like:
 HTTP/1.0 200 OK
 HTTP/1.0 401 Unauthorized
 
and extracts the ints 200 and 401 respectively. from the response (i.e., the response is not valid HTTP).

Specified by:
getResponseCode in interface HttpConnection
Returns:
the HTTP Status-Code or -1 if no status code can be discerned.
Throws:
IOException - if an error occurred connecting to the server.
See Also:
HttpConnection.getResponseCode()
Since:
BlackBerry API 5.0.0

getResponseMessage

public String getResponseMessage()
                          throws IOException
Description copied from interface: HttpConnection
Gets the HTTP response message, if any, returned along with the response code from a server. From responses like:
 HTTP/1.0 200 OK
 HTTP/1.0 404 Not Found
 
Extracts the Strings "OK" and "Not Found" respectively. Returns null if none could be discerned from the responses (the result was not valid HTTP).

Specified by:
getResponseMessage in interface HttpConnection
Returns:
the HTTP response message, or null
Throws:
IOException - if an error occurred connecting to the server.
See Also:
HttpConnection.getResponseMessage()
Since:
BlackBerry API 5.0.0

getURL

public String getURL()
Description copied from interface: HttpConnection
Return a string representation of the URL for this connection.

Specified by:
getURL in interface HttpConnection
Returns:
the string representation of the URL for this connection.
See Also:
HttpConnection.getURL()
Since:
BlackBerry API 5.0.0

setRequestMethod

public void setRequestMethod(String method)
                      throws IOException
This method does nothing

Specified by:
setRequestMethod in interface HttpConnection
Parameters:
method - the HTTP method
Throws:
IOException - if the method cannot be reset or if the requested method isn't valid for HTTP.
See Also:
HttpConnection.getRequestMethod()
Since:
BlackBerry API 5.0.0

setRequestProperty

public void setRequestProperty(String key,
                               String value)
                        throws IOException
This method does nothing

Specified by:
setRequestProperty in interface HttpConnection
Parameters:
key - the keyword by which the request is known (e.g., "accept").
value - the value associated with it.
Throws:
IOException - is thrown if the connection is in the connected state.
See Also:
HttpConnection.getRequestProperty(java.lang.String)
Since:
BlackBerry API 5.0.0

getType

public String getType()
Description copied from interface: ContentConnection
Returns the type of content that the resource connected to is providing. E.g. if the connection is via HTTP, then the value of the content-type header field is returned.

Specified by:
getType in interface ContentConnection
Returns:
the content type of the resource that the URL references, or null if not known.
See Also:
ContentConnection.getType()
Since:
BlackBerry API 5.0.0

getEncoding

public String getEncoding()
Description copied from interface: ContentConnection
Returns a string describing the encoding of the content which the resource connected to is providing. E.g. if the connection is via HTTP, the value of the content-encoding header field is returned.

Specified by:
getEncoding in interface ContentConnection
Returns:
the content encoding of the resource that the URL references, or null if not known.
See Also:
ContentConnection.getEncoding()
Since:
BlackBerry API 5.0.0

getLength

public long getLength()
Description copied from interface: ContentConnection
Returns the length of the content which is being provided. E.g. if the connection is via HTTP, then the value of the content-length header field is returned.

Specified by:
getLength in interface ContentConnection
Returns:
the content length of the resource that this connection's URL references, or -1 if the content length is not known.
See Also:
ContentConnection.getLength()
Since:
BlackBerry API 5.0.0

openInputStream

public InputStream openInputStream()
                            throws IOException
Description copied from interface: InputConnection
Open and return an input stream for a connection.

Specified by:
openInputStream in interface InputConnection
Returns:
An input stream
Throws:
IOException - If an I/O error occurs
See Also:
InputConnection.openInputStream()
Since:
BlackBerry API 5.0.0

openDataInputStream

public DataInputStream openDataInputStream()
                                    throws IOException
Description copied from interface: InputConnection
Open and return a data input stream for a connection.

Specified by:
openDataInputStream in interface InputConnection
Returns:
An input stream
Throws:
IOException - If an I/O error occurs
See Also:
InputConnection.openDataInputStream()
Since:
BlackBerry API 5.0.0

openOutputStream

public OutputStream openOutputStream()
                              throws IOException
Always returns null

Specified by:
openOutputStream in interface OutputConnection
Returns:
An output stream
Throws:
IOException - If an I/O error occurs
Since:
BlackBerry API 5.0.0

openDataOutputStream

public DataOutputStream openDataOutputStream()
                                      throws IOException
Always returns null

Specified by:
openDataOutputStream in interface OutputConnection
Returns:
An output stream
Throws:
IOException - If an I/O error occurs
Since:
BlackBerry API 5.0.0

close

public void close()
           throws IOException
Description copied from interface: Connection
Close the connection.

When a connection has been closed, access to any of its methods except this close() will cause an an IOException to be thrown. Closing an already closed connection has no effect. Streams derived from the connection may be open when method is called. Any open streams will cause the connection to be held open until they themselves are closed. In this latter case access to the open streams is permitted, but access to the connection is not.

BlackBerry Implementation Note: When developing applications for the BlackBerry Wireless handheld, note that the stream must be flushed or closed before the program exits, otherwise all pending data will be lost.

Specified by:
close in interface Connection
Throws:
IOException - If an I/O error occurs
See Also:
Connection.close()
Since:
BlackBerry API 5.0.0





Copyright 1999-2010 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Copyright 1993-2003 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. All Rights Reserved.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark of Sun Microsystems, Inc.