Whacked to get RDF/XUL working right, with local content mderged in.

git-svn-id: svn://10.0.0.236/trunk@20079 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
waterson%netscape.com
1999-02-09 03:15:41 +00:00
parent 0c1cbba8b5
commit 991f41cbc8
25 changed files with 3600 additions and 1102 deletions

View File

@@ -84,12 +84,6 @@ public:
*/
NS_IMETHOD OnNamedDataSourceAdded(nsIRDFXMLDataSource* aStream, const char* aNamedDataSourceURI) = 0;
/**
* Called when a content model builder is specified (via XML processing
* instruction).
*/
NS_IMETHOD OnContentModelBuilderSpecified(nsIRDFXMLDataSource* aStream,
nsID* aCID) = 0;
};
@@ -181,16 +175,6 @@ public:
*/
NS_IMETHOD AddNameSpace(nsIAtom* aPrefix, const nsString& aURI) = 0;
/**
* Set the RDF/XML document's content model builder class ID.
*/
NS_IMETHOD SetContentModelBuilderCID(nsID* aCID) = 0;
/**
* Get the RDF/XML document's content model builder class ID.
*/
NS_IMETHOD GetContentModelBuilderCID(nsID* aCID) = 0;
/**
* Add an observer to the document. The observer will be notified of
* RDF/XML events via the nsIRDFXMLDataSourceObserver interface. Note that

View File

@@ -33,7 +33,6 @@ CPPSRCS = \
nsEmptyCursor.cpp \
nsInMemoryDataSource.cpp \
nsRDFContentSink.cpp \
nsXULContentSink.cpp \
nsRDFService.cpp \
nsRDFXMLDataSource.cpp \
rdfutil.cpp \

View File

@@ -26,7 +26,6 @@ CPP_OBJS=\
.\$(OBJDIR)\nsEmptyCursor.obj \
.\$(OBJDIR)\nsInMemoryDataSource.obj \
.\$(OBJDIR)\nsRDFContentSink.obj \
.\$(OBJDIR)\nsXULContentSink.obj \
.\$(OBJDIR)\nsRDFService.obj \
.\$(OBJDIR)\nsRDFXMLDataSource.obj \
.\$(OBJDIR)\rdfutil.obj \

View File

@@ -711,21 +711,6 @@ static const char kContentModelBuilderPI[] = "<?rdf-builder";
rv = mDataSource->AddNamedDataSourceURI(uri);
}
else if (0 == text.Find(kContentModelBuilderPI)) {
nsAutoString cidStr;
rv = rdf_GetQuotedAttributeValue(text, "cid", cidStr);
if (NS_FAILED(rv) || (0 == cidStr.Length()))
return rv;
char buf[256];
cidStr.ToCString(buf, sizeof(buf));
nsID cid;
if (! cid.Parse(buf))
return NS_ERROR_FAILURE;
rv = mDataSource->SetContentModelBuilderCID(&cid);
}
return rv;
}

View File

@@ -229,7 +229,6 @@ protected:
nsIRDFResource* mRootResource;
PRBool mIsLoading; // true while the document is loading
NameSpaceMap* mNameSpaces;
nsID mContentModelBuilderCID;
public:
RDFXMLDataSourceImpl(void);
@@ -341,8 +340,6 @@ public:
NS_IMETHOD AddNamedDataSourceURI(const char* aNamedDataSourceURI);
NS_IMETHOD GetNamedDataSourceURIs(const char* const** aNamedDataSourceURIs, PRInt32* aCount);
NS_IMETHOD AddNameSpace(nsIAtom* aPrefix, const nsString& aURI);
NS_IMETHOD SetContentModelBuilderCID(nsID* aCID);
NS_IMETHOD GetContentModelBuilderCID(nsID* aCID);
NS_IMETHOD AddXMLStreamObserver(nsIRDFXMLDataSourceObserver* aObserver);
NS_IMETHOD RemoveXMLStreamObserver(nsIRDFXMLDataSourceObserver* aObserver);
@@ -919,26 +916,6 @@ RDFXMLDataSourceImpl::AddNameSpace(nsIAtom* aPrefix, const nsString& aURI)
}
NS_IMETHODIMP
RDFXMLDataSourceImpl::SetContentModelBuilderCID(nsID* aCID)
{
mContentModelBuilderCID = *aCID;
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
nsIRDFXMLDataSourceObserver* obs = (nsIRDFXMLDataSourceObserver*) mObservers[i];
obs->OnContentModelBuilderSpecified(this, &mContentModelBuilderCID);
}
return NS_OK;
}
NS_IMETHODIMP
RDFXMLDataSourceImpl::GetContentModelBuilderCID(nsID* aCID)
{
*aCID = mContentModelBuilderCID;
return NS_OK;
}
NS_IMETHODIMP
RDFXMLDataSourceImpl::AddXMLStreamObserver(nsIRDFXMLDataSourceObserver* aObserver)
{

View File

@@ -30,6 +30,10 @@ CPP_OBJS=\
.\$(OBJDIR)\nsRDFFactory.obj \
$(NULL)
# XXX linking in raptor is a heinous crime that will go away once we
# have a more DOM-based mechanism for constructing elements and
# hooking in to their changes.
LLIBS=\
$(DIST)\lib\rdfbase_s.lib \
$(DIST)\lib\rdfcontent_s.lib \
@@ -39,9 +43,7 @@ LLIBS=\
$(DIST)\lib\raptorgfxwin.lib \
$(DIST)\lib\netlib.lib \
$(DIST)\lib\libplc21.lib \
#if 0 # for HTML-in-XUL
$(DIST)\lib\raptorhtml.lib \
#endif
$(LIBNSPR)
MISCDEP=$(LLIBS)

View File

@@ -46,10 +46,6 @@
#define NS_RDFCOMPOSITEDATASOURCE_CID \
{ 0xe638d761, 0x8687, 0x11d2, { 0xb5, 0x30, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
// {541AFCB2-A9A3-11d2-8EC5-00805F29F370}
#define NS_RDFDOCUMENT_CID \
{ 0x541afcb2, 0xa9a3, 0x11d2, { 0x8e, 0xc5, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
// {954F0813-81DC-11d2-B52A-000000000000}
#define NS_RDFHTMLBUILDER_CID \
{ 0x954f0813, 0x81dc, 0x11d2, { 0xb5, 0x2a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
@@ -78,4 +74,8 @@
#define NS_XULCONTENTSINK_CID \
{ 0xce058b21, 0xba9c, 0x11d2, { 0xbf, 0x86, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }
// {541AFCB2-A9A3-11d2-8EC5-00805F29F370}
#define NS_XULDOCUMENT_CID \
{ 0x541afcb2, 0xa9a3, 0x11d2, { 0x8e, 0xc5, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
#endif // nsRDFCID_h__

View File

@@ -33,6 +33,7 @@
#include "nsRDFBaseDataSources.h"
#include "nsRDFBuiltInDataSources.h"
#include "nsRDFCID.h"
#include "nsRepository.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
@@ -40,15 +41,15 @@ static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_CID(kRDFBookmarkDataSourceCID, NS_RDFBOOKMARKDATASOURCE_CID);
static NS_DEFINE_CID(kRDFCompositeDataSourceCID, NS_RDFCOMPOSITEDATASOURCE_CID);
static NS_DEFINE_CID(kRDFContentSinkCID, NS_RDFCONTENTSINK_CID);
static NS_DEFINE_CID(kRDFDocumentCID, NS_RDFDOCUMENT_CID);
static NS_DEFINE_CID(kRDFHTMLBuilderCID, NS_RDFHTMLBUILDER_CID);
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kRDFTreeBuilderCID, NS_RDFTREEBUILDER_CID);
static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID);
static NS_DEFINE_CID(kRDFXULBuilderCID, NS_RDFXULBUILDER_CID);
static NS_DEFINE_CID(kXULDataSourceCID, NS_XULDATASOURCE_CID);
static NS_DEFINE_CID(kXULContentSinkCID, NS_XULCONTENTSINK_CID);
static NS_DEFINE_CID(kXULDataSourceCID, NS_XULDATASOURCE_CID);
static NS_DEFINE_CID(kXULDocumentCID, NS_XULDOCUMENT_CID);
class RDFFactoryImpl : public nsIFactory
{
@@ -148,8 +149,8 @@ RDFFactoryImpl::CreateInstance(nsISupports *aOuter,
if (NS_FAILED(rv = NS_NewRDFCompositeDataSource((nsIRDFCompositeDataSource**) &inst)))
return rv;
}
else if (mClassID.Equals(kRDFDocumentCID)) {
if (NS_FAILED(rv = NS_NewRDFDocument((nsIRDFDocument**) &inst)))
else if (mClassID.Equals(kXULDocumentCID)) {
if (NS_FAILED(rv = NS_NewXULDocument((nsIRDFDocument**) &inst)))
return rv;
}
else if (mClassID.Equals(kRDFHTMLBuilderCID)) {
@@ -219,3 +220,43 @@ NSGetFactory(const nsCID &aClass, nsISupports* aServiceManager, nsIFactory **aFa
return NS_OK;
}
extern "C" PR_IMPLEMENT(nsresult)
NSRegisterSelf(const char* aPath)
{
nsRepository::RegisterFactory(kRDFBookmarkDataSourceCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kRDFCompositeDataSourceCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kRDFContentSinkCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kRDFHTMLBuilderCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kRDFInMemoryDataSourceCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kRDFServiceCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kRDFTreeBuilderCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kRDFXMLDataSourceCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kRDFXULBuilderCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kXULContentSinkCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kXULDataSourceCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kXULDocumentCID, aPath, PR_TRUE, PR_TRUE);
return NS_OK;
}
extern "C" PR_IMPLEMENT(nsresult)
NSUnregisterSelf(const char* aPath)
{
nsRepository::UnregisterFactory(kRDFBookmarkDataSourceCID, aPath);
nsRepository::UnregisterFactory(kRDFCompositeDataSourceCID, aPath);
nsRepository::UnregisterFactory(kRDFContentSinkCID, aPath);
nsRepository::UnregisterFactory(kRDFHTMLBuilderCID, aPath);
nsRepository::UnregisterFactory(kRDFInMemoryDataSourceCID, aPath);
nsRepository::UnregisterFactory(kRDFServiceCID, aPath);
nsRepository::UnregisterFactory(kRDFTreeBuilderCID, aPath);
nsRepository::UnregisterFactory(kRDFXMLDataSourceCID, aPath);
nsRepository::UnregisterFactory(kRDFXULBuilderCID, aPath);
nsRepository::UnregisterFactory(kXULContentSinkCID, aPath);
nsRepository::UnregisterFactory(kXULDataSourceCID, aPath);
nsRepository::UnregisterFactory(kXULDocumentCID, aPath);
return NS_OK;
}

View File

@@ -30,7 +30,9 @@
#include "nsISupports.h"
class nsIRDFContent;
class nsIContent;
class nsIRDFCompositeDataSource;
class nsIRDFContent; // XXX get rid of these...
class nsIRDFDocument;
class nsIRDFNode;
class nsIRDFResource;
@@ -50,32 +52,20 @@ public:
*/
NS_IMETHOD SetDocument(nsIRDFDocument* aDocument) = 0;
NS_IMETHOD SetDataBase(nsIRDFCompositeDataSource* aDataBase) = 0;
NS_IMETHOD GetDataBase(nsIRDFCompositeDataSource** aDataBase) = 0;
/**
* Called to instruct the content model builder to construct the root
* document element. The content model builder should construct an
* nsIContent object and set the document's content root to that object
* via the nsIDocument::SetDocumentRoot() method.
* Set the root element from which this content model will
* operate.
*/
NS_IMETHOD CreateRoot(nsIRDFResource* aResource) = 0;
NS_IMETHOD CreateRootContent(nsIRDFResource* aResource) = 0;
NS_IMETHOD SetRootContent(nsIContent* aElement) = 0;
/**
* Construct the contents for a container element.
*/
NS_IMETHOD CreateContents(nsIRDFContent* aElement) = 0;
/**
* Called when a new assertion is made to the RDF graph that affects an
* element in the content model. The content model builder should update
* the document's content model as appropriate.
*/
NS_IMETHOD OnAssert(nsIRDFContent* aElement, nsIRDFResource* aProperty, nsIRDFNode* aValue) = 0;
/**
* Called when an assertion is removed from the RDF graph that affects
* an element in the content model. The content model builder should
* update the document's content model as appropriate.
*/
NS_IMETHOD OnUnassert(nsIRDFContent* aElement, nsIRDFResource* aProperty, nsIRDFNode* aValue) = 0;
NS_IMETHOD CreateContents(nsIContent* aElement) = 0;
};

