AI2 Component  (Version nb184)
com.google.appinventor.components.runtime.Web Class Reference
Inheritance diagram for com.google.appinventor.components.runtime.Web:
com.google.appinventor.components.runtime.AndroidNonvisibleComponent com.google.appinventor.components.runtime.Component com.google.appinventor.components.runtime.Component

Classes

class  BuildRequestDataException
 

Public Member Functions

 Web (ComponentContainer container)
 
String Url ()
 
void Url (String url)
 
YailList RequestHeaders ()
 
void RequestHeaders (YailList list)
 
boolean AllowCookies ()
 
void AllowCookies (boolean allowCookies)
 
boolean SaveResponse ()
 
void SaveResponse (boolean saveResponse)
 
String ResponseFileName ()
 
void ResponseFileName (String responseFileName)
 
int Timeout ()
 
void Timeout (int timeout)
 
void ClearCookies ()
 
void Get ()
 
void PostText (final String text)
 
void PostTextWithEncoding (final String text, final String encoding)
 
void PostFile (final String path)
 
void PutText (final String text)
 
void PutTextWithEncoding (final String text, final String encoding)
 
void PutFile (final String path)
 
void Delete ()
 
void GotText (String url, int responseCode, String responseType, String responseContent)
 
void GotFile (String url, int responseCode, String responseType, String fileName)
 
void TimedOut (String url)
 
String BuildRequestData (YailList list)
 
String UriEncode (String text)
 
String UriDecode (String text)
 
Object JsonTextDecode (String jsonText)
 
Object JsonTextDecodeWithDictionaries (String jsonText)
 
String JsonObjectEncode (Object jsonObject)
 
Object XMLTextDecodeAsDictionary (String XmlText)
 
Object XMLTextDecode (String XmlText)
 
String HtmlTextDecode (String htmlText)
 
- Public Member Functions inherited from com.google.appinventor.components.runtime.AndroidNonvisibleComponent
HandlesEventDispatching getDispatchDelegate ()
 

Protected Member Functions

 Web ()
 
- Protected Member Functions inherited from com.google.appinventor.components.runtime.AndroidNonvisibleComponent
 AndroidNonvisibleComponent (Form form)
 

Additional Inherited Members

- Static Public Attributes inherited from com.google.appinventor.components.runtime.Component
static final String ASSET_DIRECTORY = "component"
 
static final int ALIGNMENT_NORMAL = 0
 
static final int ALIGNMENT_CENTER = 1
 
static final int ALIGNMENT_OPPOSITE = 2
 
static final int ACCELEROMETER_SENSITIVITY_WEAK = 1
 
static final int ACCELEROMETER_SENSITIVITY_MODERATE = 2
 
static final int ACCELEROMETER_SENSITIVITY_STRONG = 3
 
static final int BUTTON_SHAPE_DEFAULT = 0
 
static final int BUTTON_SHAPE_ROUNDED = 1
 
static final int BUTTON_SHAPE_RECT = 2
 
static final int BUTTON_SHAPE_OVAL = 3
 
static final int COLOR_NONE = 0x00FFFFFF
 
static final int COLOR_BLACK = 0xFF000000
 
static final int COLOR_BLUE = 0xFF0000FF
 
static final int COLOR_CYAN = 0xFF00FFFF
 
static final int COLOR_DKGRAY = 0xFF444444
 
static final int COLOR_GRAY = 0xFF888888
 
static final int COLOR_GREEN = 0xFF00FF00
 
static final int COLOR_LTGRAY = 0xFFCCCCCC
 
static final int COLOR_MAGENTA = 0xFFFF00FF
 
static final int COLOR_ORANGE = 0xFFFFC800
 
static final int COLOR_PINK = 0xFFFFAFAF
 
static final int COLOR_RED = 0xFFFF0000
 
static final int COLOR_WHITE = 0xFFFFFFFF
 
static final int COLOR_YELLOW = 0xFFFFFF00
 
static final int COLOR_DEFAULT = 0x00000000
 
static final String DEFAULT_VALUE_COLOR_NONE = "&H00FFFFFF"
 
static final String DEFAULT_VALUE_COLOR_BLACK = "&HFF000000"
 
static final String DEFAULT_VALUE_COLOR_BLUE = "&HFF0000FF"
 
static final String DEFAULT_VALUE_COLOR_CYAN = "&HFF00FFFF"
 
static final String DEFAULT_VALUE_COLOR_DKGRAY = "&HFF444444"
 
static final String DEFAULT_VALUE_COLOR_GRAY = "&HFF888888"
 
