nsFileURL		url(uri); nsNativeFileSpec	native(url); nsAutoString		name; native.GetLeafName(name);
nsCOMPtr<nsIURI>	fileURI; if (NS_FAILED(rv = NS_NewURI(getter_AddRefs(fileURI), uri))) return(rv); if (!fileURI)	return(NS_ERROR_UNEXPECTED);  nsCOMPtr<nsIChannel>	channel; if (NS_FAILED(rv = NS_OpenURI(getter_AddRefs(channel), fileURI, nsnull, nsnull))) return(rv); if (!channel)	return(NS_ERROR_UNEXPECTED);  nsCOMPtr<nsIFileChannel>	fileChannel = do_QueryInterface(channel); if (!fileChannel)	return(NS_ERROR_UNEXPECTED);  nsCOMPtr<nsIFile>	aFile; if (NS_FAILED(rv = fileChannel->GetFile(getter_AddRefs(aFile)))) return(rv); if (!aFile)		return(NS_ERROR_UNEXPECTED);  PRUnichar		*nameUni = nsnull; if (NS_FAILED(rv = aFile->GetUnicodeLeafName(&nameUni))) return(rv); if (!nameUni)		return(NS_ERROR_UNEXPECTED);  nsAutoString		name(nameUni); Recycle(nameUni); nameUni = nsnull;
FileSystemDataSource::GetName(nsIRDFResource *source, nsIRDFLiteral **aResult){	nsresult		rv;	const char		*uri;	rv = source->GetValueConst(&uri);	if (NS_FAILED(rv)) return(rv);	nsFileURL		url(uri);	nsNativeFileSpec	native(url);	nsAutoString		name;	native.GetLeafName(name);#ifdef	XP_WIN	// special hack for IE favorites under Windows; strip off the	// trailing ".url" or ".lnk" at the end of IE favorites names	PRInt32			nameLen = name.Length();	nsAutoString		theURI; theURI.AssignWithConversion(uri);	if ((theURI.Find(ieFavoritesDir) == 0) && (nameLen > 4))	{		nsAutoString	extension;		name.Right(extension, 4);		if (extension.EqualsIgnoreCase(".url") ||		    extension.EqualsIgnoreCase(".lnk"))		{			name.Truncate(nameLen - 4);		}	}#endif#ifdef	XP_BEOS	// under BEOS, try and get the "META:title" attribute (if its a file)	nsAutoString		theURI; theURI.AssignWithConversion(uri);	if (theURI.Find(netPositiveDir) == 0)	{		nsFileSpec		spec(url);		if (spec.IsFile() && (!spec.IsHidden()))		{			const char	*nativeURI = spec.GetNativePathCString();			if (nativeURI)			{				BFile	bf(nativeURI, B_READ_ONLY);				if (bf.InitCheck() == B_OK)				{					char		beNameAttr[4096];					ssize_t		len;					if ((len = bf.ReadAttr("META:title", B_STRING_TYPE,						0, beNameAttr, sizeof(beNameAttr-1))) > 0)					{						beNameAttr[len] = '\0';						name.AssignWithConversion(beNameAttr);					}				}			}		}	}#endif	nsIRDFLiteral *literal;	gRDFService->GetLiteral(name.GetUnicode(), &literal);	*aResult = literal;	return NS_OK;}