temp.AppendWithConversion("?sort=true");
temp.Append(NS_LITERAL_STRING("?sort=true"));
XULSortServiceImpl::DoSort(nsIDOMNode* node, const nsString& sortResource,                           const nsString& sortDirection){	PRInt32		treeBodyIndex;	nsresult	rv;	_sortStruct	sortInfo;	// get tree node	nsCOMPtr<nsIContent>	contentNode = do_QueryInterface(node);	if (!contentNode)	return(NS_ERROR_FAILURE);	nsCOMPtr<nsIContent>	treeNode;	if (NS_FAILED(rv = FindTreeElement(nsnull, contentNode, getter_AddRefs(treeNode))))		return(rv);	nsCOMPtr<nsIDOMXULElement>	domXulTree = do_QueryInterface(treeNode);	if (!domXulTree)	return(NS_ERROR_FAILURE);	// get composite db for tree	sortInfo.rdfService = gRDFService;	sortInfo.db = nsnull;	sortInfo.resCache = nsnull;	sortInfo.mInner = nsnull;	sortInfo.parentContainer = treeNode;	sortInfo.inbetweenSeparatorSort = PR_FALSE;	sortInfo.cacheFirstHint = PR_FALSE;	sortInfo.cacheFirstNode = nsnull;	sortInfo.cacheIsFirstNodeCollationKey = PR_FALSE;    // optimization - if we're about to merely invert the current sort    // then just reverse-index the current tree    PRBool          invertTreeFlag = PR_FALSE;	nsAutoString	value;	if (NS_SUCCEEDED(rv = treeNode->GetAttr(kNameSpaceID_None, kSortActiveAtom, value))		&& (rv == NS_CONTENT_ATTR_HAS_VALUE) && (value.EqualsIgnoreCase(*trueStr)))	{		if (NS_SUCCEEDED(rv = treeNode->GetAttr(kNameSpaceID_None, kResourceAtom,			value)) && (rv == NS_CONTENT_ATTR_HAS_VALUE) && (value.EqualsIgnoreCase(sortResource)))		{			if (NS_SUCCEEDED(rv = treeNode->GetAttr(kNameSpaceID_None, kSortDirectionAtom,				value)) && (rv == NS_CONTENT_ATTR_HAS_VALUE))			{        		if ((value.Equals(*descendingStr) && sortDirection.Equals(*ascendingStr)) ||        		    (value.Equals(*ascendingStr) && sortDirection.Equals(*descendingStr)))        		{        		    invertTreeFlag = PR_TRUE;        		}			}		}	}	// remove any sort hints on tree root node	treeNode->UnsetAttr(kNameSpaceID_None, kSortActiveAtom, PR_FALSE);	treeNode->UnsetAttr(kNameSpaceID_None, kSortDirectionAtom, PR_FALSE);	treeNode->UnsetAttr(kNameSpaceID_None, kSortSeparatorsAtom, PR_FALSE);	treeNode->UnsetAttr(kNameSpaceID_None, kResourceAtom, PR_FALSE);	treeNode->UnsetAttr(kNameSpaceID_None, kResource2Atom, PR_FALSE);	nsCOMPtr<nsIRDFCompositeDataSource>	cds;	if (NS_SUCCEEDED(rv = domXulTree->GetDatabase(getter_AddRefs(cds))))	{		sortInfo.db = cds;	}	sortInfo.kTreeCellAtom = kTreeCellAtom;	sortInfo.kNameSpaceID_XUL = kNameSpaceID_XUL;	// determine new sort resource and direction to use	if (sortDirection.Equals(*naturalStr))	{		sortInfo.naturalOrderSort = PR_TRUE;		sortInfo.descendingSort = PR_FALSE;	}	else	{		sortInfo.naturalOrderSort = PR_FALSE;		if (sortDirection.Equals(*ascendingStr))		sortInfo.descendingSort = PR_FALSE;		else if (sortDirection.Equals(*descendingStr))	sortInfo.descendingSort = PR_TRUE;	}	// get index of sort column, find tree body, and sort. The sort	// _won't_ send any notifications, so we won't trigger any reflows...	nsAutoString	sortResource2;	PRBool		found;	if (NS_FAILED(rv = GetSortColumnIndex(treeNode, sortResource, sortDirection, sortResource2,		sortInfo.inbetweenSeparatorSort, sortInfo.colIndex, found)))	return(rv);	rv = gRDFService->GetUnicodeResource(sortResource.get(), getter_AddRefs(sortInfo.sortProperty));	if (NS_FAILED(rv))	return(rv);	nsAutoString	temp;	temp.Assign(sortResource);	temp.AppendWithConversion("?collation=true");	rv = gRDFService->GetUnicodeResource(temp.get(), getter_AddRefs(sortInfo.sortPropertyColl));	if (NS_FAILED(rv))	return(rv);	temp.Assign(sortResource);	temp.AppendWithConversion("?sort=true");	rv = gRDFService->GetUnicodeResource(temp.get(), getter_AddRefs(sortInfo.sortPropertySort));	if (NS_FAILED(rv))	return(rv);	if (sortResource2.Length() > 0)	{		rv = gRDFService->GetUnicodeResource(sortResource2.get(), getter_AddRefs(sortInfo.sortProperty2));		if (NS_FAILED(rv))	return(rv);		temp = sortResource2;		temp.AppendWithConversion("?collation=true");		rv = gRDFService->GetUnicodeResource(temp.get(), getter_AddRefs(sortInfo.sortPropertyColl2));		if (NS_FAILED(rv))	return(rv);		temp = sortResource2;		temp.AppendWithConversion("?sort=true");		rv = gRDFService->GetUnicodeResource(temp.get(), getter_AddRefs(sortInfo.sortPropertySort2));		if (NS_FAILED(rv))	return(rv);	}	SetSortHints(treeNode, sortResource, sortDirection, sortResource2, sortInfo.inbetweenSeparatorSort, found);	nsCOMPtr<nsIContent>	treeBody;	if (NS_FAILED(rv = FindTreeChildrenElement(treeNode, getter_AddRefs(treeBody))))	return(rv);    SortTreeChildren(treeBody, &sortInfo, invertTreeFlag);	// Now remove the treebody and re-insert it to force the frames to be rebuilt.    nsCOMPtr<nsIContent>	treeParent;	if (NS_FAILED(rv = treeBody->GetParent(*getter_AddRefs(treeParent))))	return(rv);	if (NS_FAILED(rv = treeParent->IndexOf(treeBody, treeBodyIndex)))	return(rv);	if (NS_FAILED(rv = treeParent->RemoveChildAt(treeBodyIndex, PR_TRUE)))	return(rv);	if (NS_FAILED(rv = treeParent->AppendChildTo(treeBody, PR_TRUE, PR_TRUE)))		return(rv);	return(NS_OK);}