Compare commits

..

18 Commits

Author SHA1 Message Date
waterson%netscape.com
43f83c6887 Added JS and DOM libs to link.
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990215_BRANCH@20813 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-16 19:23:21 +00:00
waterson%netscape.com
8362cce878 Changed itoa() to PR_snprintf() because there is no itoa() on a Mac.
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990215_BRANCH@20812 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-16 19:17:12 +00:00
waterson%netscape.com
ec2d371258 Added precondition on GetParentNode().
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990215_BRANCH@20770 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-16 07:22:03 +00:00
waterson%netscape.com
feece20aab Exposed fns that convert indicies to ordinal resources and back.
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990215_BRANCH@20769 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-16 07:20:41 +00:00
waterson%netscape.com
262c8520bf Fixed buggy GetPredicate(), made some stuff into pseudo-constants to reduce overhead.
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990215_BRANCH@20768 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-16 07:20:12 +00:00
waterson%netscape.com
6c64aec9da Altered XUL representation to use RDF:Seq containers so that DOM node ordering is preserved.
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990215_BRANCH@20763 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-16 04:40:25 +00:00
waterson%netscape.com
bc0d43c97d Added more utility routines to manipulate RDF containers.
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990215_BRANCH@20762 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-16 04:39:06 +00:00
waterson%netscape.com
2866975b2e Moved check to ensure that resource is a container to the factory function (so we can return an intelligent error code instead of just asserting).
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990215_BRANCH@20753 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-16 01:25:11 +00:00
waterson%netscape.com
eba763e6b7 Made sure that dtor was virtual.
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990215_BRANCH@20742 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-15 21:20:59 +00:00
waterson%netscape.com
c29d2e26b5 Moved some of the utility routines into nsRDFParserUtils. Made this work more like the XML content sink; that is, got rid of the nsIRDFXMLDataSource interface, which really isn't appropriate for XUL.
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990215_BRANCH@20741 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-15 20:19:33 +00:00
waterson%netscape.com
c88ea6ae58 Added nsIXULContentSink interface.
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990215_BRANCH@20740 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-15 20:16:44 +00:00
waterson%netscape.com
2065767bc6 Started implementing DOM functionality in a big way.
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990215_BRANCH@20739 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-15 20:15:23 +00:00
waterson%netscape.com
8c4c803e8f Added nsIDOMNodeObserver interface.
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990215_BRANCH@20738 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-15 20:12:16 +00:00
waterson%netscape.com
2c4d514bc0 Added JS libs to link.
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990215_BRANCH@20737 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-15 20:10:54 +00:00
waterson%netscape.com
a1a2c4e5fe Renamed nsIRDFContentSink to nsIXULContentSink.
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990215_BRANCH@20736 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-15 20:10:47 +00:00
waterson%netscape.com
601c74c421 Added IsJavaScriptLanguage() routine.
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990215_BRANCH@20735 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-15 20:10:02 +00:00
waterson%netscape.com
755fd8300e Renamed RDF content sink to XUL content sink.
git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990215_BRANCH@20734 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-15 20:09:30 +00:00
(no author)
56495a3530 This commit was manufactured by cvs2svn to create branch
'RDFDOM_19990215_BRANCH'.

git-svn-id: svn://10.0.0.236/branches/RDFDOM_19990215_BRANCH@20684 18797224-902f-48f8-a5cc-f745e15eee43
1999-02-14 06:20:54 +00:00
441 changed files with 55339 additions and 106012 deletions

View File

@@ -0,0 +1,305 @@
/* -*- 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.
*/
/*
Helper class to implement the nsIDOMNodeList interface.
XXX It's probably wrong in some sense, as it uses the "naked"
content interface to look for kids. (I assume in general this is
bad because there may be pseudo-elements created for presentation
that aren't visible to the DOM.)
*/
#include "nsDOMCID.h"
#include "nsIDOMNode.h"
#include "nsIDOMHTMLCollection.h"
#include "nsIDOMScriptObjectFactory.h"
#include "nsIScriptGlobalObject.h"
#include "nsIServiceManager.h"
#include "nsISupportsArray.h"
#include "nsRDFDOMNodeList.h"
////////////////////////////////////////////////////////////////////////
// GUID definitions
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kIDOMNodeListIID, NS_IDOMNODELIST_IID);
static NS_DEFINE_IID(kIDOMScriptObjectFactoryIID, NS_IDOM_SCRIPT_OBJECT_FACTORY_IID);
static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
////////////////////////////////////////////////////////////////////////
//
class RDFHTMLCollectionImpl : public nsIDOMHTMLCollection
{
private:
nsRDFDOMNodeList* mOuter;
public:
RDFHTMLCollectionImpl(nsRDFDOMNodeList* aOuter);
virtual ~RDFHTMLCollectionImpl();
// nsISupports interface
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aResult);
// nsIDOMHTMLCollection interface
NS_DECL_IDOMHTMLCOLLECTION
};
RDFHTMLCollectionImpl::RDFHTMLCollectionImpl(nsRDFDOMNodeList* aOuter)
: mOuter(aOuter)
{
}
RDFHTMLCollectionImpl::~RDFHTMLCollectionImpl(void)
{
}
NS_IMETHODIMP_(nsrefcnt)
RDFHTMLCollectionImpl::AddRef(void)
{
return mOuter->AddRef();
}
NS_IMETHODIMP_(nsrefcnt)
RDFHTMLCollectionImpl::Release(void)
{
return mOuter->Release();
}
NS_IMETHODIMP
RDFHTMLCollectionImpl::QueryInterface(REFNSIID aIID, void** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
if (aIID.Equals(nsIDOMHTMLCollection::IID())) {
*aResult = NS_STATIC_CAST(nsIDOMHTMLCollection*, this);
NS_ADDREF(this);
return NS_OK;
}
else {
return mOuter->QueryInterface(aIID, aResult);
}
}
NS_IMETHODIMP
RDFHTMLCollectionImpl::GetLength(PRUint32* aLength)
{
return mOuter->GetLength(aLength);
}
NS_IMETHODIMP
RDFHTMLCollectionImpl::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
return mOuter->Item(aIndex, aReturn);
}
NS_IMETHODIMP
RDFHTMLCollectionImpl::NamedItem(const nsString& aName, nsIDOMNode** aReturn)
{
NS_NOTYETIMPLEMENTED("write me!");
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////
// ctors & dtors
nsRDFDOMNodeList::nsRDFDOMNodeList(void)
: mInner(nsnull),
mElements(nsnull),
mScriptObject(nsnull)
{
NS_INIT_REFCNT();
}
nsRDFDOMNodeList::~nsRDFDOMNodeList(void)
{
NS_IF_RELEASE(mElements);
delete mInner;
}
nsresult
nsRDFDOMNodeList::Create(nsRDFDOMNodeList** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
nsRDFDOMNodeList* list = new nsRDFDOMNodeList();
if (! list)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv;
if (NS_FAILED(rv = list->Init())) {
delete list;
return rv;
}
NS_ADDREF(list);
*aResult = list;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// nsISupports interface
NS_IMPL_ADDREF(nsRDFDOMNodeList);
NS_IMPL_RELEASE(nsRDFDOMNodeList);
nsresult
nsRDFDOMNodeList::QueryInterface(REFNSIID aIID, void** aResult)
{
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
if (aIID.Equals(nsIDOMNodeList::IID()) ||
aIID.Equals(kISupportsIID)) {
*aResult = NS_STATIC_CAST(nsIDOMNodeList*, this);
NS_ADDREF(this);
return NS_OK;
}
else if (aIID.Equals(kIScriptObjectOwnerIID)) {
*aResult = NS_STATIC_CAST(nsIScriptObjectOwner*, this);
NS_ADDREF(this);
return NS_OK;
}
else if (aIID.Equals(nsIDOMHTMLCollection::IID())) {
// Aggregate this interface
if (! mInner) {
if (! (mInner = new RDFHTMLCollectionImpl(this)))
return NS_ERROR_OUT_OF_MEMORY;
}
return mInner->QueryInterface(aIID, aResult);
}
return NS_NOINTERFACE;
}
////////////////////////////////////////////////////////////////////////
// nsIDOMNodeList interface
NS_IMETHODIMP
nsRDFDOMNodeList::GetLength(PRUint32* aLength)
{
NS_ASSERTION(aLength != nsnull, "null ptr");
if (! aLength)
return NS_ERROR_NULL_POINTER;
*aLength = mElements->Count();
return NS_OK;
}
NS_IMETHODIMP
nsRDFDOMNodeList::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
NS_PRECONDITION(aReturn != nsnull, "null ptr");
if (! aReturn)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(aIndex < (PRUint32) mElements->Count(), "invalid arg");
if (aIndex >= (PRUint32) mElements->Count())
return NS_ERROR_INVALID_ARG;
// Cast is okay because we're in a closed system.
*aReturn = (nsIDOMNode*) mElements->ElementAt(aIndex);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// nsIScriptObjectOwner interface
NS_IMETHODIMP
nsRDFDOMNodeList::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
{
nsresult rv = NS_OK;
nsIScriptGlobalObject* global = aContext->GetGlobalObject();
if (nsnull == mScriptObject) {
nsIDOMScriptObjectFactory *factory;
if (NS_SUCCEEDED(rv = nsServiceManager::GetService(kDOMScriptObjectFactoryCID,
kIDOMScriptObjectFactoryIID,
(nsISupports **)&factory))) {
rv = factory->NewScriptHTMLCollection(aContext,
(nsISupports*)(nsIDOMNodeList*)this,
global,
(void**)&mScriptObject);
nsServiceManager::ReleaseService(kDOMScriptObjectFactoryCID, factory);
}
}
*aScriptObject = mScriptObject;
NS_RELEASE(global);
return rv;
}
NS_IMETHODIMP
nsRDFDOMNodeList::SetScriptObject(void* aScriptObject)
{
mScriptObject = aScriptObject;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// Implementation methods
nsresult
nsRDFDOMNodeList::Init(void)
{
nsresult rv;
if (NS_FAILED(rv = NS_NewISupportsArray(&mElements))) {
NS_ERROR("unable to create elements array");
return rv;
}
return NS_OK;
}
nsresult
nsRDFDOMNodeList::AppendNode(nsIDOMNode* aNode)
{
NS_PRECONDITION(aNode != nsnull, "null ptr");
if (! aNode)
return NS_ERROR_NULL_POINTER;
return mElements->AppendElement(aNode);
}

View File

@@ -0,0 +1,58 @@
/* -*- 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.
*/
#ifndef nsRDFDOMNodeList_h__
#define nsRDFDOMNodeList_h__
#include "nsIDOMNodeList.h"
#include "nsIScriptObjectOwner.h"
class nsIDOMNode;
class nsISupportsArray;
class nsRDFDOMNodeList : public nsIDOMNodeList,
public nsIScriptObjectOwner
{
private:
nsISupports* mInner;
nsISupportsArray* mElements;
void* mScriptObject;
nsRDFDOMNodeList(void);
nsresult Init(void);
public:
static nsresult Create(nsRDFDOMNodeList** aResult);
virtual ~nsRDFDOMNodeList(void);
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIDOMNodeList interface
NS_DECL_IDOMNODELIST
// nsIScriptObjectOwner interface
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void* aScriptObject);
// Implementation methods
nsresult AppendNode(nsIDOMNode* aNode);
};
#endif // nsRDFDOMNodeList_h__

File diff suppressed because it is too large Load Diff

33
mozilla/rdf/Makefile.in Normal file
View File

@@ -0,0 +1,33 @@
#!gmake
#
# 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.
DEPTH = ..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = base content datasource build
ifdef ENABLE_TESTS
DIRS += tests
endif
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,29 @@
#!gmake
#
# 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.
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = public src
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,27 @@
#!gmake
#
# 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.
DEPTH=..\..
MODULE = rdf
DIRS=\
public \
src \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,11 @@
rdf.h
nsIRDFCompositeDataSource.h
nsIRDFContentSink.h
nsIRDFCursor.h
nsIRDFDataSource.h
nsIRDFNode.h
nsIRDFObserver.h
nsIRDFResourceFactory.h
nsIRDFService.h
nsIRDFXMLDataSource.h
nsIRDFXMLSource.h

View File

@@ -0,0 +1,46 @@
#!gmake
#
# 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.
DEPTH=../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = rdf
EXPORTS = \
rdf.h \
nsIRDFCompositeDataSource.h \
nsIRDFContentSink.h \
nsIRDFCursor.h \
nsIRDFDataSource.h \
nsIRDFNode.h \
nsIRDFObserver.h \
nsIRDFResourceFactory.h \
nsIRDFService.h \
nsIRDFXMLDataSource.h \
nsIRDFXMLSource.h \
nsRDFResource.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,40 @@
#!gmake
#
# 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.
MODULE=rdf
DEPTH=..\..\..
EXPORTS=\
rdf.h \
nsIRDFCompositeDataSource.h \
nsIRDFContentSink.h \
nsIRDFCursor.h \
nsIRDFDataSource.h \
nsIRDFNode.h \
nsIRDFObserver.h \
nsIRDFResourceFactory.h \
nsIRDFService.h \
nsIRDFXMLDataSource.h \
nsIRDFXMLSource.h \
nsRDFResource.h \
$(NULL)
include <$(DEPTH)/config/rules.mak>

View File

@@ -0,0 +1,60 @@
/* -*- 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.
*/
/*
RDF composite data source interface. A composite data source
aggregates individual RDF data sources.
*/
#ifndef nsIRDFCompositeDataSource_h__
#define nsIRDFCompositeDataSource_h__
#include "nsISupports.h"
#include "nsIRDFDataSource.h"
class nsIRDFDataSource;
// 96343820-307c-11d2-bc15-00805f912fe7
#define NS_IRDFCOMPOSITEDATASOURCE_IID \
{ 0x96343820, 0x307c, 0x11d2, { 0xb, 0x15, 0x00, 0x80, 0x5f, 0x91, 0x2f, 0xe7 } }
/**
* An <tt>nsIRDFCompositeDataSource</tt> composes individual data sources, providing
* the illusion of a single, coherent RDF graph.
*/
class nsIRDFCompositeDataSource : public nsIRDFDataSource {
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFCOMPOSITEDATASOURCE_IID; return iid; }
/**
* Add a datasource the the database.
*/
NS_IMETHOD AddDataSource(nsIRDFDataSource* source) = 0;
/**
* Remove a datasource from the database
*/
NS_IMETHOD RemoveDataSource(nsIRDFDataSource* source) = 0;
};
extern nsresult
NS_NewRDFCompositeDataSource(nsIRDFCompositeDataSource** result);
#endif /* nsIRDFCompositeDataSource_h__ */

View File

@@ -0,0 +1,72 @@
/* -*- 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.
*/
/*
An RDF-specific content sink. The content sink is targeted by the
parser for building the RDF content model.
*/
#ifndef nsIRDFContentSink_h___
#define nsIRDFContentSink_h___
#include "nsIXMLContentSink.h"
class nsIDocument;
class nsIRDFXMLDataSource;
class nsINameSpaceManager;
class nsIURL;
// {751843E2-8309-11d2-8EAC-00805F29F370}
#define NS_IRDFCONTENTSINK_IID \
{ 0x751843e2, 0x8309, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
/**
* This interface represents a content sink for RDF files.
*/
class nsIRDFContentSink : public nsIXMLContentSink {
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFCONTENTSINK_IID; return iid; }
/**
* Initialize the content sink.
*/
NS_IMETHOD Init(nsIURL* aURL, nsINameSpaceManager* aNameSpaceManager) = 0;
/**
* Set the content sink's RDF Data source
*/
NS_IMETHOD SetDataSource(nsIRDFXMLDataSource* aDataSource) = 0;
/**
* Retrieve the content sink's RDF data source.
*/
NS_IMETHOD GetDataSource(nsIRDFXMLDataSource*& rDataSource) = 0;
};
/**
* This constructs a content sink that can be used without a
* document, say, to create a stand-alone in-memory graph.
*/
nsresult
NS_NewRDFContentSink(nsIRDFContentSink** aResult);
#endif // nsIRDFContentSink_h___

View File

@@ -0,0 +1,174 @@
/* -*- 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.
*/
/*
Interfaces for RDF cursors, including nsIRDFCursor,
nsIRDFAssertionCursor, nsIRDFArcsInCursor, nsIRDFArcsOutCursor,
nad nsIRDFResourceCursor.
*/
#ifndef nsIRDFCursor_h__
#define nsIRDFCursor_h__
#include "nsISupports.h"
#include "prtypes.h"
#include "rdf.h" // for error codes
class nsIRDFDataSource;
class nsIRDFNode;
class nsIRDFResource;
// 1c2abdb0-4cef-11d2-bc16-00805f912fe7
#define NS_IRDFCURSOR_IID \
{ 0x1c2abdb0, 0x4cef, 0x11d2, { 0xbc, 0x16, 0x00, 0x80, 0x5f, 0x91, 0x2f, 0xe7 } }
/**
* An abstract base interface that is the basis for all RDF cursors.
*/
class nsIRDFCursor : public nsISupports {
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFCURSOR_IID; return iid; }
/**
* Advance the cursor to the next element.
* @return NS_ERROR_RDF_CURSOR_EMPTY if the cursor has reached the end
* and there are no more elements to enumerate; otherwise, NS_OK
* unless a catastrophic error occurs.
*/
NS_IMETHOD Advance(void) = 0;
/* Retrieve the data source from which the current item was obtained.
* @return NS_OK, unless a catastrophic error occurs.
*/
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource) = 0;
/**
* Irrespective of the query, a cursor is an interator over a set.
* This allows you to obtain the current value.
*/
NS_IMETHOD GetValue(nsIRDFNode** aValue) = 0;
};
// {1ED57100-9904-11d2-8EBA-00805F29F370}
#define NS_IRDFASSERTIONCURSOR_IID \
{ 0x1ed57100, 0x9904, 0x11d2, { 0x8e, 0xba, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
/**
* A cursor that enumerates assertions
* @seealso nsIRDFDataSource::GetTargetS(), nsIRDFDataSource::GetSources()
*/
class nsIRDFAssertionCursor : public nsIRDFCursor {
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFASSERTIONCURSOR_IID; return iid; }
/**
* Retrieve the assertion's subject resource.
* @return NS_OK, unless a catastrophic error occurs.
*/
NS_IMETHOD GetSubject(nsIRDFResource** aSubject) = 0;
/**
* Retrieve the assertion's predicate resource.
* @return NS_OK, unless a catastrophic error occurs.
*/
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate) = 0;
/**
* Retrieve the assertion's object node.
* @return NS_OK, unless a catastrophic error occurs.
*/
NS_IMETHOD GetObject(nsIRDFNode** aObject) = 0;
/**
* Retrieve the assertion's truth value.
* @return NS_OK, unless a catastrophic error occurs.
*/
NS_IMETHOD GetTruthValue(PRBool* aTruthValue) = 0;
};
// {1ED57101-9904-11d2-8EBA-00805F29F370}
#define NS_IRDFARCSOUTCURSOR_IID \
{ 0x1ed57101, 0x9904, 0x11d2, { 0x8e, 0xba, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
/**
* A cursor that enumerates the outbound arcs from a resource node.
* @seealso nsIRDFDataSource::ArcsOut()
*/
class nsIRDFArcsOutCursor : public nsIRDFCursor {
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFARCSOUTCURSOR_IID; return iid; }
/**
* Retrieve the "subject" node from which the arcs originate.
* @return NS_OK, unless a catastrophic error occurs.
*/
NS_IMETHOD GetSubject(nsIRDFResource** aSubject) = 0;
/**
* Retrieve the predicate label of the arc.
* @return NS_OK, unless a catastrophic error occurs.
*/
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate) = 0;
};
// {1ED57102-9904-11d2-8EBA-00805F29F370}
#define NS_IRDFARCSINCURSOR_IID \
{ 0x1ed57102, 0x9904, 0x11d2, { 0x8e, 0xba, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
/**
* A cursor that enumerates the inbound arcs to a node.
* @seealso nsIRDFDataSource::ArcsIn()
*/
class nsIRDFArcsInCursor : public nsIRDFCursor {
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFARCSINCURSOR_IID; return iid; }
/**
* Retrieve the "object" node in which the arc terminates.
* @return NS_OK, unless a catastrophic error occurs.
*/
NS_IMETHOD GetObject(nsIRDFNode** aObject) = 0;
/**
* Retrieve the predicate label of the arc
* @return NS_OK, unless a catastrophic error occurs.
*/
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate) = 0;
};
// {C2850C10-B0CF-11d2-A684-00104BDE6048}
#define NS_IRDFRESOURCECURSOR_IID \
{ 0xc2850c10, 0xb0cf, 0x11d2, { 0xa6, 0x84, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } }
/**
* A cursor that enumerates all of the resources in a data source.
*/
class nsIRDFResourceCursor : public nsIRDFCursor {
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFRESOURCECURSOR_IID; return iid; }
NS_IMETHOD GetResource(nsIRDFResource** aResource) = 0;
};
#endif /* nsIRDFCursor_h__ */

View File

@@ -0,0 +1,210 @@
/* -*- 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.
*/
/*
The RDF data source interface. An RDF data source presents a
graph-like interface to a back-end service.
*/
#ifndef nsIRDFDataSource_h__
#define nsIRDFDataSource_h__
#include "nsISupports.h"
// {0F78DA58-8321-11d2-8EAC-00805F29F370}
#define NS_IRDFDATASOURCE_IID \
{ 0xf78da58, 0x8321, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
class nsIRDFAssertionCursor;
class nsIRDFArcsInCursor;
class nsIRDFArcsOutCursor;
class nsIRDFDataBase;
class nsIRDFNode;
class nsIRDFObserver;
class nsIRDFResource;
class nsIRDFResourceCursor;
/**
* An RDF data source.
*/
class nsIRDFDataSource : public nsISupports {
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFDATASOURCE_IID; return iid; }
// XXX I didn't make some of these methods "const" because it's
// probably pretty likely that many data sources will just make
// stuff up at runtime to answer queries.
/**
* Specify the URI for the data source: this is the prefix
* that will be used to register the data source in the
* data source registry.
*/
NS_IMETHOD Init(const char* uri) = 0;
/**
* Retrieve the URI of the data source.
*/
NS_IMETHOD GetURI(const char* *uri) const = 0;
/**
* Find an RDF resource that points to a given node over the
* specified arc & truth value
*
* @return NS_ERROR_FAILURE if there is no source that leads
* to the target with the specified property.
*/
NS_IMETHOD GetSource(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFResource** source /* out */) = 0;
/**
* Find all RDF resources that point to a given node over the
* specified arc & truth value
*
* @return NS_OK unless a catastrophic error occurs. If the
* method returns NS_OK, you may assume that nsIRDFCursor points
* to a valid (but possibly empty) cursor.
*/
NS_IMETHOD GetSources(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFAssertionCursor** sources /* out */) = 0;
/**
* Find a child of that is related to the source by the given arc
* arc and truth value
*
* @return NS_ERROR_FAILURE if there is no target accessable from the
* source via the specified property.
*/
NS_IMETHOD GetTarget(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFNode** target /* out */) = 0;
/**
* Find all children of that are related to the source by the given arc
* arc and truth value.
*
* @return NS_OK unless a catastrophic error occurs. If the
* method returns NS_OK, you may assume that nsIRDFCursor points
* to a valid (but possibly empty) cursor.
*/
NS_IMETHOD GetTargets(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFAssertionCursor** targets /* out */) = 0;
/**
* Add an assertion to the graph.
*/
NS_IMETHOD Assert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv) = 0;
/**
* Remove an assertion from the graph.
*/
NS_IMETHOD Unassert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target) = 0;
/**
* Query whether an assertion exists in this graph.
*
* @return NS_OK unless a catastrophic error occurs.
*/
NS_IMETHOD HasAssertion(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
PRBool* hasAssertion /* out */) = 0;
/**
* Add an observer to this data source.
*/
NS_IMETHOD AddObserver(nsIRDFObserver* n) = 0;
/**
* Remove an observer from this data source
*/
NS_IMETHOD RemoveObserver(nsIRDFObserver* n) = 0;
// XXX individual resource observers?
/**
* Get a cursor to iterate over all the arcs that point into a node.
*
* @return NS_OK unless a catastrophic error occurs. If the method
* returns NS_OK, you may assume that labels points to a valid (but
* possible empty) nsIRDFCursor object.
*/
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
nsIRDFArcsInCursor** labels /* out */) = 0;
/**
* Get a cursor to iterate over all the arcs that originate in
* a resource.
*
* @return NS_OK unless a catastrophic error occurs. If the method
* returns NS_OK, you may assume that labels points to a valid (but
* possible empty) nsIRDFCursor object.
*/
NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
nsIRDFArcsOutCursor** labels /* out */) = 0;
/**
* Retrieve all of the resources that the data source currently
* refers to.
*/
NS_IMETHOD GetAllResources(nsIRDFResourceCursor** aCursor) = 0;
/**
* Request that a data source write it's contents out to
* permanent storage if applicable.
*/
NS_IMETHOD Flush(void) = 0;
/**
* Determine whether the specified command is enabled for the
* resource.
*
* XXX We will probably need to make this interface much more intricate
* to handle arbitrary arguments and selection sets.
*/
NS_IMETHOD IsCommandEnabled(const char* aCommand,
nsIRDFResource* aCommandTarget,
PRBool* aResult) = 0;
/**
* Perform the specified command on the resource.
*
* XXX We will probably need to make this interface much more intricate
* to handle arbitrary arguments and selection sets.
*/
NS_IMETHOD DoCommand(const char* aCommand,
nsIRDFResource* aCommandTarget) = 0;
};
#endif /* nsIRDFDataSource_h__ */

View File

