PageRenderTime 20ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/ext-4.0.7/examples/app/feed-viewer/app/lib/FeedValidator.js

https://bitbucket.org/srogerf/javascript
JavaScript | 75 lines | 42 code | 7 blank | 26 comment | 3 complexity | 44e4495a3a3cacf6522f01926f9fbb55 MD5 | raw file
  1. /*
  2. This file is part of Ext JS 4
  3. Copyright (c) 2011 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  7. If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
  8. */
  9. Ext.define('FV.lib.FeedValidator', {
  10. singleton: true,
  11. /**
  12. * @cfg {String} url The url to validate feeds on
  13. */
  14. url: 'feed-proxy.php',
  15. /**
  16. * Validates a given feed's formating by fetching it and ensuring it is well formed
  17. * @param {FV.model.Feed} feed The feed to validate
  18. */
  19. validate: function(feed, options) {
  20. options = options || {};
  21. Ext.applyIf(options, {
  22. scope: this,
  23. success: Ext.emptyFn,
  24. failure: Ext.emptyFn
  25. });
  26. Ext.Ajax.request({
  27. url: this.url,
  28. params: {
  29. feed: feed.get('url')
  30. },
  31. scope: this,
  32. success: function(response) {
  33. if (this.checkResponse(response, feed)) {
  34. options.success.call(options.scope, feed);
  35. }
  36. },
  37. failure: function() {
  38. options.failure.call(options.scope);
  39. }
  40. });
  41. },
  42. /**
  43. * @private
  44. * Validates that a response contains a well-formed feed
  45. * @param {Object} response The response object
  46. */
  47. checkResponse: function(response, feed) {
  48. var dq = Ext.DomQuery,
  49. url = feed.get('url'),
  50. xml, channel, title;
  51. try {
  52. xml = response.responseXML;
  53. channel = xml.getElementsByTagName('channel')[0];
  54. if (channel) {
  55. title = dq.selectValue('title', channel, url);
  56. return true;
  57. }
  58. } catch(e) {
  59. }
  60. return false;
  61. }
  62. });