Landed changes from RDF_19981124_BRANCH. This is still not in the build.

This commit is contained in:
waterson%netscape.com 1998-12-01 03:01:35 +00:00
parent ce4f25a746
commit 5ca3227fb5
47 changed files with 6970 additions and 3093 deletions

View File

@ -23,11 +23,14 @@ DEPTH = ..\..
EXPORTS = rdf.h \
rdfc.h \
nsIRDFService.h \
nsIRDFDataSource.h \
nsIRDFDataBase.h \
nsIRDFObserver.h \
nsIRDFCursor.h \
nsIRDFDataBase.h \
nsIRDFDataSource.h \
nsIRDFNode.h \
nsIRDFObserver.h \
nsIRDFRegistry.h \
nsIRDFResourceManager.h \
nsIRDFService.h \
nsRDFCID.h \
htrdf.h \
vocab.h \

View File

@ -44,10 +44,13 @@
class nsIRDFCursor : public nsISupports {
public:
NS_IMETHOD HasElements(PRBool& hasElements) = 0;
NS_IMETHOD HasMoreElements(PRBool& result /* out */) = 0;
NS_IMETHOD Next(RDF_NodeStruct& next /* in/out */) = 0;
// XXX If the node struct contains an nsIAtom, did you refcount it
// before returning?
NS_IMETHOD GetNext(nsIRDFNode*& next /* in/out */,
PRBool& tv /* out */) = 0;
};
#endif /* nsIRDFCursor_h__ */

View File

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
/* -*- 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
@ -20,54 +20,30 @@
#define nsIRDFDataBase_h__
/*
This file contains the interface definition for an RDF database.
RDF databases aggregate RDF data sources (see nsIRDFDataSource.h)
XXX This needs to be thought about real hard. It seems really wrong
to me to have to hard code the data sources that a database knows
about.
*/
#include "nsISupports.h"
#include "nsIRDFDataSource.h"
#include "rdf.h"
class nsIRDFDataSource;
// 96343820-307c-11d2-bc15-00805f912fe7
#define NS_IRDFDATABASE_IID \
{ \
0x96343820, \
0x307c, \
0x11d2, \
{ 0xb, 0x15, 0x00, 0x80, 0x5f, 0x91, 0x2f, 0xe7 } \
}
{ 0x96343820, 0x307c, 0x11d2, { 0xb, 0x15, 0x00, 0x80, 0x5f, 0x91, 0x2f, 0xe7 } }
class nsIRDFDataBase : public nsIRDFDataSource {
public:
#ifdef RDF_NOT_IMPLEMENTED
NS_IMETHOD Initialize(nsIRDFResourceManager* r) = 0;
#endif
#ifdef RDF_NOT_IMPLEMENTED
/*
Add a data source for the specified URL to the database.
Parameters:
dataSource -- a ptr to the data source to add
Returns:
*/
NS_IMETHOD AddDataSource(nsIRDFDataSource* dataSource) = 0;
NS_IMETHOD RemoveDataSource(nsIRDFDataSource* dataSource) = 0;
NS_IMETHOD GetDataSource(RDF_String url,
nsIRDFDataSource **source /* out */ ) = 0;
#endif
// XXX move these to datasource?
NS_IMETHOD DeleteAllArcs(RDF_Resource resource) = 0;
// XXX This is really a hack. I wish that the database was just a
// plain old data source that was smart import the data sources
// that it needed.
NS_IMETHOD AddDataSource(nsIRDFDataSource* source) = 0;
};

View File

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
/* -*- 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
@ -21,209 +21,124 @@
/*
This file contains the interface definition for an RDF data source.
Classes which implement this interface for a particular type of URL
are registered with the RDF singleton via nsIRDF::RegisterHandler(...)
*/
#include "nsISupports.h"
#include "rdf.h"
// 852666b0-2cce-11d2-bc14-00805f912fe7
// {0F78DA58-8321-11d2-8EAC-00805F29F370}
#define NS_IRDFDATASOURCE_IID \
{ \
0x852666b0, \
0x2cce, \
0x11d2, \
{ 0xb, 0xc14,0x00, 0x80, 0x5f, 0x91 0x2f, 0xe7 } \
}
{ 0xf78da58, 0x8321, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
class nsIRDFNode;
class nsIRDFCursor;
class nsIRDFObserver;
class nsIRDFDataBase;
class nsString;
// XXX I didn't make any of these methods "const" because it's
// probably pretty likely that many data sources will just make stuff
// up at runtime to answer queries.
class nsIRDFDataSource : public nsISupports {
public:
/**
* 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 Initialize(const nsString& uri) = 0;
#ifdef RDF_NOT_IMPLEMENTED
/**
* Initialize this data source
*/
NS_IMETHOD Initialize(RDF_String url,
nsIRDFResourceManager* m);
#endif
/**
* Find an RDF resource that points to a given node over the
* specified arc & truth value
*/
NS_IMETHOD GetSource(nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFNode*& source /* out */) = 0;
NS_IMETHOD GetResource(RDF_String id,
RDF_Resource * r) = 0;
/**
* Find all RDF resources that point to a given node over the
* specified arc & truth value
*/
NS_IMETHOD GetSources(nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFCursor*& sources /* out */) = 0;
NS_IMETHOD CreateResource(RDF_String id,
RDF_Resource* r) = 0;
/**
* Find a child of that is related to the source by the given arc
* arc and truth value
*/
NS_IMETHOD GetTarget(nsIRDFNode* source,
nsIRDFNode* property,
PRBool tv,
nsIRDFNode*& target /* out */) = 0;
NS_IMETHOD ReleaseResource(RDF_Resource r) = 0;
/**
* Find all children of that are related to the source by the given arc
* arc and truth value
*/
NS_IMETHOD GetTargets(nsIRDFNode* source,
nsIRDFNode* property,
PRBool tv,
nsIRDFCursor*& targets /* out */) = 0;
/**
* Get the name of this data source.
*
* For regular data sources, this will be the URL of the source.
*
* For aggregated sources, it generally will not be a valid RDF URL.
*/
NS_IMETHOD GetName(const RDF_String* name /* out */ ) = 0;
/**
* Add an assertion to the graph.
*/
NS_IMETHOD Assert(nsIRDFNode* source,
nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv = PR_TRUE) = 0;
/**
* Find an RDF resource that points to a given node over the
* specified arc & truth value (defaults to "PR_TRUE").
*/
NS_IMETHOD GetSource(RDF_Node target,
RDF_Resource arcLabel,
RDF_Resource *source /* out */) = 0;
/**
* Remove an assertion from the graph.
*/
NS_IMETHOD Unassert(nsIRDFNode* source,
nsIRDFNode* property,
nsIRDFNode* target) = 0;
NS_IMETHOD GetSource(RDF_Node target,
RDF_Resource arcLabel,
PRBool tv,
RDF_Resource *source /* out */) = 0;
/**
* Query whether an assertion exists in this graph.
*
*/
NS_IMETHOD HasAssertion(nsIRDFNode* source,
nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv,
PRBool& hasAssertion /* out */) = 0;
/**
* Find all RDF resources that point to a given node over the
* specified arc & truth value (defaults to "PR_TRUE").
*/
NS_IMETHOD GetSources(RDF_Resource target,
RDF_Resource arcLabel,
nsIRDFCursor **sources /* out */) = 0;
/**
* Add an observer to this data source.
*/
NS_IMETHOD AddObserver(nsIRDFObserver* n) = 0;
NS_IMETHOD GetSources(RDF_Resource target,
RDF_Resource arcLabel,
PRBool tv,
nsIRDFCursor **sources /* out */) = 0;
/**
* Remove an observer from this data source
*/
NS_IMETHOD RemoveObserver(nsIRDFObserver* n) = 0;
/**
* Find a child of that is related to the source by the given arc
* arc and truth value (defaults to PR_TRUE).
*/
NS_IMETHOD GetTarget(RDF_Resource source,
RDF_Resource arcLabel,
RDF_ValueType targetType,
RDF_NodeStruct& target /* in/out */) = 0;
// XXX individual resource observers?
NS_IMETHOD GetTarget(RDF_Resource source,
RDF_Resource arcLabel,
RDF_ValueType targetType,
PRBool tv,
RDF_NodeStruct& target /* in/out */) = 0;
/**
* Get a cursor to iterate over all the arcs that point into a node.
*/
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
nsIRDFCursor*& labels /* out */) = 0;
/**
* Find all children of that are related to the source by the given arc
* arc and truth value (defaults to PR_TRUE).
*/
NS_IMETHOD GetTargets(RDF_Resource source,
RDF_Resource arcLabel,
RDF_ValueType targetType,
nsIRDFCursor **targets /* out */) = 0;
/**
* Get a cursor to iterate over all the arcs that originate in
* a resource.
*/
NS_IMETHOD ArcLabelsOut(nsIRDFNode* source,
nsIRDFCursor*& labels /* out */) = 0;
NS_IMETHOD GetTargets(RDF_Resource source,
RDF_Resource arcLabel,
PRBool tv,
RDF_ValueType targetType,
nsIRDFCursor **targets /* out */) = 0;
#ifdef RDF_NOT_IMPLEMENTED
/**
* Find all parents that point to a node over a given arc label,
* regardless of truth value.
*/
NS_IMETHOD GetAllSources(RDF_Node target,
RDF_Resource arcLabel,
nsIRDFCursor2 **sources /* out */) = 0;
/**
* Find all children of a resource that are related by the
* given arc label, regardless of the truth value.
*/
NS_IMETHOD GetAllTargets(RDF_Resource source,
RDF_Resource arcLabel,
RDF_ValueType targetType,
nsIRDFCursor2 **targets /* out */);
#endif /* RDF_NOT_IMPLEMENTED */
/**
* Add an assertion to the graph.
*/
NS_IMETHOD Assert(RDF_Resource source,
RDF_Resource arcLabel,
RDF_Node target,
PRBool tv = PR_TRUE) = 0;
/**
* Remove an assertion from the graph.
*/
NS_IMETHOD Unassert(RDF_Resource source,
RDF_Resource arcLabel,
RDF_Node target) = 0;
/**
* Query whether an assertion exists in this graph.
*
*/
NS_IMETHOD HasAssertion(RDF_Resource source,
RDF_Resource arcLabel,
RDF_Node target,
PRBool truthValue,
PRBool* hasAssertion /* out */) = 0;
/**
* Add an observer to this data source.
*/
NS_IMETHOD AddObserver(nsIRDFObserver *n,
RDF_EventMask type = RDF_ANY_NOTIFY) = 0;
/**
* Remove an observer from this data source
*/
NS_IMETHOD RemoveObserver(nsIRDFObserver *n,
RDF_EventMask = RDF_ANY_NOTIFY) = 0;
/**
* Get a cursor to iterate over all the arcs that point into a node.
*/
NS_IMETHOD ArcLabelsIn(RDF_Node node,
nsIRDFCursor **labels /* out */) = 0;
/**
* Get a cursor to iterate over all the arcs that originate in
* a resource.
*/
NS_IMETHOD ArcLabelsOut(RDF_Resource source,
nsIRDFCursor **labels /* out */) = 0;
#ifdef RDF_NOT_IMPLEMENTED
/**
* Notify this data source that it is a child of a database.
*
* The datasource must send notifications to the parent when
* changes to it's graph are made, in case the parent has observers
* interested in the events generated.
*/
NS_IMETHOD AddParent(nsIRDFDataBase* parent) = 0;
/**
* Notify this data source that it has been disconnected from a
* parent.
*/
NS_IMETHOD RemoveParent(nsIRDFDataBase* parent) = 0;
/**
* Request that a data source obtain updates if applicable.
*/
// XXX move this to an nsIRDFRemoteDataStore interface?
NS_IMETHOD Update(RDF_Resource hint) = 0;
#endif /* RDF_NOT_IMPLEMENTED */
/**
* Request that a data source write it's contents out to
* permanent storage if applicable.
*/
NS_IMETHOD Flush() = 0;
/**
* Request that a data source write it's contents out to
* permanent storage if applicable.
*/
NS_IMETHOD Flush() = 0;
};

66
rdf/include/nsIRDFNode.h Normal file
View File

@ -0,0 +1,66 @@
/* -*- 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 nsIRDFNode_h__
#define nsIRDFNode_h__
#include "nsISupports.h"
class nsString;
class nsIAtom;
// {0F78DA50-8321-11d2-8EAC-00805F29F370}
#define NS_IRDFNODE_IID \
{ 0xf78da50, 0x8321, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
/**
A globally unique node in the RDF graph that can be compared
for equality using "==". Nodes are created using an instance of
nsIRDFResourceManager, which should be obtained from the service
manager:
nsIRDFResourceManager* mgr;
if (NS_SUCCEEDED(nsServiceManager::GetService(kCRDFResourceManagerCID,
kIRDFResourceManagerIID,
&mgr))) {
nsIRDFNode* node;
if (NS_SUCCEEDED(mgr->GetNode(nsString("http://foo.bar/"), node))) {
// do something useful here...
NS_IF_RELEASE(node);
}
nsServiceManager::ReleaseService(kCRDFManagerCID, mgr);
}
*/
class nsIRDFNode : public nsISupports {
public:
/**
* Get the string value of the node.
*/
NS_IMETHOD GetStringValue(nsString& value) const = 0;
/**
* Get the string value of the node as an atom
*/
NS_IMETHOD GetAtomValue(nsIAtom*& value) const = 0;
};
#endif // nsIRDFNode_h__

View File

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* -*- 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
@ -41,10 +41,7 @@ class nsIRDFDataSource;
class nsIRDFObserver : public nsISupports
{
public:
NS_IMETHOD HandleEvent(nsIRDFDataSource *source,
RDF_Event event) = 0;
};

View File

@ -0,0 +1,57 @@
/* -*- 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 nsIRDFRegistry_h__
#define nsIRDFRegistry_h__
#include "nsISupports.h"
class nsString;
class nsIRDFDataSource;
// {E638D762-8687-11d2-B530-000000000000}
#define NS_IRDFREGISTRY_IID \
{ 0xe638d762, 0x8687, 0x11d2, { 0xb5, 0x30, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
/**
* The RDF registry manages the RDF data sources.
*/
class nsIRDFRegistry : public nsISupports {
public:
/**
* Registers the specified prefix as being handled by the
* data source. Note that the data source will <em>not</em>
* be reference counted.
*/
NS_IMETHOD Register(const nsString& prefix, nsIRDFDataSource* dataSource) = 0;
/**
* Unregisters the data source from the registry.
*/
NS_IMETHOD Unregister(const nsIRDFDataSource* dataSource) = 0;
/**
* Looks for a data source that will handle the specified URI.
*/
NS_IMETHOD Find(const nsString& uri, nsIRDFDataSource*& result) = 0;
};
#endif nsIRDFRegistry_h__

View File

@ -0,0 +1,37 @@
/* -*- 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 nsIRDFResourceManager_h__
#define nsIRDFResourceManager_h__
#include "nsISupports.h"
class nsString;
class nsIRDFNode;
// {BFD05261-834C-11d2-8EAC-00805F29F370}
#define NS_IRDFRESOURCEMANAGER_IID \
{ 0xbfd05261, 0x834c, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
class nsIRDFResourceManager : public nsISupports {
public:
NS_IMETHOD GetNode(const nsString& uri, nsIRDFNode*& resource) = 0;
};
#endif // nsIRDFResourceManager_h__

View File

@ -19,13 +19,34 @@
#ifndef nsRDFCID_h__
#define nsRDFCID_h__
// {2564E6E0-79C9-11d2-B51D-000000000000}
#define NS_RDFTREEDATAMODEL_CID \
{ 0x2564e6e0, 0x79c9, 0x11d2, { 0xb5, 0x1d, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
// {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_RDFRESOURCEMANAGER_CID \
{ 0xbfd05264, 0x834c, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
// {BFD0526D-834C-11d2-8EAC-00805F29F370}
#define NS_RDFMEMORYDATASOURCE_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_RDFSIMPLEDATABASE_CID \
{ 0xe638d761, 0x8687, 0x11d2, { 0xb5, 0x30, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
// {E638D763-8687-11d2-B530-000000000000}
#define NS_RDFREGISTRY_CID \
{ 0xe638d763, 0x8687, 0x11d2, { 0xb5, 0x30, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
// {954F0813-81DC-11d2-B52A-000000000000}
#define NS_RDFDOCUMENT_CID \
{ 0x954f0813, 0x81dc, 0x11d2, { 0xb5, 0x2a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
// {6B13A9C0-79C9-11d2-B51D-000000000000}
#define NS_RDFTOOLBARDATAMODEL_CID \
{ 0x6b13a9c0, 0x79c9, 0x11d2, { 0xb5, 0x1d, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
#endif // nsRDFCID_h__

View File

@ -23,6 +23,26 @@
#include "nspr.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
typedef int RDF_Error;
#define RDF_ERROR_ILLEGAL_ASSERT 1 /* NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_RDF,1) */
@ -58,17 +78,6 @@ typedef struct RDF_BlobStruct {
} *RDF_Blob;
#endif
typedef struct RDF_NodeStruct {
RDF_ValueType type;
union {
RDF_Resource r;
RDF_String s;
#ifdef RDF_BLOB
RDF_Blob b;
#endif
} value;
} *RDF_Node;
typedef PRUint32 RDF_EventType;
#define RDF_ASSERT_NOTIFY ((RDF_EventType)0x00000001)
#define RDF_DELETE_NOTIFY ((RDF_EventType)0x00000002)

View File

