1 /******************************************************************************
3 * This code belongs to its author. All rights reserved.
5 * Author : michel.gutierrez@gmail.com
7 ******************************************************************************/
10 * @fileoverview Accessing global utilities
18 const NS_UTIL_SERVICE_CID = Components.ID("{dbd8dc72-2cdf-44ad-bf9a-5dc7a3fc3036}");
19 const NS_UTIL_SERVICE_PROG_ID = "@downloadhelper.net/util-service;1";
26 * @class Service accessing global utilities
28 function UtilService() {
29 this.stringBundle=Components.classes["@mozilla.org/intl/stringbundle;1"].getService().
30 QueryInterface(Components.interfaces.nsIStringBundleService).
31 createBundle("chrome://dwhelper/locale/strings.properties");
32 this.RDF = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService().
33 QueryInterface(Components.interfaces.nsIRDFService);
34 this.RDFCUtils = Components.classes["@mozilla.org/rdf/container-utils;1"].getService().
35 QueryInterface(Components.interfaces.nsIRDFContainerUtils);
38 UtilService.prototype = {
41 UtilService.prototype.getRDF = function() {
45 UtilService.prototype.getRDFCUtils = function() {
46 return this.RDFCUtils;
49 UtilService.prototype.getText = function(name) {
51 return this.stringBundle.GetStringFromName(name);
57 UtilService.prototype.getFText=function(name,params,length) {
61 return this.stringBundle.formatStringFromName(name,params,params.length);
67 UtilService.prototype.getVersion=function(uuid) {
68 var RDF = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService().
69 QueryInterface(Components.interfaces.nsIRDFService);
70 var RDFCUtils = Components.classes["@mozilla.org/rdf/container-utils;1"].getService().
71 QueryInterface(Components.interfaces.nsIRDFContainerUtils);
72 var extMgr=Components.classes["@mozilla.org/extensions/manager;1"].
73 getService(Components.interfaces.nsIExtensionManager);
74 var target=extMgr.datasource.GetTarget(
75 RDF.GetResource("urn:mozilla:item:"+uuid),
76 RDF.GetResource("http://www.mozilla.org/2004/em-rdf#version"),
80 return target.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
83 UtilService.prototype.getPropertyValue = function(ds,res,prop) {
84 var target=ds.GetTarget(res,prop,true);
87 return target.QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
90 UtilService.prototype.getPropertyValueRS = function(ds,res,prop) {
91 return this.getPropertyValue(ds,res,this.RDF.GetResource(prop));
94 UtilService.prototype.getPropertyValueSR = function(ds,res,prop) {
95 return this.getPropertyValue(ds,this.RDF.GetResource(res),prop);
98 UtilService.prototype.getPropertyValueSS = function(ds,res,prop) {
99 return this.getPropertyValue(ds,this.RDF.GetResource(res),this.RDF.GetResource(prop));
102 UtilService.prototype.setPropertyValue = function(ds,res,prop,value) {
103 value=this.RDF.GetLiteral(value);
104 this.removeProperties(ds,res,prop);
106 ds.Assert(res,prop,value,true);
110 UtilService.prototype.setPropertyValueSR = function(ds,res,prop,value) {
111 this.setPropertyValue(ds,this.RDF.GetResource(res),prop,value);
114 UtilService.prototype.setPropertyValueRS = function(ds,res,prop,value) {
115 this.setPropertyValue(ds,res,this.RDF.GetResource(prop),value);
118 UtilService.prototype.setPropertyValueSS = function(ds,res,prop,value) {
119 this.setPropertyValue(ds,this.RDF.GetResource(res),this.RDF.GetResource(prop),value);
122 UtilService.prototype.removeProperties = function(ds,res,prop) {
123 var i=ds.GetTargets(res,prop,true);
125 while(i.hasMoreElements()) {
126 targets.push(i.getNext());
128 for(var i=0;i<targets.length;i++) {
129 ds.Unassert(res,prop,targets[i]);
133 UtilService.prototype.removePropertiesSR = function(ds,res,prop) {
134 this.removeProperties(ds,this.RDF.GetResource(res),prop);
137 UtilService.prototype.removePropertiesRS = function(ds,res,prop) {
138 this.removeProperties(ds,res,this.RDF.GetResource(prop));
141 UtilService.prototype.removePropertiesSS = function(ds,res,prop) {
142 this.removeProperties(ds,this.RDF.GetResource(res),this.RDF.GetResource(prop));
145 UtilService.prototype.getChildResources = function(ds,res,count) {
147 var seq=this.RDFCUtils.MakeSeq(ds,res);
148 var j=seq.GetElements();
149 while(j.hasMoreElements()) {
150 var li=j.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
153 count.value=children.length;
157 UtilService.prototype.getChildResourcesS = function(ds,res,count) {
158 return this.getChildResources(ds,this.RDF.GetResource(res),count);
161 UtilService.prototype.getPropertyResource = function(ds,res,prop) {
162 var target=ds.GetTarget(res,prop,true);
165 return target.QueryInterface(Components.interfaces.nsIRDFResource);
168 UtilService.prototype.getPropertyResourceRS = function(ds,res,prop) {
169 return this.getPropertyResource(ds,res,this.RDF.GetResource(prop));
172 UtilService.prototype.getPropertyResourceSR = function(ds,res,prop) {
173 return this.getPropertyResource(ds,this.RDF.GetResource(res),prop);
176 UtilService.prototype.getPropertyResourceSS = function(ds,res,prop) {
177 return this.getPropertyResource(ds,this.RDF.GetResource(res),this.RDF.GetResource(prop));
180 UtilService.prototype.setPropertyResource = function(ds,res,prop,value) {
181 this.removeProperties(ds,res,prop);
183 ds.Assert(res,prop,value,true);
187 UtilService.prototype.setPropertyResourceRRS = function(ds,res,prop,value) {
188 this.setPropertyResource(ds,res,prop,this.RDF.GetResource(value));
191 UtilService.prototype.setPropertyResourceRSR = function(ds,res,prop,value) {
192 this.setPropertyResource(ds,res,this.RDF.GetResource(prop),value);
195 UtilService.prototype.setPropertyResourceRSS = function(ds,res,prop,value) {
196 this.setPropertyResource(ds,res,this.RDF.GetResource(prop),this.RDF.GetResource(value));
199 UtilService.prototype.setPropertyResourceSRR = function(ds,res,prop,value) {
200 this.setPropertyResource(ds,this.RDF.GetResource(res),prop,value);
203 UtilService.prototype.setPropertyResourceSRS = function(ds,res,prop,value) {
204 this.setPropertyResource(ds,this.RDF.GetResource(res),prop,this.RDF.GetResource(value));
207 UtilService.prototype.setPropertyResourceSSR = function(ds,res,prop,value) {
208 this.setPropertyResource(ds,this.RDF.GetResource(res),this.RDF.GetResource(prop),value);
211 UtilService.prototype.setPropertyResourceSSS = function(ds,res,prop,value) {
212 this.setPropertyResource(ds,this.RDF.GetResource(res),this.RDF.GetResource(prop),this.RDF.GetResource(value));
215 UtilService.prototype.createNode=function(ds,parentNode,res) {
218 node=this.RDF.GetAnonymousResource();
220 this.setPropertyResourceRSS(ds,node,
221 "http://www.w3.org/1999/02/22-rdf-syntax-ns#instanceOf",
222 "http://www.w3.org/1999/02/22-rdf-syntax-ns#Seq");
223 this.setPropertyValueRS(ds,node,
224 "http://www.w3.org/1999/02/22-rdf-syntax-ns#nextVal","1");
226 if(parentNode!=null) {
227 parentNode=this.RDFCUtils.MakeSeq(ds,parentNode);
228 parentNode.AppendElement(node);
233 UtilService.prototype.createNodeRS=function(ds,parentNode,resValue) {
235 resValue=this.RDF.GetResource(resValue);
236 return this.createNode(ds,parentNode,resValue);
239 UtilService.prototype.createNodeSR=function(ds,parentNode,resValue) {
241 parentNode=this.RDF.GetResource(parentNode);
242 return this.createNode(ds,parentNode,resValue);
245 UtilService.prototype.createNodeSS=function(ds,parentNode,resValue) {
247 parentNode=this.RDF.GetResource(parentNode);
249 resValue=this.RDF.GetResource(resValue);
250 return this.createNode(ds,parentNode,resValue);
253 UtilService.prototype.createAnonymousNode=function(ds,parentNode) {
254 return this.createNode(ds,parentNode,null);
257 UtilService.prototype.createAnonymousNodeS=function(ds,parentNode) {
258 return this.createAnonymousNode(ds,this.RDF.GetResource(parentNode));
261 UtilService.prototype.createRootNode=function(ds,res) {
262 return this.createNode(ds,null,res);
265 UtilService.prototype.createRootNodeS=function(ds,resValue) {
266 return this.createRootNode(ds,this.RDF.GetResource(resValue));
269 UtilService.prototype.createAnonymousRootNode=function(ds) {
270 return this.createNode(ds,null,null);
273 UtilService.prototype.getDatasourceFromRDFFile=function(file) {
274 var stream = Components.classes['@mozilla.org/network/file-input-stream;1'].
275 createInstance(Components.interfaces.nsIFileInputStream);
276 stream.init(file,1,0,false);
277 var scriptableStream = Components.classes['@mozilla.org/scriptableinputstream;1'].createInstance(Components.interfaces.nsIScriptableInputStream);
278 scriptableStream.init(stream);
280 var fileSize = scriptableStream.available();
281 var fileContents = scriptableStream.read(fileSize);
283 scriptableStream.close();
286 var parser=Components.classes
287 ['@mozilla.org/rdf/xml-parser;1'].
288 createInstance(Components.interfaces.nsIRDFXMLParser);
289 var uri = Components.classes["@mozilla.org/network/standard-url;1"].
290 createInstance(Components.interfaces.nsIURI);
291 uri.spec = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
292 var memDS=Components.classes
293 ['@mozilla.org/rdf/datasource;1?name=in-memory-datasource'].
294 createInstance(Components.interfaces.nsIRDFDataSource);
295 parser.parseString(memDS,uri,fileContents);
299 UtilService.prototype.dumpDatasource=function(ds) {
302 var i = ds.GetAllResources();
303 while(i.hasMoreElements()) {
304 var source = i.getNext();
305 var j = ds.ArcLabelsOut(source);
306 while(j.hasMoreElements()) {
307 var predicate = j.getNext();
308 var k = ds.GetTargets(source,predicate,true);
309 while(k.hasMoreElements()) {
310 var target = k.getNext();
311 source=source.QueryInterface(Components.interfaces.nsIRDFResource);
312 predicate=predicate.QueryInterface(Components.interfaces.nsIRDFResource);
314 target=target.QueryInterface(Components.interfaces.nsIRDFResource);
316 target=target.QueryInterface(Components.interfaces.nsIRDFLiteral);
318 dump(source.Value+" - "+predicate.Value+" - "+target.Value+"\n");
324 UtilService.prototype.getDatasource=function(tree) {
325 if(tree.database==null)
327 var i=tree.database.GetDataSources();
328 if(i.hasMoreElements()) {
329 return i.getNext().QueryInterface(Components.interfaces.nsIRDFDataSource);
335 UtilService.prototype.clearDatasource=function(tree) {
336 if(tree.database==null)
339 var i=tree.database.GetDataSources();
340 while(i.hasMoreElements()) {
341 dss.push(i.getNext());
343 for(var i=0;i<dss.length;i++) {
344 var ds = dss[i].QueryInterface(Components.interfaces.nsIRDFDataSource);
345 var i = ds.GetAllResources();
346 ds.beginUpdateBatch();
347 while(i.hasMoreElements()) {
348 var source = i.getNext();
349 var j = ds.ArcLabelsOut(source);
350 while(j.hasMoreElements()) {
351 var predicate = j.getNext();
352 var k = ds.GetTargets(source,predicate,true);
353 while(k.hasMoreElements()) {
354 var target = k.getNext();
355 ds.Unassert(source,predicate,target);
361 for(var i=0;i<dss.length;i++) {
362 var ds = dss[i].QueryInterface(Components.interfaces.nsIRDFDataSource);
363 tree.database.RemoveDataSource(ds);
367 UtilService.prototype.removeDatasources=function(tree) {
368 if(tree.database==null)
371 var i=tree.builder.database.GetDataSources();
372 while(i.hasMoreElements()) {
373 dss.push(i.getNext());
375 for(var i=0;i<dss.length;i++) {
376 var ds = dss[i].QueryInterface(Components.interfaces.nsIRDFDataSource);
377 tree.builder.database.RemoveDataSource(ds);
381 UtilService.prototype.setDatasource=function(tree,ds) {
382 this.removeDatasources(tree);
384 tree.builder.database.AddDataSource(ds);
385 tree.builder.rebuild();
388 UtilService.prototype.addDatasource=function(tree,ds) {
390 tree.builder.database.AddDataSource(ds);
391 tree.builder.rebuild();
394 UtilService.prototype.copyDatasource=function(ds) {
395 var memDS=Components.classes
396 ['@mozilla.org/rdf/datasource;1?name=in-memory-datasource'].
397 createInstance(Components.interfaces.nsIRDFDataSource);
398 var i = ds.GetAllResources();
399 memDS.beginUpdateBatch();
400 while(i.hasMoreElements()) {
401 var source = i.getNext();
402 var j = ds.ArcLabelsOut(source);
403 while(j.hasMoreElements()) {
404 var predicate = j.getNext();
405 var k = ds.GetTargets(source,predicate,true);
406 while(k.hasMoreElements()) {
407 var target = k.getNext();
408 memDS.Assert(source,predicate,target,true);
412 memDS.endUpdateBatch();
417 UtilService.prototype.getParentNode=function(ds,node) {
418 var iter=ds.ArcLabelsIn(node);
419 while(iter.hasMoreElements()) {
420 var arc=iter.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
421 if(ChartletUtil.startsWith(arc.Value,"http://www.w3.org/1999/02/22-rdf-syntax-ns#_")) {
422 node = ds.GetSource(arc,node,true);
429 UtilService.prototype.getParentNodeS=function(ds,node) {
430 return this.getParentNode(ds,this.RDF.GetResource(node));
433 UtilService.prototype.appendNode=function(ds,parentNode,node) {
434 parentNode=this.RDFCUtils.MakeSeq(ds,parentNode);
435 parentNode.AppendElement(node);
438 UtilService.prototype.appendNodeRS=function(ds,parentNode,node) {
439 this.appendNode(ds,parentNode,this.RDF.GetResource(node));
442 UtilService.prototype.appendNodeSR=function(ds,parentNode,node) {
443 this.appendNode(ds,this.RDF.GetResource(parentNode),node);
446 UtilService.prototype.appendNodeSS=function(ds,parentNode,node) {
447 this.appendNode(ds,this.RDF.GetResource(parentNode),this.RDF.GetResource(node));
450 UtilService.prototype.removeReference = function(ds,res) {
454 var i=ds.ArcLabelsIn(res);
455 while(i.hasMoreElements()) {
456 var arc=i.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
457 var j=ds.GetSources(arc,res,true);
458 while(j.hasMoreElements()) {
459 var source=j.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
460 var m=/^http\:\/\/www\.w3\.org\/1999\/02\/22\-rdf\-syntax\-ns#_([1-9][0-9]*)$/.exec(arc.Value);
462 var seq=ChartletUtil.RDFCUtils.MakeSeq(ds,source);
463 seqElems.push({seq: seq, elem: res});
474 var i=ds.ArcLabelsOut(res);
475 while(i.hasMoreElements()) {
476 var arc=i.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
477 var j=ds.GetTargets(res,arc,true);
478 while(j.hasMoreElements()) {
479 var target=j.getNext().QueryInterface(Components.interfaces.nsIRDFNode);
488 ds.beginUpdateBatch();
489 for(var i=0;i<deltriplet.length;i++) {
490 var triplet=deltriplet[i];
491 ds.Unassert(triplet.source,triplet.property,triplet.target);
493 for(var i=0;i<seqElems.length;i++) {
494 seqElems[i].seq.RemoveElement(seqElems[i].elem,true);
499 UtilService.prototype.removeReferenceS = function(ds,res) {
500 this.removeReference(ds,this.RDF.GetResource(res));
503 UtilService.prototype.xpGetSingleNode = function(node,xpath) {
504 var anode=node.ownerDocument.evaluate(xpath,node,null,
505 XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;
509 UtilService.prototype.xpGetNodes = function(node,xpath,count) {
511 var xpr=node.ownerDocument.evaluate(xpath,
513 XPathResult.ORDERED_NODE_ITERATOR_TYPE,
515 var node0=xpr.iterateNext();
518 node0=xpr.iterateNext();
520 count.value=nodes.length;
524 UtilService.prototype.xpGetStrings = function(node,xpath,count) {
526 var xpr=node.ownerDocument.evaluate(xpath,
528 XPathResult.ORDERED_NODE_ITERATOR_TYPE,
530 var node0=xpr.iterateNext();
532 if(node0.nodeType==Node.TEXT_NODE)
533 strings.push(node0.nodeValue);
534 else if(node0.firstChild!=null && node0.firstChild.nodeType==Node.TEXT_NODE)
535 strings.push(node0.firstChild.nodeValue);
536 node0=xpr.iterateNext();
538 count.value=strings.length;
542 UtilService.prototype.xpGetString = function(node,xpath) {
543 var text=node.ownerDocument.evaluate(xpath,node,null,
544 XPathResult.STRING_TYPE,null).stringValue;
548 UtilService.prototype.getProfileDir=function() {
549 var file = Components.classes["@mozilla.org/file/directory_service;1"]
550 .getService(Components.interfaces.nsIProperties)
551 .get("ProfD", Components.interfaces.nsIFile);
555 UtilService.prototype.getProfilePath=function() {
556 return this.getProfileDir().path;
559 UtilService.prototype.getExtensionDir=function(uuid) {
560 var file = this.getProfileDir();
561 file.append("extensions");
566 UtilService.prototype.getExtensionPath=function(uuid) {
567 return this.getExtensionDir(uuid).path;
570 UtilService.prototype.removeReferenceS=function(ds,res) {
571 this.removeReference(ds,this.RDF.GetResource(res));
574 UtilService.prototype.removeReference=function(ds,res) {
579 var i=ds.ArcLabelsIn(res);
580 while(i.hasMoreElements()) {
581 var arc=i.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
582 var j=ds.GetSources(arc,res,true);
583 while(j.hasMoreElements()) {
584 var source=j.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
585 var m=/^http\:\/\/www\.w3\.org\/1999\/02\/22\-rdf\-syntax\-ns#_([1-9][0-9]*)$/.exec(arc.Value);
587 var seq=this.RDFCUtils.MakeSeq(ds,source);
588 seqElems.push({seq: seq, elem: res});
599 var i=ds.ArcLabelsOut(res);
600 while(i.hasMoreElements()) {
601 var arc=i.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
602 var j=ds.GetTargets(res,arc,true);
603 while(j.hasMoreElements()) {
604 var target=j.getNext().QueryInterface(Components.interfaces.nsIRDFNode);
613 ds.beginUpdateBatch();
614 for(var i=0;i<deltriplet.length;i++) {
615 var triplet=deltriplet[i];
616 ds.Unassert(triplet.source,triplet.property,triplet.target);
618 for(var i=0;i<seqElems.length;i++) {
619 seqElems[i].seq.RemoveElement(seqElems[i].elem,true);
624 UtilService.prototype.generateUuid=function() {
626 var groups=[8,4,4,4,12];
627 for(var i=0;i<groups.length;i++) {
630 for(var j=0;j<groups[i];j++) {
631 var d=Math.floor(Math.random()*16);
633 uuid+=String.fromCharCode("0".charCodeAt(0)+d);
635 uuid+=String.fromCharCode("a".charCodeAt(0)-10+d);
642 UtilService.prototype.generateXPath = function(node) {
645 while(node.parentNode!=null) {
647 if(node.nodeType==Node.TEXT_NODE) {
650 str0+=node.nodeName.toLowerCase();
652 var index=this.getNodeChildIndex(node);
653 str0+="["+(index+1)+"]";
655 node=node.parentNode;
657 str=node.nodeName+str;
658 if(str.substr(0,9)=="#document")
659 str=str.substring(9);
663 UtilService.prototype.getNodeChildIndex = function(child) {
665 var parent=child.parentNode;
666 var node=parent.firstChild;
670 if(node.nodeName==child.nodeName &&
671 (node.nodeType==Node.ELEMENT_NODE || node.nodeType==Node.TEXT_NODE))
673 node=node.nextSibling;
678 UtilService.prototype.decodeURL = function(text) {
679 var decoder=Components.classes["@mozilla.org/intl/utf8converterservice;1"]
680 .getService(Components.interfaces.nsIUTF8ConverterService);
681 text=decoder.convertURISpecToUTF8(text,null);
682 var hc="0123456789ABCDEFabcdef";
685 while (i < text.length) {
686 var ch=text.charAt(i);
690 } else if (ch=="%") {
691 if (i < (text.length-2)
692 && hc.indexOf(text.charAt(i+1)) != -1
693 && hc.indexOf(text.charAt(i+2)) != -1 ) {
694 pt+=unescape( text.substr(i,3) );
708 UtilService.prototype.encodeURL = function(text) {
709 var sc="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.!~*'()";
710 var h="0123456789ABCDEF";
712 for (var i=0; i < text.length; i++ ) {
713 var ch=text.charAt(i);
716 } else if (sc.indexOf(ch) != -1) {
719 var charCode=ch.charCodeAt(0);
720 if (charCode > 255) {
723 encoded+="%"+h.charAt((charCode >> 4) & 0xF)+h.charAt(charCode & 0xF);
730 UtilService.prototype.contentPost = function(url,body,target,targetName,features) {
732 var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"].getService().
733 QueryInterface(Components.interfaces.nsIWindowWatcher);
734 target=wwatch.openWindow(null, "about:blank",
735 targetName, features, null);
737 var webNav = target.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
738 getInterface(Components.interfaces.nsIWebNavigation);
741 sis=Components.classes["@mozilla.org/io/string-input-stream;1"].
742 createInstance(Components.interfaces.nsIStringInputStream);
743 sis.setData("Content-length: "+body.length+"\r\n\r\n"+body,-1);
745 webNav.loadURI(url,webNav.LOAD_FLAGS_NONE,null,sis,null);
748 UtilService.prototype.xmlEscape = function(str) {
749 str=str.replace(/&/g,"&");
750 str=str.replace(/</g,"<");
751 str=str.replace(/>/g,">");
753 str=str.replace(/'/g,"'");
754 str=str.replace(/"/g,""");
756 for(var i=0;i<str.length;i++) {
757 var cc=str.charCodeAt(i);
766 UtilService.prototype.getUTCTime = function() {
768 var t=date.getTime();
769 t+=date.getTimezoneOffset()*60*1000;
773 UtilService.prototype.formatNumberMinDigits = function(value,digits) {
775 while(str.length<digits)
780 UtilService.prototype.getExceptionStack = function(e) {
783 var location=e.location;
784 while(location!=null) {
785 msg+=location.filename+":"+location.lineNumber+"\n";
786 location=location.caller;
790 return "[UtilService] error while getting exception frame: "+e0;
794 UtilService.prototype.removeChild = function(ds,parent,child) {
795 var seq=this.RDFCUtils.MakeSeq(ds,parent);
796 seq.RemoveElement(child,true);
799 UtilService.prototype.removeChildRS = function(ds,parent,child) {
800 var seq=this.RDFCUtils.MakeSeq(ds,parent);
801 seq.RemoveElement(this.RDF.GetResource(child),true);
804 UtilService.prototype.removeChildSR = function(ds,parent,child) {
805 var seq=this.RDFCUtils.MakeSeq(ds,this.RDF.GetResource(parent));
806 seq.RemoveElement(child,true);
809 UtilService.prototype.removeChildSS = function(ds,parent,child) {
810 var seq=this.RDFCUtils.MakeSeq(ds,this.RDF.GetResource(parent));
811 seq.RemoveElement(this.RDF.GetResource(child),true);
814 UtilService.prototype.getRDFNodeValue = function(node) {
818 var res=node.QueryInterface(Components.interfaces.nsIRDFResource);
822 var lit=node.QueryInterface(Components.interfaces.nsIRDFLiteral);
828 UtilService.prototype.QueryInterface = function(iid) {
829 if (!iid.equals(Components.interfaces.nsISupports) &&
830 !iid.equals(Components.interfaces.dhIUtilService)) {
831 //dump("UtilService: requested invalid interface "+iid+"\n");
832 throw Components.results.NS_ERROR_NO_INTERFACE;
837 var vUtilServiceModule = {
841 * RegisterSelf is called at registration time (component installation
842 * or the only-until-release startup autoregistration) and is responsible
843 * for notifying the component manager of all components implemented in
844 * this module. The fileSpec, location and type parameters are mostly
845 * opaque, and should be passed on to the registerComponent call
848 registerSelf: function (compMgr, fileSpec, location, type) {
850 if (this.firstTime) {
851 this.firstTime = false;
852 throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
854 compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
855 compMgr.registerFactoryLocation(NS_UTIL_SERVICE_CID,
857 NS_UTIL_SERVICE_PROG_ID,
863 unregisterSelf: function(compMgr, fileSpec, location) {
864 compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
865 compMgr.unregisterFactoryLocation(NS_UTIL_SERVICE_CID, fileSpec);
869 * The GetClassObject method is responsible for producing Factory and
870 * SingletonFactory objects (the latter are specialized for services).
872 getClassObject: function (compMgr, cid, iid) {
873 if (!cid.equals(NS_UTIL_SERVICE_CID)) {
874 throw Components.results.NS_ERROR_NO_INTERFACE;
877 if (!iid.equals(Components.interfaces.nsIFactory)) {
878 throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
881 return this.vUtilServiceFactory;
885 vUtilServiceFactory: {
887 * Construct an instance of the interface specified by iid, possibly
888 * aggregating it with the provided outer. (If you don't know what
889 * aggregation is all about, you don't need to. It reduces even the
890 * mightiest of XPCOM warriors to snivelling cowards.)
892 createInstance: function (outer, iid) {
894 throw Components.results.NS_ERROR_NO_AGGREGATION;
898 Node=Components.interfaces.nsIDOMNode;
900 if(XPathResult==null)
901 XPathResult=Components.interfaces.nsIDOMXPathResult;
903 return (new UtilService()).QueryInterface(iid);
908 * The canUnload method signals that the component is about to be unloaded.
909 * C++ components can return false to indicate that they don't wish to be
910 * unloaded, but the return value from JS components' canUnload is ignored:
911 * mark-and-sweep will keep everything around until it's no longer in use,
912 * making unconditional ``unload'' safe.
914 * You still need to provide a (likely useless) canUnload method, though:
915 * it's part of the nsIModule interface contract, and the JS loader _will_
918 canUnload: function(compMgr) {
923 function NSGetModule(compMgr, fileSpec) {
924 return vUtilServiceModule;