nsAutoString itemName;   if (aItemType == kNC_Bookmark || aItemType == kNC_Folder) { nsCOMPtr<nsIRDFNode> nameNode; getArgumentN(aArguments, kNC_Name, kParentArgumentIndex, getter_AddRefs(nameNode)); nsCOMPtr<nsIRDFLiteral> nameLiteral; nameLiteral = do_QueryInterface(nameNode); if (nameLiteral) { const PRUnichar* uName = nsnull; nameLiteral->GetValueConst(&uName); if (uName) itemName = uName; } }
if (objType == kNC_Bookmark) { newName = "New Bookmark"; } else if (objType == kNC_Folder) { if (NS_FAILED(rv = gRDFC->MakeSeq(mInner, newElement, nsnull))) return(rv);
nsBookmarksService::insertBookmarkItem(nsIRDFResource *aRelativeNode,                                        nsISupportsArray *aArguments,                                        nsIRDFResource *aItemType){    nsresult rv;    const PRInt32 kParentArgumentIndex = 0;      nsCOMPtr<nsIRDFResource> rParent;    if (aRelativeNode == kNC_BookmarksRoot)        rParent = aRelativeNode;    else    {        nsCOMPtr<nsIRDFNode> parentNode;        rv = getArgumentN(aArguments, kNC_Parent, kParentArgumentIndex, getter_AddRefs(parentNode));        if (NS_FAILED(rv)) return rv;        rParent = do_QueryInterface(parentNode, &rv);        if (NS_FAILED(rv)) return rv;    }    nsCOMPtr<nsIRDFContainer> container(do_CreateInstance("@mozilla.org/rdf/container;1", &rv));    if (NS_FAILED(rv)) return rv;    rv = container->Init(this, rParent);    if (NS_FAILED(rv)) return rv;    PRInt32 relNodeIdx = 0;    if (aRelativeNode != kNC_BookmarksRoot) {        // Find the position of the relative node, so we can create this item         // adjacent to it.        rv = container->IndexOf(aRelativeNode, &relNodeIdx);        if (NS_FAILED(rv)) return rv;        // If the item isn't in the container, just append to the container.        if (relNodeIdx == -1) {            rv = container->GetCount(&relNodeIdx);            if (NS_FAILED(rv)) return rv;        }    }    nsAutoString itemName;      // If a creation name was supplied, use it.     if (aItemType == kNC_Bookmark || aItemType == kNC_Folder) {        nsCOMPtr<nsIRDFNode> nameNode;        getArgumentN(aArguments, kNC_Name, kParentArgumentIndex, getter_AddRefs(nameNode));        nsCOMPtr<nsIRDFLiteral> nameLiteral;        nameLiteral = do_QueryInterface(nameNode);        if (nameLiteral) {            const PRUnichar* uName = nsnull;            nameLiteral->GetValueConst(&uName);            if (uName)                 itemName = uName;        }    }    if (itemName.IsEmpty())    {        // Retrieve a default name from the bookmark properties file.        if (aItemType == kNC_Bookmark)             getLocaleString("NewBookmark", itemName);        else if (aItemType == kNC_Folder)             getLocaleString("NewFolder", itemName);    }    nsCOMPtr<nsIRDFResource> newResource;      // Retrieve the URL from the arguments list.     if (aItemType == kNC_Bookmark || aItemType == kNC_Folder)    {        nsCOMPtr<nsIRDFNode> urlNode;        getArgumentN(aArguments, kNC_URL, kParentArgumentIndex, getter_AddRefs(urlNode));        nsCOMPtr<nsIRDFLiteral> bookmarkURILiteral(do_QueryInterface(urlNode));        if (bookmarkURILiteral)        {            const PRUnichar* uURL = nsnull;            bookmarkURILiteral->GetValueConst(&uURL);            if (uURL)            {                rv = gRDF->GetUnicodeResource(nsDependentString(uURL), getter_AddRefs(newResource));                if (NS_FAILED(rv)) return rv;            }        }    }    if (!newResource)    {        // We're a folder, or some other type of anonymous resource.        rv = gRDF->GetAnonymousResource(getter_AddRefs(newResource));        if (NS_FAILED(rv)) return rv;    }    if (aItemType == kNC_Folder)    {        // Make Sequences for Folders.        rv = gRDFC->MakeSeq(mInner, newResource, nsnull);        if (NS_FAILED(rv)) return rv;    }    // Assert Name arc    if (!itemName.IsEmpty())    {        nsCOMPtr<nsIRDFLiteral> nameLiteral;        rv = gRDF->GetLiteral(itemName.get(), getter_AddRefs(nameLiteral));        if (NS_FAILED(rv)) return rv;        rv = mInner->Assert(newResource, kNC_Name, nameLiteral, PR_TRUE);        if (NS_FAILED(rv)) return rv;    }    // Assert type arc    rv = mInner->Assert(newResource, kRDF_type, aItemType, PR_TRUE);    if (NS_FAILED(rv)) return rv;    // XXX - investigate asserting date as a resource with a raw date value for    //       lookup, and a Name arc with a pretty display name, e.g. "Saturday"      // Convert the current date/time from microseconds (PRTime) to seconds.    nsCOMPtr<nsIRDFDate> dateLiteral;    rv = gRDF->GetDateLiteral(PR_Now(), getter_AddRefs(dateLiteral));    if (NS_FAILED(rv)) return rv;    rv = mInner->Assert(newResource, kNC_BookmarkAddDate, dateLiteral, PR_TRUE);    if (NS_FAILED(rv)) return rv;    // Add to container.     rv = container->InsertElementAt(newResource, !relNodeIdx ? 1 : relNodeIdx, PR_TRUE);      return rv;}