if (NS_FAILED(rv = GetElementResource(aTreeItemElement, getter_AddRefs(treeItemResource)))) { NS_ERROR("unable to get tree item resource"); return rv; }
rv = nsRDFContentUtils::GetElementResource(aTreeItemElement, getter_AddRefs(treeItemResource)); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get tree item resource"); if (NS_FAILED(rv)) return rv;
RDFTreeBuilderImpl::CreateTreeItemCells(nsIContent* aTreeItemElement){    // <xul:treeitem>    //   <xul:treecell RDF:ID="property">value</xul:treecell>    //   ...    // </xul:treeitem>    nsresult rv;    // XXX at this point, we should probably ensure that aElement is    // actually a <xul:treeitem>...    // Get the treeitem's resource so that we can generate cell    // values. We could QI for the nsIRDFResource here, but doing this    // via the nsIContent interface allows us to support generic nodes    // that might get added in by DOM calls.    nsCOMPtr<nsIRDFResource> treeItemResource;    if (NS_FAILED(rv = GetElementResource(aTreeItemElement, getter_AddRefs(treeItemResource)))) {        NS_ERROR("unable to get tree item resource");        return rv;    }    PRInt32 count;    if (NS_FAILED(rv = mRoot->ChildCount(count))) {        NS_ERROR("unable to count xul:tree element's kids");        return rv;    }    // Iterate through all the columns that have been specified,    // constructing a cell in the content model for each one.    PRInt32 cellIndex = 0;    for (PRInt32 i = 0; i < count; ++i) {        nsCOMPtr<nsIContent> kid;        if (NS_FAILED(rv = mRoot->ChildAt(i, *getter_AddRefs(kid)))) {            NS_ERROR("unable to get xul:tree's child");            return rv;        }        PRInt32 nameSpaceID;        if (NS_FAILED(rv = kid->GetNameSpaceID(nameSpaceID))) {            NS_ERROR("unable to get child's namespace");            return rv;        }        if (nameSpaceID != kNameSpaceID_XUL)            continue; // not <xul:*>        nsCOMPtr<nsIAtom> tag;        if (NS_FAILED(rv = kid->GetTag(*getter_AddRefs(tag)))) {            NS_ERROR("unable to get child's tag");            return rv;        }        if (tag.get() != kTreeColAtom)            continue; // not <xul:treecol>        // Okay, we've found a column. Ensure that we've got a real        // tree cell that lives beneath _this_ tree item for its        // value.        nsCOMPtr<nsIContent> cellElement;        if (NS_FAILED(rv = EnsureCell(aTreeItemElement, cellIndex, getter_AddRefs(cellElement)))) {            NS_ERROR("unable to find/create cell element");            return rv;        }        nsIContent* textParent = cellElement;        // The first cell gets a <xul:treeindentation> element and a        // <xul:treeicon> element...        //        // XXX This is bogus: dogfood ready crap. We need to figure        // out a better way to specify this.        if (cellIndex == 0) {            nsCOMPtr<nsIContent> indentationElement;            if (NS_FAILED(rv = NS_NewRDFElement(kNameSpaceID_XUL,                                                kTreeIndentationAtom,                                                getter_AddRefs(indentationElement)))) {                NS_ERROR("unable to create indentation node");                return rv;            }            if (NS_FAILED(rv = cellElement->AppendChildTo(indentationElement, PR_FALSE))) {                NS_ERROR("unable to append indentation element");                return rv;            }            nsCOMPtr<nsIContent> iconElement;            if (NS_FAILED(rv = NS_NewRDFElement(kNameSpaceID_XUL,                                                kTitledButtonAtom /* kTreeIconAtom */,                                                getter_AddRefs(iconElement)))) {                NS_ERROR("unable to create icon node");                return rv;            }            if (NS_FAILED(rv = cellElement->AppendChildTo(iconElement, PR_FALSE))) {                NS_ERROR("uanble to append icon element");                return rv;            }            //textParent = iconElement;        }        // The column property is stored in the RDF:resource attribute        // of the tag.        nsAutoString uri;        if (NS_FAILED(rv = kid->GetAttribute(kNameSpaceID_RDF, kResourceAtom, uri))) {            NS_ERROR("severe error occured retrieving attribute");            return rv;        }        // Set its value, if we know it.        if (rv == NS_CONTENT_ATTR_HAS_VALUE) {            // First construct a property resource from the URI...            nsCOMPtr<nsIRDFResource> property;            if (NS_FAILED(gRDFService->GetUnicodeResource(uri, getter_AddRefs(property)))) {                NS_ERROR("unable to construct resource for xul:treecell");                return rv; // XXX fatal            }            // ...then query the RDF back-end            nsCOMPtr<nsIRDFNode> value;            rv = mDB->GetTarget(treeItemResource,                                property,                                PR_TRUE,                                getter_AddRefs(value));            if (rv == NS_RDF_NO_VALUE) {                // There was no value for this. It'll have to get set                // later, when an OnAssert() comes in (if it even has                // a value at all...)            }            else if (NS_FAILED(rv)) {                NS_ERROR("error getting cell's value");                return rv; // XXX something serious happened            }            else {                // Attach a plain old text node: nothing fancy. Here's                // where we'd do wacky stuff like pull in an icon or                // whatever.                if (NS_FAILED(rv = nsRDFContentUtils::AttachTextNode(textParent, value))) {                    NS_ERROR("unable to attach text node to xul:treecell");                    return rv;                }            }        }        ++cellIndex;    }    return NS_OK;}