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