Rearranged stream and content sink stuff to be a part of base: content sink will eventually be replaced by a lower-level parser implementation. Improved the named data source handling.

This commit is contained in:
waterson%netscape.com 1999-01-14 10:55:08 +00:00
Родитель 8d41d4b0cc
Коммит d3b9f0cf03
32 изменённых файлов: 1291 добавлений и 785 удалений

Просмотреть файл

@ -1,4 +1,5 @@
rdf.h rdf.h
nsIRDFContentSink.h
nsIRDFCursor.h nsIRDFCursor.h
nsIRDFDataBase.h nsIRDFDataBase.h
nsIRDFDataSource.h nsIRDFDataSource.h
@ -6,4 +7,5 @@ nsIRDFNode.h
nsIRDFObserver.h nsIRDFObserver.h
nsIRDFResourceFactory.h nsIRDFResourceFactory.h
nsIRDFService.h nsIRDFService.h
nsIRDFXMLDocument.h
nsIRDFXMLSource.h nsIRDFXMLSource.h

Просмотреть файл

@ -26,6 +26,7 @@ MODULE = rdf
EXPORTS = \ EXPORTS = \
rdf.h \ rdf.h \
nsIRDFContentSink.h \
nsIRDFCursor.h \ nsIRDFCursor.h \
nsIRDFDataBase.h \ nsIRDFDataBase.h \
nsIRDFDataSource.h \ nsIRDFDataSource.h \
@ -33,6 +34,7 @@ EXPORTS = \
nsIRDFObserver.h \ nsIRDFObserver.h \
nsIRDFResourceFactory.h \ nsIRDFResourceFactory.h \
nsIRDFService.h \ nsIRDFService.h \
nsIRDFXMLDocument.h \
nsIRDFXMLSource.h \ nsIRDFXMLSource.h \
$(NULL) $(NULL)

Просмотреть файл

@ -23,6 +23,7 @@ DEPTH=..\..\..
EXPORTS=\ EXPORTS=\
rdf.h \ rdf.h \
nsIRDFContentSink.h \
nsIRDFCursor.h \ nsIRDFCursor.h \
nsIRDFDataBase.h \ nsIRDFDataBase.h \
nsIRDFDataSource.h \ nsIRDFDataSource.h \
@ -30,6 +31,7 @@ EXPORTS=\
nsIRDFObserver.h \ nsIRDFObserver.h \
nsIRDFResourceFactory.h \ nsIRDFResourceFactory.h \
nsIRDFService.h \ nsIRDFService.h \
nsIRDFXMLDocument.h \
nsIRDFXMLSource.h \ nsIRDFXMLSource.h \
$(NULL) $(NULL)

Просмотреть файл

@ -30,9 +30,9 @@
#include "nsIXMLContentSink.h" #include "nsIXMLContentSink.h"
class nsIDocument; class nsIDocument;
class nsIRDFDataSource; class nsIRDFDataSource;
class nsIRDFXMLDocument;
class nsINameSpaceManager; class nsINameSpaceManager;
class nsIURL; class nsIURL;
class nsIWebShell;
// {751843E2-8309-11d2-8EAC-00805F29F370} // {751843E2-8309-11d2-8EAC-00805F29F370}
#define NS_IRDFCONTENTSINK_IID \ #define NS_IRDFCONTENTSINK_IID \
@ -58,26 +58,17 @@ public:
* Retrieve the content sink's RDF data source. * Retrieve the content sink's RDF data source.
*/ */
NS_IMETHOD GetDataSource(nsIRDFDataSource*& rDataSource) = 0; NS_IMETHOD GetDataSource(nsIRDFDataSource*& rDataSource) = 0;
NS_IMETHOD SetRDFXMLDocument(nsIRDFXMLDocument* aDocument) = 0;
}; };
/**
* This constructs a content sink that is intended to be used
* with an nsIDocument to construct a content model.
*/
nsresult
NS_NewRDFDocumentContentSink(nsIRDFContentSink** aResult,
nsIDocument* aDoc,
nsIURL* aURL,
nsIWebShell* aWebShell);
/** /**
* This constructs a content sink that can be used without a * This constructs a content sink that can be used without a
* document, say, to create a stand-alone in-memory graph. * document, say, to create a stand-alone in-memory graph.
*/ */
nsresult nsresult
NS_NewRDFSimpleContentSink(nsIRDFContentSink** aResult); NS_NewRDFContentSink(nsIRDFContentSink** aResult);
#endif // nsIRDFContentSink_h___ #endif // nsIRDFContentSink_h___

Просмотреть файл

