print "Hello, world!"



function getBookmarkList (doSort) {

var rdf = Components.classes[ "@mozilla.org/rdf/rdf-service;1" ].

getService(Components.interfaces.nsIRDFService);



var bmks = rdf.GetDataSource( "rdf:bookmarks" );

var NC_NS = "http://home.netscape.com/NC-rdf#" ;

var kwArc = rdf.GetResource(NC_NS + "ShortcutURL" );

var urlArc = rdf.GetResource(NC_NS + "URL" );

var nameArc = rdf.GetResource(NC_NS + "Name" );

var rdfLiteral = Components.interfaces.nsIRDFLiteral;

var e = bmks.GetAllResources();

var items = [];



while (e.hasMoreElements()) {

var r = e.getNext().QueryInterface(

Components.interfaces.nsIRDFResource);

var urlR = bmks.GetTarget(r, urlArc, true );

var kwR = bmks.GetTarget(r, kwArc, true );

var nameR = bmks.GetTarget(r, nameArc, true );

if (!(nameR && urlR)) {

continue ;

}

var item = {};

item.name = nameR.QueryInterface(rdfLiteral).Value;

item.url = urlR.QueryInterface(rdfLiteral).Value;

if (kwR) {

item.kw = kwR.QueryInterface(rdfLiteral).Value;

}

items.push(item);

}



if (doSort) {

items.sort( function (a, b) {

return (a.name.upcase() < b.name.upcase()) ? -1 : 1;

});

}

return items;

}