@@ -0,0 +1,116 @@
/* -*- 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.
*/
/*
RDF node interfaces, including nsIRDFNode, nsIRDFResource, and
nsIRDFLiteral. Nodes are the elements that appear in RDF graphs.
*/
#ifndef nsIRDFNode_h__
#define nsIRDFNode_h__
#include "nscore.h"
#include "nsISupports.h"
// {0F78DA50-8321-11d2-8EAC-00805F29F370}
#define NS_IRDFNODE_IID \
{ 0xf78da50, 0x8321, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
/**
*
* Nodes are created using an instance of nsIRDFService, which
* should be obtained from the service manager:
*
* nsIRDFService* service;
* if (NS_SUCCEEDED(nsServiceManager::GetService(kCRDFServiceCID,
* kIRDFServiceIID,
* (nsISupports**) &service))) {
* nsIRDFNode* node;
* if (NS_SUCCEEDED(service->GetResource("http://foo.bar/", node))) {
* // do something useful here...
* NS_IF_RELEASE(node);
* }
* nsServiceManager::ReleaseService(kCRDFServiceCID, mgr);
* }
*
*/
class nsIRDFNode : public nsISupports {
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFNODE_IID; return iid; }
/**
* Determine if two nodes are identical
*/
NS_IMETHOD EqualsNode(nsIRDFNode* that, PRBool* result) const = 0;
};
/**
* A resource node, which has unique object identity.
*/
// {E0C493D1-9542-11d2-8EB8-00805F29F370}
#define NS_IRDFRESOURCE_IID \
{ 0xe0c493d1, 0x9542, 0x11d2, { 0x8e, 0xb8, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
class nsIRDFResource : public nsIRDFNode {
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFRESOURCE_IID; return iid; }
/**
* Get the 8-bit string value of the node.
*/
NS_IMETHOD GetValue(const char* *uri) const = 0;
/**
* Determine if two resources are identical.
*/
NS_IMETHOD EqualsResource(const nsIRDFResource* resource, PRBool* result) const = 0;
/**
* Determine if two resources are identical.
*/
NS_IMETHOD EqualsString(const char* uri, PRBool* result) const = 0;
};
// {E0C493D2-9542-11d2-8EB8-00805F29F370}
#define NS_IRDFLITERAL_IID \
{ 0xe0c493d2, 0x9542, 0x11d2, { 0x8e, 0xb8, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
class nsIRDFLiteral : public nsIRDFNode {
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFLITERAL_IID; return iid; }
/**
* Get the Unicode string value of the node.
*/
NS_IMETHOD GetValue(const PRUnichar* *value) const = 0;
/**
* Determine if two resources are identical.
*/
NS_IMETHOD EqualsLiteral(const nsIRDFLiteral* literal, PRBool* result) const = 0;
};
#endif // nsIRDFNode_h__

View File

@@ -0,0 +1,64 @@
/* -*- 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.
*/
/*
The RDF data source observer interface. Data source observers are
notified when the contents of the graph change.
*/
#ifndef nsIRDFObserver_h__
#define nsIRDFObserver_h__
#include "nsISupports.h"
class nsIRDFDataSource;
class nsIRDFResource;
class nsIRDFNode;
/**
* An observer on an nsIRDFDataSource.
*/
// 3cc75360-484a-11d2-bc16-00805f912fe7
#define NS_IRDFOBSERVER_IID \
{ 0x3cc75360, 0x484a, 0x11d2, { 0xbc, 0x16, 0x00, 0x80, 0x5f, 0x91, 0x2f, 0xe7 } }
class nsIRDFObserver : public nsISupports
{
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFOBSERVER_IID; return iid; }
/**
* Called whenever a new assertion is made in the data source.
*/
NS_IMETHOD OnAssert(nsIRDFResource* subject,
nsIRDFResource* predicate,
nsIRDFNode* object) = 0;
/**
* Called whenever an assertion is removed from the data source.
*/
NS_IMETHOD OnUnassert(nsIRDFResource* subject,
nsIRDFResource* predicate,
nsIRDFNode* object) = 0;
};
#endif /* nsIRDFObserver_h__ */

View File

@@ -0,0 +1,74 @@
/* -*- 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.
*/
/*
The RDF resource factory interface. A resource factory produces
nsIRDFResource objects for a specified URI prefix.
*/
#ifndef nsIRDFResourceFactory_h__
#define nsIRDFResourceFactory_h__
#include "nsISupports.h"
class nsIRDFResource;
// {8CE57A20-A02C-11d2-8EBF-00805F29F370}
#define NS_IRDFRESOURCEFACTORY_IID \
{ 0x8ce57a20, 0xa02c, 0x11d2, { 0x8e, 0xbf, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
/**
* A resource factory can be registered with <tt>nsIRDFService</tt> to produce
* resources with a certain <i>URI prefix</i>. The resource factory will be called
* upon to create a new resource, which the resource manager will cache.
*
* @see nsIRDFService::RegisterResourceFactory
* @see nsIRDFService::UnRegisterResourceFactory
*/
class nsIRDFResourceFactory : public nsISupports
{
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFRESOURCEFACTORY_IID; return iid; }
/**
* This method is called by the RDF service to create a new
* resource.
*
* NOTE. After constructing a new resource via a call to
* nsIRDFResourceFactory::CreateResource(), the implementation of
* the RDF service calls nsIRDFResource::GetValue() on the
* resulting resource. The resulting <tt>const char*</tt> is used
* as a key for the resource cache. (The assumption is that the
* custom resource implementation needs to store this information,
* anyway.)
*
* This has important implications for a custom resource's
* destructor; namely, that you must call
* nsIRDFService::UnCacheResource() <b>before</b> releasing the
* storage for the resource's URI. See
* nsIRDFService::UnCacheResource() for more information.
*/
NS_IMETHOD CreateResource(const char* aURI, nsIRDFResource** aResult) = 0;
};
#endif // nsIRDFResourceFactory_h__

View File

@@ -0,0 +1,176 @@
/* -*- 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.
*/
/*
The RDF service interface. This is a singleton object, and should be
obtained from the <tt>nsServiceManager</tt>.
XXX I'm not particularly happy with the current APIs for named data
sources. The idea is that you want "rdf:bookmarks" to always map to
the "bookmarks" data store. The thing that bothers me now is that
the implementation has to pre-load all of the data sources: that
means you need to parse the bookmarks file, read the history, etc.,
rather than doing this on-demand. With a little thought, it may be
able to enormously improve these APIs so that pre-loading data
sources is unnecessary.
*/
#ifndef nsIRDFService_h__
#define nsIRDFService_h__
#include "nscore.h"
#include "nsISupports.h"
class nsIRDFDataBase;
class nsIRDFDataSource;
class nsIRDFLiteral;
class nsIRDFResource;
class nsIRDFResourceFactory;
typedef nsresult (*NSDataSourceConstructorCallback)(nsIRDFDataSource** aResult);
// {BFD05261-834C-11d2-8EAC-00805F29F370}
#define NS_IRDFSERVICE_IID \
{ 0xbfd05261, 0x834c, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
class nsIRDFService : public nsISupports {
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFSERVICE_IID; return iid; }
// Resource management routines
/**
* Construct an RDF resource from a single-byte URI. <tt>nsIRDFSerivce</tt>
* caches resources that are in-use, so multiple calls to <tt>GetResource()</tt>
* for the same <tt>uri</tt> will return identical pointers.
*/
NS_IMETHOD GetResource(const char* uri, nsIRDFResource** resource) = 0;
/**
* Construct an RDF resource from a Unicode URI. This is provided
* as a convenience method, allowing automatic, in-line C++
* conversion from <tt>nsString</tt> objects. The <tt>uri</tt> will
* be converted to a single-byte representation internally.
*/
NS_IMETHOD GetUnicodeResource(const PRUnichar* uri, nsIRDFResource** resource) = 0;
/**
* Construct an RDF literal from a Unicode string.
*/
NS_IMETHOD GetLiteral(const PRUnichar* value, nsIRDFLiteral** literal) = 0;
/**
* Called to notify the resource manager that a resource is no
* longer in use. This method should only be called from the
* destructor of a "custom" resource implementation to notify the
* RDF service that the last reference to the resource has been
* released, so the resource is no longer valid.
*
* NOTE. As mentioned in nsIRDFResourceFactory::CreateResource(),
* the RDF service will use the result of
* nsIRDFResource::GetValue() as a key into its cache. For this
* reason, you must always un-cache the resource <b>before</b>
* releasing the storage for the <tt>const char*</tt> URI.
*/
NS_IMETHOD UnCacheResource(nsIRDFResource* resource) = 0;
/**
* Registers the specified resource factory as the producer for resources that
* have the specified <i>URI prefix</i>.
*/
NS_IMETHOD RegisterResourceFactory(const char* aURIPrefix, nsIRDFResourceFactory* aFactory) = 0;
/**
* Unregsters the specified resource factory from producing resources that have
* the specified <i>URI prefix</i>.
*/
NS_IMETHOD UnRegisterResourceFactory(const char* aURIPrefix) = 0;
// Data source management routines
/**
* 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 RegisterDataSource(nsIRDFDataSource* dataSource) = 0;
/**
* 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 UnregisterDataSource(nsIRDFDataSource* dataSource) = 0;
/**
* 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 GetDataSource(const char* uri, nsIRDFDataSource** dataSource) = 0;
/**
* Create a database that contains the specified named data
* sources. This is a convenience method whose functionality is
* equivalent to (1) constructing a new nsIRDFDataBase object from
* the repository, and (2) iteratively adding the named data sources
* to it, in order.
*/
NS_IMETHOD CreateDatabase(const char** uris, nsIRDFDataBase** dataBase) = 0;
/**
* Get the database aggregating all the stuff that Navigator sees as a default,
* including a "local" store.
*/
NS_IMETHOD CreateBrowserDatabase(nsIRDFDataBase** dataBase) = 0;
};
extern nsresult
NS_NewRDFService(nsIRDFService** result);
#endif // nsIRDFService_h__

View File

@@ -0,0 +1,60 @@
/* -*- 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.
*/
#ifndef nsIRDFTree_h__
#define nsIRDFTree_h__
#include "nscore.h"
#include "nsISupports.h"
#include "prtypes.h"
#include "rdf.h" // for error codes
/*
An interface for presenting a tree view of an rdf datasource (or
database).
Any datasource can also support nsIRDFTree. The interface is purely
syntactic sugar for traversing simple tree where the child relation
corresponds to the property type nc:child (nc = http://home.netscape.com/NC-rdf#).
Each leaf is assumed to have a certain predefined set of properties
such as creationDate, size, lastModificationDate, lastVisitDate, etc.
This interface is substantially less general than nsIRDFDataSource,
but is adequate for bookmarks, the file system, history and a few
other very commonly used data sources.
*/
// {7D7EEBD1-AA41-11d2-80B7-006097B76B8E}
#define NS_IRDFTREE_IID \
{ 0x7d7eebd1, 0xaa41, 0x11d2, { 0x80, 0xb7, 0x0, 0x60, 0x97, 0xb7, 0x6b, 0x8e } };
class nsIRDFTree : public nsISupports {
public:
NS_IMETHOD ListChildren (nsIRDFResource* folder, nsVoidArray** result);
// XXX should define something called nsResourceArray and use that
NS_IMETHOD IsFolder (nsIRDFResource* node, PRBool* result);
NS_IMETHOD GetProperty (nsIRDFResource* node, nsIRDFResource* property,
nsIRDFNode** result);
}
#endif

View File

@@ -0,0 +1,200 @@
/* -*- 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.
This file also includes an observer interface for nsIRDFXMLDataSource
objects.
*/
#ifndef nsIRDFXMLDataSource_h__
#define nsIRDFXMLDataSource_h__
#include "nsIRDFDataSource.h"
class nsIAtom;
class nsIOutputStream;
class nsIURL;
class nsString;
// {EB1A5D30-AB33-11d2-8EC6-00805F29F370}
#define NS_IRDFXMLDOCUMENTOBSERVER_IID \
{ 0xeb1a5d30, 0xab33, 0x11d2, { 0x8e, 0xc6, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
class nsIRDFXMLDataSource;
class nsIRDFXMLDataSourceObserver : public nsISupports
{
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFXMLDOCUMENTOBSERVER_IID; return iid; }
/**
* Called when the RDF/XML document begins to load.
*/
NS_IMETHOD OnBeginLoad(nsIRDFXMLDataSource* aStream) = 0;
/**
* Called when the RDF/XML document load is interrupted for some reason.
*/
NS_IMETHOD OnInterrupt(nsIRDFXMLDataSource* aStream) = 0;
/**
* Called when an interrupted RDF/XML document load is resumed.
*/
NS_IMETHOD OnResume(nsIRDFXMLDataSource* aStream) = 0;
/**
* Called whtn the RDF/XML document load is complete.
*/
NS_IMETHOD OnEndLoad(nsIRDFXMLDataSource* aStream) = 0;
/**
* Called when the root resource of the RDF/XML document is found
*/
NS_IMETHOD OnRootResourceFound(nsIRDFXMLDataSource* aStream, nsIRDFResource* aResource) = 0;
/**
* Called when a CSS style sheet is included (via XML processing
* instruction) to the document.
*/
NS_IMETHOD OnCSSStyleSheetAdded(nsIRDFXMLDataSource* aStream, nsIURL* aCSSStyleSheetURL) = 0;
/**
* Called when a named data source is included (via XML processing
* instruction) to the document.
*/
NS_IMETHOD OnNamedDataSourceAdded(nsIRDFXMLDataSource* aStream, const char* aNamedDataSourceURI) = 0;
};
// {EB1A5D31-AB33-11d2-8EC6-00805F29F370}
#define NS_IRDFXMLDATASOURCE_IID \
{ 0xeb1a5d31, 0xab33, 0x11d2, { 0x8e, 0xc6, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
class nsIRDFXMLDataSource : public nsIRDFDataSource
{
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFXMLDATASOURCE_IID; return iid; }
/**
* Sets the RDF/XML stream to load either synchronously or
* asynchronously when nsIRDFDataSource::Init() is called.
* By default, the stream will load <em>asynchronously</em>.
*/
NS_IMETHOD SetSynchronous(PRBool aIsSynchronous) = 0;
/**
* Sets the RDF/XML stream's read-only status. By default,
* the stream will be read/write if the URL on which
* nsIRDFDataSource::Init() is called is writable.
*/
NS_IMETHOD SetReadOnly(PRBool aIsReadOnly) = 0;
/**
* Notify the document that the load is beginning.
*/
NS_IMETHOD BeginLoad(void) = 0;
/**
* Notify the document that the load is being interrupted.
*/
NS_IMETHOD Interrupt(void) = 0;
/**
* Notify the document that an interrupted load is being resumed.
*/
NS_IMETHOD Resume(void) = 0;
/**
* Notify the document that the load is ending.
*/
NS_IMETHOD EndLoad(void) = 0;
/**
* Set the root resource for the document.
*/
NS_IMETHOD SetRootResource(nsIRDFResource* aResource) = 0;
/**
* Retrieve the root resource for the document.
*/
NS_IMETHOD GetRootResource(nsIRDFResource** aResource) = 0;
/**
* Add a CSS style sheet to the document.
* @param aStyleSheetURL An nsIURL object that is the URL of the style
* sheet to add to the document.
*/
NS_IMETHOD AddCSSStyleSheetURL(nsIURL* aStyleSheetURL) = 0;
/**
* Get the set of style sheets that have been included in the
* document.
* @param aStyleSheetURLs (out) A pointer to an array of pointers to nsIURL objects.
* @param aCount (out) The number of nsIURL objects returned.
*/
NS_IMETHOD GetCSSStyleSheetURLs(nsIURL*** aStyleSheetURLs, PRInt32* aCount) = 0;
/**
* Add a named data source to the document.
* @param aNamedDataSoruceURI A URI identifying the data source.
*/
NS_IMETHOD AddNamedDataSourceURI(const char* aNamedDataSourceURI) = 0;
/**
* Get the set of named data sources that have been included in
* the document
* @param aNamedDataSourceURIs (out) A pointer to an array of C-style character
* strings.
* @param aCount (out) The number of named data sources in the array.
*/
NS_IMETHOD GetNamedDataSourceURIs(const char* const** aNamedDataSourceURIs, PRInt32* aCount) = 0;
/**
* Add a new namespace declaration to the RDF/XML document.
*/
NS_IMETHOD AddNameSpace(nsIAtom* aPrefix, const nsString& aURI) = 0;
/**
* Add an observer to the document. The observer will be notified of
* RDF/XML events via the nsIRDFXMLDataSourceObserver interface. Note that
* the observer is <em>not</em> reference counted.
*/
NS_IMETHOD AddXMLStreamObserver(nsIRDFXMLDataSourceObserver* aObserver) = 0;
/**
* Remove an observer from the document.
*/
NS_IMETHOD RemoveXMLStreamObserver(nsIRDFXMLDataSourceObserver* aObserver) = 0;
};
// Two different kinds of XML data sources exist for RDF: serialized RDF and XUL.
// These are the methods that make these data sources.
extern nsresult
NS_NewRDFXMLDataSource(nsIRDFXMLDataSource** result);
extern nsresult
NS_NewXULDataSource(nsIRDFXMLDataSource** result);
#endif // nsIRDFXMLDataSource_h__

View File

@@ -0,0 +1,165 @@
/* -*- 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.
This file also includes an observer interface for nsIRDFXMLDocument
objects.
*/
#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:
/**
* Called when the RDF/XML document begins to load.
*/
NS_IMETHOD OnBeginLoad(void) = 0;
/**
* Called when the RDF/XML document load is interrupted for some reason.
*/
NS_IMETHOD OnInterrupt(void) = 0;
/**
* Called when an interrupted RDF/XML document load is resumed.
*/
NS_IMETHOD OnResume(void) = 0;
/**
* Called whtn the RDF/XML document load is complete.
*/
NS_IMETHOD OnEndLoad(void) = 0;
/**
* Called when the root resource of the RDF/XML document is found
*/
NS_IMETHOD OnRootResourceFound(nsIRDFResource* aResource) = 0;
/**
* Called when a CSS style sheet is included (via XML processing
* instruction) to the document.
*/
NS_IMETHOD OnCSSStyleSheetAdded(nsIURL* aCSSStyleSheetURL) = 0;
/**
* Called when a named data source is included (via XML processing
* instruction) to the document.
*/
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:
/**
* Notify the document that the load is beginning.
*/
NS_IMETHOD BeginLoad(void) = 0;
/**
* Notify the document that the load is being interrupted.
*/
NS_IMETHOD Interrupt(void) = 0;
/**
* Notify the document that an interrupted load is being resumed.
*/
NS_IMETHOD Resume(void) = 0;
/**
* Notify the document that the load is ending.
*/
NS_IMETHOD EndLoad(void) = 0;
/**
* Set the root resource for the document.
*/
NS_IMETHOD SetRootResource(nsIRDFResource* aResource) = 0;
/**
* Retrieve the root resource for the document.
*/
NS_IMETHOD GetRootResource(nsIRDFResource** aResource) = 0;
/**
* Add a CSS style sheet to the document.
* @param aStyleSheetURL An nsIURL object that is the URL of the style
* sheet to add to the document.
*/
NS_IMETHOD AddCSSStyleSheetURL(nsIURL* aStyleSheetURL) = 0;
/**
* Get the set of style sheets that have been included in the
* document.
* @param aStyleSheetURLs (out) A pointer to an array of pointers to nsIURL objects.
* @param aCount (out) The number of nsIURL objects returned.
*/
NS_IMETHOD GetCSSStyleSheetURLs(nsIURL*** aStyleSheetURLs, PRInt32* aCount) = 0;
/**
* Add a named data source to the document.
* @param aNamedDataSoruceURI A URI identifying the data source.
*/
NS_IMETHOD AddNamedDataSourceURI(const char* aNamedDataSourceURI) = 0;
/**
* Get the set of named data sources that have been included in
* the document
* @param aNamedDataSourceURIs (out) A pointer to an array of C-style character
* strings.
* @param aCount (out) The number of named data sources in the array.
*/
NS_IMETHOD GetNamedDataSourceURIs(const char* const** aNamedDataSourceURIs, PRInt32* aCount) = 0;
/**
* Add an observer to the document. The observer will be notified of
* RDF/XML events via the nsIRDFXMLDocumentObserver interface. Note that
* the observer is <em>not</em> reference counted.
*/
NS_IMETHOD AddDocumentObserver(nsIRDFXMLDocumentObserver* aObserver) = 0;
/**
* Remove an observer from the document.
*/
NS_IMETHOD RemoveDocumentObserver(nsIRDFXMLDocumentObserver* aObserver) = 0;
};
#endif // nsIRDFXMLDocument_h__

View File

@@ -0,0 +1,44 @@
/* -*- 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.
*/
/*
The RDF/XML source interface. An RDF/XML source is capable of
producing serialized RDF/XML to an output stream.
*/
#ifndef nsIRDFXMLSource_h__
#define nsIRDFXMLSource_h__
class nsIOutputStream;
// {4DA56F10-99FE-11d2-8EBB-00805F29F370}
#define NS_IRDFXMLSOURCE_IID \
{ 0x4da56f10, 0x99fe, 0x11d2, { 0x8e, 0xbb, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
class nsIRDFXMLSource : public nsISupports
{
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFXMLSOURCE_IID; return iid; }
NS_IMETHOD Serialize(nsIOutputStream* aStream) = 0;
};
#endif // nsIRDFXMLSource_h__

View File

@@ -0,0 +1,50 @@
/* -*- Mode: C++; tab-width: 2; 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.
*/
#ifndef nsRDFResource_h__
#define nsRDFResource_h__
#include "nsIRDFNode.h"
/**
* This simple base class implements nsIRDFResource, and can be used as a
* superclass for more sophisticated resource implementations.
*/
class nsRDFResource : public nsIRDFResource {
public:
NS_DECL_ISUPPORTS
// nsIRDFNode methods:
NS_IMETHOD EqualsNode(nsIRDFNode* node, PRBool* result) const;
// nsIRDFResource methods:
NS_IMETHOD GetValue(const char* *uri) const;
NS_IMETHOD EqualsResource(const nsIRDFResource* resource, PRBool* result) const;
NS_IMETHOD EqualsString(const char* uri, PRBool* result) const;
// nsRDFResource methods:
nsRDFResource(const char* uri);
virtual ~nsRDFResource(void);
protected:
const char* mURI;
};
#endif // nsRDFResource_h__

View File

@@ -0,0 +1,71 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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.
*/
/*
A catch-all header file for miscellaneous RDF stuff. Currently
contains error codes and vocabulary macros.
*/
#ifndef rdf_h___
#define rdf_h___
#include "nsError.h"
/*
* The following macros are to aid in vocabulary definition.
* They creates const char*'s for "kURI[prefix]_[name]" and
* "kTag[prefix]_[name]", with appropriate complete namespace
* qualification on the URI, e.g.,
*
* #define RDF_NAMESPACE_URI "http://www.w3.org/TR/WD-rdf-syntax#"
* DEFINE_RDF_ELEMENT(RDF_NAMESPACE_URI, RDF, ID);
*
* will define:
*
* kURIRDF_ID to be "http://www.w3.org/TR/WD-rdf-syntax#ID", and
* kTagRDF_ID to be "ID"
*/
#define DEFINE_RDF_VOCAB(namespace, prefix, name) \
static const char* kURI##prefix##_##name = ##namespace #name ;\
static const char* kTag##prefix##_##name = kURI##prefix##_##name## + sizeof(##namespace) - 1
/**
* Core RDF vocabularies that we use to infer semantic actions
*/
#define RDF_NAMESPACE_URI "http://www.w3.org/TR/WD-rdf-syntax#"
#define WEB_NAMESPACE_URI "http://home.netscape.com/WEB-rdf#"
#define NC_NAMESPACE_URI "http://home.netscape.com/NC-rdf#"
/**
* @name Standard RDF error codes
*/
/*@{*/
/* Returned from nsIRDFCursor::Advance() if the cursor has no more
elements to enuemrate */
#define NS_ERROR_RDF_CURSOR_EMPTY NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_RDF, 1)
#define NS_ERROR_RDF_NO_VALUE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_RDF, 2)
/*@}*/
#endif /* rdf_h___ */

View File

@@ -0,0 +1,57 @@
#!gmake
#
# 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.
DEPTH=../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
LIBRARY_NAME = rdfbase_s
CPPSRCS = \
nsCompositeDataSource.cpp \
nsContainerCursor.cpp \
nsDefaultResourceFactory.cpp \
nsEmptyCursor.cpp \
nsInMemoryDataSource.cpp \
nsRDFContentSink.cpp \
nsRDFParserUtils.cpp \
nsRDFService.cpp \
nsRDFXMLDataSource.cpp \
rdfutil.cpp \
nsRDFResource.cpp \
$(NULL)
EXPORTS = \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
MODULE = rdfbase
REQUIRES = netlib rdf raptor xpcom
MKSHLIB :=
# we don't want the shared lib
NO_SHARED_LIB=1
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,48 @@
#!gmake
#
# 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.
DEPTH=..\..\..
MODULE=rdf
LIBRARY_NAME=rdfbase_s
CPP_OBJS=\
.\$(OBJDIR)\nsCompositeDataSource.obj \
.\$(OBJDIR)\nsContainerCursor.obj \
.\$(OBJDIR)\nsDefaultResourceFactory.obj \
.\$(OBJDIR)\nsEmptyCursor.obj \
.\$(OBJDIR)\nsInMemoryDataSource.obj \
.\$(OBJDIR)\nsRDFContentSink.obj \
.\$(OBJDIR)\nsRDFParserUtils.obj \
.\$(OBJDIR)\nsRDFService.obj \
.\$(OBJDIR)\nsRDFXMLDataSource.obj \
.\$(OBJDIR)\rdfutil.obj \
.\$(OBJDIR)\nsRDFResource.obj \
$(NULL)
LINCS= -I$(PUBLIC)\rdf \
-I$(PUBLIC)\xpcom \
-I$(PUBLIC)\raptor \
-I$(PUBLIC)\netlib \
$(NULL)
include <$(DEPTH)\config\rules.mak>
libs:: $(LIBRARY)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
clobber::
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib

View File

@@ -0,0 +1,887 @@
/* -*- 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.
*/
/*
A simple composite data source implementation. A composit data
source is just a strategy for combining individual data sources into
a collective graph.
1) A composite data source holds a sequence of data sources. The set
of data sources can be specified during creation of the
database. Data sources can also be added/deleted from a database
later.
2) The aggregation mechanism is based on simple super-positioning of
the graphs from the datasources. If there is a conflict (i.e.,
data source A has a true arc from foo to bar while data source B
has a false arc from foo to bar), the data source that it earlier
in the sequence wins.
The implementation below doesn't really do this and needs to be
fixed.
*/
#include "nsIRDFCursor.h"
#include "nsIRDFNode.h"
#include "nsIRDFCompositeDataSource.h"
#include "nsIRDFObserver.h"
#include "nsRepository.h"
#include "nsVoidArray.h"
#include "prlog.h"
static NS_DEFINE_IID(kIRDFArcsInCursorIID, NS_IRDFARCSINCURSOR_IID);
static NS_DEFINE_IID(kIRDFArcsOutCursorIID, NS_IRDFARCSOUTCURSOR_IID);
static NS_DEFINE_IID(kIRDFAssertionCursorIID, NS_IRDFASSERTIONCURSOR_IID);
static NS_DEFINE_IID(kIRDFCursorIID, NS_IRDFCURSOR_IID);
static NS_DEFINE_IID(kIRDFCompositeDataSourceIID, NS_IRDFCOMPOSITEDATASOURCE_IID);
static NS_DEFINE_IID(kIRDFDataSourceIID, NS_IRDFDATASOURCE_IID);
static NS_DEFINE_IID(kIRDFObserverIID, NS_IRDFOBSERVER_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
////////////////////////////////////////////////////////////////////////
// CompositeDataSourceImpl
class CompositeDataSourceImpl : public nsIRDFCompositeDataSource,
public nsIRDFObserver
{
protected:
nsVoidArray* mObservers;
virtual ~CompositeDataSourceImpl(void);
public:
CompositeDataSourceImpl(void);
CompositeDataSourceImpl(char** dataSources);
nsVoidArray mDataSources;
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIRDFDataSource interface
NS_IMETHOD Init(const char* uri);
NS_IMETHOD GetURI(const char* *uri) const;
NS_IMETHOD GetSource(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFResource** source);
NS_IMETHOD GetSources(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFAssertionCursor** sources);
NS_IMETHOD GetTarget(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFNode** target);
NS_IMETHOD GetTargets(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFAssertionCursor** targets);
NS_IMETHOD Assert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv);
NS_IMETHOD Unassert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target);
NS_IMETHOD HasAssertion(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
PRBool* hasAssertion);
NS_IMETHOD AddObserver(nsIRDFObserver* n);
NS_IMETHOD RemoveObserver(nsIRDFObserver* n);
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
nsIRDFArcsInCursor** labels);
NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
nsIRDFArcsOutCursor** labels);
NS_IMETHOD GetAllResources(nsIRDFResourceCursor** aCursor);
NS_IMETHOD Flush();
NS_IMETHOD IsCommandEnabled(const char* aCommand,
nsIRDFResource* aCommandTarget,
PRBool* aResult);
NS_IMETHOD DoCommand(const char* aCommand,
nsIRDFResource* aCommandTarget);
// nsIRDFCompositeDataSource interface
NS_IMETHOD AddDataSource(nsIRDFDataSource* source);
NS_IMETHOD RemoveDataSource(nsIRDFDataSource* source);
// nsIRDFObserver interface
NS_IMETHOD OnAssert(nsIRDFResource* subject,
nsIRDFResource* predicate,
nsIRDFNode* object);
NS_IMETHOD OnUnassert(nsIRDFResource* subject,
nsIRDFResource* predicate,
nsIRDFNode* object);
// Implementation methods
PRBool HasAssertionN(int n, nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv);
};
class DBArcsInOutCursor : public nsIRDFArcsOutCursor,
public nsIRDFArcsInCursor
{
CompositeDataSourceImpl* mCompositeDataSourceImpl;
nsIRDFResource* mSource;
nsIRDFNode* mTarget;
PRInt32 mCount;
nsIRDFArcsOutCursor* mOutCursor;
nsIRDFArcsInCursor* mInCursor;
nsVoidArray mResults;
public:
DBArcsInOutCursor(CompositeDataSourceImpl* db, nsIRDFNode* node, PRBool arcsOutp);
virtual ~DBArcsInOutCursor();
NS_DECL_ISUPPORTS
NS_IMETHOD Advance();
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource) {
return (mInCursor ? mInCursor->GetDataSource(aDataSource) :
mOutCursor->GetDataSource(aDataSource));
}
NS_IMETHOD GetSubject(nsIRDFResource** aResource) {
return mOutCursor->GetSubject(aResource);
}
NS_IMETHOD GetObject(nsIRDFNode** aNode) {
return mInCursor->GetObject(aNode);
}
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate) {
return (mInCursor ? mInCursor->GetPredicate(aPredicate) :
mOutCursor->GetPredicate(aPredicate));
}
NS_IMETHOD GetValue(nsIRDFNode** aValue) {
return (mInCursor ? mInCursor->GetValue(aValue) :
mOutCursor->GetValue(aValue));
}
};
DBArcsInOutCursor::DBArcsInOutCursor(CompositeDataSourceImpl* db,
nsIRDFNode* node,
PRBool arcsOutp)
: mCompositeDataSourceImpl(db),
mTarget(0),
mSource(0),
mCount(0),
mInCursor(0),
mOutCursor(0)
{
NS_INIT_REFCNT();
NS_ADDREF(mCompositeDataSourceImpl);
if (arcsOutp) {
mSource = (nsIRDFResource*) node;
} else {
mTarget = node;
}
NS_IF_ADDREF(node);
// XXX there better be at least _one_ datasource in this here
// CompositeDataSourceImpl, else this'll be a real short ride...
PR_ASSERT(db->mDataSources.Count() > 0);
nsIRDFDataSource* ds = (nsIRDFDataSource*) db->mDataSources[mCount++];
if (mTarget) {
ds->ArcLabelsIn(mTarget, &mInCursor);
} else {
ds->ArcLabelsOut(mSource, &mOutCursor);
}
}
DBArcsInOutCursor::~DBArcsInOutCursor(void)
{
for (PRInt32 i = mResults.Count() - 1; i >= 0; --i) {
nsIRDFNode* node = (nsIRDFNode*) mResults[i];
NS_RELEASE(node);
}
NS_IF_RELEASE(mSource);
NS_IF_RELEASE(mTarget);
NS_IF_RELEASE(mInCursor);
NS_IF_RELEASE(mOutCursor);
NS_RELEASE(mCompositeDataSourceImpl);
}
NS_IMPL_ADDREF(DBArcsInOutCursor);
NS_IMPL_RELEASE(DBArcsInOutCursor);
NS_IMETHODIMP_(nsresult)
DBArcsInOutCursor::QueryInterface(REFNSIID iid, void** result) {
if (! result)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(kIRDFArcsOutCursorIID) ||
iid.Equals(kIRDFCursorIID) ||
iid.Equals(kISupportsIID)) {
*result = NS_STATIC_CAST(nsIRDFArcsOutCursor*, this);
NS_ADDREF(this);
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP
DBArcsInOutCursor::Advance(void)
{
nsIRDFDataSource* ds;
while (mInCursor || mOutCursor) {
nsresult result = (mInCursor ? mInCursor->Advance() : mOutCursor->Advance());
while (NS_SUCCEEDED(result)) {
nsIRDFNode* obj ;
GetValue(&obj);
if (mResults.IndexOf(obj) < 0) {
mResults.AppendElement(obj);
return NS_OK;
}
result = (mInCursor ? mInCursor->Advance() : mOutCursor->Advance());
}
if (result != NS_ERROR_RDF_CURSOR_EMPTY)
return result;
NS_IF_RELEASE(mInCursor);
NS_IF_RELEASE(mOutCursor);
if (mCount >= mCompositeDataSourceImpl->mDataSources.Count())
break;
ds = (nsIRDFDataSource*) mCompositeDataSourceImpl->mDataSources[mCount];
++mCount;
if (mTarget) {
ds->ArcLabelsIn(mTarget, &mInCursor);
} else {
ds->ArcLabelsOut(mSource, &mOutCursor);
}
}
return NS_ERROR_RDF_CURSOR_EMPTY;
}
////////////////////////////////////////////////////////////////////////
// DBAssertionCursor
//
// An assertion cursor implementation for the db.
//
class DBGetSTCursor : public nsIRDFAssertionCursor
{
private:
CompositeDataSourceImpl* mCompositeDataSourceImpl;
nsIRDFResource* mSource;
nsIRDFResource* mLabel;
nsIRDFNode* mTarget;
PRInt32 mCount;
PRBool mTruthValue;
nsIRDFAssertionCursor* mCurrentCursor;
public:
DBGetSTCursor(CompositeDataSourceImpl* db, nsIRDFNode* u,
nsIRDFResource* property, PRBool inversep, PRBool tv);
virtual ~DBGetSTCursor();
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIRDFAssertionCursor interface
NS_IMETHOD Advance();
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource) {
return mCurrentCursor->GetDataSource(aDataSource);
}
NS_IMETHOD GetSubject(nsIRDFResource** aResource) {
return mCurrentCursor->GetSubject(aResource);
}
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate) {
return mCurrentCursor->GetPredicate(aPredicate);
}
NS_IMETHOD GetObject(nsIRDFNode** aObject) {
return mCurrentCursor->GetObject(aObject);
}
NS_IMETHOD GetTruthValue(PRBool* aTruthValue) {
return mCurrentCursor->GetTruthValue(aTruthValue);
}
NS_IMETHOD GetValue(nsIRDFNode** aValue) {
return mCurrentCursor->GetValue(aValue);
}
};
//NS_IMPL_ISUPPORTS(DBGetSTCursor, kIRDFAssertionCursorIID);
DBGetSTCursor::DBGetSTCursor(CompositeDataSourceImpl* db,
nsIRDFNode* u,
nsIRDFResource* property,
PRBool inversep,
PRBool tv)
: mCompositeDataSourceImpl(db),
mSource(nsnull),
mLabel(property),
mTarget(nsnull),
mCount(0),
mTruthValue(tv),
mCurrentCursor(nsnull)
{
NS_INIT_REFCNT();
NS_ADDREF(mCompositeDataSourceImpl);
if (!inversep) {
mSource = (nsIRDFResource*) u;
} else {
mTarget = u;
}
NS_IF_ADDREF(mSource);
NS_IF_ADDREF(mTarget);
NS_IF_ADDREF(mLabel);
// XXX assume that at least one data source exists in the CompositeDataSourceImpl.
nsIRDFDataSource* ds = (nsIRDFDataSource*) db->mDataSources[mCount++];
if (mSource)
ds->GetTargets(mSource, mLabel, mTruthValue, &mCurrentCursor);
else
ds->GetSources(mLabel, mTarget, mTruthValue, &mCurrentCursor);
}
DBGetSTCursor::~DBGetSTCursor(void)
{
NS_IF_RELEASE(mCurrentCursor);
NS_IF_RELEASE(mLabel);
NS_IF_RELEASE(mSource);
NS_IF_RELEASE(mTarget);
NS_RELEASE(mCompositeDataSourceImpl);
}
NS_IMPL_ADDREF(DBGetSTCursor);
NS_IMPL_RELEASE(DBGetSTCursor);
NS_IMETHODIMP_(nsresult)
DBGetSTCursor::QueryInterface(REFNSIID iid, void** result)
{
if (! result)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(kIRDFAssertionCursorIID) ||
iid.Equals(kIRDFCursorIID) ||
iid.Equals(kISupportsIID)) {
*result = NS_STATIC_CAST(nsIRDFAssertionCursor*, this);
NS_ADDREF(this);
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP
DBGetSTCursor::Advance(void)
{
nsIRDFDataSource* ds;
while (mCurrentCursor) {
nsresult result = mCurrentCursor->Advance();
while (NS_ERROR_RDF_CURSOR_EMPTY != result) {
nsIRDFResource* src;
nsIRDFNode* trg;
mCurrentCursor->GetSubject(&src);
mCurrentCursor->GetObject(&trg);
if (!mCompositeDataSourceImpl->HasAssertionN(mCount-1, src, mLabel, trg, !mTruthValue)) {
return NS_OK;
} else {
result = mCurrentCursor->Advance();
}
}
if (mCount >= mCompositeDataSourceImpl->mDataSources.Count())
break;
ds = (nsIRDFDataSource*) mCompositeDataSourceImpl->mDataSources[mCount];
++mCount;
NS_RELEASE(mCurrentCursor);
if (mSource)
ds->GetTargets(mSource, mLabel, mTruthValue, &mCurrentCursor);
else
ds->GetSources(mLabel, mTarget, mTruthValue, &mCurrentCursor);
}
return NS_ERROR_RDF_CURSOR_EMPTY;
}
////////////////////////////////////////////////////////////////////////
nsresult
NS_NewRDFCompositeDataSource(nsIRDFCompositeDataSource** result)
{
CompositeDataSourceImpl* db = new CompositeDataSourceImpl();
if (! db)
return NS_ERROR_OUT_OF_MEMORY;
*result = db;
NS_ADDREF(*result);
return NS_OK;
}
CompositeDataSourceImpl::CompositeDataSourceImpl(void)
: mObservers(nsnull)
{
NS_INIT_REFCNT();
}
CompositeDataSourceImpl::~CompositeDataSourceImpl(void)
{
for (PRInt32 i = mDataSources.Count() - 1; i >= 0; --i) {
nsIRDFDataSource* ds = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[i]);
ds->RemoveObserver(this);
NS_IF_RELEASE(ds);
}
delete mObservers;
}
////////////////////////////////////////////////////////////////////////
// nsISupports interface
NS_IMPL_ADDREF(CompositeDataSourceImpl);
NS_IMPL_RELEASE(CompositeDataSourceImpl);
NS_IMETHODIMP
CompositeDataSourceImpl::QueryInterface(REFNSIID iid, void** result)
{
if (! result)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(kIRDFCompositeDataSourceIID) ||
iid.Equals(kIRDFDataSourceIID) ||
iid.Equals(kISupportsIID)) {
*result = NS_STATIC_CAST(nsIRDFCompositeDataSource*, this);
NS_ADDREF(this);
return NS_OK;
}
else if (iid.Equals(kIRDFObserverIID)) {
*result = NS_STATIC_CAST(nsIRDFObserver*, this);
NS_ADDREF(this);
return NS_OK;
}
else {
*result = nsnull;
return NS_NOINTERFACE;
}
}
////////////////////////////////////////////////////////////////////////
// nsIRDFDataSource interface
NS_IMETHODIMP
CompositeDataSourceImpl::Init(const char* uri)
{
PR_ASSERT(0);
return NS_ERROR_UNEXPECTED; // XXX CompositeDataSourceImpl doesn't have a URI?
}
NS_IMETHODIMP
CompositeDataSourceImpl::GetURI(const char* *uri) const
{
PR_ASSERT(0);
return NS_ERROR_UNEXPECTED; // XXX CompositeDataSourceImpl doesn't have a URI?
}
NS_IMETHODIMP
CompositeDataSourceImpl::GetSource(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFResource** source)
{
PRInt32 count = mDataSources.Count();
for (PRInt32 i = 0; i < count; ++i) {
nsIRDFDataSource* ds = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[i]);
if (NS_FAILED(ds->GetSource(property, target, tv, source)))
continue;
// okay, found it. make sure we don't have the opposite
// asserted in a more local data source
if (!HasAssertionN(count-1, *source, property, target, !tv))
return NS_OK;
NS_RELEASE(*source);
return NS_ERROR_RDF_NO_VALUE;
}
return NS_ERROR_RDF_NO_VALUE;
}
NS_IMETHODIMP
CompositeDataSourceImpl::GetSources(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFAssertionCursor** result)
{
if (! result)
return NS_ERROR_NULL_POINTER;
*result = new DBGetSTCursor(this, target, property, 1, tv);
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*result);
return NS_OK;
}
NS_IMETHODIMP
CompositeDataSourceImpl::GetTarget(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFNode** target)
{
PRInt32 count = mDataSources.Count();
for (PRInt32 i = 0; i < count; ++i) {
nsIRDFDataSource* ds = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[i]);
if (NS_FAILED(ds->GetTarget(source, property, tv, target)))
continue;
// okay, found it. make sure we don't have the opposite
// asserted in the "local" data source
if (!HasAssertionN(count-1, source, property, *target, !tv))
return NS_OK;
NS_RELEASE(*target);
return NS_ERROR_RDF_NO_VALUE;
}
return NS_ERROR_RDF_NO_VALUE;
}
PRBool
CompositeDataSourceImpl::HasAssertionN(int n,
nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv)
{
int m = 0;
PRBool result = 0;
while (m < n) {
nsIRDFDataSource* ds = (nsIRDFDataSource*) mDataSources[m];
ds->HasAssertion(source, property, target, tv, &result);
if (result) return 1;
m++;
}
return 0;
}
NS_IMETHODIMP
CompositeDataSourceImpl::GetTargets(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFAssertionCursor** targets)
{
if (! targets)
return NS_ERROR_NULL_POINTER;
nsIRDFAssertionCursor* result;
result = new DBGetSTCursor(this, source, property, 0, tv);
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(result);
*targets = result;
return NS_OK;
}
NS_IMETHODIMP
CompositeDataSourceImpl::Assert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv)
{
// Need to add back the stuff for unblocking ...
for (PRInt32 i = mDataSources.Count() - 1; i >= 0; --i) {
nsIRDFDataSource* ds = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[i]);
if (NS_SUCCEEDED(ds->Assert(source, property, target, tv)))
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
CompositeDataSourceImpl::Unassert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target)
{
nsresult rv;
PRInt32 count = mDataSources.Count();
for (PRInt32 i = 0; i < count; ++i) {
nsIRDFDataSource* ds = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[i]);
if (NS_FAILED(rv = ds->Unassert(source, property, target)))
break;
}
if (NS_FAILED(rv)) {
nsIRDFDataSource* ds0 = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[0]);
rv = ds0->Assert(source, property, target, PR_FALSE);
}
return rv;
}
NS_IMETHODIMP
CompositeDataSourceImpl::HasAssertion(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
PRBool* hasAssertion)
{
nsresult rv;
// Otherwise, look through all the data sources to see if anyone
// has the positive...
PRInt32 count = mDataSources.Count();
PRBool hasNegation = 0;
for (PRInt32 i = 0; i < count; ++i) {
nsIRDFDataSource* ds = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[i]);
if (NS_FAILED(rv = ds->HasAssertion(source, property, target, tv, hasAssertion)))
return rv;
if (*hasAssertion)
return NS_OK;
if (NS_FAILED(rv = ds->HasAssertion(source, property, target, !tv, &hasNegation)))
return rv;
if (hasNegation) {
*hasAssertion = 0;
return NS_OK;
}
}
// If we get here, nobody had the assertion at all
*hasAssertion = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
CompositeDataSourceImpl::AddObserver(nsIRDFObserver* obs)
{
if (!mObservers) {
if ((mObservers = new nsVoidArray()) == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
}
// XXX ensure uniqueness?
mObservers->AppendElement(obs);
return NS_OK;
}
NS_IMETHODIMP
CompositeDataSourceImpl::RemoveObserver(nsIRDFObserver* obs)
{
if (!mObservers)
return NS_OK;
mObservers->RemoveElement(obs);
return NS_OK;
}
NS_IMETHODIMP
CompositeDataSourceImpl::ArcLabelsIn(nsIRDFNode* node,
nsIRDFArcsInCursor** labels)
{
if (! labels)
return NS_ERROR_NULL_POINTER;
nsIRDFArcsInCursor* result = new DBArcsInOutCursor(this, node, 0);
if (! result)
return NS_ERROR_NULL_POINTER;
NS_ADDREF(result);
*labels = result;
return NS_OK;
}
NS_IMETHODIMP
CompositeDataSourceImpl::ArcLabelsOut(nsIRDFResource* source,
nsIRDFArcsOutCursor** labels)
{
if (! labels)
return NS_ERROR_NULL_POINTER;
nsIRDFArcsOutCursor* result = new DBArcsInOutCursor(this, source, 1);
if (! result)
return NS_ERROR_NULL_POINTER;
NS_ADDREF(result);
*labels = result;
return NS_OK;
}
NS_IMETHODIMP
CompositeDataSourceImpl::GetAllResources(nsIRDFResourceCursor** aCursor)
{
NS_NOTYETIMPLEMENTED("write me!");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
CompositeDataSourceImpl::Flush()
{
for (PRInt32 i = mDataSources.Count() - 1; i >= 0; --i) {
nsIRDFDataSource* ds = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[i]);
ds->Flush();
}
return NS_OK;
}
NS_IMETHODIMP
CompositeDataSourceImpl::IsCommandEnabled(const char* aCommand,
nsIRDFResource* aCommandTarget,
PRBool* aResult)
{
NS_NOTYETIMPLEMENTED("write me!");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
CompositeDataSourceImpl::DoCommand(const char* aCommand,
nsIRDFResource* aCommandTarget)
{
NS_NOTYETIMPLEMENTED("write me!");
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////
// nsIRDFCompositeDataSource methods
// XXX rvg We should make this take an additional argument specifying where
// in the sequence of data sources (of the db), the new data source should
// fit in. Right now, the new datasource gets stuck at the end.
// need to add the observers of the CompositeDataSourceImpl to the new data source.
NS_IMETHODIMP
CompositeDataSourceImpl::AddDataSource(nsIRDFDataSource* source)
{
NS_ASSERTION(source != nsnull, "null ptr");
if (! source)
return NS_ERROR_NULL_POINTER;
mDataSources.InsertElementAt(source, 0);
source->AddObserver(this);
NS_ADDREF(source);
return NS_OK;
}
NS_IMETHODIMP
CompositeDataSourceImpl::RemoveDataSource(nsIRDFDataSource* source)
{
NS_ASSERTION(source != nsnull, "null ptr");
if (! source)
return NS_ERROR_NULL_POINTER;
if (mDataSources.IndexOf(source) >= 0) {
mDataSources.RemoveElement(source);
source->RemoveObserver(this);
NS_RELEASE(source);
}
return NS_OK;
}
NS_IMETHODIMP
CompositeDataSourceImpl::OnAssert(nsIRDFResource* subject,
nsIRDFResource* predicate,
nsIRDFNode* object)
{
if (mObservers) {
for (PRInt32 i = mObservers->Count() - 1; i >= 0; --i) {
nsIRDFObserver* obs = (nsIRDFObserver*) mObservers->ElementAt(i);
obs->OnAssert(subject, predicate, object);
// XXX ignore return value?
}
}
return NS_OK;
}
NS_IMETHODIMP
CompositeDataSourceImpl::OnUnassert(nsIRDFResource* subject,
nsIRDFResource* predicate,
nsIRDFNode* object)
{
if (mObservers) {
for (PRInt32 i = mObservers->Count() - 1; i >= 0; --i) {
nsIRDFObserver* obs = (nsIRDFObserver*) mObservers->ElementAt(i);
obs->OnUnassert(subject, predicate, object);
// XXX ignore return value?
}
}
return NS_OK;
}

View File

@@ -0,0 +1,339 @@
/* -*- 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.
*/
/*
A simple cursor that enumerates the elements of an RDF container
(RDF:Bag, RDF:Seq, or RDF:Alt).
Caveats
-------
1. This uses an implementation-specific detail to determine the
index of the last element in the container; specifically, the RDF
utilities maintain a counter attribute on the container that
holds the numeric value of the next value that is to be
assigned. So, this cursor will bust if you use it with a bag that
hasn't been created using the RDF utility routines.
2. This is sort of a continuation of (1), but -- it's not smart
enough to notice duplicates.
TODO. This is way too brain dead to handle aggregated RDF
databases. It needs to be upgraded in a big way.
*/
#include "nscore.h"
#include "nsIRDFCursor.h"
#include "nsIRDFDataSource.h"
#include "nsIRDFNode.h"
#include "nsIRDFService.h"
#include "nsIServiceManager.h"
#include "nsRDFCID.h"
#include "nsString.h"
#include "prlog.h"
#include "rdf.h"
#include "rdfutil.h"
////////////////////////////////////////////////////////////////////////
static NS_DEFINE_IID(kIRDFAssertionCursorIID, NS_IRDFASSERTIONCURSOR_IID);
static NS_DEFINE_IID(kIRDFCursorIID, NS_IRDFCURSOR_IID);
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
////////////////////////////////////////////////////////////////////////
static const char kRDFNameSpaceURI[] = RDF_NAMESPACE_URI;
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, nextVal); // ad hoc way to make containers fast
////////////////////////////////////////////////////////////////////////
class ContainerCursorImpl : public nsIRDFAssertionCursor {
private:
// pseudo-constants
static nsrefcnt gRefCnt;
static nsIRDFResource* kRDF_nextVal;
nsIRDFDataSource* mDataSource;
nsIRDFResource* mContainer;
nsIRDFNode* mCurrent;
nsIRDFResource* mOrdinalProperty;
PRInt32 mNextIndex;
public:
ContainerCursorImpl(nsIRDFDataSource* ds, nsIRDFResource* container);
virtual ~ContainerCursorImpl(void);
NS_DECL_ISUPPORTS
NS_IMETHOD Advance(void);
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource);
NS_IMETHOD GetSubject(nsIRDFResource** aResource);
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate);
NS_IMETHOD GetObject(nsIRDFNode** aObject);
NS_IMETHOD GetTruthValue(PRBool* aTruthValue);
NS_IMETHOD GetValue(nsIRDFNode** aValue);
};
nsrefcnt ContainerCursorImpl::gRefCnt;
nsIRDFResource* ContainerCursorImpl::kRDF_nextVal;
ContainerCursorImpl::ContainerCursorImpl(nsIRDFDataSource* ds,
nsIRDFResource* container)
: mDataSource(ds),
mContainer(container),
mCurrent(nsnull),
mOrdinalProperty(nsnull),
mNextIndex(1)
{
NS_INIT_REFCNT();
NS_IF_ADDREF(mDataSource);
NS_IF_ADDREF(mContainer);
if (gRefCnt++ == 0) {
nsresult rv;
nsIRDFService* service;
rv = nsServiceManager::GetService(kRDFServiceCID,
kIRDFServiceIID,
(nsISupports**) &service);
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to acquire resource manager");
if (! service)
return;
NS_VERIFY(NS_SUCCEEDED(rv = service->GetResource(kURIRDF_nextVal, &kRDF_nextVal)),
"unable to get resource");
}
}
ContainerCursorImpl::~ContainerCursorImpl(void)
{
NS_IF_RELEASE(mCurrent);
NS_IF_RELEASE(mOrdinalProperty);
NS_IF_RELEASE(mContainer);
NS_IF_RELEASE(mDataSource);
if (--gRefCnt == 0) {
NS_IF_RELEASE(kRDF_nextVal);
}
}
NS_IMPL_ADDREF(ContainerCursorImpl);
NS_IMPL_RELEASE(ContainerCursorImpl);
NS_IMETHODIMP_(nsresult)
ContainerCursorImpl::QueryInterface(REFNSIID iid, void** result) {
if (! result)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(kIRDFAssertionCursorIID) ||
iid.Equals(kIRDFCursorIID) ||
iid.Equals(kISupportsIID)) {
*result = NS_STATIC_CAST(nsIRDFAssertionCursor*, this);
/* AddRef(); // not necessary */
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP
ContainerCursorImpl::Advance(void)
{
nsresult rv;
// release the last value that we were holding
NS_IF_RELEASE(mCurrent);
nsIRDFNode* nextNode = nsnull;
nsIRDFLiteral* nextVal = nsnull;
const PRUnichar* p;
nsAutoString s;
PRInt32 last;
PRInt32 err;
// Figure out the upper bound so we'll know when we're done.
// XXX we could cache all this crap when the cursor gets created.
if (NS_FAILED(rv = mDataSource->GetTarget(mContainer, kRDF_nextVal, PR_TRUE, &nextNode)))
goto done;
if (NS_FAILED(rv = nextNode->QueryInterface(kIRDFLiteralIID, (void**) &nextVal)))
goto done;
if (NS_FAILED(rv = nextVal->GetValue(&p)))
goto done;
s = p;
last = s.ToInteger(&err);
if (NS_FAILED(err))
goto done;
// initialize rv to the case where mNextIndex has advanced past the
// last element
rv = NS_ERROR_RDF_CURSOR_EMPTY;
while (mNextIndex < last) {
NS_IF_RELEASE(mOrdinalProperty);
if (NS_FAILED(rv = rdf_IndexToOrdinalResource(mNextIndex, &mOrdinalProperty)))
break;
rv = mDataSource->GetTarget(mContainer, mOrdinalProperty, PR_TRUE, &mCurrent);
++mNextIndex;
if (NS_SUCCEEDED(rv)) {
// Don't bother releasing mCurrent; we'll let the AddRef
// serve as the implicit addref that GetNext() should
// perform.
break;
}
}
done:
NS_IF_RELEASE(nextNode);
NS_IF_RELEASE(nextVal);
return rv;
}
NS_IMETHODIMP
ContainerCursorImpl::GetDataSource(nsIRDFDataSource** aDataSource)
{
NS_PRECONDITION(aDataSource != nsnull, "null ptr");
if (! aDataSource)
return NS_ERROR_NULL_POINTER;
NS_ADDREF(mDataSource);
*aDataSource = mDataSource;
return NS_OK;
}
NS_IMETHODIMP
ContainerCursorImpl::GetSubject(nsIRDFResource** aSubject)
{
NS_PRECONDITION(aSubject != nsnull, "null ptr");
if (! aSubject)
return NS_ERROR_NULL_POINTER;
NS_ADDREF(mContainer);
*aSubject = mContainer;
return NS_OK;
}
NS_IMETHODIMP
ContainerCursorImpl::GetPredicate(nsIRDFResource** aPredicate)
{
NS_PRECONDITION(aPredicate != nsnull, "null ptr");
if (! aPredicate)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(mOrdinalProperty, "unexpected");
if (! mOrdinalProperty)
return NS_ERROR_UNEXPECTED;
NS_ADDREF(mOrdinalProperty);
*aPredicate = mOrdinalProperty;
return NS_OK;
}
NS_IMETHODIMP
ContainerCursorImpl::GetObject(nsIRDFNode** aObject)
{
NS_PRECONDITION(aObject != nsnull, "null ptr");
if (! aObject)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(mCurrent, "unexpected");
if (! mCurrent)
return NS_ERROR_UNEXPECTED;
NS_ADDREF(mCurrent);
*aObject = mCurrent;
return NS_OK;
}
NS_IMETHODIMP
ContainerCursorImpl::GetValue(nsIRDFNode** aObject)
{
NS_PRECONDITION(aObject != nsnull, "null ptr");
if (! aObject)
return NS_ERROR_NULL_POINTER;
if (! mCurrent)
return NS_ERROR_UNEXPECTED;
NS_ADDREF(mCurrent);
*aObject = mCurrent;
return NS_OK;
}
NS_IMETHODIMP
ContainerCursorImpl::GetTruthValue(PRBool* aTruthValue)
{
NS_PRECONDITION(aTruthValue != nsnull, "null ptr");
if (! aTruthValue)
return NS_ERROR_NULL_POINTER;
*aTruthValue = PR_TRUE;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
nsresult
NS_NewContainerCursor(nsIRDFDataSource* ds,
nsIRDFResource* container,
nsIRDFAssertionCursor** cursor)
{
NS_PRECONDITION(ds != nsnull, "null ptr");
NS_PRECONDITION(container != nsnull, "null ptr");
NS_PRECONDITION(cursor != nsnull, "null ptr");
if (!ds || !container || !cursor)
return NS_ERROR_NULL_POINTER;
NS_ASSERTION(rdf_IsContainer(ds, container), "not a container");
if (! rdf_IsContainer(ds, container))
return NS_ERROR_ILLEGAL_VALUE;
ContainerCursorImpl* result = new ContainerCursorImpl(ds, container);
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
*cursor = result;
NS_ADDREF(result);
return NS_OK;
}

View File

@@ -0,0 +1,229 @@
/* -*- 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.
*/
/*
The default resource factory implementation. This resource factory
produces nsIRDFResource objects for any URI prefix that is not
covered by some other factory.
*/
#include "nsIRDFNode.h"
#include "nsIRDFResourceFactory.h"
#include "nsIRDFService.h"
#include "nsIServiceManager.h"
#include "nsRDFCID.h"
#include "plstr.h"
////////////////////////////////////////////////////////////////////////
static NS_DEFINE_IID(kIRDFNodeIID, NS_IRDFNODE_IID);
static NS_DEFINE_IID(kIRDFResourceFactoryIID, NS_IRDFRESOURCEFACTORY_IID);
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
////////////////////////////////////////////////////////////////////////
class DefaultResourceImpl : public nsIRDFResource
{
public:
DefaultResourceImpl(const char* uri);
virtual ~DefaultResourceImpl(void);
// nsISupports
NS_DECL_ISUPPORTS
// nsIRDFNode
NS_IMETHOD EqualsNode(nsIRDFNode* node, PRBool* result) const;
// nsIRDFResource
NS_IMETHOD GetValue(const char* *uri) const;
NS_IMETHOD EqualsResource(const nsIRDFResource* resource, PRBool* result) const;
NS_IMETHOD EqualsString(const char* uri, PRBool* result) const;
// Implementation methods
const char* GetURI(void) const {
return mURI;
}
private:
char* mURI;
};
DefaultResourceImpl::DefaultResourceImpl(const char* uri)
{
NS_INIT_REFCNT();
mURI = PL_strdup(uri);
}
DefaultResourceImpl::~DefaultResourceImpl(void)
{
nsresult rv;
nsIRDFService* mgr;
rv = nsServiceManager::GetService(kRDFServiceCID,
kIRDFServiceIID,
(nsISupports**) &mgr);
PR_ASSERT(NS_SUCCEEDED(rv));
if (NS_SUCCEEDED(rv)) {
mgr->UnCacheResource(this);
nsServiceManager::ReleaseService(kRDFServiceCID, mgr);
}
// N.B. that we need to free the URI *after* we un-cache the resource,
// due to the way that the resource manager is implemented.
PL_strfree(mURI);
}
NS_IMPL_ADDREF(DefaultResourceImpl);
NS_IMPL_RELEASE(DefaultResourceImpl);
nsresult
DefaultResourceImpl::QueryInterface(REFNSIID iid, void** result)
{
if (! result)
return NS_ERROR_NULL_POINTER;
*result = nsnull;
if (iid.Equals(kIRDFResourceIID) ||
iid.Equals(kIRDFNodeIID) ||
iid.Equals(kISupportsIID)) {
*result = NS_STATIC_CAST(nsIRDFResource*, this);
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP
DefaultResourceImpl::EqualsNode(nsIRDFNode* node, PRBool* result) const
{
nsresult rv;
nsIRDFResource* resource;
if (NS_SUCCEEDED(node->QueryInterface(kIRDFResourceIID, (void**) &resource))) {
rv = EqualsResource(resource, result);
NS_RELEASE(resource);
}
else {
*result = PR_FALSE;
rv = NS_OK;
}
return rv;
}
NS_IMETHODIMP
DefaultResourceImpl::GetValue(const char* *uri) const
{
if (!uri)
return NS_ERROR_NULL_POINTER;
*uri = mURI;
return NS_OK;
}
NS_IMETHODIMP
DefaultResourceImpl::EqualsResource(const nsIRDFResource* resource, PRBool* result) const
{
if (!resource || !result)
return NS_ERROR_NULL_POINTER;
*result = (resource == this);
return NS_OK;
}
NS_IMETHODIMP
DefaultResourceImpl::EqualsString(const char* uri, PRBool* result) const
{
if (!uri || !result)
return NS_ERROR_NULL_POINTER;
*result = (PL_strcmp(uri, mURI) == 0);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
class DefaultResourceFactoryImpl : public nsIRDFResourceFactory
{
public:
DefaultResourceFactoryImpl(void);
virtual ~DefaultResourceFactoryImpl(void);
NS_DECL_ISUPPORTS
NS_IMETHOD CreateResource(const char* aURI, nsIRDFResource** aResult);
};
DefaultResourceFactoryImpl::DefaultResourceFactoryImpl(void)
{
NS_INIT_REFCNT();
}
DefaultResourceFactoryImpl::~DefaultResourceFactoryImpl(void)
{
}
NS_IMPL_ISUPPORTS(DefaultResourceFactoryImpl, kIRDFResourceFactoryIID);
NS_IMETHODIMP
DefaultResourceFactoryImpl::CreateResource(const char* aURI, nsIRDFResource** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
DefaultResourceImpl* resource = new DefaultResourceImpl(aURI);
if (! resource)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(resource);
*aResult = resource;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
nsresult
NS_NewRDFDefaultResourceFactory(nsIRDFResourceFactory** result)
{
NS_PRECONDITION(result != nsnull, "null ptr");
if (! result)
return NS_ERROR_NULL_POINTER;
DefaultResourceFactoryImpl* factory = new DefaultResourceFactoryImpl();
if (! factory)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(factory);
*result = factory;
return NS_OK;
}

View File

@@ -0,0 +1,240 @@
/* -*- 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.
*/
/*
A set of "empty cursors" (nsIRDFAssertionCursor,
nsIRDFArcsOutCursor, nsIRDFArcsInCursor) that can be used to ensure
that the data source methods which return a cursor always return
*something*.
*/
#include "nscore.h"
#include "nsIRDFCursor.h"
static NS_DEFINE_IID(kIRDFArcsInCursorIID, NS_IRDFARCSINCURSOR_IID);
static NS_DEFINE_IID(kIRDFArcsOutCursorIID, NS_IRDFARCSOUTCURSOR_IID);
static NS_DEFINE_IID(kIRDFAssertionCursorIID, NS_IRDFASSERTIONCURSOR_IID);
static NS_DEFINE_IID(kIRDFCursorIID, NS_IRDFCURSOR_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
////////////////////////////////////////////////////////////////////////
class EmptyAssertionCursorImpl : public nsIRDFAssertionCursor
{
public:
EmptyAssertionCursorImpl(void) {};
virtual ~EmptyAssertionCursorImpl(void) {};
// nsISupports
NS_IMETHOD_(nsrefcnt) AddRef(void) {
return 2;
}
NS_IMETHOD_(nsrefcnt) Release(void) {
return 1;
}
NS_IMETHOD QueryInterface(REFNSIID iid, void** result) {
if (! result)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(kIRDFAssertionCursorIID) ||
iid.Equals(kIRDFCursorIID) ||
iid.Equals(kISupportsIID)) {
*result = NS_STATIC_CAST(nsIRDFAssertionCursor*, this);
/* AddRef(); // not necessary */
return NS_OK;
}
return NS_NOINTERFACE;
}
// nsIRDFCursor
NS_IMETHOD Advance(void) {
return NS_ERROR_RDF_CURSOR_EMPTY;
}
// nsIRDFAssertionCursor
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource) {
return NS_ERROR_UNEXPECTED;
}
NS_IMETHOD GetSubject(nsIRDFResource** aResource) {
return NS_ERROR_UNEXPECTED;
}
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate) {
return NS_ERROR_UNEXPECTED;
}
NS_IMETHOD GetObject(nsIRDFNode** aObject) {
return NS_ERROR_UNEXPECTED;
}
NS_IMETHOD GetTruthValue(PRBool* aTruthValue) {
return NS_ERROR_UNEXPECTED;
}
NS_IMETHOD GetValue(nsIRDFNode** aValue) {
return NS_ERROR_UNEXPECTED;
}
};
nsresult
NS_NewEmptyRDFAssertionCursor(nsIRDFAssertionCursor** result)
{
static EmptyAssertionCursorImpl gEmptyAssertionCursor;
*result = &gEmptyAssertionCursor;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
class EmptyArcsOutCursorImpl : public nsIRDFArcsOutCursor
{
public:
EmptyArcsOutCursorImpl(void) {};
virtual ~EmptyArcsOutCursorImpl(void) {};
// nsISupports
NS_IMETHOD_(nsrefcnt) AddRef(void) {
return 2;
}
NS_IMETHOD_(nsrefcnt) Release(void) {
return 1;
}
NS_IMETHOD QueryInterface(REFNSIID iid, void** result) {
if (! result)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(kIRDFArcsOutCursorIID) ||
iid.Equals(kIRDFCursorIID) ||
iid.Equals(kISupportsIID)) {
*result = NS_STATIC_CAST(nsIRDFArcsOutCursor*, this);
/* AddRef(); // not necessary */
return NS_OK;
}
return NS_NOINTERFACE;
}
// nsIRDFCursor
NS_IMETHOD Advance(void) {
return NS_ERROR_RDF_CURSOR_EMPTY;
}
// nsIRDFArcsOutCursor
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource) {
return NS_ERROR_UNEXPECTED;
}
NS_IMETHOD GetSubject(nsIRDFResource** aResource) {
return NS_ERROR_UNEXPECTED;
}
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate) {
return NS_ERROR_UNEXPECTED;
}
NS_IMETHOD GetTruthValue(PRBool* aTruthValue) {
return NS_ERROR_UNEXPECTED;
}
NS_IMETHOD GetValue(nsIRDFNode** aValue) {
return NS_ERROR_UNEXPECTED;
}
};
nsresult
NS_NewEmptyRDFArcsOutCursor(nsIRDFArcsOutCursor** result)
{
static EmptyArcsOutCursorImpl gEmptyArcsOutCursor;
*result = &gEmptyArcsOutCursor;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
class EmptyArcsInCursorImpl : public nsIRDFArcsInCursor
{
public:
EmptyArcsInCursorImpl(void) {};
virtual ~EmptyArcsInCursorImpl(void) {};
// nsISupports
NS_IMETHOD_(nsrefcnt) AddRef(void) {
return 2;
}
NS_IMETHOD_(nsrefcnt) Release(void) {
return 1;
}
NS_IMETHOD QueryInterface(REFNSIID iid, void** result) {
if (! result)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(kIRDFArcsInCursorIID) ||
iid.Equals(kIRDFCursorIID) ||
iid.Equals(kISupportsIID)) {
*result = NS_STATIC_CAST(nsIRDFArcsInCursor*, this);
/* AddRef(); // not necessary */
return NS_OK;
}
return NS_NOINTERFACE;
}
// nsIRDFCursor
NS_IMETHOD Advance(void) {
return NS_ERROR_RDF_CURSOR_EMPTY;
}
// nsIRDFArcsInCursor
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource) {
return NS_ERROR_UNEXPECTED;
}
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate) {
return NS_ERROR_UNEXPECTED;
}
NS_IMETHOD GetObject(nsIRDFNode** aNode) {
return NS_ERROR_UNEXPECTED;
}
NS_IMETHOD GetTruthValue(PRBool* aTruthValue) {
return NS_ERROR_UNEXPECTED;
}
NS_IMETHOD GetValue(nsIRDFNode** aValue) {
return NS_ERROR_UNEXPECTED;
}
};
nsresult
NS_NewEmptyRDFArcsInCursor(nsIRDFArcsInCursor** result)
{
static EmptyArcsInCursorImpl gEmptyArcsInCursor;
*result = &gEmptyArcsInCursor;
return NS_OK;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,40 @@
/* -*- 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 header file just contains prototypes for the factory methods
for "builtin" data sources that are included in rdf.dll.
Each of these data sources is exposed to the external world via its
CID in ../include/nsRDFCID.h.
*/
#ifndef nsBaseDataSources_h__
#define nsBaseDataSources_h__
#include "nsError.h"
class nsIRDFDataSource;
// in nsInMemoryDataSource.cpp
nsresult NS_NewRDFInMemoryDataSource(nsIRDFDataSource** result);
#endif // nsBaseDataSources_h__

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,137 @@
/* -*- 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.
*/
/*
*/
#ifndef nsRDFContentSink_h__
#define nsRDFContentSink_h__
#include "nsIRDFContentSink.h"
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 SetDataSource(nsIRDFDataSource* ds);
NS_IMETHOD GetDataSource(nsIRDFDataSource*& ds);
NS_IMETHOD Init(nsIURL* aURL, nsINameSpaceManager* aNameSpaceManager);
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;
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
};
#endif // nsRDFContentSink_h__

