rem: debug("doContextCmd start: cmd='" + cmdName + "'");  var bundle = srGetStrBundle("chrome:     var	nameVal = "", urlVal = "";  if (cmdName == "http: { while (true) { var promptStr = bundle.GetStringFromName("NewBookmarkURLPrompt"); urlVal = prompt(promptStr, ""); if (!urlVal || urlVal=="")	return(false);   var colonOffset = urlVal.indexOf(":"); if (colonOffset > 0)	break; alert(bundle.GetStringFromName("NeedValidURL")); }  promptStr = bundle.GetStringFromName("NewBookmarkNamePrompt"); nameVal = prompt(promptStr, ""); if (!nameVal || nameVal=="")	return(false); } else if (cmdName == "http: { var promptStr = bundle.GetStringFromName("NewFolderNamePrompt"); nameVal = prompt(promptStr, ""); if (!nameVal || nameVal=="")	return(false); } else if ((cmdName == "http: (cmdName == "http: (cmdName == "http: { var promptStr = bundle.GetStringFromName("DeleteItems"); if (!confirm(promptStr))	return(false); } else if (cmdName == "http: { try { var filePicker = Components.classes["component: if (filePicker)	filePicker = filePicker.QueryInterface(Components.interfaces.nsIFileSpecWithUI); if (!filePicker)	return(false);  var promptStr = bundle.GetStringFromName("SelectImport");  filePicker.chooseInputFile(promptStr, 2, "", ""); var filespec = filePicker.QueryInterface(Components.interfaces.nsIFileSpec); if (!filespec)		return(false); var filename = filespec.URLString; if ((!filename) || (filename == ""))	return(false);  debug("Import: '" + filename + "'\n"); urlVal = filename; } catch(ex) { return(false); } } else if (cmdName == "http: { try { var filePicker = Components.classes["component: if (filePicker)	filePicker = filePicker.QueryInterface(Components.interfaces.nsIFileSpecWithUI); if (!filePicker)	return(false);  var promptStr = bundle.GetStringFromName("EnterExport");  filePicker.chooseOutputFile(promptStr, "bookmarks.html", 2); var filespec = filePicker.QueryInterface(Components.interfaces.nsIFileSpec); if (!filespec)		return(false); var filename = filespec.URLString; if ((!filename) || (filename == ""))	return(false);  debug("Export: '" + filename + "'\n"); urlVal = filename; } catch(ex) { return(false); } }  var treeNode = document.getElementById("bookmarksTree"); if (!treeNode)    return(false); var db = treeNode.database; if (!db)    return(false);  var compositeDB = db.QueryInterface(Components.interfaces.nsIRDFDataSource); if (!compositeDB)    return(false);  var isupports = Components.classes["component: if (!isupports)    return(false); var rdf = isupports.QueryInterface(Components.interfaces.nsIRDFService); if (!rdf)    return(false);   var cmdResource = rdf.GetResource(cmdName); if (!cmdResource)        return(false); cmdResource = cmdResource.QueryInterface(Components.interfaces.nsIRDFResource); if (!cmdResource)        return(false);   var selectionInstance = Components.classes["component: var selectionArray = selectionInstance.QueryInterface(Components.interfaces.nsISupportsArray);   var argumentsInstance = Components.classes["component: var argumentsArray = argumentsInstance.QueryInterface(Components.interfaces.nsISupportsArray);   var parentArc = rdf.GetResource("http: if (!parentArc)	return(false); var nameArc = rdf.GetResource("http: if (!nameArc)	return(false); var urlArc = rdf.GetResource("http: if (!urlArc)	return(false);  var select_list = treeNode.selectedItems; debug("# of Nodes selected: " + select_list.length);  if (select_list.length < 1) {  var	uri = treeNode.getAttribute("ref"); if (!uri || uri=="")    return(false); var rdfNode = rdf.GetResource(uri);  if (rdfNode) { selectionArray.AppendElement(rdfNode); }   if ((nameVal) && (nameVal != "")) { var nameLiteral = rdf.GetLiteral(nameVal); if (!nameLiteral)	return(false); argumentsArray.AppendElement(nameArc); argumentsArray.AppendElement(nameLiteral); } if ((urlVal) && (urlVal != "")) { var urlLiteral = rdf.GetLiteral(urlVal); if (!urlLiteral)	return(false); argumentsArray.AppendElement(urlArc); argumentsArray.AppendElement(urlLiteral); } } else for (var nodeIndex=0; nodeIndex<select_list.length; nodeIndex++) { var node = select_list[nodeIndex]; if (!node)    break; var	uri = node.getAttribute("ref"); if ((uri) || (uri == "")) { uri = node.getAttribute("id"); } if (!uri)    return(false);  var rdfNode = rdf.GetResource(uri); if (!rdfNode)    break;   selectionArray.AppendElement(rdfNode);   var parentURI=""; var	theParent = node; while (theParent) { theParent = theParent.parentNode;  parentURI = theParent.getAttribute("ref"); if ((!parentURI) || (parentURI == "")) { parentURI = theParent.getAttribute("id"); } if (parentURI != "")	break; } if (parentURI == "")    return(false);  var parentNode = rdf.GetResource(parentURI, true); if (!parentNode)	return(false);   argumentsArray.AppendElement(parentArc); argumentsArray.AppendElement(parentNode);  if ((nameVal) && (nameVal != "")) { var nameLiteral = rdf.GetLiteral(nameVal); if (!nameLiteral)	return(false); argumentsArray.AppendElement(nameArc); argumentsArray.AppendElement(nameLiteral); } if ((urlVal) && (urlVal != "")) { var urlLiteral = rdf.GetLiteral(urlVal); if (!urlLiteral)	return(false); argumentsArray.AppendElement(urlArc); argumentsArray.AppendElement(urlLiteral); } }   compositeDB.DoCommand( selectionArray, cmdResource, argumentsArray );  debug("doContextCmd ends."); return(true); 
add: debug("doContextCmd start: cmd='" + cmdName + "'");      var nameVal = ""; var urlVal = "";  if (cmdName == NC + "command?cmd=newbookmark") { while (true) { var promptStr = get_localized_string("NewBookmarkURLPrompt"); urlVal = prompt(promptStr, ""); if (!urlVal || urlVal=="") return false;   var colonOffset = urlVal.indexOf(":"); if (colonOffset > 0) break; alert(get_localized_string("NeedValidURL")); }  promptStr = get_localized_string("NewBookmarkNamePrompt"); nameVal = prompt(promptStr, ""); if (!nameVal || nameVal=="") return false; } else if (cmdName == NC + "command?cmd=newfolder") { var promptStr = get_localized_string("NewFolderNamePrompt"); nameVal = prompt(promptStr, ""); if (!nameVal || nameVal=="") return false; } else if ((cmdName == NC + "command?cmd=deletebookmark") || (cmdName == NC + "command?cmd=deletebookmarkfolder") || (cmdName == NC + "command?cmd=deletebookmarkseparator")) { var promptStr = get_localized_string("DeleteItems"); if (!confirm(promptStr)) return false; } else if (cmdName == NC + "command?cmd=import") { try { var picker_uri = "component: var filePicker = Components.classes[picker_uri].createInstance(); if (filePicker) { filePicker = filePicker.QueryInterface(Components.interfaces.nsIFileSpecWithUI); } if (!filePicker) return false;  var promptStr = get_localized_string("SelectImport");  filePicker.chooseInputFile(promptStr, 2, "", ""); var filespec = filePicker.QueryInterface(Components.interfaces.nsIFileSpec); if (!filespec) return false; var filename = filespec.URLString; if ((!filename) || (filename == "")) return false;  debug("Import: '" + filename + "'\n"); urlVal = filename; } catch(ex) { return false; } } else if (cmdName == NC + "command?cmd=export") { try { var picker_uri = "component: var filePicker = Components.classes[picker_uri].createInstance(); if (filePicker) { filePicker = filePicker.QueryInterface(Components.interfaces.nsIFileSpecWithUI); } if (!filePicker) return false;  var promptStr = get_localized_string("EnterExport");  filePicker.chooseOutputFile(promptStr, "bookmarks.html", 2);  var filespec = filePicker.QueryInterface(Components.interfaces.nsIFileSpec); if (!filespec) return false; var filename = filespec.URLString; if ((!filename) || (filename == "")) return false;  debug("Export: '" + filename + "'\n"); urlVal = filename; } catch(ex) { return false; } }  var treeNode = document.getElementById("bookmarksTree"); if (!treeNode) return false; var db = treeNode.database; if (!db) return false;  var compositeDB = db.QueryInterface(Components.interfaces.nsIRDFDataSource); if (!compositeDB) return false;  var isupports_uri = "component: var isupports = Components.classes[isupports_uri].getService(); if (!isupports) return false; var rdf = isupports.QueryInterface(Components.interfaces.nsIRDFService); if (!rdf) return false;   var cmdResource = rdf.GetResource(cmdName); if (!cmdResource) return false; cmdResource = cmdResource.QueryInterface(Components.interfaces.nsIRDFResource); if (!cmdResource) return false;   var selection_uri = "component: var selectionInstance = Components.classes[selection_uri].createInstance(); var selectionArray = selectionInstance.QueryInterface(Components.interfaces.nsISupportsArray);   var arguments_uri = "component: var argumentsInstance = Components.classes[arguments_uri].createInstance(); var argumentsArray = argumentsInstance.QueryInterface(Components.interfaces.nsISupportsArray);   var parentArc = rdf.GetResource(NC + "parent"); if (!parentArc) return false; var nameArc = rdf.GetResource(NC + "Name"); if (!nameArc) return false; var urlArc = rdf.GetResource(NC + "URL"); if (!urlArc) return false;  var select_list = treeNode.selectedItems; debug("# of Nodes selected: " + select_list.length);  if (select_list.length < 1) {   var uri = treeNode.getAttribute("ref"); if (!uri || uri=="") return false; var rdfNode = rdf.GetResource(uri);  if (rdfNode) { selectionArray.AppendElement(rdfNode); }   if ((nameVal) && (nameVal != "")) { var nameLiteral = rdf.GetLiteral(nameVal); if (!nameLiteral) return false; argumentsArray.AppendElement(nameArc); argumentsArray.AppendElement(nameLiteral); } if ((urlVal) && (urlVal != "")) { var urlLiteral = rdf.GetLiteral(urlVal); if (!urlLiteral) return false; argumentsArray.AppendElement(urlArc); argumentsArray.AppendElement(urlLiteral); } } else for (var nodeIndex=0; nodeIndex<select_list.length; nodeIndex++) { var node = select_list[nodeIndex]; if (!node) break; var uri = node.getAttribute("ref"); if ((uri) || (uri == "")) { uri = node.getAttribute("id"); } if (!uri) return false;  var rdfNode = rdf.GetResource(uri); if (!rdfNode) break;   selectionArray.AppendElement(rdfNode);   var parentURI = ""; var theParent = node; while (theParent) { theParent = theParent.parentNode;  parentURI = theParent.getAttribute("ref"); if ((!parentURI) || (parentURI == "")) { parentURI = theParent.getAttribute("id"); } if (parentURI != "") break; } if (parentURI == "") return false;  var parentNode = rdf.GetResource(parentURI, true); if (!parentNode) return false;   argumentsArray.AppendElement(parentArc); argumentsArray.AppendElement(parentNode);  if ((nameVal) && (nameVal != "")) { var nameLiteral = rdf.GetLiteral(nameVal); if (!nameLiteral) return false; argumentsArray.AppendElement(nameArc); argumentsArray.AppendElement(nameLiteral); } if ((urlVal) && (urlVal != "")) { var urlLiteral = rdf.GetLiteral(urlVal); if (!urlLiteral) return false; argumentsArray.AppendElement(urlArc); argumentsArray.AppendElement(urlLiteral); } }   compositeDB.DoCommand(selectionArray, cmdResource, argumentsArray);  debug("doContextCmd ends."); return true; 
context: function doContextCmd(cmdName){	debug("doContextCmd start: cmd='" + cmdName + "'");	var bundle = srGetStrBundle("chrome://communicator/locale/bookmarks/bookmark.properties");	// do some prompting/confirmation for various bookmark commands that we know about;	// if we have values to pass it, they are added to the arguments array	var	nameVal = "", urlVal = "";	if (cmdName == "http://home.netscape.com/NC-rdf#command?cmd=newbookmark")	{		while (true)		{			var promptStr = bundle.GetStringFromName("NewBookmarkURLPrompt");			urlVal = prompt(promptStr, "");			if (!urlVal || urlVal=="")	return(false);						// ensure we get a fully qualified URL (protocol colon address)			var colonOffset = urlVal.indexOf(":");			if (colonOffset > 0)	break;			alert(bundle.GetStringFromName("NeedValidURL"));		}		promptStr = bundle.GetStringFromName("NewBookmarkNamePrompt");		nameVal = prompt(promptStr, "");		if (!nameVal || nameVal=="")	return(false);	}	else if (cmdName == "http://home.netscape.com/NC-rdf#command?cmd=newfolder")	{		var promptStr = bundle.GetStringFromName("NewFolderNamePrompt");		nameVal = prompt(promptStr, "");		if (!nameVal || nameVal=="")	return(false);	}	else if ((cmdName == "http://home.netscape.com/NC-rdf#command?cmd=deletebookmark") ||		 (cmdName == "http://home.netscape.com/NC-rdf#command?cmd=deletebookmarkfolder") ||		 (cmdName == "http://home.netscape.com/NC-rdf#command?cmd=deletebookmarkseparator"))	{		var promptStr = bundle.GetStringFromName("DeleteItems");		if (!confirm(promptStr))	return(false);	}	else if (cmdName == "http://home.netscape.com/NC-rdf#command?cmd=import")	{		try		{			var filePicker = Components.classes["component://netscape/filespecwithui"].createInstance();	                if (filePicker)	filePicker = filePicker.QueryInterface(Components.interfaces.nsIFileSpecWithUI);	                if (!filePicker)	return(false);			var promptStr = bundle.GetStringFromName("SelectImport");			filePicker.chooseInputFile(promptStr, 2, "", "");		// 2 = html filter			var filespec = filePicker.QueryInterface(Components.interfaces.nsIFileSpec);			if (!filespec)		return(false);			var filename = filespec.URLString;			if ((!filename) || (filename == ""))	return(false);			debug("Import: '" + filename + "'\n");			urlVal = filename;		}		catch(ex)		{			return(false);		}	}	else if (cmdName == "http://home.netscape.com/NC-rdf#command?cmd=export")	{		try		{			var filePicker = Components.classes["component://netscape/filespecwithui"].createInstance();	                if (filePicker)	filePicker = filePicker.QueryInterface(Components.interfaces.nsIFileSpecWithUI);	                if (!filePicker)	return(false);			var promptStr = bundle.GetStringFromName("EnterExport");			filePicker.chooseOutputFile(promptStr, "bookmarks.html", 2);	// 2 = html filter			var filespec = filePicker.QueryInterface(Components.interfaces.nsIFileSpec);			if (!filespec)		return(false);			var filename = filespec.URLString;			if ((!filename) || (filename == ""))	return(false);			debug("Export: '" + filename + "'\n");			urlVal = filename;		}		catch(ex)		{			return(false);		}	}	var treeNode = document.getElementById("bookmarksTree");	if (!treeNode)    return(false);	var db = treeNode.database;	if (!db)    return(false);	var compositeDB = db.QueryInterface(Components.interfaces.nsIRDFDataSource);	if (!compositeDB)    return(false);	var isupports = Components.classes["component://netscape/rdf/rdf-service"].getService();	if (!isupports)    return(false);	var rdf = isupports.QueryInterface(Components.interfaces.nsIRDFService);	if (!rdf)    return(false);	// need a resource for the command	var cmdResource = rdf.GetResource(cmdName);	if (!cmdResource)        return(false);	cmdResource = cmdResource.QueryInterface(Components.interfaces.nsIRDFResource);	if (!cmdResource)        return(false);	// set up selection nsISupportsArray	var selectionInstance = Components.classes["component://netscape/supports-array"].createInstance();	var selectionArray = selectionInstance.QueryInterface(Components.interfaces.nsISupportsArray);	// set up arguments nsISupportsArray	var argumentsInstance = Components.classes["component://netscape/supports-array"].createInstance();	var argumentsArray = argumentsInstance.QueryInterface(Components.interfaces.nsISupportsArray);	// get various arguments (parent, name)	var parentArc = rdf.GetResource("http://home.netscape.com/NC-rdf#parent");	if (!parentArc)	return(false);	var nameArc = rdf.GetResource("http://home.netscape.com/NC-rdf#Name");	if (!nameArc)	return(false);	var urlArc = rdf.GetResource("http://home.netscape.com/NC-rdf#URL");	if (!urlArc)	return(false);	var select_list = treeNode.selectedItems;	debug("# of Nodes selected: " + select_list.length);	if (select_list.length < 1)	{		// if nothing is selected, default to using the "ref" on the root of the tree		var	uri = treeNode.getAttribute("ref");		if (!uri || uri=="")    return(false);		var rdfNode = rdf.GetResource(uri);		// add node into selection array		if (rdfNode)		{			selectionArray.AppendElement(rdfNode);		}		// add singular arguments into arguments array		if ((nameVal) && (nameVal != ""))		{			var nameLiteral = rdf.GetLiteral(nameVal);			if (!nameLiteral)	return(false);			argumentsArray.AppendElement(nameArc);			argumentsArray.AppendElement(nameLiteral);		}		if ((urlVal) && (urlVal != ""))		{			var urlLiteral = rdf.GetLiteral(urlVal);			if (!urlLiteral)	return(false);			argumentsArray.AppendElement(urlArc);			argumentsArray.AppendElement(urlLiteral);		}	}	else for (var nodeIndex=0; nodeIndex<select_list.length; nodeIndex++)	{		var node = select_list[nodeIndex];		if (!node)    break;		var	uri = node.getAttribute("ref");		if ((uri) || (uri == ""))		{			uri = node.getAttribute("id");		}		if (!uri)    return(false);		var rdfNode = rdf.GetResource(uri);		if (!rdfNode)    break;		// add node into selection array		selectionArray.AppendElement(rdfNode);		// get the parent's URI		var parentURI="";		var	theParent = node;		while (theParent)		{			theParent = theParent.parentNode;			parentURI = theParent.getAttribute("ref");			if ((!parentURI) || (parentURI == ""))			{				parentURI = theParent.getAttribute("id");			}			if (parentURI != "")	break;		}		if (parentURI == "")    return(false);		var parentNode = rdf.GetResource(parentURI, true);		if (!parentNode)	return(false);		// add multiple arguments into arguments array		argumentsArray.AppendElement(parentArc);		argumentsArray.AppendElement(parentNode);		if ((nameVal) && (nameVal != ""))		{			var nameLiteral = rdf.GetLiteral(nameVal);			if (!nameLiteral)	return(false);			argumentsArray.AppendElement(nameArc);			argumentsArray.AppendElement(nameLiteral);		}		if ((urlVal) && (urlVal != ""))		{			var urlLiteral = rdf.GetLiteral(urlVal);			if (!urlLiteral)	return(false);			argumentsArray.AppendElement(urlArc);			argumentsArray.AppendElement(urlLiteral);		}	}	// do the command	compositeDB.DoCommand( selectionArray, cmdResource, argumentsArray );	debug("doContextCmd ends.");	return(true);}
meta: 8395	/local1/tlutelli/issta_data/temp/all_js/javascript/2006_temp/2006/8395/e9736d961a24945c2f31d67dc799c3c803d7729a/bookmarks.js/buggy/xpfe/components/bookmarks/resources/bookmarks.js