static final String DEFAULT_VALUE_COLOR_GREEN = "&HFF00FF00"
 
static final String DEFAULT_VALUE_COLOR_LTGRAY = "&HFFCCCCCC"
 
static final String DEFAULT_VALUE_COLOR_MAGENTA = "&HFFFF00FF"
 
static final String DEFAULT_VALUE_COLOR_ORANGE = "&HFFFFC800"
 
static final String DEFAULT_VALUE_COLOR_PINK = "&HFFFFAFAF"
 
static final String DEFAULT_VALUE_COLOR_RED = "&HFFFF0000"
 
static final String DEFAULT_VALUE_COLOR_WHITE = "&HFFFFFFFF"
 
static final String DEFAULT_VALUE_COLOR_YELLOW = "&HFFFFFF00"
 
static final String DEFAULT_VALUE_COLOR_DEFAULT = "&H00000000"
 
static final float FONT_DEFAULT_SIZE = 14
 
static final int LAYOUT_ORIENTATION_HORIZONTAL = ComponentConstants.LAYOUT_ORIENTATION_HORIZONTAL
 
static final int LAYOUT_ORIENTATION_VERTICAL = ComponentConstants.LAYOUT_ORIENTATION_VERTICAL
 
static final int SCALING_SCALE_PROPORTIONALLY = 0
 
static final int SCALING_SCALE_TO_FIT = 1
 
static final int TYPEFACE_DEFAULT = 0
 
static final int TYPEFACE_SANSSERIF = 1
 
static final int TYPEFACE_SERIF = 2
 
static final int TYPEFACE_MONOSPACE = 3
 
static final int LENGTH_PREFERRED = -1
 
static final int LENGTH_FILL_PARENT = -2
 
static final int LENGTH_UNKNOWN = -3
 
static final int LENGTH_PERCENT_TAG = -1000
 
static final int TOAST_LENGTH_SHORT = 0
 
static final int TOAST_LENGTH_LONG = 1
 
static final int DIRECTION_NORTH = 1
 
static final int DIRECTION_NORTHEAST = 2
 
static final int DIRECTION_EAST = 3
 
static final int DIRECTION_SOUTHEAST = 4
 
static final int DIRECTION_SOUTH = -1
 
static final int DIRECTION_SOUTHWEST = -2
 
static final int DIRECTION_WEST = -3
 
static final int DIRECTION_NORTHWEST = -4
 
static final int DIRECTION_NONE = 0
 
static final int DIRECTION_MIN = -4
 
static final int DIRECTION_MAX = 4
 
static float SLIDER_MIN_VALUE = 10
 
static float SLIDER_MAX_VALUE = 50
 
static float SLIDER_THUMB_VALUE = (SLIDER_MIN_VALUE + SLIDER_MAX_VALUE) / 2.0f
 
static final String DEFAULT_VALUE_TEXT_TO_SPEECH_COUNTRY = ""
 
static final String DEFAULT_VALUE_TEXT_TO_SPEECH_LANGUAGE = ""
 
- Protected Attributes inherited from com.google.appinventor.components.runtime.AndroidNonvisibleComponent
final Form form
 

Detailed Description

Non-visible component that provides functions for HTTP GET, POST, PUT, and DELETE requests.

Author
lizlo.nosp@m.oney.nosp@m.@goog.nosp@m.le.c.nosp@m.om (Liz Looney)
josma.nosp@m.sflo.nosp@m.res@g.nosp@m.mail.nosp@m..com (Jose Dominguez)

Definition at line 102 of file Web.java.

Constructor & Destructor Documentation

◆ Web() [1/2]

com.google.appinventor.components.runtime.Web.Web ( ComponentContainer  container)

Creates a new Web component.

Parameters
containerthe Form that this component is contained in.

Definition at line 227 of file Web.java.

◆ Web() [2/2]

com.google.appinventor.components.runtime.Web.Web ( )
protected

This constructor is for testing purposes only.

Definition at line 239 of file Web.java.

Member Function Documentation

◆ AllowCookies() [1/2]

boolean com.google.appinventor.components.runtime.Web.AllowCookies ( )

Whether the cookies from a response should be saved and used in subsequent requests. Cookies are only supported on Android version 2.3 or greater.

Returns
whether cookies should be allowed

Definition at line 308 of file Web.java.

◆ AllowCookies() [2/2]

void com.google.appinventor.components.runtime.Web.AllowCookies ( boolean  allowCookies)

Specifies whether cookies should be allowed

Definition at line 318 of file Web.java.