View File

@@ -56,57 +56,31 @@ public:
*/
NS_IMETHOD SetContentType(const char* aContentType) = 0;
/**
* Set the document's content model builder.
*/
NS_IMETHOD SetContentModelBuilder(nsIRDFContentModelBuilder* aBuilder) = 0;
/**
* Get the document's content model builder.
*/
NS_IMETHOD GetContentModelBuilder(nsIRDFContentModelBuilder** aBuilder) = 0;
/**
* Set the document's "root" resource.
*/
NS_IMETHOD SetRootResource(nsIRDFResource* aResource) = 0;
/**
* Retrieve the document's RDF data base.
*/
NS_IMETHOD GetDataBase(nsIRDFCompositeDataSource*& rDataBase) = 0;
// XXX the following two methods should probably accept strings as
// parameters so you can mess with them via JS. Also, should they
// take a "notify" parameter that would control whether any viewers
// of the content model should be informed that the content model is
// invalid?
/**
* Add a property to the set of "tree properties" that the document
* should use when constructing the content model from the RDF
* graph.
*/
NS_IMETHOD AddTreeProperty(nsIRDFResource* resource) = 0;
/**
* Remove a property from the set of "tree properties" that the
* document should use when constructing the content model from the
* RDF graph.
*/
NS_IMETHOD RemoveTreeProperty(nsIRDFResource* resource) = 0;
/**
* Determine whether the specified property is a "tree" property.
*/
NS_IMETHOD IsTreeProperty(nsIRDFResource* aProperty, PRBool* aResult) const = 0;
NS_IMETHOD MapResource(nsIRDFResource* aResource, nsIRDFContent* aContent) = 0;
NS_IMETHOD UnMapResource(nsIRDFResource* aResource, nsIRDFContent* aContent) = 0;
NS_IMETHOD SplitProperty(nsIRDFResource* aResource, PRInt32* aNameSpaceID, nsIAtom** aTag) = 0;
NS_IMETHOD AddElementForResource(nsIRDFResource* aResource, nsIRDFContent* aElement) = 0;
NS_IMETHOD RemoveElementForResource(nsIRDFResource* aResource, nsIRDFContent* aElement) = 0;
NS_IMETHOD GetElementsForResource(nsIRDFResource* aResource, nsISupportsArray* aElements) = 0;
NS_IMETHOD CreateContents(nsIRDFContent* aElement) = 0;
NS_IMETHOD AddContentModelBuilder(nsIRDFContentModelBuilder* aBuilder) = 0;
};
// factory functions
nsresult NS_NewRDFDocument(nsIRDFDocument** result);
nsresult NS_NewXULDocument(nsIRDFDocument** result);
#endif // nsIRDFDocument_h___

