GoogleFeedStore.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.data.GoogleFeedStore"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.data.GoogleFeedStore"] = true;
  8. dojo.provide("dojox.data.GoogleFeedStore");
  9. dojo.require("dojox.data.GoogleSearchStore");
  10. dojo.experimental("dojox.data.GoogleFeedStore");
  11. dojo.declare("dojox.data.GoogleFeedStore", dojox.data.GoogleSearchStore,{
  12. // summary:
  13. // A data store for retrieving RSS and Atom feeds from Google. The
  14. // feeds can come from any source, which is specified in the "url"
  15. // parameter of the query passed to the "fetch" function.
  16. // The following attributes are supported on each item:
  17. // <ul>
  18. // <li>title - The feed entry title.</li>
  19. // <li>link - The URL for the HTML version of the feed entry.</li>
  20. // <li>content - The full content of the blog post, in HTML format</li>
  21. // <li>summary - A snippet of information about the feed entry, in plain text</li>
  22. // <li>published - The string date on which the entry was published.
  23. // You can parse the date with new Date(store.getValue(item, "published")</li>
  24. // <li>categories - An array of string tags for the entry</li>
  25. // </ul>
  26. // The query accepts one parameter: url - The URL of the feed to retrieve
  27. _type: "",
  28. _googleUrl: "http://ajax.googleapis.com/ajax/services/feed/load",
  29. _attributes: ["title", "link", "author", "published",
  30. "content", "summary", "categories"],
  31. _queryAttrs: {
  32. "url":"q"
  33. },
  34. getFeedValue: function(attribute, defaultValue){
  35. // summary:
  36. // Non-API method for retrieving values regarding the Atom feed,
  37. // rather than the Atom entries.
  38. var values = this.getFeedValues(attribute, defaultValue);
  39. if(dojo.isArray(values)){
  40. return values[0];
  41. }
  42. return values;
  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. _processItem: function(item, request) {
  54. this.inherited(arguments);
  55. item["summary"] = item["contentSnippet"];
  56. item["published"] = item["publishedDate"];
  57. },
  58. _getItems: function(data){
  59. if(data['feed']){
  60. this._feedMetaData = {
  61. title: data.feed.title,
  62. desc: data.feed.description,
  63. url: data.feed.link,
  64. author: data.feed.author
  65. };
  66. return data.feed.entries;
  67. }
  68. return null;
  69. },
  70. _createContent: function(query, callback, request){
  71. var cb = this.inherited(arguments);
  72. cb.num = (request.count || 10) + (request.start || 0);
  73. return cb;
  74. }
  75. });
  76. }