◆ BuildRequestData()

String com.google.appinventor.components.runtime.Web.BuildRequestData ( YailList  list)

Converts a list of two-element sublists, representing name and value pairs, to a string formatted as application/x-www-form-urlencoded media type, suitable to pass to PostText.

Parameters
lista list of two-element sublists representing name and value pairs

Definition at line 726 of file Web.java.

◆ ClearCookies()

void com.google.appinventor.components.runtime.Web.ClearCookies ( )

Definition at line 396 of file Web.java.

◆ Delete()

void com.google.appinventor.components.runtime.Web.Delete ( )

Performs an HTTP DELETE request using the Url property and retrieves the response.

If the SaveResponse property is true, the response will be saved in a file and the GotFile event will be triggered. The ResponseFileName property can be used to specify the name of the file.

If the SaveResponse property is false, the GotText event will be triggered.

Definition at line 614 of file Web.java.

◆ Get()

void com.google.appinventor.components.runtime.Web.Get ( )

Performs an HTTP GET request using the Url property and retrieves the response.

If the SaveResponse property is true, the response will be saved in a file and the GotFile event will be triggered. The ResponseFileName property can be used to specify the name of the file.

If the SaveResponse property is false, the GotText event will be triggered.

Definition at line 417 of file Web.java.

◆ GotFile()

void com.google.appinventor.components.runtime.Web.GotFile ( String  url,
int  responseCode,
String  responseType,
String  fileName 
)

Event indicating that a request has finished.

Parameters
urlthe URL used for the request
responseCodethe response code from the server
responseTypethe mime type of the response
fileNamethe full path name of the saved file

Definition at line 702 of file Web.java.

◆ GotText()

void com.google.appinventor.components.runtime.Web.GotText ( String  url,
int  responseCode,
String  responseType,
String  responseContent 
)

Event indicating that a request has finished.

Parameters
urlthe URL used for the request
responseCodethe response code from the server
responseTypethe mime type of the response
responseContentthe response content from the server

Definition at line 687 of file Web.java.

◆ HtmlTextDecode()

String com.google.appinventor.components.runtime.Web.HtmlTextDecode ( String  htmlText)

Decodes the given HTML text value.

HTML Character Entities such as &, <, >, ', and " are changed to &, <, >, ‘’, and". Entities such as&#xhhhh;, and&#nnnn;` are changed to the appropriate characters.

Parameters
htmlTextthe HTML text to decode
Returns
the decoded text

Definition at line 1022 of file Web.java.

◆ JsonObjectEncode()

String com.google.appinventor.components.runtime.Web.JsonObjectEncode ( Object  jsonObject)

Returns the value of a built-in type (i.e., boolean, number, text, list, dictionary) in its JavaScript Object Notation representation. If the value cannot be represented as JSON, the Screen's ErrorOccurred event will be run, if any, and the Web component will return the empty string.

Parameters
jsonObjectthe object to turn into JSON
Returns
the stringified JSON value

Definition at line 901 of file Web.java.

◆ JsonTextDecode()

Object com.google.appinventor.components.runtime.Web.JsonTextDecode ( String  jsonText)

Decodes the given JSON encoded value to produce a corresponding AppInventor value. A JSON list [x, y, z] decodes to a list (x y z), A JSON object with key A and value B, (denoted as {A:B}) decodes to a list ((A B)), that is, a list containing the two-element list (A B).

Use the method JsonTextDecodeWithDictionaries if you would prefer to get back dictionary objects rather than lists-of-lists in the result.

Parameters
jsonTextthe JSON text to decode
Returns
the decoded text

Definition at line 830 of file Web.java.

◆ JsonTextDecodeWithDictionaries()

Object com.google.appinventor.components.runtime.Web.JsonTextDecodeWithDictionaries ( String  jsonText)

decodes to a dictionary with the key a and value b.

Parameters
jsonTextThe JSON text to decode.
Returns
The decoded value.

Definition at line 849 of file Web.java.

◆ PostFile()

void com.google.appinventor.components.runtime.Web.PostFile ( final String  path)

Performs an HTTP POST request using the Url property and data from the specified file.

If the SaveResponse property is true, the response will be saved in a file and the GotFile event will be triggered. The ResponseFileName property can be used to specify the name of the file.

If the SaveResponse property is false, the GotText event will be triggered.

Parameters
paththe path of the file for the POST request

Definition at line 501 of file Web.java.

◆ PostText()

void com.google.appinventor.components.runtime.Web.PostText ( final String  text)

