1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
| package com.fkereki.rssread.client;
//... "import" lines ...
public class Rssreader implements EntryPoint {
// ... variable definitions...
public void onModuleLoad() {
// set up the form and its fields
// call getFeedViaProxy(...) or getFeedViaGoogle(...)
// depending on the listbox value
}
void getFeedViaProxy(final String feedUrl) {
// connect to the remote server via RPC
// when data arrives, call processAndShowFeed(...)
}
native void getFeedViaGoogle(final String feedUrl) /*-{
// call Google Feed API (using native JavaScript, not Java)
// when data arrives, call processAndShowFeed(...)
}-*/;
void processAndShowFeed(final String xmlDocument) {
// clear results from a previous run, if any
// decide whether it's RSS or Atom, and call
// processRssFeed() or processAtomFeed() as required
}
void processRssFeed(final Element root) {
// navigate a RSS feed, extraction titles, descriptions,
// and links, and using showFeedItem(...) to show them
}
void processAtomFeed(final Element root) {
// navigate an Atom feed, extraction titles, descriptions,
// and links (by using getValueIfPresent(...) and
// getLinkIfPresent(...), and showFeedItem(...) to show them
}
private String getValueIfPresent(final Element el, final String tn) {
// get an XML node, and return the value that corresponds to a certain tag
}
private String getLinkIfPresent(final Element el) {
// given a XML "link" node, return the corresponding address
}
private void showFeedItem(final String title, final String description,
final String link) {
// add some lines to the screen, with the data for the latest news
}
}
|