@ -1,712 +0,0 @@
/* -*- 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.
*/
#include "rdf.h"
#include "nspr.h"
#include "plhash.h"
PR_BEGIN_EXTERN_C
PR_PUBLIC_API(void) _comwrap_NotificationCB(RDF_Event event, void* pdata);
PR_END_EXTERN_C
class rdfDataBaseWrapper;
class rdfCursorWrapper;
class rdfServiceWrapper;
class rdfServiceFactory;
static nsIRDFService* gRDFServiceSingleton = 0;
class rdfDatabaseWrapper : public nsIRDFDataBase {
public:
NS_DECL_ISUPPORTS
rdfDatabaseWrapper(RDF r);
virtual ~rdfDatabaseWrapper();
/* nsIRDFDataSource methods: */
NS_METHOD GetResource(RDF_String id,
RDF_Resource * r);
NS_METHOD CreateResource(RDF_String id,
RDF_Resource* r);
NS_METHOD ReleaseResource(RDF_Resource r);
NS_METHOD GetName(const RDF_String* name /* out */ );
NS_METHOD GetSource(RDF_Node target,
RDF_Resource arcLabel,
RDF_Resource *source /* out */);
NS_METHOD GetSource(RDF_Node target,
RDF_Resource arcLabel,
PRBool tv,
RDF_Resource *source /* out */);
NS_METHOD GetSources(RDF_Resource target,
RDF_Resource arcLabel,
nsIRDFCursor **sources /* out */);
NS_METHOD GetSources(RDF_Resource target,
RDF_Resource arcLabel,
PRBool tv,
nsIRDFCursor **sources /* out */);
NS_METHOD GetTarget(RDF_Resource source,
RDF_Resource arcLabel,
RDF_ValueType targetType,
RDF_NodeStruct& target /* in/out */);
NS_METHOD GetTarget(RDF_Resource source,
RDF_Resource arcLabel,
RDF_ValueType targetType,
PRBool tv,
RDF_NodeStruct& target /* in/out */);
NS_METHOD GetTargets(RDF_Resource source,
RDF_Resource arcLabel,
RDF_ValueType targetType,
nsIRDFCursor **targets /* out */);
NS_METHOD GetTargets(RDF_Resource source,
RDF_Resource arcLabel,
PRBool tv,
RDF_ValueType targetType,
nsIRDFCursor **targets /* out */);
NS_METHOD Assert(RDF_Resource source,
RDF_Resource arcLabel,
RDF_Node target,
PRBool tv = PR_TRUE);
NS_METHOD Unassert(RDF_Resource source,
RDF_Resource arcLabel,
RDF_Node target);
NS_METHOD HasAssertion(RDF_Resource source,
RDF_Resource arcLabel,
RDF_Node target,
PRBool tv,
PRBool* hasAssertion /* out */);
NS_METHOD AddObserver(nsIRDFObserver *n,
RDF_EventMask type = RDF_ANY_NOTIFY);
NS_METHOD RemoveObserver(nsIRDFObserver *n,
RDF_EventMask = RDF_ANY_NOTIFY);
NS_METHOD ArcLabelsIn(RDF_Node node,
nsIRDFCursor **labels /* out */);
NS_METHOD ArcLabelsOut(RDF_Resource source,
nsIRDFCursor **labels /* out */);
NS_METHOD Flush();
/* nsIRDFDataBase methods: */
NS_METHOD AddDataSource(nsIRDFDataSource* dataSource);
NS_METHOD RemoveDataSource(nsIRDFDataSource* dataSource);
NS_METHOD GetDataSource(RDF_String url,
nsIRDFDataSource **source /* out */ );
NS_METHOD DeleteAllArcs(RDF_Resource resource);
private:
RDF mRDF;
PLHashTable* mpObserverMap;
};
class rdfCursorWrapper : public nsIRDFCursor {
public:
NS_DECL_ISUPPORTS
rdfCursorWrapper(RDF_Cursor c);
virtual ~rdfCursorWrapper();
NS_METHOD HasElements(PRBool& hasElements);
NS_METHOD Next(RDF_NodeStruct& n);
private:
RDF_Cursor mCursor;
PRBool mHasCached;
RDF_NodeStruct mNextValue;
};
class rdfServiceWrapper : public nsIRDFService {
public:
NS_DECL_ISUPPORTS
rdfServiceWrapper();
virtual ~rdfServiceWrapper();
NS_METHOD CreateDatabase(const char** url,
nsIRDFDataBase** db);
NS_METHOD ResourceIdentifier(RDF_Resource r,
char** url /* out */);
#ifdef MOZILLA_CLIENT
NS_METHOD SetBookmarkFile(const char* bookmarkFilePath);
#endif
};
class rdfServiceFactory : public nsIFactory {
public:
NS_DECL_ISUPPORTS
rdfServiceFactory();
virtual ~rdfServiceFactory();
NS_METHOD CreateInstance(nsISupports *aOuter,
REFNSIID anIID,
void **aResult);
NS_METHOD LockFactory(PRBool aLock);
};
/*
rdfDataBaseWrapper:
*/
static NS_DEFINE_IID(kIRDFDataBaseIID, NS_IRDFDATABASE_IID);
NS_IMPL_ISUPPORTS( rdfDatabaseWrapper, kIRDFDataBaseIID )
rdfDatabaseWrapper::rdfDatabaseWrapper(RDF r) : mRDF(r)
{
mpObserverMap = PL_NewHashTable( 100,
NULL, // XXX isn't there are hash fn for pointers???
PL_CompareValues,
PL_CompareValues,
0,
0 );
PR_ASSERT( mpObserverMap );
#ifdef XXX
if( !mpObserverMap ) // XXX just like 'new' failing on this object?
throw bad_alloc("rdf: unable to allocate observer map" );
#endif
}
rdfDatabaseWrapper::~rdfDatabaseWrapper()
{
PL_HashTableDestroy( mpObserverMap );
}
NS_METHOD
rdfDatabaseWrapper::GetResource(RDF_String id,
RDF_Resource * r)
{
PR_ASSERT( 0 != r );
if( 0 == r )
return NS_ERROR_NULL_POINTER;
*r = 0;
*r = RDF_GetResource( mRDF, id, PR_FALSE );
return NS_OK;
}
NS_METHOD
rdfDatabaseWrapper::CreateResource(RDF_String id,
RDF_Resource* r)
{
PR_ASSERT( 0 != r );
if( 0 == r )
return NS_ERROR_NULL_POINTER;
*r = 0;
*r = RDF_GetResource( mRDF, id, PR_TRUE );
if( 0 == *r ) { // XXX
PR_ASSERT( PR_FALSE );
return NS_ERROR_BASE;
}
return NS_OK;
}
NS_METHOD
rdfDatabaseWrapper::ReleaseResource(RDF_Resource r)
{
RDF_ReleaseResource( mRDF, r );
return NS_OK;
}
NS_METHOD
rdfDatabaseWrapper::GetName(const RDF_String* name /* out */ )
{
PR_ASSERT( PR_FALSE );
return NS_ERROR_NOT_IMPLEMENTED; // XXX
}
NS_METHOD
rdfDatabaseWrapper::GetSource(RDF_Node target,
RDF_Resource arcLabel,
RDF_Resource *source /* out */)
{
PR_ASSERT( target && source );
*source = (RDF_Resource) RDF_GetSlotValue( mRDF,
target->value.r,
arcLabel,
RDF_RESOURCE_TYPE, // anything else makes no sense
PR_TRUE,
PR_TRUE );
return NS_OK;
}
NS_METHOD
rdfDatabaseWrapper::GetSource(RDF_Node target,
RDF_Resource arcLabel,
PRBool tv,
RDF_Resource *source /* out */)
{
*source = (RDF_Resource) RDF_GetSlotValue( mRDF,
target->value.r,
arcLabel,
RDF_RESOURCE_TYPE, // anything else makes no sense
PR_TRUE,
tv );
return NS_OK;
}
NS_METHOD
rdfDatabaseWrapper::GetSources(RDF_Resource target,
RDF_Resource arcLabel,
nsIRDFCursor **sources /* out */)
{
return GetSources(target,arcLabel,PR_TRUE,sources);
}
NS_METHOD
rdfDatabaseWrapper::GetSources(RDF_Resource target,
RDF_Resource arcLabel,
PRBool tv,
nsIRDFCursor **sources /* out */)
{
PR_ASSERT( sources );
if( 0 == sources )
return NS_ERROR_NULL_POINTER;
*sources = 0;
RDF_Cursor c = RDF_GetSources( mRDF,
target,
arcLabel,
RDF_RESOURCE_TYPE, // anything else makes no sense
tv );
if( c ) {
*sources = new rdfCursorWrapper( c );
(*sources)->AddRef();
}
return NS_OK;
}
NS_METHOD
rdfDatabaseWrapper::GetTarget(RDF_Resource source,
RDF_Resource arcLabel,
RDF_ValueType targetType,
RDF_NodeStruct& target /* in/out */)
{
return GetTarget(source,arcLabel,targetType,PR_TRUE,target);
}
NS_METHOD
rdfDatabaseWrapper::GetTarget(RDF_Resource source,
RDF_Resource arcLabel,
RDF_ValueType targetType,
PRBool tv,
RDF_NodeStruct& target /* in/out */)
{
PR_ASSERT( targetType != RDF_ANY_TYPE ); // not ready to support this yet
void* value = RDF_GetSlotValue( mRDF,
target.value.r,
arcLabel,
targetType, // anything else makes no sense
PR_FALSE,
tv );
target.type = targetType;
target.value.r = (RDF_Resource) value; // reasonable? XXX
return NS_OK;
}
NS_METHOD
rdfDatabaseWrapper::GetTargets(RDF_Resource source,
RDF_Resource arcLabel,
RDF_ValueType targetType,
nsIRDFCursor **targets /* out */)
{
return GetTargets(source,arcLabel,PR_TRUE,targetType,targets);
}
NS_METHOD
rdfDatabaseWrapper::GetTargets(RDF_Resource source,
RDF_Resource arcLabel,
PRBool tv,
RDF_ValueType targetType,
nsIRDFCursor **targets /* out */)
{
PR_ASSERT( targets );
if( 0 == targets )
return NS_ERROR_NULL_POINTER;
*targets = 0;
RDF_Cursor c = RDF_GetTargets( mRDF,
source,
arcLabel,
targetType,
tv );
if( c ) {
*targets = new rdfCursorWrapper( c );
(*targets)->AddRef();
}
return NS_OK;
}
NS_METHOD
rdfDatabaseWrapper::Assert(RDF_Resource source,
RDF_Resource arcLabel,
RDF_Node target,
PRBool tv)
{
PRBool b = tv ? RDF_Assert( mRDF, source, arcLabel, (void*)target->value.r, target->type ) :
RDF_AssertFalse( mRDF, source, arcLabel, (void*)target->value.r, target->type );
// XXX
return NS_OK;
}
NS_METHOD
rdfDatabaseWrapper::Unassert(RDF_Resource source,
RDF_Resource arcLabel,
RDF_Node target)
{
PRBool b = RDF_Unassert( mRDF,
source,
arcLabel,
target->value.r,
target->type ); // XXX
return NS_OK;
}
NS_METHOD
rdfDatabaseWrapper::HasAssertion(RDF_Resource source,
RDF_Resource arcLabel,
RDF_Node target,
PRBool truthValue,
PRBool* hasAssertion /* out */)
{
*hasAssertion = RDF_HasAssertion( mRDF,
source,
arcLabel,
target->value.r,
target->type,
truthValue );
return NS_OK;
}
PR_IMPLEMENT(void)
_comwrap_NotificationCB(RDF_Event event, void* pdata)
{
nsIRDFObserver* observer = (nsIRDFObserver*) pdata;
// XXX QueryInterface & release??
observer->HandleEvent( (nsIRDFDataSource*)pdata, event );
}
NS_METHOD
rdfDatabaseWrapper::AddObserver(nsIRDFObserver *observer,
RDF_EventMask type)
{
// XXX event masking does not currently work
RDF_Notification notification = (RDF_Notification) PL_HashTableLookup( mpObserverMap, observer );
if( !notification ) {
observer->AddRef();
notification = RDF_AddNotifiable( mRDF,
_comwrap_NotificationCB,
NULL, // XXX
observer );
PL_HashTableAdd( mpObserverMap,
observer,
notification );
}
return NS_OK; // XXX
}
NS_METHOD
rdfDatabaseWrapper::RemoveObserver(nsIRDFObserver *observer,
RDF_EventMask type)
{
RDF_Notification notification = (RDF_Notification) PL_HashTableLookup( mpObserverMap, observer );
if( !notification )
return NS_ERROR_ILLEGAL_VALUE;
RDF_Error err = RDF_DeleteNotifiable( notification );
PR_ASSERT( !err ); // the current implementation never fails!
PL_HashTableRemove( mpObserverMap, observer );
observer->Release();
return NS_OK; // XXX
}
NS_METHOD
rdfDatabaseWrapper::ArcLabelsIn(RDF_Node node,
nsIRDFCursor **labels /* out */)
{
PR_ASSERT( labels );
if( 0 == labels )
return NS_ERROR_NULL_POINTER;
*labels = 0;
RDF_Cursor c = RDF_ArcLabelsIn( mRDF, node->value.r );
if( c ) {
*labels = new rdfCursorWrapper( c );
(*labels)->AddRef();
}
return NS_OK;
}
NS_METHOD
rdfDatabaseWrapper::ArcLabelsOut(RDF_Resource source,
nsIRDFCursor **labels /* out */)
{
PR_ASSERT( labels );
if( 0 == labels )
return NS_ERROR_NULL_POINTER;
*labels = 0;
RDF_Cursor c = RDF_ArcLabelsOut( mRDF, source );
if( c ) {
*labels = new rdfCursorWrapper( c );
(*labels)->AddRef();
}
return NS_OK;
}
NS_METHOD
rdfDatabaseWrapper::Flush()
{
return NS_ERROR_NOT_IMPLEMENTED; // XXX
}
NS_METHOD
rdfDatabaseWrapper::DeleteAllArcs(RDF_Resource resource)
{
return RDF_DeleteAllArcs( mRDF, resource );
}
/*
rdfServiceWrapper: the RDF service singleton
*/
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
NS_IMPL_ISUPPORTS(rdfServiceWrapper, kIRDFServiceIID )
rdfServiceWrapper::rdfServiceWrapper()
{
nsresult err = RDF_Init(); // this method currently cannot fail
PR_ASSERT( err == NS_OK ); // XXX
}
rdfServiceWrapper::~rdfServiceWrapper()
{
nsresult err = RDF_Shutdown(); // this method currently cannot fail
PR_ASSERT( err == NS_OK ); // XXX
}
NS_METHOD
rdfServiceWrapper::CreateDatabase(const char** url_ary,
nsIRDFDataBase **db)
{
PR_ASSERT( 0 != db );
if( 0 == db )
return NS_ERROR_NULL_POINTER;
*db = 0;
nsresult result = NS_OK;
RDF rdf = RDF_GetDB(url_ary);
if( 0 == rdf ) {
result = RDF_ERROR_UNABLE_TO_CREATE; // XXX this is too wishy-washy
} else {
*db = new rdfDatabaseWrapper(rdf); // XXX
}
return result;
}
NS_METHOD
rdfServiceWrapper::ResourceIdentifier(RDF_Resource r,
char** url)
{
char* resourceID(RDF_Resource r);
PR_ASSERT( 0 != r );
if( 0 == r )
return NS_ERROR_NULL_POINTER;
*url = RDF_ResourceID(r);
return NS_OK;
}
#ifdef MOZILLA_CLIENT
NS_METHOD
rdfServiceWrapper::SetBookmarkFile(const char* bookmarkFilePath) {
SetBookmarkURL(bookmarkFilePath);
return NS_OK;
}
#endif
/*
rdfCursorWrapper
*/
static NS_DEFINE_IID(kIRDFCursorIID, NS_IRDFCURSOR_IID);
NS_IMPL_ISUPPORTS( rdfCursorWrapper, kIRDFCursorIID )
rdfCursorWrapper::rdfCursorWrapper(RDF_Cursor c) : mCursor(c)
{
mHasCached = PR_FALSE;
}
rdfCursorWrapper::~rdfCursorWrapper()
{
RDF_DisposeCursor( mCursor );
}
NS_METHOD
rdfCursorWrapper::HasElements(PRBool& hasElements)
{
mNextValue.type = RDF_CursorValueType( mCursor );
mNextValue.value.r = (RDF_Resource) RDF_NextValue( mCursor );
if( mNextValue.value.r != NULL ) {
hasElements = PR_FALSE;
mHasCached = PR_TRUE;
} else {
hasElements = PR_TRUE;
mHasCached = PR_FALSE;
}
return NS_OK;
}
NS_METHOD
rdfCursorWrapper::Next(RDF_NodeStruct& next)
{
if( mHasCached == PR_TRUE ) {
next.type = mNextValue.type;
next.value.r = mNextValue.value.r;
mHasCached = PR_FALSE;
} else {
next.type = RDF_CursorValueType( mCursor );
next.value.r = (RDF_Resource) RDF_NextValue( mCursor );
}
return NS_OK;
}
/*
rdfServiceFactory
*/
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
NS_IMPL_ISUPPORTS( rdfServiceFactory, kIFactoryIID )
NS_METHOD
rdfServiceFactory::CreateInstance( nsISupports *aOuter,
REFNSIID aIID,
void **aResult )
{
PR_ASSERT( aResult );
if( 0 == aResult )
return NS_ERROR_NULL_POINTER;
*aResult = 0;
nsISupports* instance = new rdfServiceWrapper();
nsresult result = instance->QueryInterface( aIID, aResult );
PR_ASSERT( result = NS_OK );
if( result != NS_OK )
delete instance; // wrong interface!
return result;
}
NS_METHOD
rdfServiceFactory::LockFactory(PRBool lock)
{
PR_ASSERT( PR_FALSE );
return NS_ERROR_NOT_IMPLEMENTED;
}
PR_IMPLEMENT(nsresult)
NS_GetRDFService(nsIRDFService **s)
{
PR_ASSERT( s );
if( 0 == s )
return NS_ERROR_NULL_POINTER;
*s = 0;
if( 0 == gRDFServiceSingleton ) {
gRDFServiceSingleton = new rdfServiceWrapper(); // XXX use factory, check for errors
}
*s = gRDFServiceSingleton;
return NS_OK;
}

View File