Performs an HTTP POST request using the Url property and the specified text.

The characters of the text are encoded using UTF-8 encoding.

If the SaveResponse property is true, the response will be saved in a file and the GotFile event will be triggered. The responseFileName property can be used to specify the name of the file.

If the SaveResponse property is false, the GotText event will be triggered.

Parameters
textthe text data for the POST request

Definition at line 454 of file Web.java.

◆ PostTextWithEncoding()

void com.google.appinventor.components.runtime.Web.PostTextWithEncoding ( final String  text,
final String  encoding 
)

Performs an HTTP POST request using the Url property and the specified text.

The characters of the text are encoded using the given encoding.

If the SaveResponse property is true, the response will be saved in a file and the GotFile event will be triggered. The ResponseFileName property can be used to specify the name of the file.

If the SaveResponse property is false, the GotText event will be triggered.

Parameters
textthe text data for the POST request
encodingthe character encoding to use when sending the text. If encoding is empty or null, UTF-8 encoding will be used.

Definition at line 480 of file Web.java.

◆ PutFile()

void com.google.appinventor.components.runtime.Web.PutFile ( final String  path)

Performs an HTTP PUT request using the Url property and data from the specified file.

If the SaveResponse property is true, the response will be saved in a file and the GotFile event will be triggered. The ResponseFileName property can be used to specify the name of the file.

If the SaveResponse property is false, the GotText event will be triggered.

Parameters
paththe path of the file for the PUT request

Definition at line 585 of file Web.java.

◆ PutText()

void com.google.appinventor.components.runtime.Web.PutText ( final String  text)

Performs an HTTP PUT request using the Url property and the specified text.

The characters of the text are encoded using UTF-8 encoding.

If the SaveResponse property is true, the response will be saved in a file and the GotFile event will be triggered. The responseFileName property can be used to specify the name of the file.

If the SaveResponse property is false, the GotText event will be triggered.

Parameters
textthe text data for the PUT request

Definition at line 538 of file Web.java.

◆ PutTextWithEncoding()

void com.google.appinventor.components.runtime.Web.PutTextWithEncoding ( final String  text,
final String  encoding 
)

Performs an HTTP PUT request using the Url property and the specified text.

The characters of the text are encoded using the given encoding.

If the SaveResponse property is true, the response will be saved in a file and the GotFile event will be triggered. The ResponseFileName property can be used to specify the name of the file.

If the SaveResponse property is false, the GotText event will be triggered.

Parameters
textthe text data for the PUT request
encodingthe character encoding to use when sending the text. If encoding is empty or null, UTF-8 encoding will be used.

Definition at line 564 of file Web.java.

◆ RequestHeaders() [1/2]

YailList com.google.appinventor.components.runtime.Web.RequestHeaders ( )

The request headers, as a list of two-element sublists. The first element of each sublist represents the request header field name. The second element of each sublist represents the request header field values, either a single value or a list containing multiple values.

Returns
the request headers.

Definition at line 278 of file Web.java.

◆ RequestHeaders() [2/2]

void com.google.appinventor.components.runtime.Web.RequestHeaders ( YailList  list)

Sets the request headers.

Parameters
lista list of two-element sublists, each representing a header name and values

Definition at line 288 of file Web.java.

◆ ResponseFileName() [1/2]

String com.google.appinventor.components.runtime.Web.ResponseFileName ( )

The name of the file where the response should be saved. If SaveResponse is true and ResponseFileName is empty, then a new file name will be generated.

Returns
the name of the file where the response should be saved

Definition at line 354 of file Web.java.

◆ ResponseFileName() [2/2]

void com.google.appinventor.components.runtime.Web.ResponseFileName ( String  responseFileName)

Specifies the name of the file where the response should be saved. If SaveResponse is true and ResponseFileName is empty, then a new file name will be generated.

Definition at line 366 of file Web.java.

◆ SaveResponse() [1/2]

boolean com.google.appinventor.components.runtime.Web.SaveResponse ( )

Returns whether the response should be saved in a file.

Definition at line 331 of file Web.java.

◆ SaveResponse() [2/2]

void com.google.appinventor.components.runtime.Web.SaveResponse ( boolean  saveResponse)

Specifies whether the response should be saved in a file.

Definition at line 341 of file Web.java.

◆ TimedOut()

void com.google.appinventor.components.runtime.Web.TimedOut ( String  url)

Event indicating that a request has timed out.

Parameters
urlthe URL used for the request

Definition at line 713 of file Web.java.

◆ Timeout() [1/2]

