home *** CD-ROM | disk | FTP | other *** search
/ ftp.swcp.com / ftp.swcp.com.zip / ftp.swcp.com / mac / mozilla-macos9-1.3.1.sea.bin / Mozilla1.3.1 / Chrome / comm.jar / content / communicator / builtinURLs.js < prev    next >
Text File  |  2003-06-08  |  5KB  |  168 lines

  1. // the rdf service
  2. var gRDFService;
  3. var gTitleArc;
  4. var gContentArc;
  5. var gBuiltinUrlsDataSource;
  6. var gDataSourceState;
  7. var gDataSourceLoaded;
  8. var gSinkObserverRegistered;
  9.  
  10. var SinkObserver = 
  11. {
  12.     onBeginLoad: function( aSink) {
  13.         gDataSourceState = (gDataSourceState | 1); 
  14.         debug_dump("\n-> SinkObserver:onBeginLoad: " + aSink + ", gDataSourceState=" + gDataSourceState + "\n");
  15.     },
  16.     
  17.     onInterrupt: function( aSink) {
  18.         gDataSourceState = (gDataSourceState | 2);
  19.         debug_dump("\n-> SinkObserver:onInterrupt: " + aSink + ", gDataSourceState=" + gDataSourceState + "\n");
  20.     },
  21.     
  22.     onResume: function( aSink) {
  23.         gDataSourceState = (gDataSourceState & ~2);
  24.         debug_dump("\n-> SinkObserver:onResume: " + aSink + ", gDataSourceState=" + gDataSourceState + "\n");
  25.     },
  26.     
  27.     onEndLoad: function( aSink) {
  28.         gDataSourceState = (gDataSourceState | 4);
  29.         gDataSourceLoaded = (gDataSourceState  == 5);
  30.         
  31.         debug_dump("\n-> onEndLoad: " + aSink + ", gDataSourceState=" + gDataSourceState + ", gDataSourceLoaded=" + gDataSourceLoaded + "\n");
  32.  
  33.         if (!gDataSourceLoaded) {
  34.             debug_dump("\n-> builtin URLs not loaded!\n");
  35.             return;
  36.         }
  37.  
  38.         gBuiltinUrlsDataSource = aSink.QueryInterface(Components.interfaces.nsIRDFDataSource);
  39.         
  40.         debug_dump("Got gBuiltinUrlsDataSource " + gBuiltinUrlsDataSource + " with gTitleArc " + gTitleArc + " and gContentArc " + gContentArc + "\n");
  41.     },
  42.  
  43.     onError: function( aSink, aStatus, aErrMsg) {
  44.         gDataSourceState = (gDataSourceState | 8);
  45.         debug_dump("\n-> SinkObserver:onError: " + aSink +  ", status=" + aStatus + 
  46.             ", errMsg=" + aErrMsg + ", gDataSourceState=" + gDataSourceState + "\n");
  47.     }
  48. };
  49.  
  50. function debug_dump(msg)
  51. {
  52. }
  53.  
  54. /*
  55. function debug_dump(msg)
  56. {
  57.     dump(msg);
  58. }
  59. */
  60.  
  61. function loadDS()
  62. {
  63.     debug_dump("\n-->loadDS() called for " + window.document + " <--\n");
  64.     if (gBuiltinUrlsDataSource && gDataSourceLoaded) {
  65.         debug_dump("\n-->loadDS(): gBuiltinUrlsDataSource=" + gBuiltinUrlsDataSource + ", gDataSourceLoaded=" + gDataSourceLoaded + ", returning! <--\n");
  66.         return;
  67.     }
  68.     
  69.     if (gSinkObserverRegistered)
  70.     {
  71.         debug_dump("Already registered SinkObserver in loadDS()\n");
  72.         return;
  73.     }
  74.     
  75.     // initialize
  76.     gRDFService = Components.classes['@mozilla.org/rdf/rdf-service;1'].getService();
  77.     gRDFService = gRDFService.QueryInterface(Components.interfaces.nsIRDFService);
  78.  
  79.     if (!gRDFService) {
  80.         debug_dump("\n-->loadDS(): gRDFService service is null!\n");
  81.         return;
  82.     }
  83.     
  84.     gTitleArc   = gRDFService.GetResource("http://home.netscape.com/NC-rdf#title");
  85.     gContentArc = gRDFService.GetResource("http://home.netscape.com/NC-rdf#content");
  86.  
  87.     var ds_uri = "chrome://global-region/locale/builtinURLs.rdf";
  88.     var url_ds = gRDFService.GetDataSource(ds_uri); // return nsIRDFDataSource
  89.     if (!url_ds) {
  90.         debug_dump("\n >>Can't get " + ds_uri + "<-\n");
  91.         return;
  92.     }
  93.     
  94.     if (url_ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).loaded)
  95.     {
  96.         ds_uri = "chrome://global-region/locale/builtinURLs.rdf";
  97.         gBuiltinUrlsDataSource = gRDFService.GetDataSource(ds_uri); // return nsIRDFDataSource
  98.         gDataSourceLoaded = (gBuiltinUrlsDataSource != null);
  99.     }
  100.     else
  101.     {
  102.         var rdfXMLSink = url_ds.QueryInterface( Components.interfaces.nsIRDFXMLSink );
  103.         if (rdfXMLSink) {
  104.             gBuiltinUrlsDataSource         = null;
  105.             gDataSourceState      = 0x0; // init.
  106.             gDataSourceLoaded     = false;
  107.             gSinkObserverRegistered = true;
  108.             
  109.             rdfXMLSink.addXMLSinkObserver(SinkObserver);
  110.         }
  111.         else
  112.         {
  113.             debug_dump("rdfXMLSink is null\n");
  114.         }
  115.     }
  116. }
  117.  
  118. function xlateURL(key)
  119. {
  120.     debug_dump("\n>> xlateURL(" + key + "): gBuiltinUrlsDataSource=" + gBuiltinUrlsDataSource + ", gDataSourceLoaded=" + gDataSourceLoaded + "\n");
  121.     
  122.     if (!gBuiltinUrlsDataSource || !gDataSourceLoaded) {
  123.         throw("urn translation data source not loaded");
  124.     }
  125.     // get data
  126.     var srcNode = gRDFService.GetResource(key);
  127.     var titleTarget = gBuiltinUrlsDataSource.GetTarget(srcNode, gTitleArc, true);
  128.     if (titleTarget) {
  129.         titleTarget = 
  130.             titleTarget.QueryInterface(Components.interfaces.nsIRDFLiteral);
  131.         debug_dump("\n-> " + key + "::title=" + titleTarget.Value);
  132.     }
  133.     else {
  134.         debug_dump("\n title target=" + titleTarget + "\n");
  135.     }
  136.  
  137.     var contentTarget = gBuiltinUrlsDataSource.GetTarget(srcNode, gContentArc, true);
  138.     if (contentTarget) {
  139.         contentTarget = 
  140.             contentTarget.QueryInterface(Components.interfaces.nsIRDFLiteral);
  141.         debug_dump("\n-> " + key + "::content=" + contentTarget.Value + "\n");
  142.         return contentTarget.Value;
  143.     }
  144.     else {
  145.         debug_dump("\n content target=" + contentTarget + "\n");
  146.         throw("urn not found in datasource");
  147.     }
  148.     
  149.     // not reached
  150.     return "";
  151. }
  152.  
  153. function loadXURL(key)
  154. {
  155.   debug_dump("loadXURL call with " + key + "\n");
  156.     
  157.   var url = xlateURL(key);
  158.   //check to see if this is a browser window before opening.
  159.   var winType = document.documentElement.getAttribute("windowtype");
  160.  
  161.   if (window._content && winType == "navigator:browser")
  162.     window._content.location.href = url;
  163.   else
  164.     window.open(url); // on mac, there maybe no open windows: see bug 83329
  165. }
  166.  
  167. loadDS();
  168.