Java Reference
In-Depth Information
void fetch() {
String tag = input.getText();
int index = choice.getSelected();
String choiceString = (index == 1) ? "any" : "all";
Buffer query = new Buffer();
if(tag != null && tag.length() > 0) {
query.append("?tagmode=" + choiceString);
query.append("&tags=" + tag);
} Value arg = [
"ts" => 0,
"refresh" => true,
"max" => 10
Config config = getConfig();
call(null, "syndService", "getItems", arg, ok, nok);
The first few lines are used to get data typed in by the user and construct
a proper query string to pull data from the Flickr feed service. There are
two parameters: tags , used to filter feed contents to user's interests, and
tagmode , specifying whether the feed items should have all tags or just
one of them, in order to be included in the resulting feed.
Next we create a Value object, a general composite type that can
hold many different objects, primitive types and other Value objects. It
is used to communicate with the server in a generic manner much as
is done in Java with methods taking Object s as parameters, and then
casting them to something more meaningful, such as a String . The
Value object takes service parameters: ts means 'timestamp' and is
used to narrow the retrieval to a certain date; refresh means we want
fresh data from Flickr, not the data cached in the WidSets server; and
max sets the maximum number of items retrieved in this feed.
We then call the feed syndication service by its ID, syndService,
defined in the <services> item of widget.xml . We specify we want
to perform the getItems operation, passing in the arg parameter value
and two function pointers: ok , for successful operation, and nok , called
when any error occurs. Before jumping into the code for these two
functions, however, we use the Config object to set the URL of the feed
being downloaded. Why are we doing that?
Data feeds usually have static URLs, since they return the same data
day in and day out. The syndication service reflects this characteristic by
allowing a static URL to be configured in the <services> tag. However,
Flickr's public photo URL is not static: it allows a query string to be passed
as an argument to change the items presented in the feed. Therefore we
need to dynamically configure this service parameter to allow for more
Search WWH ::

Custom Search