int com.google.appinventor.components.runtime.Web.Timeout ( )

Returns the number of milliseconds that each request will wait for a response before they time out. If set to 0 (the default), then the request will wait for a response indefinitely.

Definition at line 377 of file Web.java.

◆ Timeout() [2/2]

void com.google.appinventor.components.runtime.Web.Timeout ( int  timeout)

Returns the number of milliseconds that each request will wait for a response before they time out. If set to 0, then the request will wait for a response indefinitely.

Definition at line 388 of file Web.java.

◆ UriDecode()

String com.google.appinventor.components.runtime.Web.UriDecode ( String  text)

Decodes the encoded text value so that the values aren't URL encoded anymore.

Parameters
textthe text to encode
Returns
the decoded text

Definition at line 797 of file Web.java.

◆ UriEncode()

String com.google.appinventor.components.runtime.Web.UriEncode ( String  text)

Encodes the given text value so that it can be used in a URL.

Parameters
textthe text to encode
Returns
the encoded text

Definition at line 777 of file Web.java.

◆ Url() [1/2]

String com.google.appinventor.components.runtime.Web.Url ( )

The URL for the web request.

Returns
the URL

Definition at line 252 of file Web.java.

◆ Url() [2/2]

void com.google.appinventor.components.runtime.Web.Url ( String  url)

Specifies the URL.

Definition at line 262 of file Web.java.

◆ XMLTextDecode()

Object com.google.appinventor.components.runtime.Web.XMLTextDecode ( String  XmlText)

Decodes the given XML string to produce a list structure. <tag>string</tag> decodes to a list that contains a pair of tag and string. More generally, if obj1, obj2, ... are tag-delimited XML strings, then <tag>obj1 obj2 ...</tag> decodes to a list that contains a pair whose first element is tag and whose second element is the list of the decoded obj's, ordered alphabetically by tags.

Examples:

  • <foo><123/foo> decodes to a one-item list containing the pair (foo 123)
  • <foo>1 2 3</foo> decodes to a one-item list containing the pair (foo "1 2 3")
  • <a><foo>1 2 3</foo><bar>456</bar></a> decodes to a list containing the pair (a X) where X is a 2-item list that contains the pair (bar 123) and the pair (foo "1 2 3").

If the sequence of obj's mixes tag-delimited and non-tag-delimited items, then the non-tag-delimited items are pulled out of the sequence and wrapped with a "content" tag. For example, decoding <a><bar>456</bar>many<foo>1 2 3</foo>apples<a></code> is similar to above, except that the list X is a 3-item list that contains the additional pair whose first item is the string "content", and whose second item is the list (many, apples). This method signals an error and returns the empty list if the result is not well-formed XML.

Parameters
XmlTextthe XML text to decode
Returns
the decoded text

Definition at line 993 of file Web.java.

◆ XMLTextDecodeAsDictionary()

Object com.google.appinventor.components.runtime.Web.XMLTextDecodeAsDictionary ( String  XmlText)

Decodes the given XML string to produce a dictionary structure. The dictionary includes the special keys $tag, $localName, $namespace, $namespaceUri, $attributes, and $content, as well as a key for each unique tag for every node, which points to a list of elements of the same structure as described here.

The $tag key is the full tag name, e.g., foo:bar. The $localName is the local portion of the name (everything after the colon : character). If a namespace is given (everything before the colon : character), it is provided in $namespace and the corresponding URI is given in $namespaceUri. The attributes are stored in a dictionary in $attributes and the child nodes are given as a list under $content.

More Information on Special Keys

Consider the following XML document:

<ex:Book xmlns:ex="http://example.com/">
<ex:title xml:lang="en">On the Origin of Species</ex:title>
<ex:author>Charles Darwin</ex:author>
</ex:Book>

When parsed, the $tag key will be "ex:Book", the $localName key will be "Book", the $namespace key will be "ex", $namespaceUri will be "http://example.com/", the $attributes key will be a dictionary {} (xmlns is removed for the namespace), and the $content will be a list of two items representing the decoded <ex:title> and <ex:author> elements. The first item, which corresponds to the <ex:title> element, will have an $attributes key containing the dictionary {"xml:lang": "en"}. For each name=value attribute on an element, a key-value pair mapping name to value will exist in the $attributes dictionary. In addition to these special keys, there will also be "ex:title" and "ex:author" to allow lookups faster than having to traverse the $content list.

Parameters
XmlTextthe JSON text to decode
Returns
the decoded text

Definition at line 948 of file Web.java.


The documentation for this class was generated from the following file: