123 node = itemElements[i].firstChild; |
124 node = itemElements[i].firstChild; |
124 while (node != null) { |
125 while (node != null) { |
125 if (node.nodeType == Node.ELEMENT_NODE) { |
126 if (node.nodeType == Node.ELEMENT_NODE) { |
126 if (node.nodeName == "title") { |
127 if (node.nodeName == "title") { |
127 // item title |
128 // item title |
128 title = getTextOfNode(node); |
129 title = getTextOfNode(node, this.escapeLtGt); |
129 } else if (node.nodeName == "pubDate" || node.nodeName == "dc:date") { |
130 } else if (node.nodeName == "pubDate" || node.nodeName == "dc:date") { |
130 // item publishing date |
131 // item publishing date |
131 date = getTextOfNode(node); |
132 date = getTextOfNode(node, this.escapeLtGt); |
132 } else if (node.nodeName == "description" && !this.ignoreContent ) { |
133 } else if (node.nodeName == "description" && !this.ignoreContent ) { |
133 // item description |
134 // item description |
134 description = getTextOfNode(node); |
135 description = getTextOfNode(node, this.escapeLtGt); |
135 } else if (node.nodeName == "link") { |
136 } else if (node.nodeName == "link") { |
136 // link URL |
137 // link URL |
137 url = getTextOfNode(node); |
138 url = getTextOfNode(node, this.escapeLtGt); |
138 } else if (node.nodeName == "dc:creator" ) { |
139 } else if (node.nodeName == "dc:creator" ) { |
139 author = getTextOfNode(node); |
140 author = getTextOfNode(node, this.escapeLtGt); |
140 } |
141 } |
141 } |
142 } |
142 node = node.nextSibling; |
143 node = node.nextSibling; |
143 } |
144 } |
144 |
145 |
153 return { status: "error" }; |
154 return { status: "error" }; |
154 } |
155 } |
155 } |
156 } |
156 |
157 |
157 // Returns the text of a node. |
158 // Returns the text of a node. |
158 function getTextOfNode(node) { |
159 function getTextOfNode(node, escapeLtGt) { |
159 var buf = ""; |
160 var buf = ""; |
160 // iterate through all child elements and collect all text to the buffer |
161 // iterate through all child elements and collect all text to the buffer |
161 var child = node.firstChild; |
162 var child = node.firstChild; |
162 while (child != null) { |
163 while (child != null) { |
163 if (child.nodeType == Node.TEXT_NODE || child.nodeType == Node.CDATA_SECTION_NODE) { |
164 if (child.nodeType == Node.TEXT_NODE || child.nodeType == Node.CDATA_SECTION_NODE) { |
164 // append text to buffer |
165 // append text to buffer |
165 if (buf != "") { |
166 if (buf != "") { |
166 buf += " "; |
167 buf += " "; |
167 } |
168 } |
168 buf += escapeLtGt(child.nodeValue); |
169 buf += child.textContent; |
|
170 // if (escapeLtGt) { |
|
171 // buf += doEscapeLtGt(child.nodeValue); |
|
172 // } else { |
|
173 // buf += child.nodeValue; |
|
174 // } |
169 } |
175 } |
170 child = child.nextSibling; |
176 child = child.nextSibling; |
171 } |
177 } |
172 // strip all tags from the buffer |
|
173 var strippedBuf = ""; |
|
174 var textStartPos = -1; |
|
175 var tagBalance = 0; |
|
176 |
178 |
177 var pos; |
179 return buf; |
178 // iterate through the text and append all text to the stripped buffer |
180 // // strip all tags from the buffer |
179 // that is at a tag balance of 0 |
181 // var strippedBuf = ""; |
180 for (pos = 0; pos < buf.length; pos++) { |
182 // var textStartPos = -1; |
181 var c = buf.charAt(pos); |
183 // var tagBalance = 0; |
182 if (c == '<') { |
184 // |
183 // entering a tag |
185 // var pos; |
184 if (tagBalance == 0 && textStartPos != -1) { |
186 // // iterate through the text and append all text to the stripped buffer |
185 // everything up to here was valid text |
187 // // that is at a tag balance of 0 |
186 strippedBuf += buf.substring(textStartPos, pos); |
188 // for (pos = 0; pos < buf.length; pos++) { |
187 textStartPos = -1; |
189 // var c = buf.charAt(pos); |
188 } |
190 // if (c == '<') { |
189 tagBalance++; |
191 // // entering a tag |
190 } else if (c == '>') { |
192 // if (tagBalance == 0 && textStartPos != -1) { |
191 // leaving a tag |
193 // // everything up to here was valid text |
192 tagBalance--; |
194 // strippedBuf += buf.substring(textStartPos, pos); |
193 textStartPos = -1; |
195 // textStartPos = -1; |
194 } else if (tagBalance == 0 && textStartPos == -1) { |
196 // } |
195 // first char of text |
197 // tagBalance++; |
196 textStartPos = pos; |
198 // } else if (c == '>') { |
197 } |
199 // // leaving a tag |
198 } |
200 // tagBalance--; |
|
201 // textStartPos = -1; |
|
202 // } else if (tagBalance == 0 && textStartPos == -1) { |
|
203 // // first char of text |
|
204 // textStartPos = pos; |
|
205 // } |
|
206 // } |
|
207 // |
|
208 // // add remaining text - if any |
|
209 // if (tagBalance == 0 && textStartPos != -1) { |
|
210 // strippedBuf += buf.substring(textStartPos, pos); |
|
211 // } |
199 |
212 |
200 // add remaining text - if any |
213 // return strippedBuf; |
201 if (tagBalance == 0 && textStartPos != -1) { |
|
202 strippedBuf += buf.substring(textStartPos, pos); |
|
203 } |
|
204 |
|
205 return strippedBuf; |
|
206 } |
214 } |
207 |
215 |
208 FeedUpdateBroker.prototype.cancel = function() { |
216 FeedUpdateBroker.prototype.cancel = function() { |
209 this.cancelled = true; |
217 this.cancelled = true; |
210 this.httpReq.abort(); |
218 this.httpReq.abort(); |
211 } |
219 } |
212 |
220 |
213 function escapeLtGt(text){ |
221 function doEscapeLtGt(text){ |
214 var lt = "<"; |
222 var lt = "<"; |
215 var gt = ">"; |
223 var gt = ">"; |
216 return text.replace(/</g, lt).replace(/>/g, gt); |
224 return text.replace(/</g, lt).replace(/>/g, gt); |
217 } |
225 } |