View File

@@ -0,0 +1,260 @@
/* -*- 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.
*/
/*
Some useful parsing routines.
This isn't the best place for them: I wish that they'd go into some
shared area (like mozilla/base).
*/
#include <stdlib.h> // XXX for atoi(), maybe this should go into nsCRT?
#include "nsCRT.h"
#include "nsIURL.h"
#include "nsString.h"
#include "nsRDFParserUtils.h"
// XXX This totally sucks. I wish that mozilla/base had this code.
PRUnichar
nsRDFParserUtils::EntityToUnicode(const char* buf)
{
if ((buf[0] == 'g' || buf[0] == 'G') &&
(buf[1] == 't' || buf[1] == 'T'))
return PRUnichar('>');
if ((buf[0] == 'l' || buf[0] == 'L') &&
(buf[1] == 't' || buf[1] == 'T'))
return PRUnichar('<');
if ((buf[0] == 'a' || buf[0] == 'A') &&
(buf[1] == 'm' || buf[1] == 'M') &&
(buf[2] == 'p' || buf[2] == 'P'))
return PRUnichar('&');
NS_NOTYETIMPLEMENTED("this is a named entity that I can't handle...");
return PRUnichar('?');
}
// XXX Code copied from nsHTMLContentSink. It should be shared.
void
nsRDFParserUtils::StripAndConvert(nsString& aResult)
{
// Strip quotes if present
PRUnichar first = aResult.First();
if ((first == '"') || (first == '\'')) {
if (aResult.Last() == first) {
aResult.Cut(0, 1);
PRInt32 pos = aResult.Length() - 1;
if (pos >= 0) {
aResult.Cut(pos, 1);
}
} else {
// Mismatched quotes - leave them in
}
}
// Reduce any entities
// XXX Note: as coded today, this will only convert well formed
// entities. This may not be compatible enough.
// XXX there is a table in navigator that translates some numeric entities
// should we be doing that? If so then it needs to live in two places (bad)
// so we should add a translate numeric entity method from the parser...
char cbuf[100];
PRInt32 index = 0;
while (index < aResult.Length()) {
// If we have the start of an entity (and it's not at the end of
// our string) then translate the entity into it's unicode value.
if ((aResult.CharAt(index++) == '&') && (index < aResult.Length())) {
PRInt32 start = index - 1;
PRUnichar e = aResult.CharAt(index);
if (e == '#') {
// Convert a numeric character reference
index++;
char* cp = cbuf;
char* limit = cp + sizeof(cbuf) - 1;
PRBool ok = PR_FALSE;
PRInt32 slen = aResult.Length();
while ((index < slen) && (cp < limit)) {
PRUnichar e = aResult.CharAt(index);
if (e == ';') {
index++;
ok = PR_TRUE;
break;
}
if ((e >= '0') && (e <= '9')) {
*cp++ = char(e);
index++;
continue;
}
break;
}
if (!ok || (cp == cbuf)) {
continue;
}
*cp = '\0';
if (cp - cbuf > 5) {
continue;
}
PRInt32 ch = PRInt32( ::atoi(cbuf) );
if (ch > 65535) {
continue;
}
// Remove entity from string and replace it with the integer
// value.
aResult.Cut(start, index - start);
aResult.Insert(PRUnichar(ch), start);
index = start + 1;
}
else if (((e >= 'A') && (e <= 'Z')) ||
((e >= 'a') && (e <= 'z'))) {
// Convert a named entity
index++;
char* cp = cbuf;
char* limit = cp + sizeof(cbuf) - 1;
*cp++ = char(e);
PRBool ok = PR_FALSE;
PRInt32 slen = aResult.Length();
while ((index < slen) && (cp < limit)) {
PRUnichar e = aResult.CharAt(index);
if (e == ';') {
index++;
ok = PR_TRUE;
break;
}
if (((e >= '0') && (e <= '9')) ||
((e >= 'A') && (e <= 'Z')) ||
((e >= 'a') && (e <= 'z'))) {
*cp++ = char(e);
index++;
continue;
}
break;
}
if (!ok || (cp == cbuf)) {
continue;
}
*cp = '\0';
PRInt32 ch;
// XXX Um, here's where we should be converting a
// named entity. I removed this to avoid a link-time
// dependency on core raptor.
ch = EntityToUnicode(cbuf);
if (ch < 0) {
continue;
}
// Remove entity from string and replace it with the integer
// value.
aResult.Cut(start, index - start);
aResult.Insert(PRUnichar(ch), start);
index = start + 1;
}
else if (e == '{') {
// Convert a script entity
// XXX write me!
NS_NOTYETIMPLEMENTED("convert a script entity");
}
}
}
}
nsresult
nsRDFParserUtils::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;
}
void
nsRDFParserUtils::FullyQualifyURI(const nsIURL* base, nsString& spec)
{
// This is a fairly heavy-handed way to do this, but...I don't
// like typing.
nsIURL* url;
if (NS_SUCCEEDED(NS_NewURL(&url, spec, base))) {
PRUnichar* str;
url->ToString(&str);
spec = str;
delete str;
url->Release();
}
}
PRBool
nsRDFParserUtils::IsJavaScriptLanguage(const nsString& aName)
{
if (aName.EqualsIgnoreCase("JavaScript") ||
aName.EqualsIgnoreCase("LiveScript") ||
aName.EqualsIgnoreCase("Mocha")) {
return PR_TRUE;
}
else if (aName.EqualsIgnoreCase("JavaScript1.1")) {
return PR_TRUE;
}
else if (aName.EqualsIgnoreCase("JavaScript1.2")) {
return PR_TRUE;
}
else if (aName.EqualsIgnoreCase("JavaScript1.3")) {
return PR_TRUE;
}
else if (aName.EqualsIgnoreCase("JavaScript1.4")) {
return PR_TRUE;
}
else {
return PR_FALSE;
}
}

View File

@@ -0,0 +1,58 @@
/* -*- 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.
*/
/*
Some useful parsing routines.
*/
#ifndef nsRDFParserUtils_h__
#define nsRDFParserUtils_h__
#include "nscore.h"
class nsIURL;
class nsString;
class nsRDFParserUtils {
public:
static PRUnichar
EntityToUnicode(const char* buf);
static void
StripAndConvert(nsString& aResult);
static nsresult
GetQuotedAttributeValue(const nsString& aSource,
const nsString& aAttribute,
nsString& aValue);
static void
FullyQualifyURI(const nsIURL* base, nsString& spec);
static PRBool
IsJavaScriptLanguage(const nsString& aName);
};
#endif // nsRDFPasrserUtils_h__

View File