View File

@@ -29,12 +29,12 @@ LIBRARY_NAME = rdfcontent_s
CPPSRCS = \
nsRDFContentUtils.cpp \
nsRDFDOMNodeList.cpp \
nsRDFDocument.cpp \
nsRDFGenericElement.cpp \
nsRDFHTMLBuilder.cpp \
nsRDFResourceElement.cpp \
nsRDFTreeBuilder.cpp \
nsRDFXULBuilder.cpp \
nsXULDocument.cpp \
$(NULL)
EXPORTS = \
@@ -50,6 +50,11 @@ REQUIRES = dom js netlib rdf raptor xpcom
# a first-class XPCOM interface.
INCLUDES += -I$(srcdir)/../../base/src
# XXX This is a dependency on Raptor for constructing HTML
# content. It'll go away once we move RDF content model construction
# outside the DOM APIs.
INCLUDES += -I$(srcdir)/../../../layout/html/base/src
MKSHLIB :=
# we don't want the shared lib

View File

@@ -22,14 +22,18 @@ LIBRARY_NAME=rdfcontent_s
CPP_OBJS=\
.\$(OBJDIR)\nsRDFContentUtils.obj \
.\$(OBJDIR)\nsRDFDOMNodeList.obj \
.\$(OBJDIR)\nsRDFDocument.obj \
.\$(OBJDIR)\nsRDFGenericElement.obj \
.\$(OBJDIR)\nsRDFHTMLBuilder.obj \
.\$(OBJDIR)\nsRDFResourceElement.obj \
.\$(OBJDIR)\nsRDFTreeBuilder.obj \
.\$(OBJDIR)\nsRDFXULBuilder.obj \
.\$(OBJDIR)\nsXULDocument.obj \
$(NULL)
# XXX we are including layout\html\base\src to get HTML elements
# constructed directly from Raptor. The hope is that this'll
# eventually be replaced by a DOM-based mechanism.
LINCS= -I$(PUBLIC)\rdf \
-I$(PUBLIC)\xpcom \
-I$(PUBLIC)\netlib \
@@ -37,9 +41,7 @@ LINCS= -I$(PUBLIC)\rdf \
-I$(PUBLIC)\js \
-I$(PUBLIC)\dom \
-I$(DEPTH)\rdf\base\src \
!if 0 # XXX need to link against layout.dll for this
-I$(DEPTH)\layout\html\base\src \
!endif
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@@ -49,12 +49,10 @@ static NS_DEFINE_IID(kIRDFContentModelBuilderIID, NS_IRDFCONTENTMODELBUILDER_IID
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
class RDFHTMLBuilderImpl : public nsIRDFContentModelBuilder
{
private:
nsIRDFDocument* mDocument;
nsIRDFDocument* mDocument;
nsIRDFCompositeDataSource* mDB;
public:
@@ -66,8 +64,11 @@ public:
// nsIRDFContentModelBuilder interface
NS_IMETHOD SetDocument(nsIRDFDocument* aDocument);
NS_IMETHOD CreateRoot(nsIRDFResource* aResource);
NS_IMETHOD CreateContents(nsIRDFContent* aElement);
NS_IMETHOD SetDataBase(nsIRDFCompositeDataSource* aDataBase);
NS_IMETHOD GetDataBase(nsIRDFCompositeDataSource** aDataBase);
NS_IMETHOD CreateRootContent(nsIRDFResource* aResource);
NS_IMETHOD SetRootContent(nsIContent* aElement);
NS_IMETHOD CreateContents(nsIContent* aElement);
NS_IMETHOD OnAssert(nsIRDFContent* aElement, nsIRDFResource* aProperty, nsIRDFNode* aValue);
NS_IMETHOD OnUnassert(nsIRDFContent* aElement, nsIRDFResource* aProperty, nsIRDFNode* aValue);
@@ -79,6 +80,8 @@ public:
nsresult AddLeafChild(nsIRDFContent* parent,
nsIRDFResource* property,
nsIRDFLiteral* value);
PRBool IsTreeProperty(nsIRDFResource* aProperty);
};
////////////////////////////////////////////////////////////////////////
@@ -105,7 +108,7 @@ RDFHTMLBuilderImpl::~RDFHTMLBuilderImpl(void)
NS_RELEASE2(kIdAtom, refcnt);
NS_IF_RELEASE(mDB);
// mDocument is _not_ refcounted
// NS_IF_RELEASE(mDocument) not refcounted
}
////////////////////////////////////////////////////////////////////////
@@ -201,18 +204,48 @@ RDFHTMLBuilderImpl::SetDocument(nsIRDFDocument* aDocument)
if (! aDocument)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(mDocument == nsnull, "already initialized");
if (mDocument)
return NS_ERROR_ALREADY_INITIALIZED;
mDocument = aDocument; // not refcounted
nsresult rv;
if (NS_FAILED(rv = mDocument->GetDataBase(mDB)))
return rv;
return NS_OK;
}
NS_IMETHODIMP
RDFHTMLBuilderImpl::CreateRoot(nsIRDFResource* aResource)
RDFHTMLBuilderImpl::SetDataBase(nsIRDFCompositeDataSource* aDataBase)
{
NS_PRECONDITION(aDataBase != nsnull, "null ptr");
if (! aDataBase)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(mDB == nsnull, "already initialized");
if (mDB)
return NS_ERROR_ALREADY_INITIALIZED;
mDB = aDataBase;
NS_ADDREF(mDB);
return NS_OK;
}
NS_IMETHODIMP
RDFHTMLBuilderImpl::GetDataBase(nsIRDFCompositeDataSource** aDataBase)
{
NS_PRECONDITION(aDataBase != nsnull, "null ptr");
if (! aDataBase)
return NS_ERROR_NULL_POINTER;
*aDataBase = mDB;
NS_ADDREF(mDB);
return NS_OK;
}
NS_IMETHODIMP
RDFHTMLBuilderImpl::CreateRootContent(nsIRDFResource* aResource)
{
NS_PRECONDITION(mDocument != nsnull, "not initialized");
if (! mDocument)
@@ -259,7 +292,14 @@ done:
NS_IMETHODIMP
RDFHTMLBuilderImpl::CreateContents(nsIRDFContent* aElement)
RDFHTMLBuilderImpl::SetRootContent(nsIContent* aElement)
{
NS_NOTYETIMPLEMENTED("write me");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RDFHTMLBuilderImpl::CreateContents(nsIContent* aElement)
{
NS_NOTYETIMPLEMENTED("Adapt the implementation from RDFTreeBuilderImpl");
return NS_ERROR_NOT_IMPLEMENTED;
@@ -281,9 +321,7 @@ RDFHTMLBuilderImpl::OnAssert(nsIRDFContent* 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.
PRBool isTreeProperty;
if ((NS_SUCCEEDED(rv = mDocument->IsTreeProperty(property, &isTreeProperty)) && isTreeProperty) ||
(rdf_IsContainer(mDB, valueResource))) {
if (IsTreeProperty(property) || rdf_IsContainer(mDB, valueResource)) {
rv = AddTreeChild(parent, property, valueResource);
NS_RELEASE(valueResource);
return rv;
@@ -314,6 +352,33 @@ RDFHTMLBuilderImpl::OnUnassert(nsIRDFContent* parent,
return NS_ERROR_NOT_IMPLEMENTED;
}
PRBool
RDFHTMLBuilderImpl::IsTreeProperty(nsIRDFResource* aProperty)
{
// XXX This whole method is a mega-kludge. This should be read off
// of the element somehow...
#define TREE_PROPERTY_HACK
#if defined(TREE_PROPERTY_HACK)
const char* p;
aProperty->GetValue(&p);
nsAutoString s(p);
if (s.Equals(NC_NAMESPACE_URI "child") ||
s.Equals(NC_NAMESPACE_URI "Folder") ||
s.Equals(NC_NAMESPACE_URI "Columns") ||
s.Equals(RDF_NAMESPACE_URI "child")) {
return PR_TRUE;
}
#endif // defined(TREE_PROPERTY_HACK)
if (rdf_IsOrdinalProperty(aProperty)) {
return PR_TRUE;
}
return PR_FALSE;
}
////////////////////////////////////////////////////////////////////////
nsresult

View File

@@ -780,14 +780,22 @@ RDFResourceElementImpl::GetDocument(nsIDocument*& aResult) const
NS_IMETHODIMP
RDFResourceElementImpl::SetDocument(nsIDocument* aDocument, PRBool aDeep)
{
nsresult rv;
nsCOMPtr<nsIRDFDocument> rdfDoc;
if (mDocument) {
nsIRDFDocument* rdfDoc;
if (NS_SUCCEEDED(mDocument->QueryInterface(kIRDFDocumentIID, (void**) &rdfDoc))) {
rdfDoc->UnMapResource(mResource, NS_STATIC_CAST(nsIRDFContent*, this));
NS_RELEASE(rdfDoc);
if (NS_SUCCEEDED(mDocument->QueryInterface(kIRDFDocumentIID, getter_AddRefs(rdfDoc)))) {
rv = rdfDoc->RemoveElementForResource(mResource, this);
NS_ASSERTION(NS_SUCCEEDED(rv), "error unmapping resource from element");
}
}
mDocument = aDocument; // not refcounted
if (mDocument) {
if (NS_SUCCEEDED(mDocument->QueryInterface(kIRDFDocumentIID, getter_AddRefs(rdfDoc)))) {
rv = rdfDoc->AddElementForResource(mResource, this);
NS_ASSERTION(NS_SUCCEEDED(rv), "error mapping resource to element");
}
}
if (aDeep && mChildren) {
for (PRInt32 i = mChildren->Count() - 1; i >= 0; --i) {
@@ -808,13 +816,6 @@ RDFResourceElementImpl::SetDocument(nsIDocument* aDocument, PRBool aDeep)
NS_RELEASE(obj);
}
}
if (mDocument) {
nsIRDFDocument* rdfDoc;
if (NS_SUCCEEDED(mDocument->QueryInterface(kIRDFDocumentIID, (void**) &rdfDoc))) {
rdfDoc->MapResource(mResource, NS_STATIC_CAST(nsIRDFContent*, this));
NS_RELEASE(rdfDoc);
}
}
return NS_OK;
}
@@ -1532,11 +1533,7 @@ RDFResourceElementImpl::EnsureContentsGenerated(void) const
(void**) getter_AddRefs(rdfDoc))))
return rv;
nsCOMPtr<nsIRDFContentModelBuilder> builder;
if (NS_FAILED(rv = rdfDoc->GetContentModelBuilder(getter_AddRefs(builder))))
return rv;
rv = builder->CreateContents(unconstThis);
rv = rdfDoc->CreateContents(unconstThis);
NS_ASSERTION(NS_SUCCEEDED(rv), "problem creating kids");
return rv;
}

File diff suppressed because it is too large Load Diff

View File

@@ -21,6 +21,18 @@
An nsIRDFDocument implementation that builds a XUL content model.
TO DO
1) Make sure to hook up the code that keeps track of what content
nodes we're spying on. Ugh: one thing I just realized. By putting
this stuff in the content model builder, we've made it impossible
to cleanly release hidden nodes. We'll need a notification
mechanism for that...
2) Figure out how to drag in new builders to merge data from other
sources. I'm thinking something like just spying on the
<xul:treeitem> and <xul:treebody> tags for some magical
attribute...
*/
@@ -35,6 +47,7 @@
#include "nsIRDFCompositeDataSource.h"
#include "nsIRDFDocument.h"
#include "nsIRDFNode.h"
#include "nsIRDFObserver.h"
#include "nsIRDFService.h"
#include "nsIServiceManager.h"
#include "nsINameSpaceManager.h"
@@ -47,24 +60,29 @@
#include "rdf.h"
#include "rdfutil.h"
#if 0 // need to link against layout.dll for this...
#include "nsIHTMLContent.h"
// XXX These are needed as scaffolding until we get to a more
// DOM-based solution.
#include "nsHTMLParts.h"
#endif
#include "nsIHTMLContent.h"
////////////////////////////////////////////////////////////////////////
static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID);
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
static NS_DEFINE_IID(kINameSpaceManagerIID, NS_INAMESPACEMANAGER_IID);
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
static NS_DEFINE_IID(kIRDFContentIID, NS_IRDFCONTENT_IID);
static NS_DEFINE_IID(kIRDFContentModelBuilderIID, NS_IRDFCONTENTMODELBUILDER_IID);
static NS_DEFINE_IID(kIRDFCompositeDataSourceIID, NS_IRDFCOMPOSITEDATASOURCE_IID);
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
static NS_DEFINE_IID(kIRDFObserverIID, NS_IRDFOBSERVER_IID);
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_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(kRDFTreeBuilderCID, NS_RDFTREEBUILDER_CID);
////////////////////////////////////////////////////////////////////////
// standard vocabulary items
@@ -74,11 +92,13 @@ DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, child); // XXX bogus: needs to be NC:ch
////////////////////////////////////////////////////////////////////////
class RDFXULBuilderImpl : public nsIRDFContentModelBuilder
class RDFXULBuilderImpl : public nsIRDFContentModelBuilder,
public nsIRDFObserver
{
private:
nsIRDFCompositeDataSource* mDB;
nsIRDFDocument* mDocument;
nsIContent* mRoot;
// pseudo-constants
static PRInt32 gRefCnt;
@@ -88,6 +108,9 @@ private:
static PRInt32 kNameSpaceID_XUL;
static nsIAtom* kContentsGeneratedAtom;
static nsIAtom* kDataSourcesAtom;
static nsIAtom* kIdAtom;
static nsIAtom* kTreeAtom;
static nsIRDFResource* kRDF_type;
static nsIRDFResource* kRDF_child; // XXX needs to become kNC_child
@@ -101,10 +124,15 @@ public:
// nsIRDFContentModelBuilder interface
NS_IMETHOD SetDocument(nsIRDFDocument* aDocument);
NS_IMETHOD CreateRoot(nsIRDFResource* aResource);
NS_IMETHOD CreateContents(nsIRDFContent* aElement);
NS_IMETHOD OnAssert(nsIRDFContent* aElement, nsIRDFResource* aProperty, nsIRDFNode* aValue);
NS_IMETHOD OnUnassert(nsIRDFContent* aElement, nsIRDFResource* aProperty, nsIRDFNode* aValue);
NS_IMETHOD SetDataBase(nsIRDFCompositeDataSource* aDataBase);
NS_IMETHOD GetDataBase(nsIRDFCompositeDataSource** aDataBase);
NS_IMETHOD CreateRootContent(nsIRDFResource* aResource);
NS_IMETHOD SetRootContent(nsIContent* aResource);
NS_IMETHOD CreateContents(nsIContent* aElement);
// nsIRDFObserver interface
NS_IMETHOD OnAssert(nsIRDFResource* aSubject, nsIRDFResource* aPredicate, nsIRDFNode* aObject);
NS_IMETHOD OnUnassert(nsIRDFResource* aSubject, nsIRDFResource* aPredicate, nsIRDFNode* aObjetct);
// Implementation methods
nsresult AppendChild(nsIContent* aElement,
@@ -128,9 +156,13 @@ public:
nsresult AddAttribute(nsIContent* aElement,
nsIRDFResource* aProperty,
nsIRDFNode* aValue);
nsresult CreateTreeBuilder(nsIContent* aElement,
const nsString& aDataSources);
};
////////////////////////////////////////////////////////////////////////
// Pseudo-constants
PRInt32 RDFXULBuilderImpl::gRefCnt = 0;
nsIRDFService* RDFXULBuilderImpl::gRDFService = nsnull;
@@ -139,6 +171,9 @@ PRInt32 RDFXULBuilderImpl::kNameSpaceID_RDF = kNameSpaceID_Unknown;
PRInt32 RDFXULBuilderImpl::kNameSpaceID_XUL = kNameSpaceID_Unknown;
nsIAtom* RDFXULBuilderImpl::kContentsGeneratedAtom = nsnull;
nsIAtom* RDFXULBuilderImpl::kIdAtom = nsnull;
nsIAtom* RDFXULBuilderImpl::kDataSourcesAtom = nsnull;
nsIAtom* RDFXULBuilderImpl::kTreeAtom = nsnull;
nsIRDFResource* RDFXULBuilderImpl::kRDF_type = nsnull;
nsIRDFResource* RDFXULBuilderImpl::kRDF_child = nsnull;
@@ -162,9 +197,10 @@ NS_NewRDFXULBuilder(nsIRDFContentModelBuilder** result)
}
RDFXULBuilderImpl::RDFXULBuilderImpl(void)
: mDB(nsnull)
: mDB(nsnull),
mDocument(nsnull),
mRoot(nsnull)
{
NS_INIT_REFCNT();
@@ -195,6 +231,11 @@ static const char kRDFNameSpaceURI[]
NS_ERROR("couldn't create namepsace manager");
}
kContentsGeneratedAtom = NS_NewAtom("contentsGenerated");
kIdAtom = NS_NewAtom("ID");
kDataSourcesAtom = NS_NewAtom("datasources");
kTreeAtom = NS_NewAtom("tree");
if (NS_SUCCEEDED(rv = nsServiceManager::GetService(kRDFServiceCID,
kIRDFServiceIID,
@@ -207,16 +248,16 @@ static const char kRDFNameSpaceURI[]
"unable to get resource");
}
else {
NS_ERROR("couldnt' get RDF service");
NS_ERROR("couldn't get RDF service");
}
kContentsGeneratedAtom = NS_NewAtom("contentsGenerated");
}
}
RDFXULBuilderImpl::~RDFXULBuilderImpl(void)
{
NS_IF_RELEASE(mRoot);
NS_IF_RELEASE(mDB);
// NS_IF_RELEASE(mDocument) not refcounted
if (--gRefCnt == 0) {
if (gRDFService)
@@ -224,13 +265,42 @@ RDFXULBuilderImpl::~RDFXULBuilderImpl(void)
NS_IF_RELEASE(kRDF_type);
NS_IF_RELEASE(kRDF_child);
NS_IF_RELEASE(kContentsGeneratedAtom);
NS_IF_RELEASE(kIdAtom);
NS_IF_RELEASE(kDataSourcesAtom);
NS_IF_RELEASE(kTreeAtom);
}
}
////////////////////////////////////////////////////////////////////////
NS_IMPL_ISUPPORTS(RDFXULBuilderImpl, kIRDFContentModelBuilderIID);
NS_IMPL_ADDREF(RDFXULBuilderImpl);
NS_IMPL_RELEASE(RDFXULBuilderImpl);
NS_IMETHODIMP
RDFXULBuilderImpl::QueryInterface(REFNSIID iid, void** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(kIRDFContentModelBuilderIID) ||
iid.Equals(kISupportsIID)) {
*aResult = NS_STATIC_CAST(nsIRDFContentModelBuilder*, this);
NS_ADDREF(this);
return NS_OK;
}
else if (iid.Equals(kIRDFObserverIID)) {
*aResult = NS_STATIC_CAST(nsIRDFObserver*, this);
NS_ADDREF(this);
return NS_OK;
}
else {
*aResult = nsnull;
return NS_NOINTERFACE;
}
}
////////////////////////////////////////////////////////////////////////
// nsIRDFContentModelBuilder methods
@@ -242,17 +312,45 @@ RDFXULBuilderImpl::SetDocument(nsIRDFDocument* aDocument)
if (! aDocument)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(mDocument == nsnull, "already initialized");
if (mDocument)
return NS_ERROR_ALREADY_INITIALIZED;
mDocument = aDocument; // not refcounted
nsresult rv;
if (NS_FAILED(rv = mDocument->GetDataBase(mDB)))
return rv;
return NS_OK;
}
NS_IMETHODIMP
RDFXULBuilderImpl::CreateRoot(nsIRDFResource* aResource)
RDFXULBuilderImpl::SetDataBase(nsIRDFCompositeDataSource* aDataBase)
{
NS_PRECONDITION(aDataBase != nsnull, "null ptr");
if (! aDataBase)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(mDB == nsnull, "already initialized");
if (mDB)
return NS_ERROR_ALREADY_INITIALIZED;
mDB = aDataBase;
NS_ADDREF(mDB);
return NS_OK;
}
NS_IMETHODIMP
RDFXULBuilderImpl::GetDataBase(nsIRDFCompositeDataSource** aDataBase)
{
NS_PRECONDITION(aDataBase != nsnull, "null ptr");
if (! aDataBase)
return NS_ERROR_NULL_POINTER;
*aDataBase = mDB;
NS_ADDREF(mDB);
return NS_OK;
}
NS_IMETHODIMP
RDFXULBuilderImpl::CreateRootContent(nsIRDFResource* aResource)
{
NS_PRECONDITION(mDocument != nsnull, "not initialized");
if (! mDocument)
@@ -280,15 +378,30 @@ RDFXULBuilderImpl::CreateRoot(nsIRDFResource* aResource)
doc->SetRootContent(root);
mRoot = root;
NS_ADDREF(mRoot);
return NS_OK;
}
NS_IMETHODIMP
RDFXULBuilderImpl::CreateContents(nsIRDFContent* aElement)
RDFXULBuilderImpl::SetRootContent(nsIContent* aElement)
{
NS_IF_RELEASE(mRoot);
mRoot = aElement;
NS_IF_ADDREF(mRoot);
return NS_OK;
}
NS_IMETHODIMP
RDFXULBuilderImpl::CreateContents(nsIContent* aElement)
{
nsresult rv;
// First, mark the elements contents as being generated so that
// any re-entrant calls don't trigger an infinite recursion.
if (NS_FAILED(rv = aElement->SetAttribute(kNameSpaceID_XUL,
kContentsGeneratedAtom,
"true",
@@ -297,12 +410,33 @@ RDFXULBuilderImpl::CreateContents(nsIRDFContent* aElement)
return rv;
}
nsCOMPtr<nsIRDFResource> resource;
if (NS_FAILED(rv = aElement->GetResource(*getter_AddRefs(resource)))) {
NS_ERROR("unable to get resource from element");
// Get the treeitem's resource so that we can generate cell
// values. We could QI for the nsIRDFResource here, but doing this
// via the nsIContent interface allows us to support generic nodes
// that might get added in by DOM calls.
nsAutoString uri;
if (NS_FAILED(rv = aElement->GetAttribute(kNameSpaceID_RDF,
kIdAtom,
uri))) {
NS_ERROR("severe error retrieving attribute");
return rv;
}
if (rv != NS_CONTENT_ATTR_HAS_VALUE) {
NS_ERROR("tree element has no RDF:ID");
return NS_ERROR_UNEXPECTED;
}
nsCOMPtr<nsIRDFResource> resource;
if (NS_FAILED(rv = gRDFService->GetUnicodeResource(uri, getter_AddRefs(resource)))) {
NS_ERROR("unable to create resource");
return rv;
}
// Iterate through all of the XUL:child arcs, and construct
// appropriate children for each arc.
//
// XXX this is RDF:child for now; we should fix that...
nsCOMPtr<nsIRDFAssertionCursor> children;
if (NS_FAILED(rv = mDB->GetTargets(resource, kRDF_child, PR_TRUE, getter_AddRefs(children)))) {
NS_ERROR("unable to create cursor for children");
@@ -330,52 +464,75 @@ RDFXULBuilderImpl::CreateContents(nsIRDFContent* aElement)
NS_IMETHODIMP
RDFXULBuilderImpl::OnAssert(nsIRDFContent* aElement,
nsIRDFResource* aProperty,
nsIRDFNode* aValue)
RDFXULBuilderImpl::OnAssert(nsIRDFResource* aSubject,
nsIRDFResource* aPredicate,
nsIRDFNode* aObject)
{
NS_PRECONDITION(mDocument != nsnull, "not initialized");
if (! mDocument)
return NS_ERROR_NOT_INITIALIZED;
nsresult rv;
if (aProperty == kRDF_child) {
// 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;
if (NS_FAILED(rv = aElement->GetAttribute(kNameSpaceID_XUL,
kContentsGeneratedAtom,
contentsGenerated))) {
if (rv == NS_CONTENT_ATTR_NOT_THERE) {
return NS_OK;
}
else {
nsCOMPtr<nsISupportsArray> elements;
if (NS_FAILED(rv = NS_NewISupportsArray(getter_AddRefs(elements)))) {
NS_ERROR("unable to create new ISupportsArray");
return rv;
}
// Find all the elements in the content model that correspond to
// aSubject: for each, we'll try to build XUL children if
// appropriate.
if (NS_FAILED(rv = mDocument->GetElementsForResource(aSubject, elements))) {
NS_ERROR("unable to retrieve elements from resource");
return rv;
}
for (PRInt32 i = elements->Count() - 1; i >= 0; --i) {
nsCOMPtr<nsIContent> element(elements->ElementAt(i));
// XXX somehow figure out if building XUL kids on this
// particular element makes any sense whatsoever.
if (aPredicate == kRDF_child) {
// 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;
if (NS_FAILED(rv = element->GetAttribute(kNameSpaceID_XUL,
kContentsGeneratedAtom,
contentsGenerated))) {
NS_ERROR("severe problem trying to get attribute");
return rv;
}
}
if (! contentsGenerated.EqualsIgnoreCase("true"))
return NS_OK;
if (rv == NS_CONTENT_ATTR_NOT_THERE || rv == NS_CONTENT_ATTR_NO_VALUE)
continue;
// Okay, it's a "live" element, so go ahead and append the new
// child to this node.
if (NS_FAILED(AppendChild(aElement, aValue))) {
NS_ERROR("problem appending child to content model");
return rv;
if (! contentsGenerated.EqualsIgnoreCase("true"))
continue;
// Okay, it's a "live" element, so go ahead and append the new
// child to this node.
if (NS_FAILED(AppendChild(element, aObject))) {
NS_ERROR("problem appending child to content model");
return rv;
}
}
}
else if (aProperty == kRDF_type) {
// We shouldn't ever see this: if we do, there ain't much we
// can do.
NS_ERROR("attempt to change tag type after-the-fact");
return NS_ERROR_UNEXPECTED;
}
else {
// Add the thing as a vanilla attribute to the element.
if (NS_FAILED(rv = AddAttribute(aElement, aProperty, aValue))) {
NS_ERROR("unable to add attribute to the element");
return rv;
else if (aPredicate == kRDF_type) {
// We shouldn't ever see this: if we do, there ain't much we
// can do.
NS_ERROR("attempt to change tag type after-the-fact");
return NS_ERROR_UNEXPECTED;
}
else {
// Add the thing as a vanilla attribute to the element.
if (NS_FAILED(rv = AddAttribute(element, aPredicate, aObject))) {
NS_ERROR("unable to add attribute to the element");
return rv;
}
}
}
return NS_OK;
@@ -383,9 +540,9 @@ RDFXULBuilderImpl::OnAssert(nsIRDFContent* aElement,
NS_IMETHODIMP
RDFXULBuilderImpl::OnUnassert(nsIRDFContent* aElement,
nsIRDFResource* aProperty,
nsIRDFNode* aValue)
RDFXULBuilderImpl::OnUnassert(nsIRDFResource* aSubject,
nsIRDFResource* aPredicate,
nsIRDFNode* aObject)
{
NS_NOTYETIMPLEMENTED("write me!");
return NS_ERROR_NOT_IMPLEMENTED;
@@ -467,10 +624,12 @@ RDFXULBuilderImpl::CreateElement(nsIRDFResource* aResource,
return rv;
}
if (nameSpaceID == kNameSpaceID_HTML)
if (nameSpaceID == kNameSpaceID_HTML) {
return CreateHTMLElement(aResource, tag, aResult);
else
}
else {
return CreateXULElement(aResource, nameSpaceID, tag, aResult);
}
}
nsresult
@@ -478,17 +637,33 @@ RDFXULBuilderImpl::CreateHTMLElement(nsIRDFResource* aResource,
nsIAtom* aTag,
nsIContent** aResult)
{
NS_NOTYETIMPLEMENTED("need to link against layout.dll for this to work");
#if 0
nsresult rv;
// XXX This is where we go out and create the HTML content. It's a
// bit of a hack: a bridge until we get to a more DOM-based
// solution.
nsCOMPtr<nsIHTMLContent> element;
if (NS_FAILED(rv = NS_CreateHTMLElement(getter_AddRefs(element), aTag->GetUnicode()))) {
NS_ERROR("unable to create HTML element");
return rv;
}
{
// Force the document to be set _here_. Many of the
// AppendChildTo() implementations do not recursively ensure
// that the child's doc is the same as the parent's.
nsCOMPtr<nsIDocument> doc;
if (NS_FAILED(rv = mDocument->QueryInterface(kIDocumentIID, getter_AddRefs(doc)))) {
NS_ERROR("uh, this isn't a document!");
return rv;
}
if (NS_FAILED(rv = element->SetDocument(doc, PR_FALSE))) {
NS_ERROR("couldn't set document on the element");
return rv;
}
}
// Now iterate through all the properties and add them as
// attributes on the element. First, create a cursor that'll
// iterate through all the properties that lead out of this
@@ -548,7 +723,6 @@ RDFXULBuilderImpl::CreateHTMLElement(nsIRDFResource* aResource,
NS_ERROR("unable to get nsIContent interface");
return rv;
}
#endif
return NS_OK;
}
@@ -658,6 +832,18 @@ RDFXULBuilderImpl::CreateXULElement(nsIRDFResource* aResource,
return rv;
}
// There are some tags that we need to pay extra-special attention to...
if (aTag == kTreeAtom) {
nsAutoString dataSources;
if (NS_CONTENT_ATTR_HAS_VALUE ==
element->GetAttribute(kNameSpaceID_XUL,
kDataSourcesAtom,
dataSources)) {
rv = CreateTreeBuilder(element, dataSources);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to add datasources");
}
}
// Finally, assign the newly constructed element to the result
// pointer and addref it for the trip home.
*aResult = element;
@@ -709,3 +895,102 @@ RDFXULBuilderImpl::AddAttribute(nsIContent* aElement,
return rv;
}
nsresult
RDFXULBuilderImpl::CreateTreeBuilder(nsIContent* aElement,
const nsString& aDataSources)
{
nsresult rv;
// construct a new builder
nsCOMPtr<nsIRDFContentModelBuilder> builder;
if (NS_FAILED(rv = nsRepository::CreateInstance(kRDFTreeBuilderCID,
nsnull,
kIRDFContentModelBuilderIID,
(void**) getter_AddRefs(builder)))) {
NS_ERROR("unable to create tree content model builder");
return rv;
}
if (NS_FAILED(rv = builder->SetRootContent(aElement))) {
NS_ERROR("unable to set builder's root content element");
return rv;
}
// create a database for the builder
nsCOMPtr<nsIRDFCompositeDataSource> db;
if (NS_FAILED(rv = nsRepository::CreateInstance(kRDFCompositeDataSourceCID,
nsnull,
kIRDFCompositeDataSourceIID,
(void**) getter_AddRefs(db)))) {
NS_ERROR("unable to construct new composite data source");
return rv;
}
// Parse datasources: they are assumed to be a whitespace
// separated list of URIs; e.g.,
//
// rdf:bookmarks rdf:history http://foo.bar.com/blah.cgi?baz=9
//
PRInt32 first = 0;
while(1) {
while (first < aDataSources.Length() && nsString::IsSpace(aDataSources[first]))
++first;
if (first >= aDataSources.Length())
break;
PRInt32 last = first;
while (last < aDataSources.Length() && !nsString::IsSpace(aDataSources[last]))
++last;
nsAutoString uri;
aDataSources.Mid(uri, first, last - first);
first = last + 1;
nsCOMPtr<nsIRDFDataSource> ds;
// Some monkey business to convert the nsAutoString to a
// C-string safely. Sure'd be nice to have this be automagic.
{
char buf[256], *p = buf;
if (uri.Length() >= sizeof(buf))
p = new char[uri.Length() + 1];
uri.ToCString(p, uri.Length() + 1);
rv = gRDFService->GetDataSource(p, getter_AddRefs(ds));
if (p != buf)
delete[] p;
}
if (NS_FAILED(rv)) {
// This is only a warning because the data source may not
// be accessable for any number of reasons, including
// security, a bad URL, etc.
NS_WARNING("unable to load datasource");
continue;
}
if (NS_FAILED(rv = db->AddDataSource(ds))) {
NS_ERROR("unable to add datasource to composite data source");
return rv;
}
}
if (NS_FAILED(rv = builder->SetDataBase(db))) {
NS_ERROR("unable to set builder's database");
return rv;
}
// add it to the set of builders in use by the document
if (NS_FAILED(rv = mDocument->AddContentModelBuilder(builder))) {
NS_ERROR("unable to add builder to the document");
return rv;
}
return NS_OK;
}

File diff suppressed because it is too large Load Diff

View File

@@ -29,7 +29,8 @@ LIBRARY_NAME = rdfdatasource_s
CPPSRCS = \
nsBookmarkDataSource.cpp \
nsMailDataSource.cpp \
nsXULDataSource.cpp \
nsXULContentSink.cpp \
nsXULDataSource.cpp \
$(NULL)
EXPORTS = \

View File

@@ -22,7 +22,8 @@ LIBRARY_NAME=rdfdatasource_s
CPP_OBJS=\
.\$(OBJDIR)\nsBookmarkDataSource.obj \
.\$(OBJDIR)\nsMailDataSource.obj \
.\$(OBJDIR)\nsXULDataSource.obj \
.\$(OBJDIR)\nsXULContentSink.obj \
.\$(OBJDIR)\nsXULDataSource.obj \
$(NULL)
# XXX Note the dependency on $(DEPTH)\rdf\base\src: we use rdfutil.h over

View File

@@ -45,7 +45,8 @@ 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 const char kURINC_BookmarksRoot[] = "NC:BookmarksRoot"; // XXX?
static const char kURINC_BookmarksRoot[] = "NC:BookmarksRoot"; // XXX?
static const char kURINC_PersonalToolbarFolder[] = "NC:PersonalToolbarFolder"; // XXX?
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, child);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, BookmarkAddDate);
@@ -210,10 +211,16 @@ BookmarkParser::NextToken(void)
if (mStack.Count() > 0) {
// a regular old folder
nsAutoString folderURI(kURINC_BookmarksRoot);
folderURI.Append('#');
folderURI.Append(++mCounter, 10);
nsAutoString folderURI;
if (mLine.Find(kPersonalToolbar) == 0) {
folderURI = kURINC_PersonalToolbarFolder;
}
else {
folderURI = kURINC_BookmarksRoot;
folderURI.Append('#');
folderURI.Append(++mCounter, 10);
}
if (NS_FAILED(mRDFService->GetUnicodeResource(folderURI, &folder)))
return;
@@ -240,9 +247,6 @@ BookmarkParser::NextToken(void)
if (mState != eBookmarkParserState_InTitle)
rdf_Assert(mDataSource, mLastItem, kURINC_Name, mLine);
if (mLine.Find(kPersonalToolbar) == 0)
rdf_Assert(mDataSource, mLastItem, kURIRDF_instanceOf, kURINC_PersonalToolbarFolderCategory);
}
else if (mState == eBookmarkParserState_InItemTitle) {
PR_ASSERT(mLastItem);

View File

@@ -342,14 +342,13 @@ public:
protected:
static nsrefcnt gRefCnt;
static nsINameSpaceManager* gNameSpaceManager;
static nsIRDFService* gRDFService;
// pseudo-constants
static nsIRDFResource* kRDF_child; // XXX needs to be NC:child (or something else)
static nsIRDFResource* kRDF_type;
static nsresult
nsresult
MakeResourceFromQualifiedTag(PRInt32 aNameSpaceID,
const nsString& aTag,
nsIRDFResource** aResource);
@@ -369,6 +368,7 @@ protected:
PRInt32 GetNameSpaceID(nsIAtom* aPrefix);
void PopNameSpaces();
nsINameSpaceManager* mNameSpaceManager;
nsVoidArray* mNameSpaceStack;
void SplitQualifiedName(const nsString& aQualifiedName,
@@ -398,7 +398,6 @@ protected:
};
nsrefcnt XULContentSinkImpl::gRefCnt = 0;
nsINameSpaceManager* XULContentSinkImpl::gNameSpaceManager = nsnull;
nsIRDFService* XULContentSinkImpl::gRDFService = nsnull;
nsIRDFResource* XULContentSinkImpl::kRDF_child = nsnull;
@@ -422,13 +421,6 @@ XULContentSinkImpl::XULContentSinkImpl()
if (gRefCnt++ == 0) {
nsresult rv;
rv = nsRepository::CreateInstance(kNameSpaceManagerCID,
nsnull,
kINameSpaceManagerIID,
(void**) &gNameSpaceManager);
NS_VERIFY(NS_SUCCEEDED(rv), "unable to construct namespace manager");
rv = nsServiceManager::GetService(kRDFServiceCID,
kIRDFServiceIID,
(nsISupports**) &gRDFService);
@@ -446,6 +438,7 @@ XULContentSinkImpl::XULContentSinkImpl()
XULContentSinkImpl::~XULContentSinkImpl()
{
NS_IF_RELEASE(mNameSpaceManager);
NS_IF_RELEASE(mDocumentURL);
NS_IF_RELEASE(mDataSource);
@@ -481,7 +474,6 @@ XULContentSinkImpl::~XULContentSinkImpl()
if (--gRefCnt == 0) {
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
NS_IF_RELEASE(gNameSpaceManager);
NS_IF_RELEASE(kRDF_child);
NS_IF_RELEASE(kRDF_type);
}
@@ -522,7 +514,7 @@ XULContentSinkImpl::MakeResourceFromQualifiedTag(PRInt32 aNameSpaceID,
nsresult rv;
nsAutoString uri;
rv = gNameSpaceManager->GetNameSpaceURI(aNameSpaceID, uri);
rv = mNameSpaceManager->GetNameSpaceURI(aNameSpaceID, uri);
NS_VERIFY(NS_SUCCEEDED(rv), "unable to get namespace URI");
// some hacky logic to try to construct an appopriate URI for the
@@ -832,13 +824,16 @@ XULContentSinkImpl::Init(nsIURL* aURL, nsINameSpaceManager* aNameSpaceManager)
mDocumentURL = aURL;
NS_ADDREF(aURL);
mNameSpaceManager = aNameSpaceManager;
NS_ADDREF(aNameSpaceManager);
nsresult rv;
// XXX This is sure to change. Copied from mozilla/layout/xul/content/src/nsXULAtoms.cpp
static const char kXULNameSpaceURI[]
= "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
rv = gNameSpaceManager->RegisterNameSpace(kXULNameSpaceURI, kNameSpaceID_XUL);
rv = mNameSpaceManager->RegisterNameSpace(kXULNameSpaceURI, kNameSpaceID_XUL);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to register XUL namespace");
if (NS_FAILED(rv = nsServiceManager::GetService(kRDFServiceCID,
@@ -1027,7 +1022,7 @@ XULContentSinkImpl::AddAttributes(const nsIParserNode& aNode,
// Get the URI for the namespace, so we can construct a
// fully-qualified property name.
gNameSpaceManager->GetNameSpaceURI(nameSpaceID, k);
mNameSpaceManager->GetNameSpaceURI(nameSpaceID, k);
// Insert a '#' if the namespace doesn't end with one, or the
// attribute doesn't start with one.
@@ -1201,7 +1196,7 @@ XULContentSinkImpl::PushNameSpacesFrom(const nsIParserNode& aNode)
NS_ADDREF(nameSpace);
}
else {
gNameSpaceManager->CreateRootNameSpace(nameSpace);
mNameSpaceManager->CreateRootNameSpace(nameSpace);
}
if (nsnull != nameSpace) {

View File

@@ -109,7 +109,6 @@ protected:
nsIRDFResource* mRootResource;
PRBool mIsLoading; // true while the document is loading
NameSpaceMap* mNameSpaces;
nsID mContentModelBuilderCID;
public:
XULDataSourceImpl(void);
@@ -225,8 +224,6 @@ public:
NS_IMETHOD AddNamedDataSourceURI(const char* aNamedDataSourceURI);
NS_IMETHOD GetNamedDataSourceURIs(const char* const** aNamedDataSourceURIs, PRInt32* aCount);
NS_IMETHOD AddNameSpace(nsIAtom* aPrefix, const nsString& aURI);
NS_IMETHOD SetContentModelBuilderCID(nsID* aCID);
NS_IMETHOD GetContentModelBuilderCID(nsID* aCID);
NS_IMETHOD AddXMLStreamObserver(nsIRDFXMLDataSourceObserver* aObserver);
NS_IMETHOD RemoveXMLStreamObserver(nsIRDFXMLDataSourceObserver* aObserver);
};
@@ -625,26 +622,6 @@ XULDataSourceImpl::AddNameSpace(nsIAtom* aPrefix, const nsString& aURI)
}
NS_IMETHODIMP
XULDataSourceImpl::SetContentModelBuilderCID(nsID* aCID)
{
mContentModelBuilderCID = *aCID;
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
nsIRDFXMLDataSourceObserver* obs = (nsIRDFXMLDataSourceObserver*) mObservers[i];
obs->OnContentModelBuilderSpecified(this, &mContentModelBuilderCID);
}
return NS_OK;
}
NS_IMETHODIMP
XULDataSourceImpl::GetContentModelBuilderCID(nsID* aCID)
{
*aCID = mContentModelBuilderCID;
return NS_OK;
}
NS_IMETHODIMP
XULDataSourceImpl::AddXMLStreamObserver(nsIRDFXMLDataSourceObserver* aObserver)
{

Binary file not shown.

View File

@@ -17,3 +17,5 @@ mozilla/rdf/content/src/nsRDFTreeBuilder.cpp
mozilla/rdf/content/src/nsRDFXULBuilder.cpp
mozilla/rdf/datasource/src/nsBookmarkDataSource.cpp
mozilla/rdf/datasource/src/nsMailDataSource.cpp
mozilla/rdf/datasource/src/nsXULContentSink.cpp
mozilla/rdf/datasource/src/nsXULDataSource.cpp