home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 July & August / PCWorld_2005-07-08_cd.bin / komunikace / netscape / nsb-install-8-0.exe / chrome / toolkit.jar / content / global / rdfdump.js < prev    next >
Text File  |  2005-01-13  |  2KB  |  45 lines

  1. function textEntered(event) {
  2.     var text = event.target.value;
  3.     debug('textEntered('+text+')');
  4.     var RDFService = Components.classes["@mozilla.org/rdf/rdf-service;1"]
  5.                                .getService(Components.interfaces.nsIRDFService);
  6.     var ds = RDFService.GetDataSourceBlocking(text);
  7.     handleDataSource(ds);
  8.     //ds.QueryInterface(Components.interfaces.nsIRDFXMLSink);
  9.     //ds.addXMLSinkObserver(rdfLoadObserver);
  10. }
  11.  
  12. function debug(msg) {
  13.     dump('rdfdump.js: '+msg+'\n');
  14. }
  15.  
  16. var rdfLoadObserver = {
  17.     onBeginLoad : function(sink){},
  18.     onInterrupt : function(sink){},
  19.     onResume : function(sink){},
  20.     onError : function(sink,status,msg){},
  21.     onEndLoad : function(sink) {
  22.         this.debug('onEndLoad('+sink.URI+')');
  23.         // Load datasource
  24.         sink.removeXMLSinkObserver(this);
  25.         sink.QueryInterface(Components.interfaces.nsIRDFDataSource);
  26.         handleDataSource(sink);
  27.     },
  28.     debug : function(msg) {
  29.         debug('rdfLoadObserver: '+msg);
  30.     }
  31. };
  32.  
  33. function handleDataSource(ds) {
  34.     var localFile = Components.classes["@mozilla.org/file/directory_service;1"]
  35.                               .getService(Components.interfaces.nsIProperties)
  36.                               .get("ProfD", Components.interfaces.nsILocalFile);
  37.     localFile.append('temp.rdf');
  38.     var ioService = Components.classes["@mozilla.org/network/io-service;1"]
  39.                               .getService(Components.interfaces.nsIIOService);
  40.     var localFileURI = ioService.newFileURI(localFile);
  41.     ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
  42.     ds.FlushTo(localFileURI.spec);
  43.     document.getElementById('content').setAttribute('src', 'view-source:'+localFileURI.spec);
  44. }
  45.