@@ -0,0 +1,117 @@
/* -*- Mode: C++; tab-width: 2; 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.
*/
#include "nsRDFResource.h"
#include "nsCRT.h"
////////////////////////////////////////////////////////////////////////////////
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
static NS_DEFINE_IID(kIRDFNodeIID, NS_IRDFNODE_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
////////////////////////////////////////////////////////////////////////////////
nsRDFResource::nsRDFResource(const char* uri)
: mURI(uri)
{
}
nsRDFResource::~nsRDFResource(void)
{
}
NS_IMPL_ADDREF(nsRDFResource)
NS_IMPL_RELEASE(nsRDFResource)
NS_IMETHODIMP
nsRDFResource::QueryInterface(REFNSIID iid, void** result)
{
if (! result)
return NS_ERROR_NULL_POINTER;
*result = nsnull;
if (iid.Equals(kIRDFResourceIID) ||
iid.Equals(kIRDFNodeIID) ||
iid.Equals(kISupportsIID)) {
*result = NS_STATIC_CAST(nsIRDFResource*, this);
}
if (*result != nsnull) {
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
////////////////////////////////////////////////////////////////////////////////
// nsIRDFNode methods:
NS_METHOD
nsRDFResource::EqualsNode(nsIRDFNode* node, PRBool* result) const
{
nsresult rv;
nsIRDFResource* resource;
if (NS_SUCCEEDED(node->QueryInterface(kIRDFResourceIID, (void**) &resource))) {
rv = EqualsResource(resource, result);
NS_RELEASE(resource);
}
else {
*result = PR_FALSE;
rv = NS_OK;
}
return rv;
}
////////////////////////////////////////////////////////////////////////////////
// nsIRDFResource methods:
NS_METHOD
nsRDFResource::GetValue(const char* *uri) const
{
if (!uri)
return NS_ERROR_NULL_POINTER;
*uri = mURI;
return NS_OK;
}
NS_METHOD
nsRDFResource::EqualsResource(const nsIRDFResource* resource, PRBool* result) const
{
if (!resource || !result)
return NS_ERROR_NULL_POINTER;
const char *uri;
if (NS_SUCCEEDED(resource->GetValue(&uri))) {
return EqualsString(uri, result) ? NS_OK : NS_ERROR_FAILURE;
}
return NS_ERROR_FAILURE;
}
NS_METHOD
nsRDFResource::EqualsString(const char* uri, PRBool* result) const
{
if (!uri || !result)
return NS_ERROR_NULL_POINTER;
*result = nsCRT::strcmp(uri, mURI) == 0;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////

View File

@@ -0,0 +1,759 @@
/* -*- 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 file provides the implementation for the RDF service manager.
TO DO
-----
1) Figure out a better way to do "pluggable resources." Currently,
we have two _major_ hacks:
RegisterBuiltInNamedDataSources()
RegisterBuiltInResourceFactories()
These introduce dependencies on the datasource directory. You'd
like to have this stuff discovered dynamically at startup or
something. Maybe from the registry.
2) Implement the CreateDataBase() methods.
*/
#include "nsIAtom.h"
#include "nsIRDFDataSource.h"
#include "nsIRDFNode.h"
#include "nsIRDFService.h"
#include "nsIRDFResourceFactory.h"
#include "nsString.h"
#include "plhash.h"
#include "plstr.h"
#include "prlog.h"
////////////////////////////////////////////////////////////////////////
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
static NS_DEFINE_IID(kIRDFNodeIID, NS_IRDFNODE_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
////////////////////////////////////////////////////////////////////////
// PrefixMap
//
// A simple map from a string prefix to a value. It maintains an
// ordered list of prefixes that map to a <tt>void*</tt>. The list
// is sorted in ASCII order such that if one prefix <b>p</b> is
// itself a prefix of another prefix <b>q</b>, the longest prefix
// (<b>q</b>) will appear first in the list. The idea is that you
// want to find the "best" match first. (Will this actually be
// useful? Probabably not...)
//
class PrefixMap
{
private:
struct PrefixMapEntry
{
const char* mPrefix;
PRInt32 mPrefixLen;
const void* mValue;
PrefixMapEntry* mNext;
};
PrefixMapEntry* mHead;
public:
PrefixMap();
~PrefixMap();
PRBool Add(const char* aPrefix, const void* aValue);
const void* Remove(const char* aPrefix);
/**
* Find the most specific value matching the specified string.
*/
const void* Find(const char* aString);
};
PrefixMap::PrefixMap()
: mHead(nsnull)
{
}
PrefixMap::~PrefixMap()
{
while (mHead) {
PrefixMapEntry* doomed = mHead;
mHead = mHead->mNext;
PL_strfree(NS_CONST_CAST(char*, doomed->mPrefix));
delete doomed;
}
}
PRBool
PrefixMap::Add(const char* aPrefix, const void* aValue)
{
PRInt32 newPrefixLen = PL_strlen(aPrefix);
PrefixMapEntry* entry = mHead;
PrefixMapEntry* last = nsnull;
while (entry != nsnull) {
// check to see if the new prefix is longer than the current
// entry. If so, we'll want to insert the new prefix *before*
// this one.
if (newPrefixLen > entry->mPrefixLen)
break;
// check for exact equality: if so, the prefix is already
// registered, so fail (?)
if (PL_strcmp(entry->mPrefix, aPrefix) == 0)
return PR_FALSE;
// otherwise, the new prefix is the same length or shorter
// than the current entry: continue on to the next one.
last = entry;
entry = entry->mNext;
}
PrefixMapEntry* newEntry = new PrefixMapEntry;
if (! newEntry)
return PR_FALSE;
newEntry->mPrefix = PL_strdup(aPrefix);
newEntry->mPrefixLen = newPrefixLen;
newEntry->mValue = aValue;
if (last) {
// we found an entry that we need to insert the current
// entry *before*
newEntry->mNext = last->mNext;
last->mNext = newEntry;
}
else {
// Otherwise, insert at the start
newEntry->mNext = mHead;
mHead = newEntry;
}
return PR_TRUE;
}
const void*
PrefixMap::Remove(const char* aPrefix)
{
PrefixMapEntry* entry = mHead;
PrefixMapEntry* last = nsnull;
PRInt32 doomedPrefixLen = PL_strlen(aPrefix);
while (entry != nsnull) {
if ((doomedPrefixLen == entry->mPrefixLen) &&
(PL_strcmp(entry->mPrefix, aPrefix) == 0)) {
if (last) {
last->mNext = entry->mNext;
}
else {
mHead = entry->mNext;
}
const void* value = entry->mValue;
PL_strfree(NS_CONST_CAST(char*, entry->mPrefix));
delete entry;
return value;
}
last = entry;
entry = entry->mNext;
}
return nsnull;
}
const void*
PrefixMap::Find(const char* aString)
{
for (PrefixMapEntry* entry = mHead; entry != nsnull; entry = entry->mNext) {
PRInt32 cmp = PL_strncmp(entry->mPrefix, aString, entry->mPrefixLen);
if (cmp == 0)
return entry->mValue;
}
return nsnull;
}
////////////////////////////////////////////////////////////////////////
// LiteralImpl
//
// Currently, all literals are implemented exactly the same way;
// i.e., there is are no resource factories to allow you to generate
// customer resources. I doubt that makes sense, anyway.
//
// What _may_ make sense is to atomize literals (well, at least
// short ones), to reduce in memory overhead at the expense of some
// processing time.
//
class LiteralImpl : public nsIRDFLiteral {
public:
LiteralImpl(const PRUnichar* s);
virtual ~LiteralImpl(void);
// nsISupports
NS_DECL_ISUPPORTS
// nsIRDFNode
NS_IMETHOD EqualsNode(nsIRDFNode* node, PRBool* result) const;
// nsIRDFLiteral
NS_IMETHOD GetValue(const PRUnichar* *value) const;
NS_IMETHOD EqualsLiteral(const nsIRDFLiteral* literal, PRBool* result) const;
private:
nsAutoString mValue;
};
LiteralImpl::LiteralImpl(const PRUnichar* s)
: mValue(s)
{
NS_INIT_REFCNT();
}
LiteralImpl::~LiteralImpl(void)
{
}
NS_IMPL_ADDREF(LiteralImpl);
NS_IMPL_RELEASE(LiteralImpl);
nsresult
LiteralImpl::QueryInterface(REFNSIID iid, void** result)
{
if (! result)
return NS_ERROR_NULL_POINTER;
*result = nsnull;
if (iid.Equals(kIRDFLiteralIID) ||
iid.Equals(kIRDFNodeIID) ||
iid.Equals(kISupportsIID)) {
*result = NS_STATIC_CAST(nsIRDFLiteral*, this);
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP
LiteralImpl::EqualsNode(nsIRDFNode* node, PRBool* result) const
{
nsresult rv;
nsIRDFLiteral* literal;
if (NS_SUCCEEDED(node->QueryInterface(kIRDFLiteralIID, (void**) &literal))) {
rv = EqualsLiteral(literal, result);
NS_RELEASE(literal);
}
else {
*result = PR_FALSE;
rv = NS_OK;
}
return rv;
}
NS_IMETHODIMP
LiteralImpl::GetValue(const PRUnichar* *value) const
{
NS_ASSERTION(value, "null ptr");
if (! value)
return NS_ERROR_NULL_POINTER;
*value = mValue.GetUnicode();
return NS_OK;
}
NS_IMETHODIMP
LiteralImpl::EqualsLiteral(const nsIRDFLiteral* literal, PRBool* result) const
{
NS_ASSERTION(literal && result, "null ptr");
if (!literal || !result)
return NS_ERROR_NULL_POINTER;
nsresult rv;
const PRUnichar* p;
if (NS_FAILED(rv = literal->GetValue(&p)))
return rv;
nsAutoString s(p);
*result = s.Equals(mValue);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// ServiceImpl
//
// This is the RDF service.
//
class ServiceImpl : public nsIRDFService
{
protected:
PrefixMap mResourceFactories;
PLHashTable* mNamedDataSources;
PLHashTable* mDataSourceConstructors;
PLHashTable* mResources;
ServiceImpl(void);
virtual ~ServiceImpl(void);
static nsIRDFService* gRDFService; // The one-and-only RDF service
static void RegisterBuiltInResourceFactories();
static void RegisterBuiltInNamedDataSources();
public:
static nsresult GetRDFService(nsIRDFService** result);
// nsISupports
NS_DECL_ISUPPORTS
// nsIRDFService
NS_IMETHOD GetResource(const char* uri, nsIRDFResource** resource);
NS_IMETHOD GetUnicodeResource(const PRUnichar* uri, nsIRDFResource** resource);
NS_IMETHOD GetLiteral(const PRUnichar* value, nsIRDFLiteral** literal);
NS_IMETHOD UnCacheResource(nsIRDFResource* resource);
NS_IMETHOD RegisterResourceFactory(const char* aURIPrefix, nsIRDFResourceFactory* aFactory);
NS_IMETHOD UnRegisterResourceFactory(const char* aURIPrefix);
NS_IMETHOD RegisterDataSource(nsIRDFDataSource* dataSource);
NS_IMETHOD UnregisterDataSource(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 CreateBrowserDatabase(nsIRDFDataBase** dataBase);
};
nsIRDFService* ServiceImpl::gRDFService = nsnull;
////////////////////////////////////////////////////////////////////////
ServiceImpl::ServiceImpl(void)
: mResources(nsnull), mNamedDataSources(nsnull)
{
NS_INIT_REFCNT();
mResources = PL_NewHashTable(1023, // nbuckets
PL_HashString, // hash fn
PL_CompareStrings, // key compare fn
PL_CompareValues, // value compare fn
nsnull, nsnull); // alloc ops & priv
mNamedDataSources = PL_NewHashTable(23,
PL_HashString,
PL_CompareStrings,
PL_CompareValues,
nsnull, nsnull);
mDataSourceConstructors = PL_NewHashTable(23,
PL_HashString,
PL_CompareStrings,
PL_CompareValues,
nsnull, nsnull);
}
ServiceImpl::~ServiceImpl(void)
{
if (mDataSourceConstructors) {
PL_HashTableDestroy(mDataSourceConstructors);
mDataSourceConstructors = nsnull;
}
if (mNamedDataSources) {
PL_HashTableDestroy(mNamedDataSources);
mNamedDataSources = nsnull;
}
if (mResources) {
PL_HashTableDestroy(mResources);
mResources = nsnull;
}
gRDFService = nsnull;
}
nsresult
ServiceImpl::GetRDFService(nsIRDFService** mgr)
{
if (! gRDFService) {
gRDFService = new ServiceImpl();
if (! gRDFService)
return NS_ERROR_OUT_OF_MEMORY;
RegisterBuiltInResourceFactories();
RegisterBuiltInNamedDataSources();
}
NS_ADDREF(gRDFService);
*mgr = gRDFService;
return NS_OK;
}
NS_IMETHODIMP_(nsrefcnt)
ServiceImpl::AddRef(void)
{
return 2;
}
NS_IMETHODIMP_(nsrefcnt)
ServiceImpl::Release(void)
{
return 1;
}
NS_IMPL_QUERY_INTERFACE(ServiceImpl, kIRDFServiceIID);
NS_IMETHODIMP
ServiceImpl::GetResource(const char* uri, nsIRDFResource** resource)
{
nsIRDFResource* result =
NS_STATIC_CAST(nsIRDFResource*, PL_HashTableLookup(mResources, uri));
if (! result) {
nsIRDFResourceFactory* factory =
NS_STATIC_CAST(nsIRDFResourceFactory*,
NS_CONST_CAST(void*, mResourceFactories.Find(uri)));
PR_ASSERT(factory != nsnull);
if (! factory)
return NS_ERROR_FAILURE; // XXX
nsresult rv;
if (NS_FAILED(rv = factory->CreateResource(uri, &result)))
return rv;
const char* uri;
result->GetValue(&uri);
// This is a little trick to make storage more efficient. For
// the "key" in the table, we'll use the string value that's
// stored as a member variable of the nsIRDFResource object.
PL_HashTableAdd(mResources, uri, result);
// *We* don't AddRef() the resource: that way, the resource
// can be garbage collected when the last refcount goes
// away. The single addref that the CreateResource() call made
// will be owned by the callee.
}
else {
// Addref for the callee.
NS_ADDREF(result);
}
*resource = result;
return NS_OK;
}
NS_IMETHODIMP
ServiceImpl::GetUnicodeResource(const PRUnichar* uri, nsIRDFResource** resource)
{
nsString s(uri);
char* cstr = s.ToNewCString();
nsresult rv = GetResource(cstr, resource);
delete[] cstr;
return rv;
}
NS_IMETHODIMP
ServiceImpl::GetLiteral(const PRUnichar* uri, nsIRDFLiteral** literal)
{
LiteralImpl* result = new LiteralImpl(uri);
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
*literal = result;
NS_ADDREF(result);
return NS_OK;
}
NS_IMETHODIMP
ServiceImpl::UnCacheResource(nsIRDFResource* resource)
{
nsresult rv;
const char* uri;
if (NS_FAILED(rv = resource->GetValue(&uri)))
return rv;
PL_HashTableRemove(mResources, uri);
return NS_OK;
}
NS_IMETHODIMP
ServiceImpl::RegisterResourceFactory(const char* aURIPrefix, nsIRDFResourceFactory* aFactory)
{
if (! mResourceFactories.Add(aURIPrefix, aFactory))
return NS_ERROR_ILLEGAL_VALUE;
NS_ADDREF(aFactory); // XXX should we addref?
return NS_OK;
}
NS_IMETHODIMP
ServiceImpl::UnRegisterResourceFactory(const char* aURIPrefix)
{
nsIRDFResourceFactory* factory =
NS_STATIC_CAST(nsIRDFResourceFactory*,
NS_CONST_CAST(void*, mResourceFactories.Remove(aURIPrefix)));
if (! factory)
return NS_ERROR_ILLEGAL_VALUE;
NS_RELEASE(factory); // XXX should we addref?
return NS_OK;
}
NS_IMETHODIMP
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.
PL_HashTableAdd(mNamedDataSources, uri, aDataSource);
return NS_OK;
}
NS_IMETHODIMP
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 =
NS_STATIC_CAST(nsIRDFDataSource*, PL_HashTableLookup(mNamedDataSources, uri));
if (! ds)
return NS_ERROR_ILLEGAL_VALUE;
PL_HashTableRemove(mNamedDataSources, uri);
return NS_OK;
}
NS_IMETHODIMP
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 =
NS_STATIC_CAST(nsIRDFDataSource*, PL_HashTableLookup(mNamedDataSources, uri));
if (ds) {
NS_ADDREF(ds);
*aDataSource = ds;
return NS_OK;
}
// Otherwise, see if we have a lazy constructor
NSDataSourceConstructorCallback constructor =
(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
ServiceImpl::CreateDatabase(const char** uri, nsIRDFDataBase** dataBase)
{
PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
ServiceImpl::CreateBrowserDatabase(nsIRDFDataBase** dataBase)
{
PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////
//
// This is Big Hack #1. Depedencies on all builtin resource
// factories are *here*, in the ResourceFactoryTable.
//
struct ResourceFactoryTable {
const char* mPrefix;
nsresult (*mFactoryConstructor)(nsIRDFResourceFactory** result);
};
void
ServiceImpl::RegisterBuiltInResourceFactories(void)
{
extern nsresult NS_NewRDFDefaultResourceFactory(nsIRDFResourceFactory** result);
extern nsresult NS_NewRDFMailResourceFactory(nsIRDFResourceFactory** result);
extern nsresult NS_NewRDFMailAccountResourceFactory(nsIRDFResourceFactory** result);
extern nsresult NS_NewRDFFileResourceFactory(nsIRDFResourceFactory** result);
static ResourceFactoryTable gTable[] = {
"", NS_NewRDFDefaultResourceFactory,
"mailaccount:", NS_NewRDFMailAccountResourceFactory,
"mailbox:", NS_NewRDFMailResourceFactory,
#if 0
"file:", NS_NewRDFFileResourceFactory,
#endif
nsnull, nsnull
};
nsresult rv;
for (ResourceFactoryTable* entry = gTable; entry->mPrefix != nsnull; ++entry) {
nsIRDFResourceFactory* factory;
if (NS_FAILED(rv = (entry->mFactoryConstructor)(&factory)))
continue;
rv = gRDFService->RegisterResourceFactory(entry->mPrefix, factory);
PR_ASSERT(NS_SUCCEEDED(rv));
NS_RELEASE(factory);
}
}
////////////////////////////////////////////////////////////////////////
//
// This is Big Hack #2. Dependencies on all builtin datasources are
// *here*, in the DataSourceTable.
//
// FWIW, I don't particularly like this interface *anyway*, because
// it requires each built-in data source to be constructed "up
// front". Not only does it cause the service manager to be
// re-entered (which may be a problem), but it's wasteful: I think
// these data sources should be created on demand, and released when
// you're done with them.
//
struct DataSourceTable {
const char* mURI;
nsresult (*mDataSourceConstructor)(nsIRDFDataSource** result);
};
void
ServiceImpl::RegisterBuiltInNamedDataSources(void)
{
extern nsresult NS_NewRDFBookmarkDataSource(nsIRDFDataSource** result);
extern nsresult NS_NewRDFHistoryDataSource(nsIRDFDataSource** result);
extern nsresult NS_NewRDFLocalFileSystemDataSource(nsIRDFDataSource** result);
extern nsresult NS_NewRDFMailDataSource(nsIRDFDataSource** result);
static DataSourceTable gTable[] = {
"rdf:bookmarks", NS_NewRDFBookmarkDataSource,
"rdf:mail", NS_NewRDFMailDataSource,
#if 0
"rdf:history", NS_NewRDFHistoryDataSource,
"rdf:lfs", NS_NewRDFLocalFileSystemDataSource,
#endif
nsnull, nsnull
};
nsresult rv;
for (DataSourceTable* entry = gTable; entry->mURI != nsnull; ++entry) {
if (NS_FAILED(rv = gRDFService->RegisterDataSourceConstructor(entry->mURI, entry->mDataSourceConstructor))) {
#ifdef DEBUG
printf("error registering built-in datasource constructor for %s\n", entry->mURI);
#endif
continue;
}
}
}
////////////////////////////////////////////////////////////////////////
nsresult
NS_NewRDFService(nsIRDFService** mgr)
{
return ServiceImpl::GetRDFService(mgr);
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,233 @@
/* -*- 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 bunch of useful RDF utility routines. Many of these will
eventually be exported outside of RDF.DLL via the nsIRDFService
interface.
*/
#ifndef rdfutil_h__
#define rdfutil_h__
#include "prtypes.h"
class nsIRDFCursor;
class nsIRDFDataBase;
class nsIRDFDataSource;
class nsIRDFNode;
class nsString;
/**
* Returns PR_TRUE if the URI is an RDF ordinal property; e.g., rdf:_1,
* rdf:_2, etc.
*/
PR_EXTERN(PRBool)
rdf_IsOrdinalProperty(const nsIRDFResource* property);
/**
* Converts an ordinal property to an index
*/
PR_EXTERN(nsresult)
rdf_OrdinalResourceToIndex(nsIRDFResource* aOrdinal, PRInt32* aIndex);
/**
* Converts an index to an ordinal property
*/
PR_EXTERN(nsresult)
rdf_IndexToOrdinalResource(PRInt32 aIndex, nsIRDFResource** aOrdinal);
/**
* Returns PR_TRUE if the resource is a container resource; e.g., an
* rdf:Bag.
*/
PR_EXTERN(PRBool)
rdf_IsContainer(nsIRDFDataSource* db,
nsIRDFResource* resource);
PR_EXTERN(PRBool)
rdf_IsBag(nsIRDFDataSource* aDataSource,
nsIRDFResource* aResource);
PR_EXTERN(PRBool)
rdf_IsSeq(nsIRDFDataSource* aDataSource,
nsIRDFResource* aResource);
PR_EXTERN(PRBool)
rdf_IsAlt(nsIRDFDataSource* aDataSource,
nsIRDFResource* aResource);
/**
* Various utilities routines for making assertions in a data source
*/
// 0. node, node, node
PR_EXTERN(nsresult)
rdf_Assert(nsIRDFDataSource* ds,
nsIRDFResource* subject,
nsIRDFResource* predicate,
nsIRDFNode* object);
// 1. string, string, string
PR_EXTERN(nsresult)
rdf_Assert(nsIRDFDataSource* ds,
const nsString& subjectURI,
const nsString& predicateURI,
const nsString& objectURI);
// 2. node, node, string
PR_EXTERN(nsresult)
rdf_Assert(nsIRDFDataSource* ds,
nsIRDFResource* subject,
nsIRDFResource* predicate,
const nsString& objectURI);
// 3. node, string, string
PR_EXTERN(nsresult)
rdf_Assert(nsIRDFDataSource* ds,
nsIRDFResource* subject,
const nsString& predicateURI,
const nsString& objectURI);
// 4. node, string, node
PR_EXTERN(nsresult)
rdf_Assert(nsIRDFDataSource* ds,
nsIRDFResource* subject,
const nsString& predicateURI,
nsIRDFNode* object);
// 5. string, string, node
PR_EXTERN(nsresult)
rdf_Assert(nsIRDFDataSource* ds,
const nsString& subjectURI,
const nsString& predicateURI,
nsIRDFNode* object);
/**
* Construct a new, "anonymous" node; that is, a node with an internal
* resource URI.
*/
PR_EXTERN(nsresult)
rdf_CreateAnonymousResource(const nsString& aContextURI, nsIRDFResource** result);
/**
* Determine if a resource is an "anonymous" resource that we've constructed
* ourselves.
*/
PR_EXTERN(PRBool)
rdf_IsAnonymousResource(const nsString& aContextURI, nsIRDFResource* aResource);
/**
* Try to convert the absolute URL into a relative URL.
*/
PR_EXTERN(nsresult)
rdf_PossiblyMakeRelative(const nsString& aContextURI, nsString& aURI);
/**
* Create a bag resource.
*/
PR_EXTERN(nsresult)
rdf_MakeBag(nsIRDFDataSource* ds,
nsIRDFResource* resource);
/**
* Create a sequence resource.
*/
PR_EXTERN(nsresult)
rdf_MakeSeq(nsIRDFDataSource* ds,
nsIRDFResource* resource);
/**
* Create an alternation resource.
*/
PR_EXTERN(nsresult)
rdf_MakeAlt(nsIRDFDataSource* ds,
nsIRDFResource* resource);
/**
* Add an element to the end of container.
*/
PR_EXTERN(nsresult)
rdf_ContainerAppendElement(nsIRDFDataSource* ds,
nsIRDFResource* container,
nsIRDFNode* element);
/**
* Remove an element from a container
*/
PR_EXTERN(nsresult)
rdf_ContainerRemoveElement(nsIRDFDataSource* aDataSource,
nsIRDFResource* aContainer,
nsIRDFNode* aElement);
/**
* Insert an element into a container at the specified index.
*/
PR_EXTERN(nsresult)
rdf_ContainerInsertElementAt(nsIRDFDataSource* aDataSource,
nsIRDFResource* aContainer,
nsIRDFNode* aElement,
PRInt32 aIndex);
/**
* Determine the index of an element in a container.
*/
PR_EXTERN(nsresult)
rdf_ContainerIndexOf(nsIRDFDataSource* aDataSource,
nsIRDFResource* aContainer,
nsIRDFNode* aElement,
PRInt32* aIndex);
/**
* Create a cursor on a container that enumerates its contents in
* order
*/
PR_EXTERN(nsresult)
NS_NewContainerCursor(nsIRDFDataSource* ds,
nsIRDFResource* container,
nsIRDFAssertionCursor** cursor);
/**
* Create an empty nsIRDFCursor. This will *never* fail, and will *always*
* return the same object.
*/
PR_EXTERN(nsresult)
NS_NewEmptyRDFAssertionCursor(nsIRDFAssertionCursor** result);
PR_EXTERN(nsresult)
NS_NewEmptyRDFArcsInCursor(nsIRDFArcsInCursor** result);
PR_EXTERN(nsresult)
NS_NewEmptyRDFArcsOutCursor(nsIRDFArcsOutCursor** result);
// XXX need to move nsEmptyCursor stuff here.
#endif // rdfutil_h__

View File

@@ -0,0 +1 @@
nsRDFCID.h

View File

@@ -0,0 +1,69 @@
#!gmake
#
# 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.
DEPTH=../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
LIBRARY_NAME = rdf
CPPSRCS = \
nsRDFFactory.cpp \
$(NULL)
EXPORTS = \
nsRDFCID.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
MODULE = rdf
REQUIRES = dom js netlib rdf raptor xpcom
# XXX Note dependencies on implementation headers for factory functions
INCLUDES += -I$(srcdir)/../base/src \
-I$(srcdir)/../content/src \
-I$(srcdir)/../datasource/src \
$(NULL)
EXTRA_DSO_LDOPTS = \
-L$(DIST)/bin \
-L$(DIST)/lib \
-lrdfbase_s \
-lrdfcontent_s \
-lrdfdatasource_s \
$(NULL)
include $(topsrcdir)/config/rules.mk
install:: $(TARGETS)
$(INSTALL) $(srcdir)/../resources/Mail/joe@meer.net/inbox $(DIST)/bin/res/rdf/Mail/joe@meer.net
$(INSTALL) $(srcdir)/../resources/sidebar.xul $(DIST)/bin/res/rdf
$(INSTALL) $(srcdir)/../resources/sidebar.css $(DIST)/bin/res/rdf
$(INSTALL) $(srcdir)/../resources/bookmarks.html $(DIST)/bin/res/rdf
$(INSTALL) $(srcdir)/../resources/Mail/joe@meer.net/work $(DIST)/bin/res/rdf/Mail/joe@meer.net
$(INSTALL) $(srcdir)/../resources/Mail/joe@meer.net/other $(DIST)/bin/res/rdf/Mail/joe@meer.net
$(INSTALL) $(srcdir)/../resources/Mail/jane@aol.com/inbox $(DIST)/bin/res/rdf/Mail/jane@aol.com
$(INSTALL) $(srcdir)/../resources/Mail/jane@aol.com/hiking $(DIST)/bin/res/rdf/Mail/jane@aol.com
$(INSTALL) $(srcdir)/../resources/Mail/jane@aol.com/trash $(DIST)/bin/res/rdf/Mail/jane@aol.com

View File

@@ -0,0 +1,83 @@
#!gmake
#
# 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.
DEPTH=..\..
MODULE=rdf
MAKE_OBJ_TYPE=DLL
DLLNAME=rdf
DLL=.\$(OBJDIR)\$(DLLNAME).dll
EXPORTS=\
nsRDFCID.h \
$(NULL)
CPP_OBJS=\
.\$(OBJDIR)\nsRDFFactory.obj \
$(NULL)
# XXX linking in raptor is a heinous crime that will go away once we
# have a more DOM-based mechanism for constructing elements and
# hooking in to their changes.
LLIBS=\
$(DIST)\lib\rdfbase_s.lib \
$(DIST)\lib\rdfcontent_s.lib \
$(DIST)\lib\rdfdatasource_s.lib \
$(DIST)\lib\xpcom32.lib \
$(DIST)\lib\raptorbase.lib \
$(DIST)\lib\raptorgfxwin.lib \
$(DIST)\lib\netlib.lib \
$(DIST)\lib\libplc21.lib \
$(DIST)\lib\raptorhtml.lib \
$(DIST)\lib\jsdom.lib \
$(DIST)\lib\js3250.lib \
$(LIBNSPR)
MISCDEP=$(LLIBS)
# XXX Note dependencies on implementation dirs for factory methods.
LINCS= -I$(PUBLIC)\rdf \
-I$(PUBLIC)\xpcom \
-I$(PUBLIC)\netlib \
-I$(PUBLIC)\raptor \
-I$(PUBLIC)\js \
-I$(PUBLIC)\dom \
-I$(DEPTH)\rdf\base\src \
-I$(DEPTH)\rdf\content\src \
-I$(DEPTH)\rdf\datasource\src \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib
$(MAKE_INSTALL) ..\resources\Mail\joe@meer.net\inbox $(DIST)\bin\res\rdf\Mail\joe@meer.net
$(MAKE_INSTALL) ..\resources\sidebar.xul $(DIST)\bin\res\rdf
$(MAKE_INSTALL) ..\resources\sidebar.css $(DIST)\bin\res\rdf
$(MAKE_INSTALL) ..\resources\bookmarks.html $(DIST)\bin\res\rdf
$(MAKE_INSTALL) ..\resources\Mail\joe@meer.net\work $(DIST)\bin\res\rdf\Mail\joe@meer.net
$(MAKE_INSTALL) ..\resources\Mail\joe@meer.net\other $(DIST)\bin\res\rdf\Mail\joe@meer.net
$(MAKE_INSTALL) ..\resources\Mail\jane@aol.com\inbox $(DIST)\bin\res\rdf\Mail\jane@aol.com
$(MAKE_INSTALL) ..\resources\Mail\jane@aol.com\hiking $(DIST)\bin\res\rdf\Mail\jane@aol.com
$(MAKE_INSTALL) ..\resources\Mail\jane@aol.com\trash $(DIST)\bin\res\rdf\Mail\jane@aol.com

View File

@@ -0,0 +1,81 @@
/* -*- 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.
*/
/*
XPCOM Class IDs for RDF objects that can be constructed via the RDF
factory.
*/
#ifndef nsRDFCID_h__
#define nsRDFCID_h__
// {0F78DA56-8321-11d2-8EAC-00805F29F370}
#define NS_RDFNODE_CID \
{ 0xf78da56, 0x8321, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
// {BFD05264-834C-11d2-8EAC-00805F29F370}
#define NS_RDFSERVICE_CID \
{ 0xbfd05264, 0x834c, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
// {BFD0526D-834C-11d2-8EAC-00805F29F370}
#define NS_RDFINMEMORYDATASOURCE_CID \
{ 0xbfd0526d, 0x834c, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
// {E638D760-8687-11d2-B530-000000000000}
#define NS_RDFBOOKMARKDATASOURCE_CID \
{ 0xe638d760, 0x8687, 0x11d2, { 0xb5, 0x30, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
// {E638D761-8687-11d2-B530-000000000000}
#define NS_RDFCOMPOSITEDATASOURCE_CID \
{ 0xe638d761, 0x8687, 0x11d2, { 0xb5, 0x30, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
// {954F0813-81DC-11d2-B52A-000000000000}
#define NS_RDFHTMLBUILDER_CID \
{ 0x954f0813, 0x81dc, 0x11d2, { 0xb5, 0x2a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
// {3D262D00-8B5A-11d2-8EB0-00805F29F370}
#define NS_RDFTREEBUILDER_CID \
{ 0x3d262d00, 0x8b5a, 0x11d2, { 0x8e, 0xb0, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
// {7BAF62E0-8E61-11d2-8EB1-00805F29F370}
#define NS_RDFXMLDATASOURCE_CID \
{ 0x7baf62e0, 0x8e61, 0x11d2, { 0x8e, 0xb1, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
// {6791B601-B9FE-11d2-BF86-00105A1B0627}
#define NS_XULDATASOURCE_CID \
{ 0x6791b601, 0xb9fe, 0x11d2, { 0xbf, 0x86, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }
// {0958B101-9ADA-11d2-8EBC-00805F29F370}
#define NS_RDFCONTENTSINK_CID \
{ 0x958b101, 0x9ada, 0x11d2, { 0x8e, 0xbc, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
// {E45313F0-B59C-11d2-A68C-00104BDE6048}
#define NS_RDFXULBUILDER_CID \
{ 0xe45313f0, 0xb59c, 0x11d2, { 0xa6, 0x8c, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } }
// {CE058B21-BA9C-11d2-BF86-00105A1B0627}
#define NS_XULCONTENTSINK_CID \
{ 0xce058b21, 0xba9c, 0x11d2, { 0xbf, 0x86, 0x0, 0x10, 0x5a, 0x1b, 0x6, 0x27 } }
// {541AFCB2-A9A3-11d2-8EC5-00805F29F370}
#define NS_XULDOCUMENT_CID \
{ 0x541afcb2, 0xa9a3, 0x11d2, { 0x8e, 0xc5, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
#endif // nsRDFCID_h__

View File

@@ -0,0 +1,263 @@
/* -*- 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.
*/
/*
The RDF factory implementation.
*/
#include "nsIFactory.h"
#include "nsIRDFCompositeDataSource.h"
#include "nsIRDFContentModelBuilder.h"
#include "nsIRDFContentSink.h"
#include "nsIRDFDocument.h"
#include "nsIRDFService.h"
#include "nsIRDFXMLDataSource.h"
#include "nsIXULContentSink.h"
#include "nsISupports.h"
#include "nsRDFBaseDataSources.h"
#include "nsRDFBuiltInDataSources.h"
#include "nsRDFCID.h"
#include "nsRepository.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_CID(kRDFBookmarkDataSourceCID, NS_RDFBOOKMARKDATASOURCE_CID);
static NS_DEFINE_CID(kRDFCompositeDataSourceCID, NS_RDFCOMPOSITEDATASOURCE_CID);
static NS_DEFINE_CID(kRDFContentSinkCID, NS_RDFCONTENTSINK_CID);
static NS_DEFINE_CID(kRDFHTMLBuilderCID, NS_RDFHTMLBUILDER_CID);
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kRDFTreeBuilderCID, NS_RDFTREEBUILDER_CID);
static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID);
static NS_DEFINE_CID(kRDFXULBuilderCID, NS_RDFXULBUILDER_CID);
static NS_DEFINE_CID(kXULContentSinkCID, NS_XULCONTENTSINK_CID);
static NS_DEFINE_CID(kXULDataSourceCID, NS_XULDATASOURCE_CID);
static NS_DEFINE_CID(kXULDocumentCID, NS_XULDOCUMENT_CID);
class RDFFactoryImpl : public nsIFactory
{
public:
RDFFactoryImpl(const nsCID &aClass);
// nsISupports methods
NS_DECL_ISUPPORTS
// nsIFactory methods
NS_IMETHOD CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
protected:
virtual ~RDFFactoryImpl();
private:
nsCID mClassID;
};
////////////////////////////////////////////////////////////////////////
RDFFactoryImpl::RDFFactoryImpl(const nsCID &aClass)
{
NS_INIT_REFCNT();
mClassID = aClass;
}
RDFFactoryImpl::~RDFFactoryImpl()
{
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
}
NS_IMETHODIMP
RDFFactoryImpl::QueryInterface(const nsIID &aIID,
void **aResult)
{
if (! aResult)
return NS_ERROR_NULL_POINTER;
// Always NULL result, in case of failure
*aResult = nsnull;
if (aIID.Equals(kISupportsIID)) {
*aResult = NS_STATIC_CAST(nsISupports*, this);
AddRef();
return NS_OK;
} else if (aIID.Equals(kIFactoryIID)) {
*aResult = NS_STATIC_CAST(nsIFactory*, this);
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(RDFFactoryImpl);
NS_IMPL_RELEASE(RDFFactoryImpl);
NS_IMETHODIMP
RDFFactoryImpl::CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult)
{
if (! aResult)
return NS_ERROR_NULL_POINTER;
if (aOuter)
return NS_ERROR_NO_AGGREGATION;
*aResult = nsnull;
nsresult rv;
PRBool wasRefCounted = PR_TRUE;
nsISupports *inst = nsnull;
if (mClassID.Equals(kRDFServiceCID)) {
if (NS_FAILED(rv = NS_NewRDFService((nsIRDFService**) &inst)))
return rv;
}
else if (mClassID.Equals(kRDFInMemoryDataSourceCID)) {
if (NS_FAILED(rv = NS_NewRDFInMemoryDataSource((nsIRDFDataSource**) &inst)))
return rv;
}
else if (mClassID.Equals(kRDFXMLDataSourceCID)) {
if (NS_FAILED(rv = NS_NewRDFXMLDataSource((nsIRDFXMLDataSource**) &inst)))
return rv;
}
else if (mClassID.Equals(kRDFBookmarkDataSourceCID)) {
if (NS_FAILED(rv = NS_NewRDFBookmarkDataSource((nsIRDFDataSource**) &inst)))
return rv;
}
else if (mClassID.Equals(kRDFCompositeDataSourceCID)) {
if (NS_FAILED(rv = NS_NewRDFCompositeDataSource((nsIRDFCompositeDataSource**) &inst)))
return rv;
}
else if (mClassID.Equals(kXULDocumentCID)) {
if (NS_FAILED(rv = NS_NewXULDocument((nsIRDFDocument**) &inst)))
return rv;
}
else if (mClassID.Equals(kRDFHTMLBuilderCID)) {
if (NS_FAILED(rv = NS_NewRDFHTMLBuilder((nsIRDFContentModelBuilder**) &inst)))
return rv;
}
else if (mClassID.Equals(kRDFTreeBuilderCID)) {
if (NS_FAILED(rv = NS_NewRDFTreeBuilder((nsIRDFContentModelBuilder**) &inst)))
return rv;
}
else if (mClassID.Equals(kRDFXULBuilderCID)) {
if (NS_FAILED(rv = NS_NewRDFXULBuilder((nsIRDFContentModelBuilder**) &inst)))
return rv;
}
else if (mClassID.Equals(kRDFContentSinkCID)) {
if (NS_FAILED(rv = NS_NewRDFContentSink((nsIRDFContentSink**) &inst)))
return rv;
}
else if (mClassID.Equals(kXULDataSourceCID)) {
if (NS_FAILED(rv = NS_NewXULDataSource((nsIRDFXMLDataSource**) &inst)))
return rv;
}
else if (mClassID.Equals(kXULContentSinkCID)) {
if (NS_FAILED(rv = NS_NewXULContentSink((nsIXULContentSink**) &inst)))
return rv;
}
else {
return NS_ERROR_NO_INTERFACE;
}
if (! inst)
return NS_ERROR_OUT_OF_MEMORY;
if (NS_FAILED(rv = inst->QueryInterface(aIID, aResult)))
// We didn't get the right interface, so clean up
delete inst;
if (wasRefCounted)
NS_IF_RELEASE(inst);
return rv;
}
nsresult RDFFactoryImpl::LockFactory(PRBool aLock)
{
// Not implemented in simplest case.
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// return the proper factory to the caller
extern "C" PR_IMPLEMENT(nsresult)
NSGetFactory(const nsCID &aClass, nsISupports* aServiceManager, nsIFactory **aFactory)
{
if (! aFactory)
return NS_ERROR_NULL_POINTER;
RDFFactoryImpl* factory = new RDFFactoryImpl(aClass);
if (factory == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(factory);
*aFactory = factory;
return NS_OK;
}
extern "C" PR_IMPLEMENT(nsresult)
NSRegisterSelf(const char* aPath)
{
nsRepository::RegisterFactory(kRDFBookmarkDataSourceCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kRDFCompositeDataSourceCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kRDFContentSinkCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kRDFHTMLBuilderCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kRDFInMemoryDataSourceCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kRDFServiceCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kRDFTreeBuilderCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kRDFXMLDataSourceCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kRDFXULBuilderCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kXULContentSinkCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kXULDataSourceCID, aPath, PR_TRUE, PR_TRUE);
nsRepository::RegisterFactory(kXULDocumentCID, aPath, PR_TRUE, PR_TRUE);
return NS_OK;
}
extern "C" PR_IMPLEMENT(nsresult)
NSUnregisterSelf(const char* aPath)
{
nsRepository::UnregisterFactory(kRDFBookmarkDataSourceCID, aPath);
nsRepository::UnregisterFactory(kRDFCompositeDataSourceCID, aPath);
nsRepository::UnregisterFactory(kRDFContentSinkCID, aPath);
nsRepository::UnregisterFactory(kRDFHTMLBuilderCID, aPath);
nsRepository::UnregisterFactory(kRDFInMemoryDataSourceCID, aPath);
nsRepository::UnregisterFactory(kRDFServiceCID, aPath);
nsRepository::UnregisterFactory(kRDFTreeBuilderCID, aPath);
nsRepository::UnregisterFactory(kRDFXMLDataSourceCID, aPath);
nsRepository::UnregisterFactory(kRDFXULBuilderCID, aPath);
nsRepository::UnregisterFactory(kXULContentSinkCID, aPath);
nsRepository::UnregisterFactory(kXULDataSourceCID, aPath);
nsRepository::UnregisterFactory(kXULDocumentCID, aPath);
return NS_OK;
}

View File

@@ -0,0 +1,29 @@
#!gmake
#
# 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.
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = public src
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,27 @@
#!gmake
#
# 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.
DEPTH=..\..
MODULE = rdf
DIRS=\
public \
src \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,5 @@
nsIDOMNodeObserver.h
nsIDOMXULNode.h
nsIRDFContent.h
nsIRDFContentModelBuilder.h
nsIRDFDocument.h

View File

@@ -0,0 +1,39 @@
#!gmake
#
# 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.
DEPTH=../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = rdf
EXPORTS = \
nsIDOMNodeObserver.h \
nsIDOMXULNode.h \
nsIRDFContent.h \
nsIRDFContentModelBuilder.h \
nsIRDFDocument.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,10 @@
interface NodeObserver {
/* IID: { 0x3e969070, 0xc301, 0x11d2, \
{ 0xa6, 0xae, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } } */
void onSetNodeValue(in Node node, in DOMString value);
void onInsertBefore(in Node parent, in Node newChild, in Node refChild);
void onReplaceChild(in Node parent, in Node newChild, in Node oldChild);
void onRemoveChild(in Node parent, in Node oldChild);
void onAppendChild(in Node parent, in Node newChild);
};

View File

@@ -0,0 +1,9 @@
interface XULNode {
/* IID: { 0x574ed81, 0xc088, 0x11d2, \
{ 0x96, 0xed, 0x0, 0x10, 0x4b, 0x7b, 0x7d, 0xeb } } */
void addBroadcastListener(in DOMString attr, in Node node);
void removeBroadcastListener(in DOMString attr, in Node node);
void doCommand();
};

View File

@@ -0,0 +1,53 @@
#!nmake
#
# 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.
DEPTH=..\..\..\..
IGNORE_MANIFEST=1
MODULE=rdf
IDLSRCS = \
NodeObserver.idl \
XULNode.idl \
$(NULL)
XPCOM_DESTDIR=$(DEPTH)\rdf\content\public
JSSTUB_DESTDIR=$(DEPTH)\rdf\content\src
GENXDIR=genx
GENJSDIR=genjs
!include <$(DEPTH)\config\rules.mak>
$(GENXDIR):
-mkdir $(GENXDIR)
$(GENJSDIR):
-mkdir $(GENJSDIR)
IDLC=$(DIST)\bin\idlc.exe
GENIID=$(DIST)\bin\geniid.pl
export:: $(GENXDIR) $(GENJSDIR) $(IDLSRCS)
@echo +++ make: generating xpcom headers
$(IDLC) -d $(GENXDIR) -x $(IDLSRCS)
@echo +++ make: generating JavaScript stubs
$(IDLC) -d $(GENJSDIR) -j $(IDLSRCS)
install::
$(MAKE_INSTALL:/=\) $(GENXDIR)\nsIDOM*.h $(XPCOM_DESTDIR)
$(MAKE_INSTALL:/=\) $(GENJSDIR)\nsJS*.cpp $(JSSTUB_DESTDIR)

View File

@@ -0,0 +1,32 @@
#!gmake
#
# 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.
MODULE=rdf
DEPTH=..\..\..
EXPORTS = \
nsIDOMNodeObserver.h \
nsIDOMXULNode.h \
nsIRDFContent.h \
nsIRDFContentModelBuilder.h \
nsIRDFDocument.h \
$(NULL)
include <$(DEPTH)/config/rules.mak>

View File

@@ -0,0 +1,70 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMNodeObserver_h__
#define nsIDOMNodeObserver_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
class nsIDOMNode;
#define NS_IDOMNODEOBSERVER_IID \
{ 0x3e969070, 0xc301, 0x11d2, \
{ 0xa6, 0xae, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } }
class nsIDOMNodeObserver : public nsISupports {
public:
static const nsIID& IID() { static nsIID iid = NS_IDOMNODEOBSERVER_IID; return iid; }
NS_IMETHOD OnSetNodeValue(nsIDOMNode* aNode, const nsString& aValue)=0;
NS_IMETHOD OnInsertBefore(nsIDOMNode* aParent, nsIDOMNode* aNewChild, nsIDOMNode* aRefChild)=0;
NS_IMETHOD OnReplaceChild(nsIDOMNode* aParent, nsIDOMNode* aNewChild, nsIDOMNode* aOldChild)=0;
NS_IMETHOD OnRemoveChild(nsIDOMNode* aParent, nsIDOMNode* aOldChild)=0;
NS_IMETHOD OnAppendChild(nsIDOMNode* aParent, nsIDOMNode* aNewChild)=0;
};
#define NS_DECL_IDOMNODEOBSERVER \
NS_IMETHOD OnSetNodeValue(nsIDOMNode* aNode, const nsString& aValue); \
NS_IMETHOD OnInsertBefore(nsIDOMNode* aParent, nsIDOMNode* aNewChild, nsIDOMNode* aRefChild); \
NS_IMETHOD OnReplaceChild(nsIDOMNode* aParent, nsIDOMNode* aNewChild, nsIDOMNode* aOldChild); \
NS_IMETHOD OnRemoveChild(nsIDOMNode* aParent, nsIDOMNode* aOldChild); \
NS_IMETHOD OnAppendChild(nsIDOMNode* aParent, nsIDOMNode* aNewChild); \
#define NS_FORWARD_IDOMNODEOBSERVER(_to) \
NS_IMETHOD OnSetNodeValue(nsIDOMNode* aNode, const nsString& aValue) { return _to##OnSetNodeValue(aNode, aValue); } \
NS_IMETHOD OnInsertBefore(nsIDOMNode* aParent, nsIDOMNode* aNewChild, nsIDOMNode* aRefChild) { return _to##OnInsertBefore(aParent, aNewChild, aRefChild); } \
NS_IMETHOD OnReplaceChild(nsIDOMNode* aParent, nsIDOMNode* aNewChild, nsIDOMNode* aOldChild) { return _to##OnReplaceChild(aParent, aNewChild, aOldChild); } \
NS_IMETHOD OnRemoveChild(nsIDOMNode* aParent, nsIDOMNode* aOldChild) { return _to##OnRemoveChild(aParent, aOldChild); } \
NS_IMETHOD OnAppendChild(nsIDOMNode* aParent, nsIDOMNode* aNewChild) { return _to##OnAppendChild(aParent, aNewChild); } \
extern nsresult NS_InitNodeObserverClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM nsresult NS_NewScriptNodeObserver(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMNodeObserver_h__

View File

@@ -0,0 +1,62 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMXULNode_h__
#define nsIDOMXULNode_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
class nsIDOMNode;
#define NS_IDOMXULNODE_IID \
{ 0x574ed81, 0xc088, 0x11d2, \
{ 0x96, 0xed, 0x0, 0x10, 0x4b, 0x7b, 0x7d, 0xeb } }
class nsIDOMXULNode : public nsISupports {
public:
static const nsIID& IID() { static nsIID iid = NS_IDOMXULNODE_IID; return iid; }
NS_IMETHOD AddBroadcastListener(const nsString& aAttr, nsIDOMNode* aNode)=0;
NS_IMETHOD RemoveBroadcastListener(const nsString& aAttr, nsIDOMNode* aNode)=0;
NS_IMETHOD DoCommand()=0;
};
#define NS_DECL_IDOMXULNODE \
NS_IMETHOD AddBroadcastListener(const nsString& aAttr, nsIDOMNode* aNode); \
NS_IMETHOD RemoveBroadcastListener(const nsString& aAttr, nsIDOMNode* aNode); \
NS_IMETHOD DoCommand(); \
#define NS_FORWARD_IDOMXULNODE(_to) \
NS_IMETHOD AddBroadcastListener(const nsString& aAttr, nsIDOMNode* aNode) { return _to##AddBroadcastListener(aAttr, aNode); } \
NS_IMETHOD RemoveBroadcastListener(const nsString& aAttr, nsIDOMNode* aNode) { return _to##RemoveBroadcastListener(aAttr, aNode); } \
NS_IMETHOD DoCommand() { return _to##DoCommand(); } \
extern nsresult NS_InitXULNodeClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM nsresult NS_NewScriptXULNode(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMXULNode_h__

View File

@@ -0,0 +1,69 @@
/* -*- 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.
*/
/*
An interface for RDF content model elements.
*/
#ifndef nsIRDFContent_h___
#define nsIRDFContent_h___
#include "nsISupports.h"
#include "nsIXMLContent.h"
class nsIRDFResource;
// {954F0810-81DC-11d2-B52A-000000000000}
#define NS_IRDFCONTENT_IID \
{ 0x954f0810, 0x81dc, 0x11d2, { 0xb5, 0x2a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
/**
* RDF content extensions to nsIContent
*/
class nsIRDFContent : public nsIContent {
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFCONTENT_IID; return iid; }
/**
* Return the RDF resource on which this RDF content element was based.
*/
NS_IMETHOD GetResource(nsIRDFResource*& aResource) const = 0;
/**
* Mark a an element as a "container element" so that its contents
* will be generated on-demand.
*/
NS_IMETHOD SetContainer(PRBool aIsContainer) = 0;
};
nsresult
NS_NewRDFResourceElement(nsIRDFContent** aResult,
nsIRDFResource* aResource,
PRInt32 aNameSpaceID,
nsIAtom* aTag);
nsresult
NS_NewRDFGenericElement(nsIContent** aResult,
PRInt32 aNameSpaceID,
nsIAtom* aTag);
#endif // nsIRDFContent_h___

View File

@@ -0,0 +1,76 @@
/* -*- 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 model builder interface. An object that implements this
interface is associated with an nsIRDFDocument object to construct
an NGLayout content model.
*/
#ifndef nsIRDFContentModelBuilder_h__
#define nsIRDFContentModelBuilder_h__
#include "nsISupports.h"
class nsIContent;
class nsIRDFCompositeDataSource;
class nsIRDFContent; // XXX get rid of these...
class nsIRDFDocument;
class nsIRDFNode;
class nsIRDFResource;
// {541AFCB0-A9A3-11d2-8EC5-00805F29F370}
#define NS_IRDFCONTENTMODELBUILDER_IID \
{ 0x541afcb0, 0xa9a3, 0x11d2, { 0x8e, 0xc5, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
class nsIRDFContentModelBuilder : public nsISupports
{
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFCONTENTMODELBUILDER_IID; return iid; }
/**
* Point the content model builder to the document. The content model
* builder must not reference count the document.
*/
NS_IMETHOD SetDocument(nsIRDFDocument* aDocument) = 0;
NS_IMETHOD SetDataBase(nsIRDFCompositeDataSource* aDataBase) = 0;
NS_IMETHOD GetDataBase(nsIRDFCompositeDataSource** aDataBase) = 0;
/**
* Set the root element from which this content model will
* operate.
*/
NS_IMETHOD CreateRootContent(nsIRDFResource* aResource) = 0;
NS_IMETHOD SetRootContent(nsIContent* aElement) = 0;
/**
* Construct the contents for a container element.
*/
NS_IMETHOD CreateContents(nsIContent* aElement) = 0;
};
extern nsresult NS_NewRDFHTMLBuilder(nsIRDFContentModelBuilder** aResult);
extern nsresult NS_NewRDFTreeBuilder(nsIRDFContentModelBuilder** aResult);
extern nsresult NS_NewRDFXULBuilder(nsIRDFContentModelBuilder** aResult);
#endif // nsIRDFContentModelBuilder_h__

View File

@@ -0,0 +1,81 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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.
*/
/*
An RDF-specific extension to nsIXMLDocument. Includes methods for
setting the root resource of the document content model, a factory
method for constructing the children of a node, etc.
*/
#ifndef nsIRDFDocument_h___
#define nsIRDFDocument_h___
class nsIContent; // XXX nsIXMLDocument.h is bad and doesn't declare this class...
#include "nsIXMLDocument.h"
class nsIAtom;
class nsIRDFCompositeDataSource;
class nsIRDFContent;
class nsIRDFContentModelBuilder;
class nsISupportsArray;
class nsIRDFResource;
// {954F0811-81DC-11d2-B52A-000000000000}
#define NS_IRDFDOCUMENT_IID \
{ 0x954f0811, 0x81dc, 0x11d2, { 0xb5, 0x2a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
/**
* RDF document extensions to nsIDocument
*/
class nsIRDFDocument : public nsIXMLDocument
{
public:
static const nsIID& IID() { static nsIID iid = NS_IRDFDOCUMENT_IID; return iid; }
/**
* Set the document's "root" resource.
*/
NS_IMETHOD SetRootResource(nsIRDFResource* aResource) = 0;
// XXX the following two methods should probably accept strings as
// parameters so you can mess with them via JS. Also, should they
// take a "notify" parameter that would control whether any viewers
// of the content model should be informed that the content model is
// invalid?
NS_IMETHOD SplitProperty(nsIRDFResource* aResource, PRInt32* aNameSpaceID, nsIAtom** aTag) = 0;
NS_IMETHOD AddElementForResource(nsIRDFResource* aResource, nsIRDFContent* aElement) = 0;
NS_IMETHOD RemoveElementForResource(nsIRDFResource* aResource, nsIRDFContent* aElement) = 0;
NS_IMETHOD GetElementsForResource(nsIRDFResource* aResource, nsISupportsArray* aElements) = 0;
NS_IMETHOD CreateContents(nsIRDFContent* aElement) = 0;
NS_IMETHOD AddContentModelBuilder(nsIRDFContentModelBuilder* aBuilder) = 0;
};
// factory functions
nsresult NS_NewXULDocument(nsIRDFDocument** result);
#endif // nsIRDFDocument_h___

View File

@@ -0,0 +1,65 @@
#!gmake
#
# 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.
DEPTH=../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
LIBRARY_NAME = rdfcontent_s
CPPSRCS = \
nsRDFContentUtils.cpp \
nsRDFDOMNodeList.cpp \
nsRDFGenericElement.cpp \
nsRDFHTMLBuilder.cpp \
nsRDFResourceElement.cpp \
nsRDFTreeBuilder.cpp \
nsRDFXULBuilder.cpp \
nsXULDocument.cpp \
nsJSXULNode.cpp \
$(NULL)
EXPORTS = \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
MODULE = rdf
REQUIRES = dom js netlib rdf raptor xpcom
# XXX This is a dependency on rdfutil.h: it'll go away once that becomes
# a first-class XPCOM interface.
INCLUDES += -I$(srcdir)/../../base/src
# XXX This is a dependency on Raptor for constructing HTML
# content. It'll go away once we move RDF content model construction
# outside the DOM APIs.
INCLUDES += -I$(srcdir)/../../../layout/html/base/src
MKSHLIB :=
# we don't want the shared lib
NO_SHARED_LIB=1
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,63 @@
#!gmake
#
# 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.
DEPTH=..\..\..
MODULE=rdf
LIBRARY_NAME=rdfcontent_s
DEFINES=-D_IMPL_NS_DOM
LCFLAGS = \
$(LCFLAGS) \
$(DEFINES) \
$(NULL)
CPP_OBJS=\
.\$(OBJDIR)\nsJSXULNode.obj \
.\$(OBJDIR)\nsRDFContentUtils.obj \
.\$(OBJDIR)\nsRDFDOMNodeList.obj \
.\$(OBJDIR)\nsRDFGenericElement.obj \
.\$(OBJDIR)\nsRDFHTMLBuilder.obj \
.\$(OBJDIR)\nsRDFResourceElement.obj \
.\$(OBJDIR)\nsRDFTreeBuilder.obj \
.\$(OBJDIR)\nsRDFXULBuilder.obj \
.\$(OBJDIR)\nsXULDocument.obj \
$(NULL)
# XXX we are including layout\html\base\src to get HTML elements
# constructed directly from Raptor. The hope is that this'll
# eventually be replaced by a DOM-based mechanism.
LINCS= -I$(PUBLIC)\rdf \
-I$(PUBLIC)\xpcom \
-I$(PUBLIC)\netlib \
-I$(PUBLIC)\raptor \
-I$(PUBLIC)\js \
-I$(PUBLIC)\dom \
-I$(DEPTH)\rdf\base\src \
-I$(DEPTH)\layout\html\base\src \
$(NULL)
include <$(DEPTH)\config\rules.mak>
libs:: $(LIBRARY)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
clobber::
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib

View File

@@ -0,0 +1,53 @@
/* -*- 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 helper class used to implement attributes.
*/
#ifndef nsGenericAttribute_h__
#define nsGenericAttribute_h__
class nsGenericAttribute
{
public:
nsGenericAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, const nsString& aValue)
: mNameSpaceID(aNameSpaceID),
mName(aName),
mValue(aValue)
{
NS_IF_ADDREF(mName);
}
~nsGenericAttribute(void)
{
NS_IF_RELEASE(mName);
}
PRInt32 mNameSpaceID;
nsIAtom* mName;
nsString mValue;
};
#endif // nsGenericAttribute_h__

View File

@@ -0,0 +1,543 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#include "jsapi.h"
#include "nsJSUtils.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsIJSScriptObject.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIDOMNode.h"
#include "nsIDOMNodeObserver.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kINodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kINodeObserverIID, NS_IDOMNODEOBSERVER_IID);
NS_DEF_PTR(nsIDOMNode);
NS_DEF_PTR(nsIDOMNodeObserver);
/***********************************************************************/
//
// NodeObserver Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetNodeObserverProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMNodeObserver *a = (nsIDOMNodeObserver*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
default:
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
/***********************************************************************/
//
// NodeObserver Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetNodeObserverProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMNodeObserver *a = (nsIDOMNodeObserver*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
default:
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
//
// NodeObserver finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeNodeObserver(JSContext *cx, JSObject *obj)
{
nsJSUtils::nsGenericFinalize(cx, obj);
}
//
// NodeObserver enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateNodeObserver(JSContext *cx, JSObject *obj)
{
return nsJSUtils::nsGenericEnumerate(cx, obj);
}
//
// NodeObserver resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveNodeObserver(JSContext *cx, JSObject *obj, jsval id)
{
return nsJSUtils::nsGenericResolve(cx, obj, id);
}
//
// Native method OnSetNodeValue
//
PR_STATIC_CALLBACK(JSBool)
NodeObserverOnSetNodeValue(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMNodeObserver *nativeThis = (nsIDOMNodeObserver*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNodePtr b0;
nsAutoString b1;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 2) {
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b0,
kINodeIID,
"Node",
cx,
argv[0])) {
return JS_FALSE;
}
nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]);
if (NS_OK != nativeThis->OnSetNodeValue(b0, b1)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function onSetNodeValue requires 2 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method OnInsertBefore
//
PR_STATIC_CALLBACK(JSBool)
NodeObserverOnInsertBefore(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMNodeObserver *nativeThis = (nsIDOMNodeObserver*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNodePtr b0;
nsIDOMNodePtr b1;
nsIDOMNodePtr b2;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 3) {
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b0,
kINodeIID,
"Node",
cx,
argv[0])) {
return JS_FALSE;
}
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b1,
kINodeIID,
"Node",
cx,
argv[1])) {
return JS_FALSE;
}
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b2,
kINodeIID,
"Node",
cx,
argv[2])) {
return JS_FALSE;
}
if (NS_OK != nativeThis->OnInsertBefore(b0, b1, b2)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function onInsertBefore requires 3 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method OnReplaceChild
//
PR_STATIC_CALLBACK(JSBool)
NodeObserverOnReplaceChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMNodeObserver *nativeThis = (nsIDOMNodeObserver*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNodePtr b0;
nsIDOMNodePtr b1;
nsIDOMNodePtr b2;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 3) {
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b0,
kINodeIID,
"Node",
cx,
argv[0])) {
return JS_FALSE;
}
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b1,
kINodeIID,
"Node",
cx,
argv[1])) {
return JS_FALSE;
}
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b2,
kINodeIID,
"Node",
cx,
argv[2])) {
return JS_FALSE;
}
if (NS_OK != nativeThis->OnReplaceChild(b0, b1, b2)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function onReplaceChild requires 3 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method OnRemoveChild
//
PR_STATIC_CALLBACK(JSBool)
NodeObserverOnRemoveChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMNodeObserver *nativeThis = (nsIDOMNodeObserver*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNodePtr b0;
nsIDOMNodePtr b1;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 2) {
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b0,
kINodeIID,
"Node",
cx,
argv[0])) {
return JS_FALSE;
}
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b1,
kINodeIID,
"Node",
cx,
argv[1])) {
return JS_FALSE;
}
if (NS_OK != nativeThis->OnRemoveChild(b0, b1)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function onRemoveChild requires 2 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method OnAppendChild
//
PR_STATIC_CALLBACK(JSBool)
NodeObserverOnAppendChild(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMNodeObserver *nativeThis = (nsIDOMNodeObserver*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsIDOMNodePtr b0;
nsIDOMNodePtr b1;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 2) {
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b0,
kINodeIID,
"Node",
cx,
argv[0])) {
return JS_FALSE;
}
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b1,
kINodeIID,
"Node",
cx,
argv[1])) {
return JS_FALSE;
}
if (NS_OK != nativeThis->OnAppendChild(b0, b1)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function onAppendChild requires 2 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for NodeObserver
//
JSClass NodeObserverClass = {
"NodeObserver",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
GetNodeObserverProperty,
SetNodeObserverProperty,
EnumerateNodeObserver,
ResolveNodeObserver,
JS_ConvertStub,
FinalizeNodeObserver
};
//
// NodeObserver class properties
//
static JSPropertySpec NodeObserverProperties[] =
{
{0}
};
//
// NodeObserver class methods
//
static JSFunctionSpec NodeObserverMethods[] =
{
{"onSetNodeValue", NodeObserverOnSetNodeValue, 2},
{"onInsertBefore", NodeObserverOnInsertBefore, 3},
{"onReplaceChild", NodeObserverOnReplaceChild, 3},
{"onRemoveChild", NodeObserverOnRemoveChild, 2},
{"onAppendChild", NodeObserverOnAppendChild, 2},
{0}
};
//
// NodeObserver constructor
//
PR_STATIC_CALLBACK(JSBool)
NodeObserver(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_FALSE;
}
//
// NodeObserver class initialization
//
nsresult NS_InitNodeObserverClass(nsIScriptContext *aContext, void **aPrototype)
{
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *proto = nsnull;
JSObject *constructor = nsnull;
JSObject *parent_proto = nsnull;
JSObject *global = JS_GetGlobalObject(jscontext);
jsval vp;
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "NodeObserver", &vp)) ||
!JSVAL_IS_OBJECT(vp) ||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
!JSVAL_IS_OBJECT(vp)) {
proto = JS_InitClass(jscontext, // context
global, // global object
parent_proto, // parent proto
&NodeObserverClass, // JSClass
NodeObserver, // JSNative ctor
0, // ctor args
NodeObserverProperties, // proto props
NodeObserverMethods, // proto funcs
nsnull, // ctor props (static)
nsnull); // ctor funcs (static)
if (nsnull == proto) {
return NS_ERROR_FAILURE;
}
}
else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) {
proto = JSVAL_TO_OBJECT(vp);
}
else {
return NS_ERROR_FAILURE;
}
if (aPrototype) {
*aPrototype = proto;
}
return NS_OK;
}
//
// Method for creating a new NodeObserver JavaScript object
//
extern "C" NS_DOM nsresult NS_NewScriptNodeObserver(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptNodeObserver");
JSObject *proto;
JSObject *parent;
nsIScriptObjectOwner *owner;
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
nsresult result = NS_OK;
nsIDOMNodeObserver *aNodeObserver;
if (nsnull == aParent) {
parent = nsnull;
}
else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
NS_RELEASE(owner);
return NS_ERROR_FAILURE;
}
NS_RELEASE(owner);
}
else {
return NS_ERROR_FAILURE;
}
if (NS_OK != NS_InitNodeObserverClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
result = aSupports->QueryInterface(kINodeObserverIID, (void **)&aNodeObserver);
if (NS_OK != result) {
return result;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &NodeObserverClass, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aNodeObserver);
}
else {
NS_RELEASE(aNodeObserver);
return NS_ERROR_FAILURE;
}
return NS_OK;
}

View File

@@ -0,0 +1,397 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#include "jsapi.h"
#include "nsJSUtils.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsIJSScriptObject.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIDOMXULNode.h"
#include "nsIDOMNode.h"
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kIXULNodeIID, NS_IDOMXULNODE_IID);
static NS_DEFINE_IID(kINodeIID, NS_IDOMNODE_IID);
NS_DEF_PTR(nsIDOMXULNode);
NS_DEF_PTR(nsIDOMNode);
/***********************************************************************/
//
// XULNode Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetXULNodeProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMXULNode *a = (nsIDOMXULNode*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
default:
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
/***********************************************************************/
//
// XULNode Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetXULNodeProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMXULNode *a = (nsIDOMXULNode*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
default:
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
//
// XULNode finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeXULNode(JSContext *cx, JSObject *obj)
{
nsJSUtils::nsGenericFinalize(cx, obj);
}
//
// XULNode enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateXULNode(JSContext *cx, JSObject *obj)
{
return nsJSUtils::nsGenericEnumerate(cx, obj);
}
//
// XULNode resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveXULNode(JSContext *cx, JSObject *obj, jsval id)
{
return nsJSUtils::nsGenericResolve(cx, obj, id);
}
//
// Native method AddBroadcastListener
//
PR_STATIC_CALLBACK(JSBool)
XULNodeAddBroadcastListener(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMXULNode *nativeThis = (nsIDOMXULNode*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsAutoString b0;
nsIDOMNodePtr b1;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 2) {
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b1,
kINodeIID,
"Node",
cx,
argv[1])) {
return JS_FALSE;
}
if (NS_OK != nativeThis->AddBroadcastListener(b0, b1)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function addBroadcastListener requires 2 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method RemoveBroadcastListener
//
PR_STATIC_CALLBACK(JSBool)
XULNodeRemoveBroadcastListener(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMXULNode *nativeThis = (nsIDOMXULNode*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsAutoString b0;
nsIDOMNodePtr b1;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 2) {
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b1,
kINodeIID,
"Node",
cx,
argv[1])) {
return JS_FALSE;
}
if (NS_OK != nativeThis->RemoveBroadcastListener(b0, b1)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function removeBroadcastListener requires 2 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method DoCommand
//
PR_STATIC_CALLBACK(JSBool)
XULNodeDoCommand(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMXULNode *nativeThis = (nsIDOMXULNode*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->DoCommand()) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function doCommand requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for XULNode
//
JSClass XULNodeClass = {
"XULNode",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
GetXULNodeProperty,
SetXULNodeProperty,
EnumerateXULNode,
ResolveXULNode,
JS_ConvertStub,
FinalizeXULNode
};
//
// XULNode class properties
//
static JSPropertySpec XULNodeProperties[] =
{
{0}
};
//
// XULNode class methods
//
static JSFunctionSpec XULNodeMethods[] =
{
{"addBroadcastListener", XULNodeAddBroadcastListener, 2},
{"removeBroadcastListener", XULNodeRemoveBroadcastListener, 2},
{"doCommand", XULNodeDoCommand, 0},
{0}
};
//
// XULNode constructor
//
PR_STATIC_CALLBACK(JSBool)
XULNode(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_FALSE;
}
//
// XULNode class initialization
//
nsresult NS_InitXULNodeClass(nsIScriptContext *aContext, void **aPrototype)
{
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *proto = nsnull;
JSObject *constructor = nsnull;
JSObject *parent_proto = nsnull;
JSObject *global = JS_GetGlobalObject(jscontext);
jsval vp;
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "XULNode", &vp)) ||
!JSVAL_IS_OBJECT(vp) ||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
!JSVAL_IS_OBJECT(vp)) {
proto = JS_InitClass(jscontext, // context
global, // global object
parent_proto, // parent proto
&XULNodeClass, // JSClass
XULNode, // JSNative ctor
0, // ctor args
XULNodeProperties, // proto props
XULNodeMethods, // proto funcs
nsnull, // ctor props (static)
nsnull); // ctor funcs (static)
if (nsnull == proto) {
return NS_ERROR_FAILURE;
}
}
else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) {
proto = JSVAL_TO_OBJECT(vp);
}
else {
return NS_ERROR_FAILURE;
}
if (aPrototype) {
*aPrototype = proto;
}
return NS_OK;
}
//
// Method for creating a new XULNode JavaScript object
//
extern "C" NS_DOM nsresult NS_NewScriptXULNode(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptXULNode");
JSObject *proto;
JSObject *parent;
nsIScriptObjectOwner *owner;
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
nsresult result = NS_OK;
nsIDOMXULNode *aXULNode;
if (nsnull == aParent) {
parent = nsnull;
}
else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
NS_RELEASE(owner);
return NS_ERROR_FAILURE;
}
NS_RELEASE(owner);
}
else {
return NS_ERROR_FAILURE;
}
if (NS_OK != NS_InitXULNodeClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
result = aSupports->QueryInterface(kIXULNodeIID, (void **)&aXULNode);
if (NS_OK != result) {
return result;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &XULNodeClass, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aXULNode);
}
else {
NS_RELEASE(aXULNode);
return NS_ERROR_FAILURE;
}
return NS_OK;
}

View File

@@ -0,0 +1,96 @@
/* -*- 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 package of routines shared by the RDF content code.
*/
#include "nsIContent.h"
#include "nsIRDFNode.h"
#include "nsITextContent.h"
#include "nsLayoutCID.h"
#include "nsRDFContentUtils.h"
#include "nsString.h"
static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID);
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
static NS_DEFINE_IID(kITextContentIID, NS_ITEXT_CONTENT_IID); // XXX grr...
static NS_DEFINE_CID(kTextNodeCID, NS_TEXTNODE_CID);
nsresult
nsRDFContentUtils::AttachTextNode(nsIContent* parent, nsIRDFNode* value)
{
nsresult rv;
nsAutoString s;
nsIContent* node = nsnull;
nsITextContent* text = nsnull;
nsIRDFResource* resource = nsnull;
nsIRDFLiteral* literal = nsnull;
if (NS_SUCCEEDED(rv = value->QueryInterface(kIRDFResourceIID, (void**) &resource))) {
const char* p;
if (NS_FAILED(rv = resource->GetValue(&p)))
goto error;
s = p;
}
else if (NS_SUCCEEDED(rv = value->QueryInterface(kIRDFLiteralIID, (void**) &literal))) {
const PRUnichar* p;
if (NS_FAILED(rv = literal->GetValue(&p)))
goto error;
s = p;
}
else {
PR_ASSERT(0);
goto error;
}
if (NS_FAILED(rv = nsRepository::CreateInstance(kTextNodeCID,
nsnull,
kIContentIID,
(void**) &node)))
goto error;
if (NS_FAILED(rv = node->QueryInterface(kITextContentIID, (void**) &text)))
goto error;
if (NS_FAILED(rv = text->SetText(s.GetUnicode(), s.Length(), PR_FALSE)))
goto error;
// hook it up to the child
if (NS_FAILED(rv = parent->AppendChildTo(NS_STATIC_CAST(nsIContent*, node), PR_TRUE)))
goto error;
error:
NS_IF_RELEASE(node);
NS_IF_RELEASE(text);
return rv;
}

View File

@@ -0,0 +1,47 @@
/* -*- 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 package of routines shared by the RDF content code.
*/
#ifndef nsRDFContentUtils_h__
#define nsRDFContentUtils_h__
#include "nsError.h"
class nsIContent;
class nsIDOMNodeList;
class nsIRDFNode;
class nsString;
class nsRDFContentUtils
{
public:
static nsresult
AttachTextNode(nsIContent* parent, nsIRDFNode* value);
};
#endif // nsRDFContentUtils_h__

View File

@@ -0,0 +1,305 @@
/* -*- 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.
*/
/*
Helper class to implement the nsIDOMNodeList interface.
XXX It's probably wrong in some sense, as it uses the "naked"
content interface to look for kids. (I assume in general this is
bad because there may be pseudo-elements created for presentation
that aren't visible to the DOM.)
*/
#include "nsDOMCID.h"
#include "nsIDOMNode.h"
#include "nsIDOMHTMLCollection.h"
#include "nsIDOMScriptObjectFactory.h"
#include "nsIScriptGlobalObject.h"
#include "nsIServiceManager.h"
#include "nsISupportsArray.h"
#include "nsRDFDOMNodeList.h"
////////////////////////////////////////////////////////////////////////
// GUID definitions
static NS_DEFINE_IID(kIDOMNodeIID, NS_IDOMNODE_IID);
static NS_DEFINE_IID(kIDOMNodeListIID, NS_IDOMNODELIST_IID);
static NS_DEFINE_IID(kIDOMScriptObjectFactoryIID, NS_IDOM_SCRIPT_OBJECT_FACTORY_IID);
static NS_DEFINE_CID(kDOMScriptObjectFactoryCID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID);
////////////////////////////////////////////////////////////////////////
//
class RDFHTMLCollectionImpl : public nsIDOMHTMLCollection
{
private:
nsRDFDOMNodeList* mOuter;
public:
RDFHTMLCollectionImpl(nsRDFDOMNodeList* aOuter);
virtual ~RDFHTMLCollectionImpl();
// nsISupports interface
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aResult);
// nsIDOMHTMLCollection interface
NS_DECL_IDOMHTMLCOLLECTION
};
RDFHTMLCollectionImpl::RDFHTMLCollectionImpl(nsRDFDOMNodeList* aOuter)
: mOuter(aOuter)
{
}
RDFHTMLCollectionImpl::~RDFHTMLCollectionImpl(void)
{
}
NS_IMETHODIMP_(nsrefcnt)
RDFHTMLCollectionImpl::AddRef(void)
{
return mOuter->AddRef();
}
NS_IMETHODIMP_(nsrefcnt)
RDFHTMLCollectionImpl::Release(void)
{
return mOuter->Release();
}
NS_IMETHODIMP
RDFHTMLCollectionImpl::QueryInterface(REFNSIID aIID, void** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
if (aIID.Equals(nsIDOMHTMLCollection::IID())) {
*aResult = NS_STATIC_CAST(nsIDOMHTMLCollection*, this);
NS_ADDREF(this);
return NS_OK;
}
else {
return mOuter->QueryInterface(aIID, aResult);
}
}
NS_IMETHODIMP
RDFHTMLCollectionImpl::GetLength(PRUint32* aLength)
{
return mOuter->GetLength(aLength);
}
NS_IMETHODIMP
RDFHTMLCollectionImpl::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
return mOuter->Item(aIndex, aReturn);
}
NS_IMETHODIMP
RDFHTMLCollectionImpl::NamedItem(const nsString& aName, nsIDOMNode** aReturn)
{
NS_NOTYETIMPLEMENTED("write me!");
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////
// ctors & dtors
nsRDFDOMNodeList::nsRDFDOMNodeList(void)
: mInner(nsnull),
mElements(nsnull),
mScriptObject(nsnull)
{
NS_INIT_REFCNT();
}
nsRDFDOMNodeList::~nsRDFDOMNodeList(void)
{
NS_IF_RELEASE(mElements);
delete mInner;
}
nsresult
nsRDFDOMNodeList::Create(nsRDFDOMNodeList** aResult)
{
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
nsRDFDOMNodeList* list = new nsRDFDOMNodeList();
if (! list)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv;
if (NS_FAILED(rv = list->Init())) {
delete list;
return rv;
}
NS_ADDREF(list);
*aResult = list;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// nsISupports interface
NS_IMPL_ADDREF(nsRDFDOMNodeList);
NS_IMPL_RELEASE(nsRDFDOMNodeList);
nsresult
nsRDFDOMNodeList::QueryInterface(REFNSIID aIID, void** aResult)
{
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
NS_PRECONDITION(aResult != nsnull, "null ptr");
if (! aResult)
return NS_ERROR_NULL_POINTER;
if (aIID.Equals(nsIDOMNodeList::IID()) ||
aIID.Equals(kISupportsIID)) {
*aResult = NS_STATIC_CAST(nsIDOMNodeList*, this);
NS_ADDREF(this);
return NS_OK;
}
else if (aIID.Equals(kIScriptObjectOwnerIID)) {
*aResult = NS_STATIC_CAST(nsIScriptObjectOwner*, this);
NS_ADDREF(this);
return NS_OK;
}
else if (aIID.Equals(nsIDOMHTMLCollection::IID())) {
// Aggregate this interface
if (! mInner) {
if (! (mInner = new RDFHTMLCollectionImpl(this)))
return NS_ERROR_OUT_OF_MEMORY;
}
return mInner->QueryInterface(aIID, aResult);
}
return NS_NOINTERFACE;
}
////////////////////////////////////////////////////////////////////////
// nsIDOMNodeList interface
NS_IMETHODIMP
nsRDFDOMNodeList::GetLength(PRUint32* aLength)
{
NS_ASSERTION(aLength != nsnull, "null ptr");
if (! aLength)
return NS_ERROR_NULL_POINTER;
*aLength = mElements->Count();
return NS_OK;
}
NS_IMETHODIMP
nsRDFDOMNodeList::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
{
NS_PRECONDITION(aReturn != nsnull, "null ptr");
if (! aReturn)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(aIndex < (PRUint32) mElements->Count(), "invalid arg");
if (aIndex >= (PRUint32) mElements->Count())
return NS_ERROR_INVALID_ARG;
// Cast is okay because we're in a closed system.
*aReturn = (nsIDOMNode*) mElements->ElementAt(aIndex);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// nsIScriptObjectOwner interface
NS_IMETHODIMP
nsRDFDOMNodeList::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
{
nsresult rv = NS_OK;
nsIScriptGlobalObject* global = aContext->GetGlobalObject();
if (nsnull == mScriptObject) {
nsIDOMScriptObjectFactory *factory;
if (NS_SUCCEEDED(rv = nsServiceManager::GetService(kDOMScriptObjectFactoryCID,
kIDOMScriptObjectFactoryIID,
(nsISupports **)&factory))) {
rv = factory->NewScriptHTMLCollection(aContext,
(nsISupports*)(nsIDOMNodeList*)this,
global,
(void**)&mScriptObject);
nsServiceManager::ReleaseService(kDOMScriptObjectFactoryCID, factory);
}
}
*aScriptObject = mScriptObject;
NS_RELEASE(global);
return rv;
}
NS_IMETHODIMP
nsRDFDOMNodeList::SetScriptObject(void* aScriptObject)
{
mScriptObject = aScriptObject;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// Implementation methods
nsresult
nsRDFDOMNodeList::Init(void)
{
nsresult rv;
if (NS_FAILED(rv = NS_NewISupportsArray(&mElements))) {
NS_ERROR("unable to create elements array");
return rv;
}
return NS_OK;
}
nsresult
nsRDFDOMNodeList::AppendNode(nsIDOMNode* aNode)
{
NS_PRECONDITION(aNode != nsnull, "null ptr");
if (! aNode)
return NS_ERROR_NULL_POINTER;
return mElements->AppendElement(aNode);
}

View File

@@ -0,0 +1,58 @@
/* -*- 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.
*/
#ifndef nsRDFDOMNodeList_h__
#define nsRDFDOMNodeList_h__
#include "nsIDOMNodeList.h"
#include "nsIScriptObjectOwner.h"
class nsIDOMNode;
class nsISupportsArray;
class nsRDFDOMNodeList : public nsIDOMNodeList,
public nsIScriptObjectOwner
{
private:
nsISupports* mInner;
nsISupportsArray* mElements;
void* mScriptObject;
nsRDFDOMNodeList(void);
nsresult Init(void);
public:
static nsresult Create(nsRDFDOMNodeList** aResult);
virtual ~nsRDFDOMNodeList(void);
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIDOMNodeList interface
NS_DECL_IDOMNODELIST
// nsIScriptObjectOwner interface
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void* aScriptObject);
// Implementation methods
nsresult AppendNode(nsIDOMNode* aNode);
};
#endif // nsRDFDOMNodeList_h__

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,398 @@
/* -*- 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.
*/
/*
An nsIRDFDocument implementation that builds an HTML-like model,
complete with text nodes. The model can be displayed in a vanilla
HTML content viewer by applying CSS2 styles to the text.
*/
#include "nsIDocument.h"
#include "nsIRDFCompositeDataSource.h"
#include "nsIRDFContent.h"
#include "nsIRDFContentModelBuilder.h"
#include "nsIRDFCursor.h"
#include "nsIRDFDocument.h"
#include "nsIRDFNode.h"
#include "nsIRDFService.h"
#include "nsIServiceManager.h"
#include "nsINameSpaceManager.h"
#include "nsISupportsArray.h"
#include "nsRDFContentUtils.h"
#include "rdfutil.h"
////////////////////////////////////////////////////////////////////////
static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID);
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
static NS_DEFINE_IID(kIRDFContentModelBuilderIID, NS_IRDFCONTENTMODELBUILDER_IID);
////////////////////////////////////////////////////////////////////////
class RDFHTMLBuilderImpl : public nsIRDFContentModelBuilder
{
private:
nsIRDFDocument* mDocument;
nsIRDFCompositeDataSource* mDB;
public:
RDFHTMLBuilderImpl();
virtual ~RDFHTMLBuilderImpl();
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIRDFContentModelBuilder interface
NS_IMETHOD SetDocument(nsIRDFDocument* aDocument);
NS_IMETHOD SetDataBase(nsIRDFCompositeDataSource* aDataBase);
NS_IMETHOD GetDataBase(nsIRDFCompositeDataSource** aDataBase);
NS_IMETHOD CreateRootContent(nsIRDFResource* aResource);
NS_IMETHOD SetRootContent(nsIContent* aElement);
NS_IMETHOD CreateContents(nsIContent* aElement);
NS_IMETHOD OnAssert(nsIRDFContent* aElement, nsIRDFResource* aProperty, nsIRDFNode* aValue);
NS_IMETHOD OnUnassert(nsIRDFContent* aElement, nsIRDFResource* aProperty, nsIRDFNode* aValue);
// Implementation methods
nsresult AddTreeChild(nsIRDFContent* aParent,
nsIRDFResource* property,
nsIRDFResource* value);
nsresult AddLeafChild(nsIRDFContent* parent,
nsIRDFResource* property,
nsIRDFLiteral* value);
PRBool IsTreeProperty(nsIRDFResource* aProperty);
};
////////////////////////////////////////////////////////////////////////
static nsIAtom* kIdAtom;
RDFHTMLBuilderImpl::RDFHTMLBuilderImpl(void)
: mDocument(nsnull),
mDB(nsnull)
{
NS_INIT_REFCNT();
if (nsnull == kIdAtom) {
kIdAtom = NS_NewAtom("id");
}
else {
NS_ADDREF(kIdAtom);
}
}
RDFHTMLBuilderImpl::~RDFHTMLBuilderImpl(void)
{
nsrefcnt refcnt;
NS_RELEASE2(kIdAtom, refcnt);
NS_IF_RELEASE(mDB);
// NS_IF_RELEASE(mDocument) not refcounted
}
////////////////////////////////////////////////////////////////////////
NS_IMPL_ISUPPORTS(RDFHTMLBuilderImpl, kIRDFContentModelBuilderIID);
////////////////////////////////////////////////////////////////////////
nsresult
RDFHTMLBuilderImpl::AddTreeChild(nsIRDFContent* parent,
nsIRDFResource* property,
nsIRDFResource* value)
{
// If it's a tree property, then create a child element whose
// value is the value of the property. We'll also attach an "ID="
// attribute to the new child; e.g.,
//
// <parent>
// <property id="value">
// <!-- recursively generated -->
// </property>
// ...
// </parent>
nsresult rv;
PRInt32 nameSpaceID;
nsIAtom* tag = nsnull;
nsIRDFContent* child = nsnull;
const char* p;
if (NS_FAILED(rv = mDocument->SplitProperty(property, &nameSpaceID, &tag)))
goto done;
if (NS_FAILED(rv = NS_NewRDFResourceElement(&child, value, nameSpaceID, tag /* , PR_TRUE */)))
goto done;
if (NS_FAILED(rv = value->GetValue(&p)))
goto done;
if (NS_FAILED(rv = child->SetAttribute(kNameSpaceID_HTML, kIdAtom, p, PR_FALSE)))
goto done;
rv = parent->AppendChildTo(child, PR_TRUE);
done:
NS_IF_RELEASE(child);
NS_IF_RELEASE(tag);
return rv;
}
nsresult
RDFHTMLBuilderImpl::AddLeafChild(nsIRDFContent* parent,
nsIRDFResource* property,
nsIRDFLiteral* value)
{
// Otherwise, it's not a tree property. So we'll just create a
// new element for the property, and a simple text node for
// its value; e.g.,
//
// <parent>
// <property>value</property>
// ...
// </parent>
nsresult rv;
PRInt32 nameSpaceID;
nsIAtom* tag = nsnull;
nsIRDFContent* child = nsnull;
if (NS_FAILED(rv = mDocument->SplitProperty(property, &nameSpaceID, &tag)))
goto done;
if (NS_FAILED(rv = NS_NewRDFResourceElement(&child, property, nameSpaceID, tag /* , PR_FALSE */)))
goto done;
if (NS_FAILED(rv = parent->AppendChildTo(child, PR_TRUE)))
goto done;
rv = nsRDFContentUtils::AttachTextNode(child, value);
done:
NS_IF_RELEASE(tag);
NS_IF_RELEASE(child);
return rv;
}
NS_IMETHODIMP
RDFHTMLBuilderImpl::SetDocument(nsIRDFDocument* aDocument)
{
NS_PRECONDITION(aDocument != nsnull, "null ptr");
if (! aDocument)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(mDocument == nsnull, "already initialized");
if (mDocument)
return NS_ERROR_ALREADY_INITIALIZED;
mDocument = aDocument; // not refcounted
return NS_OK;
}
NS_IMETHODIMP
RDFHTMLBuilderImpl::SetDataBase(nsIRDFCompositeDataSource* aDataBase)
{
NS_PRECONDITION(aDataBase != nsnull, "null ptr");
if (! aDataBase)
return NS_ERROR_NULL_POINTER;
NS_PRECONDITION(mDB == nsnull, "already initialized");
if (mDB)
return NS_ERROR_ALREADY_INITIALIZED;
mDB = aDataBase;
NS_ADDREF(mDB);
return NS_OK;
}
NS_IMETHODIMP
RDFHTMLBuilderImpl::GetDataBase(nsIRDFCompositeDataSource** aDataBase)
{
NS_PRECONDITION(aDataBase != nsnull, "null ptr");
if (! aDataBase)
return NS_ERROR_NULL_POINTER;
*aDataBase = mDB;
NS_ADDREF(mDB);
return NS_OK;
}
NS_IMETHODIMP
RDFHTMLBuilderImpl::CreateRootContent(nsIRDFResource* aResource)
{
NS_PRECONDITION(mDocument != nsnull, "not initialized");
if (! mDocument)
return NS_ERROR_NOT_INITIALIZED;
nsresult rv;
nsIAtom* tag = nsnull;
nsIDocument* doc = nsnull;
nsIContent* root = nsnull;
nsIRDFContent* body = nsnull;
if (NS_FAILED(rv = mDocument->QueryInterface(kIDocumentIID, (void**) &doc)))
goto done;
rv = NS_ERROR_OUT_OF_MEMORY;
if ((tag = NS_NewAtom("document")) == nsnull)
goto done;
if (NS_FAILED(rv = NS_NewRDFGenericElement(&root, kNameSpaceID_None, tag)))
goto done;
doc->SetRootContent(NS_STATIC_CAST(nsIContent*, root));
NS_RELEASE(tag);
rv = NS_ERROR_OUT_OF_MEMORY;
if ((tag = NS_NewAtom("body")) == nsnull)
goto done;
// PR_TRUE indicates that children should be recursively generated on demand
if (NS_FAILED(rv = NS_NewRDFResourceElement(&body, aResource, kNameSpaceID_None, tag /* , PR_TRUE */)))
goto done;
if (NS_FAILED(rv = root->AppendChildTo(body, PR_FALSE)))
goto done;
done:
NS_IF_RELEASE(body);
NS_IF_RELEASE(root);
NS_IF_RELEASE(tag);
NS_IF_RELEASE(doc);
return NS_OK;
}
NS_IMETHODIMP
RDFHTMLBuilderImpl::SetRootContent(nsIContent* aElement)
{
NS_NOTYETIMPLEMENTED("write me");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RDFHTMLBuilderImpl::CreateContents(nsIContent* aElement)
{
NS_NOTYETIMPLEMENTED("Adapt the implementation from RDFTreeBuilderImpl");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
RDFHTMLBuilderImpl::OnAssert(nsIRDFContent* parent,
nsIRDFResource* property,
nsIRDFNode* value)
{
NS_PRECONDITION(mDocument != nsnull, "not initialized");
if (! mDocument)
return NS_ERROR_NOT_INITIALIZED;
nsresult rv;
nsIRDFResource* valueResource;
if (NS_SUCCEEDED(rv = value->QueryInterface(kIRDFResourceIID, (void**) &valueResource))) {
// If it's a tree property or an RDF container, then add it as
// a tree child and return.
if (IsTreeProperty(property) || rdf_IsContainer(mDB, valueResource)) {
rv = AddTreeChild(parent, property, valueResource);
NS_RELEASE(valueResource);
return rv;
}
// Otherwise, fall through and add try to add it as a property
NS_RELEASE(valueResource);
}
nsIRDFLiteral* valueLiteral;
if (NS_SUCCEEDED(rv = value->QueryInterface(kIRDFLiteralIID, (void**) &valueLiteral))) {
rv = AddLeafChild(parent, property, valueLiteral);
NS_RELEASE(valueLiteral);
}
else {
return NS_OK; // ignore resources on the leaf.
}
return rv;
}
NS_IMETHODIMP
RDFHTMLBuilderImpl::OnUnassert(nsIRDFContent* parent,
nsIRDFResource* property,
nsIRDFNode* value)
{
PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED;
}
PRBool
RDFHTMLBuilderImpl::IsTreeProperty(nsIRDFResource* aProperty)
{
// XXX This whole method is a mega-kludge. This should be read off
// of the element somehow...
#define TREE_PROPERTY_HACK
#if defined(TREE_PROPERTY_HACK)
const char* p;
aProperty->GetValue(&p);
nsAutoString s(p);
if (s.Equals(NC_NAMESPACE_URI "child") ||
s.Equals(NC_NAMESPACE_URI "Folder") ||
s.Equals(NC_NAMESPACE_URI "Columns") ||
s.Equals(RDF_NAMESPACE_URI "child")) {
return PR_TRUE;
}
#endif // defined(TREE_PROPERTY_HACK)
if (rdf_IsOrdinalProperty(aProperty)) {
return PR_TRUE;
}
return PR_FALSE;
}
////////////////////////////////////////////////////////////////////////
nsresult
NS_NewRDFHTMLBuilder(nsIRDFContentModelBuilder** result)
{
NS_PRECONDITION(result != nsnull, "null ptr");
if (! result)
return NS_ERROR_NULL_POINTER;
RDFHTMLBuilderImpl* builder = new RDFHTMLBuilderImpl();
if (! builder)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(builder);
*result = builder;
return NS_OK;
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,29 @@
#!gmake
#
# 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.
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = public src
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,27 @@
#!gmake
#
# 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.
DEPTH=..\..
MODULE = rdf
DIRS=\
public \
src \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,2 @@
nsIRDFMail.h
nsIXULContentSink.h

View File

@@ -0,0 +1,36 @@
#!gmake
#
# 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.
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = rdf
EXPORTS = \
nsIRDFMail.h \
nsIXULContentSink.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,29 @@
#!gmake
#
# 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.
MODULE=rdf
DEPTH=..\..\..
EXPORTS = \
nsIRDFMail.h \
nsIXULContentSink.h \
$(NULL)
include <$(DEPTH)/config/rules.mak>

View File

@@ -0,0 +1,50 @@
/* -*- 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.
*/
#ifndef nsIRDFFileSystem_h__
#define nsIRDFFileSystem_h__
#include "nscore.h"
#include "nsISupports.h"
#define NS_IRDFFILESYSTEMDATAOURCE_IID \
{ 0x1222e6f0, 0xa5e3, 0x11d2, { 0x8b, 0x7c, 0x00, 0x80, 0x5f, 0x8a, 0x7d, 0xb5 } }
class nsIRDFFileSystemDataSource : public nsIRDFDataSource
{
public:
};
#define NS_IRDFFILESYSTEM_IID \
{ 0x204a1a00, 0xa5e4, 0x11d2, { 0x8b, 0x7c, 0x00, 0x80, 0x5f, 0x8a, 0x7d, 0xb5 } }
class nsIRDFFileSystem : public nsIRDFResource
{
public:
NS_IMETHOD GetFolderList(nsIRDFResource *source, nsVoidArray **array) const = 0;
NS_IMETHOD GetName(nsVoidArray **array) const = 0;
NS_IMETHOD GetURL(nsVoidArray **array) const = 0;
};
#endif // nsIRDFFileSystem_h__

View File

@@ -0,0 +1,56 @@
/* -*- 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.
*/
#ifndef nsIRDFHistory_h__
#define nsIRDFHistory_h__
#include "nscore.h"
#include "nsISupports.h"
// {115CE051-A59D-11d2-80B6-006097B76B8E}
#define NS_IRDFWEBPAGE_IID \
{ 0x115ce051, 0xa59d, 0x11d2, { 0x80, 0xb6, 0x0, 0x60, 0x97, 0xb7, 0x6b, 0x8e } };
// {1A880051-A59D-11d2-80B6-006097B76B8E}
#define NS_IRDFHISTORYDATASOURCE_IID \
{ 0x1a880051, 0xa59d, 0x11d2, { 0x80, 0xb6, 0x0, 0x60, 0x97, 0xb7, 0x6b, 0x8e } };
class nsIRDFHistoryDataSource : public nsIRDFDataSource {
public:
/**
* Add the specified item to history
*/
NS_IMETHOD AddPage (const char* uri) = 0;
/**
* Set the title of the page
*/
NS_IMETHOD SetPageTitle (const char* uri, PRUnichar* title) = 0;
/**
* Remove the page from history
*/
NS_IMETHOD RemovePage (nsIRDFResource* page) = 0;
/**
* Get the uri's last visit date
*/
NS_IMETHOD LastVisitDate (const char* uri, unit32 *date) = 0;
};

View File

@@ -0,0 +1,128 @@
/* -*- 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.
*/
#ifndef nsIRDFMail_h__
#define nsIRDFMail_h__
#include "nscore.h"
#include "nsISupports.h"
/*
Interfaces for the mail data source.
The UI will interact with the mail data source via the
nsIRDFDataSource interface. The following methods are mostly for
netlib to talk to the database. It needs to be able to add/delete an
account, folder or message.
*/
// {669F3361-9EAF-11d2-80B4-006097B76B8E}
#define NS_IRDFMAILDATAOURCE_IID \
{ 0x669f3361, 0x9eaf, 0x11d2, { 0x80, 0xb4, 0x0, 0x60, 0x97, 0xb7, 0x6b, 0x8e } }
class nsIRDFMailAccount;
class nsIRDFMailFolder;
class nsIRDFMailMessage;
class nsIRDFMailDataSource : public nsIRDFDataSource {
public:
/**
* Add the specified mail account to the data source.
*/
NS_IMETHOD AddAccount (nsIRDFMailAccount* folder) = 0;
/**
* Remove the specified mail account from the data source.
*/
NS_IMETHOD RemoveAccount (nsIRDFMailAccount* folder) = 0;
};
// {9D2792E0-9EAE-11d2-80B4-006097B76B8E}
#define NS_IMAILACCOUNT_IID \
{ 0x9d2792e0, 0x9eae, 0x11d2, { 0x80, 0xb4, 0x0, 0x60, 0x97, 0xb7, 0x6b, 0x8e } }
/**
* A resource specialization for mail accounts.
*/
class nsIRDFMailAccount : public nsIRDFResource {
public:
NS_IMETHOD GetUser(nsIRDFLiteral** result) const = 0;
NS_IMETHOD GetHost(nsIRDFLiteral** result) const = 0;
NS_IMETHOD GetName(nsIRDFLiteral** result) const = 0;
NS_IMETHOD AddFolder (nsIRDFMailFolder* folder) = 0;
NS_IMETHOD RemoveFolder (nsIRDFMailFolder* folder) = 0;
};
// {9D2792E1-9EAE-11d2-80B4-006097B76B8E}
#define NS_IMAILFOLDER_IID \
{ 0x9d2792e1, 0x9eae, 0x11d2, { 0x80, 0xb4, 0x0, 0x60, 0x97, 0xb7, 0x6b, 0x8e } }
/**
* A resource specialization for mail folders.
*/
class nsIRDFMailFolder : public nsIRDFResource {
public:
NS_IMETHOD GetAccount(nsIRDFMailAccount** account) = 0;
NS_IMETHOD GetName(nsIRDFLiteral** result) const = 0;
NS_IMETHOD GetMessageList (nsVoidArray** result) = 0;
NS_IMETHOD AddMessage (nsIRDFMailMessage* msg) = 0;
NS_IMETHOD RemoveMessage (nsIRDFMailMessage* msg) = 0;
};
// {9D2792E2-9EAE-11d2-80B4-006097B76B8E}
#define NS_IMAILMESSAGE_IID \
{ 0x9d2792e2, 0x9eae, 0x11d2, { 0x80, 0xb4, 0x0, 0x60, 0x97, 0xb7, 0x6b, 0x8e } }
/**
* A resource specialization for mail messages.
*/
class nsIRDFMailMessage : public nsIRDFResource {
public:
NS_IMETHOD GetFolder(nsIRDFMailFolder** account) = 0;
NS_IMETHOD GetSubject(nsIRDFLiteral** result) = 0;
NS_IMETHOD GetSender(nsIRDFResource** result) = 0;
NS_IMETHOD GetDate(nsIRDFLiteral** result) = 0;
NS_IMETHOD GetContent(const char* result) = 0;
NS_IMETHOD GetMessageID(nsIRDFLiteral** id) = 0;
// XXX this really sucks --- the flags, such as replied, forwarded, read, etc.
// should have separate methods
NS_IMETHOD GetFlags(char** result) = 0;
NS_IMETHOD SetFlags(const char* result) = 0;
};
#endif nsIRDFMail_h

View File

@@ -0,0 +1,49 @@
/* -*- 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.
*/
#ifndef nsIXULContentSink_h__
#define nsIXULContentSink_h__
#include "nsIXMLContentSink.h"
class nsIDocument;
class nsIRDFDataSource;
class nsIWebShell;
// {E49AA620-C16C-11d2-A6AA-00104BDE6048}
#define NS_IXULCONTENTSINK_IID \
{ 0xe49aa620, 0xc16c, 0x11d2, { 0xa6, 0xaa, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } }
class nsIXULContentSink : public nsIXMLContentSink
{
public:
static const nsIID& IID() { static nsIID iid = NS_IXULCONTENTSINK_IID; return iid; }
NS_IMETHOD Init(nsIDocument* aDocument,
nsIWebShell* aWebShell,
nsIRDFDataSource* aDataSource) = 0;
};
nsresult
NS_NewXULContentSink(nsIXULContentSink** aResult);
#endif // nsIXULContentSink_h__

View File

@@ -0,0 +1,56 @@
#!gmake
#
# 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.
DEPTH=../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
LIBRARY_NAME = rdfdatasource_s
CPPSRCS = \
nsBookmarkDataSource.cpp \
nsMailDataSource.cpp \
nsXULContentSink.cpp \
nsXULDataSource.cpp \
$(NULL)
EXPORTS = \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
MODULE = rdf
REQUIRES = dom js netlib rdf raptor xpcom
# XXX This is a dependency on rdfutil.h: it'll go away once that becomes
# a first-class XPCOM interface.
INCLUDES += -I$(srcdir)/../../base/src
MKSHLIB :=
# we don't want the shared lib
NO_SHARED_LIB=1
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,52 @@
#!gmake
#
# 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.
DEPTH=..\..\..
MODULE=rdf
LIBRARY_NAME=rdfdatasource_s
CPP_OBJS=\
.\$(OBJDIR)\nsBookmarkDataSource.obj \
.\$(OBJDIR)\nsMailDataSource.obj \
.\$(OBJDIR)\nsXULContentSink.obj \
.\$(OBJDIR)\nsXULDataSource.obj \
$(NULL)
# XXX Note the dependency on $(DEPTH)\rdf\base\src: we use rdfutil.h over
# in this library: this'll go away once we formalize utilities into an
# "real live" XPCOM interface.
LINCS= -I$(PUBLIC)\rdf \
-I$(PUBLIC)\xpcom \
-I$(PUBLIC)\netlib \
-I$(PUBLIC)\raptor \
-I$(PUBLIC)\js \
-I$(PUBLIC)\dom \
-I$(DEPTH)\rdf\base\src \
$(NULL)
include <$(DEPTH)\config\rules.mak>
libs:: $(LIBRARY)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
clobber::
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib

View File

@@ -0,0 +1,728 @@
/* -*- 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.
*/
/*
A data source that reads the 4.x "bookmarks.html" file and
constructs an in-memory data source.
TO DO
1) Write the modified bookmarks file back to disk.
*/
#include "nsIRDFDataSource.h"
#include "nsIRDFNode.h"
#include "nsIRDFService.h"
#include "nsIServiceManager.h"
#include "nsRDFCID.h"
#include "nsString.h"
#include "nsVoidArray.h"
#include "prio.h"
#include "rdf.h"
#include "rdfutil.h"
////////////////////////////////////////////////////////////////////////
static NS_DEFINE_IID(kIRDFDataSourceIID, NS_IRDFDATASOURCE_IID);
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static const char kURINC_BookmarksRoot[] = "NC:BookmarksRoot"; // XXX?
static const char kURINC_PersonalToolbarFolder[] = "NC:PersonalToolbarFolder"; // XXX?
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, child);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, BookmarkAddDate);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Description);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Folder);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Name);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, PersonalToolbarFolderCategory);
DEFINE_RDF_VOCAB(WEB_NAMESPACE_URI, WEB, LastVisitDate);
DEFINE_RDF_VOCAB(WEB_NAMESPACE_URI, WEB, LastModifiedDate);
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, instanceOf);
static const char kPersonalToolbar[] = "Personal Toolbar";
////////////////////////////////////////////////////////////////////////
/**
* The bookmark parser knows how to read <tt>bookmarks.html</tt> and convert it
* into an RDF graph.
*/
class BookmarkParser {
protected:
static const char* kBRString;
static const char* kCloseDLString;
static const char* kDDString;
static const char* kOpenAnchorString;
static const char* kOpenDLString;
static const char* kOpenH3String;
static const char* kOpenTitleString;
static const char* kSeparatorString;
enum BookmarkParserState {
eBookmarkParserState_Initial,
eBookmarkParserState_InTitle,
eBookmarkParserState_InH3,
eBookmarkParserState_InItemTitle,
eBookmarkParserState_InItemDescription
};
nsIRDFService* mRDFService;
nsIRDFDataSource* mDataSource;
nsVoidArray mStack;
nsIRDFResource* mLastItem;
nsAutoString mLine;
PRInt32 mCounter;
nsAutoString mFolderDate;
BookmarkParserState mState;
void Tokenize(const char* buf, PRInt32 size);
void NextToken(void);
void DoStateTransition(void);
void CreateBookmark(void);
nsresult AssertTime(nsIRDFResource* subject,
const nsString& predicateURI,
const nsString& time);
public:
BookmarkParser(void);
~BookmarkParser();
nsresult Parse(PRFileDesc* file, nsIRDFDataSource* dataSource);
};
const char* BookmarkParser::kBRString = "<BR>";
const char* BookmarkParser::kCloseDLString = "</DL>";
const char* BookmarkParser::kDDString = "<DD>";
const char* BookmarkParser::kOpenAnchorString = "<A";
const char* BookmarkParser::kOpenDLString = "<DL>";
const char* BookmarkParser::kOpenH3String = "<H3";
const char* BookmarkParser::kOpenTitleString = "<TITLE>";
const char* BookmarkParser::kSeparatorString = "<HR>";
BookmarkParser::BookmarkParser(void)
: mRDFService(nsnull), mDataSource(nsnull)
{
nsresult rv;
rv = nsServiceManager::GetService(kRDFServiceCID,
kIRDFServiceIID,
(nsISupports**) &mRDFService);
PR_ASSERT(NS_SUCCEEDED(rv));
}
BookmarkParser::~BookmarkParser(void)
{
if (mRDFService)
nsServiceManager::ReleaseService(kRDFServiceCID, mRDFService);
}
nsresult
BookmarkParser::Parse(PRFileDesc* file, nsIRDFDataSource* dataSource)
{
NS_PRECONDITION(file && dataSource && mRDFService, "null ptr");
if (! file)
return NS_ERROR_NULL_POINTER;
if (! dataSource)
return NS_ERROR_NULL_POINTER;
if (! mRDFService)
return NS_ERROR_NOT_INITIALIZED;
// Initialize the parser for a run...
mDataSource = dataSource;
mState = eBookmarkParserState_Initial;
mCounter = 0;
mLastItem = nsnull;
mLine.Truncate();
char buf[1024];
PRInt32 len;
while ((len = PR_Read(file, buf, sizeof(buf))) > 0)
Tokenize(buf, len);
NS_IF_RELEASE(mLastItem);
return NS_OK;
}
void
BookmarkParser::Tokenize(const char* buf, PRInt32 size)
{
for (PRInt32 i = 0; i < size; ++i) {
char c = buf[i];
if (c == '<') {
if (mLine.Length() > 0) {
NextToken();
mLine.Truncate();
}
}
mLine.Append(c);
if (c == '>') {
if (mLine.Length() > 0) {
NextToken();
mLine.Truncate();
}
}
}
}
void
BookmarkParser::NextToken(void)
{
if (mLine[0] == '<') {
DoStateTransition();
return;
}
// ok, we have a piece of content. can be the title, or a
// description
if ((mState == eBookmarkParserState_InTitle) ||
(mState == eBookmarkParserState_InH3)) {
nsIRDFResource* folder;
if (mStack.Count() > 0) {
// a regular old folder
nsAutoString folderURI;
if (mLine.Find(kPersonalToolbar) == 0) {
folderURI = kURINC_PersonalToolbarFolder;
}
else {
folderURI = kURINC_BookmarksRoot;
folderURI.Append('#');
folderURI.Append(++mCounter, 10);
}
if (NS_FAILED(mRDFService->GetUnicodeResource(folderURI, &folder)))
return;
nsIRDFResource* parent = (nsIRDFResource*) mStack[mStack.Count() - 1];
rdf_Assert(mDataSource, parent, kURINC_Folder, folder);
}
else {
// it's the root
if (NS_FAILED(mRDFService->GetResource(kURINC_BookmarksRoot, &folder)))
return;
}
if (mFolderDate.Length()) {
AssertTime(folder, kURINC_BookmarkAddDate, mFolderDate);
mFolderDate.Truncate();
}
NS_IF_RELEASE(mLastItem);
mLastItem = folder;
// XXX Implied
//NS_ADDREF(mLastItem);
//NS_RELEASE(folder);
if (mState != eBookmarkParserState_InTitle)
rdf_Assert(mDataSource, mLastItem, kURINC_Name, mLine);
}
else if (mState == eBookmarkParserState_InItemTitle) {
PR_ASSERT(mLastItem);
if (! mLastItem)
return;
rdf_Assert(mDataSource, mLastItem, kURINC_Name, mLine);
NS_IF_RELEASE(mLastItem);
}
else if (mState == eBookmarkParserState_InItemDescription) {
rdf_Assert(mDataSource, mLastItem, kURINC_Description, mLine);
}
}
void
BookmarkParser::DoStateTransition(void)
{
if (mLine.Find(kOpenAnchorString) == 0) {
CreateBookmark();
mState = eBookmarkParserState_InItemTitle;
}
else if (mLine.Find(kOpenH3String) == 0) {
PRInt32 start = mLine.Find('"');
PRInt32 end = mLine.RFind('"');
if (start >= 0 && end >= 0)
mLine.Mid(mFolderDate, start + 1, end - start - 1);
mState = eBookmarkParserState_InH3;
}
else if (mLine.Find(kOpenTitleString) == 0) {
mState = eBookmarkParserState_InTitle;
}
else if (mLine.Find(kDDString) == 0) {
#if 0 // XXX if it doesn't already have a description? Huh?
if (remoteStoreGetSlotValue(gLocalStore, mLastItem, gWebData->RDF_description,
RDF_STRING_TYPE, false, true)
== nsnull)
#endif
mState = eBookmarkParserState_InItemDescription;
}
else if (mLine.Find(kOpenDLString) == 0) {
mStack.AppendElement(mLastItem);
NS_ADDREF(mLastItem);
}
else if (mLine.Find(kCloseDLString) == 0) {
PRInt32 count = mStack.Count();
if (count) {
nsIRDFNode* top = NS_STATIC_CAST(nsIRDFNode*, mStack[--count]);
mStack.RemoveElementAt(count);
NS_IF_RELEASE(top);
}
}
else if (mLine.Find(kSeparatorString) == 0) {
#if FIXME // separators
addSlotValue(f, createSeparator(), gCoreVocab->RDF_parent, mStack[mStack.Count() - 1],
RDF_RESOURCE_TYPE, nsnull);
#endif
mState = eBookmarkParserState_Initial;
}
else if ((mState == eBookmarkParserState_InItemDescription) &&
(mLine.Find(kBRString) == 0)) {
// XXX in the original bmk2rdf.c, we only added the
// description in the case that it wasn't set already...why?
rdf_Assert(mDataSource, mLastItem, kURINC_Description, mLine);
}
else {
mState = eBookmarkParserState_Initial;
}
}
void
BookmarkParser::CreateBookmark(void)
{
enum {
eBmkAttribute_URL = 0,
eBmkAttribute_AddDate = 1,
eBmkAttribute_LastVisit = 2,
eBmkAttribute_LastModified = 3
};
nsAutoString values[4];
PRInt32 index = 0;
for (PRInt32 i = 0; i < 4; ++i) {
PRInt32 start = mLine.Find('"', index);
if (start == -1)
break;
++start; // past the first quote
PRInt32 end = mLine.Find('"', start);
PR_ASSERT(end > 0); // unterminated
if (end == -1)
end = mLine.Length();
mLine.Mid(values[i], start, end - start);
index = end + 1;
}
if (values[eBmkAttribute_URL].Length() == 0)
return;
nsIRDFResource* bookmark;
if (NS_FAILED(mRDFService->GetUnicodeResource(values[eBmkAttribute_URL], &bookmark)))
return;
if (! mStack.Count())
return;
nsIRDFResource* parent = (nsIRDFResource*) mStack[mStack.Count() - 1];
if (! parent)
return;
rdf_Assert(mDataSource, parent, kURINC_child, bookmark);
if (values[eBmkAttribute_AddDate].Length() > 0)
AssertTime(bookmark, kURINC_BookmarkAddDate, values[eBmkAttribute_AddDate]);
if (values[eBmkAttribute_LastVisit].Length() > 0)
AssertTime(bookmark, kURIWEB_LastVisitDate, values[eBmkAttribute_LastVisit]);
if (values[eBmkAttribute_LastModified].Length() > 0)
AssertTime(bookmark, kURIWEB_LastModifiedDate, values[eBmkAttribute_LastModified]);
NS_IF_RELEASE(mLastItem);
mLastItem = bookmark;
// XXX Implied
//NS_ADDREF(mLastItem);
//NS_RELEASE(bookmark);
}
nsresult
BookmarkParser::AssertTime(nsIRDFResource* object,
const nsString& predicateURI,
const nsString& time)
{
// XXX
return rdf_Assert(mDataSource, object, predicateURI, time);
}
////////////////////////////////////////////////////////////////////////
// BookmarkDataSourceImpl
/**
* The bookmark data source uses a <tt>BookmarkParser</tt> to read the
* <tt>bookmarks.html</tt> file from the local disk and present an
* in-memory RDF graph based on it.
*/
class BookmarkDataSourceImpl : public nsIRDFDataSource {
protected:
static const char* kBookmarksFilename;
nsIRDFDataSource* mInner;
nsresult ReadBookmarks(void);
nsresult WriteBookmarks(void);
nsresult AddColumns(void);
public:
BookmarkDataSourceImpl(void);
virtual ~BookmarkDataSourceImpl(void);
// nsISupports
NS_DECL_ISUPPORTS
// nsIRDFDataSource
NS_IMETHOD Init(const char* uri);
NS_IMETHOD GetURI(const char* *uri) const {
return mInner->GetURI(uri);
}
NS_IMETHOD GetSource(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFResource** source) {
return mInner->GetSource(property, target, tv, source);
}
NS_IMETHOD GetSources(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFAssertionCursor** sources) {
return mInner->GetSources(property, target, tv, sources);
}
NS_IMETHOD GetTarget(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFNode** target) {
return mInner->GetTarget(source, property, tv, target);
}
NS_IMETHOD GetTargets(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFAssertionCursor** targets) {
return mInner->GetTargets(source, property, tv, targets);
}
NS_IMETHOD Assert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv) {
return mInner->Assert(source, property, target, tv);
}
NS_IMETHOD Unassert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target) {
return mInner->Unassert(source, property, target);
}
NS_IMETHOD HasAssertion(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
PRBool* hasAssertion) {
return mInner->HasAssertion(source, property, target, tv, hasAssertion);
}
NS_IMETHOD AddObserver(nsIRDFObserver* n) {
return mInner->AddObserver(n);
}
NS_IMETHOD RemoveObserver(nsIRDFObserver* n) {
return mInner->RemoveObserver(n);
}
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
nsIRDFArcsInCursor** labels) {
return mInner->ArcLabelsIn(node, labels);
}
NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
nsIRDFArcsOutCursor** labels) {
return mInner->ArcLabelsOut(source, labels);
}
NS_IMETHOD GetAllResources(nsIRDFResourceCursor** aCursor) {
return mInner->GetAllResources(aCursor);
}
NS_IMETHOD Flush(void);
NS_IMETHOD IsCommandEnabled(const char* aCommand,
nsIRDFResource* aCommandTarget,
PRBool* aResult);
NS_IMETHOD DoCommand(const char* aCommand,
nsIRDFResource* aCommandTarget);
};
////////////////////////////////////////////////////////////////////////
// XXX we should get this from prefs.
#if defined(XP_MAC)
const char* BookmarkDataSourceImpl::kBookmarksFilename = "/usr/local/netscape/bin/res/rdf/bookmarks.html";
#elif defined(XP_PC)
const char* BookmarkDataSourceImpl::kBookmarksFilename = "res\\rdf\\bookmarks.html";
#elif defined(XP_UNIX)
const char* BookmarkDataSourceImpl::kBookmarksFilename = "res/rdf/bookmarks.html";
#endif
BookmarkDataSourceImpl::BookmarkDataSourceImpl(void)
{
// XXX rvg there should be only one instance of this class.
// this is actually true of all datasources.
NS_INIT_REFCNT();
}
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();
NS_RELEASE(mInner);
}
NS_IMPL_ISUPPORTS(BookmarkDataSourceImpl, kIRDFDataSourceIID);
NS_IMETHODIMP
BookmarkDataSourceImpl::Init(const char* uri)
{
nsresult rv;
if (NS_FAILED(rv = nsRepository::CreateInstance(kRDFInMemoryDataSourceCID,
nsnull,
kIRDFDataSourceIID,
(void**) &mInner)))
return rv;
if (NS_FAILED(rv = mInner->Init(uri)))
return rv;
if (NS_FAILED(rv = ReadBookmarks()))
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;
}
NS_IMETHODIMP
BookmarkDataSourceImpl::Flush(void)
{
return WriteBookmarks();
}
NS_IMETHODIMP
BookmarkDataSourceImpl::IsCommandEnabled(const char* aCommand,
nsIRDFResource* aCommandTarget,
PRBool* aResult)
{
PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
BookmarkDataSourceImpl::DoCommand(const char* aCommand,
nsIRDFResource* aCommandTarget)
{
PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
BookmarkDataSourceImpl::ReadBookmarks(void)
{
nsresult rv = NS_ERROR_FAILURE;
PRFileDesc* f;
if ((f = PR_Open(kBookmarksFilename, PR_RDONLY, 0644)) != nsnull) {
BookmarkParser parser;
rv = parser.Parse(f, this);
PR_Close(f);
}
return rv;
}
nsresult
BookmarkDataSourceImpl::WriteBookmarks(void)
{
//PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED;
}
#if FIXME
static const nsString&
rdf_NumericDate(const nsString& url)
{
nsAutoString result;
PRInt32 len = url.Length();
PRInt32 index = 0;
while (index < len && url[index] < '0' && url[index] > '9')
++index;
if (index >= len)
return result;
while (index < len && url[index] >= '0' && url[index] <= '9')
result.Append(url[index++]);
result;
}
void
HT_WriteOutAsBookmarks1 (RDF rdf, PRFileDesc *fp, RDF_Resource u, RDF_Resource top, int indent)
{
RDF_Cursor c = RDF_GetSources(rdf, u, gCoreVocab->RDF_parent, RDF_RESOURCE_TYPE, true);
RDF_Resource next;
char *date, *name, *url;
int loop;
if (c == nsnull) return;
if (u == top) {
name = RDF_GetResourceName(rdf, u);
ht_rjcprintf(fp, "<!DOCTYPE NETSCAPE-Bookmark-file-1>\n", nsnull);
ht_rjcprintf(fp, "<!-- This is an automatically generated file.\n", nsnull);
ht_rjcprintf(fp, "It will be read and overwritten.\n", nsnull);
ht_rjcprintf(fp, "Do Not Edit! -->\n", nsnull);
ht_rjcprintf(fp, "<TITLE>%s</TITLE>\n", (name) ? name:"");
ht_rjcprintf(fp, "<H1>%s</H1>\n<DL><p>\n", (name) ? name:"");
}
while ((next = RDF_NextValue(c)) != nsnull) {
url = resourceID(next);
if (containerp(next) && (!startsWith("ftp:",url)) && (!startsWith("file:",url))
&& (!startsWith("IMAP:", url)) && (!startsWith("nes:", url))
&& (!startsWith("mail:", url)) && (!startsWith("cache:", url))
&& (!startsWith("ldap:", url))) {
for (loop=0; loop<indent; loop++) ht_rjcprintf(fp, " ", nsnull);
date = numericDate(resourceID(next));
ht_rjcprintf(fp, "<DT><H3 ADD_DATE=\"%s\">", (date) ? date:"");
if (date) freeMem(date);
name = RDF_GetResourceName(rdf, next);
ht_rjcprintf(fp, "%s</H3>\n", name);
for (loop=0; loop<indent; loop++) ht_rjcprintf(fp, " ", nsnull);
ht_rjcprintf(fp, "<DL><p>\n", nsnull);
HT_WriteOutAsBookmarks1(rdf, fp, next, top, indent+1);
for (loop=0; loop<indent; loop++) ht_rjcprintf(fp, " ", nsnull);
ht_rjcprintf(fp, "</DL><p>\n", nsnull);
}
else if (isSeparator(next)) {
for (loop=0; loop<indent; loop++) ht_rjcprintf(fp, " ", nsnull);
ht_rjcprintf(fp, "<HR>\n", nsnull);
}
else {
char* bkAddDate = (char*)RDF_GetSlotValue(rdf, next,
gNavCenter->RDF_bookmarkAddDate,
RDF_STRING_TYPE, false, true);
for (loop=0; loop<indent; loop++) ht_rjcprintf(fp, " ", nsnull);
ht_rjcprintf(fp, "<DT><A HREF=\"%s\" ", resourceID(next));
date = numericDate(bkAddDate);
ht_rjcprintf(fp, "ADD_DATE=\"%s\" ", (date) ? date: "");
if (date) freeMem(date);
ht_rjcprintf(fp, "LAST_VISIT=\"%s\" ", resourceLastVisitDate(rdf, next));
ht_rjcprintf(fp, "LAST_MODIFIED=\"%s\">", resourceLastModifiedDate(rdf, next));
ht_rjcprintf(fp, "%s</A>\n", RDF_GetResourceName(rdf, next));
if (resourceDescription(rdf, next) != nsnull) {
ht_rjcprintf(fp, "<DD>%s\n", resourceDescription(rdf, next));
}
}
}
RDF_DisposeCursor(c);
if (u == top) {
ht_rjcprintf(fp, "</DL>\n", nsnull);
}
}
#endif
////////////////////////////////////////////////////////////////////////
nsresult
NS_NewRDFBookmarkDataSource(nsIRDFDataSource** result)
{
BookmarkDataSourceImpl* ds = new BookmarkDataSourceImpl();
if (! ds)
return NS_ERROR_NULL_POINTER;
*result = ds;
NS_ADDREF(*result);
return NS_OK;
}

View File

@@ -0,0 +1,961 @@
/* -*- Mode: C++; tab-width: 8; 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.
*/
/*
Implementation for a file system RDF data store.
*/
/*
To do:
1) build up volume list correctly (platform dependant).
Currently hardcoded, Windows only.
2) Encode/decode URLs appropriately (0x20 <-> %20, 0x2F <> '/', etc)
*/
#include <ctype.h> // for toupper()
#include <stdio.h>
#include "nscore.h"
#include "nsIRDFCursor.h"
#include "nsIRDFDataSource.h"
#include "nsIRDFNode.h"
#include "nsIRDFObserver.h"
#include "nsIRDFResourceFactory.h"
#include "nsIServiceManager.h"
#include "nsString.h"
#include "nsVoidArray.h" // XXX introduces dependency on raptorbase
#include "nsRDFCID.h"
#include "rdfutil.h"
#include "nsIRDFService.h"
#include "xp_core.h"
#include "plhash.h"
#include "plstr.h"
#include "prmem.h"
#include "prprf.h"
#include "prio.h"
#include "nsFileSpec.h"
#include "nsIRDFFileSystem.h"
#include "nsFileSystemDataSource.h"
#ifdef XP_WIN
#include "windef.h"
#include "winbase.h"
#endif
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
static NS_DEFINE_IID(kIRDFFileSystemDataSourceIID, NS_IRDFFILESYSTEMDATAOURCE_IID);
static NS_DEFINE_IID(kIRDFFileSystemIID, NS_IRDFFILESYSTEM_IID);
static NS_DEFINE_IID(kIRDFAssertionCursorIID, NS_IRDFASSERTIONCURSOR_IID);
static NS_DEFINE_IID(kIRDFCursorIID, NS_IRDFCURSOR_IID);
static NS_DEFINE_IID(kIRDFArcsOutCursorIID, NS_IRDFARCSOUTCURSOR_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
static NS_DEFINE_IID(kIRDFResourceFactoryIID, NS_IRDFRESOURCEFACTORY_IID);
static NS_DEFINE_IID(kIRDFNodeIID, NS_IRDFNODE_IID);
static const char kURINC_FileSystemRoot[] = "NC:FilesRoot";
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, child);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, name);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, url);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Columns);
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, instanceOf);
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, Bag);
static nsIRDFService *gRDFService = nsnull;
static FileSystemDataSource *gFileSystemDataSource = nsnull;
static PRBool
peq(nsIRDFResource* r1, nsIRDFResource* r2)
{
PRBool retVal=PR_FALSE, result;
if (NS_SUCCEEDED(r1->EqualsResource(r2, &result)))
{
if (result)
{
retVal = PR_TRUE;
}
}
return(retVal);
}
nsIRDFResource *FileSystemDataSource::kNC_FileSystemRoot;
nsIRDFResource *FileSystemDataSource::kNC_Child;
nsIRDFResource *FileSystemDataSource::kNC_Name;
nsIRDFResource *FileSystemDataSource::kNC_URL;
nsIRDFResource *FileSystemDataSource::kNC_Columns;
nsIRDFResource *FileSystemDataSource::kRDF_InstanceOf;
nsIRDFResource *FileSystemDataSource::kRDF_Bag;
FileSystemDataSource::FileSystemDataSource(void)
: mURI(nsnull),
mObservers(nsnull)
{
NS_INIT_REFCNT();
nsresult rv = nsServiceManager::GetService(kRDFServiceCID,
kIRDFServiceIID, (nsISupports**) &gRDFService);
PR_ASSERT(NS_SUCCEEDED(rv));
gFileSystemDataSource = this;
}
FileSystemDataSource::~FileSystemDataSource (void)
{
gRDFService->UnregisterDataSource(this);
PL_strfree(mURI);
if (nsnull != mObservers)
{
for (PRInt32 i = mObservers->Count(); i >= 0; --i)
{
nsIRDFObserver* obs = (nsIRDFObserver*) mObservers->ElementAt(i);
NS_RELEASE(obs);
}
delete mObservers;
mObservers = nsnull;
}
nsrefcnt refcnt;
NS_RELEASE2(kNC_FileSystemRoot, refcnt);
NS_RELEASE2(kNC_Child, refcnt);
NS_RELEASE2(kNC_Name, refcnt);
NS_RELEASE2(kNC_URL, refcnt);
NS_RELEASE2(kNC_Columns, refcnt);
NS_RELEASE2(kRDF_InstanceOf, refcnt);
NS_RELEASE2(kRDF_Bag, refcnt);
gFileSystemDataSource = nsnull;
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
gRDFService = nsnull;
}
NS_IMPL_ISUPPORTS(FileSystemDataSource, kIRDFFileSystemDataSourceIID);
NS_IMETHODIMP
FileSystemDataSource::Init(const char *uri)
{
nsresult rv = NS_ERROR_OUT_OF_MEMORY;
if ((mURI = PL_strdup(uri)) == nsnull)
return rv;
gRDFService->GetResource(kURINC_FileSystemRoot, &kNC_FileSystemRoot);
gRDFService->GetResource(kURINC_child, &kNC_Child);
gRDFService->GetResource(kURINC_name, &kNC_Name);
gRDFService->GetResource(kURINC_url, &kNC_URL);
gRDFService->GetResource(kURINC_Columns, &kNC_Columns);
gRDFService->GetResource(kURIRDF_instanceOf, &kRDF_InstanceOf);
gRDFService->GetResource(kURIRDF_Bag, &kRDF_Bag);
// if (NS_FAILED(rv = AddColumns()))
// 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;
}
NS_IMETHODIMP
FileSystemDataSource::GetURI(const char **uri) const
{
*uri = mURI;
return NS_OK;
}
NS_IMETHODIMP
FileSystemDataSource::GetSource(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFResource** source /* out */)
{
nsresult rv = NS_ERROR_RDF_NO_VALUE;
return rv;
}
NS_IMETHODIMP
FileSystemDataSource::GetSources(nsIRDFResource *property,
nsIRDFNode *target,
PRBool tv,
nsIRDFAssertionCursor **sources /* out */)
{
PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
FileSystemDataSource::GetTarget(nsIRDFResource *source,
nsIRDFResource *property,
PRBool tv,
nsIRDFNode **target /* out */)
{
nsIRDFFileSystem *fs;
nsresult rv = NS_ERROR_RDF_NO_VALUE;
// we only have positive assertions in the file system data source.
if (! tv)
return rv;
if (NS_SUCCEEDED(source->QueryInterface(kIRDFFileSystemIID, (void **) &fs)))
{
if (peq(property, kNC_Name))
{
// rv = fs->GetName((nsIRDFLiteral **)target);
}
else
{
rv = NS_ERROR_RDF_NO_VALUE;
}
NS_IF_RELEASE(fs);
}
return(rv);
}
nsresult GetVolumeList(nsVoidArray **array);
NS_IMETHODIMP
FileSystemDataSource::GetTargets(nsIRDFResource *source,
nsIRDFResource *property,
PRBool tv,
nsIRDFAssertionCursor **targets /* out */)
{
nsIRDFFileSystem *fs;
nsVoidArray *array = nsnull;
nsresult rv = NS_ERROR_FAILURE;
if (peq(source, kNC_FileSystemRoot))
{
if (peq(property, kNC_Child))
{
rv = GetVolumeList(&array);
}
}
else if (NS_OK == source->QueryInterface(kIRDFFileSystemIID, (void **)&fs))
{
if (peq(property, kNC_Child))
{
rv = fs->GetFolderList(source, &array);
}
else if (peq(property, kNC_Name))
{
rv = fs->GetName(&array);
}
else if (peq(property, kNC_URL))
{
rv = fs->GetURL(&array);
}
NS_IF_RELEASE(fs);
}
if ((rv == NS_OK) && (nsnull != array))
{
*targets = new FileSystemCursor(source, property, array);
NS_ADDREF(*targets);
}
return(rv);
}
NS_IMETHODIMP
FileSystemDataSource::Assert(nsIRDFResource *source,
nsIRDFResource *property,
nsIRDFNode *target,
PRBool tv)
{
PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
FileSystemDataSource::Unassert(nsIRDFResource *source,
nsIRDFResource *property,
nsIRDFNode *target)
{
PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
FileSystemDataSource::HasAssertion(nsIRDFResource *source,
nsIRDFResource *property,
nsIRDFNode *target,
PRBool tv,
PRBool *hasAssertion /* out */)
{
nsIRDFFileSystem *fs = nsnull;
PRBool retVal = PR_FALSE;
nsresult rv = 0; // xxx
*hasAssertion = PR_FALSE;
if (NS_SUCCEEDED(source->QueryInterface(kIRDFFileSystemIID, (void**) &fs)))
{
if (peq(property, kRDF_InstanceOf))
{
if (peq((nsIRDFResource *)target, kRDF_Bag))
{
*hasAssertion = PR_TRUE;
rv = NS_OK;
}
}
NS_IF_RELEASE(fs);
}
return (rv);
}
NS_IMETHODIMP
FileSystemDataSource::ArcLabelsIn(nsIRDFNode *node,
nsIRDFArcsInCursor ** labels /* out */)
{
PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
FileSystemDataSource::ArcLabelsOut(nsIRDFResource *source,
nsIRDFArcsOutCursor **labels /* out */)
{
nsIRDFFileSystem *fs;
nsresult rv = NS_ERROR_RDF_NO_VALUE;
if (NS_SUCCEEDED(source->QueryInterface(kIRDFFileSystemIID, (void**) &fs)))
{
nsVoidArray *temp = new nsVoidArray();
if (nsnull == temp)
return NS_ERROR_OUT_OF_MEMORY;
temp->AppendElement(kNC_Child);
temp->AppendElement(kNC_Name);
temp->AppendElement(kNC_URL);
temp->AppendElement(kNC_Columns);
*labels = new FileSystemCursor(source, kNC_Child, temp);
if (nsnull != *labels)
{
NS_ADDREF(*labels);
rv = NS_OK;
}
NS_RELEASE(fs);
}
return(rv);
}
NS_IMETHODIMP
FileSystemDataSource::GetAllResources(nsIRDFResourceCursor** aCursor)
{
NS_NOTYETIMPLEMENTED("sorry!");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
FileSystemDataSource::AddObserver(nsIRDFObserver *n)
{
if (nsnull == mObservers)
{
if ((mObservers = new nsVoidArray()) == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
}
mObservers->AppendElement(n);
return NS_OK;
}
NS_IMETHODIMP
FileSystemDataSource::RemoveObserver(nsIRDFObserver *n)
{
if (nsnull == mObservers)
return NS_OK;
mObservers->RemoveElement(n);
return NS_OK;
}
NS_IMETHODIMP
FileSystemDataSource::Flush()
{
PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
FileSystemDataSource::IsCommandEnabled(const char* aCommand,
nsIRDFResource* aCommandTarget,
PRBool* aResult)
{
return NS_OK;
}
NS_IMETHODIMP
FileSystemDataSource::DoCommand(const char* aCommand,
nsIRDFResource* aCommandTarget)
{
return NS_OK;
}
nsresult
NS_NewRDFFileSystemDataSource(nsIRDFDataSource **result)
{
if (!result)
return NS_ERROR_NULL_POINTER;
// only one file system data source
if (nsnull == gFileSystemDataSource)
{
if ((gFileSystemDataSource = new FileSystemDataSource()) == nsnull)
{
return NS_ERROR_OUT_OF_MEMORY;
}
}
NS_ADDREF(gFileSystemDataSource);
*result = gFileSystemDataSource;
return NS_OK;
}
nsresult
GetVolumeList(nsVoidArray **array)
{
nsIRDFFileSystem *vol;
nsVoidArray *volumes = new nsVoidArray();
#if 1
#ifdef XP_WIN
PRInt32 driveType;
char drive[32];
PRInt32 volNum;
char *url;
for (volNum = 0; volNum < 26; volNum++)
{
sprintf(drive, "%c:\\", volNum + 'A');
driveType = GetDriveType(drive);
if (driveType != DRIVE_UNKNOWN && driveType != DRIVE_NO_ROOT_DIR)
{
if (nsnull != (url = PR_smprintf("file:///%c|/", volNum + 'A')))
{
gRDFService->GetResource(url, (nsIRDFResource **)&vol);
NS_ADDREF(vol);
volumes->AppendElement(vol);
PR_Free(url);
}
}
}
*array = volumes;
return NS_OK;
#else
#endif
#else
gRDFService->GetResource("file:///c|/", (nsIRDFResource **)&vol);
volumes->AppendElement(vol);
// NS_ADDREF(vol);
gRDFService->GetResource("file:///d|/", (nsIRDFResource **)&vol);
volumes->AppendElement(vol);
// NS_ADDREF(vol);
*array = volumes;
return NS_OK;
#endif
}
FileSystemCursor::FileSystemCursor(nsIRDFResource *source,
nsIRDFResource *property,
nsVoidArray *array)
{
mSource = source;
mProperty = property;
mArray = array;
NS_ADDREF(mSource);
NS_ADDREF(mProperty);
mCount = 0;
mTarget = nsnull;
mValue = nsnull;
}
FileSystemCursor::~FileSystemCursor(void)
{
NS_IF_RELEASE(mSource);
NS_IF_RELEASE(mValue);
NS_IF_RELEASE(mProperty);
NS_IF_RELEASE(mTarget);
}
NS_IMETHODIMP
FileSystemCursor::Advance(void)
{
if (!mArray)
return NS_ERROR_NULL_POINTER;
if (mArray->Count() <= mCount)
return NS_ERROR_RDF_CURSOR_EMPTY;
NS_IF_RELEASE(mValue);
mTarget = mValue = (nsIRDFNode *)mArray->ElementAt(mCount++);
NS_ADDREF(mValue);
return NS_OK;
}
NS_IMETHODIMP
FileSystemCursor::GetValue(nsIRDFNode **aValue)
{
if (nsnull == mValue)
return NS_ERROR_NULL_POINTER;
NS_ADDREF(mValue);
*aValue = mValue;
return NS_OK;
}
NS_IMETHODIMP
FileSystemCursor::GetDataSource(nsIRDFDataSource **aDataSource)
{
NS_ADDREF(gFileSystemDataSource);
*aDataSource = gFileSystemDataSource;
return NS_OK;
}
NS_IMETHODIMP
FileSystemCursor::GetSubject(nsIRDFResource **aResource)
{
NS_ADDREF(mSource);
*aResource = mSource;
return NS_OK;
}
NS_IMETHODIMP
FileSystemCursor::GetPredicate(nsIRDFResource **aPredicate)
{
NS_ADDREF(mProperty);
*aPredicate = mProperty;
return NS_OK;
}
NS_IMETHODIMP
FileSystemCursor::GetObject(nsIRDFNode **aObject)
{
if (nsnull != mTarget)
NS_ADDREF(mTarget);
*aObject = mTarget;
return NS_OK;
}
NS_IMETHODIMP
FileSystemCursor::GetTruthValue(PRBool *aTruthValue)
{
*aTruthValue = 1;
return NS_OK;
}
NS_IMPL_ADDREF(FileSystemCursor);
NS_IMPL_RELEASE(FileSystemCursor);
NS_IMETHODIMP
FileSystemCursor::QueryInterface(REFNSIID iid, void **result)
{
if (! result)
return NS_ERROR_NULL_POINTER;
*result = nsnull;
if (iid.Equals(kIRDFAssertionCursorIID) ||
iid.Equals(kIRDFCursorIID) ||
iid.Equals(kIRDFArcsOutCursorIID) ||
iid.Equals(kISupportsIID))
{
*result = NS_STATIC_CAST(nsIRDFAssertionCursor *, this);
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
/********************************** FileSystem **************************************
************************************************************************************/
FileSystem::FileSystem(const char *uri)
{
NS_INIT_REFCNT();
mURI = PL_strdup(uri);
}
FileSystem::~FileSystem(void)
{
gRDFService->UnCacheResource(this);
PL_strfree(mURI);
}
NS_IMPL_IRDFRESOURCE(FileSystem);
NS_IMPL_ADDREF(FileSystem);
NS_IMPL_RELEASE(FileSystem);
NS_IMETHODIMP
FileSystem::QueryInterface(REFNSIID iid, void **result)
{
if (! result)
return NS_ERROR_NULL_POINTER;
*result = nsnull;
if (iid.Equals(kIRDFResourceIID) ||
iid.Equals(kIRDFNodeIID) ||
iid.Equals(kIRDFFileSystemIID) ||
iid.Equals(kISupportsIID))
{
*result = NS_STATIC_CAST(nsIRDFFileSystem *, this);
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
static PRBool
isDirectory(const char *parent, const char *optFile)
{
PRFileInfo info;
PRStatus err;
PRBool isDirFlag = PR_FALSE;
char *url;
nsAutoString pathname(parent);
if (nsnull != optFile)
{
pathname += optFile;
}
url = pathname.ToNewCString();
if (nsnull != url)
{
if ((err = PR_GetFileInfo(url, &info)) == PR_SUCCESS)
{
if (info.type == PR_FILE_DIRECTORY)
{
isDirFlag = PR_TRUE;
}
}
}
return(isDirFlag);
}
NS_IMETHODIMP
FileSystem::GetFolderList(nsIRDFResource *source, nsVoidArray **array /* out */) const
{
nsAutoString name(mURI);
*array = nsnull;
if (name.Find("file:///") == 0)
{
#ifdef XP_UNIX
name.Cut(0, strlen("file://"));
#else
name.Cut(0, strlen("file:///"));
#endif
#ifdef XP_WIN
// on Windows, replace pipe with colon
if (name.Length() > 2)
{
if (name.CharAt(1) == '|')
{
name.CharAt(1) = ':';
}
}
#endif
PRDir *dir;
PRDirEntry *de;
PRInt32 n = PR_SKIP_BOTH;
nsIRDFFileSystem *file;
nsVoidArray *nameArray = new nsVoidArray();
char *dirName = name.ToNewCString();
#define DEPTH_LIMIT 2
#ifdef DEPTH_LIMIT
char *p;
PRInt32 slashCount = 0;
char *temp = name.ToNewCString();
p = strchr(temp, '/');
while (nsnull != p)
{
++ slashCount;
++p;
p = strchr(p, '/');
}
delete temp;
if (slashCount > DEPTH_LIMIT)
{
*array = nsnull;
delete dirName;
delete nameArray;
return NS_OK;
}
#endif
if (nsnull != dirName)
{
if (nsnull != (dir = PR_OpenDir(dirName)))
{
while (nsnull != (de = PR_ReadDir(dir, (PRDirFlags)(n++))))
{
nsAutoString pathname(mURI);
pathname += de->name;
if (PR_TRUE == isDirectory(dirName, de->name))
{
pathname += "/";
}
char *filename = pathname.ToNewCString();
if (nsnull != filename)
{
gRDFService->GetResource(filename, (nsIRDFResource **)&file);
delete filename;
nameArray->AppendElement(file);
}
}
PR_CloseDir(dir);
}
delete dirName;
}
*array = nameArray;
}
return NS_OK;
}
NS_IMETHODIMP
FileSystem::GetName(nsVoidArray **array) const
{
nsString *basename = nsnull;
nsAutoString name(mURI);
PRInt32 len = name.Length();
if (len > 0)
{
if (name.CharAt(len-1) == '/')
{
name.SetLength(--len);
}
}
PRInt32 slashIndex = name.RFind("/");
if (slashIndex > 0)
{
basename = new nsString;
name.Mid(*basename, slashIndex+1, len-slashIndex);
#ifdef XP_WIN
// on Windows, replace pipe with colon and uppercase drive letter
if (basename->Length() == 2)
{
if (basename->CharAt(1) == '|')
{
basename->CharAt(1) = ':';
basename->ToUpperCase();
}
}
#endif
}
*array = nsnull;
if (nsnull != basename)
{
nsIRDFLiteral *literal;
gRDFService->GetLiteral(*basename, &literal);
// NS_ADDREF(literal);
delete basename;
nsVoidArray *nameArray = new nsVoidArray();
nameArray->AppendElement(literal);
*array = nameArray;
}
return NS_OK;
}
NS_IMETHODIMP
FileSystem::GetURL(nsVoidArray **array) const
{
nsVoidArray *urlArray = new nsVoidArray();
*array = urlArray;
if (nsnull != urlArray)
{
nsIRDFLiteral *literal;
nsAutoString url(mURI);
gRDFService->GetLiteral(url, &literal);
NS_ADDREF(literal);
urlArray->AppendElement(literal);
}
return NS_OK;
}
class FileSystemResourceFactoryImpl : public nsIRDFResourceFactory
{
public:
FileSystemResourceFactoryImpl(void);
virtual ~FileSystemResourceFactoryImpl(void);
NS_DECL_ISUPPORTS
NS_IMETHOD CreateResource(const char* aURI, nsIRDFResource** aResult);
};
FileSystemResourceFactoryImpl::FileSystemResourceFactoryImpl(void)
{
NS_INIT_REFCNT();
}
FileSystemResourceFactoryImpl::~FileSystemResourceFactoryImpl(void)
{
}
NS_IMPL_ISUPPORTS(FileSystemResourceFactoryImpl, kIRDFResourceFactoryIID);
NS_IMETHODIMP
FileSystemResourceFactoryImpl::CreateResource(const char* aURI, nsIRDFResource** aResult)
{
if (! aResult)
return NS_ERROR_NULL_POINTER;
FileSystem *fs = new FileSystem(aURI);
if (!fs)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(fs);
*aResult = fs;
return NS_OK;
}
nsresult
NS_NewRDFFileSystemResourceFactory(nsIRDFResourceFactory** aResult)
{
if (! aResult)
return NS_ERROR_NULL_POINTER;
FileSystemResourceFactoryImpl *factory = new FileSystemResourceFactoryImpl();
if (! factory)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(factory);
*aResult = factory;
return NS_OK;
}

View File

@@ -0,0 +1,192 @@
/* -*- 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.
*/
#ifndef nsFileSystemDataSource_h__
#define nsFileSystemDataSource_h__
////////////////////////////////////////////////////////////////////////
// NS_DECL_IRDFRESOURCE, NS_IMPL_IRDFRESOURCE
//
// Convenience macros for implementing the RDF resource interface.
//
// XXX It might make sense to move these macros to nsIRDFResource.h?
#define NS_DECL_IRDFRESOURCE \
NS_IMETHOD EqualsNode(nsIRDFNode* node, PRBool* result) const;\
NS_IMETHOD GetValue(const char* *uri) const;\
NS_IMETHOD EqualsResource(const nsIRDFResource* resource, PRBool* result) const;\
NS_IMETHOD EqualsString(const char* uri, PRBool* result) const;
#define NS_IMPL_IRDFRESOURCE(__class) \
NS_IMETHODIMP \
__class::EqualsNode(nsIRDFNode* node, PRBool* result) const {\
nsresult rv;\
nsIRDFResource* resource;\
if (NS_SUCCEEDED(node->QueryInterface(kIRDFResourceIID, (void**) &resource))) {\
rv = EqualsResource(resource, result);\
NS_RELEASE(resource);\
}\
else {\
*result = PR_FALSE;\
rv = NS_OK;\
}\
return rv;\
}\
NS_IMETHODIMP \
__class::GetValue(const char* *uri) const{\
if (!uri)\
return NS_ERROR_NULL_POINTER;\
*uri = mURI;\
return NS_OK;\
}\
NS_IMETHODIMP \
__class::EqualsResource(const nsIRDFResource* resource, PRBool* result) const {\
if (!resource || !result) return NS_ERROR_NULL_POINTER;\
*result = (resource == (nsIRDFResource*) this);\
return NS_OK;\
}\
NS_IMETHODIMP \
__class::EqualsString(const char* uri, PRBool* result) const {\
if (!uri || !result) return NS_ERROR_NULL_POINTER;\
*result = (PL_strcmp(uri, mURI) == 0);\
return NS_OK;\
}
class FileSystemDataSource : public nsIRDFFileSystemDataSource
{
private:
char *mURI;
nsVoidArray *mObservers;
static nsIRDFResource *kNC_FileSystemRoot;
static nsIRDFResource *kNC_Child;
static nsIRDFResource *kNC_Name;
static nsIRDFResource *kNC_URL;
static nsIRDFResource *kNC_Columns;
static nsIRDFResource *kRDF_InstanceOf;
static nsIRDFResource *kRDF_Bag;
public:
NS_DECL_ISUPPORTS
FileSystemDataSource(void);
virtual ~FileSystemDataSource(void);
// nsIRDFDataSource methods
NS_IMETHOD Init(const char *uri);
NS_IMETHOD GetURI(const char **uri) const;
NS_IMETHOD GetSource(nsIRDFResource *property,
nsIRDFNode *target,
PRBool tv,
nsIRDFResource **source /* out */);
NS_IMETHOD GetSources(nsIRDFResource *property,
nsIRDFNode *target,
PRBool tv,
nsIRDFAssertionCursor **sources /* out */);
NS_IMETHOD GetTarget(nsIRDFResource *source,
nsIRDFResource *property,
PRBool tv,
nsIRDFNode **target /* out */);
NS_IMETHOD GetTargets(nsIRDFResource *source,
nsIRDFResource *property,
PRBool tv,
nsIRDFAssertionCursor **targets /* out */);
NS_IMETHOD Assert(nsIRDFResource *source,
nsIRDFResource *property,
nsIRDFNode *target,
PRBool tv);
NS_IMETHOD Unassert(nsIRDFResource *source,
nsIRDFResource *property,
nsIRDFNode *target);
NS_IMETHOD HasAssertion(nsIRDFResource *source,
nsIRDFResource *property,
nsIRDFNode *target,
PRBool tv,
PRBool *hasAssertion /* out */);
NS_IMETHOD ArcLabelsIn(nsIRDFNode *node,
nsIRDFArcsInCursor **labels /* out */);
NS_IMETHOD ArcLabelsOut(nsIRDFResource *source,
nsIRDFArcsOutCursor **labels /* out */);
NS_IMETHOD GetAllResources(nsIRDFResourceCursor** aCursor);
NS_IMETHOD AddObserver(nsIRDFObserver *n);
NS_IMETHOD RemoveObserver(nsIRDFObserver *n);
NS_IMETHOD Flush();
NS_IMETHOD IsCommandEnabled(const char *aCommand,
nsIRDFResource *aCommandTarget,
PRBool *aResult);
NS_IMETHOD DoCommand(const char *aCommand,
nsIRDFResource *aCommandTarget);
};
class FileSystem : public nsIRDFFileSystem
{
private:
char *mURI;
public:
FileSystem(const char *uri);
virtual ~FileSystem(void);
NS_DECL_ISUPPORTS
NS_DECL_IRDFRESOURCE
NS_IMETHOD GetFolderList(nsIRDFResource *source,
nsVoidArray **array /* out */) const;
NS_IMETHOD GetName(nsVoidArray **array /* out */) const;
NS_IMETHOD GetURL(nsVoidArray **array /* out */) const;
};
class FileSystemCursor : public nsIRDFAssertionCursor, public nsIRDFArcsOutCursor
{
private:
nsIRDFNode *mValue;
nsIRDFResource *mSource;
nsIRDFResource *mProperty;
nsIRDFNode *mTarget;
int mCount;
nsVoidArray *mArray;
public:
FileSystemCursor(nsIRDFResource *source, nsIRDFResource *property, nsVoidArray *array);
virtual ~FileSystemCursor(void);
NS_DECL_ISUPPORTS
NS_IMETHOD Advance(void);
NS_IMETHOD GetValue(nsIRDFNode **aValue);
NS_IMETHOD GetDataSource(nsIRDFDataSource **aDataSource);
NS_IMETHOD GetSubject(nsIRDFResource **aResource);
NS_IMETHOD GetPredicate(nsIRDFResource **aPredicate);
NS_IMETHOD GetObject(nsIRDFNode **aObject);
NS_IMETHOD GetTruthValue(PRBool *aTruthValue);
};
#endif // nsFileSystemDataSource_h__

View File

@@ -0,0 +1,162 @@
/* -*- 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.
*/
#include <ctype.h> // for toupper()
#include <stdio.h>
#include "nscore.h"
#include "nsIRDFCursor.h"
#include "nsIRDFDataSource.h"
#include "nsIRDFNode.h"
#include "nsIRDFObserver.h"
#include "nsIRDFResourceFactory.h"
#include "nsIServiceManager.h"
#include "nsString.h"
#include "nsVoidArray.h" // XXX introduces dependency on raptorbase
#include "nsRDFCID.h"
#include "rdfutil.h"
#include "nsIRDFMail.h"
#include "nsIRDFService.h"
#include "plhash.h"
#include "plstr.h"
#include "prmem.h"
#include "prprf.h"
#include "prio.h"
#include "nsMailDataSource.h"
////////////////////////////////////////////////////////////////////////
// Interface IDs
static NS_DEFINE_IID(kIRDFArcsInCursorIID, NS_IRDFARCSINCURSOR_IID);
static NS_DEFINE_IID(kIRDFArcsOutCursorIID, NS_IRDFARCSOUTCURSOR_IID);
static NS_DEFINE_IID(kIRDFAssertionCursorIID, NS_IRDFASSERTIONCURSOR_IID);
static NS_DEFINE_IID(kIRDFCursorIID, NS_IRDFCURSOR_IID);
static NS_DEFINE_IID(kIRDFDataSourceIID, NS_IRDFDATASOURCE_IID);
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
static NS_DEFINE_IID(kIRDFHistoryDataSourceIID, NS_IRDFHISTORYDATAOURCE_IID);
static NS_DEFINE_IID(kIRDFNodeIID, NS_IRDFNODE_IID);
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
static NS_DEFINE_IID(kIRDFResourceFactoryIID, NS_IRDFRESOURCEFACTORY_IID);
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
////////////////////////////////////////////////////////////////////////
// RDF property & resource declarations
static const char kURIHistoryRoot[] = "HistoryRoot";
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, child);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Name);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Folder);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Column);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Columns);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Title);
DEFINE_RDF_VOCAB(WEB_NAMESPACE_URI, WEB, LastVisitDate);
DEFINE_RDF_VOCAB(WEB_NAMESPACE_URI, WEB, LastModifiedDate);
class nsHistoryDataSource : public nsIHistoryDataSource {
nsIRDFDataSource** mInner;
nsVoidArray mFiles;
public:
NS_IMETHOD Init(const char* uri) ;
NS_IMETHOD GetURI(const char* *uri) {
return mInner->GetURI(uri);
}
NS_IMETHOD GetSource(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv, nsIRDFResource** source) {
return mInner->GetSource(property, target, tv, source);
}
NS_IMETHOD GetSources(nsIRDFResource* property,
nsIRDFNode* target, PRBool tv,
nsIRDFAssertionCursor** sources) {
return mInner->GetSources(property, target, tv, sources);
}
NS_IMETHOD GetTarget(nsIRDFResource* source,
nsIRDFResource* property, PRBool tv,
nsIRDFNode** target) {
return mInner->GetTarget(source, property, tv, target);
}
NS_IMETHOD GetTargets(nsIRDFResource* source,
nsIRDFResource* property, PRBool tv,
nsIRDFAssertionCursor** targets) {
return mInner->GetTargets(source, property, tv, targets);
}
NS_IMETHOD Assert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target, PRBool tv) {
return mInner->Assert(source, property, target, tv);
}
NS_IMETHOD Unassert(nsIRDFResource* source,
nsIRDFResource* property, nsIRDFNode* target) {
return mInner->Unassert(source, property, target);
}
NS_IMETHOD HasAssertion(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target, PRBool tv,
PRBool* hasAssertion) {
return mInner->HasAssertion(source, property, target, tv, hasAssertion);
}
NS_IMETHOD AddObserver(nsIRDFObserver* n) {
return mInner->AddObserver(n);
}
NS_IMETHOD RemoveObserver(nsIRDFObserver* n) {
return mInner->RemoveObserver(n);
}
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
nsIRDFArcsInCursor** labels) {
return mInner->ArcLabelsIn(node, labels);
}
NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
nsIRDFArcsOutCursor** labels) {
return mInner->ArcLabelsOut(source, labels);
}
NS_IMETHOD Flush() {
return mInner->Flush();
}
NS_IMETHOD IsCommandEnabled(const char* aCommand,
nsIRDFResource* aCommandTarget,
PRBool* aResult) {
return mInner->IsCommandEnabled(aCommand, aCommandTarget, aResult);
}
NS_IMETHOD DoCommand(const char* aCommand,
nsIRDFResource* aCommandTarget) {
return mInner->DoCommand(aCommand, aCommandTarget);
}
};

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,363 @@
/* -*- 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.
*/
/*
Class declarations for mail data source resource types.
XXX Should these be factored out into their own implementation files, etc.?
*/
#ifndef nsMailDataSource_h__
#define nsMailDataSource_h__
////////////////////////////////////////////////////////////////////////
// NS_DECL_IRDFRESOURCE, NS_IMPL_IRDFRESOURCE
//
// Convenience macros for implementing the RDF resource interface.
//
// XXX It might make sense to move these macros to nsIRDFResource.h?
#define NS_DECL_IRDFRESOURCE \
NS_IMETHOD EqualsNode(nsIRDFNode* node, PRBool* result) const;\
NS_IMETHOD GetValue(const char* *uri) const;\
NS_IMETHOD EqualsResource(const nsIRDFResource* resource, PRBool* result) const;\
NS_IMETHOD EqualsString(const char* uri, PRBool* result) const;
#define NS_IMPL_IRDFRESOURCE(__class) \
NS_IMETHODIMP \
__class::EqualsNode(nsIRDFNode* node, PRBool* result) const {\
nsresult rv;\
nsIRDFResource* resource;\
if (NS_SUCCEEDED(node->QueryInterface(kIRDFResourceIID, (void**) &resource))) {\
rv = EqualsResource(resource, result);\
NS_RELEASE(resource);\
}\
else {\
*result = PR_FALSE;\
rv = NS_OK;\
}\
return rv;\
}\
NS_IMETHODIMP \
__class::GetValue(const char* *uri) const{\
if (!uri)\
return NS_ERROR_NULL_POINTER;\
*uri = mURI;\
return NS_OK;\
}\
NS_IMETHODIMP \
__class::EqualsResource(const nsIRDFResource* resource, PRBool* result) const {\
if (!resource || !result) return NS_ERROR_NULL_POINTER;\
*result = (resource == (nsIRDFResource*) this);\
return NS_OK;\
}\
NS_IMETHODIMP \
__class::EqualsString(const char* uri, PRBool* result) const {\
if (!uri || !result) return NS_ERROR_NULL_POINTER;\
*result = (PL_strcmp(uri, mURI) == 0);\
return NS_OK;\
}
////////////////////////////////////////////////////////////////////////
/**
* The mail data source.
*/
class MailDataSource : public nsIRDFMailDataSource
{
private:
char* mURI;
nsVoidArray* mObservers;
// internal methods
nsresult InitAccountList (void);
nsresult AddColumns (void);
public:
NS_DECL_ISUPPORTS
MailDataSource(void);
virtual ~MailDataSource (void);
// nsIRDFMailDataSource methods
NS_IMETHOD AddAccount (nsIRDFMailAccount* folder);
NS_IMETHOD RemoveAccount (nsIRDFMailAccount* folder);
// nsIRDFDataSource methods
NS_IMETHOD Init(const char* uri);
NS_IMETHOD GetURI(const char* *uri) const;
NS_IMETHOD GetSource(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFResource** source /* out */);
NS_IMETHOD GetTarget(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFNode** target);
NS_IMETHOD GetSources(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFAssertionCursor** sources);
NS_IMETHOD GetTargets(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFAssertionCursor** targets);
NS_IMETHOD Assert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv);
NS_IMETHOD Unassert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target);
NS_IMETHOD HasAssertion(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
PRBool* hasAssertion);
NS_IMETHOD AddObserver(nsIRDFObserver* n);
NS_IMETHOD RemoveObserver(nsIRDFObserver* n);
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
nsIRDFArcsInCursor** labels);
NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
nsIRDFArcsOutCursor** labels);
NS_IMETHOD GetAllResources(nsIRDFResourceCursor** aCursor);
NS_IMETHOD Flush();
NS_IMETHOD IsCommandEnabled(const char* aCommand,
nsIRDFResource* aCommandTarget,
PRBool* aResult);
NS_IMETHOD DoCommand(const char* aCommand,
nsIRDFResource* aCommandTarget);
// caching frequently used resources
static nsIRDFResource* kNC_Child;
static nsIRDFResource* kNC_Folder;
static nsIRDFResource* kNC_From;
static nsIRDFResource* kNC_subject;
static nsIRDFResource* kNC_date;
static nsIRDFResource* kNC_user;
static nsIRDFResource* kNC_host;
static nsIRDFResource* kNC_account;
static nsIRDFResource* kNC_Name;
static nsIRDFResource* kNC_Columns;
static nsIRDFResource* kNC_MailRoot;
nsIRDFDataSource* mMiscMailData;
};
////////////////////////////////////////////////////////////////////////
class MailAccount : public nsIRDFMailAccount
{
private:
char* mURI;
nsresult InitMailAccount (const char* uri);
public:
MailAccount (const char* uri);
MailAccount (char* uri, nsIRDFLiteral* user, nsIRDFLiteral* host);
virtual ~MailAccount (void);
NS_DECL_ISUPPORTS
NS_DECL_IRDFRESOURCE
NS_IMETHOD GetUser(nsIRDFLiteral** result) const;
NS_IMETHOD GetName(nsIRDFLiteral** result) const;
NS_IMETHOD GetHost(nsIRDFLiteral** result) const;
NS_IMETHOD AddFolder (nsIRDFMailFolder* folder);
NS_IMETHOD RemoveFolder (nsIRDFMailFolder* folder);
};
////////////////////////////////////////////////////////////////////////
class MailFolder : public nsIRDFMailFolder
{
private:
enum MailFolderStatus {
eMailFolder_Uninitialized,
eMailFolder_InitInProgress,
eMailFolder_WriteInProgress,
eMailFolder_OK
};
nsVoidArray mMessages;
FILE* mSummaryFile;
MailFolderStatus mStatus;
char* mURI;
public:
MailFolder (const char* uri);
virtual ~MailFolder (void);
NS_DECL_ISUPPORTS
NS_DECL_IRDFRESOURCE
NS_IMETHOD GetAccount(nsIRDFMailAccount** account);
NS_IMETHOD GetName(nsIRDFLiteral** result) const;
NS_IMETHOD GetMessageList (nsVoidArray** result);
NS_IMETHOD AddMessage (nsIRDFMailMessage* msg);
NS_IMETHOD RemoveMessage (nsIRDFMailMessage* msg);
nsresult AddMessage(PRUnichar* uri,
MailFolder* folder,
nsIRDFResource* from,
nsIRDFLiteral* subject,
nsIRDFLiteral* date,
int summaryFileOffset,
int mailFileOffset,
char* flags,
nsIRDFLiteral* messageID);
nsresult AddMessage(PRUnichar* uri,
MailFolder* folder,
nsIRDFResource* from,
nsIRDFLiteral* subject,
nsIRDFLiteral* date,
int mailFileOffset,
char* flags,
nsIRDFLiteral* messageID);
nsresult ReadSummaryFile(char* uri);
};
////////////////////////////////////////////////////////////////////////
class MailMessage : public nsIRDFMailMessage
{
private:
MailFolder* mFolder;
nsIRDFResource* mFrom;
nsIRDFLiteral* mSubject;
int mSummaryFileOffset;
int mMailFileOffset;
nsIRDFLiteral* mDate;
nsIRDFLiteral* mMessageID;
char mFlags[4];
char* mURI;
public:
MailMessage (const char* uri);
virtual ~MailMessage (void);
NS_DECL_ISUPPORTS
NS_DECL_IRDFRESOURCE
NS_IMETHOD GetFolder(nsIRDFMailFolder** result);
NS_IMETHOD GetSubject(nsIRDFLiteral** result);
NS_IMETHOD GetSender(nsIRDFResource** result);
NS_IMETHOD GetDate(nsIRDFLiteral** result);
NS_IMETHOD GetContent(const char* result);
NS_IMETHOD GetMessageID(nsIRDFLiteral** id);
NS_IMETHOD GetFlags(char** result);
NS_IMETHOD SetFlags(const char* result);
nsresult SetupMessage (MailFolder* folder,
nsIRDFResource* from,
nsIRDFLiteral* subject,
nsIRDFLiteral* date,
int summaryFileOffset,
int mailFileOffset,
char* flags,
nsIRDFLiteral* messageID);
};
////////////////////////////////////////////////////////////////////////
class SingletonMailCursor : public nsIRDFAssertionCursor
{
private:
nsIRDFNode* mValue;
nsIRDFResource* mSource;
nsIRDFResource* mProperty;
nsIRDFNode* mTarget;
PRBool mValueReturnedp;
PRBool mInversep;
public:
SingletonMailCursor(nsIRDFNode* u,
nsIRDFResource* s,
PRBool inversep);
virtual ~SingletonMailCursor(void);
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIRDFCursor interface
NS_IMETHOD Advance(void);
NS_IMETHOD GetValue(nsIRDFNode** aValue);
// nsIRDFAssertionCursor interface
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource);
NS_IMETHOD GetSubject(nsIRDFResource** aResource);
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate);
NS_IMETHOD GetObject(nsIRDFNode** aObject);
NS_IMETHOD GetTruthValue(PRBool* aTruthValue);
};
////////////////////////////////////////////////////////////////////////
class ArrayMailCursor : public nsIRDFAssertionCursor ,
public nsIRDFArcsOutCursor
{
private:
nsIRDFNode* mValue;
nsIRDFResource* mSource;
nsIRDFResource* mProperty;
nsIRDFNode* mTarget;
int mCount;
nsVoidArray* mArray;
public:
ArrayMailCursor(nsIRDFResource* u, nsIRDFResource* s, nsVoidArray* array);
virtual ~ArrayMailCursor(void);
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIRDFCursor interface
NS_IMETHOD Advance(void);
NS_IMETHOD GetValue(nsIRDFNode** aValue);
// nsIRDFAssertionCursor interface
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource);
NS_IMETHOD GetSubject(nsIRDFResource** aResource);
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate);
NS_IMETHOD GetObject(nsIRDFNode** aObject);
NS_IMETHOD GetTruthValue(PRBool* aTruthValue);
};
#endif // nsMailDataSource_h__

View File

@@ -0,0 +1,48 @@
/* -*- 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 header file just contains prototypes for the factory methods
for "builtin" data sources that are included in rdf.dll.
Each of these data sources is exposed to the external world via its
CID in ../include/nsRDFCID.h.
*/
#ifndef nsBuiltinDataSources_h__
#define nsBuiltinDataSources_h__
#include "nsError.h"
class nsIRDFDataSource;
class nsIRDFDataBase;
// in nsBookmarkDataSource.cpp
nsresult NS_NewRDFBookmarkDataSource(nsIRDFDataSource** result);
// in nsMemoryDataSource.cpp
nsresult NS_NewRDFInMemoryDataSource(nsIRDFDataSource** result);
// in nsStreamDataSource.cpp
nsresult NS_NewRDFStreamDataSource(nsIRDFDataSource** result);
#endif // nsBuiltinDataSources_h__

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,639 @@
/* -*- 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.
*/
/*
A data source that can read itself from and write itself to an
XUL stream.
TO DO
-----
1) Write code to serialize XUL back.
*/
#include "nsFileSpec.h"
#include "nsFileStream.h"
#include "nsIDTD.h"
#include "nsIInputStream.h"
#include "nsINameSpaceManager.h"
#include "nsIOutputStream.h"
#include "nsIParser.h"
#include "nsIRDFContentSink.h"
#include "nsIRDFCursor.h"
#include "nsIRDFNode.h"
#include "nsIRDFService.h"
#include "nsIRDFDataSource.h"
#include "nsIRDFXMLDataSource.h"
#include "nsIServiceManager.h"
#include "nsIStreamListener.h"
#include "nsIURL.h"
#include "nsLayoutCID.h" // for NS_NAMESPACEMANAGER_CID.
#include "nsParserCIID.h"
#include "nsRDFCID.h"
#include "nsVoidArray.h"
#include "plstr.h"
#include "prio.h"
#include "prthread.h"
#include "rdfutil.h"
////////////////////////////////////////////////////////////////////////
static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID);
static NS_DEFINE_IID(kIInputStreamIID, NS_IINPUTSTREAM_IID);
static NS_DEFINE_IID(kINameSpaceManagerIID, NS_INAMESPACEMANAGER_IID);
static NS_DEFINE_IID(kIOutputStreamIID, NS_IOUTPUTSTREAM_IID);
static NS_DEFINE_IID(kIParserIID, NS_IPARSER_IID);
static NS_DEFINE_IID(kIRDFContentSinkIID, NS_IRDFCONTENTSINK_IID);
static NS_DEFINE_IID(kIRDFDataSourceIID, NS_IRDFDATASOURCE_IID);
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID);
static NS_DEFINE_CID(kParserCID, NS_PARSER_IID); // XXX
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
static NS_DEFINE_CID(kRDFContentSinkCID, NS_RDFCONTENTSINK_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_CID(kWellFormedDTDCID, NS_WELLFORMEDDTD_CID);
static NS_DEFINE_IID(kIRDFXMLDataSourceIID, NS_IRDFXMLDATASOURCE_IID);
static NS_DEFINE_IID(kXULContentSinkCID, NS_XULCONTENTSINK_CID);
////////////////////////////////////////////////////////////////////////
// Vocabulary stuff
#include "rdf.h"
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, instanceOf);
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, nextVal);
////////////////////////////////////////////////////////////////////////
// XULDataSourceImpl
class XULDataSourceImpl : public nsIRDFXMLDataSource
{
protected:
struct NameSpaceMap {
nsString URI;
nsIAtom* Prefix;
NameSpaceMap* Next;
};
nsIRDFDataSource* mInner;
PRBool mIsSynchronous; // true if the document should be loaded synchronously
PRBool mIsWritable; // true if the document can be written back
PRBool mIsDirty; // true if the document should be written back
nsVoidArray mObservers;
char** mNamedDataSourceURIs;
PRInt32 mNumNamedDataSourceURIs;
nsIURL** mCSSStyleSheetURLs;
PRInt32 mNumCSSStyleSheetURLs;
nsIRDFResource* mRootResource;
PRBool mIsLoading; // true while the document is loading
NameSpaceMap* mNameSpaces;
public:
XULDataSourceImpl(void);
virtual ~XULDataSourceImpl(void);
// nsISupports
NS_DECL_ISUPPORTS
// nsIRDFDataSource
NS_IMETHOD Init(const char* uri);
NS_IMETHOD GetURI(const char* *uri) const {
return mInner->GetURI(uri);
}
NS_IMETHOD GetSource(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFResource** source) {
return mInner->GetSource(property, target, tv, source);
}
NS_IMETHOD GetSources(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFAssertionCursor** sources) {
return mInner->GetSources(property, target, tv, sources);
}
NS_IMETHOD GetTarget(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFNode** target) {
return mInner->GetTarget(source, property, tv, target);
}
NS_IMETHOD GetTargets(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFAssertionCursor** targets) {
return mInner->GetTargets(source, property, tv, targets);
}
NS_IMETHOD Assert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv) {
return mInner->Assert(source, property, target, tv);;
}
NS_IMETHOD Unassert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target) {
return mInner->Unassert(source, property, target);
}
NS_IMETHOD HasAssertion(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
PRBool* hasAssertion) {
return mInner->HasAssertion(source, property, target, tv, hasAssertion);
}
NS_IMETHOD AddObserver(nsIRDFObserver* n) {
return mInner->AddObserver(n);
}
NS_IMETHOD RemoveObserver(nsIRDFObserver* n) {
return mInner->RemoveObserver(n);
}
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
nsIRDFArcsInCursor** labels) {
return mInner->ArcLabelsIn(node, labels);
}
NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
nsIRDFArcsOutCursor** labels) {
return mInner->ArcLabelsOut(source, labels);
}
NS_IMETHOD GetAllResources(nsIRDFResourceCursor** aCursor) {
return mInner->GetAllResources(aCursor);
}
NS_IMETHOD Flush(void);
NS_IMETHOD IsCommandEnabled(const char* aCommand,
nsIRDFResource* aCommandTarget,
PRBool* aResult) {
return mInner->IsCommandEnabled(aCommand, aCommandTarget, aResult);
}
NS_IMETHOD DoCommand(const char* aCommand,
nsIRDFResource* aCommandTarget) {
// XXX Uh oh, this could cause problems wrt. the "dirty" flag
// if it changes the in-memory store's internal state.
return mInner->DoCommand(aCommand, aCommandTarget);
}
// nsIRDFXMLDataSource interface
NS_IMETHOD SetSynchronous(PRBool aIsSynchronous);
NS_IMETHOD SetReadOnly(PRBool aIsReadOnly);
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 AddNameSpace(nsIAtom* aPrefix, const nsString& aURI);
NS_IMETHOD AddXMLStreamObserver(nsIRDFXMLDataSourceObserver* aObserver);
NS_IMETHOD RemoveXMLStreamObserver(nsIRDFXMLDataSourceObserver* aObserver);
};
////////////////////////////////////////////////////////////////////////
nsresult
NS_NewXULDataSource(nsIRDFXMLDataSource** result)
{
XULDataSourceImpl* ds = new XULDataSourceImpl();
if (! ds)
return NS_ERROR_NULL_POINTER;
*result = ds;
NS_ADDREF(*result);
return NS_OK;
}
XULDataSourceImpl::XULDataSourceImpl(void)
: mIsSynchronous(PR_FALSE),
mIsWritable(PR_TRUE),
mIsDirty(PR_FALSE),
mNamedDataSourceURIs(nsnull),
mNumNamedDataSourceURIs(0),
mCSSStyleSheetURLs(nsnull),
mNumCSSStyleSheetURLs(0),
mIsLoading(PR_FALSE),
mNameSpaces(nsnull)
{
nsresult rv;
if (NS_FAILED(rv = nsRepository::CreateInstance(kRDFInMemoryDataSourceCID,
nsnull,
kIRDFDataSourceIID,
(void**) &mInner)))
PR_ASSERT(0);
NS_INIT_REFCNT();
}
XULDataSourceImpl::~XULDataSourceImpl(void)
{
nsIRDFService* rdfService;
if (NS_SUCCEEDED(nsServiceManager::GetService(kRDFServiceCID,
kIRDFServiceIID,
(nsISupports**) &rdfService))) {
rdfService->UnregisterDataSource(this);
nsServiceManager::ReleaseService(kRDFServiceCID, rdfService);
}
Flush();
while (mNumNamedDataSourceURIs-- > 0) {
delete mNamedDataSourceURIs[mNumNamedDataSourceURIs];
}
delete mNamedDataSourceURIs;
while (mNumCSSStyleSheetURLs-- > 0) {
NS_RELEASE(mCSSStyleSheetURLs[mNumCSSStyleSheetURLs]);
}
delete mCSSStyleSheetURLs;
while (mNameSpaces) {
NameSpaceMap* doomed = mNameSpaces;
mNameSpaces = mNameSpaces->Next;
NS_RELEASE(doomed->Prefix);
delete doomed;
}
}
NS_IMPL_ADDREF(XULDataSourceImpl);
NS_IMPL_RELEASE(XULDataSourceImpl);
NS_IMETHODIMP
XULDataSourceImpl::QueryInterface(REFNSIID iid, void** result)
{
if (! result)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(kISupportsIID) ||
iid.Equals(kIRDFDataSourceIID) ||
iid.Equals(kIRDFXMLDataSourceIID)) {
*result = NS_STATIC_CAST(nsIRDFDataSource*, this);
NS_ADDREF(this);
return NS_OK;
}
else {
*result = nsnull;
return NS_NOINTERFACE;
}
}
NS_IMETHODIMP
XULDataSourceImpl::Init(const char* uri)
{
static const char kFileURIPrefix[] = "file:";
static const char kResourceURIPrefix[] = "resource:";
NS_PRECONDITION(mInner != nsnull, "not initialized");
if (! mInner)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv;
// XXX this is a hack: any "file:" URI is considered writable. All
// others are considered read-only.
if (PL_strncmp(uri, kFileURIPrefix, sizeof(kFileURIPrefix) - 1) != 0)
mIsWritable = PR_FALSE;
nsIRDFService* rdfService = nsnull;
nsINameSpaceManager* ns = nsnull;
nsIRDFContentSink* sink = nsnull;
nsIParser* parser = nsnull;
nsIDTD* dtd = nsnull;
nsIStreamListener* lsnr = nsnull;
nsIURL* url = nsnull;
if (NS_FAILED(rv = NS_NewURL(&url, uri)))
goto done;
if (NS_FAILED(rv = mInner->Init(uri)))
goto done;
if (NS_FAILED(rv = nsServiceManager::GetService(kRDFServiceCID,
kIRDFServiceIID,
(nsISupports**) &rdfService)))
goto done;
if (NS_FAILED(rv = rdfService->RegisterDataSource(this)))
goto done;
if (NS_FAILED(rv = nsRepository::CreateInstance(kNameSpaceManagerCID,
nsnull,
kINameSpaceManagerIID,
(void**) &ns)))
goto done;
if (NS_FAILED(rv = nsRepository::CreateInstance(kXULContentSinkCID,
nsnull,
kIRDFContentSinkIID,
(void**) &sink)))
goto done;
if (NS_FAILED(sink->Init(url, ns)))
goto done;
// We set the content sink's data source directly to our in-memory
// store. This allows the initial content to be generated "directly".
if (NS_FAILED(rv = sink->SetDataSource(this)))
goto done;
if (NS_FAILED(rv = nsRepository::CreateInstance(kParserCID,
nsnull,
kIParserIID,
(void**) &parser)))
goto done;
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,
nsnull,
kIDTDIID,
(void**) &dtd)))
goto done;
parser->RegisterDTD(dtd);
if (NS_FAILED(rv = parser->QueryInterface(kIStreamListenerIID, (void**) &lsnr)))
goto done;
if (NS_FAILED(parser->Parse(url)))
goto done;
rv = NS_OpenURL(url, lsnr);
done:
NS_IF_RELEASE(lsnr);
NS_IF_RELEASE(dtd);
NS_IF_RELEASE(parser);
NS_IF_RELEASE(sink);
if (rdfService) {
nsServiceManager::ReleaseService(kRDFServiceCID, rdfService);
rdfService = nsnull;
}
NS_IF_RELEASE(url);
return rv;
}
NS_IMETHODIMP
XULDataSourceImpl::Flush(void)
{
NS_NOTYETIMPLEMENTED("write me!");
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////
// nsIRDFXMLDataSource methods
NS_IMETHODIMP
XULDataSourceImpl::SetSynchronous(PRBool aIsSynchronous)
{
mIsSynchronous = aIsSynchronous;
return NS_OK;
}
NS_IMETHODIMP
XULDataSourceImpl::SetReadOnly(PRBool aIsReadOnly)
{
if (mIsWritable && aIsReadOnly)
mIsWritable = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
XULDataSourceImpl::BeginLoad(void)
{
mIsLoading = PR_TRUE;
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
nsIRDFXMLDataSourceObserver* obs = (nsIRDFXMLDataSourceObserver*) mObservers[i];
obs->OnBeginLoad(this);
}
return NS_OK;
}
NS_IMETHODIMP
XULDataSourceImpl::Interrupt(void)
{
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
nsIRDFXMLDataSourceObserver* obs = (nsIRDFXMLDataSourceObserver*) mObservers[i];
obs->OnInterrupt(this);
}
return NS_OK;
}
NS_IMETHODIMP
XULDataSourceImpl::Resume(void)
{
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
nsIRDFXMLDataSourceObserver* obs = (nsIRDFXMLDataSourceObserver*) mObservers[i];
obs->OnResume(this);
}
return NS_OK;
}
NS_IMETHODIMP
XULDataSourceImpl::EndLoad(void)
{
mIsLoading = PR_FALSE;
for (PRInt32 i = mObservers.Count() - 1; i >= 0; --i) {
nsIRDFXMLDataSourceObserver* obs = (nsIRDFXMLDataSourceObserver*) mObservers[i];
obs->OnEndLoad(this);
}
return NS_OK;
}
NS_IMETHODIMP
XULDataSourceImpl::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) {
nsIRDFXMLDataSourceObserver* obs = (nsIRDFXMLDataSourceObserver*) mObservers[i];
obs->OnRootResourceFound(this, mRootResource);
}
return NS_OK;
}
NS_IMETHODIMP
XULDataSourceImpl::GetRootResource(nsIRDFResource** aResource)
{
NS_ADDREF(mRootResource);
*aResource = mRootResource;
return NS_OK;
}
NS_IMETHODIMP
XULDataSourceImpl::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) {
nsIRDFXMLDataSourceObserver* obs = (nsIRDFXMLDataSourceObserver*) mObservers[i];
obs->OnCSSStyleSheetAdded(this, aCSSStyleSheetURL);
}
return NS_OK;
}
NS_IMETHODIMP
XULDataSourceImpl::GetCSSStyleSheetURLs(nsIURL*** aCSSStyleSheetURLs, PRInt32* aCount)
{
*aCSSStyleSheetURLs = mCSSStyleSheetURLs;
*aCount = mNumCSSStyleSheetURLs;
return NS_OK;
}
NS_IMETHODIMP
XULDataSourceImpl::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) {
nsIRDFXMLDataSourceObserver* obs = (nsIRDFXMLDataSourceObserver*) mObservers[i];
obs->OnNamedDataSourceAdded(this, aNamedDataSourceURI);
}
return NS_OK;
}
NS_IMETHODIMP
XULDataSourceImpl::GetNamedDataSourceURIs(const char* const** aNamedDataSourceURIs, PRInt32* aCount)
{
*aNamedDataSourceURIs = mNamedDataSourceURIs;
*aCount = mNumNamedDataSourceURIs;
return NS_OK;
}
NS_IMETHODIMP
XULDataSourceImpl::AddNameSpace(nsIAtom* aPrefix, const nsString& aURI)
{
NameSpaceMap* entry;
// ensure that URIs are unique
for (entry = mNameSpaces; entry != nsnull; entry = entry->Next) {
if (aURI.Equals(entry->URI))
return NS_OK;
}
// okay, it's a new one: let's add it.
entry = new NameSpaceMap;
if (! entry)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(aPrefix);
entry->Prefix = aPrefix;
entry->URI = aURI;
entry->Next = mNameSpaces;
mNameSpaces = entry;
return NS_OK;
}
NS_IMETHODIMP
XULDataSourceImpl::AddXMLStreamObserver(nsIRDFXMLDataSourceObserver* aObserver)
{
mObservers.AppendElement(aObserver);
return NS_OK;
}
NS_IMETHODIMP
XULDataSourceImpl::RemoveXMLStreamObserver(nsIRDFXMLDataSourceObserver* aObserver)
{
mObservers.RemoveElement(aObserver);
return NS_OK;
}

