]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | Ext.define('FV.lib.FeedValidator', {\r |
2 | singleton: true,\r | |
3 | \r | |
4 | /**\r | |
5 | * @cfg {String} url The url to validate feeds on\r | |
6 | */\r | |
7 | url: 'feed-proxy.php',\r | |
8 | \r | |
9 | /**\r | |
10 | * Validates a given feed's formating by fetching it and ensuring it is well formed\r | |
11 | * @param {FV.model.Feed} feed The feed to validate\r | |
12 | */\r | |
13 | validate: function(feed, options) {\r | |
14 | options = options || {};\r | |
15 | \r | |
16 | Ext.applyIf(options, {\r | |
17 | scope: this,\r | |
18 | success: Ext.emptyFn,\r | |
19 | failure: Ext.emptyFn\r | |
20 | });\r | |
21 | \r | |
22 | Ext.Ajax.request({\r | |
23 | url: this.url,\r | |
24 | params: {\r | |
25 | feed: feed.get('url')\r | |
26 | },\r | |
27 | scope: this,\r | |
28 | success: function(response) {\r | |
29 | var title = this.checkResponse(response, feed);\r | |
30 | if (title) {\r | |
31 | feed.set('name', title);\r | |
32 | options.success.call(options.scope, feed);\r | |
33 | }\r | |
34 | else {\r | |
35 | options.failure.call(options.scope);\r | |
36 | }\r | |
37 | },\r | |
38 | failure: function() {\r | |
39 | options.failure.call(options.scope);\r | |
40 | }\r | |
41 | });\r | |
42 | },\r | |
43 | \r | |
44 | /**\r | |
45 | * @private\r | |
46 | * Validates that a response contains a well-formed feed\r | |
47 | * @param {Object} response The response object\r | |
48 | */\r | |
49 | checkResponse: function(response, feed) {\r | |
50 | var dq = Ext.DomQuery,\r | |
51 | url = feed.get('url'),\r | |
52 | xml, channel, title;\r | |
53 | \r | |
54 | try {\r | |
55 | xml = response.responseXML;\r | |
56 | channel = xml.getElementsByTagName('channel')[0];\r | |
57 | \r | |
58 | if (channel) {\r | |
59 | title = dq.selectValue('title', channel, url);\r | |
60 | return title;\r | |
61 | }\r | |
62 | } catch(e) {\r | |
63 | }\r | |
64 | return false;\r | |
65 | }\r | |
66 | }); |