GoogleFeedStore.js 2.6 KB

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