1 | define(["dojo/_base/kernel", "dojo/_base/lang", "dojo/_base/declare", "dojox/data/GoogleSearchStore"], |
---|
2 | function(dojo, lang, declare, GoogleSearchStore) { |
---|
3 | |
---|
4 | dojo.experimental("dojox.data.GoogleFeedStore"); |
---|
5 | |
---|
6 | /*===== var Search = dojox.data.GoogleSearchStore =====*/ |
---|
7 | var Search = GoogleSearchStore.Search; |
---|
8 | |
---|
9 | return declare("dojox.data.GoogleFeedStore", Search,{ |
---|
10 | // summary: |
---|
11 | // A data store for retrieving RSS and Atom feeds from Google. The |
---|
12 | // feeds can come from any source, which is specified in the "url" |
---|
13 | // parameter of the query passed to the "fetch" function. |
---|
14 | // The following attributes are supported on each item: |
---|
15 | // <ul> |
---|
16 | // <li>title - The feed entry title.</li> |
---|
17 | // <li>link - The URL for the HTML version of the feed entry.</li> |
---|
18 | // <li>content - The full content of the blog post, in HTML format</li> |
---|
19 | // <li>summary - A snippet of information about the feed entry, in plain text</li> |
---|
20 | // <li>published - The string date on which the entry was published. |
---|
21 | // You can parse the date with new Date(store.getValue(item, "published")</li> |
---|
22 | // <li>categories - An array of string tags for the entry</li> |
---|
23 | // </ul> |
---|
24 | // The query accepts one parameter: url - The URL of the feed to retrieve |
---|
25 | _type: "", |
---|
26 | _googleUrl: "http://ajax.googleapis.com/ajax/services/feed/load", |
---|
27 | _attributes: ["title", "link", "author", "published", |
---|
28 | "content", "summary", "categories"], |
---|
29 | _queryAttrs: { |
---|
30 | "url":"q" |
---|
31 | }, |
---|
32 | |
---|
33 | getFeedValue: function(attribute, defaultValue){ |
---|
34 | // summary: |
---|
35 | // Non-API method for retrieving values regarding the Atom feed, |
---|
36 | // rather than the Atom entries. |
---|
37 | var values = this.getFeedValues(attribute, defaultValue); |
---|
38 | if(lang.isArray(values)){ |
---|
39 | return values[0]; |
---|
40 | } |
---|
41 | return values; |
---|
42 | }, |
---|
43 | |
---|
44 | getFeedValues: function(attribute, defaultValue){ |
---|
45 | // summary: |
---|
46 | // Non-API method for retrieving values regarding the Atom feed, |
---|
47 | // rather than the Atom entries. |
---|
48 | if(!this._feedMetaData){ |
---|
49 | return defaultValue; |
---|
50 | } |
---|
51 | return this._feedMetaData[attribute] || defaultValue; |
---|
52 | }, |
---|
53 | |
---|
54 | _processItem: function(item, request) { |
---|
55 | this.inherited(arguments); |
---|
56 | item["summary"] = item["contentSnippet"]; |
---|
57 | item["published"] = item["publishedDate"]; |
---|
58 | }, |
---|
59 | |
---|
60 | _getItems: function(data){ |
---|
61 | if(data['feed']){ |
---|
62 | this._feedMetaData = { |
---|
63 | title: data.feed.title, |
---|
64 | desc: data.feed.description, |
---|
65 | url: data.feed.link, |
---|
66 | author: data.feed.author |
---|
67 | }; |
---|
68 | return data.feed.entries; |
---|
69 | } |
---|
70 | return null; |
---|
71 | }, |
---|
72 | |
---|
73 | _createContent: function(query, callback, request){ |
---|
74 | var cb = this.inherited(arguments); |
---|
75 | cb.num = (request.count || 10) + (request.start || 0); |
---|
76 | return cb; |
---|
77 | } |
---|
78 | }); |
---|
79 | |
---|
80 | }); |
---|