[Jslib] rdfDebug.js: created using test.js

Frank Koenen fkoenen at vonworld.com
Mon Jan 26 20:38:07 EST 2004


If anyone is interested, I took the logic found in test/test.js and created a file rdf/rdfDebug.js
from it. 

Here's a sample usage of it:

    include('chrome://jslib/content/rdf/rdfDebug.js');

    var rdf = new RDFFile("file://my/rdf.rdf");
    jslibDebug("rdf=" + rdf.getSource() + "\n");
    var rdfdebug = new RDFDebug();
    var conts = rdf.getAllContainers();
    for(var i=0; i<conts.length; i++) {
       rdfdebug.walk_container(conts[i]);
    }


Here's the code of rdfDebug.js:

 1  if(typeof(JS_LIB_LOADED)=='boolean')
 2  {
 3    const JS_RDFDEBUG_LOADED        = true;
 4    const JS_RDFDEBUG_FILE          = "rdfDebug.js";
 5
 6    // test to make sure rdf base classes are loaded
 7    if(typeof(JS_RDFBASE_LOADED)!='boolean')
 8          include(JS_LIB_PATH+'rdf/rdfBase.js');
 9    if(typeof(JS_RDFRESOURCE_LOADED)!='boolean')
10          include(JS_LIB_PATH+'rdf/rdfResource.js');
11    if(typeof(JS_RDFCONTAINER_LOADED)!='boolean')
12          include(JS_LIB_PATH+'rdf/rdfContainer.js');
13
14    function RDFDebug() {
15     this._rdfdebug_init();
16    }   
17
18    RDFDebug.prototype = { 
19      _rdfdebug_init : function() {
20      }   
21    };  
22
23    RDFDebug.prototype.walk_container = function(res) {
24      var list;
25      dump("Container: " + res.getSubject() + "\n");
26      list = res.getSubContainers();
27      for(var i=0; i<list.length; i++) {
28         this.walk_container(list[i]);
29      }   
30      list = res.getSubNodes();
31      for(var i=0; i<list.length; i++) {
32         dump("\tnode: " + list[i].getSubject() + "\n");
33         this.walk_attributes(list[i]);
34      }   
35    };  
36
37    RDFDebug.prototype.walk_attributes = function(node) {
38      list = node.getAllAttributes();
39      for(var i=0; i<list.length; i++) {
40         dump("\t\tattr: [name=" + list[i].name + "][value=" + list[i].value + "]\n");
41      }   
42    };  
43
44    jslibDebug('*** load: '+JS_RDFDEBUG_FILE+' OK');
45
46  } // END BLOCK JS_LIB_LOADED CHECK
47
48  else
49  {
50    dump("JS_RDFDEBUG library not loaded:\n"                                +   
51        " \tTo load use: chrome://jslib/content/jslib.js\n"            +   
52        " \tThen: include('chrome://jslib/content/rdf/rdfDebug.js');\n\n");
53  }


-- 
Frank Koenen <fkoenen at vonworld.com>



More information about the Jslib mailing list