annotate js/feed-parser.js @ 19:3fcd2209b39a

Add support for RSS 1.0 feeds
author Guido Berhoerster <guido+feed-preview@berhoerster.name>
date Thu, 13 Dec 2018 09:02:40 +0100
parents 15db49e77deb
children da483ce3832d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
1 /*
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
2 * Copyright (C) 2018 Guido Berhoerster <guido+feed-preview@berhoerster.name>
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
3 *
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
4 * This Source Code Form is subject to the terms of the Mozilla Public
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
7 */
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
8
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
9 'use strict';
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
10
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
11 export const XMLNS = {
15
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
12 ATOM03: 'http://purl.org/atom/ns#',
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
13 ATOM10: 'http://www.w3.org/2005/Atom',
14
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
14 RSS09: 'http://my.netscape.com/rdf/simple/0.9/',
19
3fcd2209b39a Add support for RSS 1.0 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 18
diff changeset
15 RSS10: 'http://purl.org/rss/1.0/',
15
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
16 XHTML: 'http://www.w3.org/1999/xhtml',
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
17 PARSERERROR: 'http://www.mozilla.org/newlayout/xml/parsererror.xml'
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
18 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
19 const ALLOWED_LINK_PROTOCOLS = new Set(['http:', 'https:', 'ftp:']);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
20
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
21 function encodeXML(str) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
22 return str.replace(/[<>&'"]/g, c => {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
23 switch (c) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
24 case '<': return '&lt;';
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
25 case '>': return '&gt;';
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
26 case '&': return '&amp;';
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
27 case '\'': return '&apos;';
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
28 case '"': return '&quot;';
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
29 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
30 });
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
31 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
32
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
33 function parseDate(s) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
34 let date = new Date(s);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
35
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
36 return isNaN(date) ? new Date(0) : date;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
37 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
38
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
39 function parseURL(text, baseURL = '') {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
40 let url;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
41
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
42 try {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
43 url = new URL(text, baseURL);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
44 } catch (e) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
45 return null;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
46 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
47 if (!ALLOWED_LINK_PROTOCOLS.has(url.protocol)) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
48 return null;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
49 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
50
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
51 return url;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
52 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
53
15
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
54 function base64Decode(base64Str) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
55 let encodedText;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
56 try {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
57 encodedText = atob(base64Str);
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
58 } catch (e) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
59 throw (e instanceof DOMException) ? new TypeError(e.message) : e;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
60 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
61 let byteBuffer = new Uint8Array(new ArrayBuffer(encodedText.length));
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
62 for (let i = 0; i < encodedText.length; i++) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
63 byteBuffer[i] = encodedText.charCodeAt(i);
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
64 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
65 return new TextDecoder().decode(byteBuffer);
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
66 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
67
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
68 function feedNSResolver(prefix) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
69 switch (prefix) {
15
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
70 case 'atom03':
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
71 return XMLNS.ATOM03;
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
72 case 'atom':
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
73 return XMLNS.ATOM10;
19
3fcd2209b39a Add support for RSS 1.0 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 18
diff changeset
74 case 'rss09':
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
75 return XMLNS.RSS09;
19
3fcd2209b39a Add support for RSS 1.0 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 18
diff changeset
76 case 'rss10':
3fcd2209b39a Add support for RSS 1.0 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 18
diff changeset
77 return XMLNS.RSS10;
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
78 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
79 return null;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
80 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
81
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
82 function feedQueryXPath(feedDocument, scopeElement, xpathQuery) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
83 return feedDocument.evaluate(xpathQuery, scopeElement, feedNSResolver,
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
84 XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
85 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
86
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
87 function feedQueryXPathAll(feedDocument, scopeElement, xpathQuery) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
88 let result = feedDocument.evaluate(xpathQuery, scopeElement, feedNSResolver,
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
89 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
90 let nodes = [];
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
91 for (let node = result.iterateNext(); node !== null;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
92 node = result.iterateNext()) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
93 nodes.push(node);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
94 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
95
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
96 return nodes;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
97 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
98
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
99 export class ParserError extends Error {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
100 constructor() {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
101 super(...arguments);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
102 this.name = this.constructor.name;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
103 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
104 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
105
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
106 export class UnsupportedFeedTypeError extends Error {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
107 constructor(message = 'Document is not a supported feed', ...params) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
108 super(message, ...params);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
109 this.name = this.constructor.name;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
110 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
111 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
112
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
113 export class ProtocolError extends Error {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
114 constructor(url, status, statusText, ...params) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
115 let message = `Protocol error: Transfer of ${url} failed with: ` +
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
116 `${status} ${statusText}`
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
117 super(message, ...params);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
118 this.name = this.constructor.name;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
119 this.url = url;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
120 this.status = status;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
121 this.statusText = statusText;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
122 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
123 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
124
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
125 class FeedLogo {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
126 constructor(url, {title = ''} = {}) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
127 this.url = url;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
128 this.title = title;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
129 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
130 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
131
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
132 class FeedEntryFile {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
133 constructor(url, {type = browser.i18n.getMessage('defaultFileType'),
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
134 size = 0} = {}) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
135 this.filename = undefined;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
136 this._url = undefined;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
137 this.url = url;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
138 this.type = type;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
139 this.size = size;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
140 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
141
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
142 set url(url) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
143 this._url = url;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
144 let filename = url.pathname.split('/').pop();
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
145 this.filename = filename !== '' ? filename :
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
146 browser.i18n.getMessage('defaultFileName');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
147 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
148
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
149 get url() {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
150 return this._url;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
151 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
152 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
153
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
154 class FeedEntry {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
155 constructor({title = browser.i18n.getMessage('defaultFeedEntryTitle'),
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
156 link = undefined, date = new Date(0), content = '',
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
157 files = []} = {}) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
158 this.title = title;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
159 this.link = link;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
160 this.date = date;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
161 this._content = undefined;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
162 this.content = content;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
163 this.files = files;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
164 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
165
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
166 normalizeContent(text) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
167 if (typeof text === 'undefined') {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
168 return
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
169 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
170
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
171 let contentDocument = document.implementation.createHTMLDocument();
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
172 let parsedDocument = new DOMParser().parseFromString(text, 'text/html');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
173 contentDocument.body = contentDocument.adoptNode(parsedDocument.body);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
174 return new XMLSerializer().serializeToString(contentDocument);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
175 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
176
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
177 set content(content) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
178 this._content = this.normalizeContent(content);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
179 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
180
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
181 get content() {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
182 return this._content;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
183 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
184 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
185
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
186 class Feed {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
187 constructor(url, {title = browser.i18n.getMessage('defaultFeedTitle'),
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
188 subtitle = '', logo, entries = []} = {}) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
189 this.url = url;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
190 this.title = title;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
191 this.subtitle = subtitle;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
192 this.logo = logo;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
193 this.entries = entries;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
194 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
195 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
196
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
197 export class FeedParser {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
198 static probeFeed(feedDocument) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
199 let documentElement = feedDocument.documentElement;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
200 if (documentElement.nodeName === 'feed' &&
15
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
201 documentElement.namespaceURI === XMLNS.ATOM03) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
202 return ['atom', '0.3'];
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
203 } else if (documentElement.nodeName === 'feed' &&
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
204 documentElement.namespaceURI === XMLNS.ATOM10) {
15
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
205 return ['atom', '1.0'];
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
206 } else if (documentElement.nodeName === 'rss') {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
207 let version = documentElement.getAttribute('version');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
208 switch (version) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
209 case '0.90':
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
210 case '0.91':
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
211 case '0.92':
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
212 case '0.93':
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
213 case '0.94':
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
214 case '2.0':
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
215 return ['rss', version];
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
216 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
217 } else if (documentElement.localName.toLowerCase() === 'rdf' &&
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
218 documentElement.getAttribute('xmlns') === XMLNS.RSS09) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
219 return ['rss', '0.9'];
19
3fcd2209b39a Add support for RSS 1.0 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 18
diff changeset
220 } else if (documentElement.localName.toLowerCase() === 'rdf' &&
3fcd2209b39a Add support for RSS 1.0 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 18
diff changeset
221 documentElement.getAttribute('xmlns') === XMLNS.RSS10) {
3fcd2209b39a Add support for RSS 1.0 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 18
diff changeset
222 return ['rss', '1.0'];
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
223 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
224
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
225 return [undefined, undefined];
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
226 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
227
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
228 constructor() {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
229 this.url = undefined;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
230 this.document = undefined;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
231 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
232
15
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
233 parseAtom03ContentConstruct(containerElement, textOnly = true) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
234 let contentType = containerElement.getAttribute('type');
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
235 let contentMode = containerElement.getAttribute('mode');
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
236 if (contentType === null) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
237 contentType = 'text/plain';
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
238 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
239 if (contentMode === null) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
240 contentMode = 'xml';
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
241 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
242 if (contentType === 'application/xhtml+xml') {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
243 let htmlText;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
244 if (contentMode === 'xml') {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
245 return textOnly ? containerElement.textContent.trim() :
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
246 containerElement.innerHTML;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
247 } else if (contentMode === 'escaped') {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
248 htmlText = containerElement.textContent;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
249 } else if (contentMode === 'base64') {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
250 htmlText = base64Decode(containerElement.textContent);
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
251 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
252 if (typeof htmlText === 'undefined') {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
253 return;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
254 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
255 if (textOnly) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
256 let htmlDocument = new DOMParser().parseFromString(htmlText,
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
257 'application/xhtml+xml');
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
258 if (htmlDocument.documentElement.namespaceURI ===
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
259 XMLNS.PARSERERROR) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
260 return;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
261 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
262 return htmlDocument.body.textContent.trim();
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
263 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
264 return htmlText;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
265 } else if (contentType === 'text/html') {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
266 let htmlText;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
267 if (contentMode === 'escaped') {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
268 htmlText = containerElement.textContent;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
269 } else if (contentMode === 'base64') {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
270 htmlText = base64Decode(containerElement.textContent);
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
271 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
272 if (typeof htmlText === 'undefined') {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
273 return;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
274 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
275 if (textOnly) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
276 let htmlDocument = new DOMParser().parseFromString(htmlText,
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
277 'text/html');
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
278 return htmlDocument.body.textContent.trim();
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
279 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
280 return htmlText;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
281 } else if (contentType === 'text/plain') {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
282 let text;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
283 if (contentMode === 'escaped') {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
284 text = containerElement.textContent;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
285 } else if (contentMode === 'base64') {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
286 text = base64Decode(containerElement.textContent);
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
287 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
288 if (typeof text === 'undefined') {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
289 return;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
290 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
291 return textOnly ? text : `<pre>${encodeXML(text)}</pre>`;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
292 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
293 return;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
294 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
295
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
296 parseAtom03Content(contentElement) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
297 // ordered from lowest to highest preference
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
298 const contentTypes = [
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
299 'text/plain',
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
300 'text/html',
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
301 'application/xhtml+xml'
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
302 ];
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
303 if (contentElement.getAttribute('type') === 'multipart/alternative' &&
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
304 contentElement.getAttribute('mode') === null) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
305 // select alternative according to above preference
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
306 let selectedTypeIndex = -1;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
307 let selectedElement;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
308 for (let innerContentElement of contentElement.children) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
309 if (innerContentElement.localName !== 'content' ||
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
310 innerContentElement.namespaceURI !== XMLNS.ATOM03) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
311 throw new TypeError('child elements of a multipart ' +
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
312 ' content elements must be content elements');
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
313 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
314 let innerContentType = innerContentElement.getAttribute('type');
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
315 if (innerContentType === null) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
316 innerContentType = 'text/plain';
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
317 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
318 let typeIndex = contentTypes.indexOf(innerContentType);
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
319 if (typeIndex > selectedTypeIndex) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
320 selectedTypeIndex = typeIndex;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
321 selectedElement = innerContentElement;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
322 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
323 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
324 if (selectedTypeIndex >= 0) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
325 contentElement = selectedElement;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
326 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
327 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
328
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
329 return this.parseAtom03ContentConstruct(contentElement, false);
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
330 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
331
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
332 parseAtom03Entry(entryElement) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
333 let title;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
334 let link;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
335 let date;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
336 let content;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
337 let titleElement = feedQueryXPath(this.document, entryElement,
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
338 './atom03:title');
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
339 if (titleElement !== null) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
340 title = titleElement.textContent.trim();
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
341 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
342
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
343 let linkElement = feedQueryXPath(this.document, entryElement,
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
344 './atom03:link[@href][@rel="alternate"]');
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
345 if (linkElement !== null) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
346 link = parseURL(linkElement.getAttribute('href'), this.url);
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
347 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
348
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
349 let modifiedElement = feedQueryXPath(this.document, entryElement,
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
350 './atom03:modified');
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
351 if (modifiedElement !== null) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
352 date = parseDate(modifiedElement.textContent);
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
353 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
354
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
355 let contentElement = feedQueryXPath(this.document, entryElement,
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
356 './atom03:content');
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
357 if (contentElement !== null) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
358 try {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
359 content = this.parseAtom03Content(contentElement);
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
360 } catch (e) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
361 if (!(e instanceof TypeError)) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
362 throw e;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
363 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
364 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
365 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
366 if (typeof content === 'undefined') {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
367 let summaryElement = feedQueryXPath(this.document, entryElement,
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
368 './atom03:summary');
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
369 if (summaryElement !== null) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
370 try {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
371 content = this.parseAtom03ContentConstruct(summaryElement,
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
372 false);
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
373 } catch (e) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
374 if (!(e instanceof TypeError)) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
375 throw e;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
376 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
377 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
378 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
379 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
380
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
381 return new FeedEntry({title, link, date, content});
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
382 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
383
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
384 parseAtom03Feed() {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
385 let title;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
386 let subtitle;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
387 let logo;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
388 let entries = [];
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
389 let documentElement = this.document.documentElement;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
390
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
391 let titleElement = feedQueryXPath(this.document, documentElement,
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
392 './atom03:title');
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
393 if (titleElement !== null) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
394 try {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
395 title = this.parseAtom03ContentConstruct(titleElement);
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
396 } catch (e) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
397 if (!(e instanceof TypeError)) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
398 throw e;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
399 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
400 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
401 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
402
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
403 let taglineElement = feedQueryXPath(this.document, documentElement,
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
404 './atom03:tagline');
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
405 if (taglineElement !== null) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
406 try {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
407 title = this.parseAtom03ContentConstruct(taglineElement);
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
408 } catch (e) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
409 if (!(e instanceof TypeError)) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
410 throw e;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
411 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
412 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
413 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
414
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
415 let logoElement = feedQueryXPath(this.document, documentElement,
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
416 './atom03:logo');
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
417 if (logoElement !== null) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
418 try {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
419 logo = this.parseAtomLogo(logoElement);
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
420 } catch (e) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
421 if (!(e instanceof TypeError)) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
422 throw e;
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
423 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
424 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
425 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
426
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
427 let entryElements = feedQueryXPathAll(this.document, documentElement,
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
428 './atom03:entry');
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
429 for (let entryElement of entryElements) {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
430 entries.push(this.parseAtom03Entry(entryElement));
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
431 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
432
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
433 return new Feed(this.url, {title, subtitle, logo, entries});
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
434 }
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
435
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
436 parseAtomLogo(logoElement) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
437 let url = parseURL(logoElement.textContent.trim(), this.url);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
438 if (url === null) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
439 throw new TypeError('invalid URL in <logo> element');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
440 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
441 return new FeedLogo(url);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
442 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
443
14
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
444 parseAtomTextConstruct(containerElement, textOnly = true) {
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
445 let contentType = containerElement.getAttribute('type');
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
446 if (contentType === null) {
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
447 contentType = 'text';
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
448 }
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
449
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
450 if (contentType === 'xhtml') {
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
451 let xhtmlRootElement = containerElement.firstElementChild;
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
452 if (xhtmlRootElement !== null &&
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
453 xhtmlRootElement.localName === 'div' &&
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
454 xhtmlRootElement.namespaceURI === XMLNS.XHTML) {
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
455 return textOnly ? xhtmlRootElement.textContent.trim() :
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
456 xhtmlRootElement.innerHTML;
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
457 }
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
458 } else if (contentType === 'html') {
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
459 let htmlText = containerElement.textContent;
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
460 if (textOnly) {
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
461 let htmlDocument = new DOMParser().parseFromString(htmlText,
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
462 'text/html');
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
463 return htmlDocument.body.textContent.trim();
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
464 }
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
465 return htmlText
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
466 } else if (contentType === 'text') {
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
467 let text = containerElement.textContent.trim();
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
468 return textOnly ? text : `<pre>${encodeXML(text)}</pre>`;
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
469 }
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
470
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
471 // unsupported content type
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
472 return;
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
473 }
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
474
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
475 parseAtomContent(contentElement) {
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
476 let contentSrc = contentElement.getAttribute('src');
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
477 if (contentSrc !== null) {
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
478 // externally referenced content is not supported
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
479 return;
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
480 }
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
481 return this.parseAtomTextConstruct(contentElement, false);
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
482 }
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
483
17
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
484 parseAtomEntryFile(enclosureElement) {
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
485 let type;
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
486 let size;
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
487 let url = parseURL(enclosureElement.getAttribute('href'), this.url);
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
488 if (url === null) {
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
489 throw new TypeError('invalid URL in enclosure href attribute');
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
490 }
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
491
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
492 let typeAttribute = enclosureElement.getAttribute('type');
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
493 if (typeAttribute !== null) {
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
494 type = typeAttribute;
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
495 }
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
496
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
497 let length = parseInt(enclosureElement.getAttribute('length'), 10);
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
498 if (!isNaN(length)) {
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
499 size = length;
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
500 }
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
501
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
502 return new FeedEntryFile(url, {type, size});
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
503 }
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
504
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
505 parseAtomEntry(entryElement) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
506 let title;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
507 let link;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
508 let date;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
509 let content;
17
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
510 let files = [];
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
511 let titleElement = feedQueryXPath(this.document, entryElement,
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
512 './atom:title');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
513 if (titleElement !== null) {
14
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
514 title = this.parseAtomTextConstruct(titleElement);
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
515 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
516
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
517 let linkElement = feedQueryXPath(this.document, entryElement,
7
2bbb7617dd13 Alternatively use Atom links without the rel attribute
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 6
diff changeset
518 './atom:link[@href][not(@rel) or @rel="alternate"]');
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
519 if (linkElement !== null) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
520 link = parseURL(linkElement.getAttribute('href'), this.url);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
521 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
522
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
523 let updatedElement = feedQueryXPath(this.document, entryElement,
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
524 './atom:updated');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
525 if (updatedElement !== null) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
526 date = parseDate(updatedElement.textContent);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
527 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
528
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
529 let contentElement = feedQueryXPath(this.document, entryElement,
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
530 './atom:content');
14
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
531 if (contentElement !== null) {
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
532 content = this.parseAtomContent(contentElement);
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
533 }
14
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
534 if (typeof content === 'undefined') {
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
535 let summaryElement = feedQueryXPath(this.document, entryElement,
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
536 './atom:summary');
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
537 if (summaryElement !== null) {
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
538 content = this.parseAtomTextConstruct(summaryElement, false);
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
539 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
540 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
541
17
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
542 for (let enclosureElement of feedQueryXPathAll(this.document,
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
543 entryElement, './atom:link[@href][@rel="enclosure"]')) {
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
544 try {
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
545 let entryFile = this.parseAtomEntryFile(enclosureElement);
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
546 files.push(entryFile);
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
547 } catch (e) {
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
548 if (!(e instanceof TypeError)) {
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
549 throw e;
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
550 }
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
551 }
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
552 }
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
553
48cabd01ef64 Add support for enclosures in Atom feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 15
diff changeset
554 return new FeedEntry({title, link, date, content, files});
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
555 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
556
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
557 parseAtomFeed() {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
558 let title;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
559 let subtitle;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
560 let logo;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
561 let entries = [];
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
562 let documentElement = this.document.documentElement;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
563
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
564 let titleElement = feedQueryXPath(this.document, documentElement,
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
565 './atom:title');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
566 if (titleElement !== null) {
14
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
567 title = this.parseAtomTextConstruct(titleElement);
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
568 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
569
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
570 let subtitleElement = feedQueryXPath(this.document, documentElement,
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
571 './atom:subtitle');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
572 if (subtitleElement !== null) {
14
376a0e415bba Properly handle non-text content in Atom feed elements
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 7
diff changeset
573 subtitle = this.parseAtomTextConstruct(subtitleElement);
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
574 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
575
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
576 let logoElement = feedQueryXPath(this.document, documentElement,
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
577 './atom:logo');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
578 if (logoElement !== null) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
579 try {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
580 logo = this.parseAtomLogo(logoElement);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
581 } catch (e) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
582 if (!(e instanceof TypeError)) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
583 throw e;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
584 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
585 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
586 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
587
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
588 let entryElements = feedQueryXPathAll(this.document, documentElement,
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
589 './atom:entry');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
590 for (let entryElement of entryElements) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
591 entries.push(this.parseAtomEntry(entryElement));
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
592 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
593
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
594 return new Feed(this.url, {title, subtitle, logo, entries});
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
595 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
596
19
3fcd2209b39a Add support for RSS 1.0 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 18
diff changeset
597 parseRSS1Logo(imageElement, nsPrefix) {
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
598 let title;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
599 let urlElement = feedQueryXPath(this.document, imageElement,
19
3fcd2209b39a Add support for RSS 1.0 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 18
diff changeset
600 `./${nsPrefix}:url`);
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
601 if (urlElement === null) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
602 throw new TypeError('missing <url> element in <logo> element');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
603 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
604 let url = parseURL(urlElement.textContent.trim(), this.url);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
605 if (url === null) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
606 throw new TypeError('invalid URL in <logo> element');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
607 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
608
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
609 let titleElement = feedQueryXPath(this.document, imageElement,
19
3fcd2209b39a Add support for RSS 1.0 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 18
diff changeset
610 `./${nsPrefix}:title`);
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
611 if (titleElement !== null) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
612 title = titleElement.textContent.trim();
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
613 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
614
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
615 return new FeedLogo(url, {title});
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
616 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
617
19
3fcd2209b39a Add support for RSS 1.0 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 18
diff changeset
618 parseRSS1Entry(itemElement, nsPrefix) {
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
619 let title;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
620 let link;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
621 let titleElement = feedQueryXPath(this.document, itemElement,
19
3fcd2209b39a Add support for RSS 1.0 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 18
diff changeset
622 `./${nsPrefix}:title`);
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
623 if (titleElement !== null) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
624 title = titleElement.textContent;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
625 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
626
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
627 let linkElement = feedQueryXPath(this.document, itemElement,
19
3fcd2209b39a Add support for RSS 1.0 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 18
diff changeset
628 `./${nsPrefix}:link`);
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
629 if (linkElement !== null) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
630 link = parseURL(linkElement.textContent, this.url);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
631 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
632
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
633 return new FeedEntry({title, link});
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
634 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
635
19
3fcd2209b39a Add support for RSS 1.0 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 18
diff changeset
636 parseRSS1Feed(version) {
3fcd2209b39a Add support for RSS 1.0 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 18
diff changeset
637 let nsPrefix = version === '0.9' ? 'rss09' : 'rss10';
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
638 let title;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
639 let subtitle;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
640 let logo;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
641 let entries = [];
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
642 let documentElement = this.document.documentElement;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
643 let titleElement = feedQueryXPath(this.document, documentElement,
19
3fcd2209b39a Add support for RSS 1.0 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 18
diff changeset
644 `./${nsPrefix}:channel/${nsPrefix}:title`);
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
645 if (titleElement !== null) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
646 title = titleElement.textContent;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
647 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
648
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
649 let descriptionElement = feedQueryXPath(this.document, documentElement,
19
3fcd2209b39a Add support for RSS 1.0 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 18
diff changeset
650 `./${nsPrefix}:channel/${nsPrefix}:description`);
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
651 if (descriptionElement !== null) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
652 subtitle = descriptionElement.textContent;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
653 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
654
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
655 let imageElement = feedQueryXPath(this.document, documentElement,
19
3fcd2209b39a Add support for RSS 1.0 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 18
diff changeset
656 `./${nsPrefix}:image`);
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
657 if (imageElement !== null) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
658 try {
19
3fcd2209b39a Add support for RSS 1.0 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 18
diff changeset
659 logo = this.parseRSS1Logo(imageElement, nsPrefix);
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
660 } catch (e) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
661 if (!(e instanceof TypeError)) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
662 throw e;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
663 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
664 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
665 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
666
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
667 let itemElements = feedQueryXPathAll(this.document, documentElement,
19
3fcd2209b39a Add support for RSS 1.0 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 18
diff changeset
668 `./${nsPrefix}:item`);
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
669 for (let itemElement of itemElements) {
19
3fcd2209b39a Add support for RSS 1.0 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 18
diff changeset
670 let entry = this.parseRSS1Entry(itemElement, nsPrefix);
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
671 if (typeof entry !== 'undefined') {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
672 entries.push(entry);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
673 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
674 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
675
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
676 return new Feed(this.url, {title, subtitle, logo, entries});
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
677 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
678
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
679 parseRSS2Logo(imageElement) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
680 let title;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
681 let urlElement = feedQueryXPath(this.document, imageElement, './url');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
682 if (urlElement === null) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
683 throw new TypeError('missing <url> element in <logo> element');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
684 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
685 let url = parseURL(urlElement.textContent.trim(), this.url);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
686 if (url === null) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
687 throw new TypeError('invalid URL in <logo> element');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
688 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
689
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
690 let titleElement = feedQueryXPath(this.document, imageElement,
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
691 './title');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
692 if (titleElement !== null) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
693 title = titleElement.textContent.trim();
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
694 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
695
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
696 return new FeedLogo(url, {title});
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
697 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
698
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
699 parseRSS2EntryFile(enclosureElement) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
700 let type;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
701 let size;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
702 let url = parseURL(enclosureElement.getAttribute('url'), this.url);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
703 if (url === null) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
704 throw new TypeError('invalid URL in <enclosure> element');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
705 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
706
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
707 let typeAttribute = enclosureElement.getAttribute('type');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
708 if (typeAttribute !== null) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
709 type = typeAttribute;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
710 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
711
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
712 let length = parseInt(enclosureElement.getAttribute('length'),
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
713 10);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
714 if (!isNaN(length)) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
715 size = length;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
716 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
717
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
718 return new FeedEntryFile(url, {type, size});
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
719 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
720
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
721 parseRSS2Entry(itemElement) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
722 let title;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
723 let link;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
724 let date;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
725 let content;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
726 let files = [];
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
727 let titleElement = feedQueryXPath(this.document, itemElement,
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
728 './title');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
729 if (titleElement !== null) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
730 title = titleElement.textContent;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
731 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
732
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
733 let linkElement = feedQueryXPath(this.document, itemElement, './link');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
734 if (linkElement !== null) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
735 link = parseURL(linkElement.textContent, this.url);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
736 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
737
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
738 let pubDateElement = feedQueryXPath(this.document, itemElement,
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
739 './pubDate');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
740 if (pubDateElement !== null) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
741 date = parseDate(pubDateElement.textContent);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
742 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
743
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
744 let descriptionElement = feedQueryXPath(this.document, itemElement,
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
745 './description');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
746 if (descriptionElement !== null) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
747 content = descriptionElement.textContent.trim();
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
748 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
749
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
750 for (let enclosureElement of
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
751 feedQueryXPathAll(this.document, itemElement, './enclosure')) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
752 try {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
753 let entryFile = this.parseRSS2EntryFile(enclosureElement);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
754 files.push(entryFile);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
755 } catch (e) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
756 if (!(e instanceof TypeError)) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
757 throw e;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
758 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
759 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
760 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
761
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
762 return new FeedEntry({title, link, date, content, files});
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
763 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
764
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
765 parseRSS2Feed() {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
766 let title;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
767 let subtitle;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
768 let logo;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
769 let entries = [];
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
770 let documentElement = this.document.documentElement;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
771 let titleElement = feedQueryXPath(this.document, documentElement,
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
772 './channel/title');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
773 if (titleElement !== null) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
774 title = titleElement.textContent;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
775 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
776
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
777 let descriptionElement = feedQueryXPath(this.document, documentElement,
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
778 './channel/description');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
779 if (descriptionElement !== null) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
780 subtitle = descriptionElement.textContent;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
781 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
782
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
783 let imageElement = feedQueryXPath(this.document, documentElement,
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
784 './channel/image');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
785 if (imageElement !== null) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
786 try {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
787 logo = this.parseRSS2Logo(imageElement);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
788 } catch (e) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
789 if (!(e instanceof TypeError)) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
790 throw e;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
791 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
792 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
793 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
794
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
795 let itemElements = feedQueryXPathAll(this.document, documentElement,
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
796 './channel/item');
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
797 for (let itemElement of itemElements) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
798 let entry = this.parseRSS2Entry(itemElement);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
799 if (typeof entry !== 'undefined') {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
800 entries.push(entry);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
801 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
802 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
803
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
804 return new Feed(this.url, {title, subtitle, logo, entries});
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
805 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
806
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
807 parseFromString(xmlString, url) {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
808 this.url = url;
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
809 this.document = new DOMParser().parseFromString(xmlString,
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
810 'application/xml');
15
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
811 if (this.document.documentElement.namespaceURI === XMLNS.PARSERERROR) {
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
812 throw new ParserError(this.document.documentElement.textContent);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
813 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
814
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
815 let [type, version] = this.constructor.probeFeed(this.document);
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
816 if (type === 'atom') {
15
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
817 if (version === '0.3') {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
818 return this.parseAtom03Feed();
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
819 } else if (version === '1.0') {
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
820 return this.parseAtomFeed();
150f07c7595f Add support for Atom 0.3 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 14
diff changeset
821 }
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
822 } else if (type === 'rss') {
19
3fcd2209b39a Add support for RSS 1.0 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 18
diff changeset
823 if (version === '0.9' || version === '1.0') {
3fcd2209b39a Add support for RSS 1.0 feeds
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents: 18
diff changeset
824 return this.parseRSS1Feed(version);
6
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
825 } else {
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
826 return this.parseRSS2Feed();
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
827 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
828 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
829 throw new UnsupportedFeedTypeError();
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
830 }
5d7c13e998e9 Create feed previews using a stream filter
Guido Berhoerster <guido+feed-preview@berhoerster.name>
parents:
diff changeset
831 }