NS_ASSERTION(rv != NS_RDF_NO_VALUE, "arc-out with no target: fix your arcs-out cursor!");
RDFMenuBuilderImpl::AddWidgetItem(nsIContent* aElement,                                  nsIRDFResource* aProperty,                                  nsIRDFResource* aValue,                                  PRInt32 naturalOrderPos){    nsresult rv;    nsCOMPtr<nsIContent> menuParent;    menuParent = dont_QueryInterface(aElement);    if (!IsItemOrFolder(aElement) && !IsWidgetInsertionRootElement(aElement))    {        NS_ERROR("Can't add something here!");        return NS_ERROR_UNEXPECTED;    }    // Find out if we're a container or not.    PRBool markAsContainer = IsContainer(aElement, aValue);    nsCOMPtr<nsIAtom> itemAtom;        // Figure out what atom to use based on whether or not we're a container    // or leaf    if (markAsContainer)    {        // We're a menu element        GetWidgetFolderAtom(getter_AddRefs(itemAtom));    }    else    {        // We're a menuitem element        GetWidgetItemAtom(getter_AddRefs(itemAtom));    }    // Create the <xul:menuitem> element    nsCOMPtr<nsIContent> menuItem;    if (NS_FAILED(rv = CreateResourceElement(kNameSpaceID_XUL,                                             itemAtom,                                             aValue,                                             getter_AddRefs(menuItem))))        return rv;    // Add the new menu item to the <xul:menu> element.    menuParent->AppendChildTo(menuItem, PR_TRUE);    // Add miscellaneous attributes by iterating _all_ of the    // properties out of the resource.    // XXX Per Bug 3367, this'll have to be fixed.    nsCOMPtr<nsISimpleEnumerator> arcs;    rv = mDB->ArcLabelsOut(aValue, getter_AddRefs(arcs));    NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get arcs out");    if (NS_FAILED(rv)) return rv;    while (1) {        PRBool hasMore;        rv = arcs->HasMoreElements(&hasMore);        if (NS_FAILED(rv)) return rv;        if (! hasMore)            break;        nsCOMPtr<nsISupports> isupports;        rv = arcs->GetNext(getter_AddRefs(isupports));        NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get cursor value");        if (NS_FAILED(rv)) return rv;        nsCOMPtr<nsIRDFResource> property = do_QueryInterface(isupports);        // Ignore properties that are used to indicate containment        if (IsContainmentProperty(aElement, property))            continue;        PRInt32 nameSpaceID;        nsCOMPtr<nsIAtom> tag;        if (NS_FAILED(rv = mDocument->SplitProperty(property, &nameSpaceID, getter_AddRefs(tag)))) {            NS_ERROR("unable to split property");            return rv;        }        nsCOMPtr<nsIRDFNode> value;        if (NS_FAILED(rv = mDB->GetTarget(aValue, property, PR_TRUE, getter_AddRefs(value)))) {            NS_ERROR("unable to get target");            return rv;        }        NS_ASSERTION(rv != NS_RDF_NO_VALUE, "arc-out with no target: fix your arcs-out cursor!");        if (rv == NS_RDF_NO_VALUE)            continue;        nsAutoString s;        rv = nsRDFContentUtils::GetTextForNode(value, s);        if (NS_FAILED(rv)) return rv;        rv = menuItem->SetAttribute(nameSpaceID, tag, s, PR_FALSE);        if (NS_FAILED(rv)) return rv;        // XXX This should go away and just be determined dynamically;        // e.g., by setting an attribute on the "xul:menu" tag        nsAutoString tagStr;        tag->ToString(tagStr);        if (tagStr.EqualsIgnoreCase("name")) {            // Hack to ensure that we add in a lowercase name attribute also.            menuItem->SetAttribute(kNameSpaceID_None, kNameAtom, s, PR_FALSE);        }    }    // XXX: This is a hack until the menu folks get their act together.    menuItem->SetAttribute(kNameSpaceID_None, kOpenAtom, "true", PR_FALSE);    // Finally, mark this as a "container" so that we know to    // recursively generate kids if they're asked for.    if (markAsContainer == PR_TRUE)    {        // Finally, mark this as a "container" so that we know to        // recursively generate kids if they're asked for.        if (NS_FAILED(rv = menuItem->SetAttribute(kNameSpaceID_RDF, kContainerAtom, "true", PR_FALSE)))            return rv;    }    return NS_OK;}