Binary file not shown.

View File

@@ -0,0 +1,4 @@
#include "DefinesMac.h"
#include "DefinesMozilla.h"
#include "IDE_Options.h"
#include "ansi_prefix.mac.h"

View File

@@ -0,0 +1,21 @@
# target: rdf.shlb
mozilla/rdf/base/src/nsCompositeDataSource.cpp
mozilla/rdf/base/src/nsContainerCursor.cpp
mozilla/rdf/base/src/nsEmptyCursor.cpp
mozilla/rdf/base/src/nsInMemoryDataSource.cpp
mozilla/rdf/base/src/nsRDFContentSink.cpp
mozilla/rdf/base/src/nsRDFService.cpp
mozilla/rdf/base/src/nsRDFXMLDataSource.cpp
mozilla/rdf/base/src/rdfutil.cpp
mozilla/rdf/build/nsRDFFactory.cpp
mozilla/rdf/content/src/nsRDFContentUtils.cpp
mozilla/rdf/content/src/nsRDFDocument.cpp
mozilla/rdf/content/src/nsRDFGenericElement.cpp
mozilla/rdf/content/src/nsRDFHTMLBuilder.cpp
mozilla/rdf/content/src/nsRDFResourceElement.cpp
mozilla/rdf/content/src/nsRDFTreeBuilder.cpp
mozilla/rdf/content/src/nsRDFXULBuilder.cpp
mozilla/rdf/datasource/src/nsBookmarkDataSource.cpp
mozilla/rdf/datasource/src/nsMailDataSource.cpp
mozilla/rdf/datasource/src/nsXULContentSink.cpp
mozilla/rdf/datasource/src/nsXULDataSource.cpp

