本文整理汇总了C++中nsIRDFService::GetLiteral方法的典型用法代码示例。如果您正苦于以下问题:C++ nsIRDFService::GetLiteral方法的具体用法?C++ nsIRDFService::GetLiteral怎么用?C++ nsIRDFService::GetLiteral使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsIRDFService
的用法示例。
在下文中一共展示了nsIRDFService::GetLiteral方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
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;
}
示例2: propertyStr
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;
}
示例3: switch
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;
}
}