sortInfo.kNaturalOrderPosAtom = kNaturalOrderPosAtom;
XULSortServiceImpl::DoSort(nsIDOMNode* node, const nsString& sortResource,                           const nsString& sortDirection){	PRInt32		colIndex, 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);	// get composite db for tree	sortInfo.rdfService = gRDFService;	sortInfo.db = nsnull;	sortInfo.resCache = nsnull;	sortInfo.mInner = nsnull;	nsCOMPtr<nsIDOMXULElement>	domXulTree = do_QueryInterface(treeNode);	if (!domXulTree)	return(NS_ERROR_FAILURE);	nsCOMPtr<nsIRDFCompositeDataSource>	cds;	if (NS_SUCCEEDED(rv = domXulTree->GetDatabase(getter_AddRefs(cds))))	{		sortInfo.db = cds;	}	sortInfo.kNaturalOrderPosAtom = kNaturalOrderPosAtom;	sortInfo.kTreeCellAtom = kTreeCellAtom;	sortInfo.kNameSpaceID_XUL = kNameSpaceID_XUL;	if (NS_FAILED(rv = gRDFService->GetResource(nsCAutoString(sortResource),		getter_AddRefs(sortInfo.sortProperty))))		return(rv);		// determine new sort resource and direction to use	if (sortDirection.EqualsIgnoreCase("natural"))	{		sortInfo.naturalOrderSort = PR_TRUE;		sortInfo.descendingSort = PR_FALSE;	}	else	{		sortInfo.naturalOrderSort = PR_FALSE;		if (sortDirection.EqualsIgnoreCase("ascending"))	sortInfo.descendingSort = PR_FALSE;		else if (sortDirection.EqualsIgnoreCase("descending"))	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...	if (NS_FAILED(rv = GetSortColumnIndex(treeNode, sortResource, sortDirection, &colIndex)))	return(rv);	sortInfo.colIndex = colIndex;	nsCOMPtr<nsIContent>	treeBody;	if (NS_FAILED(rv = FindTreeChildrenElement(treeNode, getter_AddRefs(treeBody))))	return(rv);	if (NS_SUCCEEDED(rv = SortTreeChildren(treeBody, colIndex, &sortInfo)))	{	}	// 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)))	return(rv);	return(NS_OK);}