if (! contentsGenerated.EqualsIgnoreCase("true"))
if (! contentsGenerated.Equals("true"))
RDFXULBuilderImpl::OnChange(nsIRDFResource* aSource,                            nsIRDFResource* aProperty,                            nsIRDFNode* aOldTarget,                            nsIRDFNode* aNewTarget){    NS_PRECONDITION(mDocument != nsnull, "not initialized");    if (! mDocument)        return NS_ERROR_NOT_INITIALIZED;    if (mPermitted && mPermitted != aNewTarget)        return NS_OK;    // Stuff that we can ignore outright    // XXX is this the best place to put it???    if (aProperty == kRDF_nextVal)        return NS_OK;    nsresult rv;    {        // Make sure it's a XUL node we're talking about        PRBool isXULElement;        rv = mDB->HasAssertion(aSource, kRDF_instanceOf, kXUL_element, PR_TRUE, &isXULElement);        if (NS_FAILED(rv)) return rv;        if (! isXULElement)            return NS_OK;    }#ifdef PR_LOGGING    if (PR_LOG_TEST(gLog, PR_LOG_DEBUG)) {        nsXPIDLCString source;        aSource->GetValue(getter_Copies(source));        nsXPIDLCString property;        aProperty->GetValue(getter_Copies(property));        nsAutoString oldTargetStr;        nsRDFContentUtils::GetTextForNode(aOldTarget, oldTargetStr);        nsAutoString newTargetStr;        nsRDFContentUtils::GetTextForNode(aNewTarget, newTargetStr);        char* oldTargetCStr = oldTargetStr.ToNewCString();        char* newTargetCStr = newTargetStr.ToNewCString();        PR_LOG(gLog, PR_LOG_DEBUG, ("xulbuilder on-change"));        PR_LOG(gLog, PR_LOG_DEBUG, ("    (%s)",   (const char*) source));        PR_LOG(gLog, PR_LOG_DEBUG, ("  --[%s]--", (const char*) property));        PR_LOG(gLog, PR_LOG_DEBUG, ("  -X(%s)",   oldTargetCStr));        PR_LOG(gLog, PR_LOG_DEBUG, ("  ->(%s)",   newTargetCStr));        nsCRT::free(oldTargetCStr);        nsCRT::free(newTargetCStr);    }#endif    nsCOMPtr<nsISupportsArray> elements;    rv = NS_NewISupportsArray(getter_AddRefs(elements));    if (NS_FAILED(rv)) return rv;    // Find all the elements in the content model that correspond to    // aSource: for each, we'll try to build XUL children if    // appropriate.    rv = mDocument->GetElementsForResource(aSource, elements);    NS_ASSERTION(NS_SUCCEEDED(rv), "unable to retrieve elements from resource");    if (NS_FAILED(rv)) return rv;    PRUint32 cnt = 0;    rv = elements->Count(&cnt);    NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed");    for (PRInt32 i = cnt - 1; i >= 0; --i) {        nsISupports* isupports = elements->ElementAt(i);        nsCOMPtr<nsIContent> element( do_QueryInterface(isupports) );        NS_IF_RELEASE(isupports);        // XXX Make sure that the element we're looking at is really        // an element generated by this content-model builder?        PRBool isOrdinal;        rv = gRDFContainerUtils->IsOrdinalProperty(aProperty, &isOrdinal);        if (NS_FAILED(rv)) return rv;        if (isOrdinal) {            // It's a child node. If the contents of aElement _haven't_            // yet been generated, then just ignore the assertion. We do            // this because we know that _eventually_ the contents will be            // generated (via CreateContents()) when somebody asks for            // them later.            nsAutoString contentsGenerated;            rv = element->GetAttribute(kNameSpaceID_None,                                       kXULContentsGeneratedAtom,                                       contentsGenerated);            NS_ASSERTION(NS_SUCCEEDED(rv), "severe problem trying to get attribute");            if (NS_FAILED(rv)) return rv;            if (rv == NS_CONTENT_ATTR_NOT_THERE || rv == NS_CONTENT_ATTR_NO_VALUE)                continue;            if (! contentsGenerated.EqualsIgnoreCase("true"))                continue;            // Okay, it's a "live" element, so go ahead and insert the            // new element under the parent node according to the            // ordinal.            PRInt32 indx;            rv = gRDFContainerUtils->OrdinalResourceToIndex(aProperty, &indx);            if (NS_FAILED(rv)) return rv;            nsCOMPtr<nsINameSpace> containingNameSpace;            rv = GetContainingNameSpace(element, getter_AddRefs(containingNameSpace));            if (NS_FAILED(rv)) return rv;            PRInt32 count;            rv = element->ChildCount(count);            if (NS_FAILED(rv)) return rv;            // "indx - 1" because RDF containers are 1-indexed.            rv = ReplaceChildAt(containingNameSpace, element, aNewTarget, indx - 1);            NS_ASSERTION(NS_SUCCEEDED(rv), "problem inserting new child into content model");            if (NS_FAILED(rv)) return rv;        }        else if (aProperty == kXUL_tag) {            // We shouldn't ever see this: if we do, there ain't much we            // can do.            PR_LOG(gLog, PR_LOG_ALWAYS,                   ("xulbuilder on-change: attempt to change tag type after-the-fact ignored"));        }        else if (IsAttributeProperty(aProperty)) {            // Add the thing as a vanilla attribute to the element.            rv = AddAttribute(element, aProperty, aNewTarget);            NS_ASSERTION(NS_SUCCEEDED(rv), "unable to add attribute to the element");            if (NS_FAILED(rv)) return rv;        }    }    return NS_OK;}