mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 20:05:49 +00:00
Land RDF_19990426_BRANCH, which extracted some static C++ routines for manipulating RDF containers into bona fide interfaces.
This commit is contained in:
parent
3f3dced3eb
commit
b6bd7f337e
@ -72,16 +72,6 @@
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, child);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Columns);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Column);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Folder);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Title);
|
||||
|
||||
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, child);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID);
|
||||
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
|
||||
static NS_DEFINE_IID(kINameSpaceManagerIID, NS_INAMESPACEMANAGER_IID);
|
||||
@ -94,6 +84,7 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID);
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID);
|
||||
|
||||
static NS_DEFINE_IID(kXULSortServiceCID, NS_XULSORTSERVICE_CID);
|
||||
static NS_DEFINE_IID(kIXULSortServiceIID, NS_IXULSORTSERVICE_IID);
|
||||
@ -115,6 +106,7 @@ PRInt32 RDFGenericBuilderImpl::kNameSpaceID_RDF;
|
||||
PRInt32 RDFGenericBuilderImpl::kNameSpaceID_XUL;
|
||||
|
||||
nsIRDFService* RDFGenericBuilderImpl::gRDFService;
|
||||
nsIRDFContainerUtils* RDFGenericBuilderImpl::gRDFContainerUtils;
|
||||
nsINameSpaceManager* RDFGenericBuilderImpl::gNameSpaceManager;
|
||||
|
||||
nsIRDFResource* RDFGenericBuilderImpl::kNC_Title;
|
||||
@ -178,27 +170,21 @@ static const char kRDFNameSpaceURI[]
|
||||
kIRDFServiceIID,
|
||||
(nsISupports**) &gRDFService);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("couldnt' get RDF service");
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "Title", &kNC_Title);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "child", &kNC_child);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "Column", &kNC_Column);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "Folder", &kNC_Folder);
|
||||
gRDFService->GetResource(RDF_NAMESPACE_URI "child", &kRDF_child);
|
||||
}
|
||||
|
||||
rv = nsServiceManager::GetService(kXULSortServiceCID,
|
||||
kIXULSortServiceIID, (nsISupports**) &XULSortService);
|
||||
rv = nsServiceManager::GetService(kRDFContainerUtilsCID,
|
||||
nsIRDFContainerUtils::GetIID(),
|
||||
(nsISupports**) &gRDFContainerUtils);
|
||||
|
||||
NS_VERIFY(NS_SUCCEEDED(gRDFService->GetResource(kURINC_Title, &kNC_Title)),
|
||||
"couldn't get resource");
|
||||
|
||||
NS_VERIFY(NS_SUCCEEDED(gRDFService->GetResource(kURINC_child, &kNC_child)),
|
||||
"couldn't get resource");
|
||||
|
||||
NS_VERIFY(NS_SUCCEEDED(gRDFService->GetResource(kURINC_Column, &kNC_Column)),
|
||||
"couldn't get resource");
|
||||
|
||||
NS_VERIFY(NS_SUCCEEDED(gRDFService->GetResource(kURINC_Folder, &kNC_Folder)),
|
||||
"couldn't get resource");
|
||||
|
||||
NS_VERIFY(NS_SUCCEEDED(gRDFService->GetResource(kURIRDF_child, &kRDF_child)),
|
||||
"couldn't get resource");
|
||||
rv = nsServiceManager::GetService(kXULSortServiceCID,
|
||||
kIXULSortServiceIID,
|
||||
(nsISupports**) &XULSortService);
|
||||
|
||||
}
|
||||
++gRefCnt;
|
||||
@ -1243,10 +1229,16 @@ RDFGenericBuilderImpl::IsContainmentProperty(nsIContent* aElement, nsIRDFResourc
|
||||
{
|
||||
// XXX is this okay to _always_ treat ordinal properties as tree
|
||||
// properties? Probably not...
|
||||
if (rdf_IsOrdinalProperty(aProperty))
|
||||
nsresult rv;
|
||||
|
||||
PRBool isOrdinal;
|
||||
rv = gRDFContainerUtils->IsOrdinalProperty(aProperty, &isOrdinal);
|
||||
if (NS_FAILED(rv))
|
||||
return PR_FALSE;
|
||||
|
||||
if (isOrdinal)
|
||||
return PR_TRUE;
|
||||
|
||||
nsresult rv;
|
||||
nsXPIDLCString propertyURI;
|
||||
if (NS_FAILED(rv = aProperty->GetValue( getter_Copies(propertyURI) ))) {
|
||||
NS_ERROR("unable to get property URI");
|
||||
|
@ -73,11 +73,7 @@ GetXULElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
nsIRDFResource* prop;
|
||||
if (NS_OK == a->GetResource(&prop)) {
|
||||
// get the js object
|
||||
#ifdef XPIDL_JS_STUBS
|
||||
*vp = OBJECT_TO_JSVAL(nsIRDFResource::GetJSObject(cx, prop));
|
||||
#else
|
||||
nsJSUtils::nsConvertXPCObjectToJSVal(prop, nsIRDFResource::GetIID(), cx, vp);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
|
@ -67,11 +67,7 @@ GetXULTreeElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
nsIRDFCompositeDataSource* prop;
|
||||
if (NS_OK == a->GetDatabase(&prop)) {
|
||||
// get the js object
|
||||
#ifdef XPIDL_JS_STUBS
|
||||
*vp = OBJECT_TO_JSVAL(nsIRDFCompositeDataSource::GetJSObject(cx, prop));
|
||||
#else
|
||||
nsJSUtils::nsConvertXPCObjectToJSVal(prop, nsIRDFCompositeDataSource::GetIID(), cx, vp);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
@ -108,9 +104,8 @@ SetXULTreeElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
case XULTREEELEMENT_DATABASE:
|
||||
{
|
||||
nsIRDFCompositeDataSource* prop;
|
||||
if (PR_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&prop,
|
||||
kIRDFCompositeDataSourceIID, "RDFCompositeDataSource",
|
||||
cx, *vp)) {
|
||||
if (PR_FALSE == nsJSUtils::nsConvertJSValToXPCObject((nsISupports **) &prop,
|
||||
kIRDFCompositeDataSourceIID, cx, *vp)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,8 @@ CPPSRCS = \
|
||||
nsDefaultResourceFactory.cpp \
|
||||
nsInMemoryDataSource.cpp \
|
||||
nsRDFContentSink.cpp \
|
||||
nsRDFContainer.cpp \
|
||||
nsRDFContainerUtils.cpp \
|
||||
nsRDFParserUtils.cpp \
|
||||
nsRDFService.cpp \
|
||||
nsRDFXMLDataSource.cpp \
|
||||
|
@ -28,6 +28,8 @@ CPP_OBJS=\
|
||||
.\$(OBJDIR)\nsDefaultResourceFactory.obj \
|
||||
.\$(OBJDIR)\nsInMemoryDataSource.obj \
|
||||
.\$(OBJDIR)\nsRDFContentSink.obj \
|
||||
.\$(OBJDIR)\nsRDFContainer.obj \
|
||||
.\$(OBJDIR)\nsRDFContainerUtils.obj \
|
||||
.\$(OBJDIR)\nsRDFParserUtils.obj \
|
||||
.\$(OBJDIR)\nsRDFService.obj \
|
||||
.\$(OBJDIR)\nsRDFXMLDataSource.obj \
|
||||
|
@ -48,8 +48,9 @@
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -140,15 +141,33 @@ ContainerEnumeratorImpl::HasMoreElements(PRBool* aResult)
|
||||
// Otherwise, we need to grovel
|
||||
|
||||
// Figure out the upper bound so we'll know when we're done.
|
||||
PRInt32 count;
|
||||
rv = rdf_ContainerGetCount(mDataSource, mContainer, &count);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get upper bound on container");
|
||||
nsCOMPtr<nsIRDFNode> nextValNode;
|
||||
rv = mDataSource->GetTarget(mContainer, kRDF_nextVal, PR_TRUE, getter_AddRefs(nextValNode));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (rv != NS_OK)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsCOMPtr<nsIRDFLiteral> nextVal = do_QueryInterface(nextValNode);
|
||||
if (! nextVal)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsXPIDLString nextValStr;
|
||||
rv = nextVal->GetValue(getter_Copies(nextValStr));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRInt32 err;
|
||||
PRInt32 count = nsAutoString(nextValStr).ToInteger(&err);
|
||||
if (NS_FAILED(err))
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
// Now iterate through each index.
|
||||
while (mNextIndex < count) {
|
||||
if (! mCurrent) {
|
||||
NS_WITH_SERVICE(nsIRDFContainerUtils, rdfc, kRDFContainerUtilsCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = rdf_IndexToOrdinalResource(mNextIndex, getter_AddRefs(mOrdinalProperty));
|
||||
rv = rdfc->IndexToOrdinalResource(mNextIndex, getter_AddRefs(mOrdinalProperty));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = mDataSource->GetTargets(mContainer, mOrdinalProperty, PR_TRUE, &mCurrent);
|
||||
@ -226,12 +245,6 @@ NS_NewContainerEnumerator(nsIRDFDataSource* aDataSource,
|
||||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
PRBool isContainer = rdf_IsContainer(aDataSource, aContainer);
|
||||
|
||||
NS_ASSERTION(isContainer, "not a container");
|
||||
if (! isContainer)
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
|
||||
ContainerEnumeratorImpl* result = new ContainerEnumeratorImpl(aDataSource, aContainer);
|
||||
if (! result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
@ -48,6 +48,7 @@
|
||||
#include "nsIContentSink.h"
|
||||
#include "nsINameSpace.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIRDFContainer.h"
|
||||
#include "nsIRDFContentSink.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFService.h"
|
||||
@ -84,6 +85,7 @@ static NS_DEFINE_IID(kIXMLContentSinkIID, NS_IXMLCONTENT_SINK_IID);
|
||||
static NS_DEFINE_IID(kIRDFContentSinkIID, NS_IRDFCONTENTSINK_IID);
|
||||
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID);
|
||||
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
@ -169,6 +171,7 @@ protected:
|
||||
// pseudo constants
|
||||
static PRInt32 gRefCnt;
|
||||
static nsIRDFService* gRDFService;
|
||||
static nsIRDFContainerUtils* gRDFContainerUtils;
|
||||
static nsIRDFResource* kRDF_type;
|
||||
|
||||
static nsIAtom* kAboutAtom;
|
||||
@ -246,6 +249,7 @@ protected:
|
||||
|
||||
PRInt32 RDFContentSinkImpl::gRefCnt = 0;
|
||||
nsIRDFService* RDFContentSinkImpl::gRDFService;
|
||||
nsIRDFContainerUtils* RDFContentSinkImpl::gRDFContainerUtils;
|
||||
nsIRDFResource* RDFContentSinkImpl::kRDF_type;
|
||||
|
||||
nsIAtom* RDFContentSinkImpl::kAboutAtom;
|
||||
@ -288,6 +292,11 @@ RDFContentSinkImpl::RDFContentSinkImpl()
|
||||
rv = gRDFService->GetResource(RDF_NAMESPACE_URI "type", &kRDF_type);
|
||||
}
|
||||
|
||||
|
||||
rv = nsServiceManager::GetService(kRDFContainerUtilsCID,
|
||||
nsIRDFContainerUtils::GetIID(),
|
||||
(nsISupports**) &gRDFContainerUtils);
|
||||
|
||||
kAboutAtom = NS_NewAtom("about");
|
||||
kIdAtom = NS_NewAtom("ID");
|
||||
kAboutEachAtom = NS_NewAtom("aboutEach");
|
||||
@ -363,6 +372,12 @@ RDFContentSinkImpl::~RDFContentSinkImpl()
|
||||
gRDFService = nsnull;
|
||||
}
|
||||
|
||||
|
||||
if (gRDFContainerUtils) {
|
||||
nsServiceManager::ReleaseService(kRDFContainerUtilsCID, gRDFContainerUtils);
|
||||
gRDFContainerUtils = nsnull;
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(kRDF_type);
|
||||
|
||||
NS_IF_RELEASE(kAboutAtom);
|
||||
@ -819,9 +834,10 @@ RDFContentSinkImpl::FlushText(PRBool aCreateTextNode, PRBool* aDidFlush)
|
||||
|
||||
nsIRDFLiteral* literal;
|
||||
if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(value.GetUnicode(), &literal))) {
|
||||
rv = rdf_ContainerAppendElement(mDataSource,
|
||||
GetContextElement(1),
|
||||
literal);
|
||||
nsCOMPtr<nsIRDFContainer> container;
|
||||
NS_NewRDFContainer(getter_AddRefs(container));
|
||||
container->Init(mDataSource, GetContextElement(1));
|
||||
container->AppendElement(literal);
|
||||
NS_RELEASE(literal);
|
||||
}
|
||||
} break;
|
||||
@ -1161,7 +1177,10 @@ RDFContentSinkImpl::OpenObject(const nsIParserNode& aNode)
|
||||
// member/property.
|
||||
switch (mState) {
|
||||
case eRDFContentSinkState_InMemberElement: {
|
||||
rdf_ContainerAppendElement(mDataSource, GetContextElement(1), rdfResource);
|
||||
nsCOMPtr<nsIRDFContainer> container;
|
||||
NS_NewRDFContainer(getter_AddRefs(container));
|
||||
container->Init(mDataSource, GetContextElement(1));
|
||||
container->AppendElement(rdfResource);
|
||||
} break;
|
||||
|
||||
case eRDFContentSinkState_InPropertyElement: {
|
||||
@ -1189,17 +1208,17 @@ RDFContentSinkImpl::OpenObject(const nsIParserNode& aNode)
|
||||
}
|
||||
else if (tag.get() == kBagAtom) {
|
||||
// it's a bag container
|
||||
rdf_MakeBag(mDataSource, rdfResource);
|
||||
gRDFContainerUtils->MakeBag(mDataSource, rdfResource, nsnull);
|
||||
mState = eRDFContentSinkState_InContainerElement;
|
||||
}
|
||||
else if (tag.get() == kSeqAtom) {
|
||||
// it's a seq container
|
||||
rdf_MakeSeq(mDataSource, rdfResource);
|
||||
gRDFContainerUtils->MakeSeq(mDataSource, rdfResource, nsnull);
|
||||
mState = eRDFContentSinkState_InContainerElement;
|
||||
}
|
||||
else if (tag.get() == kAltAtom) {
|
||||
// it's an alt container
|
||||
rdf_MakeAlt(mDataSource, rdfResource);
|
||||
gRDFContainerUtils->MakeAlt(mDataSource, rdfResource, nsnull);
|
||||
mState = eRDFContentSinkState_InContainerElement;
|
||||
}
|
||||
else {
|
||||
@ -1320,7 +1339,10 @@ RDFContentSinkImpl::OpenMember(const nsIParserNode& aNode)
|
||||
if (NS_SUCCEEDED(rv = GetResourceAttribute(aNode, &resource))) {
|
||||
// Okay, this node has an RDF:resource="..." attribute. That
|
||||
// means that it's a "referenced item," as covered in [6.29].
|
||||
rv = rdf_ContainerAppendElement(mDataSource, container, resource);
|
||||
nsCOMPtr<nsIRDFContainer> c;
|
||||
NS_NewRDFContainer(getter_AddRefs(c));
|
||||
c->Init(mDataSource, container);
|
||||
c->AppendElement(resource);
|
||||
|
||||
// XXX Technically, we should _not_ fall through here and push
|
||||
// the element onto the stack: this is supposed to be a closed
|
||||
@ -1331,7 +1353,7 @@ RDFContentSinkImpl::OpenMember(const nsIParserNode& aNode)
|
||||
|
||||
// Change state. Pushing a null context element is a bit weird,
|
||||
// but the idea is that there really is _no_ context "property".
|
||||
// The contained element will use rdf_ContainerAppendElement() to add
|
||||
// The contained element will use nsIRDFContainer::AppendElement() to add
|
||||
// the element to the container, which requires only the container
|
||||
// and the element to be added.
|
||||
PushContext(nsnull, mState);
|
||||
|
@ -48,6 +48,7 @@
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "nsIParser.h"
|
||||
#include "nsIRDFContainerUtils.h"
|
||||
#include "nsIRDFContentSink.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFService.h"
|
||||
@ -87,6 +88,7 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID);
|
||||
static NS_DEFINE_CID(kParserCID, NS_PARSER_IID); // XXX
|
||||
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
|
||||
static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID);
|
||||
static NS_DEFINE_CID(kRDFContentSinkCID, NS_RDFCONTENTSINK_CID);
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
static NS_DEFINE_CID(kWellFormedDTDCID, NS_WELLFORMEDDTD_CID);
|
||||
@ -176,6 +178,9 @@ protected:
|
||||
static PRInt32 gRefCnt;
|
||||
static nsIRDFResource* kRDF_instanceOf;
|
||||
static nsIRDFResource* kRDF_nextVal;
|
||||
static nsIRDFResource* kRDF_Bag;
|
||||
static nsIRDFResource* kRDF_Seq;
|
||||
static nsIRDFResource* kRDF_Alt;
|
||||
|
||||
public:
|
||||
RDFXMLDataSourceImpl(void);
|
||||
@ -341,6 +346,9 @@ public:
|
||||
PRInt32 RDFXMLDataSourceImpl::gRefCnt = 0;
|
||||
nsIRDFResource* RDFXMLDataSourceImpl::kRDF_instanceOf;
|
||||
nsIRDFResource* RDFXMLDataSourceImpl::kRDF_nextVal;
|
||||
nsIRDFResource* RDFXMLDataSourceImpl::kRDF_Bag;
|
||||
nsIRDFResource* RDFXMLDataSourceImpl::kRDF_Seq;
|
||||
nsIRDFResource* RDFXMLDataSourceImpl::kRDF_Alt;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -395,6 +403,9 @@ RDFXMLDataSourceImpl::RDFXMLDataSourceImpl(void)
|
||||
|
||||
rv = rdf->GetResource(RDF_NAMESPACE_URI "instanceOf", &kRDF_instanceOf);
|
||||
rv = rdf->GetResource(RDF_NAMESPACE_URI "nextVal", &kRDF_nextVal);
|
||||
rv = rdf->GetResource(RDF_NAMESPACE_URI "Bag", &kRDF_Bag);
|
||||
rv = rdf->GetResource(RDF_NAMESPACE_URI "Seq", &kRDF_Seq);
|
||||
rv = rdf->GetResource(RDF_NAMESPACE_URI "Alt", &kRDF_Alt);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1300,13 +1311,13 @@ static const char kRDFAlt[] = "RDF:Alt";
|
||||
// Decide if it's a sequence, bag, or alternation, and print the
|
||||
// appropriate tag-open sequence
|
||||
|
||||
if (rdf_IsBag(mInner, aContainer)) {
|
||||
if (rdf_IsA(mInner, aContainer, kRDF_Bag)) {
|
||||
tag = kRDFBag;
|
||||
}
|
||||
else if (rdf_IsSeq(mInner, aContainer)) {
|
||||
else if (rdf_IsA(mInner, aContainer, kRDF_Seq)) {
|
||||
tag = kRDFSeq;
|
||||
}
|
||||
else if (rdf_IsAlt(mInner, aContainer)) {
|
||||
else if (rdf_IsA(mInner, aContainer, kRDF_Alt)) {
|
||||
tag = kRDFAlt;
|
||||
}
|
||||
else {
|
||||
@ -1346,6 +1357,9 @@ static const char kRDFAlt[] = "RDF:Alt";
|
||||
rv = mInner->ArcLabelsOut(aContainer, getter_AddRefs(arcs));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_WITH_SERVICE(nsIRDFContainerUtils, rdfc, kRDFContainerUtilsCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
while (1) {
|
||||
PRBool hasMore;
|
||||
rv = arcs->HasMoreElements(&hasMore);
|
||||
@ -1360,7 +1374,8 @@ static const char kRDFAlt[] = "RDF:Alt";
|
||||
|
||||
// If it's a membership property, then output a "LI"
|
||||
// tag. Otherwise, output a property.
|
||||
if (rdf_IsOrdinalProperty(property)) {
|
||||
PRBool isOrdinal;
|
||||
if (NS_SUCCEEDED(rdfc->IsOrdinalProperty(property, &isOrdinal)) && isOrdinal) {
|
||||
rv = SerializeMember(aStream, aContainer, property);
|
||||
}
|
||||
else if (property == kRDF_instanceOf) {
|
||||
@ -1476,7 +1491,9 @@ RDFXMLDataSourceImpl::Serialize(nsIOutputStream* aStream)
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
|
||||
if (rdf_IsContainer(mInner, resource)) {
|
||||
if (rdf_IsA(mInner, resource, kRDF_Bag) ||
|
||||
rdf_IsA(mInner, resource, kRDF_Seq) ||
|
||||
rdf_IsA(mInner, resource, kRDF_Alt)) {
|
||||
rv = SerializeContainer(aStream, resource);
|
||||
}
|
||||
else {
|
||||
|
@ -93,100 +93,7 @@ rdf_EnsureRDFService(void)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PRBool
|
||||
rdf_IsOrdinalProperty(nsIRDFResource* aProperty)
|
||||
{
|
||||
nsXPIDLCString propertyStr;
|
||||
if (NS_FAILED(aProperty->GetValue( getter_Copies(propertyStr) )))
|
||||
return PR_FALSE;
|
||||
|
||||
if (PL_strncmp(propertyStr, kRDFNameSpaceURI, sizeof(kRDFNameSpaceURI) - 1) != 0)
|
||||
return PR_FALSE;
|
||||
|
||||
const char* s = propertyStr;
|
||||
s += sizeof(kRDFNameSpaceURI) - 1;
|
||||
if (*s != '_')
|
||||
return PR_FALSE;
|
||||
|
||||
++s;
|
||||
while (*s) {
|
||||
if (*s < '0' || *s > '9')
|
||||
return PR_FALSE;
|
||||
|
||||
++s;
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
rdf_OrdinalResourceToIndex(nsIRDFResource* aOrdinal, PRInt32* aIndex)
|
||||
{
|
||||
nsXPIDLCString ordinalStr;
|
||||
if (NS_FAILED(aOrdinal->GetValue( getter_Copies(ordinalStr) )))
|
||||
return PR_FALSE;
|
||||
|
||||
const char* s = ordinalStr;
|
||||
if (PL_strncmp(s, kRDFNameSpaceURI, sizeof(kRDFNameSpaceURI) - 1) != 0) {
|
||||
NS_ERROR("not an ordinal");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
s += sizeof(kRDFNameSpaceURI) - 1;
|
||||
if (*s != '_') {
|
||||
NS_ERROR("not an ordinal");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
PRInt32 index = 0;
|
||||
|
||||
++s;
|
||||
while (*s) {
|
||||
if (*s < '0' || *s > '9') {
|
||||
NS_ERROR("not an ordinal");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
index *= 10;
|
||||
index += (*s - '0');
|
||||
|
||||
++s;
|
||||
}
|
||||
|
||||
*aIndex = index;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
rdf_IndexToOrdinalResource(PRInt32 aIndex, nsIRDFResource** aOrdinal)
|
||||
{
|
||||
NS_PRECONDITION(aIndex > 0, "illegal value");
|
||||
if (aIndex <= 0)
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
|
||||
// 16 digits should be plenty to hold a decimal version of a
|
||||
// PRInt32.
|
||||
char buf[sizeof(kRDFNameSpaceURI) + 16 + 1];
|
||||
|
||||
PL_strcpy(buf, kRDFNameSpaceURI);
|
||||
buf[sizeof(kRDFNameSpaceURI) - 1] = '_';
|
||||
|
||||
PR_snprintf(buf + sizeof(kRDFNameSpaceURI), 16, "%ld", aIndex);
|
||||
|
||||
nsresult rv;
|
||||
if (NS_FAILED(rv = rdf_EnsureRDFService()))
|
||||
return rv;
|
||||
|
||||
if (NS_FAILED(rv = gRDFService->GetResource(buf, aOrdinal))) {
|
||||
NS_ERROR("unable to get ordinal resource");
|
||||
return rv;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static PRBool
|
||||
PR_IMPLEMENT(PRBool)
|
||||
rdf_IsA(nsIRDFDataSource* aDataSource, nsIRDFResource* aResource, nsIRDFResource* aType)
|
||||
{
|
||||
nsresult rv;
|
||||
@ -201,56 +108,6 @@ rdf_IsA(nsIRDFDataSource* aDataSource, nsIRDFResource* aResource, nsIRDFResource
|
||||
}
|
||||
|
||||
|
||||
PRBool
|
||||
rdf_IsContainer(nsIRDFDataSource* aDataSource, nsIRDFResource* aResource)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = rdf_EnsureRDFService();
|
||||
if (NS_FAILED(rv)) return PR_FALSE;
|
||||
|
||||
if (rdf_IsA(aDataSource, aResource, kRDF_Bag) ||
|
||||
rdf_IsA(aDataSource, aResource, kRDF_Seq) ||
|
||||
rdf_IsA(aDataSource, aResource, kRDF_Alt)) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
else {
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
PRBool
|
||||
rdf_IsBag(nsIRDFDataSource* aDataSource, nsIRDFResource* aResource)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = rdf_EnsureRDFService();
|
||||
if (NS_FAILED(rv)) return PR_FALSE;
|
||||
|
||||
return rdf_IsA(aDataSource, aResource, kRDF_Bag);
|
||||
}
|
||||
|
||||
|
||||
PRBool
|
||||
rdf_IsSeq(nsIRDFDataSource* aDataSource, nsIRDFResource* aResource)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = rdf_EnsureRDFService();
|
||||
if (NS_FAILED(rv)) return PR_FALSE;
|
||||
|
||||
return rdf_IsA(aDataSource, aResource, kRDF_Seq);
|
||||
}
|
||||
|
||||
|
||||
PRBool
|
||||
rdf_IsAlt(nsIRDFDataSource* aDataSource, nsIRDFResource* aResource)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = rdf_EnsureRDFService();
|
||||
if (NS_FAILED(rv)) return PR_FALSE;
|
||||
|
||||
return rdf_IsA(aDataSource, aResource, kRDF_Alt);
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
rdf_CreateAnonymousResource(const nsString& aContextURI, nsIRDFResource** aResult)
|
||||
{
|
||||
@ -363,487 +220,3 @@ rdf_PossiblyMakeAbsolute(const nsString& aContextURI, nsString& aURI)
|
||||
}
|
||||
|
||||
|
||||
static nsresult
|
||||
rdf_MakeContainer(nsIRDFDataSource* aDataSource, nsIRDFResource* aContainer, nsIRDFResource* aType)
|
||||
{
|
||||
NS_ASSERTION(aDataSource != nsnull, "null ptr");
|
||||
if (! aDataSource)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_ASSERTION(aContainer != nsnull, "null ptr");
|
||||
if (! aContainer)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsresult rv;
|
||||
rv = aDataSource->Assert(aContainer, kRDF_instanceOf, aType, PR_TRUE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFLiteral> nextVal;
|
||||
rv = gRDFService->GetLiteral(nsAutoString("1").GetUnicode(), getter_AddRefs(nextVal));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = aDataSource->Assert(aContainer, kRDF_nextVal, nextVal, PR_TRUE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
rdf_MakeBag(nsIRDFDataSource* aDataSource, nsIRDFResource* aBag)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = rdf_EnsureRDFService();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return rdf_MakeContainer(aDataSource, aBag, kRDF_Bag);
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
rdf_MakeSeq(nsIRDFDataSource* aDataSource, nsIRDFResource* aSeq)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = rdf_EnsureRDFService();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return rdf_MakeContainer(aDataSource, aSeq, kRDF_Seq);
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
rdf_MakeAlt(nsIRDFDataSource* aDataSource, nsIRDFResource* aAlt)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = rdf_EnsureRDFService();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return rdf_MakeContainer(aDataSource, aAlt, kRDF_Alt);
|
||||
}
|
||||
|
||||
|
||||
static nsresult
|
||||
rdf_ContainerSetNextValue(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aContainer,
|
||||
PRInt32 aIndex)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
if (NS_FAILED(rv = rdf_EnsureRDFService()))
|
||||
return rv;
|
||||
|
||||
// Remove the current value of nextVal, if there is one.
|
||||
nsCOMPtr<nsIRDFNode> nextValNode;
|
||||
if (NS_SUCCEEDED(rv = aDataSource->GetTarget(aContainer,
|
||||
kRDF_nextVal,
|
||||
PR_TRUE,
|
||||
getter_AddRefs(nextValNode)))) {
|
||||
if (NS_FAILED(rv = aDataSource->Unassert(aContainer, kRDF_nextVal, nextValNode))) {
|
||||
NS_ERROR("unable to update nextVal");
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
nsAutoString s;
|
||||
s.Append(aIndex, 10);
|
||||
|
||||
nsCOMPtr<nsIRDFLiteral> nextVal;
|
||||
if (NS_FAILED(rv = gRDFService->GetLiteral(s.GetUnicode(), getter_AddRefs(nextVal)))) {
|
||||
NS_ERROR("unable to get nextVal literal");
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = aDataSource->Assert(aContainer, kRDF_nextVal, nextVal, PR_TRUE);
|
||||
if (rv != NS_RDF_ASSERTION_ACCEPTED) {
|
||||
NS_ERROR("unable to update nextVal");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static nsresult
|
||||
rdf_ContainerGetNextValue(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aContainer,
|
||||
nsIRDFResource** aResult)
|
||||
{
|
||||
NS_PRECONDITION(aDataSource != nsnull, "null ptr");
|
||||
if (! aDataSource)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(aContainer != nsnull, "null ptr");
|
||||
if (! aContainer)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(aResult != nsnull, "null ptr");
|
||||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsresult rv;
|
||||
rv = rdf_EnsureRDFService();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Get the next value, which hangs off of the bag via the
|
||||
// RDF:nextVal property.
|
||||
nsCOMPtr<nsIRDFNode> nextValNode;
|
||||
rv = aDataSource->GetTarget(aContainer, kRDF_nextVal, PR_TRUE, getter_AddRefs(nextValNode));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (rv == NS_RDF_NO_VALUE)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsCOMPtr<nsIRDFLiteral> nextValLiteral;
|
||||
rv = nextValNode->QueryInterface(kIRDFLiteralIID, getter_AddRefs(nextValLiteral));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsXPIDLString s;
|
||||
rv = nextValLiteral->GetValue( getter_Copies(s) );
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsAutoString nextValStr = (const PRUnichar*) s;
|
||||
|
||||
PRInt32 err;
|
||||
PRInt32 nextVal = nextValStr.ToInteger(&err);
|
||||
if (NS_FAILED(err))
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
// Generate a URI that we can return.
|
||||
nextValStr = kRDFNameSpaceURI;
|
||||
nextValStr.Append("_");
|
||||
nextValStr.Append(nextVal, 10);
|
||||
|
||||
rv = gRDFService->GetUnicodeResource(nextValStr.GetUnicode(), aResult);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Now increment the RDF:nextVal property.
|
||||
rv = aDataSource->Unassert(aContainer, kRDF_nextVal, nextValLiteral);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
++nextVal;
|
||||
nextValStr.Truncate();
|
||||
nextValStr.Append(nextVal, 10);
|
||||
|
||||
rv = gRDFService->GetLiteral(nextValStr.GetUnicode(), getter_AddRefs(nextValLiteral));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = aDataSource->Assert(aContainer, kRDF_nextVal, nextValLiteral, PR_TRUE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
rdf_ContainerGetCount(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aContainer,
|
||||
PRInt32* aCount)
|
||||
{
|
||||
NS_PRECONDITION(aDataSource != nsnull, "null ptr");
|
||||
if (! aDataSource)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(aContainer != nsnull, "null ptr");
|
||||
if (! aContainer)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(aCount != nsnull, "null ptr");
|
||||
if (! aCount)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsresult rv;
|
||||
rv = rdf_EnsureRDFService();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Get the next value, which hangs off of the bag via the
|
||||
// RDF:nextVal property.
|
||||
nsCOMPtr<nsIRDFNode> nextValNode;
|
||||
rv = aDataSource->GetTarget(aContainer, kRDF_nextVal, PR_TRUE, getter_AddRefs(nextValNode));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (rv == NS_RDF_NO_VALUE)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsCOMPtr<nsIRDFLiteral> nextValLiteral;
|
||||
rv = nextValNode->QueryInterface(kIRDFLiteralIID, getter_AddRefs(nextValLiteral));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsXPIDLString s;
|
||||
rv = nextValLiteral->GetValue( getter_Copies(s) );
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsAutoString nextValStr = (const PRUnichar*) s;
|
||||
|
||||
PRInt32 err;
|
||||
*aCount = nextValStr.ToInteger(&err);
|
||||
if (NS_FAILED(err))
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
rdf_ContainerAppendElement(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aContainer,
|
||||
nsIRDFNode* aElement)
|
||||
{
|
||||
NS_PRECONDITION(aDataSource != nsnull, "null ptr");
|
||||
if (! aDataSource)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(aContainer != nsnull, "null ptr");
|
||||
if (! aContainer)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(aElement != nsnull, "null ptr");
|
||||
if (! aElement)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(rdf_IsContainer(aDataSource, aContainer), "not a container");
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIRDFResource> nextVal;
|
||||
rv = rdf_ContainerGetNextValue(aDataSource, aContainer, getter_AddRefs(nextVal));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = aDataSource->Assert(aContainer, nextVal, aElement, PR_TRUE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
static nsresult
|
||||
rdf_ContainerRenumber(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aContainer,
|
||||
PRInt32 aStartIndex)
|
||||
{
|
||||
// Renumber the elements in the container
|
||||
nsresult rv;
|
||||
|
||||
PRInt32 count;
|
||||
rv = rdf_ContainerGetCount(aDataSource, aContainer, &count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRInt32 oldIndex = aStartIndex;
|
||||
PRInt32 newIndex = aStartIndex;
|
||||
while (oldIndex < count) {
|
||||
nsCOMPtr<nsIRDFResource> oldOrdinal;
|
||||
rv = rdf_IndexToOrdinalResource(oldIndex, getter_AddRefs(oldOrdinal));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Because of aggregation, we need to be paranoid about
|
||||
// the possibility that >1 element may be present per
|
||||
// ordinal.
|
||||
nsCOMPtr<nsISimpleEnumerator> targets;
|
||||
rv = aDataSource->GetTargets(aContainer, oldOrdinal, PR_TRUE, getter_AddRefs(targets));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
while (1) {
|
||||
PRBool hasMore;
|
||||
rv = targets->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsCOMPtr<nsISupports> isupports;
|
||||
rv = targets->GetNext(getter_AddRefs(isupports));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFNode> element( do_QueryInterface(isupports) );
|
||||
NS_ASSERTION(element != nsnull, "something funky in the enumerator");
|
||||
if (! element)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
rv = aDataSource->Unassert(aContainer, oldOrdinal, element);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> newOrdinal;
|
||||
rv = rdf_IndexToOrdinalResource(++newIndex, getter_AddRefs(newOrdinal));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = aDataSource->Assert(aContainer, newOrdinal, element, PR_TRUE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
}
|
||||
|
||||
// Update the container's nextVal to reflect the renumbering
|
||||
rv = rdf_ContainerSetNextValue(aDataSource, aContainer, ++newIndex);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
rdf_ContainerRemoveElement(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aContainer,
|
||||
nsIRDFNode* aElement,
|
||||
PRBool aRenumber)
|
||||
{
|
||||
NS_PRECONDITION(aDataSource != nsnull, "null ptr");
|
||||
if (! aDataSource)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(aContainer != nsnull, "null ptr");
|
||||
if (! aContainer)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(aElement != nsnull, "null ptr");
|
||||
if (! aElement)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsresult rv;
|
||||
|
||||
PRInt32 index;
|
||||
rv = rdf_ContainerIndexOf(aDataSource, aContainer, aElement, &index);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (index < 0) {
|
||||
NS_WARNING("attempt to remove non-existant element");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Remove the element.
|
||||
nsCOMPtr<nsIRDFResource> ordinal;
|
||||
rv = rdf_IndexToOrdinalResource(index, getter_AddRefs(ordinal));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = aDataSource->Unassert(aContainer, ordinal, aElement);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (aRenumber) {
|
||||
// Now slide the rest of the collection backwards to fill in
|
||||
// the gap. This will have the side effect of completely
|
||||
// renumber the container from index to the end.
|
||||
rv = rdf_ContainerRenumber(aDataSource, aContainer, index);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
rdf_ContainerInsertElementAt(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aContainer,
|
||||
nsIRDFNode* aElement,
|
||||
PRInt32 aIndex,
|
||||
PRBool aRenumber)
|
||||
{
|
||||
NS_PRECONDITION(aDataSource != nsnull, "null ptr");
|
||||
if (! aDataSource)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(aContainer != nsnull, "null ptr");
|
||||
if (! aContainer)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(aElement != nsnull, "null ptr");
|
||||
if (! aElement)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(aIndex >= 1, "illegal value");
|
||||
if (aIndex < 1)
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
|
||||
nsresult rv;
|
||||
|
||||
PRInt32 count;
|
||||
rv = rdf_ContainerGetCount(aDataSource, aContainer, &count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_ASSERTION(aIndex <= count, "illegal value");
|
||||
if (aIndex > count)
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
|
||||
if (aRenumber) {
|
||||
// Make a hole for the element. This will have the side effect of
|
||||
// completely renumbering the container from 'aIndex' to 'count',
|
||||
// and will spew assertions.
|
||||
rv = rdf_ContainerRenumber(aDataSource, aContainer, aIndex);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIRDFResource> ordinal;
|
||||
rv = rdf_IndexToOrdinalResource(aIndex, getter_AddRefs(ordinal));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = aDataSource->Assert(aContainer, ordinal, aElement, PR_TRUE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
rdf_ContainerIndexOf(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aContainer,
|
||||
nsIRDFNode* aElement,
|
||||
PRInt32* aIndex)
|
||||
{
|
||||
NS_PRECONDITION(aDataSource != nsnull, "null ptr");
|
||||
if (! aDataSource)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(aContainer != nsnull, "null ptr");
|
||||
if (! aContainer)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(aElement != nsnull, "null ptr");
|
||||
if (! aElement)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(aIndex != nsnull, "null ptr");
|
||||
if (! aIndex)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsresult rv;
|
||||
|
||||
PRInt32 count;
|
||||
rv = rdf_ContainerGetCount(aDataSource, aContainer, &count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
for (PRInt32 index = 0; index < count; ++index) {
|
||||
nsCOMPtr<nsIRDFResource> ordinal;
|
||||
rv = rdf_IndexToOrdinalResource(index, getter_AddRefs(ordinal));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Get all of the elements in the container with the specified
|
||||
// ordinal. This is an ultra-paranoid way to do it, but -- due
|
||||
// to aggregation, we may end up with a container that has >1
|
||||
// element for the same ordinal.
|
||||
nsCOMPtr<nsISimpleEnumerator> targets;
|
||||
rv = aDataSource->GetTargets(aContainer, ordinal, PR_TRUE, getter_AddRefs(targets));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
while (1) {
|
||||
PRBool hasMore;
|
||||
rv = targets->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsCOMPtr<nsISupports> isupports;
|
||||
rv = targets->GetNext(getter_AddRefs(isupports));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to read cursor");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFNode> element = do_QueryInterface(isupports);
|
||||
|
||||
if (element.get() != aElement)
|
||||
continue;
|
||||
|
||||
// Okay, we've found it!
|
||||
*aIndex = index;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
NS_WARNING("element not found");
|
||||
*aIndex = -1;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -49,44 +49,10 @@ class nsIRDFResource;
|
||||
class nsString;
|
||||
|
||||
/**
|
||||
* Returns PR_TRUE if the URI is an RDF ordinal property; e.g., rdf:_1,
|
||||
* rdf:_2, etc.
|
||||
* The dreaded is-a function. Uses rdf:instanceOf to determine if aResource is aType.
|
||||
*/
|
||||
PR_EXTERN(PRBool)
|
||||
rdf_IsOrdinalProperty(nsIRDFResource* property);
|
||||
|
||||
/**
|
||||
* Converts an ordinal property to an index
|
||||
*/
|
||||
PR_EXTERN(nsresult)
|
||||
rdf_OrdinalResourceToIndex(nsIRDFResource* aOrdinal, PRInt32* aIndex);
|
||||
|
||||
/**
|
||||
* Converts an index to an ordinal property
|
||||
*/
|
||||
PR_EXTERN(nsresult)
|
||||
rdf_IndexToOrdinalResource(PRInt32 aIndex, nsIRDFResource** aOrdinal);
|
||||
|
||||
|
||||
/**
|
||||
* Returns PR_TRUE if the resource is a container resource; e.g., an
|
||||
* rdf:Bag.
|
||||
*/
|
||||
PR_EXTERN(PRBool)
|
||||
rdf_IsContainer(nsIRDFDataSource* db,
|
||||
nsIRDFResource* resource);
|
||||
|
||||
PR_EXTERN(PRBool)
|
||||
rdf_IsBag(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aResource);
|
||||
|
||||
PR_EXTERN(PRBool)
|
||||
rdf_IsSeq(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aResource);
|
||||
|
||||
PR_EXTERN(PRBool)
|
||||
rdf_IsAlt(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aResource);
|
||||
rdf_IsA(nsIRDFDataSource* aDataSource, nsIRDFResource* aResource, nsIRDFResource* aType);
|
||||
|
||||
/**
|
||||
* Construct a new, "anonymous" node; that is, a node with an internal
|
||||
@ -115,83 +81,6 @@ rdf_PossiblyMakeRelative(const nsString& aContextURI, nsString& aURI);
|
||||
PR_EXTERN(nsresult)
|
||||
rdf_PossiblyMakeAbsolute(const nsString& aContextURI, nsString& aURI);
|
||||
|
||||
/**
|
||||
* Create a bag resource.
|
||||
*/
|
||||
PR_EXTERN(nsresult)
|
||||
rdf_MakeBag(nsIRDFDataSource* ds,
|
||||
nsIRDFResource* resource);
|
||||
|
||||
/**
|
||||
* Create a sequence resource.
|
||||
*/
|
||||
PR_EXTERN(nsresult)
|
||||
rdf_MakeSeq(nsIRDFDataSource* ds,
|
||||
nsIRDFResource* resource);
|
||||
|
||||
/**
|
||||
* Create an alternation resource.
|
||||
*/
|
||||
PR_EXTERN(nsresult)
|
||||
rdf_MakeAlt(nsIRDFDataSource* ds,
|
||||
nsIRDFResource* resource);
|
||||
|
||||
/**
|
||||
* Get the current upper bound of the container
|
||||
*/
|
||||
PR_EXTERN(nsresult)
|
||||
rdf_ContainerGetCount(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aContainer,
|
||||
PRInt32* aCount);
|
||||
|
||||
/**
|
||||
* Add an element to the end of container.
|
||||
*/
|
||||
PR_EXTERN(nsresult)
|
||||
rdf_ContainerAppendElement(nsIRDFDataSource* ds,
|
||||
nsIRDFResource* container,
|
||||
nsIRDFNode* element);
|
||||
|
||||
|
||||
/**
|
||||
* Remove an element from a container
|
||||
*/
|
||||
PR_EXTERN(nsresult)
|
||||
rdf_ContainerRemoveElement(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aContainer,
|
||||
nsIRDFNode* aElement,
|
||||
PRBool aRenumber);
|
||||
|
||||
|
||||
/**
|
||||
* Insert an element into a container at the specified index.
|
||||
*/
|
||||
PR_EXTERN(nsresult)
|
||||
rdf_ContainerInsertElementAt(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aContainer,
|
||||
nsIRDFNode* aElement,
|
||||
PRInt32 aIndex,
|
||||
PRBool aRenumber);
|
||||
|
||||
/**
|
||||
* Determine the index of an element in a container.
|
||||
*/
|
||||
PR_EXTERN(nsresult)
|
||||
rdf_ContainerIndexOf(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aContainer,
|
||||
nsIRDFNode* aElement,
|
||||
PRInt32* aIndex);
|
||||
|
||||
|
||||
/**
|
||||
* Create a cursor on a container that enumerates its contents in
|
||||
* order
|
||||
*/
|
||||
PR_EXTERN(nsresult)
|
||||
NS_NewContainerEnumerator(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aContainer,
|
||||
nsISimpleEnumerator** aResult);
|
||||
|
||||
|
||||
PR_EXTERN(void) SHTtest ();
|
||||
|
||||
|
@ -118,5 +118,13 @@
|
||||
#define NS_LOCALSTORE_CID \
|
||||
{ 0xdf71c6f0, 0xec53, 0x11d2, { 0xbd, 0xca, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
|
||||
|
||||
// {D4214E92-FB94-11d2-BDD8-00104BDE6048}
|
||||
#define NS_RDFCONTAINERUTILS_CID \
|
||||
{ 0xd4214e92, 0xfb94, 0x11d2, { 0xbd, 0xd8, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } }
|
||||
|
||||
// {D4214E93-FB94-11d2-BDD8-00104BDE6048}
|
||||
#define NS_RDFCONTAINER_CID \
|
||||
{ 0xd4214e93, 0xfb94, 0x11d2, { 0xbd, 0xd8, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } }
|
||||
|
||||
|
||||
#endif // nsRDFCID_h__
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include "nsIFactory.h"
|
||||
#include "nsIHistoryDataSource.h"
|
||||
#include "nsILocalStore.h"
|
||||
#include "nsIRDFContainer.h"
|
||||
#include "nsIRDFContainerUtils.h"
|
||||
#include "nsIRDFCompositeDataSource.h"
|
||||
#include "nsIRDFContentModelBuilder.h"
|
||||
#include "nsIRDFContentSink.h"
|
||||
@ -53,6 +55,8 @@ static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
static NS_DEFINE_CID(kLocalStoreCID, NS_LOCALSTORE_CID);
|
||||
static NS_DEFINE_CID(kRDFBookmarkDataSourceCID, NS_RDFBOOKMARKDATASOURCE_CID);
|
||||
static NS_DEFINE_CID(kRDFCompositeDataSourceCID, NS_RDFCOMPOSITEDATASOURCE_CID);
|
||||
static NS_DEFINE_CID(kRDFContainerCID, NS_RDFCONTAINER_CID);
|
||||
static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID);
|
||||
static NS_DEFINE_CID(kRDFContentSinkCID, NS_RDFCONTENTSINK_CID);
|
||||
static NS_DEFINE_CID(kRDFDefaultResourceCID, NS_RDFDEFAULTRESOURCE_CID);
|
||||
static NS_DEFINE_CID(kRDFFileSystemDataSourceCID, NS_RDFFILESYSTEMDATASOURCE_CID);
|
||||
@ -193,6 +197,14 @@ RDFFactoryImpl::CreateInstance(nsISupports *aOuter,
|
||||
if (NS_FAILED(rv = NS_NewRDFCompositeDataSource((nsIRDFCompositeDataSource**) &inst)))
|
||||
return rv;
|
||||
}
|
||||
else if (mClassID.Equals(kRDFContainerCID)) {
|
||||
if (NS_FAILED(rv = NS_NewRDFContainer((nsIRDFContainer**) &inst)))
|
||||
return rv;
|
||||
}
|
||||
else if (mClassID.Equals(kRDFContainerUtilsCID)) {
|
||||
if (NS_FAILED(rv = NS_NewRDFContainerUtils((nsIRDFContainerUtils**) &inst)))
|
||||
return rv;
|
||||
}
|
||||
else if (mClassID.Equals(kRDFHistoryDataSourceCID)) {
|
||||
if (NS_FAILED(rv = NS_NewHistoryDataSource((nsIHistoryDataSource**) &inst)))
|
||||
return rv;
|
||||
@ -379,7 +391,17 @@ NSRegisterSelf(nsISupports* aServMgr , const char* aPath)
|
||||
// register all the other rdf components:
|
||||
rv = compMgr->RegisterComponent(kRDFContentSinkCID,
|
||||
"RDF Content Sink",
|
||||
NS_RDF_PROGID "|content-sink",
|
||||
NS_RDF_PROGID "/content-sink",
|
||||
aPath, PR_TRUE, PR_TRUE);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
rv = compMgr->RegisterComponent(kRDFContainerCID,
|
||||
"RDF Container",
|
||||
NS_RDF_PROGID "/container",
|
||||
aPath, PR_TRUE, PR_TRUE);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
rv = compMgr->RegisterComponent(kRDFContainerUtilsCID,
|
||||
"RDF Container Utilities",
|
||||
NS_RDF_PROGID "/container-utils",
|
||||
aPath, PR_TRUE, PR_TRUE);
|
||||
if (NS_FAILED(rv)) goto done;
|
||||
rv = compMgr->RegisterComponent(kRDFHTMLBuilderCID,
|
||||
|
Binary file not shown.
@ -73,11 +73,7 @@ GetXULElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
nsIRDFResource* prop;
|
||||
if (NS_OK == a->GetResource(&prop)) {
|
||||
// get the js object
|
||||
#ifdef XPIDL_JS_STUBS
|
||||
*vp = OBJECT_TO_JSVAL(nsIRDFResource::GetJSObject(cx, prop));
|
||||
#else
|
||||
nsJSUtils::nsConvertXPCObjectToJSVal(prop, nsIRDFResource::GetIID(), cx, vp);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
|
@ -67,11 +67,7 @@ GetXULTreeElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
nsIRDFCompositeDataSource* prop;
|
||||
if (NS_OK == a->GetDatabase(&prop)) {
|
||||
// get the js object
|
||||
#ifdef XPIDL_JS_STUBS
|
||||
*vp = OBJECT_TO_JSVAL(nsIRDFCompositeDataSource::GetJSObject(cx, prop));
|
||||
#else
|
||||
nsJSUtils::nsConvertXPCObjectToJSVal(prop, nsIRDFCompositeDataSource::GetIID(), cx, vp);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
@ -108,9 +104,8 @@ SetXULTreeElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
case XULTREEELEMENT_DATABASE:
|
||||
{
|
||||
nsIRDFCompositeDataSource* prop;
|
||||
if (PR_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&prop,
|
||||
kIRDFCompositeDataSourceIID, "RDFCompositeDataSource",
|
||||
cx, *vp)) {
|
||||
if (PR_FALSE == nsJSUtils::nsConvertJSValToXPCObject((nsISupports **) &prop,
|
||||
kIRDFCompositeDataSourceIID, cx, *vp)) {
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
|
@ -72,16 +72,6 @@
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, child);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Columns);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Column);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Folder);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Title);
|
||||
|
||||
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, child);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID);
|
||||
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
|
||||
static NS_DEFINE_IID(kINameSpaceManagerIID, NS_INAMESPACEMANAGER_IID);
|
||||
@ -94,6 +84,7 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID);
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID);
|
||||
|
||||
static NS_DEFINE_IID(kXULSortServiceCID, NS_XULSORTSERVICE_CID);
|
||||
static NS_DEFINE_IID(kIXULSortServiceIID, NS_IXULSORTSERVICE_IID);
|
||||
@ -115,6 +106,7 @@ PRInt32 RDFGenericBuilderImpl::kNameSpaceID_RDF;
|
||||
PRInt32 RDFGenericBuilderImpl::kNameSpaceID_XUL;
|
||||
|
||||
nsIRDFService* RDFGenericBuilderImpl::gRDFService;
|
||||
nsIRDFContainerUtils* RDFGenericBuilderImpl::gRDFContainerUtils;
|
||||
nsINameSpaceManager* RDFGenericBuilderImpl::gNameSpaceManager;
|
||||
|
||||
nsIRDFResource* RDFGenericBuilderImpl::kNC_Title;
|
||||
@ -178,27 +170,21 @@ static const char kRDFNameSpaceURI[]
|
||||
kIRDFServiceIID,
|
||||
(nsISupports**) &gRDFService);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("couldnt' get RDF service");
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "Title", &kNC_Title);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "child", &kNC_child);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "Column", &kNC_Column);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "Folder", &kNC_Folder);
|
||||
gRDFService->GetResource(RDF_NAMESPACE_URI "child", &kRDF_child);
|
||||
}
|
||||
|
||||
rv = nsServiceManager::GetService(kXULSortServiceCID,
|
||||
kIXULSortServiceIID, (nsISupports**) &XULSortService);
|
||||
rv = nsServiceManager::GetService(kRDFContainerUtilsCID,
|
||||
nsIRDFContainerUtils::GetIID(),
|
||||
(nsISupports**) &gRDFContainerUtils);
|
||||
|
||||
NS_VERIFY(NS_SUCCEEDED(gRDFService->GetResource(kURINC_Title, &kNC_Title)),
|
||||
"couldn't get resource");
|
||||
|
||||
NS_VERIFY(NS_SUCCEEDED(gRDFService->GetResource(kURINC_child, &kNC_child)),
|
||||
"couldn't get resource");
|
||||
|
||||
NS_VERIFY(NS_SUCCEEDED(gRDFService->GetResource(kURINC_Column, &kNC_Column)),
|
||||
"couldn't get resource");
|
||||
|
||||
NS_VERIFY(NS_SUCCEEDED(gRDFService->GetResource(kURINC_Folder, &kNC_Folder)),
|
||||
"couldn't get resource");
|
||||
|
||||
NS_VERIFY(NS_SUCCEEDED(gRDFService->GetResource(kURIRDF_child, &kRDF_child)),
|
||||
"couldn't get resource");
|
||||
rv = nsServiceManager::GetService(kXULSortServiceCID,
|
||||
kIXULSortServiceIID,
|
||||
(nsISupports**) &XULSortService);
|
||||
|
||||
}
|
||||
++gRefCnt;
|
||||
@ -1243,10 +1229,16 @@ RDFGenericBuilderImpl::IsContainmentProperty(nsIContent* aElement, nsIRDFResourc
|
||||
{
|
||||
// XXX is this okay to _always_ treat ordinal properties as tree
|
||||
// properties? Probably not...
|
||||
if (rdf_IsOrdinalProperty(aProperty))
|
||||
nsresult rv;
|
||||
|
||||
PRBool isOrdinal;
|
||||
rv = gRDFContainerUtils->IsOrdinalProperty(aProperty, &isOrdinal);
|
||||
if (NS_FAILED(rv))
|
||||
return PR_FALSE;
|
||||
|
||||
if (isOrdinal)
|
||||
return PR_TRUE;
|
||||
|
||||
nsresult rv;
|
||||
nsXPIDLCString propertyURI;
|
||||
if (NS_FAILED(rv = aProperty->GetValue( getter_Copies(propertyURI) ))) {
|
||||
NS_ERROR("unable to get property URI");
|
||||
|
@ -169,7 +169,8 @@ protected:
|
||||
|
||||
// pseudo-constants
|
||||
static nsrefcnt gRefCnt;
|
||||
static nsIRDFService* gRDFService;
|
||||
static nsIRDFService* gRDFService;
|
||||
static nsIRDFContainerUtils* gRDFContainerUtils;
|
||||
static nsINameSpaceManager* gNameSpaceManager;
|
||||
|
||||
static nsIAtom* kContainerAtom;
|
||||
|
@ -339,7 +339,7 @@ RDFHTMLBuilderImpl::OnAssert(nsIContent* parent,
|
||||
if (NS_SUCCEEDED(rv = value->QueryInterface(kIRDFResourceIID, (void**) &valueResource))) {
|
||||
// If it's a tree property or an RDF container, then add it as
|
||||
// a tree child and return.
|
||||
if (IsTreeProperty(property) || rdf_IsContainer(mDB, valueResource)) {
|
||||
if (IsTreeProperty(property) /* || rdf_IsContainer(mDB, valueResource) */) {
|
||||
rv = AddTreeChild(parent, property, valueResource);
|
||||
NS_RELEASE(valueResource);
|
||||
return rv;
|
||||
@ -389,9 +389,11 @@ RDFHTMLBuilderImpl::IsTreeProperty(nsIRDFResource* aProperty)
|
||||
return PR_TRUE;
|
||||
}
|
||||
#endif // defined(TREE_PROPERTY_HACK)
|
||||
#if 0
|
||||
if (rdf_IsOrdinalProperty(aProperty)) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
#endif
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "nsIDOMXULTreeElement.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIRDFContainer.h"
|
||||
#include "nsIRDFContentModelBuilder.h"
|
||||
#include "nsIRDFCompositeDataSource.h"
|
||||
#include "nsIRDFDocument.h"
|
||||
@ -802,9 +803,20 @@ RDFTreeBuilderImpl::OnAppendChild(nsIDOMNode* aParent, nsIDOMNode* aNewChild)
|
||||
|
||||
// We'll handle things a bit differently if we're
|
||||
// tinkering with an RDF container...
|
||||
if (rdf_IsContainer(mDB, resource) &&
|
||||
rdf_IsOrdinalProperty(property)) {
|
||||
rv = rdf_ContainerAppendElement(mDB, resource, target);
|
||||
PRBool isContainer, isOrdinal;
|
||||
if (NS_SUCCEEDED(gRDFContainerUtils->IsContainer(mDB, resource, &isContainer)) &&
|
||||
isContainer &&
|
||||
NS_SUCCEEDED(gRDFContainerUtils->IsOrdinalProperty(property, &isOrdinal)) &&
|
||||
isOrdinal)
|
||||
{
|
||||
nsCOMPtr<nsIRDFContainer> container;
|
||||
rv = NS_NewRDFContainer(getter_AddRefs(container));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = container->Init(mDB, resource);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = container->AppendElement(target);
|
||||
}
|
||||
else {
|
||||
rv = mDB->Assert(resource, property, target, PR_TRUE);
|
||||
@ -948,9 +960,20 @@ RDFTreeBuilderImpl::OnRemoveChild(nsIDOMNode* aParent, nsIDOMNode* aOldChild)
|
||||
|
||||
// We'll handle things a bit differently if we're
|
||||
// tinkering with an RDF container...
|
||||
if (rdf_IsContainer(mDB, resource) &&
|
||||
rdf_IsOrdinalProperty(property)) {
|
||||
rv = rdf_ContainerRemoveElement(mDB, resource, target, PR_TRUE);
|
||||
PRBool isContainer, isOrdinal;
|
||||
if (NS_SUCCEEDED(gRDFContainerUtils->IsContainer(mDB, resource, &isContainer)) &&
|
||||
isContainer &&
|
||||
NS_SUCCEEDED(gRDFContainerUtils->IsOrdinalProperty(property, &isOrdinal)) &&
|
||||
isOrdinal)
|
||||
{
|
||||
nsCOMPtr<nsIRDFContainer> container;
|
||||
rv = NS_NewRDFContainer(getter_AddRefs(container));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = container->Init(mDB, resource);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = container->RemoveElement(target, PR_TRUE);
|
||||
}
|
||||
else {
|
||||
rv = mDB->Unassert(resource, property, target);
|
||||
|
@ -47,6 +47,7 @@
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIRDFCompositeDataSource.h"
|
||||
#include "nsIRDFContainer.h"
|
||||
#include "nsIRDFContentModelBuilder.h"
|
||||
#include "nsIRDFDocument.h"
|
||||
#include "nsIRDFNode.h"
|
||||
@ -93,6 +94,7 @@ static NS_DEFINE_IID(kIXULDocumentInfoIID, NS_IXULDOCUMENTINFO_IID);
|
||||
static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID);
|
||||
static NS_DEFINE_CID(kRDFCompositeDataSourceCID, NS_RDFCOMPOSITEDATASOURCE_CID);
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID);
|
||||
static NS_DEFINE_CID(kRDFTreeBuilderCID, NS_RDFTREEBUILDER_CID);
|
||||
static NS_DEFINE_CID(kRDFMenuBuilderCID, NS_RDFMENUBUILDER_CID);
|
||||
static NS_DEFINE_CID(kRDFToolbarBuilderCID, NS_RDFTOOLBARBUILDER_CID);
|
||||
@ -134,8 +136,9 @@ private:
|
||||
|
||||
// pseudo-constants
|
||||
static PRInt32 gRefCnt;
|
||||
static nsIRDFService* gRDFService;
|
||||
static nsINameSpaceManager* gNameSpaceManager;
|
||||
static nsIRDFService* gRDFService;
|
||||
static nsIRDFContainerUtils* gRDFContainerUtils;
|
||||
static nsINameSpaceManager* gNameSpaceManager;
|
||||
|
||||
static PRInt32 kNameSpaceID_RDF;
|
||||
static PRInt32 kNameSpaceID_XUL;
|
||||
@ -250,6 +253,7 @@ public:
|
||||
|
||||
PRInt32 RDFXULBuilderImpl::gRefCnt;
|
||||
nsIRDFService* RDFXULBuilderImpl::gRDFService;
|
||||
nsIRDFContainerUtils* RDFXULBuilderImpl::gRDFContainerUtils;
|
||||
nsINameSpaceManager* RDFXULBuilderImpl::gNameSpaceManager;
|
||||
|
||||
PRInt32 RDFXULBuilderImpl::kNameSpaceID_RDF = kNameSpaceID_Unknown;
|
||||
@ -340,6 +344,10 @@ RDFXULBuilderImpl::RDFXULBuilderImpl(void)
|
||||
gRDFService->GetResource(kURIRDF_child, &kRDF_child);
|
||||
gRDFService->GetResource(kURIXUL_element, &kXUL_element);
|
||||
}
|
||||
|
||||
rv = nsServiceManager::GetService(kRDFContainerUtilsCID,
|
||||
nsIRDFContainerUtils::GetIID(),
|
||||
(nsISupports**) &gRDFContainerUtils);
|
||||
}
|
||||
|
||||
#ifdef PR_LOGGING
|
||||
@ -358,8 +366,15 @@ RDFXULBuilderImpl::~RDFXULBuilderImpl(void)
|
||||
// NS_IF_RELEASE(mDocument) not refcounted
|
||||
|
||||
if (--gRefCnt == 0) {
|
||||
if (gRDFService)
|
||||
if (gRDFService) {
|
||||
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
|
||||
gRDFService = nsnull;
|
||||
}
|
||||
|
||||
if (gRDFContainerUtils) {
|
||||
nsServiceManager::ReleaseService(kRDFContainerUtilsCID, gRDFContainerUtils);
|
||||
gRDFContainerUtils = nsnull;
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(gNameSpaceManager);
|
||||
|
||||
@ -561,8 +576,12 @@ RDFXULBuilderImpl::CreateContents(nsIContent* aElement)
|
||||
return NS_OK;
|
||||
|
||||
// If it's a XUL element, it'd better be an RDF Sequence...
|
||||
NS_ASSERTION(rdf_IsContainer(mDB, resource), "element is a XUL:element, but not an RDF:Seq");
|
||||
if (! rdf_IsContainer(mDB, resource))
|
||||
PRBool isContainer;
|
||||
rv = gRDFContainerUtils->IsContainer(mDB, resource, &isContainer);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_ASSERTION(isContainer, "element is a XUL:element, but not an RDF:Seq");
|
||||
if (! isContainer)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
// Now mark the element's contents as being generated so that
|
||||
@ -763,8 +782,11 @@ RDFXULBuilderImpl::OnAssert(nsIRDFResource* aSource,
|
||||
|
||||
// XXX Make sure that the element we're looking at is really
|
||||
// an element generated by this content-model builder?
|
||||
|
||||
if (rdf_IsOrdinalProperty(aProperty)) {
|
||||
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
|
||||
@ -870,7 +892,11 @@ RDFXULBuilderImpl::OnUnassert(nsIRDFResource* aSource,
|
||||
// XXX somehow figure out if removing XUL kids from this
|
||||
// particular element makes any sense whatsoever.
|
||||
|
||||
if (rdf_IsOrdinalProperty(aProperty)) {
|
||||
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 unassertion. We do
|
||||
// this because we know that _eventually_ the contents will be
|
||||
@ -975,7 +1001,11 @@ RDFXULBuilderImpl::OnInsertBefore(nsIDOMNode* aParent, nsIDOMNode* aNewChild, ns
|
||||
|
||||
if (isXULElement) {
|
||||
// remove the child from the old collection
|
||||
rv = rdf_ContainerRemoveElement(mDB, oldParent, newChild, PR_TRUE);
|
||||
nsCOMPtr<nsIRDFContainer> container;
|
||||
rv = NS_NewRDFContainer(mDB, oldParent, getter_AddRefs(container));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = container->RemoveElement(newChild, PR_TRUE);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to remove newChild from oldParent");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
@ -998,14 +1028,18 @@ RDFXULBuilderImpl::OnInsertBefore(nsIDOMNode* aParent, nsIDOMNode* aNewChild, ns
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "ref child doesn't have a resource");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Create a container wrapper
|
||||
nsCOMPtr<nsIRDFContainer> container;
|
||||
rv = NS_NewRDFContainer(mDB, parent, getter_AddRefs(container));
|
||||
|
||||
// Determine the index of the refChild in the container
|
||||
PRInt32 index;
|
||||
rv = rdf_ContainerIndexOf(mDB, parent, refChild, &index);
|
||||
rv = container->IndexOf(refChild, &index);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to determine index of refChild in container");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// ...and insert the newChild before it.
|
||||
rv = rdf_ContainerInsertElementAt(mDB, parent, newChild, index, PR_TRUE);
|
||||
rv = container->InsertElementAt(newChild, index, PR_TRUE);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to insert new element into container");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
@ -1063,19 +1097,23 @@ RDFXULBuilderImpl::OnReplaceChild(nsIDOMNode* aParent, nsIDOMNode* aNewChild, ns
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (isXULElement) {
|
||||
nsCOMPtr<nsIRDFContainer> container;
|
||||
rv = NS_NewRDFContainer(mDB, parent, getter_AddRefs(container));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Remember the old child's index...
|
||||
PRInt32 index;
|
||||
rv = rdf_ContainerIndexOf(mDB, parent, oldChild, &index);
|
||||
rv = container->IndexOf(oldChild, &index);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get index of old child in container");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// ...then remove the old child from the old collection...
|
||||
rv = rdf_ContainerRemoveElement(mDB, parent, oldChild, PR_TRUE);
|
||||
rv = container->RemoveElement(oldChild, PR_TRUE);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to remove old child from container");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// ...and add the new child to the collection at the old child's index
|
||||
rv = rdf_ContainerInsertElementAt(mDB, parent, newChild, index, PR_TRUE);
|
||||
rv = container->InsertElementAt(newChild, index, PR_TRUE);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to add new child to container");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
@ -1123,7 +1161,11 @@ RDFXULBuilderImpl::OnRemoveChild(nsIDOMNode* aParent, nsIDOMNode* aOldChild)
|
||||
|
||||
if (isXULElement) {
|
||||
// ...then remove it from the container
|
||||
rv = rdf_ContainerRemoveElement(mDB, parent, oldChild, PR_TRUE);
|
||||
nsCOMPtr<nsIRDFContainer> container;
|
||||
rv = NS_NewRDFContainer(mDB, parent, getter_AddRefs(container));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = container->RemoveElement(oldChild, PR_TRUE);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to insert new element into container");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
@ -1175,7 +1217,11 @@ RDFXULBuilderImpl::OnAppendChild(nsIDOMNode* aParent, nsIDOMNode* aNewChild)
|
||||
|
||||
if (isXULElement) {
|
||||
// remove the child from the old collection
|
||||
rv = rdf_ContainerRemoveElement(mDB, oldParent, newChild, PR_TRUE);
|
||||
nsCOMPtr<nsIRDFContainer> container;
|
||||
rv = NS_NewRDFContainer(mDB, oldParent, getter_AddRefs(container));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = container->RemoveElement(newChild, PR_TRUE);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to remove newChild from oldParent");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
@ -1193,7 +1239,11 @@ RDFXULBuilderImpl::OnAppendChild(nsIDOMNode* aParent, nsIDOMNode* aNewChild)
|
||||
|
||||
if (isXULElement) {
|
||||
// ...then append it to the container
|
||||
rv = rdf_ContainerAppendElement(mDB, parent, newChild);
|
||||
nsCOMPtr<nsIRDFContainer> container;
|
||||
rv = NS_NewRDFContainer(mDB, parent, getter_AddRefs(container));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = container->AppendElement(newChild);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to insert new element into container");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
@ -1684,8 +1734,14 @@ RDFXULBuilderImpl::CreateHTMLElement(nsINameSpace* aContainingNameSpace,
|
||||
// structure of the XUL: ignore them b/c they're not attributes
|
||||
if ((property.get() == kRDF_instanceOf) ||
|
||||
(property.get() == kRDF_nextVal) ||
|
||||
(property.get() == kRDF_type) ||
|
||||
(rdf_IsOrdinalProperty(property)))
|
||||
(property.get() == kRDF_type))
|
||||
continue;
|
||||
|
||||
PRBool isOrdinal;
|
||||
rv = gRDFContainerUtils->IsOrdinalProperty(property, &isOrdinal);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (isOrdinal)
|
||||
continue;
|
||||
|
||||
// For each property, get its value: this will be the value of
|
||||
@ -1884,8 +1940,14 @@ RDFXULBuilderImpl::CreateXULElement(nsINameSpace* aContainingNameSpace,
|
||||
// These are special beacuse they're used to specify the tree
|
||||
// structure of the XUL: ignore them b/c they're not attributes
|
||||
if ((property.get() == kRDF_nextVal) ||
|
||||
(property.get() == kRDF_type) ||
|
||||
rdf_IsOrdinalProperty(property))
|
||||
(property.get() == kRDF_type))
|
||||
continue;
|
||||
|
||||
PRBool isOrdinal;
|
||||
rv = gRDFContainerUtils->IsOrdinalProperty(property, &isOrdinal);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (isOrdinal)
|
||||
continue;
|
||||
|
||||
// For each property, set its value.
|
||||
|
@ -72,16 +72,6 @@
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, child);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Columns);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Column);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Folder);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Title);
|
||||
|
||||
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, child);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID);
|
||||
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
|
||||
static NS_DEFINE_IID(kINameSpaceManagerIID, NS_INAMESPACEMANAGER_IID);
|
||||
@ -94,6 +84,7 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID);
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID);
|
||||
|
||||
static NS_DEFINE_IID(kXULSortServiceCID, NS_XULSORTSERVICE_CID);
|
||||
static NS_DEFINE_IID(kIXULSortServiceIID, NS_IXULSORTSERVICE_IID);
|
||||
@ -115,6 +106,7 @@ PRInt32 RDFGenericBuilderImpl::kNameSpaceID_RDF;
|
||||
PRInt32 RDFGenericBuilderImpl::kNameSpaceID_XUL;
|
||||
|
||||
nsIRDFService* RDFGenericBuilderImpl::gRDFService;
|
||||
nsIRDFContainerUtils* RDFGenericBuilderImpl::gRDFContainerUtils;
|
||||
nsINameSpaceManager* RDFGenericBuilderImpl::gNameSpaceManager;
|
||||
|
||||
nsIRDFResource* RDFGenericBuilderImpl::kNC_Title;
|
||||
@ -178,27 +170,21 @@ static const char kRDFNameSpaceURI[]
|
||||
kIRDFServiceIID,
|
||||
(nsISupports**) &gRDFService);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ERROR("couldnt' get RDF service");
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "Title", &kNC_Title);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "child", &kNC_child);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "Column", &kNC_Column);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "Folder", &kNC_Folder);
|
||||
gRDFService->GetResource(RDF_NAMESPACE_URI "child", &kRDF_child);
|
||||
}
|
||||
|
||||
rv = nsServiceManager::GetService(kXULSortServiceCID,
|
||||
kIXULSortServiceIID, (nsISupports**) &XULSortService);
|
||||
rv = nsServiceManager::GetService(kRDFContainerUtilsCID,
|
||||
nsIRDFContainerUtils::GetIID(),
|
||||
(nsISupports**) &gRDFContainerUtils);
|
||||
|
||||
NS_VERIFY(NS_SUCCEEDED(gRDFService->GetResource(kURINC_Title, &kNC_Title)),
|
||||
"couldn't get resource");
|
||||
|
||||
NS_VERIFY(NS_SUCCEEDED(gRDFService->GetResource(kURINC_child, &kNC_child)),
|
||||
"couldn't get resource");
|
||||
|
||||
NS_VERIFY(NS_SUCCEEDED(gRDFService->GetResource(kURINC_Column, &kNC_Column)),
|
||||
"couldn't get resource");
|
||||
|
||||
NS_VERIFY(NS_SUCCEEDED(gRDFService->GetResource(kURINC_Folder, &kNC_Folder)),
|
||||
"couldn't get resource");
|
||||
|
||||
NS_VERIFY(NS_SUCCEEDED(gRDFService->GetResource(kURIRDF_child, &kRDF_child)),
|
||||
"couldn't get resource");
|
||||
rv = nsServiceManager::GetService(kXULSortServiceCID,
|
||||
kIXULSortServiceIID,
|
||||
(nsISupports**) &XULSortService);
|
||||
|
||||
}
|
||||
++gRefCnt;
|
||||
@ -1243,10 +1229,16 @@ RDFGenericBuilderImpl::IsContainmentProperty(nsIContent* aElement, nsIRDFResourc
|
||||
{
|
||||
// XXX is this okay to _always_ treat ordinal properties as tree
|
||||
// properties? Probably not...
|
||||
if (rdf_IsOrdinalProperty(aProperty))
|
||||
nsresult rv;
|
||||
|
||||
PRBool isOrdinal;
|
||||
rv = gRDFContainerUtils->IsOrdinalProperty(aProperty, &isOrdinal);
|
||||
if (NS_FAILED(rv))
|
||||
return PR_FALSE;
|
||||
|
||||
if (isOrdinal)
|
||||
return PR_TRUE;
|
||||
|
||||
nsresult rv;
|
||||
nsXPIDLCString propertyURI;
|
||||
if (NS_FAILED(rv = aProperty->GetValue( getter_Copies(propertyURI) ))) {
|
||||
NS_ERROR("unable to get property URI");
|
||||
|
@ -27,6 +27,7 @@
|
||||
|
||||
*/
|
||||
|
||||
#include "nsIRDFContainer.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFService.h"
|
||||
@ -52,7 +53,7 @@ static NS_DEFINE_IID(kIRDFDataSourceIID, NS_IRDFDATASOURCE_IID);
|
||||
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
|
||||
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
|
||||
static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID);
|
||||
static NS_DEFINE_CID(kRDFBookmarkDataSourceCID, NS_RDFBOOKMARKDATASOURCE_CID);
|
||||
static NS_DEFINE_IID(kIRDFBookmarkDataSourceIID,NS_IRDFBOOKMARKDATASOURCE_IID);
|
||||
|
||||
@ -431,11 +432,13 @@ BookmarkParser::AddBookmark(nsIRDFResource * aContainer, const char *url, const
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv = rdf_ContainerAppendElement(mDataSource, aContainer, bookmark)))
|
||||
{
|
||||
NS_ERROR("unable to add bookmark to container");
|
||||
return rv;
|
||||
}
|
||||
nsCOMPtr<nsIRDFContainer> container;
|
||||
rv = NS_NewRDFContainer(mDataSource, aContainer, getter_AddRefs(container));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = container->AppendElement(bookmark);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to add bookmark to container");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = mDataSource->Assert(bookmark, kRDF_type, kNC_Bookmark, PR_TRUE);
|
||||
if (rv != NS_RDF_ASSERTION_ACCEPTED)
|
||||
@ -556,15 +559,20 @@ BookmarkParser::ParseBookmarkHeader(const nsString& aLine, nsIRDFResource* aCont
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv = rdf_ContainerAppendElement(mDataSource, aContainer, folder))) {
|
||||
NS_ERROR("unable to add new folder to parent");
|
||||
return rv;
|
||||
}
|
||||
nsCOMPtr<nsIRDFContainer> container;
|
||||
rv = NS_NewRDFContainer(mDataSource, aContainer, getter_AddRefs(container));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (NS_FAILED(rv = rdf_MakeSeq(mDataSource, folder))) {
|
||||
NS_ERROR("unable to make new folder as sequence");
|
||||
return rv;
|
||||
}
|
||||
rv = container->AppendElement(folder);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to add bookmark to container");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_WITH_SERVICE(nsIRDFContainerUtils, rdfc, kRDFContainerUtilsCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = rdfc->MakeSeq(mDataSource, folder, nsnull);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to make new folder as sequence");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = mDataSource->Assert(folder, kRDF_type, kNC_Folder, PR_TRUE);
|
||||
if (rv != NS_RDF_ASSERTION_ACCEPTED) {
|
||||
@ -606,9 +614,11 @@ BookmarkParser::ParseBookmarkSeparator(const nsString& aLine, nsIRDFResource* aC
|
||||
}
|
||||
if (NS_SUCCEEDED(rv = mDataSource->Assert(separator, kRDF_type, kNC_BookmarkSeparator, PR_TRUE)))
|
||||
{
|
||||
if (NS_SUCCEEDED(rv = rdf_ContainerAppendElement(mDataSource, aContainer, separator)))
|
||||
{
|
||||
}
|
||||
nsCOMPtr<nsIRDFContainer> container;
|
||||
rv = NS_NewRDFContainer(mDataSource, aContainer, getter_AddRefs(container));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = container->AppendElement(separator);
|
||||
}
|
||||
}
|
||||
}
|
||||
return(rv);
|
||||
@ -992,10 +1002,13 @@ nsresult
|
||||
BookmarkDataSourceImpl::ReadBookmarks(void)
|
||||
{
|
||||
nsresult rv;
|
||||
if (NS_FAILED(rv = rdf_MakeSeq(mInner, kNC_BookmarksRoot))) {
|
||||
NS_ERROR("Unaboe to make NC:BookmarksRoot a sequence");
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_WITH_SERVICE(nsIRDFContainerUtils, rdfc, kRDFContainerUtilsCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = rdfc->MakeSeq(mInner, kNC_BookmarksRoot, nsnull);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to make NC:BookmarksRoot a sequence");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsSpecialSystemDirectory bookmarksFile(nsSpecialSystemDirectory::OS_CurrentProcessDirectory);
|
||||
|
||||
@ -1029,9 +1042,10 @@ BookmarkDataSourceImpl::ReadBookmarks(void)
|
||||
nsCOMPtr<nsIRDFResource> ieFolder;
|
||||
if (NS_SUCCEEDED(rv = rdf_CreateAnonymousResource(kURINC_IEFavoritesRoot, getter_AddRefs(ieFolder))))
|
||||
{
|
||||
if (NS_SUCCEEDED(rv = rdf_MakeSeq(mInner, ieFolder)))
|
||||
NS_WITH_SERVICE(nsIRDFContainerUtils, rdfc, kRDFContainerUtilsCID, &rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
if (NS_SUCCEEDED(rv = mInner->Assert(ieFolder, kRDF_type, kNC_Folder, PR_TRUE)))
|
||||
if (NS_SUCCEEDED(rv = rdfc->MakeSeq(mInner, ieFolder, nsnull)))
|
||||
{
|
||||
BookmarkParser parser;
|
||||
parser.Init(&ieStream, this);
|
||||
@ -1042,9 +1056,28 @@ BookmarkDataSourceImpl::ReadBookmarks(void)
|
||||
{
|
||||
rv = mInner->Assert(ieFolder, kNC_Name, ieTitleLiteral, PR_TRUE);
|
||||
}
|
||||
if (NS_SUCCEEDED(rv = rdf_ContainerAppendElement(mInner, kNC_BookmarksRoot, ieFolder)))
|
||||
nsCOMPtr<nsIRDFContainer> bookmarksRoot;
|
||||
rv = NS_NewRDFContainer(mInner, kNC_BookmarksRoot, getter_AddRefs(bookmarksRoot));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
if (NS_SUCCEEDED(rv = bookmarksRoot->AppendElement(ieFolder)))
|
||||
{
|
||||
BookmarkParser parser;
|
||||
parser.Init(&ieStream, this);
|
||||
parser.Parse(ieFolder);
|
||||
|
||||
nsCOMPtr<nsIRDFLiteral> ieTitleLiteral;
|
||||
if (NS_SUCCEEDED(rv = gRDFService->GetLiteral(ieTitle, getter_AddRefs(ieTitleLiteral))))
|
||||
{
|
||||
rv = mInner->Assert(ieFolder, kNC_Name, ieTitleLiteral, PR_TRUE);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIRDFContainer> container;
|
||||
rv = NS_NewRDFContainer(mInner, kNC_BookmarksRoot, getter_AddRefs(container));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = container->AppendElement(ieFolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1064,9 +1097,12 @@ BookmarkDataSourceImpl::ReadBookmarks(void)
|
||||
{
|
||||
rv = mInner->Assert(ieFolder, kNC_Name, ieTitleLiteral, PR_TRUE);
|
||||
}
|
||||
if (NS_SUCCEEDED(rv = rdf_ContainerAppendElement(mInner, kNC_BookmarksRoot, ieFolder)))
|
||||
{
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIRDFContainer> container;
|
||||
rv = NS_NewRDFContainer(mInner, kNC_BookmarksRoot, getter_AddRefs(container));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = container->AppendElement(ieFolder);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1090,8 +1126,20 @@ BookmarkDataSourceImpl::CanAccept(nsIRDFResource* aSource,
|
||||
// XXX This is really crippled, and needs to be stricter. We want
|
||||
// to exclude any property that isn't talking about a known
|
||||
// bookmark.
|
||||
if (! rdf_IsOrdinalProperty(aProperty) ||
|
||||
(aProperty != kRDF_type) ||
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIRDFContainerUtils, rdfc, kRDFContainerUtilsCID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return PR_FALSE;
|
||||
|
||||
PRBool isOrdinal;
|
||||
rv = rdfc->IsOrdinalProperty(aProperty, &isOrdinal);
|
||||
if (NS_FAILED(rv))
|
||||
return PR_FALSE;
|
||||
|
||||
if (isOrdinal) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
else if ((aProperty != kRDF_type) ||
|
||||
(aProperty != kWEB_LastModifiedDate) ||
|
||||
(aProperty != kWEB_LastVisitDate) ||
|
||||
(aProperty != kNC_Name) ||
|
||||
|
@ -48,6 +48,7 @@
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIParser.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIRDFContainer.h"
|
||||
#include "nsIRDFDocument.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFService.h"
|
||||
@ -108,6 +109,7 @@ static NS_DEFINE_IID(kIXULContentSinkIID, NS_IXULCONTENTSINK_IID);
|
||||
|
||||
static NS_DEFINE_CID(kCSSParserCID, NS_CSSPARSER_CID);
|
||||
static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID);
|
||||
static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID);
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
|
||||
|
||||
@ -1109,15 +1111,15 @@ XULContentSinkImpl::FlushText(PRBool aCreateTextNode, PRBool* aDidFlush)
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIRDFLiteral> literal;
|
||||
if (NS_FAILED(rv = gRDFService->GetLiteral(value.GetUnicode(), getter_AddRefs(literal)))) {
|
||||
NS_ERROR("unable to create RDF literal");
|
||||
return rv;
|
||||
}
|
||||
rv = gRDFService->GetLiteral(value.GetUnicode(), getter_AddRefs(literal));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (NS_FAILED(rv = rdf_ContainerAppendElement(mDataSource, GetTopResource(), literal))) {
|
||||
NS_ERROR("unable to add text to container");
|
||||
return rv;
|
||||
}
|
||||
nsCOMPtr<nsIRDFContainer> container;
|
||||
rv = NS_NewRDFContainer(mDataSource, GetTopResource(), getter_AddRefs(container));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = container->AppendElement(literal);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to add text to container");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1323,10 +1325,12 @@ XULContentSinkImpl::OpenTag(const nsIParserNode& aNode)
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv = rdf_MakeSeq(mDataSource, rdfResource))) {
|
||||
NS_ERROR("unable to create sequence for tag");
|
||||
return rv;
|
||||
}
|
||||
NS_WITH_SERVICE(nsIRDFContainerUtils, rdfc, kRDFContainerUtilsCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = rdfc->MakeSeq(mDataSource, rdfResource, nsnull);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create sequence for tag");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = mDataSource->Assert(rdfResource, kRDF_instanceOf, kXUL_element, PR_TRUE);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to mark resource as XUL element");
|
||||
@ -1377,12 +1381,13 @@ XULContentSinkImpl::OpenTag(const nsIParserNode& aNode)
|
||||
else {
|
||||
// We now have an RDF node for the container. Hook it up to
|
||||
// its parent container with a "child" relationship.
|
||||
if (NS_FAILED(rv = rdf_ContainerAppendElement(mDataSource,
|
||||
GetTopResource(),
|
||||
rdfResource))) {
|
||||
NS_ERROR("unable to add child to container");
|
||||
return rv;
|
||||
}
|
||||
nsCOMPtr<nsIRDFContainer> container;
|
||||
rv = NS_NewRDFContainer(mDataSource, GetTopResource(), getter_AddRefs(container));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = container->AppendElement(rdfResource);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to add child to container");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
// Push the element onto the context stack, so that child
|
||||
|
Loading…
Reference in New Issue
Block a user