2 // The FeedUpdateBroker class implements a simple RSS fetcher and parser. |
2 // The FeedUpdateBroker class implements a simple RSS fetcher and parser. |
3 // Adapted from WRTKit RssReader example |
3 // Adapted from WRTKit RssReader example |
4 |
4 |
5 // Constructor. |
5 // Constructor. |
6 function FeedUpdateBroker() { |
6 function FeedUpdateBroker() { |
7 this.escapeLtGt=true; |
|
8 this.httpReq = null; |
7 this.httpReq = null; |
9 this.feedAddress = null; |
8 this.feedAddress = null; |
10 this.callback = null; |
9 this.callback = null; |
11 this.ignoreContent = false; |
10 this.ignoreContent = false; |
12 this.cancelled = false; |
11 this.cancelled = false; |
94 while (node != null) { |
93 while (node != null) { |
95 if (node.nodeType == Node.ELEMENT_NODE) { |
94 if (node.nodeType == Node.ELEMENT_NODE) { |
96 if (node.nodeName == "pubDate" || |
95 if (node.nodeName == "pubDate" || |
97 node.nodeName == "lastBuildDate" || |
96 node.nodeName == "lastBuildDate" || |
98 node.nodeName == "dc:date") { |
97 node.nodeName == "dc:date") { |
99 lastModified = getTextOfNode(node, this.escapeLtGt); |
98 lastModified = getTextOfNode(node); |
100 break; |
99 break; |
101 } |
100 } |
102 } |
101 } |
103 node = node.nextSibling; |
102 node = node.nextSibling; |
104 } |
103 } |
124 node = itemElements[i].firstChild; |
123 node = itemElements[i].firstChild; |
125 while (node != null) { |
124 while (node != null) { |
126 if (node.nodeType == Node.ELEMENT_NODE) { |
125 if (node.nodeType == Node.ELEMENT_NODE) { |
127 if (node.nodeName == "title") { |
126 if (node.nodeName == "title") { |
128 // item title |
127 // item title |
129 title = getTextOfNode(node, this.escapeLtGt); |
128 title = getTextOfNode(node); |
130 } else if (node.nodeName == "pubDate" || node.nodeName == "dc:date") { |
129 } else if (node.nodeName == "pubDate" || node.nodeName == "dc:date") { |
131 // item publishing date |
130 // item publishing date |
132 date = getTextOfNode(node, this.escapeLtGt); |
131 date = getTextOfNode(node); |
133 } else if (node.nodeName == "description" && !this.ignoreContent ) { |
132 } else if (node.nodeName == "description" && !this.ignoreContent ) { |
134 // item description |
133 // item description |
135 description = getTextOfNode(node, this.escapeLtGt); |
134 description = getTextOfNode(node); |
136 } else if (node.nodeName == "link") { |
135 } else if (node.nodeName == "link") { |
137 // link URL |
136 // link URL |
138 url = getTextOfNode(node, this.escapeLtGt); |
137 url = getTextOfNode(node); |
139 } else if (node.nodeName == "dc:creator" ) { |
138 } else if (node.nodeName == "dc:creator" ) { |
140 author = getTextOfNode(node, this.escapeLtGt); |
139 author = getTextOfNode(node); |
141 } |
140 } |
142 } |
141 } |
143 node = node.nextSibling; |
142 node = node.nextSibling; |
144 } |
143 } |
145 |
144 |
154 return { status: "error" }; |
153 return { status: "error" }; |
155 } |
154 } |
156 } |
155 } |
157 |
156 |
158 // Returns the text of a node. |
157 // Returns the text of a node. |
159 function getTextOfNode(node, escapeLtGt) { |
158 function getTextOfNode(node) { |
160 var buf = ""; |
159 var buf = ""; |
161 // iterate through all child elements and collect all text to the buffer |
160 // iterate through all child elements and collect all text to the buffer |
162 var child = node.firstChild; |
161 var child = node.firstChild; |
163 while (child != null) { |
162 while (child != null) { |
164 if (child.nodeType == Node.TEXT_NODE || child.nodeType == Node.CDATA_SECTION_NODE) { |
163 if (child.nodeType == Node.TEXT_NODE || child.nodeType == Node.CDATA_SECTION_NODE) { |
165 // append text to buffer |
164 // append text to buffer |
166 if (buf != "") { |
165 if (buf != "") { |
167 buf += " "; |
166 buf += " "; |
168 } |
167 } |
169 buf += child.textContent; |
168 buf += child.textContent; |
170 // if (escapeLtGt) { |
|
171 // buf += doEscapeLtGt(child.nodeValue); |
169 // buf += doEscapeLtGt(child.nodeValue); |
172 // } else { |
|
173 // buf += child.nodeValue; |
|
174 // } |
|
175 } |
170 } |
176 child = child.nextSibling; |
171 child = child.nextSibling; |
177 } |
172 } |
178 |
173 |
179 return buf; |
174 return buf; |