home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 120 / cdrom120.iso / internet / sage / sage.xpi / chrome / sage.jar / content / getrsstitle.js < prev    next >
Encoding:
Text File  |  2005-05-12  |  1.7 KB  |  62 lines

  1. var GetRssTitle = {
  2.     checking: false,
  3.     httpReq: null,
  4.     res: null,
  5.     url: "",
  6.     
  7.     getRssTitle: function(aBookmrkID){
  8.         if(this.checking) return;
  9.     
  10.         this.res = RDF.GetResource(aBookmrkID);
  11.         var type = CommonFunc.getBMDSProperty(this.res, CommonFunc.RDF_TYPE);
  12.         if(type == NC_NS + "Bookmark") {
  13.             this.url = CommonFunc.getBMDSProperty(this.res, CommonFunc.BM_URL);
  14.         }
  15.         if(type == NC_NS + "Livemark") {
  16.             this.url = CommonFunc.getBMDSProperty(this.res, CommonFunc.BM_FEEDURL);
  17.         }
  18.         
  19.         this.httpReq = new XMLHttpRequest();
  20.         this.httpReq.onload = this.httpLoaded;
  21.         this.httpReq.onreadystatechange = this.httpReadyStateChange;
  22.         this.httpReq.open("GET", this.url);
  23.         this.httpReq.setRequestHeader("User-Agent", USER_AGENT);
  24.         this.httpReq.overrideMimeType("application/xml");
  25.         try {
  26.             this.httpReq.send(null);
  27.         } catch(e) {
  28.                 // FAILURE
  29.             this.httpReq.abort();
  30.             this.checking = false;
  31.         }
  32.     },
  33.     
  34.     httpReadyStateChange: function() {
  35.         if(GetRssTitle.httpReq.readyState == 2) {
  36.             try {
  37.                 GetRssTitle.httpReq.status;
  38.             } catch(e) {
  39.                     // URL NOT AVAILABLE
  40.                 GetRssTitle.httpReq.abort();
  41.                 GetRssTitle.checking = false;
  42.             }
  43.         }
  44.     },
  45.     
  46.     httpLoaded: function() {
  47.         this.checking = false;
  48.         
  49.         var feed = new Feed(GetRssTitle.httpReq.responseXML);
  50.         var rssTitle = feed.getTitle();
  51.  
  52.         if(!rssTitle) return;
  53.         
  54.         var prompt = Components.classes["@mozilla.org/embedcomp/prompt-service;1"].getService(Components.interfaces.nsIPromptService);
  55.         var resultValue = { value: rssTitle };
  56.         var result = prompt.prompt(window, "Sage", strRes.getString("get_feed_title"), resultValue, null, {});
  57.  
  58.         if(result) {
  59.             CommonFunc.setBMDSProperty(GetRssTitle.res, CommonFunc.BM_NAME, resultValue.value);
  60.         }
  61.     }
  62. }