@ -15,7 +15,6 @@
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH = ..\..
MODULE=rdf
@ -24,31 +23,44 @@ DLLNAME=rdf
DLL=.\$(OBJDIR)\$(DLLNAME).dll
C_OBJS=\
.\$(OBJDIR)\vocab.obj \
.\$(OBJDIR)\core.obj \
.\$(OBJDIR)\remstore.obj \
.\$(OBJDIR)\utils.obj \
.\$(OBJDIR)\rdfparse.obj \
.\$(OBJDIR)\bmk2rdf.obj \
.\$(OBJDIR)\columns.obj \
.\$(OBJDIR)\rdfht.obj \
$(NULL)
CPP_OBJS=\
.\$(OBJDIR)\comwrap.obj \
.\$(OBJDIR)\netglue.obj \
.\$(OBJDIR)\nsRDFDataModel.obj \
.\$(OBJDIR)\nsRDFDataModelItem.obj \
.\$(OBJDIR)\nsBookmarkDataSource.obj \
.\$(OBJDIR)\nsEmptyCursor.obj \
.\$(OBJDIR)\nsMemoryDataSource.obj \
.\$(OBJDIR)\nsRDFContentSink.obj \
.\$(OBJDIR)\nsRDFDocument.obj \
.\$(OBJDIR)\nsRDFElement.obj \
.\$(OBJDIR)\nsRDFFactory.obj \
.\$(OBJDIR)\nsRDFToolbarDataModel.obj \
.\$(OBJDIR)\nsRDFToolbarDataModelItem.obj \
.\$(OBJDIR)\nsRDFTreeColumn.obj \
.\$(OBJDIR)\nsRDFTreeDataModel.obj \
.\$(OBJDIR)\nsRDFTreeDataModelItem.obj \
.\$(OBJDIR)\nsRDFRegistryImpl.obj \
.\$(OBJDIR)\nsRDFResourceManager.obj \
.\$(OBJDIR)\nsSimpleDataBase.obj \
$(NULL)
# Right now, the RDF parser depends on some of the Raptor support
# classes to work (e.g., nsDocument). So, we need to reach over
# and link in a bunch of private stuff from over there. This *will*
# go away.
EVIL_RAPTOR_DEPENDENCY=1
LLIBS=\
!ifdef EVIL_RAPTOR_DEPENDENCY
$(DIST)\lib\raptorhtml.lib \
$(DIST)\lib\raptorlayout_s.lib \
$(DIST)\lib\raptorhtmlbase_s.lib \
$(DIST)\lib\nglhtmlcon_s.lib \
$(DIST)\lib\raptorhtmldoc_s.lib \
$(DIST)\lib\raptorhtmlforms_s.lib \
$(DIST)\lib\raptorhtmlstyle_s.lib \
$(DIST)\lib\raptorhtmltable_s.lib \
$(DIST)\lib\raptorxmlcontent_s.lib \
$(DIST)\lib\raptorxmldoc_s.lib \
$(DIST)\lib\raptorevents_s.lib \
$(DIST)\lib\raptorbase.lib \
$(DIST)\lib\raptorgfxwin.lib \
$(DIST)\lib\raptorhtmlpars.lib \
$(DIST)\lib\jsdom.lib \
$(DIST)\lib\js32$(VERSION_NUMBER).lib \
!endif
$(DIST)\lib\xpcom32.lib \
$(DIST)\lib\raptorbase.lib \
$(DIST)\lib\netlib.lib \
@ -56,9 +68,17 @@ LLIBS=\
$(LIBNSPR)
LINCS= -I$(PUBLIC)\rdf \
-I$(XPDIST)\public\xpcom \
-I$(PUBLIC)\xpcom \
-I$(PUBLIC)\netlib \
-I$(PUBLIC)\raptor \
-I$(PUBLIC)\js \
-I$(PUBLIC)\dom \
!ifdef EVIL_RAPTOR_DEPENDENCY
-I..\..\layout\base\src \
-I..\..\layout\html\base\src \
-I..\..\layout\html\style\src \
-I..\..\layout\html\document\src \
!endif
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@ -0,0 +1,584 @@
/* -*- 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 "nsIRDFDataSource.h"
#include "nsIRDFNode.h"
#include "nsIRDFResourceManager.h"
#include "nsIServiceManager.h"
#include "nsBookmarkDataSource.h"
#include "nsRDFCID.h"
#include "nsString.h"
#include "nsVoidArray.h"
#include "prio.h"
#include "rdf.h"
////////////////////////////////////////////////////////////////////////
static NS_DEFINE_IID(kIRDFResourceManagerIID, NS_IRDFRESOURCEMANAGER_IID);
static NS_DEFINE_CID(kRDFResourceManagerCID, NS_RDFRESOURCEMANAGER_CID);
static const char kURI_bookmarks[] = "rdf:bookmarks"; // XXX?
#define NC_NAMESPACE_URI "http://home.netscape.com/NC-rdf#"
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Bookmark);
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(NC_NAMESPACE_URI, NC, BookmarkAddDate);
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Description);
#define WEB_NAMESPACE_URI "http://home.netscape.com/WEB-rdf#"
DEFINE_RDF_VOCAB(WEB_NAMESPACE_URI, WEB, LastVisitDate);
DEFINE_RDF_VOCAB(WEB_NAMESPACE_URI, WEB, LastModifiedDate);
#define RDF_NAMESPACE_URI "http://www.w3.org/TR/WD-rdf-syntax#"
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, instanceOf);
static const char kPersonalToolbar[] = "Personal Toolbar";
////////////////////////////////////////////////////////////////////////
class BookmarkParser {
protected:
static const PRUnichar* kBRString;
static const PRUnichar* kCloseDLString;
static const PRUnichar* kDDString;
static const PRUnichar* kOpenAnchorString;
static const PRUnichar* kOpenDLString;
static const PRUnichar* kOpenH3String;
static const PRUnichar* kOpenTitleString;
static const PRUnichar* kSeparatorString;
enum BookmarkParserState {
eBookmarkParserState_Initial,
eBookmarkParserState_InTitle,
eBookmarkParserState_InH3,
eBookmarkParserState_InItemTitle,
eBookmarkParserState_InItemDescription
};
nsIRDFResourceManager* mResourceMgr;
nsIRDFDataSource* mDataSource;
nsVoidArray mStack;
nsIRDFNode* 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(nsIRDFNode* subject,
const nsString& predicateURI,
const nsString& time);
nsresult Assert(nsIRDFNode* subject,
const nsString& predicateURI,
const nsString& objectURI);
nsresult Assert(nsIRDFNode* subject,
const nsString& predicateURI,
nsIRDFNode* object);
nsresult Assert(nsIRDFNode* subject,
nsIRDFNode* predicate,
nsIRDFNode* object);
public:
BookmarkParser(nsIRDFResourceManager* resourceMgr,
nsIRDFDataSource* dataSource);
~BookmarkParser();
nsresult Parse(PRFileDesc* file);
};
const PRUnichar* BookmarkParser::kBRString = L"<BR>";
const PRUnichar* BookmarkParser::kCloseDLString = L"</DL>";
const PRUnichar* BookmarkParser::kDDString = L"<DD>";
const PRUnichar* BookmarkParser::kOpenAnchorString = L"<A";
const PRUnichar* BookmarkParser::kOpenDLString = L"<DL>";
const PRUnichar* BookmarkParser::kOpenH3String = L"<H3";
const PRUnichar* BookmarkParser::kOpenTitleString = L"<TITLE>";
const PRUnichar* BookmarkParser::kSeparatorString = L"<HR>";
BookmarkParser::BookmarkParser(nsIRDFResourceManager* resourceMgr,
nsIRDFDataSource* dataSource)
: mResourceMgr(resourceMgr),
mDataSource(dataSource)
{
NS_IF_ADDREF(mResourceMgr);
//NS_IF_ADDREF(mDataSource);
}
BookmarkParser::~BookmarkParser(void)
{
//NS_IF_RELEASE(mDataSource);
NS_IF_RELEASE(mResourceMgr);
}
nsresult
BookmarkParser::Parse(PRFileDesc* file)
{
if (! file)
return NS_ERROR_NULL_POINTER;
if (! mResourceMgr)
return NS_ERROR_NULL_POINTER;
if (! mDataSource)
return NS_ERROR_NULL_POINTER;
// Initialize the parser for a run...
mState = eBookmarkParserState_Initial;
mCounter = 0;
mLastItem = NULL;
mLine.Truncate();
nsresult rv;
nsIRDFNode* bookmarks;
if (NS_SUCCEEDED(rv = mResourceMgr->GetNode(kURI_bookmarks, bookmarks))) {
mStack.AppendElement(bookmarks);
char buf[1024];
PRInt32 len;
while ((len = PR_Read(file, buf, sizeof(buf))) > 0)
Tokenize(buf, len);
NS_RELEASE(bookmarks);
}
NS_IF_RELEASE(mLastItem);
return rv;
}
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) ||
(mState == eBookmarkParserState_InItemTitle)) {
// Create a new folder
nsAutoString folderURI(kURI_bookmarks);
folderURI.Append('#');
folderURI.Append(++mCounter, 10);
nsIRDFNode* parent = (nsIRDFNode*) mStack[mStack.Count() - 1];
PR_ASSERT(parent);
if (! parent)
return;
nsIRDFNode* folder;
if (NS_FAILED(mResourceMgr->GetNode(folderURI, folder)))
return;
Assert(parent, kURINC_Folder, folder);
if (mFolderDate.Length()) {
AssertTime(folder, kURINC_BookmarkAddDate, mFolderDate);
mFolderDate.Truncate();
}
NS_IF_RELEASE(mLastItem);
mLastItem = folder;
if (mState != eBookmarkParserState_InTitle)
Assert(mLastItem, kURINC_Name, mLine);
if (mLine.Find(kPersonalToolbar) == 0)
Assert(mLastItem, kURIRDF_instanceOf, kURINC_PersonalToolbarFolderCategory);
}
else if (mState == eBookmarkParserState_InItemDescription) {
Assert(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)
== NULL)
#endif
mState = eBookmarkParserState_InItemDescription;
}
else if (mLine.Find(kOpenDLString) == 0) {
mStack.AppendElement(mLastItem);
}
else if (mLine.Find(kCloseDLString) == 0) {
PRInt32 count = mStack.Count();
if (count) {
nsIRDFNode* top = 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, NULL);
#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?
Assert(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;
nsIRDFNode* bookmark;
if (NS_FAILED(mResourceMgr->GetNode(values[eBmkAttribute_URL], bookmark)))
return;
if (! mStack.Count())
return;
nsIRDFNode* parent = (nsIRDFNode*) mStack[mStack.Count() - 1];
if (! parent)
return;
Assert(parent, kURINC_Bookmark, 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_RELEASE(bookmark);
}
nsresult
BookmarkParser::AssertTime(nsIRDFNode* object,
const nsString& predicateURI,
const nsString& time)
{
// XXX
return Assert(object, predicateURI, time);
}
nsresult
BookmarkParser::Assert(nsIRDFNode* subject,
nsIRDFNode* predicate,
nsIRDFNode* object)
{
#ifdef DEBUG
char buf[1024];
nsAutoString s;
subject->GetStringValue(s);
printf("(%s\n", s.ToCString(buf, sizeof buf));
predicate->GetStringValue(s);
printf(" %s\n", s.ToCString(buf, sizeof buf));
object->GetStringValue(s);
printf(" %s)\n", s.ToCString(buf, sizeof buf));
#endif
return mDataSource->Assert(subject, predicate, object);
}
nsresult
BookmarkParser::Assert(nsIRDFNode* subject,
const nsString& predicateURI,
nsIRDFNode* object)
{
nsresult rv;
nsIRDFNode* predicate;
if (NS_FAILED(rv = mResourceMgr->GetNode(predicateURI, predicate)))
return rv;
rv = Assert(subject, predicate, object);
NS_RELEASE(predicate);
return rv;
}
nsresult
BookmarkParser::Assert(nsIRDFNode* subject,
const nsString& predicateURI,
const nsString& objectURI)
{
nsresult rv;
nsIRDFNode* object;
if (NS_FAILED(rv = mResourceMgr->GetNode(objectURI, object)))
return rv;
rv = Assert(subject, predicateURI, object);
NS_RELEASE(object);
return rv;
}
////////////////////////////////////////////////////////////////////////
// nsBookmarkDataSource
// XXX we should get this from prefs.
const char* nsBookmarkDataSource::kBookmarksFilename = "bookmarks.html";
nsBookmarkDataSource::nsBookmarkDataSource(void)
{
NS_INIT_REFCNT();
ReadBookmarks(); // XXX do or die, eh?
Initialize(kURI_bookmarks);
}
nsBookmarkDataSource::~nsBookmarkDataSource(void)
{
Flush();
}
NS_IMETHODIMP
nsBookmarkDataSource::Flush(void)
{
return WriteBookmarks();
}
nsresult
nsBookmarkDataSource::ReadBookmarks(void)
{
nsresult rv;
nsIRDFResourceManager* mgr;
if (NS_FAILED(rv = nsServiceManager::GetService(kRDFResourceManagerCID,
kIRDFResourceManagerIID,
(nsISupports**) &mgr)))
return rv;
BookmarkParser parser(mgr, this);
PRFileDesc* f;
rv = NS_ERROR_FAILURE;
if ((f = PR_Open(kBookmarksFilename, PR_RDONLY, 0644))) {
rv = parser.Parse(f);
PR_Close(f);
}
nsServiceManager::ReleaseService(kRDFResourceManagerCID, mgr);
return rv;
}
nsresult
nsBookmarkDataSource::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 == NULL) return;
if (u == top) {
name = RDF_GetResourceName(rdf, u);
ht_rjcprintf(fp, "<!DOCTYPE NETSCAPE-Bookmark-file-1>\n", NULL);
ht_rjcprintf(fp, "<!-- This is an automatically generated file.\n", NULL);
ht_rjcprintf(fp, "It will be read and overwritten.\n", NULL);
ht_rjcprintf(fp, "Do Not Edit! -->\n", NULL);
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)) != NULL) {
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, " ", NULL);
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, " ", NULL);
ht_rjcprintf(fp, "<DL><p>\n", NULL);
HT_WriteOutAsBookmarks1(rdf, fp, next, top, indent+1);
for (loop=0; loop<indent; loop++) ht_rjcprintf(fp, " ", NULL);
ht_rjcprintf(fp, "</DL><p>\n", NULL);
}
else if (isSeparator(next)) {
for (loop=0; loop<indent; loop++) ht_rjcprintf(fp, " ", NULL);
ht_rjcprintf(fp, "<HR>\n", NULL);
}
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, " ", NULL);
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) != NULL) {
ht_rjcprintf(fp, "<DD>%s\n", resourceDescription(rdf, next));
}
}
}
RDF_DisposeCursor(c);
if (u == top) {
ht_rjcprintf(fp, "</DL>\n", NULL);
}
}
#endif

View File

@ -0,0 +1,39 @@
/* -*- 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 nsBookmarkDataSource_h__
#define nsBookmarkDataSource_h__
#include "nsMemoryDataSource.h"
class nsBookmarkDataSource : public nsMemoryDataSource {
protected:
static const char* kBookmarksFilename;
nsresult ReadBookmarks(void);
nsresult WriteBookmarks(void);
public:
nsBookmarkDataSource(void);
virtual ~nsBookmarkDataSource(void);
NS_IMETHOD Flush(void);
};
#endif nsBookmarkDataSource_h__

91
rdf/src/nsEmptyCursor.cpp Normal file
View File

@ -0,0 +1,91 @@
/* -*- 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 "nsIRDFCursor.h"
static NS_DEFINE_IID(kIRDFCursorIID, NS_IRDFCURSOR_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
class EmptyCursorImpl : public nsIRDFCursor {
public:
EmptyCursorImpl(void);
virtual ~EmptyCursorImpl(void) {};
// nsISupports
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
NS_IMETHOD QueryInterface(REFNSIID iid, void** result);
// nsIRDFCursor
NS_IMETHOD HasMoreElements(PRBool& result);
NS_IMETHOD GetNext(nsIRDFNode*& next, PRBool& tv);
};
nsIRDFCursor* gEmptyCursor;
static EmptyCursorImpl gEmptyCursorImpl;
EmptyCursorImpl::EmptyCursorImpl(void)
{
gEmptyCursor = this;
}
NS_IMETHODIMP_(nsrefcnt)
EmptyCursorImpl::AddRef(void)
{
return 2;
}
NS_IMETHODIMP_(nsrefcnt)
EmptyCursorImpl::Release(void)
{
return 1;
}
NS_IMETHODIMP
EmptyCursorImpl::QueryInterface(REFNSIID iid, void** result)
{
if (! result)
return NS_ERROR_NULL_POINTER;
if (iid.Equals(kIRDFCursorIID) ||
iid.Equals(kISupportsIID)) {
*result = static_cast<nsIRDFCursor*>(this);
/* AddRef(); // not necessary */
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP
EmptyCursorImpl::HasMoreElements(PRBool& result)
{
result = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
EmptyCursorImpl::GetNext(nsIRDFNode*& next, PRBool& tv)
{
next = NULL;
return NS_ERROR_UNEXPECTED;
}

46
rdf/src/nsIRDFContent.h Normal file
View File

@ -0,0 +1,46 @@
/* -*- 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.
*/
#ifndef nsIRDFContent_h___
#define nsIRDFContent_h___
#include "nsISupports.h"
#include "nsIXMLContent.h"
// {954F0810-81DC-11d2-B52A-000000000000}
#define NS_IRDFCONTENT_IID \
{ 0x954f0810, 0x81dc, 0x11d2, { 0xb5, 0x2a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
/**
* RDF content extensions to nsIXMLContent
*/
class nsIRDFContent : public nsIXMLContent {
public:
NS_IMETHOD SetResource(const nsString& aURI) = 0;
NS_IMETHOD GetResource(nsString& rURI) const = 0;
NS_IMETHOD SetProperty(const nsString& aPropertyURI, const nsString& aValue) = 0;
NS_IMETHOD GetProperty(const nsString& aPropertyURI, nsString& rValue) const = 0;
};
extern nsresult
NS_NewRDFElement(nsIRDFContent** aResult);
#endif // nsIRDFContent_h___

View File

@ -0,0 +1,64 @@
/* -*- 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.
*/
#ifndef nsIRDFContentSink_h___
#define nsIRDFContentSink_h___
#include "nsIXMLContentSink.h"
class nsIDocument;
class nsIURL;
class nsIWebShell;
// {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 generic XML files.
* The goal of this sink is to deal with XML documents that do not
* have pre-built semantics, though it may also be implemented for
* cases in which semantics are hard-wired.
*
* The expectation is that the parser has already performed
* well-formedness and validity checking.
*
* XXX The expectation is that entity expansion will be done by the sink
* itself. This would require, however, that the sink has the ability
* to query the parser for entity replacement text.
*
* XXX This interface does not contain a mechanism for the sink to
* get specific schema/DTD information from the parser. This information
* may be necessary for entity expansion. It is also necessary for
* building the DOM portions that relate to the schema.
*
* XXX This interface does not deal with the presence of an external
* subset. It seems possible that this could be dealt with completely
* at the parser level.
*/
class nsIRDFContentSink : public nsIXMLContentSink {
public:
};
extern nsresult NS_NewRDFContentSink(nsIRDFContentSink** aInstancePtrResult,
nsIDocument* aDoc,
nsIURL* aURL,
nsIWebShell* aWebShell);
#endif // nsIRDFContentSink_h___

44
rdf/src/nsIRDFDocument.h Normal file
View File

@ -0,0 +1,44 @@
/* -*- 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.
*/
#ifndef nsIRDFDocument_h___
#define nsIRDFDocument_h___
#include "nsIXMLDocument.h"
class nsString;
class nsIRDFDataBase;
class nsIRDFDataSource;
class nsIRDFNode;
// {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:
NS_IMETHOD GetDataBase(nsIRDFDataBase*& rDataBase) = 0;
NS_IMETHOD SetDataSource(nsIRDFDataSource* aDataSource) = 0;
};
#endif // nsIRDFDocument_h___

View File

@ -0,0 +1,730 @@
/* -*- 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.
*/
/*
Implementation for an in-memory RDF data store.
TO DO:
1) There is no implementation for walking property arcs backwards;
i.e., GetSource(), GetSources(), and ArcLabelsIn(). Gotta fix
this. Or maybe factor the API so that you don't always need to
implement that crap. I can see that being a real headache for
some implementations.
2) Need to hook up observer mechanisms.
*/
#include "nsMemoryDataSource.h"
#include "nsIRDFCursor.h"
#include "nsIRDFNode.h"
#include "nsIRDFRegistry.h"
#include "nsIServiceManager.h"
#include "nsISupportsArray.h"
#include "nsRDFCID.h"
extern nsIRDFCursor* gEmptyCursor;
static NS_DEFINE_IID(kIRDFCursorIID, NS_IRDFCURSOR_IID);
static NS_DEFINE_IID(kIRDFDataSourceIID, NS_IRDFDATASOURCE_IID);
static NS_DEFINE_IID(kIRDFNodeIID, NS_IRDFNODE_IID);
static NS_DEFINE_IID(kIRDFRegistryIID, NS_IRDFREGISTRY_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_CID(kRDFRegistryCID, NS_RDFREGISTRY_CID);
////////////////////////////////////////////////////////////////////////
// PropertyListElement
class PropertyListElement {
private:
nsIRDFNode* mValue;
PRBool mTruthValue;
PropertyListElement* mNext;
PropertyListElement* mPrev;
public:
PropertyListElement(nsIRDFNode* value, PRBool truthValue)
: mValue(value), mTruthValue(truthValue) {
mNext = mPrev = this;
NS_IF_ADDREF(mValue);
}
~PropertyListElement(void) {
NS_IF_RELEASE(mValue);
}
nsIRDFNode* GetValue(void) {
return mValue;
}
PRBool GetTruthValue(void) {
return mTruthValue;
}
PropertyListElement* GetNext(void) {
return mNext;
}
PropertyListElement* GetPrev(void) {
return mPrev;
}
void InsertAfter(PropertyListElement* e) {
e->mNext->mPrev = this;
this->mNext = e->mNext;
e->mNext = this;
this->mPrev = e;
}
PRBool UnlinkAndTestIfEmpty(void) {
if (mPrev == mNext)
return PR_TRUE;
mPrev->mNext = mNext;
mNext->mPrev = mPrev;
return PR_FALSE;
}
};
////////////////////////////////////////////////////////////////////////
// NodeImpl
class NodeHashKey;
class NodeImpl {
protected:
nsIRDFNode* mNode;
nsHashtable mProperties; // maps an nsIRDFNode* property to a property list
inline PropertyListElement* FindPropertyValue(NodeHashKey* key, nsIRDFNode* value, PRBool tv);
public:
NodeImpl(nsIRDFNode* node) : mNode(node) {
NS_IF_ADDREF(mNode);
}
virtual ~NodeImpl(void);
nsIRDFNode* GetNode(void) {
return mNode;
}
PRBool HasPropertyValue(nsIRDFNode* property, nsIRDFNode* value, PRBool tv);
void AddProperty(nsIRDFNode* property, nsIRDFNode* value, PRBool tv);
void RemoveProperty(nsIRDFNode* property, nsIRDFNode* value);
nsIRDFNode* GetProperty(nsIRDFNode* property, PRBool tv);
nsIRDFCursor* GetProperties(nsIRDFNode* property, PRBool tv);
nsIRDFCursor* GetArcLabelsOut(void);
};
////////////////////////////////////////////////////////////////////////
// NodeHashKey
class NodeHashKey : public nsHashKey
{
private:
nsIRDFNode* mNode;
public:
NodeHashKey(void) : mNode(NULL) {
}
NodeHashKey(nsIRDFNode* aNode) : mNode(aNode) {
NS_IF_ADDREF(mNode);
}
NodeHashKey(const NodeHashKey& key) : mNode(key.mNode) {
NS_IF_ADDREF(mNode);
}
NodeHashKey& operator=(const NodeHashKey& key) {
NS_IF_RELEASE(mNode);
mNode = key.mNode;
NS_IF_ADDREF(mNode);
return *this;
}
NodeHashKey& operator=(nsIRDFNode* aNode) {
NS_IF_RELEASE(mNode);
mNode = aNode;
NS_IF_ADDREF(mNode);
return *this;
}
virtual ~NodeHashKey(void) {
NS_IF_RELEASE(mNode);
}
nsIRDFNode* GetNode(void) {
return mNode;
}
// nsHashKey pure virtual interface methods
virtual PRUint32 HashValue(void) const {
return (PRUint32) mNode;
}
virtual PRBool Equals(const nsHashKey* aKey) const {
NodeHashKey* that;
//if (! (that = dynamic_cast<NodeHashKey*>(aKey)))
if (! (that = (NodeHashKey*)(aKey)))
return PR_FALSE;
return (that->mNode == this->mNode);
}
virtual nsHashKey* Clone(void) const {
return new NodeHashKey(mNode);
}
};
////////////////////////////////////////////////////////////////////////
// PropertyCursorImpl
class PropertyCursorImpl : public nsIRDFCursor {
private:
PropertyListElement* mFirst;
PropertyListElement* mNext;
PRBool mTruthValueToMatch;
public:
PropertyCursorImpl(PropertyListElement* first, PRBool truthValue);
virtual ~PropertyCursorImpl(void);
NS_DECL_ISUPPORTS
NS_IMETHOD HasMoreElements(PRBool& result);
NS_IMETHOD GetNext(nsIRDFNode*& next, PRBool& tv);
};
PropertyCursorImpl::PropertyCursorImpl(PropertyListElement* first, PRBool truthValueToMatch)
: mFirst(first),
mNext(first),
mTruthValueToMatch(truthValueToMatch)
{
NS_INIT_REFCNT();
while (1) {
if (mNext->GetTruthValue() == mTruthValueToMatch)
break;
if (mNext == mFirst) {
mNext = NULL; // wrapped all the way back to the start
break;
}
mNext = mNext->GetNext();
}
}
PropertyCursorImpl::~PropertyCursorImpl(void)
{
}
NS_IMPL_ISUPPORTS(PropertyCursorImpl, kIRDFCursorIID);
NS_IMETHODIMP
PropertyCursorImpl::HasMoreElements(PRBool& result)
{
result = (mNext != NULL);
return NS_OK;
}
NS_IMETHODIMP
PropertyCursorImpl::GetNext(nsIRDFNode*& next, PRBool& tv)
{
if (mNext == NULL)
return NS_ERROR_UNEXPECTED;
next = mNext->GetValue();
tv = mNext->GetTruthValue();
mNext = mNext->GetNext(); // advance past the current node
while (1) {
if (mNext == mFirst) {
mNext = NULL; // wrapped all the way back to the start
break;
}
if (mNext->GetTruthValue() == mTruthValueToMatch)
break;
mNext = mNext->GetNext();
}
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// ArcCursorImpl
class ArcCursorImpl : public nsIRDFCursor {
private:
nsISupportsArray* mProperties;
static PRBool Enumerator(nsHashKey* key, void* value, void* closure);
public:
ArcCursorImpl(nsHashtable& properties);
virtual ~ArcCursorImpl(void);
NS_DECL_ISUPPORTS
NS_IMETHOD HasMoreElements(PRBool& result);
NS_IMETHOD GetNext(nsIRDFNode*& next, PRBool& tv);
};
ArcCursorImpl::ArcCursorImpl(nsHashtable& properties)
{
NS_INIT_REFCNT();
if (NS_SUCCEEDED(NS_NewISupportsArray(&mProperties)))
properties.Enumerate(Enumerator, mProperties);
}
ArcCursorImpl::~ArcCursorImpl(void)
{
NS_IF_RELEASE(mProperties);
}
NS_IMPL_ISUPPORTS(ArcCursorImpl, kIRDFCursorIID);
PRBool
ArcCursorImpl::Enumerator(nsHashKey* key, void* value, void* closure)
{
nsISupportsArray* properties = static_cast<nsISupportsArray*>(closure);
NodeHashKey* k = (NodeHashKey*) key;
properties->AppendElement(k->GetNode());
return PR_TRUE;
}
NS_IMETHODIMP
ArcCursorImpl::HasMoreElements(PRBool& result)
{
result = (mProperties && mProperties->Count() > 0);
return NS_OK;
}
NS_IMETHODIMP
ArcCursorImpl::GetNext(nsIRDFNode*& next, PRBool& tv)
{
if (! mProperties || ! mProperties->Count())
return NS_ERROR_UNEXPECTED;
PRInt32 index = mProperties->Count() - 1;
nsISupports* obj = mProperties->ElementAt(index); // this'll AddRef()
PR_ASSERT(obj);
if (obj) {
obj->QueryInterface(kIRDFNodeIID, (void**) &next);
obj->Release();
}
mProperties->RemoveElementAt(index);
tv = PR_TRUE; // not really applicable...
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// NodeImpl implementation
NodeImpl::~NodeImpl(void)
{
NS_IF_RELEASE(mNode);
// XXX LEAK! we need to make sure that the properties are
// released!
}
PropertyListElement*
NodeImpl::FindPropertyValue(NodeHashKey* key, nsIRDFNode* value, PRBool tv)
{
PropertyListElement* head
= static_cast<PropertyListElement*>(mProperties.Get(key));
if (! head)
return NULL;
PropertyListElement* e = head;
do {
if (e->GetValue() == value && e->GetTruthValue() == tv)
return e;
e = e->GetNext();
} while (e != head);
return NULL;
}
PRBool
NodeImpl::HasPropertyValue(nsIRDFNode* property, nsIRDFNode* value, PRBool tv)
{
NodeHashKey key(property);
return (FindPropertyValue(&key, value, tv) != NULL);
}
nsIRDFNode*
NodeImpl::GetProperty(nsIRDFNode* property, PRBool tv)
{
NodeHashKey key(property);
PropertyListElement* head
= static_cast<PropertyListElement*>(mProperties.Get(&key));
if (! head)
return NULL;
PropertyListElement* e = head;
do {
if (e->GetTruthValue() == tv)
return e->GetValue();
e = e->GetNext();
} while (e != head);
return NULL;
}
void
NodeImpl::AddProperty(nsIRDFNode* property, nsIRDFNode* value, PRBool tv)
{
NodeHashKey key(property);
if (FindPropertyValue(&key, value, tv))
return;
// XXX so both positive and negative assertions can live in the
// graph together. This seems wrong...
PropertyListElement* head
= static_cast<PropertyListElement*>(mProperties.Get(&key));
PropertyListElement* e
= new PropertyListElement(value, tv);
if (head) {
e->InsertAfter(head);
} else {
mProperties.Put(&key, e);
}
}
void
NodeImpl::RemoveProperty(nsIRDFNode* property, nsIRDFNode* value)
{
NodeHashKey key(property);
PropertyListElement* e;
// this is really bizarre that two truth values can live in one
// data source. I'm suspicious that this isn't quite right...
e = FindPropertyValue(&key, value, PR_TRUE);
if (e) {
if (e->UnlinkAndTestIfEmpty())
mProperties.Remove(&key);
delete e;
}
e = FindPropertyValue(&key, value, PR_FALSE);
if (e) {
if (e->UnlinkAndTestIfEmpty())
mProperties.Remove(&key);
delete e;
}
}
nsIRDFCursor*
NodeImpl::GetProperties(nsIRDFNode* property, PRBool tv)
{
NodeHashKey key(property);
PropertyListElement* head
= static_cast<PropertyListElement*>(mProperties.Get(&key));
return (head) ? (new PropertyCursorImpl(head, tv)) : gEmptyCursor;
}
nsIRDFCursor*
NodeImpl::GetArcLabelsOut(void)
{
return new ArcCursorImpl(mProperties);
}
////////////////////////////////////////////////////////////////////////
// nsMemoryDataSource implementation
nsMemoryDataSource::nsMemoryDataSource(void)
: mRegistry(NULL)
{
NS_INIT_REFCNT();
}
nsMemoryDataSource::~nsMemoryDataSource(void)
{
// XXX LEAK! make sure that you release the nodes
if (mRegistry) {
mRegistry->Unregister(this);
nsServiceManager::ReleaseService(kRDFRegistryCID, mRegistry);
mRegistry = NULL;
}
}
NS_IMPL_ISUPPORTS(nsMemoryDataSource, kIRDFDataSourceIID);
NS_IMETHODIMP
nsMemoryDataSource::Initialize(const nsString& uri)
{
nsresult rv;
if (mRegistry)
return NS_ERROR_ALREADY_INITIALIZED;
if (NS_FAILED(rv = nsServiceManager::GetService(kRDFRegistryCID,
kIRDFRegistryIID,
(nsISupports**) &mRegistry)))
return rv;
return mRegistry->Register(uri, this);
}
NS_IMETHODIMP
nsMemoryDataSource::GetSource(nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFNode*& source)
{
PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED; // XXX
}
NS_IMETHODIMP
nsMemoryDataSource::GetSources(nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFCursor*& sources)
{
PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED; // XXX
}
NS_IMETHODIMP
nsMemoryDataSource::GetTarget(nsIRDFNode* source,
nsIRDFNode* property,
PRBool tv,
nsIRDFNode*& target)
{
NS_PRECONDITION(source && property, "null ptr");
if (!source || !property)
return NS_ERROR_NULL_POINTER;
target = NULL; // reasonable default
NodeHashKey key(source);
NodeImpl *u;
if (! (u = static_cast<NodeImpl*>(mNodes.Get(&key))))
return NS_ERROR_FAILURE;
target = u->GetProperty(property, tv);
if (! target)
return NS_ERROR_FAILURE;
NS_ADDREF(target); // need to AddRef()
return NS_OK;
}
NS_IMETHODIMP
nsMemoryDataSource::GetTargets(nsIRDFNode* source,
nsIRDFNode* property,
PRBool tv,
nsIRDFCursor*& targets)
{
NS_PRECONDITION(source && property, "null ptr");
if (!source || !property)
return NS_ERROR_NULL_POINTER;
targets = gEmptyCursor; // reasonable default
NodeHashKey key(source);
NodeImpl *u;
if (! (u = static_cast<NodeImpl*>(mNodes.Get(&key))))
return NS_OK;
if (! (targets = u->GetProperties(property, tv)))
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(targets);
return NS_OK;
}
NS_IMETHODIMP
nsMemoryDataSource::Assert(nsIRDFNode* source,
nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv)
{
NS_PRECONDITION(source && property && target, "null ptr");
if (!source || !property || !target)
return NS_ERROR_NULL_POINTER;
NodeImpl *u;
if (! (u = Ensure(source)))
return NS_ERROR_OUT_OF_MEMORY;
if (! Ensure(property))
return NS_ERROR_OUT_OF_MEMORY;
if (! Ensure(target))
return NS_ERROR_OUT_OF_MEMORY;
u->AddProperty(property, target, tv);
return NS_OK;
}
NS_IMETHODIMP
nsMemoryDataSource::Unassert(nsIRDFNode* source,
nsIRDFNode* property,
nsIRDFNode* target)
{
NS_PRECONDITION(source && property && target, "null ptr");
if (!source || !property || !target)
return NS_ERROR_NULL_POINTER;
NodeHashKey key(source);
NodeImpl *u;
if (! (u = static_cast<NodeImpl*>(mNodes.Get(&key))))
return NS_OK;
u->RemoveProperty(property, target);
return NS_OK;
}
NS_IMETHODIMP
nsMemoryDataSource::HasAssertion(nsIRDFNode* source,
nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv,
PRBool& hasAssertion)
{
NS_PRECONDITION(source && property && target, "null ptr");
if (!source || !property || !target)
return NS_ERROR_NULL_POINTER;
hasAssertion = PR_FALSE; // reasonable default
NodeHashKey key(source);
NodeImpl *u;
if (! (u = static_cast<NodeImpl*>(mNodes.Get(&key))))
return NS_OK;
hasAssertion = (u->GetProperty(property, tv) != NULL);
return NS_OK;
}
NS_IMETHODIMP
nsMemoryDataSource::AddObserver(nsIRDFObserver* n)
{
PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsMemoryDataSource::RemoveObserver(nsIRDFObserver* n)
{
PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsMemoryDataSource::ArcLabelsIn(nsIRDFNode* node,
nsIRDFCursor*& labels)
{
PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsMemoryDataSource::ArcLabelsOut(nsIRDFNode* source,
nsIRDFCursor*& labels)
{
NS_PRECONDITION(source, "null ptr");
if (! source)
return NS_ERROR_NULL_POINTER;
labels = gEmptyCursor; // reasonable default
NodeHashKey key(source);
NodeImpl *u;
if (! (u = static_cast<NodeImpl*>(mNodes.Get(&key))))
return NS_OK;
if (! (labels = u->GetArcLabelsOut()))
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(labels);
return NS_OK;
}
NS_IMETHODIMP
nsMemoryDataSource::Flush()
{
return NS_OK; // nothing to flush!
}
NodeImpl*
nsMemoryDataSource::Ensure(nsIRDFNode* node)
{
// The NodeHashKey does an AddRef(), and is cloned for insertion
// into the nsHashTable. This makes resource management really
// easy, because when the nsHashtable is destroyed, all of the
// keys are automatically deleted, which in turn does an
// appropriate Release() on the nsIRDFNode.
NodeHashKey key(node);
NodeImpl* result = static_cast<NodeImpl*>(mNodes.Get(&key));
if (! result) {
result = new NodeImpl(node);
if (result)
mNodes.Put(&key, result);
}
return result;
}

View File

@ -0,0 +1,97 @@
/* -*- 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 nsMemoryDataSource_h__
#define nsMemoryDataSource_h__
#include "prtypes.h"
#include "nsIRDFDataSource.h"
#include "nsHashtable.h"
class nsIRDFNode;
class nsIRDFCursor;
class nsIRDFRegistry;
class NodeImpl;
class nsMemoryDataSource : public nsIRDFDataSource {
protected:
nsHashtable mNodes;
nsIRDFRegistry* mRegistry;
NodeImpl* Ensure(nsIRDFNode* node);
public:
nsMemoryDataSource(void);
virtual ~nsMemoryDataSource(void);
// nsISupports
NS_DECL_ISUPPORTS
// nsIRDFDataSource methods
NS_IMETHOD Initialize(const nsString& uri);
NS_IMETHOD GetSource(nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFNode*& source);
NS_IMETHOD GetSources(nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFCursor*& sources);
NS_IMETHOD GetTarget(nsIRDFNode* source,
nsIRDFNode* property,
PRBool tv,
nsIRDFNode*& target);
NS_IMETHOD GetTargets(nsIRDFNode* source,
nsIRDFNode* property,
PRBool tv,
nsIRDFCursor*& targets);
NS_IMETHOD Assert(nsIRDFNode* source,
nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv = PR_TRUE);
NS_IMETHOD Unassert(nsIRDFNode* source,
nsIRDFNode* property,
nsIRDFNode* target);
NS_IMETHOD HasAssertion(nsIRDFNode* source,
nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv,
PRBool& hasAssertion);
NS_IMETHOD AddObserver(nsIRDFObserver* n);
NS_IMETHOD RemoveObserver(nsIRDFObserver* n);
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
nsIRDFCursor*& labels);
NS_IMETHOD ArcLabelsOut(nsIRDFNode* source,
nsIRDFCursor*& labels);
NS_IMETHOD Flush();
};
#endif // nsMemoryDataSource_h__

1615
rdf/src/nsRDFContentSink.cpp Normal file

File diff suppressed because it is too large Load Diff

153
rdf/src/nsRDFContentSink.h Normal file
View File

@ -0,0 +1,153 @@
/* -*- 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"
#include "nsIViewManager.h"
#include "nsIScrollableView.h"
class nsIDocument;
class nsIScriptObjectOwner;
class nsIURL;
class nsIWebShell;
class nsIContent;
class nsVoidArray;
class nsIRDFDocument;
class nsIRDFContent;
class nsIRDFNode;
class nsIRDFResourceManager;
class nsIUnicharInputStream;
class nsIStyleSheet;
typedef enum {
eRDFContentSinkState_InProlog,
eRDFContentSinkState_InDocumentElement,
eRDFContentSinkState_InDescriptionElement,
eRDFContentSinkState_InContainerElement,
eRDFContentSinkState_InPropertyElement,
eRDFContentSinkState_InMemberElement,
eRDFContentSinkState_InEpilog
} RDFContentSinkState;
class nsRDFContentSink : public nsIRDFContentSink {
public:
nsRDFContentSink();
~nsRDFContentSink();
nsresult Init(nsIDocument* aDoc,
nsIURL* aURL,
nsIWebShell* aContainer);
// nsISupports
NS_DECL_ISUPPORTS
// nsIContentSink
NS_IMETHOD WillBuildModel(void);
NS_IMETHOD DidBuildModel(PRInt32 aQualityLevel);
NS_IMETHOD WillInterrupt(void);
NS_IMETHOD WillResume(void);
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);
protected:
void StartLayout();
nsresult LoadStyleSheet(nsIURL* aURL,
nsIUnicharInputStream* aUIN);
nsresult FlushText(PRBool aCreateTextNode=PR_TRUE,
PRBool* aDidFlush=nsnull);
void FindNameSpaceAttributes(const nsIParserNode& aNode);
// namespace management
PRInt32 OpenNameSpace(const nsString& aPrefix, const nsString& aURI);
PRInt32 GetNameSpaceId(const nsString& aPrefix);
void CloseNameSpacesAtNestLevel(PRInt32 mNestLevel);
nsresult SplitQualifiedName(const nsString& aQualifiedName,
nsString& rNameSpaceURI,
nsString& rPropertyURI);
// RDF-specific parsing
nsresult GetIdAboutAttribute(const nsIParserNode& aNode, nsString& rResource);
nsresult GetResourceAttribute(const nsIParserNode& aNode, nsString& rResource);
nsresult AddProperties(const nsIParserNode& aNode, nsIRDFNode* aSubject);
nsresult OpenRDF(const nsIParserNode& aNode);
nsresult OpenObject(const nsIParserNode& aNode);
nsresult OpenProperty(const nsIParserNode& aNode);
nsresult OpenMember(const nsIParserNode& aNode);
nsresult OpenValue(const nsIParserNode& aNode);
// RDF helper routines
nsresult Assert(nsIRDFNode* subject, nsIRDFNode* predicate, nsIRDFNode* object);
nsresult Assert(nsIRDFNode* subject, nsIRDFNode* predicate, const nsString& objectLiteral);
nsresult Assert(nsIRDFNode* subject, const nsString& predicateURI, const nsString& objectLiteral);
// content stack management
PRInt32 PushContext(nsIRDFNode *aContext, RDFContentSinkState aState);
nsresult PopContext(nsIRDFNode*& rContext, RDFContentSinkState& rState);
nsIRDFNode* GetContextElement(PRInt32 ancestor = 0);
PRInt32 GetCurrentNestLevel();
struct NameSpaceStruct {
nsIAtom* mPrefix;
PRInt32 mId;
PRInt32 mNestLevel;
};
nsIDocument* mDocument;
nsIURL* mDocumentURL;
nsIWebShell* mWebShell;
nsIContent* mRootElement;
PRUint32 mGenSym; // for generating anonymous resources
nsIRDFResourceManager* mRDFResourceManager;
nsIRDFDataSource* mDataSource; // XXX should this really be a rdf *db* vs. a raw datasource?
RDFContentSinkState mState;
nsVoidArray* mNameSpaces;
PRInt32 mNestLevel;
nsVoidArray* mContextStack;
nsIStyleSheet* mStyleSheet;
nsScrollPreference mOriginalScrollPreference;
PRUnichar* mText;
PRInt32 mTextLength;
PRInt32 mTextSize;
PRBool mConstrainSize;
};
#endif // nsRDFContentSink_h__

View File

@ -1,213 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "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 is mostly a naive re-implementation of ht.c. There is currently
lots of stuff missing. For example, sorting, drag-and-drop support,
the "local HT database" (whatever that was for), fast access into
the tree for GetNthItem(). The list goes on and on, and I'm sure
that I don't know the half of it.
*/
#include "nsIDMWidget.h"
#include "nsRDFDataModel.h"
#include "nsRDFDataModelItem.h"
#include "nsIRDFDataBase.h"
#include "nsString.h"
#include "plstr.h"
#include "prprf.h"
#include "rdf-int.h"
static NS_DEFINE_IID(kIDataModelIID, NS_IDATAMODEL_IID);
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
////////////////////////////////////////////////////////////////////////
// Utility functions
static RDF
rdf_GetDefaultDB(void)
{
// hackery that I don't understand from HTRDF_GetDB()
static const char* gNavCenterDataSources1[15] = {
"rdf:localStore",
"rdf:remoteStore",
"rdf:bookmarks",
"rdf:remoteStore",
"rdf:history",
/* "rdf:ldap", */
"rdf:esftp",
/* "rdf:mail", */
#ifdef XP_MAC
"rdf:appletalk",
#endif
"rdf:lfs",
"rdf:ht",
"rdf:columns",
"rdf:find",
NULL
};
return RDF_GetDB(gNavCenterDataSources1);
}
////////////////////////////////////////////////////////////////////////
nsRDFDataModel::nsRDFDataModel(void)
: mDB(NULL),
mRoot(NULL),
mWidget(NULL),
mArcProperty(NULL)
{
PR_ASSERT(gCoreVocab);
if (gCoreVocab) {
mArcProperty = gCoreVocab->RDF_parent;
mArcType = eRDFArcType_Inbound;
}
NS_INIT_REFCNT();
}
nsRDFDataModel::~nsRDFDataModel(void)
{
if (mRoot)
mRoot->Release();
if (mDB)
RDF_ReleaseDB(mDB);
}
NS_IMPL_ADDREF(nsRDFDataModel);
NS_IMPL_RELEASE(nsRDFDataModel);
NS_IMPL_QUERY_INTERFACE(nsRDFDataModel, kIDataModelIID);
////////////////////////////////////////////////////////////////////////
// nsIDataModel interface
NS_IMETHODIMP
nsRDFDataModel::InitFromURL(const nsString& aUrl)
{
// XXX A ghastly simplification of HT_PaneFromURL()
char* url = aUrl.ToNewCString();
const char* dbstr[2];
dbstr[0] = getBaseURL(url);
dbstr[1] = NULL;
mDB = RDF_GetDB(dbstr);
PL_strfree(const_cast<char*>(dbstr[0]));
// XXX now we try to find the top-level resource in the
// database. PR_FALSE indicates that, if it ain't there, don't
// create it.
RDF_Resource r = RDF_GetResource(mDB, url, PR_FALSE);
delete url;
PR_ASSERT(r);
if (! r)
return NS_ERROR_UNEXPECTED;
nsRDFDataModelItem* item;
nsresult res = CreateItem(r, item);
if (NS_FAILED(res))
return res;
if (mRoot)
mRoot->Release();
mRoot = item; // n.b. implicit AddRef() in CreateItem()
mRoot->SetOpenState(PR_TRUE);
return NS_OK;
}
NS_IMETHODIMP
nsRDFDataModel::InitFromResource(nsIDMItem* pItem)
{
nsIRDFResource* resource;
if (NS_FAILED(pItem->QueryInterface(kIRDFResourceIID, (void**) &resource)))
return NS_ERROR_INVALID_ARG;
nsresult res = NS_OK;
do {
RDF_Resource r;
if (NS_FAILED(res = resource->GetResource(r)))
break;
nsRDFDataModelItem* item;
if (NS_FAILED(res = CreateItem(r, item)))
break;
if (mRoot)
mRoot->Release();
mRoot = item; // n.b. implicit AddRef() in CreateItem()
mRoot->SetOpenState(PR_TRUE);
if (mDB)
RDF_ReleaseDB(mDB);
mDB = rdf_GetDefaultDB();
} while (0);
resource->Release();
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
nsRDFDataModel::GetDMWidget(nsIDMWidget*& widget) const
{
NS_IF_ADDREF(mWidget);
widget = mWidget;
return NS_OK;
}
NS_IMETHODIMP
nsRDFDataModel::SetDMWidget(nsIDMWidget* widget)
{
NS_IF_ADDREF(widget);
NS_IF_RELEASE(mWidget);
mWidget = widget;
return NS_OK;
}
NS_IMETHODIMP
nsRDFDataModel::GetStringPropertyValue(nsString& value, const nsString& property) const
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsRDFDataModel::GetIntPropertyValue(PRInt32& value, const nsString& property) const
{
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////
// Implementation methods

View File

@ -1,99 +0,0 @@
/* -*- 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.
*/
#ifndef nsRDFDataModel_h__
#define nsRDFDataModel_h__
#include "nsIDataModel.h"
#include "rdf.h" // XXX
class nsString;
class nsRDFDataModelItem;
enum nsRDFArcType {
eRDFArcType_Outbound, // follow outbound arcs (e.g., children-of)
eRDFArcType_Inbound // follow inbound arcs (e.g., parent-of)
};
////////////////////////////////////////////////////////////////////////
class nsRDFDataModel : public nsIDataModel {
private:
// XXX eventually, when we XPCOM the back-end
//nsIRDFDataBase& mDB;
RDF mDB;
nsRDFDataModelItem* mRoot;
nsIDMWidget* mWidget;
RDF_Resource mArcProperty;
nsRDFArcType mArcType;
public:
nsRDFDataModel(void);
virtual ~nsRDFDataModel(void);
////////////////////////////////////////////////////////////////////////
// nsISupports
NS_DECL_ISUPPORTS
////////////////////////////////////////////////////////////////////////
// nsIDataModel interface
// Initializers
NS_IMETHOD InitFromURL(const nsString& url);
NS_IMETHOD InitFromResource(nsIDMItem* pResource);
// Inspectors
NS_IMETHOD GetDMWidget(nsIDMWidget*& pWidget) const;
// Setters
NS_IMETHOD SetDMWidget(nsIDMWidget* pWidget);
// Methods to query the data model for property values for an entire widget.
NS_IMETHOD GetStringPropertyValue(nsString& value, const nsString& property) const;
NS_IMETHOD GetIntPropertyValue(PRInt32& value, const nsString& property) const;
////////////////////////////////////////////////////////////////////////
// Implementation methods
RDF GetDB(void) const {
return mDB;
}
nsRDFDataModelItem* GetRoot(void) const {
return mRoot;
}
RDF_Resource GetArcProperty(void) const {
return mArcProperty;
}
nsRDFArcType GetArcType(void) const {
return mArcType;
}
// Internal accessor for the widget. Just wraps a member variable access.
nsIDMWidget* GetWidget() { return mWidget; }
virtual NS_METHOD
CreateItem(RDF_Resource r, nsRDFDataModelItem*& result) = 0;
};
#endif // nsRDFDataModel_h__

View File

@ -1,262 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "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 "nsRDFDataModel.h"
#include "nsRDFDataModelItem.h"
#include "rdf-int.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIDMItemIID, NS_IDMITEM_IID);
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
////////////////////////////////////////////////////////////////////////
nsRDFDataModelItem::nsRDFDataModelItem(nsRDFDataModel& model, RDF_Resource resource)
: mDataModel(model),
mResource(resource),
mOpen(PR_FALSE),
mParent(NULL),
mCachedSubtreeSize(1)
{
NS_INIT_REFCNT();
}
nsRDFDataModelItem::~nsRDFDataModelItem(void)
{
for (PRUint32 i = 0; i < mChildren.GetSize(); ++i) {
nsRDFDataModelItem* child = static_cast<nsRDFDataModelItem*>(mChildren[i]);
child->Release();
}
}
NS_IMPL_ADDREF(nsRDFDataModelItem);
NS_IMPL_RELEASE(nsRDFDataModelItem);
NS_IMETHODIMP
nsRDFDataModelItem::QueryInterface(const nsIID& iid, void** result)
{
if (! result)
return NS_ERROR_NULL_POINTER;
*result = NULL;
if (iid.Equals(kIDMItemIID) ||
iid.Equals(kISupportsIID)) {
*result = static_cast<nsIDMItem*>(this);
AddRef();
return NS_OK;
}
else if (iid.Equals(kIRDFResourceIID)) {
*result = static_cast<nsIRDFResource*>(this);
AddRef();
return NS_OK;
}
return NS_ERROR_NO_INTERFACE;
}
////////////////////////////////////////////////////////////////////////
// nsIDMItem interface
NS_IMETHODIMP
nsRDFDataModelItem::GetIconImage(nsIImage*& image, nsIImageGroup* group) const
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsRDFDataModelItem::GetOpenState(PRBool& result) const
{
result = IsOpen();
return NS_OK;
}
// XXX I assume this is coming...
NS_IMETHODIMP
nsRDFDataModelItem::SetOpenState(PRBool open)
{
if (open)
Open();
else
Close();
return NS_OK;
}
NS_IMETHODIMP
nsRDFDataModelItem::GetChildCount(PRUint32& count) const
{
count = mChildren.GetSize();
return NS_OK;
}
NS_IMETHODIMP
nsRDFDataModelItem::GetNthChild(nsIDMItem*& pItem, PRUint32 n) const
{
if (n < 0 || n > mChildren.GetUpperBound())
return NS_ERROR_UNEXPECTED; // XXX
pItem = static_cast<nsIDMItem*>(mChildren[n]);
pItem->AddRef();
return NS_OK;
}
NS_IMETHODIMP
nsRDFDataModelItem::GetSubtreeSize(PRUint32& result) const
{
if (! mCachedSubtreeSize) {
mCachedSubtreeSize = 1; // me
for (PRUint32 i = 0; i < mChildren.GetSize(); ++i) {
nsRDFDataModelItem* child =
static_cast<nsRDFDataModelItem*>(mChildren[i]);
PRUint32 childSubtreeSize;
child->GetSubtreeSize(childSubtreeSize);
mCachedSubtreeSize += childSubtreeSize;
}
}
result = mCachedSubtreeSize;
return NS_OK;
}
NS_IMETHODIMP
nsRDFDataModelItem::GetParent(nsIDMItem*& pItem) const
{
pItem = static_cast<nsIDMItem*>(mParent);
return NS_OK;
}
NS_IMETHODIMP
nsRDFDataModelItem::GetStringPropertyValue(nsString& result, const nsString& property) const
{
// 1. convert the property to a URI
// 2. ask the RDF database for the value of the property
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsRDFDataModelItem::GetIntPropertyValue(PRInt32& value, const nsString& itemProperty) const
{
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////
// nsIRDFResource interface
NS_IMETHODIMP
nsRDFDataModelItem::GetResource(RDF_Resource& resource /* out */) const
{
resource = mResource;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// Implementation methods
void
nsRDFDataModelItem::InvalidateCachedSubtreeSize(void)
{
if (mCachedSubtreeSize) {
mCachedSubtreeSize = 0;
if (mParent)
mParent->InvalidateCachedSubtreeSize();
}
}
void
nsRDFDataModelItem::AddChild(nsRDFDataModelItem* child)
{
mChildren.Add(child);
nsRDFDataModelItem* item = this;
while (item) {
PRUint32 subtreeSize;
child->GetSubtreeSize(subtreeSize);
item->mCachedSubtreeSize += subtreeSize;
item = item->mParent;
}
}
void
nsRDFDataModelItem::Open(void)
{
RDF_Cursor cursor;
if (mDataModel.GetArcType() == eRDFArcType_Outbound) {
// Arcs are outbound, that is, from a parent to it's
// child. Find all targets whose source is "me".
cursor = RDF_GetTargets(mDataModel.GetDB(),
mResource,
mDataModel.GetArcProperty(),
RDF_RESOURCE_TYPE,
PR_TRUE);
}
else {
// Arcs are inbound, that is, from a child to it's
// parent. Find all sources whose target is "me".
cursor = RDF_GetSources(mDataModel.GetDB(),
mResource,
mDataModel.GetArcProperty(),
RDF_RESOURCE_TYPE,
PR_TRUE);
}
if (cursor) {
RDF_Resource r;
while ((r = static_cast<RDF_Resource>(RDF_NextValue(cursor))) != NULL) {
nsRDFDataModelItem* child;
if (NS_FAILED(mDataModel.CreateItem(r, child)))
continue;
// CreateItem() will have done an AddRef(), like a good
// COM citizen...
mChildren.Add(child);
child->mParent = this;
}
RDF_DisposeCursor(cursor);
}
InvalidateCachedSubtreeSize();
mOpen = PR_TRUE;
}
void
nsRDFDataModelItem::Close(void)
{
for (PRUint32 i = 0; i < mChildren.GetSize(); ++i) {
nsRDFDataModelItem* child = static_cast<nsRDFDataModelItem*>(mChildren[i]);
child->Release();
}
InvalidateCachedSubtreeSize();
mOpen = PR_FALSE;
}

View File

@ -1,118 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "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 nsRDFDataModelItem_h__
#define nsRDFDataModelItem_h__
#include "rdf.h"
#include "nsIDMItem.h"
#include "nsIRDFResource.h"
#include "nsVector.h"
class nsRDFDataModel;
////////////////////////////////////////////////////////////////////////
class nsRDFDataModelItem : public nsIDMItem, public nsIRDFResource {
private:
nsRDFDataModel& mDataModel;
RDF_Resource mResource;
PRBool mOpen;
nsVector mChildren;
nsRDFDataModelItem* mParent;
/**
* A cached value for the size of this item's subtree. Zero means "invalid"
* or "unknown", and the next call to GetSubtreeSize() will force it to be
* recomputed.
*/
mutable PRUint32 mCachedSubtreeSize;
void InvalidateCachedSubtreeSize(void);
public:
nsRDFDataModelItem(nsRDFDataModel& model, RDF_Resource resource);
virtual ~nsRDFDataModelItem(void);
////////////////////////////////////////////////////////////////////////
// nsISupports interface
NS_DECL_ISUPPORTS
////////////////////////////////////////////////////////////////////////
// nsIDMItem interface
// Inspectors
NS_IMETHOD GetIconImage(nsIImage*& pImage, nsIImageGroup* pGroup) const;
NS_IMETHOD GetOpenState(PRBool& answer) const;
// Methods for iterating over children.
NS_IMETHOD GetChildCount(PRUint32& count) const;
NS_IMETHOD GetNthChild(nsIDMItem*& pItem, PRUint32 item) const;
NS_IMETHOD GetSubtreeSize(PRUint32& result) const;
// Parent access
NS_IMETHOD GetParent(nsIDMItem*& pItem) const;
// Setters
NS_IMETHOD SetOpenState(PRBool state); // XXX not there yet...
// Methods to query the data model for a specific item displayed within the widget.
NS_IMETHOD GetStringPropertyValue(nsString& value, const nsString& itemProperty) const;
NS_IMETHOD GetIntPropertyValue(PRInt32& value, const nsString& itemProperty) const;
////////////////////////////////////////////////////////////////////////
// nsIRDFResource interface
NS_IMETHOD GetResource(RDF_Resource& resource /* out */) const;
////////////////////////////////////////////////////////////////////////
// Implementation methods
nsRDFDataModel& GetDataModel(void) const {
return mDataModel;
}
PRBool IsOpen(void) const {
return mOpen;
}
void Open(void);
void Close(void);
nsRDFDataModelItem* ChildAt(PRUint32 index) const {
return static_cast<nsRDFDataModelItem*>(mChildren[index]);
}
void AddChild(nsRDFDataModelItem* child);
PRUint32 GetChildCount(void) const {
return mChildren.GetSize();
}
nsRDFDataModelItem* GetParent(void) const {
return mParent;
}
};
////////////////////////////////////////////////////////////////////////
#endif // nsRDFDataModelItem_h__

311
rdf/src/nsRDFDocument.cpp Normal file
View File

@ -0,0 +1,311 @@
/* -*- 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.
*/
#include "nsIDTD.h"
#include "nsIParser.h"
#include "nsIRDFContentSink.h"
#include "nsIStreamListener.h"
#include "nsIWebShell.h"
#include "nsIURL.h"
#include "nsParserCIID.h"
#include "nsRDFDocument.h"
#include "nsWellFormedDTD.h"
#include "nsRDFCID.h"
#include "nsIRDFDataBase.h"
#include "nsIRDFDataSource.h"
#include "nsIRDFNode.h"
#include "nsIHTMLStyleSheet.h" // for basic styles
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
static NS_DEFINE_IID(kIParserIID, NS_IPARSER_IID);
static NS_DEFINE_IID(kIRDFDocumentIID, NS_IRDFDOCUMENT_IID);
static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
static NS_DEFINE_IID(kIXMLDocumentIID, NS_IXMLDOCUMENT_IID);
static NS_DEFINE_IID(kIRDFDataBaseIID, NS_IRDFDATABASE_IID);
static NS_DEFINE_CID(kRDFSimpleDataBaseCID, NS_RDFSIMPLEDATABASE_CID);
struct NameSpaceStruct {
nsIAtom* mPrefix;
nsString mURI;
};
////////////////////////////////////////////////////////////////////////
nsRDFDocument::nsRDFDocument()
: mParser(NULL),
mNameSpaces(NULL),
mDB(NULL)
{
}
nsRDFDocument::~nsRDFDocument()
{
NS_IF_RELEASE(mParser);
if (mNameSpaces) {
for (PRInt32 i = 0; i < mNameSpaces->Count(); ++i) {
NameSpaceStruct* ns =
static_cast<NameSpaceStruct*>(mNameSpaces->ElementAt(i));
if (! ns)
continue;
NS_IF_RELEASE(ns->mPrefix);
delete ns;
}
delete mNameSpaces;
mNameSpaces = NULL;
}
NS_IF_RELEASE(mDB);
}
NS_IMETHODIMP
nsRDFDocument::QueryInterface(REFNSIID iid, void** result)
{
if (! result)
return NS_ERROR_NULL_POINTER;
*result = NULL;
if (iid.Equals(kIRDFDocumentIID) ||
iid.Equals(kIXMLDocumentIID)) {
*result = static_cast<nsIRDFDocument*>(this);
AddRef();
return NS_OK;
}
return nsMarkupDocument::QueryInterface(iid, result);
}
nsrefcnt nsRDFDocument::AddRef()
{
return nsDocument::AddRef();
}
nsrefcnt nsRDFDocument::Release()
{
return nsDocument::Release();
}
NS_IMETHODIMP
nsRDFDocument::StartDocumentLoad(nsIURL *aUrl,
nsIContentViewerContainer* aContainer,
nsIStreamListener **aDocListener,
const char* aCommand)
{
nsresult rv = nsDocument::StartDocumentLoad(aUrl, aContainer,
aDocListener);
if (NS_FAILED(rv)) {
return rv;
}
nsIWebShell* webShell;
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);
rv = nsRepository::CreateInstance(kCParserCID,
nsnull,
kCParserIID,
(void **)&mParser);
if (NS_OK == rv) {
nsIRDFContentSink* sink;
aContainer->QueryInterface(kIWebShellIID, (void**)&webShell);
rv = NS_NewRDFContentSink(&sink, this, aUrl, webShell);
NS_IF_RELEASE(webShell);
if (NS_OK == rv) {
// For the HTML content within a document
nsIHTMLStyleSheet* mAttrStyleSheet;
if (NS_OK == NS_NewHTMLStyleSheet(&mAttrStyleSheet, aUrl, this)) {
AddStyleSheet(mAttrStyleSheet); // tell the world about our new style sheet
}
// Set the parser as the stream listener for the document loader...
static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID);
rv = mParser->QueryInterface(kIStreamListenerIID, (void**)aDocListener);
if (NS_OK == rv) {
nsIDTD* theDTD=0;
// XXX For now, we'll use the "well formed" DTD
NS_NewWellFormed_DTD(&theDTD);
mParser->RegisterDTD(theDTD);
mParser->SetCommand(aCommand);
mParser->SetContentSink(sink);
mParser->Parse(aUrl);
}
NS_RELEASE(sink);
}
}
return rv;
}
NS_IMETHODIMP
nsRDFDocument::EndLoad()
{
NS_IF_RELEASE(mParser);
return nsDocument::EndLoad();
}
////////////////////////////////////////////////////////////////////////
// nsIXMLDocument interface
NS_IMETHODIMP
nsRDFDocument::RegisterNameSpace(nsIAtom* aPrefix, const nsString& aURI,
PRInt32& aNameSpaceId)
{
if (! mNameSpaces) {
mNameSpaces = new nsVoidArray();
if (! mNameSpaces)
return NS_ERROR_OUT_OF_MEMORY;
}
NameSpaceStruct* ns = new NameSpaceStruct;
if (! ns)
return NS_ERROR_OUT_OF_MEMORY;
NS_IF_ADDREF(aPrefix);
ns->mPrefix = aPrefix;
ns->mURI = aURI;
aNameSpaceId = mNameSpaces->Count(); // just an index into the array
mNameSpaces->AppendElement(static_cast<void*>(ns));
return NS_OK;
}
NS_IMETHODIMP
nsRDFDocument::GetNameSpaceURI(PRInt32 aNameSpaceId, nsString& aURI)
{
if (! mNameSpaces)
return NS_ERROR_NULL_POINTER;
if (aNameSpaceId < 0 || aNameSpaceId >= mNameSpaces->Count())
return NS_ERROR_INVALID_ARG;
NameSpaceStruct* ns =
static_cast<NameSpaceStruct*>(mNameSpaces->ElementAt(aNameSpaceId));
if (! ns)
return NS_ERROR_NULL_POINTER;
aURI = ns->mURI;
return NS_OK;
}
NS_IMETHODIMP
nsRDFDocument::GetNameSpacePrefix(PRInt32 aNameSpaceId, nsIAtom*& aPrefix)
{
if (! mNameSpaces)
return NS_ERROR_NULL_POINTER;
if (aNameSpaceId < 0 || aNameSpaceId >= mNameSpaces->Count())
return NS_ERROR_INVALID_ARG;
NameSpaceStruct* ns =
static_cast<NameSpaceStruct*>(mNameSpaces->ElementAt(aNameSpaceId));
if (! ns)
return NS_ERROR_NULL_POINTER;
aPrefix = ns->mPrefix;
NS_IF_ADDREF(aPrefix);
return NS_OK;
}
NS_IMETHODIMP
nsRDFDocument::PrologElementAt(PRInt32 aOffset, nsIContent** aContent)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsRDFDocument::PrologCount(PRInt32* aCount)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsRDFDocument::AppendToProlog(nsIContent* aContent)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsRDFDocument::EpilogElementAt(PRInt32 aOffset, nsIContent** aContent)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsRDFDocument::EpilogCount(PRInt32* aCount)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsRDFDocument::AppendToEpilog(nsIContent* aContent)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////
// nsIRDFDocument interface
NS_IMETHODIMP
nsRDFDocument::GetDataBase(nsIRDFDataBase*& result)
{
if (! mDB)
return NS_ERROR_NOT_INITIALIZED;
result = mDB;
result->AddRef();
return NS_OK;
}
NS_IMETHODIMP
nsRDFDocument::SetDataSource(nsIRDFDataSource* ds)
{
NS_IF_RELEASE(mDB);
nsresult rv;
rv = nsRepository::CreateInstance(kRDFSimpleDataBaseCID,
NULL,
kIRDFDataBaseIID,
(void**) &mDB);
if (NS_FAILED(rv))
return rv;
rv = mDB->AddDataSource(ds);
return rv;
}

76
rdf/src/nsRDFDocument.h Normal file
View File

@ -0,0 +1,76 @@
/* -*- 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.
*/
#ifndef nsRDFDocument_h___
#define nsRDFDocument_h___
#include "nsMarkupDocument.h"
#include "nsIRDFDocument.h"
class nsIParser;
class nsRDFDocument : public nsMarkupDocument,
public nsIRDFDocument
{
public:
nsRDFDocument();
virtual ~nsRDFDocument();
// nsISupports
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
// Override nsDocument's implementation
NS_IMETHOD StartDocumentLoad(nsIURL *aUrl,
nsIContentViewerContainer* aContainer,
nsIStreamListener **aDocListener,
const char* aCommand);
NS_IMETHOD EndLoad();
// nsIXMLDocument interface
NS_IMETHOD RegisterNameSpace(nsIAtom* aPrefix, const nsString& aURI,
PRInt32& aNameSpaceId);
NS_IMETHOD GetNameSpaceURI(PRInt32 aNameSpaceId, nsString& aURI);
NS_IMETHOD GetNameSpacePrefix(PRInt32 aNameSpaceId, nsIAtom*& aPrefix);
NS_IMETHOD PrologElementAt(PRInt32 aOffset, nsIContent** aContent);
NS_IMETHOD PrologCount(PRInt32* aCount);
NS_IMETHOD AppendToProlog(nsIContent* aContent);
NS_IMETHOD EpilogElementAt(PRInt32 aOffset, nsIContent** aContent);
NS_IMETHOD EpilogCount(PRInt32* aCount);
NS_IMETHOD AppendToEpilog(nsIContent* aContent);
// nsIRDFDocument interface
NS_IMETHOD GetDataBase(nsIRDFDataBase*& result);
NS_IMETHOD SetDataSource(nsIRDFDataSource* ds);
protected:
nsVoidArray* mNameSpaces;
nsIParser* mParser;
nsIRDFDataBase* mDB;
};
#endif // nsRDFDocument_h___

1472
rdf/src/nsRDFElement.cpp Normal file

File diff suppressed because it is too large Load Diff

140
rdf/src/nsRDFElement.h Normal file
View File

@ -0,0 +1,140 @@
/* -*- 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 nsRDFElement_h___
#define nsRDFElement_h___
#include "nsIDOMElement.h"
#include "nsIScriptObjectOwner.h"
#include "nsIDOMEventReceiver.h"
#include "nsIRDFContent.h"
#include "nsIJSScriptObject.h"
class nsIContent;
class nsIRDFDocument;
class nsIAtom;
class nsIEventListenerManager;
class nsIHTMLAttributes;
class nsIRDFNode;
class nsISupportsArray;
// XXX should we make this inheirit from the nsXMLElement
// implementation???
class nsRDFElement : public nsIDOMElement,
public nsIDOMEventReceiver,
public nsIScriptObjectOwner,
public nsIJSScriptObject,
public nsIRDFContent
{
public:
nsRDFElement(void);
~nsRDFElement(void);
// nsISupports
NS_DECL_ISUPPORTS
// nsIDOMNode (from nsIDOMElement)
NS_DECL_IDOMNODE
// nsIDOMElement
NS_DECL_IDOMELEMENT
// nsIScriptObjectOwner
NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void *aScriptObject);
// nsIContent (from nsIRDFContent via nsIXMLContent)
NS_IMETHOD GetDocument(nsIDocument*& aResult) const;
NS_IMETHOD SetDocument(nsIDocument* aDocument, PRBool aDeep);
NS_IMETHOD GetParent(nsIContent*& aResult) const;
NS_IMETHOD SetParent(nsIContent* aParent);
NS_IMETHOD CanContainChildren(PRBool& aResult) const;
NS_IMETHOD ChildCount(PRInt32& aResult) const;
NS_IMETHOD ChildAt(PRInt32 aIndex, nsIContent*& aResult) const;
NS_IMETHOD IndexOf(nsIContent* aPossibleChild, PRInt32& aResult) const;
NS_IMETHOD InsertChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify);
NS_IMETHOD ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify);
NS_IMETHOD AppendChildTo(nsIContent* aKid, PRBool aNotify);
NS_IMETHOD RemoveChildAt(PRInt32 aIndex, PRBool aNotify);
NS_IMETHOD IsSynthetic(PRBool& aResult);
NS_IMETHOD GetTag(nsIAtom*& aResult) const;
NS_IMETHOD SetAttribute(const nsString& aName, const nsString& aValue, PRBool aNotify);
NS_IMETHOD GetAttribute(const nsString& aName, nsString& aResult) const;
NS_IMETHOD UnsetAttribute(nsIAtom* aAttribute, PRBool aNotify);
NS_IMETHOD GetAllAttributeNames(nsISupportsArray* aArray, PRInt32& aResult) const;
NS_IMETHOD GetAttributeCount(PRInt32& aResult) const;
NS_IMETHOD List(FILE* out, PRInt32 aIndent) const;
NS_IMETHOD BeginConvertToXIF(nsXIFConverter& aConverter) const;
NS_IMETHOD ConvertContentToXIF(nsXIFConverter& aConverter) const;
NS_IMETHOD FinishConvertToXIF(nsXIFConverter& aConverter) const;
NS_IMETHOD SizeOf(nsISizeOfHandler* aHandler) const;
NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext,
nsEvent* aEvent,
nsIDOMEvent** aDOMEvent,
PRUint32 aFlags,
nsEventStatus& aEventStatus);
// nsIXMLContent (from nsIRDFContent)
NS_IMETHOD SetNameSpace(nsIAtom* aNameSpace);
NS_IMETHOD GetNameSpace(nsIAtom*& aNameSpace);
NS_IMETHOD SetNameSpaceIdentifier(PRInt32 aNameSpaceId);
NS_IMETHOD GetNameSpaceIdentifier(PRInt32& aNameSpeceId);
// nsIRDFContent
NS_IMETHOD SetResource(const nsString& aURI);
NS_IMETHOD GetResource(nsString& rURI) const;
NS_IMETHOD SetProperty(const nsString& aPropertyURI, const nsString& aValue);
NS_IMETHOD GetProperty(const nsString& aPropertyURI, nsString& rValue) const;
// nsIDOMEventReceiver
NS_IMETHOD AddEventListener(nsIDOMEventListener *aListener, const nsIID& aIID);
NS_IMETHOD RemoveEventListener(nsIDOMEventListener *aListener, const nsIID& aIID);
NS_IMETHOD GetListenerManager(nsIEventListenerManager** aInstancePtrResult);
NS_IMETHOD GetNewListenerManager(nsIEventListenerManager **aInstancePtrResult);
// nsIJSScriptObject
virtual PRBool AddProperty(JSContext *aContext, jsval aID, jsval *aVp);
virtual PRBool DeleteProperty(JSContext *aContext, jsval aID, jsval *aVp);
virtual PRBool GetProperty(JSContext *aContext, jsval aID, jsval *aVp);
virtual PRBool SetProperty(JSContext *aContext, jsval aID, jsval *aVp);
virtual PRBool EnumerateProperty(JSContext *aContext);
virtual PRBool Resolve(JSContext *aContext, jsval aID);
virtual PRBool Convert(JSContext *aContext, jsval aID);
virtual void Finalize(JSContext *aContext);
protected:
nsIRDFDocument* mDocument;
nsIAtom* mNameSpace;
PRInt32 mNameSpaceId;
void* mScriptObject;
nsIRDFNode* mResource;
mutable nsISupportsArray* mChildren;
nsIContent* mParent;
nsresult GenerateChildren(void) const;
nsresult CreateChild(nsIRDFNode* value, nsIRDFContent*& result) const;
nsresult CreateChild(nsIRDFNode* property,
nsIRDFNode* value,
nsIRDFContent*& result) const;
};
#endif // nsRDFElement_h___

View File

@ -18,29 +18,33 @@
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsRDFTreeDataModel.h"
#include "nsRDFToolbarDataModel.h"
#include "nsRDFResourceManager.h"
#include "nsMemoryDataSource.h"
#include "nsBookmarkDataSource.h"
#include "nsSimpleDataBase.h"
#include "nsRDFDocument.h"
#include "nsRDFRegistryImpl.h"
#include "nsRDFCID.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_CID(kRDFTreeDataModelCID, NS_RDFTREEDATAMODEL_CID);
static NS_DEFINE_CID(kRDFToolbarDataModelCID, NS_RDFTOOLBARDATAMODEL_CID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_CID(kRDFBookmarkDataSourceCID, NS_RDFBOOKMARKDATASOURCE_CID);
static NS_DEFINE_CID(kRDFMemoryDataSourceCID, NS_RDFMEMORYDATASOURCE_CID);
static NS_DEFINE_CID(kRDFRegistryCID, NS_RDFREGISTRY_CID);
static NS_DEFINE_CID(kRDFResourceManagerCID, NS_RDFRESOURCEMANAGER_CID);
static NS_DEFINE_CID(kRDFSimpleDataBaseCID, NS_RDFSIMPLEDATABASE_CID);
static NS_DEFINE_CID(kRDFDocumentCID, NS_RDFDOCUMENT_CID);
class nsRDFFactory : public nsIFactory
{
public:
nsRDFFactory(const nsCID &aClass);
////////////////////////////////////////
// nsISupports methods
//
NS_DECL_ISUPPORTS
////////////////////////////////////////
// nsIFactory methods
//
NS_IMETHOD CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult);
@ -107,11 +111,23 @@ nsRDFFactory::CreateInstance(nsISupports *aOuter,
*aResult = NULL;
nsISupports *inst = NULL;
if (mClassID.Equals(kRDFTreeDataModelCID)) {
inst = static_cast<nsITreeDataModel*>(new nsRDFTreeDataModel());
if (mClassID.Equals(kRDFResourceManagerCID)) {
inst = static_cast<nsISupports*>(new nsRDFResourceManager());
}
else if (mClassID.Equals(kRDFToolbarDataModelCID)) {
inst = static_cast<nsIToolbarDataModel*>(new nsRDFToolbarDataModel());
else if (mClassID.Equals(kRDFMemoryDataSourceCID)) {
inst = static_cast<nsISupports*>(new nsMemoryDataSource());
}
else if (mClassID.Equals(kRDFBookmarkDataSourceCID)) {
inst = static_cast<nsISupports*>(new nsBookmarkDataSource());
}
else if (mClassID.Equals(kRDFRegistryCID)) {
inst = static_cast<nsISupports*>(new nsRDFRegistryImpl());
}
else if (mClassID.Equals(kRDFSimpleDataBaseCID)) {
inst = static_cast<nsISupports*>(new nsSimpleDataBase());
}
else if (mClassID.Equals(kRDFDocumentCID)) {
inst = static_cast<nsIRDFDocument*>(new nsRDFDocument());
}
if (! inst)
@ -131,18 +147,14 @@ nsresult nsRDFFactory::LockFactory(PRBool aLock)
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// return the proper factory to the caller
extern "C" PR_EXTERN(nsresult)
NSGetFactory(const nsCID &aClass, nsIFactory **aFactory)
{
static PRBool gInitialized = PR_FALSE;
if (! gInitialized) {
gInitialized = PR_TRUE;
// do one-time library initialization
RDF_Init();
}
if (! aFactory)
return NS_ERROR_NULL_POINTER;
@ -152,3 +164,4 @@ NSGetFactory(const nsCID &aClass, nsIFactory **aFactory)
return (*aFactory)->QueryInterface(kIFactoryIID, (void**)aFactory);
}

View File

@ -0,0 +1,109 @@
/* -*- 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 "nsIRDFDataSource.h"
#include "nsRDFRegistryImpl.h"
#include "nsString.h"
#include "prlog.h"
static NS_DEFINE_IID(kIRDFRegistryIID, NS_IRDFREGISTRY_IID);
////////////////////////////////////////////////////////////////////////
struct RegistryEntry {
nsAutoString mPrefix;
nsIRDFDataSource* mDataSource;
};
////////////////////////////////////////////////////////////////////////
nsRDFRegistryImpl::nsRDFRegistryImpl(void)
{
NS_INIT_REFCNT();
}
nsRDFRegistryImpl::~nsRDFRegistryImpl(void)
{
PR_ASSERT(mDataSources.Count() == 0);
}
NS_IMPL_ISUPPORTS(nsRDFRegistryImpl, kIRDFRegistryIID);
NS_IMETHODIMP
nsRDFRegistryImpl::Register(const nsString& prefix,
nsIRDFDataSource* dataSource)
{
if (! dataSource)
return NS_ERROR_NULL_POINTER;
// Make sure that we don't have duplicates, and that we don't try
// to replace an existing entry...
for (PRInt32 i = mDataSources.Count() - 1; i >= 0; --i) {
RegistryEntry* e = static_cast<RegistryEntry*>(mDataSources[i]);
if (e->mPrefix == prefix)
return NS_ERROR_FAILURE;
// XXX not sure if this is right...
if (e->mDataSource == dataSource)
return NS_ERROR_FAILURE;
}
RegistryEntry* e = new RegistryEntry;
if (! e)
return NS_ERROR_OUT_OF_MEMORY;
e->mPrefix = prefix;
e->mDataSource = dataSource; // n.b., no AddRef()!
mDataSources.AppendElement(e);
return NS_OK;
}
NS_IMETHODIMP
nsRDFRegistryImpl::Unregister(const nsIRDFDataSource* dataSource)
{
for (PRInt32 i = mDataSources.Count() - 1; i >= 0; --i) {
RegistryEntry* e = static_cast<RegistryEntry*>(mDataSources[i]);
if (e->mDataSource == dataSource) {
mDataSources.RemoveElementAt(i);
delete e;
return NS_OK;
}
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsRDFRegistryImpl::Find(const nsString& uri, nsIRDFDataSource*& result)
{
for (PRInt32 i = mDataSources.Count() - 1; i >= 0; --i) {
RegistryEntry* e = static_cast<RegistryEntry*>(mDataSources[i]);
if (uri.Find(e->mPrefix) == 0) {
result = e->mDataSource;
NS_ADDREF(result);
return NS_OK;
}
}
return NS_ERROR_FAILURE;
}

View File

@ -0,0 +1,42 @@
/* -*- 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 nsRDFRegistryImpl_h__
#define nsRDFRegistryImpl_h__
#include "nsIRDFRegistry.h"
#include "nsVoidArray.h"
class nsRDFRegistryImpl : public nsIRDFRegistry {
protected:
nsVoidArray mDataSources;
~nsRDFRegistryImpl(void);
public:
nsRDFRegistryImpl(void);
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIRDFRegistry interface
NS_IMETHOD Register(const nsString& prefix, nsIRDFDataSource* dataSource);
NS_IMETHOD Unregister(const nsIRDFDataSource* dataSource);
NS_IMETHOD Find(const nsString& uri, nsIRDFDataSource*& result);
};
#endif // nsRDFRegistryImpl_h__

View File

@ -0,0 +1,177 @@
/* -*- 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 "nsIRDFNode.h"
#include "nsRDFResourceManager.h"
#include "nsString.h"
#include "nsIAtom.h"
static NS_DEFINE_IID(kIRDFResourceManagerIID, NS_IRDFRESOURCEMANAGER_IID);
////////////////////////////////////////////////////////////////////////
class RDFNodeImpl : public nsIRDFNode {
public:
RDFNodeImpl(nsRDFResourceManager* mgr, nsIAtom* value);
virtual ~RDFNodeImpl(void);
// nsISupports
NS_DECL_ISUPPORTS
// nsIRDFNode
NS_IMETHOD GetStringValue(nsString& value) const;
NS_IMETHOD GetAtomValue(nsIAtom*& value) const;
private:
nsIAtom* mValue;
nsRDFResourceManager* mMgr;
};
RDFNodeImpl::RDFNodeImpl(nsRDFResourceManager* mgr, nsIAtom* value)
: mMgr(mgr), mValue(value)
{
NS_INIT_REFCNT();
NS_IF_ADDREF(mValue);
NS_IF_ADDREF(mMgr);
}
RDFNodeImpl::~RDFNodeImpl(void)
{
mMgr->ReleaseNode(this);
NS_IF_RELEASE(mValue);
NS_IF_RELEASE(mMgr);
}
static NS_DEFINE_IID(kIRDFNodeIID, NS_IRDFNODE_IID);
NS_IMPL_ISUPPORTS(RDFNodeImpl, kIRDFNodeIID);
NS_IMETHODIMP
RDFNodeImpl::GetStringValue(nsString& value) const
{
mValue->ToString(value);
return NS_OK;
}
NS_IMETHODIMP
RDFNodeImpl::GetAtomValue(nsIAtom*& value) const
{
value = mValue;
value->AddRef();
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// ResourceHashKey
class ResourceHashKey : public nsHashKey
{
private:
nsIAtom* mResource;
public:
ResourceHashKey(nsIAtom* resource) : mResource(resource) {
NS_IF_ADDREF(mResource);
}
virtual ~ResourceHashKey(void) {
NS_IF_RELEASE(mResource);
}
// nsHashKey pure virtual interface methods
virtual PRUint32 HashValue(void) const {
return (PRUint32) mResource;
}
virtual PRBool Equals(const nsHashKey* aKey) const {
ResourceHashKey* that;
//if (! (that = dynamic_cast<ResourceHashKey*>(aKey)))
if (! (that = (ResourceHashKey*)(aKey)))
return PR_FALSE;
return (that->mResource == this->mResource);
}
virtual nsHashKey* Clone(void) const {
return new ResourceHashKey(mResource);
}
};
////////////////////////////////////////////////////////////////////////
// nsRDFResourceManager
nsRDFResourceManager::nsRDFResourceManager(void)
{
NS_INIT_REFCNT();
}
nsRDFResourceManager::~nsRDFResourceManager(void)
{
// XXX LEAK! Make sure you release the nodes!
}
NS_IMPL_ISUPPORTS(nsRDFResourceManager, kIRDFResourceManagerIID);
NS_IMETHODIMP
nsRDFResourceManager::GetNode(const nsString& uri, nsIRDFNode*& resource)
{
nsIAtom* atom = NS_NewAtom(uri);
if (!atom)
return NS_ERROR_OUT_OF_MEMORY;
ResourceHashKey key(atom);
resource = static_cast<nsIRDFNode*>(mResources.Get(&key));
if (! resource) {
resource = new RDFNodeImpl(this, atom);
if (resource)
mResources.Put(&key, resource);
// We don't AddRef() the resource.
}
atom->Release();
if (! resource)
return NS_ERROR_OUT_OF_MEMORY;
resource->AddRef();
return NS_OK;
}
void
nsRDFResourceManager::ReleaseNode(const RDFNodeImpl* resource)
{
nsIAtom* atom;
resource->GetAtomValue(atom);
ResourceHashKey key(atom);
atom->Release();
mResources.Remove(&key);
}

View File

@ -0,0 +1,46 @@
/* -*- 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 nsRDFResourceManager_h__
#define nsRDFResourceManager_h__
#include "nsIRDFResourceManager.h"
#include "nsHashtable.h"
class nsString;
class nsIRDFNode;
class RDFNodeImpl;
class nsRDFResourceManager : public nsIRDFResourceManager {
protected:
nsHashtable mResources;
virtual ~nsRDFResourceManager(void);
public:
nsRDFResourceManager(void);
// nsISupports
NS_DECL_ISUPPORTS
// nsIRDFResourceManager
NS_IMETHOD GetNode(const nsString& uri, nsIRDFNode*& resource);
void ReleaseNode(const RDFNodeImpl* resource);
};
#endif // nsRDFResourceManager_h__

View File

@ -1,131 +0,0 @@
/* -*- 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.
*/
#include "nsRDFToolbarDataModel.h"
#include "nsRDFToolbarDataModelItem.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIDataModelIID, NS_IDATAMODEL_IID);
static NS_DEFINE_IID(kIToolbarDataModelIID, NS_ITOOLBARDATAMODEL_IID);
////////////////////////////////////////////////////////////////////////
nsRDFToolbarDataModel::nsRDFToolbarDataModel(void)
{
NS_INIT_REFCNT();
}
nsRDFToolbarDataModel::~nsRDFToolbarDataModel(void)
{
}
NS_IMETHODIMP_(nsrefcnt)
nsRDFToolbarDataModel::AddRef(void)
{
return nsRDFDataModel::AddRef(); // delegate to the superclass
}
NS_IMETHODIMP_(nsrefcnt)
nsRDFToolbarDataModel::Release(void)
{
return nsRDFDataModel::Release(); // delegate to the superclass
}
NS_IMETHODIMP
nsRDFToolbarDataModel::QueryInterface(const nsIID& iid, void** result)
{
if (NULL == result)
return NS_ERROR_NULL_POINTER;
*result = NULL;
if (iid.Equals(kIToolbarDataModelIID)) {
*result = static_cast<nsIToolbarDataModel*>(this);
AddRef();
return NS_OK;
}
// delegate to the superclass
return nsRDFDataModel::QueryInterface(iid, result);
}
////////////////////////////////////////////////////////////////////////
// nsIDataModel implementation -- delgates to superclass
NS_IMETHODIMP
nsRDFToolbarDataModel::InitFromURL(const nsString& url)
{
return nsRDFDataModel::InitFromURL(url);
}
NS_IMETHODIMP
nsRDFToolbarDataModel::InitFromResource(nsIDMItem* pResource)
{
return nsRDFDataModel::InitFromResource(pResource);
}
NS_IMETHODIMP
nsRDFToolbarDataModel::GetDMWidget(nsIDMWidget*& widget) const
{
return nsRDFDataModel::GetDMWidget(widget);
}
NS_IMETHODIMP
nsRDFToolbarDataModel::SetDMWidget(nsIDMWidget* widget)
{
return nsRDFDataModel::SetDMWidget(widget);
}
NS_IMETHODIMP
nsRDFToolbarDataModel::GetStringPropertyValue(nsString& value, const nsString& property) const
{
return nsRDFDataModel::GetStringPropertyValue(value, property);
}
NS_IMETHODIMP
nsRDFToolbarDataModel::GetIntPropertyValue(PRInt32& value, const nsString& property) const
{
return nsRDFDataModel::GetIntPropertyValue(value, property);
}
////////////////////////////////////////////////////////////////////////
// nsIToolbarDataModel interface
////////////////////////////////////////////////////////////////////////
// Implementation methods
NS_METHOD
nsRDFToolbarDataModel::CreateItem(RDF_Resource r, nsRDFDataModelItem*& result)
{
result = new nsRDFToolbarDataModelItem(*this, r);
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
result->AddRef(); // like a good little COM citizen
return NS_OK;
}

View File

@ -1,75 +0,0 @@
/* -*- 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.
*/
#ifndef nsRDFToolbarDataModel_h__
#define nsRDFToolbarDataModel_h__
#include "nsRDFDataModel.h"
#include "nsIToolbarDataModel.h"
#include "rdf.h"
////////////////////////////////////////////////////////////////////////
/**
* An implementation for the Toolbar widget model.
*/
class nsRDFToolbarDataModel : public nsIToolbarDataModel, public nsRDFDataModel {
public:
nsRDFToolbarDataModel(void);
virtual ~nsRDFToolbarDataModel(void);
////////////////////////////////////////////////////////////////////////
// nsISupports interface -- delegates to superclass
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
NS_IMETHOD QueryInterface(const nsIID& iid, void** result);
////////////////////////////////////////////////////////////////////////
// nsIDataModel interface -- delegates to superclass
// Initializers
NS_IMETHOD InitFromURL(const nsString& url);
NS_IMETHOD InitFromResource(nsIDMItem* pResource);
// Inspectors
NS_IMETHOD GetDMWidget(nsIDMWidget*& pWidget) const;
// Setters
NS_IMETHOD SetDMWidget(nsIDMWidget* pWidget);
// Methods to query the data model for property values for an entire widget.
NS_IMETHOD GetStringPropertyValue(nsString& value, const nsString& property) const;
NS_IMETHOD GetIntPropertyValue(PRInt32& value, const nsString& property) const;
////////////////////////////////////////////////////////////////////////
// nsIToolbarDataModel interface
////////////////////////////////////////////////////////////////////////
// Implementation methods
virtual NS_METHOD
CreateItem(RDF_Resource r, nsRDFDataModelItem*& result);
private:
};
#endif // nsRDFToolbarDataModel_h__

View File

@ -1,133 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "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 "nsRDFToolbarDataModelItem.h"
#include "nsRDFToolbarDataModel.h"
static NS_DEFINE_IID(kIToolbarDMItemIID, NS_ITOOLBARDMITEM_IID);
static NS_DEFINE_IID(kIDMItemIID, NS_ITOOLBARDMITEM_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
////////////////////////////////////////////////////////////////////////
nsRDFToolbarDataModelItem::nsRDFToolbarDataModelItem(nsRDFToolbarDataModel& toolbar,
RDF_Resource resource)
: nsRDFDataModelItem(toolbar, resource)
{
}
nsRDFToolbarDataModelItem::~nsRDFToolbarDataModelItem(void)
{
}
NS_IMETHODIMP_(nsrefcnt)
nsRDFToolbarDataModelItem::AddRef(void)
{
return nsRDFDataModelItem::AddRef();
}
NS_IMETHODIMP_(nsrefcnt)
nsRDFToolbarDataModelItem::Release(void)
{
return nsRDFDataModelItem::Release();
}
NS_IMETHODIMP
nsRDFToolbarDataModelItem::QueryInterface(const nsIID& iid, void** result)
{
if (NULL == result)
return NS_ERROR_NULL_POINTER;
*result = NULL;
if (iid.Equals(kIToolbarDMItemIID)) {
*result = static_cast<nsIToolbarDMItem*>(this);
AddRef();
return NS_OK;
}
// delegate to the superclass.
return nsRDFDataModelItem::QueryInterface(iid, result);
}
////////////////////////////////////////////////////////////////////////
// nsIDMItem interface -- delgates to superclass
NS_IMETHODIMP
nsRDFToolbarDataModelItem::GetIconImage(nsIImage*& image, nsIImageGroup* group) const
{
return nsRDFDataModelItem::GetIconImage(image, group);
}
NS_IMETHODIMP
nsRDFToolbarDataModelItem::GetOpenState(PRBool& result) const
{
return nsRDFDataModelItem::GetOpenState(result);
}
NS_IMETHODIMP
nsRDFToolbarDataModelItem::GetChildCount(PRUint32& count) const
{
return nsRDFDataModelItem::GetChildCount(count);
}
NS_IMETHODIMP
nsRDFToolbarDataModelItem::GetNthChild(nsIDMItem*& pItem, PRUint32 item) const
{
return nsRDFDataModelItem::GetNthChild(pItem, item);
}
NS_IMETHODIMP
nsRDFToolbarDataModelItem::GetSubtreeSize(PRUint32& result) const
{
return nsRDFDataModelItem::GetSubtreeSize(result);
}
NS_IMETHODIMP
nsRDFToolbarDataModelItem::GetParent(nsIDMItem*& pItem) const
{
return nsRDFDataModelItem::GetParent(pItem);
}
NS_IMETHODIMP
nsRDFToolbarDataModelItem::SetOpenState(PRBool open)
{
return nsRDFDataModelItem::SetOpenState(open);
}
NS_IMETHODIMP
nsRDFToolbarDataModelItem::GetStringPropertyValue(nsString& result, const nsString& property) const
{
return nsRDFDataModelItem::GetStringPropertyValue(result, property);
}
NS_IMETHODIMP
nsRDFToolbarDataModelItem::GetIntPropertyValue(PRInt32& value, const nsString& itemProperty) const
{
return nsRDFDataModelItem::GetIntPropertyValue(value, itemProperty);
}
////////////////////////////////////////////////////////////////////////
// nsIToolbarDMItem interface

View File

@ -1,77 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "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 nsRDFTreeDataModelItem_h__
#define nsRDFTreeDataModelItem_h__
#include "rdf.h"
#include "nsRDFDataModelItem.h"
#include "nsIToolbarDMItem.h"
class nsRDFToolbarDataModel;
////////////////////////////////////////////////////////////////////////
class nsRDFToolbarDataModelItem : public nsIToolbarDMItem, public nsRDFDataModelItem
{
public:
nsRDFToolbarDataModelItem(nsRDFToolbarDataModel& Toolbar, RDF_Resource resource);
virtual ~nsRDFToolbarDataModelItem(void);
////////////////////////////////////////////////////////////////////////
// nsISupports interface -- delegates to superclass
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
NS_IMETHOD QueryInterface(const nsIID& iid, void** result);
////////////////////////////////////////////////////////////////////////
// nsIDMItem interface -- delegates to superclass
// Inspectors
NS_IMETHOD GetIconImage(nsIImage*& pImage, nsIImageGroup* pGroup) const;
NS_IMETHOD GetOpenState(PRBool& answer) const;
// Methods for iterating over children.
NS_IMETHOD GetChildCount(PRUint32& count) const;
NS_IMETHOD GetNthChild(nsIDMItem*& pItem, PRUint32 item) const;
NS_IMETHOD GetSubtreeSize(PRUint32& result) const;
// Parent access
NS_IMETHOD GetParent(nsIDMItem*& pItem) const;
// Setters
NS_IMETHOD SetOpenState(PRBool open);
// Methods to query the data model for a specific item displayed within the widget.
NS_IMETHOD GetStringPropertyValue(nsString& value, const nsString& itemProperty) const;
NS_IMETHOD GetIntPropertyValue(PRInt32& value, const nsString& itemProperty) const;
////////////////////////////////////////////////////////////////////////
// nsIToolbarItem interface
private:
};
////////////////////////////////////////////////////////////////////////
#endif // nsRDFToolbarDataModelItem_h__

View File

@ -1,173 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "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 "nsRDFTreeColumn.h"
#include "nsRDFTreeDataModel.h"
#include "nsIDMWidget.h"
#include "nsIDataModel.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIDataModelIID, NS_IDATAMODEL_IID);
static NS_DEFINE_IID(kITreeColumnIID, NS_ITREECOLUMN_IID);
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
const PRUint32 nsRDFTreeColumn::kDefaultWidth = 64; // XXX
////////////////////////////////////////////////////////////////////////
nsRDFTreeColumn::nsRDFTreeColumn(nsRDFTreeDataModel& tree,
const nsString& name,
RDF_Resource property,
PRUint32 width)
: mTree(tree),
mName(name),
mProperty(property),
mWidth(width),
mSortState(eColumnSortState_Unsorted),
mDesiredPercentage(0.0)
{
NS_INIT_REFCNT();
mTree.AddRef();
}
nsRDFTreeColumn::~nsRDFTreeColumn(void)
{
}
NS_IMPL_ADDREF(nsRDFTreeColumn);
NS_IMPL_RELEASE(nsRDFTreeColumn);
NS_IMETHODIMP
nsRDFTreeColumn::QueryInterface(const nsIID& iid, void** result)
{
if (! result)
return NS_ERROR_NULL_POINTER;
*result = NULL;
if (iid.Equals(kITreeColumnIID) ||
iid.Equals(kISupportsIID)) {
*result = static_cast<nsITreeColumn*>(this);
AddRef();
return NS_OK;
}
else if (iid.Equals(kIRDFResourceIID)) {
*result = static_cast<nsIRDFResource*>(this);
AddRef();
return NS_OK;
}
return NS_ERROR_NO_INTERFACE;
}
////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP
nsRDFTreeColumn::GetPixelWidth(PRUint32& width) const
{
width = mWidth;
return NS_OK;
}
NS_IMETHODIMP
nsRDFTreeColumn::GetDesiredPercentage(double& percentage) const
{
percentage = mDesiredPercentage;
return NS_OK;
}
NS_IMETHODIMP
nsRDFTreeColumn::GetSortState(nsColumnSortState& answer) const
{
answer = mSortState;
return NS_OK;
}
NS_IMETHODIMP
nsRDFTreeColumn::GetColumnName(nsString& name) const
{
name = mName;
return NS_OK;
}
NS_IMETHODIMP
nsRDFTreeColumn::SetPixelWidth(PRUint32 newWidth)
{
mWidth = newWidth;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// nsIRDFResource interface
NS_IMETHODIMP
nsRDFTreeColumn::GetResource(RDF_Resource& result) const
{
result = mProperty;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// Implementation methods
void
nsRDFTreeColumn::SetVisibility(PRBool visible)
{
if (visible != mVisible) {
mVisible = visible;
nsIDataModel* model;
if (NS_SUCCEEDED(mTree.QueryInterface(kIDataModelIID, (void**) &model))) {
nsIDMWidget* dmWidget;
// XXX if interface inheirits...
//if (NS_SUCCEEDED(mTree.GetDMWidget(dmWidget))) {
if (NS_SUCCEEDED(model->GetDMWidget(dmWidget))) {
#if 0
// XXX IMO, this should be in its own interface. Need to ask Hyatt...
nsITreeWidget* treeWidget;
if (NS_SUCCEEDED(dmWidget->QueryInterface(kITreeWidgetIID, &treeWidget))) {
treeWidget->OnColumnVisibilityChanged(static_cast<nsITreeColumn*>(this),
mVisible);
treeWidget->Release();
}
#endif
dmWidget->Release();
}
model->Release();
}
}
}
PRBool
nsRDFTreeColumn::IsVisible(void) const
{
return mVisible;
}

View File

@ -1,79 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "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 nsRDFTreeColumn_h__
#define nsRDFTreeColumn_h__
#include "nsString.h"
#include "nsITreeColumn.h"
#include "nsIRDFResource.h"
#include "rdf.h"
class nsRDFTreeDataModel;
class nsRDFTreeColumn : public nsITreeColumn, public nsIRDFResource {
private:
nsRDFTreeDataModel& mTree;
nsString mName;
RDF_Resource mProperty;
PRUint32 mWidth;
nsColumnSortState mSortState;
double mDesiredPercentage;
PRBool mVisible;
static const PRUint32 kDefaultWidth;
public:
nsRDFTreeColumn(nsRDFTreeDataModel& tree,
const nsString& name,
const RDF_Resource property,
PRUint32 width = kDefaultWidth);
virtual ~nsRDFTreeColumn(void);
////////////////////////////////////////////////////////////////////////
// nsISupports interface
NS_DECL_ISUPPORTS
////////////////////////////////////////////////////////////////////////
// nsITreeColumn interface
// Inspectors
NS_IMETHOD GetPixelWidth(PRUint32& width) const;
NS_IMETHOD GetDesiredPercentage(double& percentage) const;
NS_IMETHOD GetSortState(nsColumnSortState& answer) const;
NS_IMETHOD GetColumnName(nsString& name) const;
// Setters
NS_IMETHOD SetPixelWidth(PRUint32 newWidth);
////////////////////////////////////////////////////////////////////////
// nsIRDFResource interface
NS_IMETHOD GetResource(RDF_Resource& result /* out */) const;
////////////////////////////////////////////////////////////////////////
// Implementation methods
void SetVisibility(PRBool visible);
PRBool IsVisible(void) const;
};
#endif // nsRDFTreeColumn_h__

View File

@ -1,395 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "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 "nsRDFTreeDataModel.h"
#include "nsRDFTreeColumn.h"
#include "nsRDFTreeDataModelItem.h"
#include "rdf-int.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIDataModelIID, NS_IDATAMODEL_IID);
static NS_DEFINE_IID(kITreeDataModelIID, NS_ITREEDATAMODEL_IID);
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
////////////////////////////////////////////////////////////////////////
#ifdef ALLOW_DYNAMIC_CAST
#define DYNAMIC_CAST(__type, __pointer) dynamic_cast<__type>(__pointer)
#else
#define DYNAMIC_CAST(__type, __pointer) ((__type)(__pointer))
#endif
static nsITreeDMItem*
rdf_GetNth(nsIDMItem* node, PRUint32 n)
{
// XXX this algorithm sucks: it's O(m*log(n)), where m is the
// branching factor and n is the depth of the tree. We need to
// eventually do something like the old HT did: keep a
// vector. Alternatively, hyatt suggested that is we can keep a
// pointer to the topmost node, m will be kept small.
if (n == 0) {
node->AddRef();
return DYNAMIC_CAST(nsITreeDMItem*, node);
}
// iterate through all of the children. since we know the subtree
// height of each child, we can determine a range of indices
// contained within the subtree.
PRUint32 childCount;
if (NS_SUCCEEDED(node->GetChildCount(childCount))) {
PRUint32 firstIndexInSubtree = 1;
for (PRUint32 i = 0; i < childCount; ++i) {
nsIDMItem* child;
if (NS_FAILED(node->GetNthChild(child, i))) {
PR_ASSERT(0);
continue;
}
PRUint32 subtreeSize;
child->GetSubtreeSize(subtreeSize);
PRUint32 lastIndexInSubtree = firstIndexInSubtree + subtreeSize;
nsITreeDMItem* result = NULL;
if (n >= firstIndexInSubtree && n < lastIndexInSubtree)
result = rdf_GetNth(child, n - firstIndexInSubtree);
child->Release();
if (result)
return result;
firstIndexInSubtree = lastIndexInSubtree;
}
}
// n was larger than the total number of elements in the tree! You
// should've called GetTreeItemCount() first...
PR_ASSERT(0);
return NULL;
}
////////////////////////////////////////////////////////////////////////
nsRDFTreeDataModel::nsRDFTreeDataModel(void)
{
}
nsRDFTreeDataModel::~nsRDFTreeDataModel(void)
{
for (PRUint32 i = 0; i < mColumns.GetSize(); ++i) {
nsRDFTreeColumn* column = static_cast<nsRDFTreeColumn*>(mColumns[i]);
PR_ASSERT(column);
if (! column)
continue;
column->Release();
}
}
NS_IMETHODIMP_(nsrefcnt)
nsRDFTreeDataModel::AddRef(void)
{
return nsRDFDataModel::AddRef(); // delegate to the superclass
}
NS_IMETHODIMP_(nsrefcnt)
nsRDFTreeDataModel::Release(void)
{
return nsRDFDataModel::Release(); // delegate to the superclass
}
NS_IMETHODIMP
nsRDFTreeDataModel::QueryInterface(const nsIID& iid, void** result)
{
if (NULL == result)
return NS_ERROR_NULL_POINTER;
*result = NULL;
if (iid.Equals(kITreeDataModelIID)) {
*result = static_cast<nsITreeDataModel*>(this);
AddRef();
return NS_OK;
}
return nsRDFDataModel::QueryInterface(iid, result);
}
////////////////////////////////////////////////////////////////////////
// nsIDataModel implementation -- delgates to superclass
NS_IMETHODIMP
nsRDFTreeDataModel::InitFromURL(const nsString& url)
{
nsresult res = nsRDFDataModel::InitFromURL(url);
if (NS_SUCCEEDED(res))
res = CreateColumns();
return res;
}
NS_IMETHODIMP
nsRDFTreeDataModel::InitFromResource(nsIDMItem* pResource)
{
return nsRDFDataModel::InitFromResource(pResource);
}
NS_IMETHODIMP
nsRDFTreeDataModel::GetDMWidget(nsIDMWidget*& widget) const
{
return nsRDFDataModel::GetDMWidget(widget);
}
NS_IMETHODIMP
nsRDFTreeDataModel::SetDMWidget(nsIDMWidget* widget)
{
return nsRDFDataModel::SetDMWidget(widget);
}
NS_IMETHODIMP
nsRDFTreeDataModel::GetStringPropertyValue(nsString& value, const nsString& property) const
{
return nsRDFDataModel::GetStringPropertyValue(value, property);
}
NS_IMETHODIMP
nsRDFTreeDataModel::GetIntPropertyValue(PRInt32& value, const nsString& property) const
{
return nsRDFDataModel::GetIntPropertyValue(value, property);
}
////////////////////////////////////////////////////////////////////////
// nsITreeDataModel interface
NS_IMETHODIMP
nsRDFTreeDataModel::GetVisibleColumnCount(PRUint32& count) const
{
count = 0;
for (PRUint32 i = 0; i < mColumns.GetSize(); ++i) {
nsRDFTreeColumn* column = static_cast<nsRDFTreeColumn*>(mColumns.Get(i));
if (column->IsVisible())
++count;
}
return NS_OK;
}
NS_IMETHODIMP
nsRDFTreeDataModel::GetColumnCount(PRUint32& count) const
{
count = mColumns.GetSize();
return NS_OK;
}
NS_IMETHODIMP
nsRDFTreeDataModel::GetNthColumn(nsITreeColumn*& pColumn, PRUint32 n) const
{
if (n < 0 || n > mColumns.GetUpperBound()) {
PR_ASSERT(0);
return NS_ERROR_ILLEGAL_VALUE;
}
pColumn = static_cast<nsITreeColumn*>(mColumns.Get(n));
pColumn->AddRef();
return NS_OK;
}
NS_IMETHODIMP
nsRDFTreeDataModel::GetFirstVisibleItemIndex(PRUint32& index) const
{
// XXX hack! where do we ever set this???
index = 0;
return NS_OK;
}
NS_IMETHODIMP
nsRDFTreeDataModel::GetTreeItemCount(PRUint32& result) const
{
nsRDFDataModelItem* root = GetRoot();
if (! root)
return NS_ERROR_NOT_INITIALIZED;
return root->GetSubtreeSize(result);
}
NS_IMETHODIMP
nsRDFTreeDataModel::GetNthTreeItem(nsITreeDMItem*& pItem, PRUint32 n) const
{
nsRDFDataModelItem* root = GetRoot();
if (! root)
return NS_ERROR_NOT_INITIALIZED;
pItem = rdf_GetNth(root, n);
return pItem ? NS_OK : NS_ERROR_INVALID_ARG;
}
NS_IMETHODIMP
nsRDFTreeDataModel::GetItemTextForColumn(nsString& result,
nsITreeDMItem* pItem,
nsITreeColumn* pColumn) const
{
// XXX this is a horribly simplified version of what
// HT_GetNodeData() does. Hopefully it's enough to do the job for
// now.
nsresult res = NS_OK;
nsIRDFResource* itemRsrc = NULL;
nsIRDFResource* columnRsrc = NULL;
do {
if (NS_FAILED(res = pItem->QueryInterface(kIRDFResourceIID, (void**) &itemRsrc)))
break;
if (NS_FAILED(res = pColumn->QueryInterface(kIRDFResourceIID, (void**) &columnRsrc)))
break;
RDF_Resource item;
if (NS_FAILED(res = itemRsrc->GetResource(item)))
break;
RDF_Resource property;
if (NS_FAILED(res = columnRsrc->GetResource(property)))
break;
const char* text =
(const char*) RDF_GetSlotValue(GetDB(),
item,
property, // property
RDF_STRING_TYPE,
PR_FALSE,
PR_TRUE);
if (! text) {
res = NS_ERROR_UNEXPECTED;
break;
}
result = nsString(text);
} while (0);
if (columnRsrc)
columnRsrc->Release();
if (itemRsrc)
itemRsrc->Release();
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// nsRDFTreeDataModel implementation methods
nsresult
nsRDFTreeDataModel::CreateColumns(void)
{
/*
// XXX manually add columns for testing
AddColumn(nsString("Name"), gCoreVocab->RDF_name);
AddColumn(nsString("Last Modified"), gWebData->RDF_lastModifiedDate);
AddColumn(nsString("Last Visited"), gWebData->RDF_lastVisitDate);
AddColumn(nsString("Description"), gWebData->RDF_description);
return NS_OK;
*/
// This mostly came over from HT_NewView()
nsRDFDataModelItem* root = GetRoot();
PR_ASSERT(root);
if (! root)
return NS_ERROR_NULL_POINTER; // XXX need something better here
RDF_Resource rootResource;
if (NS_FAILED(root->GetResource(rootResource)))
return NS_ERROR_UNEXPECTED;
RDF_Cursor cursor;
cursor = RDF_GetSources(GetDB(), rootResource,
gNavCenter->RDF_Column,
RDF_RESOURCE_TYPE, PR_TRUE);
PR_ASSERT(cursor != NULL);
if (cursor == NULL)
return NS_ERROR_UNEXPECTED; // XXX need something better here
RDF_Resource r;
while ((r = static_cast<RDF_Resource>(RDF_NextValue(cursor))) != NULL) {
if (resourceID(r) == NULL)
break;
#if 0 // XXX no datatype support yet...
PRUint32 type;
type = (PRUint32) RDF_GetSlotValue(GetDB(), r, gNavCenter->RDF_ColumnDataType,
RDF_INT_TYPE, PR_FALSE, PR_TRUE);
if (!type)
type = HT_COLUMN_STRING;
#endif
PRUint32 width;
width = (PRUint32) RDF_GetSlotValue(GetDB(), r, gNavCenter->RDF_ColumnWidth,
RDF_INT_TYPE, PR_FALSE, PR_TRUE);
const char* name;
name = (const char *) RDF_GetSlotValue(GetDB(), r, gCoreVocab->RDF_name,
RDF_STRING_TYPE, PR_FALSE, PR_TRUE);
nsRDFTreeColumn* column = new nsRDFTreeColumn(*this, name, r, width);
PR_ASSERT(column);
if (! column)
continue;
column->AddRef();
mColumns.Add(column);
}
RDF_DisposeCursor(cursor);
return NS_OK;
}
void
nsRDFTreeDataModel::AddColumn(const nsString& name, RDF_Resource property)
{
nsRDFTreeColumn* column = new nsRDFTreeColumn(*this, name, property);
mColumns.Add(column);
}
NS_METHOD
nsRDFTreeDataModel::CreateItem(RDF_Resource r, nsRDFDataModelItem*& result)
{
result = new nsRDFTreeDataModelItem(*this, r);
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
result->AddRef(); // like a good little COM citizen
return NS_OK;
}

View File

@ -1,93 +0,0 @@
/* -*- 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.
*/
#ifndef nsRDFTreeDataModel_h__
#define nsRDFTreeDataModel_h__
#include "nsRDFDataModel.h"
#include "nsITreeDataModel.h"
#include "nsVector.h"
#include "rdf.h"
////////////////////////////////////////////////////////////////////////
/**
* An implementation for the tree widget model.
*/
class nsRDFTreeDataModel : public nsITreeDataModel, public nsRDFDataModel {
public:
nsRDFTreeDataModel(void);
virtual ~nsRDFTreeDataModel(void);
////////////////////////////////////////////////////////////////////////
// nsISupports interface -- delgates to superclass
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
NS_IMETHOD QueryInterface(const nsIID& iid, void** result);
////////////////////////////////////////////////////////////////////////
// nsIDataModel interface -- delgates to superclass
// Initializers
NS_IMETHOD InitFromURL(const nsString& url);
NS_IMETHOD InitFromResource(nsIDMItem* pResource);
// Inspectors
NS_IMETHOD GetDMWidget(nsIDMWidget*& pWidget) const;
// Setters
NS_IMETHOD SetDMWidget(nsIDMWidget* pWidget);
// Methods to query the data model for property values for an entire widget.
NS_IMETHOD GetStringPropertyValue(nsString& value, const nsString& property) const;
NS_IMETHOD GetIntPropertyValue(PRInt32& value, const nsString& property) const;
////////////////////////////////////////////////////////////////////////
// nsITreeDataModel interface
// Column APIs
NS_IMETHOD GetVisibleColumnCount(PRUint32& count) const;
NS_IMETHOD GetColumnCount(PRUint32& count) const;
NS_IMETHOD GetNthColumn(nsITreeColumn*& pColumn, PRUint32 n) const;
// TreeItem APIs
NS_IMETHOD GetFirstVisibleItemIndex(PRUint32& index) const;
NS_IMETHOD GetTreeItemCount(PRUint32& result) const;
NS_IMETHOD GetNthTreeItem(nsITreeDMItem*& pItem, PRUint32 n) const;
NS_IMETHOD GetItemTextForColumn(nsString& nodeText, nsITreeDMItem* pItem, nsITreeColumn* pColumn) const;
////////////////////////////////////////////////////////////////////////
// Implemantation methods
void AddColumn(const nsString& name, RDF_Resource property);
virtual NS_METHOD
CreateItem(RDF_Resource r, nsRDFDataModelItem*& result);
private:
nsVector mColumns;
nsresult CreateColumns(void);
};
#endif // nsRDFTreeDataModel_h__

View File

@ -1,160 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "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 "nsRDFTreeDataModelItem.h"
#include "nsRDFTreeDataModel.h"
const PRUint32 nsRDFTreeDataModelItem::kInvalidIndentationLevel = PRUint32(-1);
static NS_DEFINE_IID(kIDMItemIID, NS_IDMITEM_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kITreeDMItemIID, NS_ITREEDMITEM_IID);
////////////////////////////////////////////////////////////////////////
nsRDFTreeDataModelItem::nsRDFTreeDataModelItem(nsRDFTreeDataModel& tree,
RDF_Resource resource)
: nsRDFDataModelItem(tree, resource)
{
}
nsRDFTreeDataModelItem::~nsRDFTreeDataModelItem(void)
{
}
NS_IMETHODIMP_(nsrefcnt)
nsRDFTreeDataModelItem::AddRef(void)
{
return nsRDFDataModelItem::AddRef();
}
NS_IMETHODIMP_(nsrefcnt)
nsRDFTreeDataModelItem::Release(void)
{
return nsRDFDataModelItem::Release();
}
NS_IMETHODIMP
nsRDFTreeDataModelItem::QueryInterface(const nsIID& iid, void** result)
{
if (NULL == result)
return NS_ERROR_NULL_POINTER;
*result = NULL;
if (iid.Equals(kITreeDMItemIID)) {
*result = static_cast<nsITreeDMItem*>(this);
AddRef();
return NS_OK;
}
// delegate to the superclass.
return nsRDFDataModelItem::QueryInterface(iid, result);
}
////////////////////////////////////////////////////////////////////////
// nsIDMItem interface -- delgates to superclass
NS_IMETHODIMP
nsRDFTreeDataModelItem::GetIconImage(nsIImage*& image, nsIImageGroup* group) const
{
return nsRDFDataModelItem::GetIconImage(image, group);
}
NS_IMETHODIMP
nsRDFTreeDataModelItem::GetOpenState(PRBool& result) const
{
return nsRDFDataModelItem::GetOpenState(result);
}
NS_IMETHODIMP
nsRDFTreeDataModelItem::GetChildCount(PRUint32& count) const
{
return nsRDFDataModelItem::GetChildCount(count);
}
NS_IMETHODIMP
nsRDFTreeDataModelItem::GetNthChild(nsIDMItem*& pItem, PRUint32 item) const
{
return nsRDFDataModelItem::GetNthChild(pItem, item);
}
NS_IMETHODIMP
nsRDFTreeDataModelItem::GetSubtreeSize(PRUint32& result) const
{
return nsRDFDataModelItem::GetSubtreeSize(result);
}
NS_IMETHODIMP
nsRDFTreeDataModelItem::GetParent(nsIDMItem*& pItem) const
{
return nsRDFDataModelItem::GetParent(pItem);
}
NS_IMETHODIMP
nsRDFTreeDataModelItem::SetOpenState(PRBool open)
{
return nsRDFDataModelItem::SetOpenState(open);
}
NS_IMETHODIMP
nsRDFTreeDataModelItem::GetStringPropertyValue(nsString& result, const nsString& property) const
{
return nsRDFDataModelItem::GetStringPropertyValue(result, property);
}
NS_IMETHODIMP
nsRDFTreeDataModelItem::GetIntPropertyValue(PRInt32& value, const nsString& itemProperty) const
{
return nsRDFDataModelItem::GetIntPropertyValue(value, itemProperty);
}
////////////////////////////////////////////////////////////////////////
// nsITreeDMItem interface
NS_IMETHODIMP
nsRDFTreeDataModelItem::GetTriggerImage(nsIImage*& pImage, nsIImageGroup* pGroup) const
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsRDFTreeDataModelItem::GetIndentationLevel(PRUint32& indentation) const
{
PRUint32 i = 0;
nsRDFDataModelItem* item =
static_cast<nsRDFDataModelItem*>(const_cast<nsRDFTreeDataModelItem*>(this));
while ((item = item->GetParent()) != NULL)
i += 1; // XXX should this be some pixel value?
indentation = i;
return NS_OK;
}

View File

@ -1,86 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "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 nsRDFTreeDataModelItem_h__
#define nsRDFTreeDataModelItem_h__
#include "rdf.h"
#include "nsRDFDataModelItem.h"
#include "nsITreeDMItem.h"
class nsRDFTreeDataModel;
////////////////////////////////////////////////////////////////////////
class nsRDFTreeDataModelItem : public nsITreeDMItem, public nsRDFDataModelItem
{
public:
nsRDFTreeDataModelItem(nsRDFTreeDataModel& tree, RDF_Resource resource);
virtual ~nsRDFTreeDataModelItem(void);
////////////////////////////////////////////////////////////////////////
// nsISupports interface
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);
NS_IMETHOD QueryInterface(const nsIID& iid, void** result);
////////////////////////////////////////////////////////////////////////
// nsIDMItem interface -- delegate to the superclass
// Inspectors
NS_IMETHOD GetIconImage(nsIImage*& pImage, nsIImageGroup* pGroup) const;
NS_IMETHOD GetOpenState(PRBool& answer) const;
// Methods for iterating over children.
NS_IMETHOD GetChildCount(PRUint32& count) const;
NS_IMETHOD GetNthChild(nsIDMItem*& pItem, PRUint32 item) const;
NS_IMETHOD GetSubtreeSize(PRUint32& result) const;
// Parent access
NS_IMETHOD GetParent(nsIDMItem*& pItem) const;
// Setters
NS_IMETHOD SetOpenState(PRBool open);
// Methods to query the data model for a specific item displayed within the widget.
NS_IMETHOD GetStringPropertyValue(nsString& value, const nsString& itemProperty) const;
NS_IMETHOD GetIntPropertyValue(PRInt32& value, const nsString& itemProperty) const;
////////////////////////////////////////////////////////////////////////
// nsITreeItem interface
// Inspectors
NS_IMETHOD GetTriggerImage(nsIImage*& pImage, nsIImageGroup* pGroup) const;
NS_IMETHOD GetIndentationLevel(PRUint32& indentation) const;
// Setters
private:
mutable PRUint32 mCachedIndentationLevel;
static const PRUint32 kInvalidIndentationLevel;
};
////////////////////////////////////////////////////////////////////////
#endif // nsRDFTreeDataModelItem_h__

View File

@ -0,0 +1,638 @@
/* -*- 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 "nsSimpleDataBase.h"
#include "nsIRDFCursor.h"
#include "nsIRDFNode.h"
#include "nsISupportsArray.h"
#include "nsRDFCID.h"
#include "nsRepository.h"
#include "prlog.h"
/*
A simple "database" implementation. An RDF database is just a
"strategy" pattern for combining individual data sources into a
collective graph.
This implementation is pretty much lifted straight out of the old C
RDF implementation. As such, it inheirits some horrible problems.
1) A database is a hard-coded collection of data sources. What you'd
really like would be fore data sources to be discovered at
runtime, and added in to the database as needed.
2) The aggregation mechanism is horribly ad hoc, specifically, with
respect to negative assertions. It works something like this.
Check the "first" data source for a negative assertion. If it has
one, then return it. Otherwise, check the "rest" of the data
sources for a positive assertion.
3) Related to the above, there are no clear semantics for ordering
or precedence. Things all depend on the order that you said "add
this data source".
*/
static NS_DEFINE_IID(kIRDFCursorIID, NS_IRDFCURSOR_IID);
static NS_DEFINE_IID(kIRDFDataBaseIID, NS_IRDFDATABASE_IID);
static NS_DEFINE_IID(kIRDFDataSourceIID, NS_IRDFDATASOURCE_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_CID(kRDFBookmarkDataSourceCID, NS_RDFBOOKMARKDATASOURCE_CID);
////////////////////////////////////////////////////////////////////////
// MultiCursor
class MultiCursor : public nsIRDFCursor {
private:
nsIRDFDataSource* mDataSource0;
nsIRDFDataSource** mDataSources;
nsIRDFCursor* mCurrentCursor;
nsIRDFNode* mNextResult;
PRBool mNextTruthValue;
PRInt32 mNextDataSource;
PRInt32 mCount;
public:
MultiCursor(nsVoidArray& dataSources);
virtual ~MultiCursor(void);
NS_DECL_ISUPPORTS;
NS_IMETHOD HasMoreElements(PRBool& result);
NS_IMETHOD GetNext(nsIRDFNode*& next, PRBool& tv);
virtual nsresult
GetCursor(nsIRDFDataSource* ds, nsIRDFCursor*& result) = 0;
virtual nsresult
HasNegation(nsIRDFDataSource* ds0,
nsIRDFNode* nodeToTest,
PRBool tv,
PRBool& result) = 0;
};
MultiCursor::MultiCursor(nsVoidArray& dataSources)
: mDataSource0(NULL),
mDataSources(NULL),
mCurrentCursor(NULL),
mNextResult(NULL),
mCount(0),
mNextDataSource(0)
{
NS_INIT_REFCNT();
mCount = dataSources.Count();
mDataSources = new nsIRDFDataSource*[mCount];
PR_ASSERT(mDataSources);
if (! mDataSources)
return;
for (PRInt32 i = 0; i < mCount; ++i) {
mDataSources[i] = static_cast<nsIRDFDataSource*>(dataSources[i]);
NS_ADDREF(mDataSources[i]);
}
mDataSource0 = mDataSources[0];
NS_ADDREF(mDataSource0);
}
MultiCursor::~MultiCursor(void)
{
NS_IF_RELEASE(mNextResult);
NS_IF_RELEASE(mCurrentCursor);
for (PRInt32 i = mCount - 1; i >= 0; --i) {
NS_IF_RELEASE(mDataSources[i]);
}
NS_IF_RELEASE(mDataSource0);
}
NS_IMPL_ISUPPORTS(MultiCursor, kIRDFCursorIID);
NS_IMETHODIMP
MultiCursor::HasMoreElements(PRBool& result)
{
nsresult rv;
if (! mDataSources)
return NS_ERROR_OUT_OF_MEMORY;
// If we've already queued up a next target, then yep, there are
// more elements.
if (mNextResult) {
result = PR_TRUE;
return NS_OK;
}
// Otherwise, we'll need to find a next target, switching cursors
// if necessary.
result = PR_FALSE;
while (mNextDataSource < mCount) {
if (! mCurrentCursor) {
// We don't have a current cursor, so create a new one on
// the next data source.
rv = GetCursor(mDataSources[mNextDataSource], mCurrentCursor);
if (NS_FAILED(rv))
return rv;
}
do {
if (NS_FAILED(rv = mCurrentCursor->HasMoreElements(result)))
return rv;
// Is the current cursor depleted?
if (!result)
break;
// Even if the current cursor has more elements, we still
// need to check that the current element isn't masked by
// the "main" data source.
// "Peek" ahead and pull out the next target.
if (NS_FAILED(mCurrentCursor->GetNext(mNextResult, mNextTruthValue)))
return rv;
// See if data source zero has the negation
PRBool hasNegation;
if (NS_FAILED(rv = HasNegation(mDataSource0,
mNextResult,
mNextTruthValue,
hasNegation)))
return rv;
// if not, we're done
if (! hasNegation)
return NS_OK;
// Otherwise, we found the negation in data source
// zero. Gotta keep lookin'...
NS_RELEASE(mNextResult);
} while (1);
NS_RELEASE(mCurrentCursor);
NS_RELEASE(mDataSources[mNextDataSource]);
++mNextDataSource;
}
// if we get here, there aren't any elements left.
return NS_OK;
}
NS_IMETHODIMP
MultiCursor::GetNext(nsIRDFNode*& next, PRBool& tv)
{
nsresult rv;
PRBool hasMore;
if (NS_FAILED(rv = HasMoreElements(hasMore)))
return rv;
if (! hasMore)
return NS_ERROR_UNEXPECTED;
next = mNextResult; // no need to AddRef() again...
tv = mNextTruthValue;
mNextResult = NULL; // ...because we'll just "transfer ownership".
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// dbNodeCursorImpl
class dbNodeCursorImpl : public MultiCursor {
private:
nsIRDFNode* mSource;
nsIRDFNode* mProperty;
PRBool mTruthValue;
public:
dbNodeCursorImpl(nsVoidArray& dataSources,
nsIRDFNode* source,
nsIRDFNode* property,
PRBool tv);
virtual ~dbNodeCursorImpl();
virtual nsresult
GetCursor(nsIRDFDataSource* ds, nsIRDFCursor*& result);
virtual nsresult
HasNegation(nsIRDFDataSource* ds0,
nsIRDFNode* nodeToTest,
PRBool tv,
PRBool& result);
};
dbNodeCursorImpl::dbNodeCursorImpl(nsVoidArray& dataSources,
nsIRDFNode* source,
nsIRDFNode* property,
PRBool tv)
: MultiCursor(dataSources),
mSource(source),
mProperty(property),
mTruthValue(tv)
{
NS_IF_ADDREF(mSource);
NS_IF_ADDREF(mProperty);
}
dbNodeCursorImpl::~dbNodeCursorImpl(void)
{
NS_IF_RELEASE(mProperty);
NS_IF_RELEASE(mSource);
}
nsresult
dbNodeCursorImpl::GetCursor(nsIRDFDataSource* ds, nsIRDFCursor*& result)
{
return ds->GetTargets(mSource, mProperty, mTruthValue, result);
}
nsresult
dbNodeCursorImpl::HasNegation(nsIRDFDataSource* ds0,
nsIRDFNode* target,
PRBool tv,
PRBool& result)
{
return ds0->HasAssertion(mSource, mProperty, target, !tv, result);
}
////////////////////////////////////////////////////////////////////////
// dbArcCursorImpl
class dbArcCursorImpl : public MultiCursor {
private:
nsIRDFNode* mSource;
public:
dbArcCursorImpl(nsVoidArray& dataSources, nsIRDFNode* source);
virtual ~dbArcCursorImpl();
virtual nsresult
GetCursor(nsIRDFDataSource* ds, nsIRDFCursor*& result);
virtual nsresult
HasNegation(nsIRDFDataSource* ds0,
nsIRDFNode* nodeToTest,
PRBool tv,
PRBool& result);
};
dbArcCursorImpl::dbArcCursorImpl(nsVoidArray& dataSources,
nsIRDFNode* source)
: MultiCursor(dataSources),
mSource(source)
{
NS_IF_ADDREF(mSource);
}
dbArcCursorImpl::~dbArcCursorImpl(void)
{
NS_IF_RELEASE(mSource);
}
nsresult
dbArcCursorImpl::GetCursor(nsIRDFDataSource* ds, nsIRDFCursor*& result)
{
return ds->ArcLabelsOut(mSource, result);
}
nsresult
dbArcCursorImpl::HasNegation(nsIRDFDataSource* ds0,
nsIRDFNode* target,
PRBool tv,
PRBool& result)
{
result = PR_FALSE;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// nsSimpleDataBase
nsSimpleDataBase::nsSimpleDataBase(void)
{
NS_INIT_REFCNT();
// Add standard data sources here.
// XXX this is so wrong.
nsIRDFDataSource* ds;
if (NS_SUCCEEDED(nsRepository::CreateInstance(kRDFBookmarkDataSourceCID,
NULL,
kIRDFDataSourceIID,
(void**) &ds))) {
AddDataSource(ds);
NS_RELEASE(ds);
}
}
nsSimpleDataBase::~nsSimpleDataBase(void)
{
for (PRInt32 i = mDataSources.Count() - 1; i >= 0; --i) {
nsIRDFDataSource* ds = static_cast<nsIRDFDataSource*>(mDataSources[i]);
NS_IF_RELEASE(ds);
}
}
////////////////////////////////////////////////////////////////////////
// nsISupports interface
NS_IMPL_ADDREF(nsSimpleDataBase);
NS_IMPL_RELEASE(nsSimpleDataBase);
NS_IMETHODIMP
nsSimpleDataBase::QueryInterface(REFNSIID iid, void** result)
{
if (! result)
return NS_ERROR_NULL_POINTER;
*result = NULL;
if (iid.Equals(kIRDFDataBaseIID) ||
iid.Equals(kIRDFDataSourceIID) ||
iid.Equals(kISupportsIID)) {
*result = static_cast<nsIRDFDataBase*>(this);
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
////////////////////////////////////////////////////////////////////////
// nsIRDFDataSource interface
NS_IMETHODIMP
nsSimpleDataBase::Initialize(const nsString& uri)
{
PR_ASSERT(0);
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
nsSimpleDataBase::GetSource(nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFNode*& source)
{
PRInt32 count = mDataSources.Count();
for (PRInt32 i = 0; i < count; ++i) {
nsIRDFDataSource* ds = 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 the "main" data source
nsIRDFDataSource* ds0 = static_cast<nsIRDFDataSource*>(mDataSources[0]);
nsIRDFNode* tmp;
if (NS_FAILED(ds->GetSource(property, target, !tv, tmp)))
return NS_OK;
NS_RELEASE(tmp);
NS_RELEASE(source);
return NS_ERROR_FAILURE;
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsSimpleDataBase::GetSources(nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFCursor*& sources)
{
PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsSimpleDataBase::GetTarget(nsIRDFNode* source,
nsIRDFNode* property,
PRBool tv,
nsIRDFNode*& target)
{
PRInt32 count = mDataSources.Count();
for (PRInt32 i = 0; i < count; ++i) {
nsIRDFDataSource* ds = 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 "main" data source
nsIRDFDataSource* ds0 = static_cast<nsIRDFDataSource*>(mDataSources[0]);
nsIRDFNode* tmp;
if (NS_FAILED(ds0->GetTarget(source, property, !tv, tmp)))
return NS_OK;
NS_RELEASE(tmp);
NS_RELEASE(target);
return NS_ERROR_FAILURE;
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsSimpleDataBase::GetTargets(nsIRDFNode* source,
nsIRDFNode* property,
PRBool tv,
nsIRDFCursor*& targets)
{
targets = new dbNodeCursorImpl(mDataSources, source, property, tv);
if (! targets)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(targets);
return NS_OK;
}
NS_IMETHODIMP
nsSimpleDataBase::Assert(nsIRDFNode* source,
nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv)
{
nsresult rv;
// First see if we just need to remove a negative assertion from ds0. (Sigh)
nsIRDFDataSource* ds0 = static_cast<nsIRDFDataSource*>(mDataSources[0]);
PRBool ds0HasNegation;
if (NS_FAILED(rv = ds0->HasAssertion(source, property, target, !tv, ds0HasNegation)))
return rv;
if (ds0HasNegation) {
if (NS_FAILED(rv = ds0->Unassert(source, property, target)))
return rv;
}
// Now, see if the assertion has been "unmasked"
PRBool isAlreadyAsserted;
if (NS_FAILED(rv = HasAssertion(source, property, target, tv, isAlreadyAsserted)))
return rv;
if (isAlreadyAsserted)
return NS_OK;
// If not, iterate from the "remote-est" data source to the
// "local-est", trying to make the assertion.
for (PRInt32 i = mDataSources.Count() - 1; i >= 0; --i) {
nsIRDFDataSource* ds = static_cast<nsIRDFDataSource*>(mDataSources[i]);
if (NS_SUCCEEDED(ds->Assert(source, property, target, tv)))
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
nsSimpleDataBase::Unassert(nsIRDFNode* source,
nsIRDFNode* property,
nsIRDFNode* target)
{
// XXX I have no idea what this is trying to do. I'm just going to
// copy Guha's logic and punt.
nsresult rv;
PRInt32 count = mDataSources.Count();
for (PRInt32 i = 0; i < count; ++i) {
nsIRDFDataSource* ds = static_cast<nsIRDFDataSource*>(mDataSources[i]);
if (NS_FAILED(rv = ds->Unassert(source, property, target)))
break;
}
if (NS_FAILED(rv)) {
nsIRDFDataSource* ds0 = static_cast<nsIRDFDataSource*>(mDataSources[0]);
rv = ds0->Assert(source, property, target);
}
return rv;
}
NS_IMETHODIMP
nsSimpleDataBase::HasAssertion(nsIRDFNode* source,
nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv,
PRBool& hasAssertion)
{
nsresult rv;
// First check to see if ds0 has the negation...
nsIRDFDataSource* ds0 = static_cast<nsIRDFDataSource*>(mDataSources[0]);
PRBool ds0HasNegation;
if (NS_FAILED(rv = ds0->HasAssertion(source, property, target, !tv, ds0HasNegation)))
return rv;
if (ds0HasNegation) {
hasAssertion = PR_FALSE;
return NS_OK;
}
// Otherwise, look through all the data sources to see if anyone
// has the positive...
PRInt32 count = mDataSources.Count();
for (PRInt32 i = 0; i < count; ++i) {
nsIRDFDataSource* ds = static_cast<nsIRDFDataSource*>(mDataSources[i]);
if (NS_FAILED(rv = ds->HasAssertion(source, property, target, tv, hasAssertion)))
return rv;
if (hasAssertion)
return NS_OK;
}
// If we get here, nobody had the assertion at all
return NS_OK;
}
NS_IMETHODIMP
nsSimpleDataBase::AddObserver(nsIRDFObserver* n)
{
PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsSimpleDataBase::RemoveObserver(nsIRDFObserver* n)
{
PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsSimpleDataBase::ArcLabelsIn(nsIRDFNode* node,
nsIRDFCursor*& labels)
{
PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsSimpleDataBase::ArcLabelsOut(nsIRDFNode* source,
nsIRDFCursor*& labels)
{
labels = new dbArcCursorImpl(mDataSources, source);
if (! labels)
return NS_ERROR_NULL_POINTER;
NS_ADDREF(labels);
return NS_OK;
}
NS_IMETHODIMP
nsSimpleDataBase::Flush()
{
for (PRInt32 i = mDataSources.Count() - 1; i >= 0; --i) {
nsIRDFDataSource* ds = static_cast<nsIRDFDataSource*>(mDataSources[i]);
ds->Flush();
}
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// nsIRDFDataBase methods
NS_IMETHODIMP
nsSimpleDataBase::AddDataSource(nsIRDFDataSource* source)
{
if (! source)
return NS_ERROR_NULL_POINTER;
mDataSources.InsertElementAt(source, 0);
NS_ADDREF(source);
return NS_OK;
}

View File

@ -0,0 +1,92 @@
/* -*- 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 nsSimpleDataBase_h__
#define nsSimpleDataBase_h__
#include "nsIRDFDataBase.h"
#include "nsVoidArray.h"
class nsSimpleDataBase : public nsIRDFDataBase {
protected:
nsVoidArray mDataSources;
virtual ~nsSimpleDataBase(void);
public:
nsSimpleDataBase(void);
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIRDFDataSource interface
NS_IMETHOD Initialize(const nsString& uri);
NS_IMETHOD GetSource(nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFNode*& source);
NS_IMETHOD GetSources(nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFCursor*& sources);
NS_IMETHOD GetTarget(nsIRDFNode* source,
nsIRDFNode* property,
PRBool tv,
nsIRDFNode*& target);
NS_IMETHOD GetTargets(nsIRDFNode* source,
nsIRDFNode* property,
PRBool tv,
nsIRDFCursor*& targets);
NS_IMETHOD Assert(nsIRDFNode* source,
nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv = PR_TRUE);
NS_IMETHOD Unassert(nsIRDFNode* source,
nsIRDFNode* property,
nsIRDFNode* target);
NS_IMETHOD HasAssertion(nsIRDFNode* source,
nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv,
PRBool& hasAssertion);
NS_IMETHOD AddObserver(nsIRDFObserver* n);
NS_IMETHOD RemoveObserver(nsIRDFObserver* n);
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
nsIRDFCursor*& labels);
NS_IMETHOD ArcLabelsOut(nsIRDFNode* source,
nsIRDFCursor*& labels);
NS_IMETHOD Flush();
// nsIRDFDataBase interface
NS_IMETHOD AddDataSource(nsIRDFDataSource* source);
};
#endif // nsSimpleDataBase_h__