@ -43,6 +43,8 @@ class nsIRDFLiteral;
class nsIRDFResource; class nsIRDFResource;
class nsIRDFResourceFactory; class nsIRDFResourceFactory;
typedef nsresult (*NSDataSourceConstructorCallback)(nsIRDFDataSource** aResult);
class nsIRDFService : public nsISupports { class nsIRDFService : public nsISupports {
public: public:
@ -99,19 +101,50 @@ public:
// Data source management routines // Data source management routines
/** /**
* Register a <i>named data source</i> with the specified URI. * Register a <i>named data source</i>. The RDF service will call
* <tt>nsIRDFDataSource::GetURI()</tt> to determine the URI under which to
* register the data source.
*
* Note that the data source will <i>not</i> be refcounted by the
* RDF service! The assumption is that an RDF data source registers
* with the service once it is initialized (via <tt>nsIRDFDataSource::Init()</tt>),
* and unregisters when the last reference to the data source is
* released.
*/ */
NS_IMETHOD RegisterNamedDataSource(const char* uri, nsIRDFDataSource* dataSource) = 0; NS_IMETHOD RegisterDataSource(nsIRDFDataSource* dataSource) = 0;
/** /**
* Unregister a <i>named data source</i>. * Unregister a <i>named data source</i>. The RDF service will call
* <tt>nsIRDFDataSource::GetURI()</tt> to determine the URI under which the
* data source was registered.
*/ */
NS_IMETHOD UnRegisterNamedDataSource(const char* uri) = 0; NS_IMETHOD UnregisterDataSource(nsIRDFDataSource* dataSource) = 0;
/** /**
* Get the <i>named data source</i> corresponding to the URI. * Register a constructor function that will create a named data source.
* The RDF service will call this function to attempt to create a
* named data source.
*/
NS_IMETHOD RegisterDataSourceConstructor(const char* aURI, NSDataSourceConstructorCallback aFn) = 0;
/**
* Unregister the constructor function for a named data source.
*/
NS_IMETHOD UnregisterDataSourceConstructor(const char* aURI) = 0;
/**
* Get the <i>named data source</i> corresponding to the URI. If a data
* source has been registered via <tt>RegisterDataSource()</tt>, that
* data source will be returned.
*
* If no data source is currently
* registered for the specified URI, and a data source <i>constructor</i>
* function has been registered via <tt>RegisterDatasourceConstructor()</tt>,
* the RDF service will call the constructor to attempt to construct a
* new data source. If construction is successful, the data source will
* be initialized via <tt>nsIRDFDataSource::Init()</tt>.
*/ */
NS_IMETHOD GetNamedDataSource(const char* uri, nsIRDFDataSource** dataSource) = 0; NS_IMETHOD GetDataSource(const char* uri, nsIRDFDataSource** dataSource) = 0;
/** /**
* Create a database that contains the specified named data * Create a database that contains the specified named data

Просмотреть файл

@ -0,0 +1,75 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
This interface encapsulates information about an RDF/XML file,
including the root resource, CSS style sheets, and named data
sources.
*/
#ifndef nsIRDFXMLDocument_h__
#define nsIRDFXMLDocument_h__
#include "nsISupports.h"
class nsIOutputStream;
class nsIURL;
// {EB1A5D30-AB33-11d2-8EC6-00805F29F370}
#define NS_IRDFXMLDOCUMENTOBSERVER_IID \
{ 0xeb1a5d30, 0xab33, 0x11d2, { 0x8e, 0xc6, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
class nsIRDFXMLDocumentObserver : public nsISupports
{
public:
NS_IMETHOD OnBeginLoad(void) = 0;
NS_IMETHOD OnInterrupt(void) = 0;
NS_IMETHOD OnResume(void) = 0;
NS_IMETHOD OnEndLoad(void) = 0;
NS_IMETHOD OnRootResourceFound(nsIRDFResource* aResource) = 0;
NS_IMETHOD OnCSSStyleSheetAdded(nsIURL* aCSSStyleSheetURL) = 0;
NS_IMETHOD OnNamedDataSourceAdded(const char* aNamedDataSourceURI) = 0;
};
// {EB1A5D31-AB33-11d2-8EC6-00805F29F370}
#define NS_IRDFXMLDOCUMENT_IID \
{ 0xeb1a5d31, 0xab33, 0x11d2, { 0x8e, 0xc6, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
class nsIRDFXMLDocument : public nsISupports
{
public:
NS_IMETHOD BeginLoad(void) = 0;
NS_IMETHOD Interrupt(void) = 0;
NS_IMETHOD Resume(void) = 0;
NS_IMETHOD EndLoad(void) = 0;
NS_IMETHOD SetRootResource(nsIRDFResource* aResource) = 0;
NS_IMETHOD GetRootResource(nsIRDFResource** aResource) = 0;
NS_IMETHOD AddCSSStyleSheetURL(nsIURL* aStyleSheetURL) = 0;
NS_IMETHOD GetCSSStyleSheetURLs(nsIURL*** aStyleSheetURLs, PRInt32* aCount) = 0;
NS_IMETHOD AddNamedDataSourceURI(const char* aNamedDataSourceURI) = 0;
NS_IMETHOD GetNamedDataSourceURIs(const char* const** aNamedDataSourceURIs, PRInt32* aCount) = 0;
NS_IMETHOD AddDocumentObserver(nsIRDFXMLDocumentObserver* aObserver) = 0;
NS_IMETHOD RemoveDocumentObserver(nsIRDFXMLDocumentObserver* aObserver) = 0;
};
#endif // nsIRDFXMLDocument_h__

Просмотреть файл

@ -32,7 +32,9 @@ CPPSRCS = \
nsDefaultResourceFactory.cpp \ nsDefaultResourceFactory.cpp \
nsEmptyCursor.cpp \ nsEmptyCursor.cpp \
nsInMemoryDataSource.cpp \ nsInMemoryDataSource.cpp \
nsRDFContentSink.cpp \
nsRDFService.cpp \ nsRDFService.cpp \
nsStreamDataSource.cpp \
rdfutil.cpp \ rdfutil.cpp \
$(NULL) $(NULL)
@ -43,7 +45,7 @@ EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
MODULE = rdfbase MODULE = rdfbase
REQUIRES = rdf raptor xpcom REQUIRES = netlib rdf raptor xpcom
MKSHLIB := MKSHLIB :=

Просмотреть файл

@ -25,13 +25,16 @@ CPP_OBJS=\
.\$(OBJDIR)\nsDefaultResourceFactory.obj \ .\$(OBJDIR)\nsDefaultResourceFactory.obj \
.\$(OBJDIR)\nsEmptyCursor.obj \ .\$(OBJDIR)\nsEmptyCursor.obj \
.\$(OBJDIR)\nsInMemoryDataSource.obj \ .\$(OBJDIR)\nsInMemoryDataSource.obj \
.\$(OBJDIR)\nsRDFContentSink.obj \
.\$(OBJDIR)\nsRDFService.obj \ .\$(OBJDIR)\nsRDFService.obj \
.\$(OBJDIR)\nsStreamDataSource.obj \
.\$(OBJDIR)\rdfutil.obj \ .\$(OBJDIR)\rdfutil.obj \
$(NULL) $(NULL)
LINCS= -I$(PUBLIC)\rdf \ LINCS= -I$(PUBLIC)\rdf \
-I$(PUBLIC)\xpcom \ -I$(PUBLIC)\xpcom \
-I$(PUBLIC)\raptor \ -I$(PUBLIC)\raptor \
-I$(PUBLIC)\netlib \
$(NULL) $(NULL)
include <$(DEPTH)\config\rules.mak> include <$(DEPTH)\config\rules.mak>

Просмотреть файл

@ -46,18 +46,19 @@
*/ */
#include "nsCRT.h" #include "nsIContentSink.h"
#include "nsINameSpace.h"
#include "nsINameSpaceManager.h"
#include "nsIRDFContentSink.h"
#include "nsIRDFDataSource.h" #include "nsIRDFDataSource.h"
#include "nsIRDFNode.h" #include "nsIRDFNode.h"
#include "nsIRDFService.h" #include "nsIRDFService.h"
#include "nsRDFCID.h" #include "nsIRDFXMLDocument.h"
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
#include "nsIURL.h" #include "nsIURL.h"
#include "nsRDFContentSink.h" #include "nsIXMLContentSink.h"
#include "nsRDFCID.h"
#include "nsVoidArray.h" #include "nsVoidArray.h"
#include "nsINameSpaceManager.h"
#include "nsINameSpace.h"
#include "nsRDFContentUtils.h"
#include "prlog.h" #include "prlog.h"
#include "prmem.h" #include "prmem.h"
#include "rdfutil.h" #include "rdfutil.h"
@ -250,6 +251,45 @@ rdf_StripAndConvert(nsString& aResult)
} }
} }
nsresult
rdf_GetQuotedAttributeValue(const nsString& aSource,
const nsString& aAttribute,
nsString& aValue)
{
static const char kQuote = '\"';
static const char kApostrophe = '\'';
PRInt32 offset;
PRInt32 endOffset = -1;
nsresult result = NS_OK;
offset = aSource.Find(aAttribute);
if (-1 != offset) {
offset = aSource.Find('=', offset);
PRUnichar next = aSource.CharAt(++offset);
if (kQuote == next) {
endOffset = aSource.Find(kQuote, ++offset);
}
else if (kApostrophe == next) {
endOffset = aSource.Find(kApostrophe, ++offset);
}
if (-1 != endOffset) {
aSource.Mid(aValue, offset, endOffset-offset);
}
else {
// Mismatched quotes - return an error
result = NS_ERROR_FAILURE;
}
}
else {
aValue.Truncate();
}
return result;
}
static void static void
rdf_FullyQualifyURI(const nsIURL* base, nsString& spec) rdf_FullyQualifyURI(const nsIURL* base, nsString& spec)
@ -268,10 +308,122 @@ rdf_FullyQualifyURI(const nsIURL* base, nsString& spec)
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
nsRDFContentSink::nsRDFContentSink() class nsIURL;
class nsVoidArray;
class nsIRDFResource;
class nsIRDFDataSource;
class nsIRDFService;
class nsINameSpaceManager;
typedef enum {
eRDFContentSinkState_InProlog,
eRDFContentSinkState_InDocumentElement,
eRDFContentSinkState_InDescriptionElement,
eRDFContentSinkState_InContainerElement,
eRDFContentSinkState_InPropertyElement,
eRDFContentSinkState_InMemberElement,
eRDFContentSinkState_InEpilog
} RDFContentSinkState;
class RDFContentSinkImpl : public nsIRDFContentSink
{
public:
RDFContentSinkImpl();
virtual ~RDFContentSinkImpl();
// nsISupports
NS_DECL_ISUPPORTS
// nsIContentSink
NS_IMETHOD WillBuildModel(void);
NS_IMETHOD DidBuildModel(PRInt32 aQualityLevel);
NS_IMETHOD WillInterrupt(void);
NS_IMETHOD WillResume(void);
NS_IMETHOD SetParser(nsIParser* aParser);
NS_IMETHOD OpenContainer(const nsIParserNode& aNode);
NS_IMETHOD CloseContainer(const nsIParserNode& aNode);
NS_IMETHOD AddLeaf(const nsIParserNode& aNode);
NS_IMETHOD AddComment(const nsIParserNode& aNode);
NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode);
NS_IMETHOD NotifyError(nsresult aErrorResult);
// nsIXMLContentSink
NS_IMETHOD AddXMLDecl(const nsIParserNode& aNode);
NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode);
NS_IMETHOD AddCharacterData(const nsIParserNode& aNode);
NS_IMETHOD AddUnparsedEntity(const nsIParserNode& aNode);
NS_IMETHOD AddNotation(const nsIParserNode& aNode);
NS_IMETHOD AddEntityReference(const nsIParserNode& aNode);
// nsIRDFContentSink
NS_IMETHOD Init(nsIURL* aURL, nsINameSpaceManager* aNameSpaceManager);
NS_IMETHOD SetDataSource(nsIRDFDataSource* ds);
NS_IMETHOD GetDataSource(nsIRDFDataSource*& ds);
NS_IMETHOD SetRDFXMLDocument(nsIRDFXMLDocument* aDocument);
protected:
// Text management
nsresult FlushText(PRBool aCreateTextNode=PR_TRUE,
PRBool* aDidFlush=nsnull);
PRUnichar* mText;
PRInt32 mTextLength;
PRInt32 mTextSize;
PRBool mConstrainSize;
// namespace management
void PushNameSpacesFrom(const nsIParserNode& aNode);
nsIAtom* CutNameSpacePrefix(nsString& aString);
PRInt32 GetNameSpaceID(nsIAtom* aPrefix);
void GetNameSpaceURI(PRInt32 aID, nsString& aURI);
void PopNameSpaces();
nsINameSpaceManager* mNameSpaceManager;
nsVoidArray* mNameSpaceStack;
PRInt32 mRDFNameSpaceID;
void SplitQualifiedName(const nsString& aQualifiedName,
PRInt32& rNameSpaceID,
nsString& rProperty);
// RDF-specific parsing
nsresult GetIdAboutAttribute(const nsIParserNode& aNode, nsString& rResource);
nsresult GetResourceAttribute(const nsIParserNode& aNode, nsString& rResource);
nsresult AddProperties(const nsIParserNode& aNode, nsIRDFResource* aSubject);
virtual nsresult OpenRDF(const nsIParserNode& aNode);
virtual nsresult OpenObject(const nsIParserNode& aNode);
virtual nsresult OpenProperty(const nsIParserNode& aNode);
virtual nsresult OpenMember(const nsIParserNode& aNode);
virtual nsresult OpenValue(const nsIParserNode& aNode);
// Miscellaneous RDF junk
nsIRDFService* mRDFService;
nsIRDFDataSource* mDataSource;
nsIRDFXMLDocument* mDocument;
RDFContentSinkState mState;
// content stack management
PRInt32 PushContext(nsIRDFResource *aContext, RDFContentSinkState aState);
nsresult PopContext(nsIRDFResource*& rContext, RDFContentSinkState& rState);
nsIRDFResource* GetContextElement(PRInt32 ancestor = 0);
nsVoidArray* mContextStack;
nsIURL* mDocumentURL;
PRUint32 mGenSym; // for generating anonymous resources
PRBool mHaveSetRootResource;
};
////////////////////////////////////////////////////////////////////////
RDFContentSinkImpl::RDFContentSinkImpl()
: mDocumentURL(nsnull), : mDocumentURL(nsnull),
mRDFService(nsnull), mRDFService(nsnull),
mDataSource(nsnull), mDataSource(nsnull),
mDocument(nsnull),
mGenSym(0), mGenSym(0),
mNameSpaceManager(nsnull), mNameSpaceManager(nsnull),
mNameSpaceStack(nsnull), mNameSpaceStack(nsnull),
@ -280,13 +432,14 @@ nsRDFContentSink::nsRDFContentSink()
mText(nsnull), mText(nsnull),
mTextLength(0), mTextLength(0),
mTextSize(0), mTextSize(0),
mConstrainSize(PR_TRUE) mConstrainSize(PR_TRUE),
mHaveSetRootResource(PR_FALSE)
{ {
NS_INIT_REFCNT(); NS_INIT_REFCNT();
} }
nsRDFContentSink::~nsRDFContentSink() RDFContentSinkImpl::~RDFContentSinkImpl()
{ {
NS_IF_RELEASE(mDocumentURL); NS_IF_RELEASE(mDocumentURL);
@ -329,11 +482,11 @@ nsRDFContentSink::~nsRDFContentSink()
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// nsISupports interface // nsISupports interface
NS_IMPL_ADDREF(nsRDFContentSink); NS_IMPL_ADDREF(RDFContentSinkImpl);
NS_IMPL_RELEASE(nsRDFContentSink); NS_IMPL_RELEASE(RDFContentSinkImpl);
NS_IMETHODIMP NS_IMETHODIMP
nsRDFContentSink::QueryInterface(REFNSIID iid, void** result) RDFContentSinkImpl::QueryInterface(REFNSIID iid, void** result)
{ {
NS_PRECONDITION(result, "null ptr"); NS_PRECONDITION(result, "null ptr");
if (! result) if (! result)
@ -356,37 +509,37 @@ nsRDFContentSink::QueryInterface(REFNSIID iid, void** result)
// nsIContentSink interface // nsIContentSink interface
NS_IMETHODIMP NS_IMETHODIMP
nsRDFContentSink::WillBuildModel(void) RDFContentSinkImpl::WillBuildModel(void)
{
return (mDocument != nsnull) ? mDocument->BeginLoad() : NS_OK;
}
NS_IMETHODIMP
RDFContentSinkImpl::DidBuildModel(PRInt32 aQualityLevel)
{
return (mDocument != nsnull) ? mDocument->EndLoad() : NS_OK;
}
NS_IMETHODIMP
RDFContentSinkImpl::WillInterrupt(void)
{
return (mDocument != nsnull) ? mDocument->Interrupt() : NS_OK;
}
NS_IMETHODIMP
RDFContentSinkImpl::WillResume(void)
{
return (mDocument != nsnull) ? mDocument->Resume() : NS_OK;
}
NS_IMETHODIMP
RDFContentSinkImpl::SetParser(nsIParser* aParser)
{ {
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsRDFContentSink::DidBuildModel(PRInt32 aQualityLevel) RDFContentSinkImpl::OpenContainer(const nsIParserNode& aNode)
{
return NS_OK;
}
NS_IMETHODIMP
nsRDFContentSink::WillInterrupt(void)
{
return NS_OK;
}
NS_IMETHODIMP
nsRDFContentSink::WillResume(void)
{
return NS_OK;
}
NS_IMETHODIMP
nsRDFContentSink::SetParser(nsIParser* aParser)
{
return NS_OK;
}
NS_IMETHODIMP
nsRDFContentSink::OpenContainer(const nsIParserNode& aNode)
{ {
// XXX Hopefully the parser will flag this before we get here. If // XXX Hopefully the parser will flag this before we get here. If
// we're in the epilog, there should be no new elements // we're in the epilog, there should be no new elements
@ -441,7 +594,7 @@ nsRDFContentSink::OpenContainer(const nsIParserNode& aNode)
} }
NS_IMETHODIMP NS_IMETHODIMP
nsRDFContentSink::CloseContainer(const nsIParserNode& aNode) RDFContentSinkImpl::CloseContainer(const nsIParserNode& aNode)
{ {
#ifdef DEBUG #ifdef DEBUG
const nsString& text = aNode.GetText(); const nsString& text = aNode.GetText();
@ -468,7 +621,7 @@ nsRDFContentSink::CloseContainer(const nsIParserNode& aNode)
NS_IMETHODIMP NS_IMETHODIMP
nsRDFContentSink::AddLeaf(const nsIParserNode& aNode) RDFContentSinkImpl::AddLeaf(const nsIParserNode& aNode)
{ {
// XXX For now, all leaf content is character data // XXX For now, all leaf content is character data
AddCharacterData(aNode); AddCharacterData(aNode);
@ -476,24 +629,24 @@ nsRDFContentSink::AddLeaf(const nsIParserNode& aNode)
} }
NS_IMETHODIMP NS_IMETHODIMP
nsRDFContentSink::NotifyError(nsresult aErrorResult) RDFContentSinkImpl::NotifyError(nsresult aErrorResult)
{ {
printf("nsRDFContentSink::NotifyError\n"); printf("RDFContentSinkImpl::NotifyError\n");
return NS_OK; return NS_OK;
} }
// nsIXMLContentSink // nsIXMLContentSink
NS_IMETHODIMP NS_IMETHODIMP
nsRDFContentSink::AddXMLDecl(const nsIParserNode& aNode) RDFContentSinkImpl::AddXMLDecl(const nsIParserNode& aNode)
{ {
// XXX We'll ignore it for now // XXX We'll ignore it for now
printf("nsRDFContentSink::AddXMLDecl\n"); printf("RDFContentSinkImpl::AddXMLDecl\n");
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsRDFContentSink::AddComment(const nsIParserNode& aNode) RDFContentSinkImpl::AddComment(const nsIParserNode& aNode)
{ {
FlushText(); FlushText();
nsAutoString text; nsAutoString text;
@ -508,22 +661,80 @@ nsRDFContentSink::AddComment(const nsIParserNode& aNode)
NS_IMETHODIMP NS_IMETHODIMP
nsRDFContentSink::AddProcessingInstruction(const nsIParserNode& aNode) RDFContentSinkImpl::AddProcessingInstruction(const nsIParserNode& aNode)
{ {
static const char kStyleSheetPI[] = "<?xml-stylesheet";
static const char kCSSType[] = "text/css";
static const char kDataSourcePI[] = "<?rdf-datasource";
nsresult rv;
FlushText(); FlushText();
return NS_OK;
if (! mDocument)
return NS_OK;
// XXX For now, we don't add the PI to the content model.
// We just check for a style sheet PI
const nsString& text = aNode.GetText();
// If it's a stylesheet PI...
if (0 == text.Find(kStyleSheetPI)) {
nsAutoString href;
if (NS_FAILED(rv = rdf_GetQuotedAttributeValue(text, "href", href)))
return rv;
// If there was an error or there's no href, we can't do
// anything with this PI
if (! href.Length())
return NS_OK;
nsAutoString type;
if (NS_FAILED(rv = rdf_GetQuotedAttributeValue(text, "type", type)))
return rv;
if (! type.Equals(kCSSType))
return NS_OK;
nsIURL* url = nsnull;
nsAutoString absURL;
nsAutoString emptyURL;
emptyURL.Truncate();
if (NS_FAILED(rv = NS_MakeAbsoluteURL(mDocumentURL, emptyURL, href, absURL)))
return rv;
if (NS_FAILED(rv = NS_NewURL(&url, absURL)))
return rv;
rv = mDocument->AddCSSStyleSheetURL(url);
NS_RELEASE(url);
}
else if (0 == text.Find(kDataSourcePI)) {
nsAutoString href;
rv = rdf_GetQuotedAttributeValue(text, "href", href);
if (NS_FAILED(rv) || (0 == href.Length()))
return rv;
char uri[256];
href.ToCString(uri, sizeof(uri));
rv = mDocument->AddNamedDataSourceURI(uri);
}
return rv;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsRDFContentSink::AddDocTypeDecl(const nsIParserNode& aNode) RDFContentSinkImpl::AddDocTypeDecl(const nsIParserNode& aNode)
{ {
printf("nsRDFContentSink::AddDocTypeDecl\n"); printf("RDFContentSinkImpl::AddDocTypeDecl\n");
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsRDFContentSink::AddCharacterData(const nsIParserNode& aNode) RDFContentSinkImpl::AddCharacterData(const nsIParserNode& aNode)
{ {
nsAutoString text = aNode.GetText(); nsAutoString text = aNode.GetText();
@ -581,23 +792,23 @@ nsRDFContentSink::AddCharacterData(const nsIParserNode& aNode)
} }
NS_IMETHODIMP NS_IMETHODIMP
nsRDFContentSink::AddUnparsedEntity(const nsIParserNode& aNode) RDFContentSinkImpl::AddUnparsedEntity(const nsIParserNode& aNode)
{ {
printf("nsRDFContentSink::AddUnparsedEntity\n"); printf("RDFContentSinkImpl::AddUnparsedEntity\n");
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsRDFContentSink::AddNotation(const nsIParserNode& aNode) RDFContentSinkImpl::AddNotation(const nsIParserNode& aNode)
{ {
printf("nsRDFContentSink::AddNotation\n"); printf("RDFContentSinkImpl::AddNotation\n");
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
nsRDFContentSink::AddEntityReference(const nsIParserNode& aNode) RDFContentSinkImpl::AddEntityReference(const nsIParserNode& aNode)
{ {
printf("nsRDFContentSink::AddEntityReference\n"); printf("RDFContentSinkImpl::AddEntityReference\n");
return NS_OK; return NS_OK;
} }
@ -605,7 +816,7 @@ nsRDFContentSink::AddEntityReference(const nsIParserNode& aNode)
// nsIRDFContentSink interface // nsIRDFContentSink interface
NS_IMETHODIMP NS_IMETHODIMP
nsRDFContentSink::Init(nsIURL* aURL, nsINameSpaceManager* aNameSpaceManager) RDFContentSinkImpl::Init(nsIURL* aURL, nsINameSpaceManager* aNameSpaceManager)
{ {
NS_PRECONDITION((nsnull != aURL) && (nsnull != aNameSpaceManager), "null ptr"); NS_PRECONDITION((nsnull != aURL) && (nsnull != aNameSpaceManager), "null ptr");
if ((! aURL) || (! aNameSpaceManager)) if ((! aURL) || (! aNameSpaceManager))
@ -628,7 +839,7 @@ nsRDFContentSink::Init(nsIURL* aURL, nsINameSpaceManager* aNameSpaceManager)
} }
NS_IMETHODIMP NS_IMETHODIMP
nsRDFContentSink::SetDataSource(nsIRDFDataSource* ds) RDFContentSinkImpl::SetDataSource(nsIRDFDataSource* ds)
{ {
NS_IF_RELEASE(mDataSource); NS_IF_RELEASE(mDataSource);
mDataSource = ds; mDataSource = ds;
@ -638,13 +849,21 @@ nsRDFContentSink::SetDataSource(nsIRDFDataSource* ds)
NS_IMETHODIMP NS_IMETHODIMP
nsRDFContentSink::GetDataSource(nsIRDFDataSource*& ds) RDFContentSinkImpl::GetDataSource(nsIRDFDataSource*& ds)
{ {
ds = mDataSource; ds = mDataSource;
NS_IF_ADDREF(mDataSource); NS_IF_ADDREF(mDataSource);
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
RDFContentSinkImpl::SetRDFXMLDocument(nsIRDFXMLDocument* aDocument)
{
mDocument = aDocument;
NS_IF_ADDREF(mDocument);
return NS_OK;
}
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// Text buffering // Text buffering
@ -665,7 +884,7 @@ rdf_IsDataInBuffer(PRUnichar* buffer, PRInt32 length)
nsresult nsresult
nsRDFContentSink::FlushText(PRBool aCreateTextNode, PRBool* aDidFlush) RDFContentSinkImpl::FlushText(PRBool aCreateTextNode, PRBool* aDidFlush)
{ {
nsresult rv = NS_OK; nsresult rv = NS_OK;
PRBool didFlush = PR_FALSE; PRBool didFlush = PR_FALSE;
@ -721,7 +940,7 @@ nsRDFContentSink::FlushText(PRBool aCreateTextNode, PRBool* aDidFlush)
// Qualified name resolution // Qualified name resolution
void void
nsRDFContentSink::SplitQualifiedName(const nsString& aQualifiedName, RDFContentSinkImpl::SplitQualifiedName(const nsString& aQualifiedName,
PRInt32& rNameSpaceID, PRInt32& rNameSpaceID,
nsString& rProperty) nsString& rProperty)
{ {
@ -733,7 +952,7 @@ nsRDFContentSink::SplitQualifiedName(const nsString& aQualifiedName,
nsresult nsresult
nsRDFContentSink::GetIdAboutAttribute(const nsIParserNode& aNode, RDFContentSinkImpl::GetIdAboutAttribute(const nsIParserNode& aNode,
nsString& rResource) nsString& rResource)
{ {
// This corresponds to the dirty work of production [6.5] // This corresponds to the dirty work of production [6.5]
@ -790,7 +1009,7 @@ nsRDFContentSink::GetIdAboutAttribute(const nsIParserNode& aNode,
nsresult nsresult
nsRDFContentSink::GetResourceAttribute(const nsIParserNode& aNode, RDFContentSinkImpl::GetResourceAttribute(const nsIParserNode& aNode,
nsString& rResource) nsString& rResource)
{ {
nsAutoString k; nsAutoString k;
@ -825,7 +1044,7 @@ nsRDFContentSink::GetResourceAttribute(const nsIParserNode& aNode,
} }
nsresult nsresult
nsRDFContentSink::AddProperties(const nsIParserNode& aNode, RDFContentSinkImpl::AddProperties(const nsIParserNode& aNode,
nsIRDFResource* aSubject) nsIRDFResource* aSubject)
{ {
// Add tag attributes to the content attributes // Add tag attributes to the content attributes
@ -865,7 +1084,7 @@ nsRDFContentSink::AddProperties(const nsIParserNode& aNode,
// RDF-specific routines used to build the model // RDF-specific routines used to build the model
nsresult nsresult
nsRDFContentSink::OpenRDF(const nsIParserNode& aNode) RDFContentSinkImpl::OpenRDF(const nsIParserNode& aNode)
{ {
// ensure that we're actually reading RDF by making sure that the // ensure that we're actually reading RDF by making sure that the
// opening tag is <rdf:RDF>, where "rdf:" corresponds to whatever // opening tag is <rdf:RDF>, where "rdf:" corresponds to whatever
@ -888,7 +1107,7 @@ nsRDFContentSink::OpenRDF(const nsIParserNode& aNode)
nsresult nsresult
nsRDFContentSink::OpenObject(const nsIParserNode& aNode) RDFContentSinkImpl::OpenObject(const nsIParserNode& aNode)
{ {
// an "object" non-terminal is either a "description", a "typed // an "object" non-terminal is either a "description", a "typed
// node", or a "container", so this change the content sink's // node", or a "container", so this change the content sink's
@ -976,6 +1195,12 @@ nsRDFContentSink::OpenObject(const nsIParserNode& aNode)
} }
AddProperties(aNode, rdfResource); AddProperties(aNode, rdfResource);
if (mDocument && !mHaveSetRootResource) {
mHaveSetRootResource = PR_TRUE;
mDocument->SetRootResource(rdfResource);
}
NS_RELEASE(rdfResource); NS_RELEASE(rdfResource);
return NS_OK; return NS_OK;
@ -983,7 +1208,7 @@ nsRDFContentSink::OpenObject(const nsIParserNode& aNode)
nsresult nsresult
nsRDFContentSink::OpenProperty(const nsIParserNode& aNode) RDFContentSinkImpl::OpenProperty(const nsIParserNode& aNode)
{ {
if (! mRDFService) if (! mRDFService)
return NS_ERROR_NOT_INITIALIZED; return NS_ERROR_NOT_INITIALIZED;
@ -1043,7 +1268,7 @@ nsRDFContentSink::OpenProperty(const nsIParserNode& aNode)
nsresult nsresult
nsRDFContentSink::OpenMember(const nsIParserNode& aNode) RDFContentSinkImpl::OpenMember(const nsIParserNode& aNode)
{ {
// ensure that we're actually reading a member element by making // ensure that we're actually reading a member element by making
// sure that the opening tag is <rdf:li>, where "rdf:" corresponds // sure that the opening tag is <rdf:li>, where "rdf:" corresponds
@ -1093,7 +1318,7 @@ nsRDFContentSink::OpenMember(const nsIParserNode& aNode)
nsresult nsresult
nsRDFContentSink::OpenValue(const nsIParserNode& aNode) RDFContentSinkImpl::OpenValue(const nsIParserNode& aNode)
{ {
// a "value" can either be an object or a string: we'll only get // a "value" can either be an object or a string: we'll only get
// *here* if it's an object, as raw text is added as a leaf. // *here* if it's an object, as raw text is added as a leaf.
@ -1110,7 +1335,7 @@ struct RDFContextStackElement {
}; };
nsIRDFResource* nsIRDFResource*
nsRDFContentSink::GetContextElement(PRInt32 ancestor /* = 0 */) RDFContentSinkImpl::GetContextElement(PRInt32 ancestor /* = 0 */)
{ {
if ((nsnull == mContextStack) || if ((nsnull == mContextStack) ||
(ancestor >= mContextStack->Count())) { (ancestor >= mContextStack->Count())) {
@ -1124,7 +1349,7 @@ nsRDFContentSink::GetContextElement(PRInt32 ancestor /* = 0 */)
} }
PRInt32 PRInt32
nsRDFContentSink::PushContext(nsIRDFResource *aResource, RDFContentSinkState aState) RDFContentSinkImpl::PushContext(nsIRDFResource *aResource, RDFContentSinkState aState)
{ {
if (! mContextStack) { if (! mContextStack) {
mContextStack = new nsVoidArray(); mContextStack = new nsVoidArray();
@ -1145,7 +1370,7 @@ nsRDFContentSink::PushContext(nsIRDFResource *aResource, RDFContentSinkState aSt
} }
nsresult nsresult
nsRDFContentSink::PopContext(nsIRDFResource*& rResource, RDFContentSinkState& rState) RDFContentSinkImpl::PopContext(nsIRDFResource*& rResource, RDFContentSinkState& rState)
{ {
RDFContextStackElement* e; RDFContextStackElement* e;
if ((nsnull == mContextStack) || if ((nsnull == mContextStack) ||
@ -1170,7 +1395,7 @@ nsRDFContentSink::PopContext(nsIRDFResource*& rResource, RDFContentSinkState& rS
// Namespace management // Namespace management
void void
nsRDFContentSink::PushNameSpacesFrom(const nsIParserNode& aNode) RDFContentSinkImpl::PushNameSpacesFrom(const nsIParserNode& aNode)
{ {
nsAutoString k, uri, prefix; nsAutoString k, uri, prefix;
PRInt32 ac = aNode.GetAttributeCount(); PRInt32 ac = aNode.GetAttributeCount();
@ -1228,7 +1453,7 @@ nsRDFContentSink::PushNameSpacesFrom(const nsIParserNode& aNode)
} }
nsIAtom* nsIAtom*
nsRDFContentSink::CutNameSpacePrefix(nsString& aString) RDFContentSinkImpl::CutNameSpacePrefix(nsString& aString)
{ {
nsAutoString prefix; nsAutoString prefix;
PRInt32 nsoffset = aString.Find(kNameSpaceSeparator); PRInt32 nsoffset = aString.Find(kNameSpaceSeparator);
@ -1243,7 +1468,7 @@ nsRDFContentSink::CutNameSpacePrefix(nsString& aString)
} }
PRInt32 PRInt32
nsRDFContentSink::GetNameSpaceID(nsIAtom* aPrefix) RDFContentSinkImpl::GetNameSpaceID(nsIAtom* aPrefix)
{ {
PRInt32 id = kNameSpaceID_Unknown; PRInt32 id = kNameSpaceID_Unknown;
@ -1258,13 +1483,13 @@ nsRDFContentSink::GetNameSpaceID(nsIAtom* aPrefix)
} }
void void
nsRDFContentSink::GetNameSpaceURI(PRInt32 aID, nsString& aURI) RDFContentSinkImpl::GetNameSpaceURI(PRInt32 aID, nsString& aURI)
{ {
mNameSpaceManager->GetNameSpaceURI(aID, aURI); mNameSpaceManager->GetNameSpaceURI(aID, aURI);
} }
void void
nsRDFContentSink::PopNameSpaces() RDFContentSinkImpl::PopNameSpaces()
{ {
if ((nsnull != mNameSpaceStack) && (0 < mNameSpaceStack->Count())) { if ((nsnull != mNameSpaceStack) && (0 < mNameSpaceStack->Count())) {
PRInt32 index = mNameSpaceStack->Count() - 1; PRInt32 index = mNameSpaceStack->Count() - 1;
@ -1278,3 +1503,20 @@ nsRDFContentSink::PopNameSpaces()
} }
} }
////////////////////////////////////////////////////////////////////////
nsresult
NS_NewRDFContentSink(nsIRDFContentSink** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
RDFContentSinkImpl* sink = new RDFContentSinkImpl();
if (! sink)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(sink);
*aResult = sink;
return NS_OK;
}

Просмотреть файл

@ -19,8 +19,7 @@
/* /*
An abstract base class that serves as the basis for the
implementation of the nsIRDFContentSink interface.
*/ */
@ -47,11 +46,11 @@ typedef enum {
} RDFContentSinkState; } RDFContentSinkState;
class nsRDFContentSink : public nsIRDFContentSink class RDFContentSinkImpl : public nsIRDFContentSink
{ {
public: public:
nsRDFContentSink(); RDFContentSinkImpl();
virtual ~nsRDFContentSink(); virtual ~RDFContentSinkImpl();
// nsISupports // nsISupports
NS_DECL_ISUPPORTS NS_DECL_ISUPPORTS

Просмотреть файл

@ -318,6 +318,7 @@ class ServiceImpl : public nsIRDFService
protected: protected:
PrefixMap mResourceFactories; PrefixMap mResourceFactories;
PLHashTable* mNamedDataSources; PLHashTable* mNamedDataSources;
PLHashTable* mDataSourceConstructors;
PLHashTable* mResources; PLHashTable* mResources;
ServiceImpl(void); ServiceImpl(void);
@ -344,9 +345,11 @@ public:
NS_IMETHOD RegisterResourceFactory(const char* aURIPrefix, nsIRDFResourceFactory* aFactory); NS_IMETHOD RegisterResourceFactory(const char* aURIPrefix, nsIRDFResourceFactory* aFactory);
NS_IMETHOD UnRegisterResourceFactory(const char* aURIPrefix); NS_IMETHOD UnRegisterResourceFactory(const char* aURIPrefix);
NS_IMETHOD RegisterNamedDataSource(const char* uri, nsIRDFDataSource* dataSource); NS_IMETHOD RegisterDataSource(nsIRDFDataSource* dataSource);
NS_IMETHOD UnRegisterNamedDataSource(const char* uri); NS_IMETHOD UnregisterDataSource(nsIRDFDataSource* dataSource);
NS_IMETHOD GetNamedDataSource(const char* uri, nsIRDFDataSource** dataSource); NS_IMETHOD RegisterDataSourceConstructor(const char* uri, NSDataSourceConstructorCallback fn);
NS_IMETHOD UnregisterDataSourceConstructor(const char* uri);
NS_IMETHOD GetDataSource(const char* uri, nsIRDFDataSource** dataSource);
NS_IMETHOD CreateDatabase(const char** uris, nsIRDFDataBase** dataBase); NS_IMETHOD CreateDatabase(const char** uris, nsIRDFDataBase** dataBase);
NS_IMETHOD CreateBrowserDatabase(nsIRDFDataBase** dataBase); NS_IMETHOD CreateBrowserDatabase(nsIRDFDataBase** dataBase);
}; };
@ -370,19 +373,29 @@ ServiceImpl::ServiceImpl(void)
PL_CompareStrings, PL_CompareStrings,
PL_CompareValues, PL_CompareValues,
nsnull, nsnull); nsnull, nsnull);
mDataSourceConstructors = PL_NewHashTable(23,
PL_HashString,
PL_CompareStrings,
PL_CompareValues,
nsnull, nsnull);
} }
ServiceImpl::~ServiceImpl(void) ServiceImpl::~ServiceImpl(void)
{ {
if (mResources) { if (mDataSourceConstructors) {
PL_HashTableDestroy(mResources); PL_HashTableDestroy(mDataSourceConstructors);
mResources = nsnull; mDataSourceConstructors = nsnull;
} }
if (mNamedDataSources) { if (mNamedDataSources) {
PL_HashTableDestroy(mNamedDataSources); PL_HashTableDestroy(mNamedDataSources);
mNamedDataSources = nsnull; mNamedDataSources = nsnull;
} }
if (mResources) {
PL_HashTableDestroy(mResources);
mResources = nsnull;
}
gRDFService = nsnull; gRDFService = nsnull;
} }
@ -522,17 +535,37 @@ ServiceImpl::UnRegisterResourceFactory(const char* aURIPrefix)
} }
NS_IMETHODIMP NS_IMETHODIMP
ServiceImpl::RegisterNamedDataSource(const char* uri, nsIRDFDataSource* dataSource) ServiceImpl::RegisterDataSource(nsIRDFDataSource* aDataSource)
{ {
NS_PRECONDITION(aDataSource != nsnull, "null ptr");
if (! aDataSource)
return NS_ERROR_NULL_POINTER;
nsresult rv;
const char* uri;
if (NS_FAILED(rv = aDataSource->GetURI(&uri)))
return rv;
// XXX check for dups, etc. // XXX check for dups, etc.
NS_ADDREF(dataSource); // XXX is this the right thing to do?
PL_HashTableAdd(mNamedDataSources, uri, dataSource); PL_HashTableAdd(mNamedDataSources, uri, aDataSource);
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
ServiceImpl::UnRegisterNamedDataSource(const char* uri) ServiceImpl::UnregisterDataSource(nsIRDFDataSource* aDataSource)
{ {
NS_PRECONDITION(aDataSource != nsnull, "null ptr");
if (! aDataSource)
return NS_ERROR_NULL_POINTER;
nsresult rv;
const char* uri;
if (NS_FAILED(rv = aDataSource->GetURI(&uri)))
return rv;
nsIRDFDataSource* ds = nsIRDFDataSource* ds =
NS_STATIC_CAST(nsIRDFDataSource*, PL_HashTableLookup(mNamedDataSources, uri)); NS_STATIC_CAST(nsIRDFDataSource*, PL_HashTableLookup(mNamedDataSources, uri));
@ -540,36 +573,70 @@ ServiceImpl::UnRegisterNamedDataSource(const char* uri)
return NS_ERROR_ILLEGAL_VALUE; return NS_ERROR_ILLEGAL_VALUE;
PL_HashTableRemove(mNamedDataSources, uri); PL_HashTableRemove(mNamedDataSources, uri);
NS_RELEASE(ds);
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP NS_IMETHODIMP
ServiceImpl::GetNamedDataSource(const char* uri, nsIRDFDataSource** dataSource) ServiceImpl::RegisterDataSourceConstructor(const char* uri, NSDataSourceConstructorCallback fn)
{
// XXX check for dups, etc.
PL_HashTableAdd(mDataSourceConstructors, uri, fn);
return NS_OK;
}
NS_IMETHODIMP
ServiceImpl::UnregisterDataSourceConstructor(const char* uri)
{
PL_HashTableRemove(mDataSourceConstructors, uri);
return NS_OK;
}
NS_IMETHODIMP
ServiceImpl::GetDataSource(const char* uri, nsIRDFDataSource** aDataSource)
{ {
nsIRDFDataSource* ds = nsIRDFDataSource* ds =
NS_STATIC_CAST(nsIRDFDataSource*, PL_HashTableLookup(mNamedDataSources, uri)); NS_STATIC_CAST(nsIRDFDataSource*, PL_HashTableLookup(mNamedDataSources, uri));
// XXX if it's not a named data source, and it looks like it might be if (ds) {
// a URL, then try to create a stream data source on the URL. NS_ADDREF(ds);
if (! ds) { *aDataSource = ds;
size_t len = strlen(uri); return NS_OK;
if ((len > 4) && (strcmp(&uri[len-4], ".rdf") == 0)) {
extern nsresult NS_NewRDFStreamDataSource(nsIRDFDataSource** result);
if (NS_OK != NS_NewRDFStreamDataSource(&ds)) {
return NS_ERROR_ILLEGAL_VALUE;
} else {
ds->Init(uri);
// XXX do we really want to globally register this datasource?
RegisterNamedDataSource(uri, ds);
}
} else return NS_ERROR_ILLEGAL_VALUE;
} }
NS_ADDREF(ds); // Otherwise, see if we have a lazy constructor
*dataSource = ds; NSDataSourceConstructorCallback constructor =
return NS_OK; (NSDataSourceConstructorCallback)
PL_HashTableLookup(mDataSourceConstructors, uri);
if (constructor) {
// Yep, so try to construct it on the fly...
nsresult rv;
if (NS_FAILED(rv = constructor(&ds))) {
#ifdef DEBUG
printf("error constructing built-in datasource %s\n", uri);
#endif
return rv;
}
// If it wants to register itself, it should do so in the Init() method.
if (NS_FAILED(rv = ds->Init(uri))) {
#ifdef DEBUG
printf("error initializing named datasource %s\n", uri);
#endif
NS_RELEASE(ds);
return rv;
}
// constructor did an implicit addref
*aDataSource = ds;
return NS_OK;
}
// XXX at this point, we might want to try to construct a
// stream URI and load it that way...
return NS_ERROR_ILLEGAL_VALUE;
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -669,17 +736,12 @@ ServiceImpl::RegisterBuiltInNamedDataSources(void)
nsresult rv; nsresult rv;
for (DataSourceTable* entry = gTable; entry->mURI != nsnull; ++entry) { for (DataSourceTable* entry = gTable; entry->mURI != nsnull; ++entry) {
nsIRDFDataSource* ds; if (NS_FAILED(rv = gRDFService->RegisterDataSourceConstructor(entry->mURI, entry->mDataSourceConstructor))) {
#ifdef DEBUG
if (NS_FAILED(rv = (entry->mDataSourceConstructor)(&ds))) printf("error registering built-in datasource constructor for %s\n", entry->mURI);
#endif
continue; continue;
if (NS_SUCCEEDED(rv = ds->Init(entry->mURI))) {
rv = gRDFService->RegisterNamedDataSource(entry->mURI, ds);
PR_ASSERT(NS_SUCCEEDED(rv));
} }
NS_RELEASE(ds);
} }
} }

Просмотреть файл

@ -42,12 +42,17 @@
#include "nsIRDFContentSink.h" #include "nsIRDFContentSink.h"
#include "nsIRDFCursor.h" #include "nsIRDFCursor.h"
#include "nsIRDFDataSource.h" #include "nsIRDFDataSource.h"
#include "nsIRDFNode.h"
#include "nsIRDFService.h"
#include "nsIRDFXMLDocument.h"
#include "nsIRDFXMLSource.h" #include "nsIRDFXMLSource.h"
#include "nsIServiceManager.h"
#include "nsIStreamListener.h" #include "nsIStreamListener.h"
#include "nsIURL.h" #include "nsIURL.h"
#include "nsLayoutCID.h" // for NS_NAMESPACEMANAGER_CID. #include "nsLayoutCID.h" // for NS_NAMESPACEMANAGER_CID.
#include "nsParserCIID.h" #include "nsParserCIID.h"
#include "nsRDFCID.h" #include "nsRDFCID.h"
#include "nsVoidArray.h"
#include "plstr.h" #include "plstr.h"
#include "prio.h" #include "prio.h"
@ -59,6 +64,8 @@ static NS_DEFINE_IID(kIOutputStreamIID, NS_IOUTPUTSTREAM_IID);
static NS_DEFINE_IID(kIParserIID, NS_IPARSER_IID); static NS_DEFINE_IID(kIParserIID, NS_IPARSER_IID);
static NS_DEFINE_IID(kIRDFDataSourceIID, NS_IRDFDATASOURCE_IID); static NS_DEFINE_IID(kIRDFDataSourceIID, NS_IRDFDATASOURCE_IID);
static NS_DEFINE_IID(kIRDFContentSinkIID, NS_IRDFCONTENTSINK_IID); static NS_DEFINE_IID(kIRDFContentSinkIID, NS_IRDFCONTENTSINK_IID);
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
static NS_DEFINE_IID(kIRDFXMLDocumentIID, NS_IRDFXMLDOCUMENT_IID);
static NS_DEFINE_IID(kIRDFXMLSourceIID, NS_IRDFXMLSOURCE_IID); static NS_DEFINE_IID(kIRDFXMLSourceIID, NS_IRDFXMLSOURCE_IID);
static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID); static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
@ -66,7 +73,8 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID); static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID);
static NS_DEFINE_CID(kParserCID, NS_PARSER_IID); // XXX static NS_DEFINE_CID(kParserCID, NS_PARSER_IID); // XXX
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID); static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
static NS_DEFINE_CID(kRDFSimpleContentSinkCID, NS_RDFSIMPLECONTENTSINK_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); static NS_DEFINE_CID(kWellFormedDTDCID, NS_WELLFORMEDDTD_CID);
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
@ -119,12 +127,19 @@ NS_IMPL_ISUPPORTS(FileOutputStreamImpl, kIOutputStreamIID);
// StreamDataSourceImpl // StreamDataSourceImpl
class StreamDataSourceImpl : public nsIRDFDataSource, class StreamDataSourceImpl : public nsIRDFDataSource,
public nsIRDFXMLDocument,
public nsIRDFXMLSource public nsIRDFXMLSource
{ {
protected: protected:
nsIRDFDataSource* mInner; nsIRDFDataSource* mInner;
PRBool mIsWritable; PRBool mIsWritable;
PRBool mIsDirty; PRBool mIsDirty;
nsVoidArray mObservers;
char** mNamedDataSourceURIs;
PRInt32 mNumNamedDataSourceURIs;
nsIURL** mCSSStyleSheetURLs;
PRInt32 mNumCSSStyleSheetURLs;
nsIRDFResource* mRootResource;
public: public:
StreamDataSourceImpl(void); StreamDataSourceImpl(void);
@ -218,8 +233,24 @@ public:
return mInner->DoCommand(aCommand, aCommandTarget); return mInner->DoCommand(aCommand, aCommandTarget);
} }
// nsIRDFXMLDocument interface
NS_IMETHOD BeginLoad(void);
NS_IMETHOD Interrupt(void);
NS_IMETHOD Resume(void);
NS_IMETHOD EndLoad(void);
NS_IMETHOD SetRootResource(nsIRDFResource* aResource);
NS_IMETHOD GetRootResource(nsIRDFResource** aResource);
NS_IMETHOD AddCSSStyleSheetURL(nsIURL* aStyleSheetURL);
NS_IMETHOD GetCSSStyleSheetURLs(nsIURL*** aStyleSheetURLs, PRInt32* aCount);
NS_IMETHOD AddNamedDataSourceURI(const char* aNamedDataSourceURI);
NS_IMETHOD GetNamedDataSourceURIs(const char* const** aNamedDataSourceURIs, PRInt32* aCount);
NS_IMETHOD AddDocumentObserver(nsIRDFXMLDocumentObserver* aObserver);
NS_IMETHOD RemoveDocumentObserver(nsIRDFXMLDocumentObserver* aObserver);
// nsIRDFXMLSource interface // nsIRDFXMLSource interface
NS_IMETHOD Serialize(nsIOutputStream* aStream); NS_IMETHOD Serialize(nsIOutputStream* aStream);
// Implementation methods
}; };
@ -227,14 +258,42 @@ public:
StreamDataSourceImpl::StreamDataSourceImpl(void) StreamDataSourceImpl::StreamDataSourceImpl(void)
: mIsWritable(PR_FALSE) : mIsWritable(PR_FALSE),
mNamedDataSourceURIs(nsnull),
mNumNamedDataSourceURIs(0),
mCSSStyleSheetURLs(nsnull),
mNumCSSStyleSheetURLs(0)
{ {
nsresult rv;
if (NS_FAILED(rv = nsRepository::CreateInstance(kRDFInMemoryDataSourceCID,
nsnull,
kIRDFDataSourceIID,
(void**) &mInner)))
PR_ASSERT(0);
} }
StreamDataSourceImpl::~StreamDataSourceImpl(void) StreamDataSourceImpl::~StreamDataSourceImpl(void)
{ {
nsIRDFService* rdfService;
if (NS_SUCCEEDED(nsServiceManager::GetService(kRDFServiceCID,
kIRDFServiceIID,
(nsISupports**) &rdfService))) {
rdfService->UnregisterDataSource(this);
nsServiceManager::ReleaseService(kRDFServiceCID, rdfService);
}
Flush(); Flush();
while (--mNumNamedDataSourceURIs >= 0)
delete mNamedDataSourceURIs[mNumNamedDataSourceURIs];
delete mNamedDataSourceURIs;
while (--mNumCSSStyleSheetURLs >= 0)
NS_RELEASE(mCSSStyleSheetURLs[mNumCSSStyleSheetURLs]);
delete mCSSStyleSheetURLs;
} }
@ -258,6 +317,11 @@ StreamDataSourceImpl::QueryInterface(REFNSIID iid, void** result)
NS_ADDREF(this); NS_ADDREF(this);
return NS_OK; return NS_OK;
} }
else if (iid.Equals(kIRDFXMLDocumentIID)) {
*result = NS_STATIC_CAST(nsIRDFXMLDocument*, this);
NS_ADDREF(this);
return NS_OK;
}
else { else {
*result = nsnull; *result = nsnull;
return NS_NOINTERFACE; return NS_NOINTERFACE;
@ -270,6 +334,10 @@ const PRInt32 kFileURIPrefixLen = 5;
NS_IMETHODIMP NS_IMETHODIMP
StreamDataSourceImpl::Init(const char* uri) StreamDataSourceImpl::Init(const char* uri)
{ {
NS_PRECONDITION(mInner != nsnull, "not initialized");
if (! mInner)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv; nsresult rv;
// XXX this is a hack: any "file:" URI is considered writable. All // XXX this is a hack: any "file:" URI is considered writable. All
@ -277,6 +345,7 @@ StreamDataSourceImpl::Init(const char* uri)
if (PL_strncmp(uri, kFileURIPrefix, kFileURIPrefixLen) == 0) if (PL_strncmp(uri, kFileURIPrefix, kFileURIPrefixLen) == 0)
mIsWritable = PR_TRUE; mIsWritable = PR_TRUE;
nsIRDFService* rdfService = nsnull;
nsINameSpaceManager* ns = nsnull; nsINameSpaceManager* ns = nsnull;
nsIRDFContentSink* sink = nsnull; nsIRDFContentSink* sink = nsnull;
nsIParser* parser = nsnull; nsIParser* parser = nsnull;
@ -287,13 +356,15 @@ StreamDataSourceImpl::Init(const char* uri)
if (NS_FAILED(rv = NS_NewURL(&url, uri))) if (NS_FAILED(rv = NS_NewURL(&url, uri)))
goto done; goto done;
if (NS_FAILED(rv = nsRepository::CreateInstance(kRDFInMemoryDataSourceCID, if (NS_FAILED(rv = mInner->Init(uri)))
nsnull,
kIRDFDataSourceIID,
(void**) &mInner)))
goto done; goto done;
if (NS_FAILED(rv = mInner->Init(uri))) if (NS_FAILED(rv = nsServiceManager::GetService(kRDFServiceCID,
kIRDFServiceIID,
(nsISupports**) &rdfService)))
goto done;
if (NS_FAILED(rv = rdfService->RegisterDataSource(this)))
goto done; goto done;
if (NS_FAILED(rv = nsRepository::CreateInstance(kNameSpaceManagerCID, if (NS_FAILED(rv = nsRepository::CreateInstance(kNameSpaceManagerCID,
@ -302,7 +373,7 @@ StreamDataSourceImpl::Init(const char* uri)
(void**) &ns))) (void**) &ns)))
goto done; goto done;
if (NS_FAILED(rv = nsRepository::CreateInstance(kRDFSimpleContentSinkCID, if (NS_FAILED(rv = nsRepository::CreateInstance(kRDFContentSinkCID,
nsnull, nsnull,
kIRDFContentSinkIID, kIRDFContentSinkIID,
(void**) &sink))) (void**) &sink)))
@ -312,10 +383,13 @@ StreamDataSourceImpl::Init(const char* uri)
goto done; goto done;
// We set the content sink's data source directly to our in-memory // We set the content sink's data source directly to our in-memory
// store. We _always_ fail asserts because they're not allowed. // store. This allows the initial content to be generated "directly".
if (NS_FAILED(rv = sink->SetDataSource(mInner))) if (NS_FAILED(rv = sink->SetDataSource(mInner)))
goto done; goto done;
if (NS_FAILED(rv = sink->SetRDFXMLDocument(this)))
goto done;
if (NS_FAILED(rv = nsRepository::CreateInstance(kParserCID, if (NS_FAILED(rv = nsRepository::CreateInstance(kParserCID,
nsnull, nsnull,
kIParserIID, kIParserIID,
@ -324,6 +398,9 @@ StreamDataSourceImpl::Init(const char* uri)
parser->SetContentSink(sink); parser->SetContentSink(sink);
// XXX this should eventually be kRDFDTDCID (oh boy, that's a
// pretty identifier). The RDF DTD will be a much more
// RDF-resilient parser.
if (NS_FAILED(rv = nsRepository::CreateInstance(kWellFormedDTDCID, if (NS_FAILED(rv = nsRepository::CreateInstance(kWellFormedDTDCID,
nsnull, nsnull,
kIDTDIID, kIDTDIID,
@ -346,6 +423,10 @@ done:
NS_IF_RELEASE(dtd); NS_IF_RELEASE(dtd);
NS_IF_RELEASE(parser); NS_IF_RELEASE(parser);
NS_IF_RELEASE(sink); NS_IF_RELEASE(sink);
if (rdfService) {
nsServiceManager::ReleaseService(kRDFServiceCID, rdfService);
rdfService = nsnull;
}
NS_IF_RELEASE(url); NS_IF_RELEASE(url);
return rv; return rv;
} }
@ -407,6 +488,175 @@ StreamDataSourceImpl::Flush(void)
return NS_OK; return NS_OK;
} }
////////////////////////////////////////////////////////////////////////
// nsIRDFXMLDocument methods
NS_IMETHODIMP
StreamDataSourceImpl::BeginLoad(void)
{
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
nsIRDFXMLDocumentObserver* obs = (nsIRDFXMLDocumentObserver*) mObservers[i];
obs->OnBeginLoad();
}
return NS_OK;
}
NS_IMETHODIMP
StreamDataSourceImpl::Interrupt(void)
{
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
nsIRDFXMLDocumentObserver* obs = (nsIRDFXMLDocumentObserver*) mObservers[i];
obs->OnInterrupt();
}
return NS_OK;
}
NS_IMETHODIMP
StreamDataSourceImpl::Resume(void)
{
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
nsIRDFXMLDocumentObserver* obs = (nsIRDFXMLDocumentObserver*) mObservers[i];
obs->OnResume();
}
return NS_OK;
}
NS_IMETHODIMP
StreamDataSourceImpl::EndLoad(void)
{
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
nsIRDFXMLDocumentObserver* obs = (nsIRDFXMLDocumentObserver*) mObservers[i];
obs->OnEndLoad();
}
return NS_OK;
}
NS_IMETHODIMP
StreamDataSourceImpl::SetRootResource(nsIRDFResource* aResource)
{
NS_PRECONDITION(aResource != nsnull, "null ptr");
if (! aResource)
return NS_ERROR_NULL_POINTER;
NS_ADDREF(aResource);
mRootResource = aResource;
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
nsIRDFXMLDocumentObserver* obs = (nsIRDFXMLDocumentObserver*) mObservers[i];
obs->OnRootResourceFound(mRootResource);
}
return NS_OK;
}
NS_IMETHODIMP
StreamDataSourceImpl::GetRootResource(nsIRDFResource** aResource)
{
NS_ADDREF(mRootResource);
*aResource = mRootResource;
return NS_OK;
}
NS_IMETHODIMP
StreamDataSourceImpl::AddCSSStyleSheetURL(nsIURL* aCSSStyleSheetURL)
{
NS_PRECONDITION(aCSSStyleSheetURL != nsnull, "null ptr");
if (! aCSSStyleSheetURL)
return NS_ERROR_NULL_POINTER;
nsIURL** p = new nsIURL*[mNumCSSStyleSheetURLs + 1];
if (! p)
return NS_ERROR_OUT_OF_MEMORY;
PRInt32 i;
for (i = mNumCSSStyleSheetURLs - 1; i >= 0; --i)
p[i] = mCSSStyleSheetURLs[i];
NS_ADDREF(aCSSStyleSheetURL);
p[mNumCSSStyleSheetURLs] = aCSSStyleSheetURL;
++mNumCSSStyleSheetURLs;
mCSSStyleSheetURLs = p;
for (i = mObservers.Count() - 1; i >= 0; --i) {
nsIRDFXMLDocumentObserver* obs = (nsIRDFXMLDocumentObserver*) mObservers[i];
obs->OnCSSStyleSheetAdded(aCSSStyleSheetURL);
}
return NS_OK;
}
NS_IMETHODIMP
StreamDataSourceImpl::GetCSSStyleSheetURLs(nsIURL*** aCSSStyleSheetURLs, PRInt32* aCount)
{
*aCSSStyleSheetURLs = mCSSStyleSheetURLs;
*aCount = mNumCSSStyleSheetURLs;
return NS_OK;
}
NS_IMETHODIMP
StreamDataSourceImpl::AddNamedDataSourceURI(const char* aNamedDataSourceURI)
{
NS_PRECONDITION(aNamedDataSourceURI != nsnull, "null ptr");
if (! aNamedDataSourceURI)
return NS_ERROR_NULL_POINTER;
char** p = new char*[mNumNamedDataSourceURIs + 1];
if (! p)
return NS_ERROR_OUT_OF_MEMORY;
PRInt32 i;
for (i = mNumNamedDataSourceURIs - 1; i >= 0; --i)
p[i] = mNamedDataSourceURIs[i];
PRInt32 len = PL_strlen(aNamedDataSourceURI);
char* buf = new char[len + 1];
if (! buf) {
delete p;
return NS_ERROR_OUT_OF_MEMORY;
}
PL_strcpy(buf, aNamedDataSourceURI);
p[mNumNamedDataSourceURIs] = buf;
++mNumNamedDataSourceURIs;
mNamedDataSourceURIs = p;
for (i = mObservers.Count() - 1; i >= 0; --i) {
nsIRDFXMLDocumentObserver* obs = (nsIRDFXMLDocumentObserver*) mObservers[i];
obs->OnNamedDataSourceAdded(aNamedDataSourceURI);
}
return NS_OK;
}
NS_IMETHODIMP
StreamDataSourceImpl::GetNamedDataSourceURIs(const char* const** aNamedDataSourceURIs, PRInt32* aCount)
{
*aNamedDataSourceURIs = mNamedDataSourceURIs;
*aCount = mNumNamedDataSourceURIs;
return NS_OK;
}
NS_IMETHODIMP
StreamDataSourceImpl::AddDocumentObserver(nsIRDFXMLDocumentObserver* aObserver)
{
mObservers.AppendElement(aObserver);
return NS_OK;
}
NS_IMETHODIMP
StreamDataSourceImpl::RemoveDocumentObserver(nsIRDFXMLDocumentObserver* aObserver)
{
mObservers.RemoveElement(aObserver);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// nsIRDFXMLSource methods
NS_IMETHODIMP NS_IMETHODIMP
StreamDataSourceImpl::Serialize(nsIOutputStream* stream) StreamDataSourceImpl::Serialize(nsIOutputStream* stream)
{ {

Просмотреть файл

@ -63,7 +63,7 @@
{ 0x7baf62e0, 0x8e61, 0x11d2, { 0x8e, 0xb1, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } } { 0x7baf62e0, 0x8e61, 0x11d2, { 0x8e, 0xb1, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
// {0958B101-9ADA-11d2-8EBC-00805F29F370} // {0958B101-9ADA-11d2-8EBC-00805F29F370}
#define NS_RDFSIMPLECONTENTSINK_CID \ #define NS_RDFCONTENTSINK_CID \
{ 0x958b101, 0x9ada, 0x11d2, { 0x8e, 0xbc, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } } { 0x958b101, 0x9ada, 0x11d2, { 0x8e, 0xbc, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }

Просмотреть файл

@ -41,7 +41,7 @@ static NS_DEFINE_CID(kRDFDocumentCID, NS_RDFDOCUMENT_CID);
static NS_DEFINE_CID(kRDFHTMLBuilderCID, NS_RDFHTMLBUILDER_CID); static NS_DEFINE_CID(kRDFHTMLBuilderCID, NS_RDFHTMLBUILDER_CID);
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID); static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kRDFSimpleContentSinkCID, NS_RDFSIMPLECONTENTSINK_CID); static NS_DEFINE_CID(kRDFContentSinkCID, NS_RDFCONTENTSINK_CID);
static NS_DEFINE_CID(kRDFStreamDataSourceCID, NS_RDFSTREAMDATASOURCE_CID); static NS_DEFINE_CID(kRDFStreamDataSourceCID, NS_RDFSTREAMDATASOURCE_CID);
static NS_DEFINE_CID(kRDFTreeBuilderCID, NS_RDFTREEBUILDER_CID); static NS_DEFINE_CID(kRDFTreeBuilderCID, NS_RDFTREEBUILDER_CID);
@ -155,8 +155,8 @@ RDFFactoryImpl::CreateInstance(nsISupports *aOuter,
if (NS_FAILED(rv = NS_NewRDFTreeBuilder((nsIRDFContentModelBuilder**) &inst))) if (NS_FAILED(rv = NS_NewRDFTreeBuilder((nsIRDFContentModelBuilder**) &inst)))
return rv; return rv;
} }
else if (mClassID.Equals(kRDFSimpleContentSinkCID)) { else if (mClassID.Equals(kRDFContentSinkCID)) {
if (NS_FAILED(rv = NS_NewRDFSimpleContentSink((nsIRDFContentSink**) &inst))) if (NS_FAILED(rv = NS_NewRDFContentSink((nsIRDFContentSink**) &inst)))
return rv; return rv;
} }
else { else {

Просмотреть файл

@ -1,4 +1,3 @@
nsIRDFContent.h nsIRDFContent.h
nsIRDFContentModelBuilder.h nsIRDFContentModelBuilder.h
nsIRDFContentSink.h
nsIRDFDocument.h nsIRDFDocument.h

Просмотреть файл

@ -27,7 +27,6 @@ MODULE = rdf
EXPORTS = \ EXPORTS = \
nsIRDFContent.h \ nsIRDFContent.h \
nsIRDFContentModelBuilder.h \ nsIRDFContentModelBuilder.h \
nsIRDFContentSink.h \
nsIRDFDocument.h \ nsIRDFDocument.h \
$(NULL) $(NULL)

Просмотреть файл

@ -23,7 +23,6 @@ DEPTH=..\..\..
EXPORTS = \ EXPORTS = \
nsIRDFContent.h \ nsIRDFContent.h \
nsIRDFContentModelBuilder.h \ nsIRDFContentModelBuilder.h \
nsIRDFContentSink.h \
nsIRDFDocument.h \ nsIRDFDocument.h \
$(NULL) $(NULL)

Просмотреть файл

@ -27,15 +27,12 @@ include $(topsrcdir)/config/config.mk
LIBRARY_NAME = rdfcontent_s LIBRARY_NAME = rdfcontent_s
CPPSRCS = \ CPPSRCS = \
nsRDFContentSink.cpp \
nsRDFContentUtils.cpp \ nsRDFContentUtils.cpp \
nsRDFDOMNodeList.cpp \ nsRDFDOMNodeList.cpp \
nsRDFDocument.cpp \ nsRDFDocument.cpp \
nsRDFDocumentContentSink.cpp \
nsRDFGenericElement.cpp \ nsRDFGenericElement.cpp \
nsRDFHTMLBuilder.cpp \ nsRDFHTMLBuilder.cpp \
nsRDFResourceElement.cpp \ nsRDFResourceElement.cpp \
nsRDFSimpleContentSink.cpp \
nsRDFTreeBuilder.cpp \ nsRDFTreeBuilder.cpp \
$(NULL) $(NULL)

Просмотреть файл

@ -20,15 +20,12 @@ MODULE=rdf
LIBRARY_NAME=rdfcontent_s LIBRARY_NAME=rdfcontent_s
CPP_OBJS=\ CPP_OBJS=\
.\$(OBJDIR)\nsRDFContentSink.obj \
.\$(OBJDIR)\nsRDFContentUtils.obj \ .\$(OBJDIR)\nsRDFContentUtils.obj \
.\$(OBJDIR)\nsRDFDOMNodeList.obj \ .\$(OBJDIR)\nsRDFDOMNodeList.obj \
.\$(OBJDIR)\nsRDFDocument.obj \ .\$(OBJDIR)\nsRDFDocument.obj \
.\$(OBJDIR)\nsRDFDocumentContentSink.obj \
.\$(OBJDIR)\nsRDFGenericElement.obj \ .\$(OBJDIR)\nsRDFGenericElement.obj \
.\$(OBJDIR)\nsRDFHTMLBuilder.obj \ .\$(OBJDIR)\nsRDFHTMLBuilder.obj \
.\$(OBJDIR)\nsRDFResourceElement.obj \ .\$(OBJDIR)\nsRDFResourceElement.obj \
.\$(OBJDIR)\nsRDFSimpleContentSink.obj \
.\$(OBJDIR)\nsRDFTreeBuilder.obj \ .\$(OBJDIR)\nsRDFTreeBuilder.obj \
$(NULL) $(NULL)

Просмотреть файл

@ -32,45 +32,6 @@ static NS_DEFINE_IID(kITextContentIID, NS_ITEXT_CONTENT_IID); // XXX grr...
static NS_DEFINE_CID(kTextNodeCID, NS_TEXTNODE_CID); static NS_DEFINE_CID(kTextNodeCID, NS_TEXTNODE_CID);
nsresult
rdf_GetQuotedAttributeValue(const nsString& aSource,
const nsString& aAttribute,
nsString& aValue)
{
static const char kQuote = '\"';
static const char kApostrophe = '\'';
PRInt32 offset;
PRInt32 endOffset = -1;
nsresult result = NS_OK;
offset = aSource.Find(aAttribute);
if (-1 != offset) {
offset = aSource.Find('=', offset);
PRUnichar next = aSource.CharAt(++offset);
if (kQuote == next) {
endOffset = aSource.Find(kQuote, ++offset);
}
else if (kApostrophe == next) {
endOffset = aSource.Find(kApostrophe, ++offset);
}
if (-1 != endOffset) {
aSource.Mid(aValue, offset, endOffset-offset);
}
else {
// Mismatched quotes - return an error
result = NS_ERROR_FAILURE;
}
}
else {
aValue.Truncate();
}
return result;
}
nsresult nsresult

Просмотреть файл

@ -23,14 +23,21 @@
implementation serves as the basis for generating an NGLayout implementation serves as the basis for generating an NGLayout
content model. content model.
TO DO
1) Figure out how to get rid of the DummyListener hack.
*/ */
#include "nsIArena.h" #include "nsIArena.h"
#include "nsICollection.h" #include "nsICollection.h"
#include "nsIContent.h" #include "nsIContent.h"
#include "nsICSSParser.h"
#include "nsICSSStyleSheet.h"
#include "nsIDTD.h" #include "nsIDTD.h"
#include "nsIDocument.h" #include "nsIDocument.h"
#include "nsIDocumentObserver.h" #include "nsIDocumentObserver.h"
#include "nsIEnumerator.h"
#include "nsIHTMLStyleSheet.h" #include "nsIHTMLStyleSheet.h"
#include "nsINameSpaceManager.h" #include "nsINameSpaceManager.h"
#include "nsIParser.h" #include "nsIParser.h"
@ -45,6 +52,7 @@
#include "nsIRDFNode.h" #include "nsIRDFNode.h"
#include "nsIRDFObserver.h" #include "nsIRDFObserver.h"
#include "nsIRDFService.h" #include "nsIRDFService.h"
#include "nsIRDFXMLDocument.h"
#include "nsIScriptContextOwner.h" #include "nsIScriptContextOwner.h"
#include "nsIServiceManager.h" #include "nsIServiceManager.h"
#include "nsIStreamListener.h" #include "nsIStreamListener.h"
@ -64,6 +72,7 @@
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
static NS_DEFINE_IID(kICSSParserIID, NS_ICSS_PARSER_IID); // XXX grr..
static NS_DEFINE_IID(kICollectionIID, NS_ICOLLECTION_IID); static NS_DEFINE_IID(kICollectionIID, NS_ICOLLECTION_IID);
static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID); static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID);
static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID); static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID);
@ -78,17 +87,21 @@ static NS_DEFINE_IID(kIRDFDocumentIID, NS_IRDFDOCUMENT_IID);
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID); static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID); static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID); static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
static NS_DEFINE_IID(kIRDFXMLDocumentIID, NS_IRDFXMLDOCUMENT_IID);
static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID); static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID);
static NS_DEFINE_IID(kIStreamObserverIID, NS_ISTREAMOBSERVER_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID); static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
static NS_DEFINE_IID(kIXMLDocumentIID, NS_IXMLDOCUMENT_IID); static NS_DEFINE_IID(kIXMLDocumentIID, NS_IXMLDOCUMENT_IID);
static NS_DEFINE_CID(kCSSParserCID, NS_CSSPARSER_CID);
static NS_DEFINE_CID(kHTMLStyleSheetCID, NS_HTMLSTYLESHEET_CID); static NS_DEFINE_CID(kHTMLStyleSheetCID, NS_HTMLSTYLESHEET_CID);
static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID); static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID);
static NS_DEFINE_CID(kParserCID, NS_PARSER_IID); // XXX static NS_DEFINE_CID(kParserCID, NS_PARSER_IID); // XXX
static NS_DEFINE_CID(kPresShellCID, NS_PRESSHELL_CID); static NS_DEFINE_CID(kPresShellCID, NS_PRESSHELL_CID);
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID); static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kRDFStreamDataSourceCID, NS_RDFSTREAMDATASOURCE_CID);
static NS_DEFINE_CID(kRDFDataBaseCID, NS_RDFDATABASE_CID); static NS_DEFINE_CID(kRDFDataBaseCID, NS_RDFDATABASE_CID);
static NS_DEFINE_CID(kRangeListCID, NS_RANGELIST_CID); static NS_DEFINE_CID(kRangeListCID, NS_RANGELIST_CID);
static NS_DEFINE_CID(kWellFormedDTDCID, NS_WELLFORMEDDTD_CID); static NS_DEFINE_CID(kWellFormedDTDCID, NS_WELLFORMEDDTD_CID);
@ -106,7 +119,8 @@ rdf_HashPointer(const void* key)
class RDFDocumentImpl : public nsIDocument, class RDFDocumentImpl : public nsIDocument,
public nsIRDFDocument, public nsIRDFDocument,
public nsIRDFObserver public nsIRDFObserver,
public nsIRDFXMLDocumentObserver
{ {
public: public:
RDFDocumentImpl(); RDFDocumentImpl();
@ -281,12 +295,32 @@ public:
nsIRDFResource* predicate, nsIRDFResource* predicate,
nsIRDFNode* object); nsIRDFNode* object);
// nsIRDFXMLDocumentObserver interface
NS_IMETHOD OnBeginLoad(void);
NS_IMETHOD OnInterrupt(void);
NS_IMETHOD OnResume(void);
NS_IMETHOD OnEndLoad(void);
NS_IMETHOD OnRootResourceFound(nsIRDFResource* aResource);
NS_IMETHOD OnCSSStyleSheetAdded(nsIURL* aStyleSheetURI);
NS_IMETHOD OnNamedDataSourceAdded(const char* aNamedDataSourceURI);
// Implementation methods
nsresult StartLayout(void);
protected: protected:
nsIContent* nsIContent*
FindContent(const nsIContent* aStartNode, FindContent(const nsIContent* aStartNode,
const nsIContent* aTest1, const nsIContent* aTest1,
const nsIContent* aTest2) const; const nsIContent* aTest2) const;
nsresult
LoadCSSStyleSheet(nsIURL* url);
nsresult
AddNamedDataSource(const char* uri);
nsIArena* mArena; nsIArena* mArena;
nsVoidArray mObservers; nsVoidArray mObservers;
nsAutoString mDocumentTitle; nsAutoString mDocumentTitle;
@ -302,15 +336,109 @@ protected:
nsVoidArray mPresShells; nsVoidArray mPresShells;
nsINameSpaceManager* mNameSpaceManager; nsINameSpaceManager* mNameSpaceManager;
nsIStyleSheet* mAttrStyleSheet; nsIStyleSheet* mAttrStyleSheet;
nsIParser* mParser;
nsIRDFDataBase* mDB; nsIRDFDataBase* mDB;
nsIRDFService* mRDFService; nsIRDFService* mRDFService;
nsISupportsArray* mTreeProperties; nsISupportsArray* mTreeProperties;
nsIRDFContentModelBuilder* mBuilder; nsIRDFContentModelBuilder* mBuilder;
PLHashTable* mResources; PLHashTable* mResources;
nsIRDFDataSource* mLocalDataSource;
nsIRDFDataSource* mDocumentDataSource;
}; };
////////////////////////////////////////////////////////////////////////
// DummyListener
//
// This is a _total_ hack that is used to get stuff to draw right
// when a second copy is loaded. I need to talk to Guha about what
// the expected behavior should be...
//
class DummyListener : public nsIStreamListener
{
private:
RDFDocumentImpl* mRDFDocument;
PRBool mWasNotifiedOnce; // XXX why do we get _two_ OnStart/StopBinding() calls?
public:
DummyListener(RDFDocumentImpl* aRDFDocument)
: mRDFDocument(aRDFDocument),
mWasNotifiedOnce(PR_FALSE)
{
NS_INIT_REFCNT();
NS_ADDREF(mRDFDocument);
}
virtual ~DummyListener(void) {
NS_RELEASE(mRDFDocument);
}
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIStreamObserver interface
NS_IMETHOD
OnStartBinding(nsIURL* aURL, const char *aContentType) {
if (! mWasNotifiedOnce) {
mRDFDocument->BeginLoad();
mRDFDocument->StartLayout();
}
return NS_OK;
}
NS_IMETHOD
OnProgress(nsIURL* aURL, PRUint32 aProgress, PRUint32 aProgressMax) {
return NS_OK;
}
NS_IMETHOD OnStatus(nsIURL* aURL, const PRUnichar* aMsg) {
return NS_OK;
}
NS_IMETHOD OnStopBinding(nsIURL* aURL, nsresult aStatus, const PRUnichar* aMsg) {
if (! mWasNotifiedOnce) {
mRDFDocument->EndLoad();
mWasNotifiedOnce = PR_TRUE;
}
return NS_OK;
}
// nsIStreamListener interface
NS_IMETHOD
GetBindInfo(nsIURL* aURL, nsStreamBindingInfo* aInfo) {
aInfo->seekable = PR_FALSE;
return NS_OK;
}
NS_IMETHOD
OnDataAvailable(nsIURL* aURL, nsIInputStream *aIStream, PRUint32 aLength) {
return NS_OK;
}
};
NS_IMPL_ADDREF(DummyListener);
NS_IMPL_RELEASE(DummyListener);
NS_IMETHODIMP
DummyListener::QueryInterface(REFNSIID aIID, void** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
if (aIID.Equals(kIStreamListenerIID) ||
aIID.Equals(kIStreamObserverIID) ||
aIID.Equals(kISupportsIID)) {
*aResult = NS_STATIC_CAST(nsIStreamListener*, this);
NS_ADDREF(this);
return NS_OK;
}
else {
*aResult = nsnull;
return NS_NOINTERFACE;
}
}
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// ctors & dtors // ctors & dtors
@ -325,12 +453,13 @@ RDFDocumentImpl::RDFDocumentImpl(void)
mDisplaySelection(PR_FALSE), mDisplaySelection(PR_FALSE),
mNameSpaceManager(nsnull), mNameSpaceManager(nsnull),
mAttrStyleSheet(nsnull), mAttrStyleSheet(nsnull),
mParser(nsnull),
mDB(nsnull), mDB(nsnull),
mRDFService(nsnull), mRDFService(nsnull),
mTreeProperties(nsnull), mTreeProperties(nsnull),
mBuilder(nsnull), mBuilder(nsnull),
mResources(nsnull) mResources(nsnull),
mLocalDataSource(nsnull),
mDocumentDataSource(nsnull)
{ {
NS_INIT_REFCNT(); NS_INIT_REFCNT();
@ -348,11 +477,19 @@ RDFDocumentImpl::RDFDocumentImpl(void)
RDFDocumentImpl::~RDFDocumentImpl() RDFDocumentImpl::~RDFDocumentImpl()
{ {
if (mDocumentDataSource) {
nsIRDFXMLDocument* doc;
if (NS_SUCCEEDED(mDocumentDataSource->QueryInterface(kIRDFXMLDocumentIID, (void**) &doc))) {
doc->RemoveDocumentObserver(this);
NS_RELEASE(doc);
}
NS_RELEASE(mDocumentDataSource);
}
NS_IF_RELEASE(mLocalDataSource);
if (mResources) if (mResources)
PL_HashTableDestroy(mResources); PL_HashTableDestroy(mResources);
NS_IF_RELEASE(mParser);
if (mRDFService) { if (mRDFService) {
nsServiceManager::ReleaseService(kRDFServiceCID, mRDFService); nsServiceManager::ReleaseService(kRDFServiceCID, mRDFService);
mRDFService = nsnull; mRDFService = nsnull;
@ -439,99 +576,145 @@ RDFDocumentImpl::StartDocumentLoad(nsIURL *aURL,
(void)aURL->GetURLGroup(&mDocumentURLGroup); (void)aURL->GetURLGroup(&mDocumentURLGroup);
rv = nsRepository::CreateInstance(kParserCID, // Create an HTML style sheet for the HTML content.
nsnull, nsIHTMLStyleSheet* sheet;
kIParserIID, if (NS_SUCCEEDED(rv = nsRepository::CreateInstance(kHTMLStyleSheetCID,
(void**) &mParser); nsnull,
PR_ASSERT(NS_SUCCEEDED(rv)); kIHTMLStyleSheetIID,
(void**) &sheet))) {
if (NS_SUCCEEDED(rv = sheet->Init(aURL, this))) {
mAttrStyleSheet = sheet;
NS_ADDREF(mAttrStyleSheet);
AddStyleSheet(mAttrStyleSheet);
}
NS_RELEASE(sheet);
}
if (NS_FAILED(rv)) if (NS_FAILED(rv))
return rv; return rv;
nsIWebShell* webShell = nsnull; // Create a "scratch" in-memory data store to associate with the
nsIRDFContentSink* sink = nsnull; // document to be a catch-all for any doc-specific info that we
nsIRDFDataSource* ds = nsnull; // need to store (e.g., current sort order, etc.)
nsIHTMLStyleSheet* sheet = nsnull;
nsIDTD* dtd = nsnull;
if (NS_FAILED(rv = aContainer->QueryInterface(kIWebShellIID, (void**)&webShell))) {
PR_ASSERT(0);
goto done;
}
if (NS_FAILED(rv = NS_NewRDFDocumentContentSink(&sink, this, aURL, webShell))) {
PR_ASSERT(0);
goto done;
}
NS_RELEASE(webShell);
if (NS_FAILED(rv = nsRepository::CreateInstance(kRDFInMemoryDataSourceCID, if (NS_FAILED(rv = nsRepository::CreateInstance(kRDFInMemoryDataSourceCID,
nsnull, nsnull,
kIRDFDataSourceIID, kIRDFDataSourceIID,
(void**) &ds))) { (void**) &mLocalDataSource)))
return rv;
if (NS_FAILED(rv = mDB->AddDataSource(mLocalDataSource)))
return rv;
const char* uri;
if (NS_FAILED(rv = aURL->GetSpec(&uri)))
return rv;
// Now load the actual XML/RDF document data source.
if (NS_SUCCEEDED(rv = mRDFService->GetDataSource(uri, &mDocumentDataSource))) {
if (NS_FAILED(rv = mDB->AddDataSource(mDocumentDataSource)))
return rv;
// we found the data source already loaded locally. Load it's
// style sheets and attempt to include any named data sources
// that it references into this document.
nsIRDFXMLDocument* doc;
if (NS_SUCCEEDED(rv = mDocumentDataSource->QueryInterface(kIRDFXMLDocumentIID, (void**) &doc))) {
nsIURL** styleSheetURLs;
PRInt32 count;
if (NS_SUCCEEDED(rv = doc->GetCSSStyleSheetURLs(&styleSheetURLs, &count))) {
for (PRInt32 i = 0; i < count; ++i) {
if (NS_FAILED(rv = LoadCSSStyleSheet(styleSheetURLs[i]))) {
NS_ASSERTION(PR_FALSE, "couldn't load style sheet");
}
}
}
const char* const* namedDataSourceURIs;
if (NS_SUCCEEDED(rv = doc->GetNamedDataSourceURIs(&namedDataSourceURIs, &count))) {
for (PRInt32 i = 0; i < count; ++i) {
if (NS_FAILED(rv = AddNamedDataSource(namedDataSourceURIs[i]))) {
#ifdef DEBUG
printf("error adding named data source %s\n", namedDataSourceURIs[i]);
#endif
}
}
}
nsIRDFResource* root;
if (NS_SUCCEEDED(rv = doc->GetRootResource(&root))) {
SetRootResource(root);
StartLayout();
}
NS_RELEASE(doc);
}
// XXX Allright, this is an atrocious hack. Basically, we
// construct a dummy listener object so that we can load the
// URL, which allows us to receive StartLayout() and EndLoad()
// calls asynchronously. If we don't do this, then there is no
// way (that I could figure out) to force the content model to
// be traversed so that a document is laid out again.
//
// Looking at the "big picture" here, the real problem is that
// the "registered" data sources mechanism is really just a
// cache of stream data sources. It's not really clear what
// should happen when somebody opens a second document on the
// same source. You'd kinda like both to refer to the same
// thing, so changes to one are immediately reflected in the
// other. On the other hand, you'd also like to be able to
// _unload_ and reload a content model, say by doing
// "shift+reload". _So_, that kinda ties into the real cache,
// etc. etc.
//
// What I guess I'm saying is, maybe it doesn't make that much
// sense to register stream data sources when they're
// created...I dunno...
if (aDocListener) {
nsIStreamListener* lsnr = new DummyListener(this);
if (! lsnr)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(lsnr);
*aDocListener = lsnr;
if (NS_FAILED(rv = NS_OpenURL(aURL, lsnr)))
return rv;
}
}
else if (NS_SUCCEEDED(rv = nsRepository::CreateInstance(kRDFStreamDataSourceCID,
nsnull,
kIRDFDataSourceIID,
(void**) &mDocumentDataSource))) {
if (NS_FAILED(rv = mDB->AddDataSource(mDocumentDataSource)))
return rv;
// We need to construct a new stream and load it. The stream
// will automagically register itself as a named data source,
// so if subsequent docs ask for it, they'll get the real
// deal. In the meantime, add us as an
// nsIRDFXMLDocumentObserver so that we'll be notified when we
// need to load style sheets, etc.
nsIRDFXMLDocument* doc;
if (NS_SUCCEEDED(rv = mDocumentDataSource->QueryInterface(kIRDFXMLDocumentIID, (void**) &doc))) {
doc->AddDocumentObserver(this);
NS_RELEASE(doc);
}
if (NS_FAILED(rv = mDocumentDataSource->Init(uri)))
return rv;
if (aDocListener) {
*aDocListener = nsnull;
}
}
else {
// an error occurred
PR_ASSERT(0); PR_ASSERT(0);
goto done;
} }
if (NS_FAILED(rv = sink->SetDataSource(ds))) { return NS_OK;
PR_ASSERT(0);
goto done;
}
if (NS_FAILED(rv = mDB->AddDataSource(ds))) {
PR_ASSERT(0);
goto done;
}
// Create an HTML style sheet for the HTML content.
if (NS_FAILED(rv = nsRepository::CreateInstance(kHTMLStyleSheetCID,
nsnull,
kIHTMLStyleSheetIID,
(void**) &sheet))) {
PR_ASSERT(0);
goto done;
}
if (NS_FAILED(rv = sheet->Init(aURL, this))) {
PR_ASSERT(0);
goto done;
}
mAttrStyleSheet = sheet;
NS_ADDREF(mAttrStyleSheet);
AddStyleSheet(mAttrStyleSheet);
// Set the parser as the stream listener for the document loader...
if (NS_FAILED(rv = mParser->QueryInterface(kIStreamListenerIID, (void**)aDocListener))) {
PR_ASSERT(0);
goto done;
}
if (NS_FAILED(rv = nsRepository::CreateInstance(kWellFormedDTDCID,
nsnull,
kIDTDIID,
(void**) &dtd))) {
PR_ASSERT(0);
goto done;
}
mParser->RegisterDTD(dtd);
mParser->SetCommand(aCommand);
mParser->SetContentSink(sink);
if (NS_FAILED(rv = mParser->Parse(aURL))) {
PR_ASSERT(0);
goto done;
}
done:
NS_IF_RELEASE(dtd);
NS_IF_RELEASE(sheet);
NS_IF_RELEASE(ds);
NS_IF_RELEASE(sink);
NS_IF_RELEASE(webShell);
return rv;
} }
const nsString* const nsString*
@ -568,9 +751,9 @@ RDFDocumentImpl::SetDocumentCharacterSet(nsCharSetID aCharSetID)
nsresult nsresult
RDFDocumentImpl::CreateShell(nsIPresContext* aContext, RDFDocumentImpl::CreateShell(nsIPresContext* aContext,
nsIViewManager* aViewManager, nsIViewManager* aViewManager,
nsIStyleSet* aStyleSet, nsIStyleSet* aStyleSet,
nsIPresShell** aInstancePtrResult) nsIPresShell** aInstancePtrResult)
{ {
NS_PRECONDITION(aInstancePtrResult, "null ptr"); NS_PRECONDITION(aInstancePtrResult, "null ptr");
if (! aInstancePtrResult) if (! aInstancePtrResult)
@ -591,7 +774,7 @@ RDFDocumentImpl::CreateShell(nsIPresContext* aContext,
} }
mPresShells.AppendElement(shell); mPresShells.AppendElement(shell);
*aInstancePtrResult = shell; *aInstancePtrResult = shell; // addref implicit
return NS_OK; return NS_OK;
} }
@ -772,7 +955,7 @@ RDFDocumentImpl::SetScriptContextOwner(nsIScriptContextOwner *aScriptContextOwne
// reference to the document. This has to be done before we // reference to the document. This has to be done before we
// actually set the script context owner to null so that the // actually set the script context owner to null so that the
// content elements can remove references to their script objects. // content elements can remove references to their script objects.
if (!aScriptContextOwner && !mRootContent) if (!aScriptContextOwner && mRootContent)
mRootContent->SetDocument(nsnull, PR_TRUE); mRootContent->SetDocument(nsnull, PR_TRUE);
NS_IF_RELEASE(mScriptContextOwner); NS_IF_RELEASE(mScriptContextOwner);
@ -825,8 +1008,6 @@ RDFDocumentImpl::EndLoad()
nsIDocumentObserver* observer = (nsIDocumentObserver*) mObservers[i]; nsIDocumentObserver* observer = (nsIDocumentObserver*) mObservers[i];
observer->EndLoad(this); observer->EndLoad(this);
} }
NS_IF_RELEASE(mParser);
return NS_OK; return NS_OK;
} }
@ -1094,7 +1275,7 @@ RDFDocumentImpl::IsBefore(const nsIContent *aNewContent, const nsIContent* aCurr
PRBool result = PR_FALSE; PRBool result = PR_FALSE;
if (nsnull != aNewContent && nsnull != aCurrentContent && aNewContent != aCurrentContent) { if (nsnull != aNewContent && nsnull != aCurrentContent && aNewContent != aCurrentContent) {
nsIContent* test = FindContent(mRootContent,aNewContent,aCurrentContent); nsIContent* test = FindContent(mRootContent, aNewContent, aCurrentContent);
if (test == aNewContent) if (test == aNewContent)
result = PR_TRUE; result = PR_TRUE;
@ -1604,14 +1785,69 @@ RDFDocumentImpl::OnUnassert(nsIRDFResource* subject,
} }
////////////////////////////////////////////////////////////////////////
// nsIRDFXMLDocumentObserver interface
NS_IMETHODIMP
RDFDocumentImpl::OnBeginLoad(void)
{
return BeginLoad();
}
NS_IMETHODIMP
RDFDocumentImpl::OnInterrupt(void)
{
// flow any content that we have up until now.
return NS_OK;
}
NS_IMETHODIMP
RDFDocumentImpl::OnResume(void)
{
return NS_OK;
}
NS_IMETHODIMP
RDFDocumentImpl::OnEndLoad(void)
{
return EndLoad();
}
NS_IMETHODIMP
RDFDocumentImpl::OnRootResourceFound(nsIRDFResource* aResource)
{
nsresult rv;
if (NS_SUCCEEDED(rv = SetRootResource(aResource))) {
rv = StartLayout();
}
return rv;
}
NS_IMETHODIMP
RDFDocumentImpl::OnCSSStyleSheetAdded(nsIURL* aStyleSheetURL)
{
return LoadCSSStyleSheet(aStyleSheetURL);
}
NS_IMETHODIMP
RDFDocumentImpl::OnNamedDataSourceAdded(const char* aNamedDataSourceURI)
{
return AddNamedDataSource(aNamedDataSourceURI);
}
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// Implementation methods // Implementation methods
nsIContent* nsIContent*
RDFDocumentImpl::FindContent(const nsIContent* aStartNode, RDFDocumentImpl::FindContent(const nsIContent* aStartNode,
const nsIContent* aTest1, const nsIContent* aTest1,
const nsIContent* aTest2) const const nsIContent* aTest2) const
{ {
PRInt32 count; PRInt32 count;
aStartNode->ChildCount(count); aStartNode->ChildCount(count);
@ -1636,6 +1872,106 @@ RDFDocumentImpl::FindContent(const nsIContent* aStartNode,
} }
nsresult
RDFDocumentImpl::LoadCSSStyleSheet(nsIURL* url)
{
nsresult rv;
nsIInputStream* iin;
rv = NS_OpenURL(url, &iin);
if (NS_OK != rv) {
NS_RELEASE(url);
return rv;
}
nsIUnicharInputStream* uin = nsnull;
rv = NS_NewConverterStream(&uin, nsnull, iin);
NS_RELEASE(iin);
if (NS_OK != rv) {
NS_RELEASE(url);
return rv;
}
nsICSSParser* parser;
rv = nsRepository::CreateInstance(kCSSParserCID,
nsnull,
kICSSParserIID,
(void**) &parser);
if (NS_SUCCEEDED(rv)) {
nsICSSStyleSheet* sheet = nsnull;
// XXX note: we are ignoring rv until the error code stuff in the
// input routines is converted to use nsresult's
parser->SetCaseSensitive(PR_TRUE);
parser->Parse(uin, url, sheet);
if (nsnull != sheet) {
AddStyleSheet(sheet);
NS_RELEASE(sheet);
rv = NS_OK;
} else {
rv = NS_ERROR_OUT_OF_MEMORY;/* XXX */
}
NS_RELEASE(parser);
}
NS_RELEASE(uin);
NS_RELEASE(url);
return rv;
}
nsresult
RDFDocumentImpl::AddNamedDataSource(const char* uri)
{
nsresult rv;
nsIRDFDataSource* ds = nsnull;
if (NS_FAILED(rv = mRDFService->GetDataSource(uri, &ds)))
goto done;
if (NS_FAILED(rv = mDB->AddDataSource(ds)))
goto done;
done:
NS_IF_RELEASE(ds);
return rv;
}
nsresult
RDFDocumentImpl::StartLayout(void)
{
PRInt32 count = GetNumberOfShells();
for (PRInt32 i = 0; i < count; i++) {
nsIPresShell* shell = GetShellAt(i);
if (nsnull == shell)
continue;
// Resize-reflow this time
nsIPresContext* cx = shell->GetPresContext();
nsRect r;
cx->GetVisibleArea(r);
shell->InitialReflow(r.width, r.height);
NS_RELEASE(cx);
// Now trigger a refresh
nsIViewManager* vm = shell->GetViewManager();
if (nsnull != vm) {
vm->EnableRefresh();
NS_RELEASE(vm);
}
// Start observing the document _after_ we do the initial
// reflow. Otherwise, we'll get into an trouble trying to
// creat kids before the root frame is established.
shell->BeginObservingDocument();
NS_RELEASE(shell);
}
return NS_OK;
}
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
nsresult nsresult

Просмотреть файл

@ -1,379 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
/*
A content sink implementation that builds a feeds a content model
via the nsIRDFDocument interface.
*/
#include "nsICSSParser.h"
#include "nsIContent.h"
#include "nsIDOMComment.h"
#include "nsIDocument.h"
#include "nsIPresShell.h"
#include "nsIPresContext.h"
#include "nsICSSStyleSheet.h"
#include "nsIRDFContent.h"
#include "nsIRDFDataBase.h"
#include "nsIRDFDocument.h"
#include "nsIRDFNode.h"
#include "nsIRDFService.h"
#include "nsIURL.h"
#include "nsIWebShell.h"
#include "nsLayoutCID.h"
#include "nsRDFContentSink.h"
#include "nsRDFContentUtils.h"
#include "nsINameSpaceManager.h"
////////////////////////////////////////////////////////////////////////
static NS_DEFINE_IID(kICSSParserIID, NS_ICSS_PARSER_IID); // XXX grr..
static NS_DEFINE_IID(kIDOMCommentIID, NS_IDOMCOMMENT_IID);
static NS_DEFINE_IID(kIRDFContentSinkIID, NS_IRDFCONTENTSINK_IID);
static NS_DEFINE_IID(kIRDFContentIID, NS_IRDFCONTENT_IID);
static NS_DEFINE_IID(kIRDFDocumentIID, NS_IRDFDOCUMENT_IID);
static NS_DEFINE_IID(kIScrollableViewIID, NS_ISCROLLABLEVIEW_IID);
static NS_DEFINE_CID(kCSSParserCID, NS_CSSPARSER_CID);
class nsRDFDocumentContentSink : public nsRDFContentSink
{
public:
nsRDFDocumentContentSink(void);
virtual ~nsRDFDocumentContentSink(void);
virtual nsresult Init(nsIDocument* aDoc,
nsIURL* aURL,
nsIWebShell* aContainer);
// nsIContentSink
NS_IMETHOD WillBuildModel(void);
NS_IMETHOD DidBuildModel(PRInt32 aQualityLevel);
NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode);
protected:
virtual nsresult OpenObject(const nsIParserNode& aNode);
// Style sheets
nsresult LoadStyleSheet(nsIURL* aURL,
nsIUnicharInputStream* aUIN);
nsresult StartLayout(void);
nsIStyleSheet* mStyleSheet;
// Document, webshell, etc.
nsIDocument* mDocument;
nsIContent* mRootElement;
nsIWebShell* mWebShell;
};
////////////////////////////////////////////////////////////////////////
nsRDFDocumentContentSink::nsRDFDocumentContentSink(void)
{
mDocument = nsnull;
mWebShell = nsnull;
mRootElement = nsnull;
}
nsRDFDocumentContentSink::~nsRDFDocumentContentSink(void)
{
NS_IF_RELEASE(mDocument);
NS_IF_RELEASE(mWebShell);
NS_IF_RELEASE(mRootElement);
}
nsresult
nsRDFDocumentContentSink::Init(nsIDocument* aDoc,
nsIURL* aURL,
nsIWebShell* aContainer)
{
NS_PRECONDITION(aDoc && aContainer, "null ptr");
if (!aDoc || !aContainer)
return NS_ERROR_NULL_POINTER;
nsINameSpaceManager* nameSpaceManager = nsnull;
nsresult rv = aDoc->GetNameSpaceManager(nameSpaceManager);
if (NS_SUCCEEDED(rv)) {
rv = nsRDFContentSink::Init(aURL, nameSpaceManager);
if (NS_SUCCEEDED(rv)) {
mDocument = aDoc;
NS_ADDREF(aDoc);
mWebShell = aContainer;
NS_ADDREF(aContainer);
}
NS_RELEASE(nameSpaceManager);
}
return rv;
}
// XXX Borrowed from HTMLContentSink. Should be shared.
nsresult
nsRDFDocumentContentSink::LoadStyleSheet(nsIURL* aURL,
nsIUnicharInputStream* aUIN)
{
nsresult rv;
nsICSSParser* parser;
rv = nsRepository::CreateInstance(kCSSParserCID,
nsnull,
kICSSParserIID,
(void**) &parser);
if (NS_SUCCEEDED(rv)) {
nsICSSStyleSheet* sheet = nsnull;
// XXX note: we are ignoring rv until the error code stuff in the
// input routines is converted to use nsresult's
parser->SetCaseSensitive(PR_TRUE);
parser->Parse(aUIN, aURL, sheet);
if (nsnull != sheet) {
mDocument->AddStyleSheet(sheet);
NS_RELEASE(sheet);
rv = NS_OK;
} else {
rv = NS_ERROR_OUT_OF_MEMORY;/* XXX */
}
NS_RELEASE(parser);
}
return rv;
}
nsresult
nsRDFDocumentContentSink::StartLayout(void)
{
PRInt32 count = mDocument->GetNumberOfShells();
for (PRInt32 i = 0; i < count; i++) {
nsIPresShell* shell = mDocument->GetShellAt(i);
if (nsnull != shell) {
// Resize-reflow this time
nsIPresContext* cx = shell->GetPresContext();
nsRect r;
cx->GetVisibleArea(r);
shell->InitialReflow(r.width, r.height);
NS_RELEASE(cx);
// Now trigger a refresh
nsIViewManager* vm = shell->GetViewManager();
if (nsnull != vm) {
vm->EnableRefresh();
NS_RELEASE(vm);
}
// Start observing the document _after_ we do the initial
// reflow. Otherwise, we'll get into an trouble trying to
// creat kids before the root frame is established.
shell->BeginObservingDocument();
NS_RELEASE(shell);
}
}
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// nsIContentSink interface
NS_IMETHODIMP
nsRDFDocumentContentSink::WillBuildModel(void)
{
mDocument->BeginLoad();
return NS_OK;
}
NS_IMETHODIMP
nsRDFDocumentContentSink::DidBuildModel(PRInt32 aQualityLevel)
{
//StartLayout();
mDocument->EndLoad();
return NS_OK;
}
NS_IMETHODIMP
nsRDFDocumentContentSink::AddProcessingInstruction(const nsIParserNode& aNode)
{
static const char kStyleSheetPI[] = "<?xml-stylesheet";
static const char kCSSType[] = "text/css";
static const char kDataSourcePI[] = "<?rdf-datasource";
nsresult rv;
if (NS_FAILED(rv = nsRDFContentSink::AddProcessingInstruction(aNode)))
return rv;
// XXX For now, we don't add the PI to the content model.
// We just check for a style sheet PI
const nsString& text = aNode.GetText();
// If it's a stylesheet PI...
if (0 == text.Find(kStyleSheetPI)) {
nsAutoString href;
rv = rdf_GetQuotedAttributeValue(text, "href", href);
// If there was an error or there's no href, we can't do
// anything with this PI
if ((NS_OK != rv) || (0 == href.Length())) {
return rv;
}
nsAutoString type;
rv = rdf_GetQuotedAttributeValue(text, "type", type);
if (NS_OK != rv) {
return rv;
}
if (type.Equals(kCSSType)) {
nsIURL* url = nsnull;
nsIUnicharInputStream* uin = nsnull;
nsAutoString absURL;
nsIURL* docURL = mDocument->GetDocumentURL();
nsAutoString emptyURL;
emptyURL.Truncate();
rv = NS_MakeAbsoluteURL(docURL, emptyURL, href, absURL);
if (NS_OK != rv) {
return rv;
}
NS_RELEASE(docURL);
rv = NS_NewURL(&url, absURL);
if (NS_OK != rv) {
return rv;
}
nsIInputStream* iin;
rv = NS_OpenURL(url, &iin);
if (NS_OK != rv) {
NS_RELEASE(url);
return rv;
}
rv = NS_NewConverterStream(&uin, nsnull, iin);
NS_RELEASE(iin);
if (NS_OK != rv) {
NS_RELEASE(url);
return rv;
}
rv = LoadStyleSheet(url, uin);
NS_RELEASE(uin);
NS_RELEASE(url);
}
}
else if (0 == text.Find(kDataSourcePI)) {
nsAutoString href;
rv = rdf_GetQuotedAttributeValue(text, "href", href);
if (NS_FAILED(rv) || (0 == href.Length()))
return rv;
char uri[256];
href.ToCString(uri, sizeof(uri));
nsIRDFDataSource* ds;
if (NS_SUCCEEDED(rv = mRDFService->GetNamedDataSource(uri, &ds))) {
nsIRDFDocument* rdfDoc;
if (NS_SUCCEEDED(mDocument->QueryInterface(kIRDFDocumentIID, (void**) &rdfDoc))) {
nsIRDFDataBase* db;
if (NS_SUCCEEDED(rv = rdfDoc->GetDataBase(db))) {
rv = db->AddDataSource(ds);
NS_RELEASE(db);
}
NS_RELEASE(rdfDoc);
}
NS_RELEASE(ds);
}
}
return rv;
}
nsresult
nsRDFDocumentContentSink::OpenObject(const nsIParserNode& aNode)
{
nsresult rv;
if (NS_FAILED(rv = nsRDFContentSink::OpenObject(aNode)))
return rv;
// Arbitrarily make the document root be the first container
// element in the RDF.
if (! mRootElement) {
nsAutoString uri;
if (NS_FAILED(rv = GetIdAboutAttribute(aNode, uri)))
return rv;
nsIRDFResource* resource;
if (NS_FAILED(rv = mRDFService->GetUnicodeResource(uri, &resource)))
return rv;
nsIRDFDocument* rdfDoc;
if (NS_SUCCEEDED(rv = mDocument->QueryInterface(kIRDFDocumentIID, (void**) &rdfDoc))) {
if (NS_SUCCEEDED(rv = rdfDoc->SetRootResource(resource))) {
mRootElement = mDocument->GetRootContent();
}
NS_RELEASE(rdfDoc);
}
NS_RELEASE(resource);
// Start layout. We need to wait until _now_ to ensure that we
// actually have a root document element.
StartLayout();
// don't release the rdfElement since we're keeping
// a reference to it in mRootElement
}
return rv;
}
////////////////////////////////////////////////////////////////////////
nsresult
NS_NewRDFDocumentContentSink(nsIRDFContentSink** aResult,
nsIDocument* aDoc,
nsIURL* aURL,
nsIWebShell* aWebShell)
{
NS_PRECONDITION(aResult, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
nsRDFDocumentContentSink* it;
NS_NEWXPCOM(it, nsRDFDocumentContentSink);
if (! it)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = it->Init(aDoc, aURL, aWebShell);
if (NS_FAILED(rv)) {
delete it;
return rv;
}
return it->QueryInterface(kIRDFContentSinkIID, (void **)aResult);
}

Просмотреть файл

@ -1,57 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
/*
A basic content sink implementation that builds an in-memory RDF
graph.
*/
#include "nsRDFContentSink.h"
static NS_DEFINE_IID(kIRDFContentSinkIID, NS_IRDFCONTENTSINK_IID);
////////////////////////////////////////////////////////////////////////
class nsRDFSimpleContentSink : public nsRDFContentSink {
public:
nsRDFSimpleContentSink(void) {};
virtual ~nsRDFSimpleContentSink(void) {};
};
////////////////////////////////////////////////////////////////////////
nsresult
NS_NewRDFSimpleContentSink(nsIRDFContentSink** aResult)
{
NS_PRECONDITION(aResult, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
nsRDFSimpleContentSink* sink = new nsRDFSimpleContentSink();
if (! sink)
return NS_ERROR_OUT_OF_MEMORY;
*aResult = sink;
NS_ADDREF(sink);
return NS_OK;
}

Просмотреть файл

@ -21,7 +21,7 @@ MODULE=rdf
DEPTH=..\..\.. DEPTH=..\..\..
EXPORTS = \ EXPORTS = \
nsIRDFMail.h \ nsIRDFMail.h \
$(NULL) $(NULL)
include <$(DEPTH)/config/rules.mak> include <$(DEPTH)/config/rules.mak>

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -515,6 +515,15 @@ BookmarkDataSourceImpl::BookmarkDataSourceImpl(void)
BookmarkDataSourceImpl::~BookmarkDataSourceImpl(void) BookmarkDataSourceImpl::~BookmarkDataSourceImpl(void)
{ {
// unregister this from the RDF service
nsresult rv;
nsIRDFService* rdfService;
if (NS_SUCCEEDED(rv = nsServiceManager::GetService(kRDFServiceCID,
kIRDFServiceIID,
(nsISupports**) &rdfService))) {
rdfService->UnregisterDataSource(this);
nsServiceManager::ReleaseService(kRDFServiceCID, rdfService);
}
Flush(); Flush();
NS_RELEASE(mInner); NS_RELEASE(mInner);
} }
@ -538,6 +547,15 @@ BookmarkDataSourceImpl::Init(const char* uri)
if (NS_FAILED(rv = ReadBookmarks())) if (NS_FAILED(rv = ReadBookmarks()))
return rv; return rv;
// register this as a named data source with the RDF service
nsIRDFService* rdfService;
if (NS_SUCCEEDED(rv = nsServiceManager::GetService(kRDFServiceCID,
kIRDFServiceIID,
(nsISupports**) &rdfService))) {
rdfService->RegisterDataSource(this);
nsServiceManager::ReleaseService(kRDFServiceCID, rdfService);
}
return NS_OK; return NS_OK;
} }

Просмотреть файл

@ -184,6 +184,8 @@ MailDataSource::MailDataSource(void)
MailDataSource::~MailDataSource (void) MailDataSource::~MailDataSource (void)
{ {
gRDFService->UnregisterDataSource(this);
PL_strfree(mURI); PL_strfree(mURI);
if (mObservers) { if (mObservers) {
for (PRInt32 i = mObservers->Count(); i >= 0; --i) { for (PRInt32 i = mObservers->Count(); i >= 0; --i) {
@ -263,6 +265,10 @@ MailDataSource::Init(const char* uri)
if (NS_FAILED(rv = InitAccountList())) if (NS_FAILED(rv = InitAccountList()))
return rv; return rv;
// register this as a named data source with the service manager
if (NS_FAILED(rv = gRDFService->RegisterDataSource(this)))
return rv;
return NS_OK; return NS_OK;
} }

Двоичные данные
rdf/macbuild/rdf.mcp

Двоичный файл не отображается.

Просмотреть файл

@ -3,18 +3,16 @@ mozilla/rdf/base/src/nsContainerCursor.cpp
mozilla/rdf/base/src/nsDataBase.cpp mozilla/rdf/base/src/nsDataBase.cpp
mozilla/rdf/base/src/nsEmptyCursor.cpp mozilla/rdf/base/src/nsEmptyCursor.cpp
mozilla/rdf/base/src/nsInMemoryDataSource.cpp mozilla/rdf/base/src/nsInMemoryDataSource.cpp
mozilla/rdf/base/src/nsRDFContentSink.cpp
mozilla/rdf/base/src/nsRDFService.cpp mozilla/rdf/base/src/nsRDFService.cpp
mozilla/rdf/base/src/nsStreamDataSource.cpp
mozilla/rdf/base/src/rdfutil.cpp mozilla/rdf/base/src/rdfutil.cpp
mozilla/rdf/build/nsRDFFactory.cpp mozilla/rdf/build/nsRDFFactory.cpp
mozilla/rdf/content/src/nsRDFContentSink.cpp
mozilla/rdf/content/src/nsRDFContentUtils.cpp mozilla/rdf/content/src/nsRDFContentUtils.cpp
mozilla/rdf/content/src/nsRDFDocument.cpp mozilla/rdf/content/src/nsRDFDocument.cpp
mozilla/rdf/content/src/nsRDFDocumentContentSink.cpp
mozilla/rdf/content/src/nsRDFGenericElement.cpp mozilla/rdf/content/src/nsRDFGenericElement.cpp
mozilla/rdf/content/src/nsRDFHTMLBuilder.cpp mozilla/rdf/content/src/nsRDFHTMLBuilder.cpp
mozilla/rdf/content/src/nsRDFResourceElement.cpp mozilla/rdf/content/src/nsRDFResourceElement.cpp
mozilla/rdf/content/src/nsRDFSimpleContentSink.cpp
mozilla/rdf/content/src/nsRDFTreeBuilder.cpp mozilla/rdf/content/src/nsRDFTreeBuilder.cpp
mozilla/rdf/datasource/src/nsBookmarkDataSource.cpp mozilla/rdf/datasource/src/nsBookmarkDataSource.cpp
mozilla/rdf/datasource/src/nsMailDataSource.cpp mozilla/rdf/datasource/src/nsMailDataSource.cpp
mozilla/rdf/datasource/src/nsStreamDataSource.cpp

Просмотреть файл

@ -866,11 +866,10 @@ static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
nsresult rv; nsresult rv;
nsIRDFDataSource* ds = nsnull;
nsIRDFDataBase* db = nsnull;
nsIRDFDocument* doc = nsnull; nsIRDFDocument* doc = nsnull;
nsIRDFContentModelBuilder* builder = nsnull; nsIRDFContentModelBuilder* builder = nsnull;
nsIRDFService* service = nsnull; nsIRDFService* service = nsnull;
nsIURL* uri = nsnull;
nsIRDFResource* root = nsnull; nsIRDFResource* root = nsnull;
result = nsnull; // reasonable default result = nsnull; // reasonable default
@ -895,55 +894,26 @@ static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
if (NS_FAILED(rv = doc->Init(builder))) if (NS_FAILED(rv = doc->Init(builder)))
goto done; goto done;
if (NS_FAILED(rv = doc->GetDataBase(db))) if (NS_FAILED(rv = NS_NewURL(&uri, "resource://res/rdf/LocalStore.rdf")))
goto done;
// XXX Allright, all this hand-coding of data sources is getting
// ridiculous and needs to be moved to the RDF back-end. I'll do
// that ASAP...
if (NS_FAILED(rv = service->GetNamedDataSource("rdf:mail", &ds)))
goto done;
if (NS_FAILED(rv = db->AddDataSource(ds)))
goto done;
NS_RELEASE(ds);
if (NS_FAILED(rv = service->GetNamedDataSource("rdf:bookmarks", &ds)))
goto done;
if (NS_FAILED(rv = db->AddDataSource(ds)))
goto done;
NS_RELEASE(ds);
if (NS_FAILED(rv = service->GetNamedDataSource("resource://res/rdf/LocalStore.rdf", &ds)))
goto done;
if (NS_FAILED(rv = db->AddDataSource(ds)))
goto done;
if (NS_FAILED(rv = service->GetResource("resource://res/rdf/LocalStore.rdf#root", &root)))
goto done;
if (NS_FAILED(rv = doc->SetRootResource(root)))
goto done; goto done;
if (NS_FAILED(rv = doc->QueryInterface(kIDocumentIID, (void**) &result))) if (NS_FAILED(rv = doc->QueryInterface(kIDocumentIID, (void**) &result)))
goto done; goto done;
if (NS_FAILED(rv = result->StartDocumentLoad(uri, nsnull, nsnull, nsnull)))
goto done;
// implicit addref on "result" from the QI // implicit addref on "result" from the QI
done: done:
NS_IF_RELEASE(root); NS_IF_RELEASE(root);
NS_IF_RELEASE(uri);
if (service) { if (service) {
nsServiceManager::ReleaseService(kRDFServiceCID, service); nsServiceManager::ReleaseService(kRDFServiceCID, service);
service = nsnull; service = nsnull;
} }
NS_IF_RELEASE(builder); NS_IF_RELEASE(builder);
NS_IF_RELEASE(doc); NS_IF_RELEASE(doc);
NS_IF_RELEASE(db);
NS_IF_RELEASE(ds);
return rv; return rv;
} }

Просмотреть файл

@ -148,7 +148,8 @@ static NS_DEFINE_CID(kRDFHTMLBuilderCID, NS_RDFHTMLBUILDER_CID);
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID); static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kRDFTreeBuilderCID, NS_RDFTREEBUILDER_CID); static NS_DEFINE_CID(kRDFTreeBuilderCID, NS_RDFTREEBUILDER_CID);
static NS_DEFINE_CID(kRDFSimpleContentSinkCID, NS_RDFSIMPLECONTENTSINK_CID); static NS_DEFINE_CID(kRDFContentSinkCID, NS_RDFCONTENTSINK_CID);
static NS_DEFINE_CID(kRDFStreamDataSourceCID, NS_RDFSTREAMDATASOURCE_CID);
static NS_DEFINE_CID(kCSSParserCID, NS_CSSPARSER_CID); static NS_DEFINE_CID(kCSSParserCID, NS_CSSPARSER_CID);
static NS_DEFINE_CID(kPresShellCID, NS_PRESSHELL_CID); static NS_DEFINE_CID(kPresShellCID, NS_PRESSHELL_CID);
@ -217,8 +218,8 @@ NS_SetupRegistry()
nsRepository::RegisterFactory(kRDFInMemoryDataSourceCID, RDF_DLL, PR_FALSE, PR_FALSE); nsRepository::RegisterFactory(kRDFInMemoryDataSourceCID, RDF_DLL, PR_FALSE, PR_FALSE);
nsRepository::RegisterFactory(kRDFServiceCID, RDF_DLL, PR_FALSE, PR_FALSE); nsRepository::RegisterFactory(kRDFServiceCID, RDF_DLL, PR_FALSE, PR_FALSE);
nsRepository::RegisterFactory(kRDFTreeBuilderCID, RDF_DLL, PR_FALSE, PR_FALSE); nsRepository::RegisterFactory(kRDFTreeBuilderCID, RDF_DLL, PR_FALSE, PR_FALSE);
nsRepository::RegisterFactory(kRDFSimpleContentSinkCID, RDF_DLL, PR_FALSE, PR_FALSE); nsRepository::RegisterFactory(kRDFContentSinkCID, RDF_DLL, PR_FALSE, PR_FALSE);
nsRepository::RegisterFactory(kRDFStreamDataSourceCID, RDF_DLL, PR_FALSE, PR_FALSE);
nsRepository::RegisterFactory(kCSSParserCID, LAYOUT_DLL, PR_FALSE, PR_FALSE); nsRepository::RegisterFactory(kCSSParserCID, LAYOUT_DLL, PR_FALSE, PR_FALSE);
nsRepository::RegisterFactory(kPresShellCID, LAYOUT_DLL, PR_FALSE, PR_FALSE); nsRepository::RegisterFactory(kPresShellCID, LAYOUT_DLL, PR_FALSE, PR_FALSE);