nsresult RDFContentSinkImpl::ReinitContainer(nsIRDFResource* aContainerType, nsIRDFResource* aContainer) { // Mega-kludge to deal with the fact that Make[Seq|Alt|Bag] is // idempotent, and as such, containers will have state (e.g., // RDF:nextVal) maintained in the graph across loads. This // re-initializes each container's RDF:nextVal to '1', and 'marks' // the container as such. nsresult rv; nsCOMPtr<nsIRDFLiteral> one; rv = gRDFService->GetLiteral(NS_LITERAL_STRING("1").get(), getter_AddRefs(one)); if (NS_FAILED(rv)) return rv; // Re-initialize the 'nextval' property nsCOMPtr<nsIRDFNode> nextval; rv = mDataSource->GetTarget(aContainer, kRDF_nextVal, true, getter_AddRefs(nextval)); if (NS_FAILED(rv)) return rv; rv = mDataSource->Change(aContainer, kRDF_nextVal, nextval, one); if (NS_FAILED(rv)) return rv; // Re-mark as a container. XXX should be kRDF_type rv = mDataSource->Assert(aContainer, kRDF_instanceOf, aContainerType, true); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to mark container as such"); if (NS_FAILED(rv)) return rv; return NS_OK; }
nsresult RDFContentSinkImpl::AddProperties(const PRUnichar** aAttributes, nsIRDFResource* aSubject, PRInt32* aCount) { if (aCount) *aCount = 0; nsCOMPtr<nsIAtom> localName; for (; *aAttributes; aAttributes += 2) { const nsDependentSubstring& nameSpaceURI = SplitExpatName(aAttributes[0], getter_AddRefs(localName)); // skip 'xmlns' directives, these are "meta" information if (nameSpaceURI.EqualsLiteral("http://www.w3.org/2000/xmlns/")) { continue; } // skip `about', `ID', `resource', and 'nodeID' attributes (either with or // without the `rdf:' prefix); these are all "special" and // should've been dealt with by the caller. if (localName == kAboutAtom || localName == kIdAtom || localName == kResourceAtom || localName == kNodeIdAtom) { if (nameSpaceURI.IsEmpty() || nameSpaceURI.EqualsLiteral(RDF_NAMESPACE_URI)) continue; } // Skip `parseType', `RDF:parseType', and `NC:parseType'. This // is meta-information that will be handled in SetParseMode. if (localName == kParseTypeAtom) { if (nameSpaceURI.IsEmpty() || nameSpaceURI.EqualsLiteral(RDF_NAMESPACE_URI) || nameSpaceURI.EqualsLiteral(NC_NAMESPACE_URI)) { continue; } } const char* attrName; localName->GetUTF8String(&attrName); NS_ConvertUTF16toUTF8 propertyStr(nameSpaceURI); propertyStr.Append(attrName); // Add the assertion to RDF nsCOMPtr<nsIRDFResource> property; gRDFService->GetResource(propertyStr, getter_AddRefs(property)); nsCOMPtr<nsIRDFLiteral> target; gRDFService->GetLiteral(aAttributes[1], getter_AddRefs(target)); mDataSource->Assert(aSubject, property, target, PR_TRUE); } return NS_OK; }
void RDFContentSinkImpl::ParseText(nsIRDFNode **aResult) { // XXXwaterson wasteful, but we'd need to make a copy anyway to be // able to call nsIRDFService::Get[Resource|Literal|...](). nsAutoString value; value.Append(mText, mTextLength); value.Trim(" \t\n\r"); switch (mParseMode) { case eRDFContentSinkParseMode_Literal: { nsIRDFLiteral *result; gRDFService->GetLiteral(value.get(), &result); *aResult = result; } break; case eRDFContentSinkParseMode_Resource: { nsIRDFResource *result; gRDFService->GetUnicodeResource(value, &result); *aResult = result; } break; case eRDFContentSinkParseMode_Int: { PRInt32 i, err; i = value.ToInteger(&err); nsIRDFInt *result; gRDFService->GetIntLiteral(i, &result); *aResult = result; } break; case eRDFContentSinkParseMode_Date: { PRTime t = rdf_ParseDate(nsDependentCString(NS_LossyConvertUTF16toASCII(value).get(), value.Length())); nsIRDFDate *result; gRDFService->GetDateLiteral(t, &result); *aResult = result; } break; default: NS_NOTREACHED("unknown parse type"); break; } }