net.rim.blackberry.api.browser
Class URLEncodedPostData

java.lang.Object
  extended by net.rim.blackberry.api.browser.PostData
      extended by net.rim.blackberry.api.browser.URLEncodedPostData

public final class URLEncodedPostData
extends PostData

Encodes form data using URL-encoding.

Encoding applies these rules, in order:

  1. Space characters are replaced by the plus "+" character.
  2. Reserved characters (";", "/", "?", ":", "=", "&") are replaced by their corresponding ASCII code in hex notation: "%HH". Note that "@" is also a reserved character, but IE does not encode it so we don't either.
  3. Line breaks are replaced by "CR LF" pairs (i.e., "%0D%0A").
  4. Alphanumeric characters are kept in their original state.
  5. Special characters ("-", "_", ".", "*") are also kept in their original state. Note that RFC 1738 specifies ("-", "_", ".", "*", "$", "+", "!", "'", "(", ")", ",") as being the special characters set but IE encodes all but the first four and this code does the same.
  6. All other characters are replaced by their corresponding ASCII code in hex notation: "%HH".
  7. The format of the encoded control is "name=value". Value can be null (or of zero length) but the name cannot. If the value is absent, the encoded control will look like "name=". If the name is absent, nothing is encoded.

This functionality is used during the submission of a form (GET or POST) that is to be encoded using the "application/x-www-form-urlencoded" content type.

Note: The "application/x-www-form-urlencoded" encoding type is inefficient for sending large quantities of binary data or text containing non-ASCII characters. The content type "multipart/form-data" should be used for submitting forms that contain files, non-ASCII data, and binary data.

Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 4.0.0

Field Summary
Category: Signed static String DEFAULT_CHARSET
          Default character set.
 
Fields inherited from class net.rim.blackberry.api.browser.PostData
ENCTYPE_MULTIPART_FORMDATA, ENCTYPE_URLENCODED
 
Constructor Summary
Category: Signed URLEncodedPostData(String charset, boolean useWAPConventions)
          Creates a new URLEncodedPostData instance for encoding form data.
Category: Signed URLEncodedPostData(String charset, String urlEncodedFormData)
          Creates a new URLEncodedPostData instance from previously-encoded form data.
 
Method Summary
Category: Signed  void append(String name, String value)
          Appends the given name-value pair to a buffer.
Category: Signed  byte[] getBytes()
          Retrieves the form data as a byte array suitable for use as an HTTP request body.
Category: Signed  String getCharset()
          Retrieves the character-encoding for the form data.
Category: Signed  String getContentType()
          Retrieves the content type of the form data, including parameters.
Category: Signed  void setData(Object data)
          Sets the form data.
Category: Signed  int size()
          Retrieves the size of the underlying storage buffer.
Category: Signed  String toString()
          Retrieves the encoded form data as a String.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 



Field Detail

DEFAULT_CHARSET

public static final String DEFAULT_CHARSET
Default character set.

See Also:
Constant Field Values
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 4.0.0


Constructor Detail

URLEncodedPostData

public URLEncodedPostData(String charset,
                          boolean useWAPConventions)
Creates a new URLEncodedPostData instance for encoding form data.

Parameters:
charset - Character encoding to use when writing the form data; if charset is null or an unsupported character encoding, iso-8859-1 is used
useWAPConventions - True if we should use WAP conventions for encoding the data and false otherwise (currently this parameter is ignored).
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 4.0.0

URLEncodedPostData

public URLEncodedPostData(String charset,
                          String urlEncodedFormData)
Creates a new URLEncodedPostData instance from previously-encoded form data.

Parameters:
charset - Character encoding of the data.
urlEncodedFormData - URL-encoded form data to use as basis for his object.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 4.0.0


Method Detail

getContentType

public String getContentType()
Retrieves the content type of the form data, including parameters.

Specified by:
getContentType in class PostData
Returns:
Form data content type.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 4.0.0

getCharset

public String getCharset()
Retrieves the character-encoding for the form data.

Returns:
Character set used for the form data.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 4.0.0

append

public void append(String name,
                   String value)
Appends the given name-value pair to a buffer.

Specified by:
append in class PostData
Parameters:
name - Name of the form control; If null or "", nothing is added.
value - Value of the form control; a null value is considered equivalent to "".
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 4.0.0

setData

public void setData(Object data)
Sets the form data.

Specified by:
setData in class PostData
Parameters:
data - URL-encoded form data; must be a String or StringBuffer.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 4.0.0

getBytes

public byte[] getBytes()
Retrieves the form data as a byte array suitable for use as an HTTP request body.

Specified by:
getBytes in class PostData
Returns:
Form data.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 4.0.0

toString

public String toString()
Retrieves the encoded form data as a String.

Overrides:
toString in class Object
Returns:
Form data.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 4.0.0

size

public int size()
Retrieves the size of the underlying storage buffer.

Specified by:
size in class PostData
Returns:
Size of the underlying buffer.
Category:
Signed: This element is only accessible by signed applications. If you intend to use this element, please visit http://www.blackberry.com/go/codesigning to obtain a set of code signing keys. Code signing is only required for applications running on BlackBerry smartphones; development on BlackBerry Smartphone Simulators can occur without code signing.
Since:
BlackBerry API 4.0.0





Copyright 1999-2011 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Java is a trademark of Oracle America Inc. in the US and other countries.
Legal