Flash required to explore WidSets

The newest version of the Flash Player is required to explore WidSets. Please download and install the free Flash Player from the icon below.

After installation, refresh this page »

HTTP service - filtering

Forum » Development discussions » HTTP service - filtering

HTTP service - filtering

louenas  2007/09/10 19:34 UTC


Hi,

I'd like to know that when we use http service to retrieve a web page content, and use the filter, will the whole html page be retrieved on the client then it filters it and send to the widget, or does Widsets server filter the html first, then send the end result (filtered result) to the widget?

This question is to know how to optimize file transfer (bandwidth), thank you.

Re:HTTP service - filtering

render  2007/09/10 20:49 UTC


Server retrieves the web page and applies possible filters at server side. Only the filtered content gets sent to mobile.

See example from Developer kit devkit/examples/filter_test. (I cannot guarantee that the example works as the webpage might be changed after I made it but you can see how it should be done;)

It uses Regex filters. Xpath filters can be also used, if you web page is xhtml, or plain xml. You can also combine regex and xpath so if some sequence inside a webpage is well-formed you can apply xpath filters to it ;)

More information about filters can be found from http://dev.widsets.com/wiki/Advanced_filters

Re:HTTP service - filtering

louenas  2007/09/14 13:12 UTC


Hi,

Thanks for answering. I have another question: Is it possible to alphabetically sort the filtered data before sending it to the client widget? For example, i have this xml:

<phonebook>
<item>
<name>Joe</name>
</item>
<item>
<name>Annie</name>
</item>
</phonebook>

Is it posible to sort the filtered data in order to receive the ret variable like this:
ret[0] = Annie
ret[1] = Joe

instead of:
ret[0] = Joe
ret[1] = Annie

?

Re:HTTP service - filtering

render  2007/09/16 15:57 UTC


I don't think sorting is possible in xpath, all matches I found from the internet used some xml-library features.

However, you can sort your data at mobile-side

http://dev.widsets.com/apidocs/widsets/api/List.html#sort(Comparator)


Value ret = [your filtered data];
  
List list = new List();
for (Value v : ret) {
  list.add(v);
}
list.sort(sorter);

int sorter(Object o1, Object o2)
{
  Value v1 = Value(o1);
  Value v2 = Value(o2);
  return String(v1.name).compareTo(String(v2.name));
}



(Wrote that adhoc so there might be typos;)

That's not the fastest possible way but gets the job done, if there are <50 items it shouldn't matter.

Re:HTTP service - filtering

cello  2007/09/24 15:37 UTC


render wrote:
See example from Developer kit devkit/examples/filter_test. (I cannot guarantee that the example works as the webpage might be changed after I made it but you can see how it should be done;)


Thanks for the filter_test example!

I'm a WidSeteer rookie trying to learn how to use the HTTP service and filtering, so I started to read all Wiki articles about the HTTP Service and filters. I have average developer knowledge about HTTP, HTML and XML, and I have used Regex before (in Python scripts), so I guess I understand to some extent how this is meant to work in general for WidSets (but not in details).

Now I try to debug the filter_test example. I do not get rid of the sys.error: host parameter is null. Is there any trick to print regex strings and matches from the XML file? It seems like the regex matching fails, but since it only calls the onFailure function in the helium script I do not know how to debug. Can I use the printf in the helium script in some clever way?

I plan to use more complex regex filtering for HTML code in a new Widget, so I would appreciate any debugging tips for regex.

Re:HTTP service - filtering

frakuk  2007/09/24 16:34 UTC


http://www.google.com/calendar/feeds/b5nla154lt6fk7flq3ifmscvl8%40group.calendar.google.com/private-3ccf29fc6b4a596110808d2cd4c1c2d2/basic?orderby=starttime&sortorder=a&singleevents=true

Re:HTTP service - filtering

frakuk  2007/09/24 16:39 UTC


frakuk wrote:
Sorry too butt in but would this sort out my problem posted earlier about Google calendar?
Would the HTTP service return the this url in the order that the the url is defined and
would I have access to the google namespace API?
I'm also a nube at this and have some programming experience but any help would
be much appreciated.

Br
Jase

http://www.google.com/calendar/feeds/b5nla154lt6fk7flq3ifmscvl8%40group.calendar.google.com/private-3ccf29fc6b4a596110808d2cd4c1c2d2/basic?orderby=starttime&sortorder=a&singleevents=true

Re:HTTP service - filtering

cello  2007/09/25 08:52 UTC


I got the filter_test example running by fetching the number of the current week (instead of the Nokia stock quote) from another short URL with very simple HTML code (and thus very simple regex code :).

In order to contribute I published the slightly modified filter_test widget named "week" in the Library "Date & Time". I published the Widget as Editable, so you should be able to pick it and change it.

However, I would still appreciate any tips regarding debugging regex matching with the WidSets SDK.

Cheers
/A rookie WidSeteer

Re:HTTP service - filtering

render  2007/09/26 10:08 UTC


Yeah, Regex and Xpath filter debugging tools are on my TODO-list but not at the top of it ;(

Rule of the thumb in filters is, firstly make it simple as possible, then add more matching piece by piece.