View File

@@ -0,0 +1,6 @@
#define DEBUG
#include "DefinesMac.h"
#include "DefinesMozilla.h"
#include "IDE_Options.h"
#include "ansi_prefix.mac.h"

29
mozilla/rdf/makefile.win Normal file
View File

@@ -0,0 +1,29 @@
#!gmake
#
# 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.
DEPTH=..
MODULE = rdf
DIRS=\
base \
content \
datasource \
build \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,318 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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.
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "rdf.h"
#include "gs.h"
void describeItem (WriteClientProc callBack, void* obj, RDF_Resource u) ;
void describeItemSimple (WriteClientProc callBack, void* obj, RDF_Resource u) ;
extern int startsWith(const char* prefix, const char* pattern);
RDF_Resource gNarrow;
RDF_Resource gLink;
RDF_Resource gName;
RDF_Resource gTopic;
RDF_Resource gDesc;
RDF_Resource gEditor;
RDF_Resource gNewsGroup;
char* gTemplate;
int gInited = 0;
#define MAX_TEMPLATE_SIZE 20000
RDF_Resource
getNodeFromQuery (char* query) {
RDF_Resource ans;
if (!(ans = RDF_GetResource(query, 0))) {
return RDF_GetResource("Top", 1);
} else return ans;
}
#define ROW_WIDTH 3
#define PREFIX "<form method=get action=\"OpenDir?\"><B>Search:</B> <input size=25 name=search> <input type=submit value=search><br><BR><BR></form><div align=right><a href=\"/odoptions.html\">Personalize</a></div>"
void
SortResourceList (RDF_Resource* list, size_t n, char sortType) {
if (sortType == 'd') {
} else {
}
}
void
listParents(WriteClientProc callBack, void* obj, RDF_Resource node, int depth) {
RDF_Resource narrow = RDF_GetResource("narrow", 1);
RDF_Resource parent = RDF_OnePropSource(0, node, narrow);
char* id = RDF_ResourceID(node);
char* nm = (char*) RDF_OnePropValue(0, node, gName, RDF_STRING_TYPE);
char* cnm = strrchr(id, '/');
char buff[500];
if (!nm || strchr(nm, '/')) nm = (cnm ? cnm + 1 : id);
if ((depth < 10) && parent) listParents(callBack, obj, parent, depth+1);
sprintf(buff, "<B><a href=\"OpenDir?browse=%s\">%s</a> > </B> ", id, nm);
(*callBack)(obj, buff);
}
char
cookiePropValue (char* cookie, char* prop) {
size_t len = strlen(prop);
char* str = strstr(cookie, prop);
if (!str) {
return 0;
} else {
return *(str + len + 1);
}
}
void
Init () {
if (!gInited) {
int n = 0;
FILE *templateFile = fopen("template.html", "r");
if (!templateFile) printf("Could not open template!\n");
gInited = 1;
gNarrow = RDF_GetResource("narrow", 1);
gLink = RDF_GetResource("link", 1);
gName = RDF_GetResource("Title", 1);
gTopic = RDF_GetResource("Topic", 1);
gDesc = RDF_GetResource("Description", 1);
gEditor = RDF_GetResource("editor", 1);
gNewsGroup = RDF_GetResource("newsGroup", 1);
gTemplate = (char*) malloc(MAX_TEMPLATE_SIZE+1);
memset(gTemplate, '\0', MAX_TEMPLATE_SIZE);
n = fread(gTemplate, 1, MAX_TEMPLATE_SIZE, templateFile);
gTemplate[n] = '\0';
fclose(templateFile);
}
}
char*
resourceName (RDF_Resource u) {
char* nm = (char*) RDF_OnePropValue(0, u, gName, RDF_STRING_TYPE);
char* id = RDF_ResourceID(u);
if (!nm || strchr(nm, '/')) nm = strrchr(id, '/') +1;
return nm;
}
void
outputTopicName (WriteClientProc callBack, void* obj, RDF_Resource node) {
char* nm = (char*) RDF_OnePropValue(0, node, gName, RDF_STRING_TYPE);
char* id = RDF_ResourceID(node);
if (!nm || strchr(nm, '/'))
if (strchr(id, '/')) {
nm = strrchr(id, '/') +1;
} else {
nm = id;
}
(*callBack)(obj, nm);
}
void
listSubTopics (WriteClientProc callBack, void* obj, RDF_Resource node, char* cookie, RDF_Resource p) {
if (node) {
RDF_Cursor c = RDF_GetTargets(0, node, p, RDF_RESOURCE_TYPE);
char widthc = cookiePropValue(cookie, "cols");
RDF_Resource u;
char buff[5000];
RDF_Resource subTopicList[200];
int n = 0;
int w = 0;
while (u = (RDF_Resource) RDF_NextValue(c)) {
subTopicList[n++] = u;
}
for (w = 0; w < n; w++) {
char* id;
if (((w == 0) || (w == ((n+1)/2))) && (p == gNarrow)) {
if (w != 0) (*callBack)(obj, "</td>");
(*callBack)(obj, "</UL>\n<TD width=\"40%\" valign=top><UL><FONT Face=\"sans-serif, Arial, Helvetica\">\n<UL>\n");
}
u = subTopicList[n-w-1];
id = RDF_ResourceID(u);
if (p == gNarrow) {
sprintf(buff, "<li><a href=\"OpenDir?browse=%s\"><B>%s</B></a>\n", id, resourceName(u));
} else {
char* des = (char*) RDF_OnePropValue(0, u, gDesc, RDF_STRING_TYPE);
sprintf(buff, "<li><a href=\"%s\">%s</a> %s %s\n", id, resourceName(u),
(des ? " : " : ""), (des ? des : ""));
}
(*callBack)(obj, buff);
}
}
}
void
AnswerOpenDirQuery (WriteClientProc callBack, void* obj, char *query, char* cookie) {
RDF_Resource node = getNodeFromQuery(query);
size_t n = 0;
char buff[MAX_TEMPLATE_SIZE];
char* pbegin = 0;
char* begin;
Init();
begin = gTemplate;
while (pbegin = strstr(begin, "&Topic")) {
memset(buff, '\0', 10000);
memcpy(buff, begin, pbegin-begin);
(*callBack)(obj, buff);
if (startsWith("&TopicName;", pbegin)) {
outputTopicName(callBack, obj, node);
} else if (startsWith("&TopicPath;", pbegin)) {
listParents(callBack, obj, node, 0);
} else if (startsWith("&TopicSubTopics;", pbegin)) {
listSubTopics(callBack, obj, node, cookie, gNarrow);
} else if (startsWith("&TopicItems;", pbegin)) {
listSubTopics(callBack, obj, node, cookie, gLink);
} else if (startsWith("&TopicAddURL;", pbegin)) {
(*callBack)(obj, "http://directory.mozilla.org/cgi-bin/add.cgi?where=");
(*callBack)(obj, RDF_ResourceID(node));
} else if (startsWith("&TopicBecomeEditor;", pbegin)) {
(*callBack)(obj, "http://directory.mozilla.org/cgi-bin/apply.cgi?where=");
(*callBack)(obj, RDF_ResourceID(node));
}
begin = pbegin + (strchr(pbegin, ';') - pbegin) + 1;
}
(*callBack)(obj, begin);
}
void describeCategory (WriteClientProc callBack, void* obj, RDF_Resource u) {
char buff[1000];
sprintf(buff, "<li><B><a href=\"OpenDir?browse=%s\">%s</a></B>", RDF_ResourceID(u),
RDF_ResourceID(u));
(*callBack)(obj, buff);
}
#define MRN 1000
char*
xGetMem (size_t n) {
char* ans = (char*) malloc(n);
if (ans) memset(ans, '\0', n);
return ans;
}
void
xFreeMem(void* item) {
free(item);
}
RDF_Resource
stToProp (char c) {
if (!c || (c == 'a')) {
return 0;
} else if (c == 'n') {
return gName;
} else if (c == 'd') {
return gDesc;
} else return 0;
}
void
AnswerSearchQuery (WriteClientProc callBack, void* obj, char *query, char* cookie) {
char st = cookiePropValue(cookie, "searchTarget");
RDF_Cursor c = RDFGS_Search(0, query, stToProp(st));
RDF_Resource topic = RDF_GetResource("Topic", 1);
RDF_Resource type = RDF_GetResource("type", 1);
RDF_Resource u ;
size_t catn = 0;
size_t itemn = 0;
size_t index;
RDF_Resource* cats = (RDF_Resource*)xGetMem(sizeof(RDF_Resource) * (MRN + 1));
RDF_Resource* items = (RDF_Resource*)xGetMem(sizeof(RDF_Resource) * (MRN + 1));
char showDesc = cookiePropValue(cookie, "searchDesc");
(*callBack)(obj, PREFIX);
(*callBack)(obj, "<B>Search : ");
(*callBack)(obj, query);
(*callBack)(obj, "</B>");
while ((u = (RDF_Resource) RDFGS_NextValue(c)) &&
(itemn < MRN-1) && (catn < MRN-1)) {
if (RDF_HasAssertion(0, u, type, topic, RDF_RESOURCE_TYPE)) {
cats[catn++] = u;
} else {
items[itemn++] = u;
}
}
RDFGS_DisposeCursor(c);
if (catn > 0) {
(*callBack)(obj, "<HR><B>Matching Categories :</B><BR>");
(*callBack)(obj, "<UL>");
for (index = 0; index < catn ; index++) {
if (cats[index]) describeCategory(callBack, obj, cats[index]);
}
(*callBack)(obj, "</UL>");
}
if (itemn > 0) {
(*callBack)(obj, "<HR><B>Matching Links :</B><BR><UL>");
for (index = 0; index < itemn ; index++) {
if (items[index]) {
if (showDesc == 'n') {
describeItemSimple(callBack, obj, items[index]);
} else {
describeItem(callBack, obj, items[index]);
}
}
}
(*callBack)(obj, "</UL>");
}
xFreeMem(items);
xFreeMem(cats);
}
void
describeItemSimple (WriteClientProc callBack, void* obj, RDF_Resource u) {
char buff[5000];
char* nm = (char*) RDF_OnePropValue(0, u, gName, RDF_STRING_TYPE);
char* id = RDF_ResourceID(u);
sprintf(buff, "<li><a href=\"%s\">%s</a>", id, (nm ? nm : id));
(*callBack)(obj, buff);
}
void
describeItem (WriteClientProc callBack, void* obj, RDF_Resource u) {
char buff[5000];
char* nm = (char*) RDF_OnePropValue(0, u, gName, RDF_STRING_TYPE);
char* id = RDF_ResourceID(u);
char* des = (char*) RDF_OnePropValue(0, u, gDesc, RDF_STRING_TYPE);
sprintf(buff, "<li><a href=\"%s\">%s</a> %s %s", id, (nm ? nm : id),
(des ? " : " : ""), (des ? des : ""));
(*callBack)(obj, buff);
}

229
mozilla/rdf/opendir/gs.c Normal file
View File

@@ -0,0 +1,229 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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.
*/
// 39204897
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include "rdf-int.h"
#include "gs.h"
typedef struct _TrieNodeStruct {
char c;
struct _TrieNodeStruct* child;
struct _TrieNodeStruct* next;
struct _TrieTargetStruct* targets;
} TrieNodeStruct;
typedef TrieNodeStruct* TNS;
typedef struct _TrieTargetStruct {
RDF_Resource label;
RDF_Resource target;
struct _TrieTargetStruct* next;
RDFT db;
} TrieTargetStruct;
typedef TrieTargetStruct* TTS;
static TNS gRootNode = 0;
int
addTarget (RDFT db, TNS node, RDF_Resource label, RDF_Resource targetNode) {
TTS target ;
int n = 0;
/* for (target = node->targets; target != null; target = target->next) {
if (target->target == targetNode) return 0;
n++;
} */
target = (TTS) fgetMem(sizeof(TrieTargetStruct));
target->next = node->targets;
node->targets = target;
target->label = label;
target->target = targetNode;
target->db = db;
return n;
}
TNS
findChildOfChar (TNS node, char c) {
TNS ch = node->child;
char c1 = tolower(c);
int n = 0;
while (ch) {
if (c1 == ch->c) return ch;
ch = ch->next;
n++;
}
return 0;
}
TNS
findChildOfString (TNS node, char* str) {
size_t size = strlen(str);
size_t n = 0;
while (n < size) {
char c = str[n++];
node = findChildOfChar(node, c);
if (!node) return 0;
}
return node;
}
void RDFGS_AddSearchIndex (RDFT db, char* string, RDF_Resource label, RDF_Resource target) {
size_t size = strlen(string);
size_t n = 0;
char* stk = 0;
TNS prev, next;
if (!gRootNode) gRootNode = (TNS) getMem(sizeof(TrieNodeStruct));
prev = gRootNode;
next = 0;
while (n < size) {
char c = string[n++];
if (!wsCharp(c) && (c != '/')) {
if (!stk) stk = &string[n-1];
next = (TNS) findChildOfChar(prev, c);
if (!next) {
next = (TNS)fgetMem(sizeof(TrieNodeStruct));
next->next = prev->child;
prev->child = next;
next->c = tolower(c);
}
prev = next;
} else if (next) {
int n = addTarget(db, next, label, target);
stk = 0;
prev = gRootNode;
next = 0;
}
}
if (next) {
addTarget(db, next, label, target);
prev = gRootNode;
next = 0;
}
}
void
countChildren (TNS node, size_t *n, size_t *m) {
TNS ch;
TTS tg ;
if (node->targets) (*n)++;
for (tg = node->targets; tg; tg = tg->next) (*m)++;
ch = node->child;
while (ch) {
countChildren(ch, n, m);
ch = ch->next;
}
}
void
fillUpChildren (RDF_Cursor c, TNS node) {
TNS ch;
if (node->targets) *((TTS*)c->pdata1 + c->count++) = node->targets;
ch = node->child;
while (ch) {
fillUpChildren(c, ch);
ch = ch->next;
}
}
RDF_Cursor RDFGS_Search (RDFT db, char* searchString, RDF_Resource label) {
RDF_Cursor c = (RDF_Cursor) getMem(sizeof(RDF_CursorStruct));
size_t n = 0;
size_t m = 0;
c->searchString = searchString;
c->s = label;
c->db = db;
c->pdata = findChildOfString(gRootNode, searchString);
if (!c->pdata) return c;
countChildren((TNS)c->pdata, &n, &m);
c->pdata2 = (RDF_Resource*) getMem(sizeof(RDF_Resource) * (m+1));
c->off1 = m;
if (n > 0) {
c->count = 0;
c->pdata1 = getMem(sizeof(TTS) * (n+1));
fillUpChildren(c, (TNS)c->pdata);
c->count = 1;
}
if (c->pdata) c->pdata = ((TNS)c->pdata)->targets;
return c;
}
void RDFGS_DisposeCursor (RDF_Cursor c) {
if (c->pdata1) freeMem(c->pdata1);
if (c->pdata2) freeMem(c->pdata2);
freeMem(c);
}
int
alreadyAdded(RDF_Resource node, RDF_Cursor c) {
int n =0;
while (c->pdata2[n] && (n < c->off)) {
if (c->pdata2[n] == node) return 1;
n++;
}
return 0;
}
RDF_Resource RDFGS_NextValue (RDF_Cursor c) {
if (!c->pdata) {
return 0;
} else {
TTS currentTTS = (TTS) c->pdata;
while (currentTTS) {
if (((!c->s) || (c->s == currentTTS->label)) &&
(!alreadyAdded(currentTTS->target, c))) {
RDF_Resource ans = currentTTS->target;
c->pdata = currentTTS = currentTTS->next;
if (!currentTTS && (c->pdata1)) {
c->pdata = ((TTS*)c->pdata1)[c->count++];
}
if (c->off < c->off1) c->pdata2[c->off++] = ans;
return ans;
}
c->pdata = currentTTS = currentTTS->next;
if (!currentTTS && (c->pdata1)) {
c->pdata = currentTTS = ((TTS*)c->pdata1)[c->count++];
}
}
}
return 0;
}

Some files were not shown because too many files have changed in this diff Show More