Incorporate comments from guha, jband, etc. Differentiate between resources and literals, make core interfaces comply with XPCOM stuff.

git-svn-id: svn://10.0.0.236/trunk@16648 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
waterson%netscape.com
1998-12-18 05:38:24 +00:00
parent abce0b152c
commit f51e5e8b7e
27 changed files with 1910 additions and 1307 deletions

View File

@@ -25,7 +25,7 @@
class nsIRDFContent;
class nsIRDFDocument;
class nsIRDFNode;
class nsIRDFResource;
// {954F0810-81DC-11d2-B52A-000000000000}
#define NS_IRDFCONTENT_IID \
@@ -38,14 +38,14 @@ class nsIRDFContent : public nsIXMLContent {
public:
NS_IMETHOD Init(nsIRDFDocument* doc,
const nsString& tag,
nsIRDFNode* resource,
nsIRDFResource* resource,
PRBool childrenMustBeGenerated) = 0;
NS_IMETHOD SetResource(const nsString& aURI) = 0;
NS_IMETHOD GetResource(nsString& rURI) const = 0;
NS_IMETHOD SetResource(nsIRDFNode* aResource) = 0;
NS_IMETHOD GetResource(nsIRDFNode*& aResource) = 0;
NS_IMETHOD SetResource(nsIRDFResource* aResource) = 0;
NS_IMETHOD GetResource(nsIRDFResource*& aResource) = 0;
NS_IMETHOD SetProperty(const nsString& aPropertyURI, const nsString& aValue) = 0;
NS_IMETHOD GetProperty(const nsString& aPropertyURI, nsString& rValue) const = 0;

View File

@@ -19,37 +19,37 @@
#ifndef nsIRDFCursor_h__
#define nsIRDFCursor_h__
/*
nsIRDFCursor:
An iterator for RDF data sources.
*/
#include "nsISupports.h"
class nsIRDFNode;
// 1c2abdb0-4cef-11d2-bc16-00805f912fe7
#define NS_IRDFCURSOR_IID \
{ \
0x1c2abdb0, \
0x4cef, \
0x11d2, \
{ 0xbc, 0x16, 0x00, 0x80, 0x5f, 0x91, 0x2f, 0xe7 } \
}
/**
* A simple cursor that enumerates nodes
*/
class nsIRDFCursor : public nsISupports {
public:
/**
* Determine whether the cursor has more elements.
* @return NS_OK unless a catastrophic error occurs.
*/
NS_IMETHOD HasMoreElements(PRBool* result /* out */) = 0;
NS_IMETHOD HasMoreElements(PRBool& result /* 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;
/**
* Fetch then next element, and possibly the truth value of the arc
* that leads to the element.
*
* @param next A pointer to receive the next <tt>nsIRDFNode</tt> object.
* @param tv A pointer to a boolean variable to receive the truth value
* of the arc that leads to the element. You pass <tt>nsnull</tt> if
* you don't care to know.
* @return NS_ERROR_UNEXPECTED if the cursor is empty; otherwise, NS_OK
* unless a catastrophic error occurs.
*/
NS_IMETHOD GetNext(nsIRDFNode** next /* out */,
PRBool* tv /* out */) = 0;
};
// 1c2abdb0-4cef-11d2-bc16-00805f912fe7
#define NS_IRDFCURSOR_IID \
{ 0x1c2abdb0, 0x4cef, 0x11d2, { 0xbc, 0x16, 0x00, 0x80, 0x5f, 0x91, 0x2f, 0xe7 } }
#endif /* nsIRDFCursor_h__ */

View File

@@ -19,34 +19,34 @@
#ifndef nsIRDFDataSource_h__
#define nsIRDFDataSource_h__
/*
This file contains the interface definition for an RDF data source.
*/
#include "nsISupports.h"
// {0F78DA58-8321-11d2-8EAC-00805F29F370}
#define NS_IRDFDATASOURCE_IID \
{ 0xf78da58, 0x8321, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
class nsIRDFNode;
class nsIRDFCursor;
class nsIRDFObserver;
class nsIRDFDataBase;
class nsString;
class nsIRDFNode;
class nsIRDFObserver;
class nsIRDFResource;
// 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.
/**
* An RDF data source.
*/
class nsIRDFDataSource : public nsISupports {
public:
// 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.
/**
* Specify the URI for the data source: this is the prefix
* that will be used to register the data source in the
* data source registry.
*/
NS_IMETHOD Init(const nsString& uri) = 0;
NS_IMETHOD Init(const char* uri) = 0;
/**
* Find an RDF resource that points to a given node over the
@@ -55,10 +55,10 @@ public:
* @return NS_ERROR_FAILURE if there is no source that leads
* to the target with the specified property.
*/
NS_IMETHOD GetSource(nsIRDFNode* property,
NS_IMETHOD GetSource(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFNode*& source /* out */) = 0;
nsIRDFResource** source /* out */) = 0;
/**
* Find all RDF resources that point to a given node over the
@@ -68,10 +68,10 @@ public:
* method returns NS_OK, you may assume that nsIRDFCursor points
* to a valid (but possibly empty) cursor.
*/
NS_IMETHOD GetSources(nsIRDFNode* property,
NS_IMETHOD GetSources(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFCursor*& sources /* out */) = 0;
nsIRDFCursor** sources /* out */) = 0;
/**
* Find a child of that is related to the source by the given arc
@@ -80,10 +80,10 @@ public:
* @return NS_ERROR_FAILURE if there is no target accessable from the
* source via the specified property.
*/
NS_IMETHOD GetTarget(nsIRDFNode* source,
nsIRDFNode* property,
NS_IMETHOD GetTarget(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFNode*& target /* out */) = 0;
nsIRDFNode** target /* out */) = 0;
/**
* Find all children of that are related to the source by the given arc
@@ -93,24 +93,24 @@ public:
* method returns NS_OK, you may assume that nsIRDFCursor points
* to a valid (but possibly empty) cursor.
*/
NS_IMETHOD GetTargets(nsIRDFNode* source,
nsIRDFNode* property,
NS_IMETHOD GetTargets(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFCursor*& targets /* out */) = 0;
nsIRDFCursor** targets /* out */) = 0;
/**
* Add an assertion to the graph.
*/
NS_IMETHOD Assert(nsIRDFNode* source,
nsIRDFNode* property,
NS_IMETHOD Assert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv = PR_TRUE) = 0;
PRBool tv) = 0;
/**
* Remove an assertion from the graph.
*/
NS_IMETHOD Unassert(nsIRDFNode* source,
nsIRDFNode* property,
NS_IMETHOD Unassert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target) = 0;
/**
@@ -118,11 +118,11 @@ public:
*
* @return NS_OK unless a catastrophic error occurs.
*/
NS_IMETHOD HasAssertion(nsIRDFNode* source,
nsIRDFNode* property,
NS_IMETHOD HasAssertion(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
PRBool& hasAssertion /* out */) = 0;
PRBool* hasAssertion /* out */) = 0;
/**
* Add an observer to this data source.
@@ -144,7 +144,7 @@ public:
* possible empty) nsIRDFCursor object.
*/
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
nsIRDFCursor*& labels /* out */) = 0;
nsIRDFCursor** labels /* out */) = 0;
/**
* Get a cursor to iterate over all the arcs that originate in
@@ -154,8 +154,8 @@ public:
* returns NS_OK, you may assume that labels points to a valid (but
* possible empty) nsIRDFCursor object.
*/
NS_IMETHOD ArcLabelsOut(nsIRDFNode* source,
nsIRDFCursor*& labels /* out */) = 0;
NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
nsIRDFCursor** labels /* out */) = 0;
/**
* Request that a data source write it's contents out to
@@ -165,5 +165,4 @@ public:
};
#endif /* nsIRDFDataSource_h__ */

View File

@@ -25,7 +25,7 @@
class nsIRDFContent;
class nsIRDFDataBase;
class nsISupportsArray;
class nsIRDFNode;
class nsIRDFResource;
// {954F0811-81DC-11d2-B52A-000000000000}
#define NS_IRDFDOCUMENT_IID \
@@ -45,7 +45,7 @@ public:
/**
* Set the document's "root" resource.
*/
NS_IMETHOD SetRootResource(nsIRDFNode* aResource) = 0;
NS_IMETHOD SetRootResource(nsIRDFResource* aResource) = 0;
/**
* Retrieve the document's RDF data base.
@@ -70,14 +70,14 @@ public:
* should use when constructing the content model from the RDF
* graph.
*/
NS_IMETHOD AddTreeProperty(nsIRDFNode* resource) = 0;
NS_IMETHOD AddTreeProperty(nsIRDFResource* resource) = 0;
/**
* Remove a property from the set of "tree properties" that the
* document should use when constructing the content model from the
* RDF graph.
*/
NS_IMETHOD RemoveTreeProperty(nsIRDFNode* resource) = 0;
NS_IMETHOD RemoveTreeProperty(nsIRDFResource* resource) = 0;
};
// factory functions

View File

@@ -19,48 +19,74 @@
#ifndef nsIRDFNode_h__
#define nsIRDFNode_h__
#include "nscore.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);
}
*
* 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->GetResource("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;
};
/**
* A resource node, which has unique object identity.
*/
class nsIRDFResource : public nsIRDFNode {
public:
/**
* Get the 8-bit string value of the node.
*/
NS_IMETHOD GetValue(const char* *uri) const = 0;
/**
* Determine if two resources are identical.
*/
NS_IMETHOD EqualsResource(const nsIRDFResource* resource, PRBool* result) const = 0;
NS_IMETHOD EqualsString(const char* uri, PRBool* result) const = 0;
};
// {E0C493D1-9542-11d2-8EB8-00805F29F370}
#define NS_IRDFRESOURCE_IID \
{ 0xe0c493d1, 0x9542, 0x11d2, { 0x8e, 0xb8, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
class nsIRDFLiteral : public nsIRDFNode {
public:
/**
* Get the Unicode string value of the node.
*/
NS_IMETHOD GetValue(const PRUnichar* *value) const = 0;
/**
* Determine if two resources are identical.
*/
NS_IMETHOD Equals(const nsIRDFLiteral* literal, PRBool* result) const = 0;
};
// {E0C493D2-9542-11d2-8EB8-00805F29F370}
#define NS_IRDFLITERAL_IID \
{ 0xe0c493d2, 0x9542, 0x11d2, { 0x8e, 0xb8, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
#endif // nsIRDFNode_h__

View File

@@ -19,29 +19,36 @@
#ifndef nsIRDFObserver_h__
#define nsIRDFObserver_h__
/*
This file defines the interface for RDF observers.
*/
#include "nsISupports.h"
class nsIRDFDataSource;
class nsIRDFResource;
class nsIRDFNode;
/**
* An observer on an nsIRDFDataSource.
*/
class nsIRDFObserver : public nsISupports
{
public:
/**
* Called whenever a new assertion is made in the data source.
*/
NS_IMETHOD OnAssert(nsIRDFResource* subject,
nsIRDFResource* predicate,
nsIRDFNode* object) = 0;
/**
* Called whenever an assertion is removed from the data source.
*/
NS_IMETHOD OnUnassert(nsIRDFResource* subject,
nsIRDFResource* predicate,
nsIRDFNode* object) = 0;
};
// 3cc75360-484a-11d2-bc16-00805f912fe7
#define NS_IRDFOBSERVER_IID \
{ \
0x3cc75360, \
0x484a, \
0x11d2, \
{ 0xbc, 0x16, 0x00, 0x80, 0x5f, 0x91, 0x2f, 0xe7 } \
}
class nsIRDFDataSource;
class nsIRDFObserver : public nsISupports
{
public:
};
{ 0x3cc75360, 0x484a, 0x11d2, { 0xbc, 0x16, 0x00, 0x80, 0x5f, 0x91, 0x2f, 0xe7 } }
#endif /* nsIRDFObserver_h__ */

View File

@@ -19,19 +19,42 @@
#ifndef nsIRDFResourceManager_h__
#define nsIRDFResourceManager_h__
#include "nscore.h"
#include "nsISupports.h"
class nsString;
class nsIRDFNode;
class nsIRDFResource;
class nsIRDFLiteral;
/**
* An RDF resource manager. This should be a singleton object, obtained
* from the <tt>nsServiceManager</tt>.
*/
class nsIRDFResourceManager : public nsISupports {
public:
/**
* Construct an RDF resource from a single-byte URI.
*/
NS_IMETHOD GetResource(const char* uri, nsIRDFResource** resource) = 0;
/**
* Construct an RDF resource from a Unicode URI. This is provided
* as a convenience method, allowing automatic, in-line C++
* conversion from <tt>nsString</tt> objects. The <tt>uri</tt> will
* be converted to a single-byte representation internally.
*/
NS_IMETHOD GetUnicodeResource(const PRUnichar* uri, nsIRDFResource** resource) = 0;
/**
* Construct an RDF literal from a Unicode string.
*/
NS_IMETHOD GetLiteral(const PRUnichar* value, nsIRDFLiteral** literal) = 0;
};
// {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;
};
extern nsresult
NS_NewRDFResourceManager(nsIRDFResourceManager** result);
#endif // nsIRDFResourceManager_h__

View File

@@ -20,7 +20,6 @@
#include "nsIRDFNode.h"
#include "nsIRDFResourceManager.h"
#include "nsIServiceManager.h"
#include "nsMemoryDataSource.h"
#include "nsRDFCID.h"
#include "nsString.h"
#include "nsVoidArray.h"
@@ -30,7 +29,9 @@
////////////////////////////////////////////////////////////////////////
static NS_DEFINE_IID(kIRDFDataSourceIID, NS_IRDFDATASOURCE_IID);
static NS_DEFINE_IID(kIRDFResourceManagerIID, NS_IRDFRESOURCEMANAGER_IID);
static NS_DEFINE_CID(kRDFMemoryDataSourceCID, NS_RDFMEMORYDATASOURCE_CID);
static NS_DEFINE_CID(kRDFResourceManagerCID, NS_RDFRESOURCEMANAGER_CID);
static const char kURI_bookmarks[] = "rdf:bookmarks"; // XXX?
@@ -64,7 +65,10 @@ static const char kPersonalToolbar[] = "Personal Toolbar";
////////////////////////////////////////////////////////////////////////
/**
* The bookmark parser knows how to read <tt>bookmarks.html</tt> and convert it
* into an RDF graph.
*/
class BookmarkParser {
protected:
static const char* kBRString;
@@ -87,7 +91,7 @@ protected:
nsIRDFResourceManager* mResourceMgr;
nsIRDFDataSource* mDataSource;
nsVoidArray mStack;
nsIRDFNode* mLastItem;
nsIRDFResource* mLastItem;
nsAutoString mLine;
PRInt32 mCounter;
nsAutoString mFolderDate;
@@ -98,7 +102,7 @@ protected:
void DoStateTransition(void);
void CreateBookmark(void);
nsresult AssertTime(nsIRDFNode* subject,
nsresult AssertTime(nsIRDFResource* subject,
const nsString& predicateURI,
const nsString& time);
@@ -183,7 +187,7 @@ BookmarkParser::AddColumns(void)
// information about columns, etc.
nsresult rv;
nsIRDFNode* columns = nsnull;
nsIRDFResource* columns = nsnull;
static const char* gColumnTitles[] = {
"Name",
@@ -204,15 +208,16 @@ BookmarkParser::AddColumns(void)
const char* const* columnTitle = gColumnTitles;
const char* const* columnURI = gColumnURIs;
if (NS_FAILED(rv = rdf_CreateSequence(mResourceMgr, mDataSource, columns)))
if (NS_FAILED(rv = rdf_CreateAnonymousResource(mResourceMgr, &columns)))
goto done;
if (NS_FAILED(rv = rdf_MakeSeq(mResourceMgr, mDataSource, columns)))
goto done;
while (*columnTitle && *columnURI) {
nsIRDFNode* column = nsnull;
nsIRDFNode* columnURIResource = nsnull;
nsIRDFNode* columnTitleResource = nsnull;
nsIRDFResource* column = nsnull;
if (NS_SUCCEEDED(rv = rdf_CreateAnonymousNode(mResourceMgr, column))) {
if (NS_SUCCEEDED(rv = rdf_CreateAnonymousResource(mResourceMgr, &column))) {
rdf_Assert(mResourceMgr, mDataSource, column, kURINC_Title, *columnTitle);
rdf_Assert(mResourceMgr, mDataSource, column, kURINC_Column, *columnURI);
@@ -270,23 +275,24 @@ BookmarkParser::NextToken(void)
// description
if ((mState == eBookmarkParserState_InTitle) ||
(mState == eBookmarkParserState_InH3)) {
nsIRDFNode* folder;
nsIRDFResource* folder;
if (mStack.Count() > 0) {
// a regular old folder
nsAutoString folderURI(kURI_bookmarks);
folderURI.Append('#');
folderURI.Append(++mCounter, 10);
if (NS_FAILED(mResourceMgr->GetNode(folderURI, folder)))
if (NS_FAILED(mResourceMgr->GetUnicodeResource(folderURI, &folder)))
return;
nsIRDFNode* parent = (nsIRDFNode*) mStack[mStack.Count() - 1];
nsIRDFResource* parent = (nsIRDFResource*) mStack[mStack.Count() - 1];
rdf_Assert(mResourceMgr, mDataSource, parent, kURINC_Folder, folder);
}
else {
// it's the root
if (NS_FAILED(mResourceMgr->GetNode(kURI_bookmarks, folder)))
if (NS_FAILED(mResourceMgr->GetResource(kURI_bookmarks, &folder)))
return;
}
@@ -297,6 +303,9 @@ BookmarkParser::NextToken(void)
NS_IF_RELEASE(mLastItem);
mLastItem = folder;
// XXX Implied
//NS_ADDREF(mLastItem);
//NS_RELEASE(folder);
if (mState != eBookmarkParserState_InTitle)
rdf_Assert(mResourceMgr, mDataSource, mLastItem, kURINC_Name, mLine);
@@ -346,6 +355,7 @@ BookmarkParser::DoStateTransition(void)
}
else if (mLine.Find(kOpenDLString) == 0) {
mStack.AppendElement(mLastItem);
NS_ADDREF(mLastItem);
}
else if (mLine.Find(kCloseDLString) == 0) {
PRInt32 count = mStack.Count();
@@ -407,14 +417,14 @@ BookmarkParser::CreateBookmark(void)
if (values[eBmkAttribute_URL].Length() == 0)
return;
nsIRDFNode* bookmark;
if (NS_FAILED(mResourceMgr->GetNode(values[eBmkAttribute_URL], bookmark)))
nsIRDFResource* bookmark;
if (NS_FAILED(mResourceMgr->GetUnicodeResource(values[eBmkAttribute_URL], &bookmark)))
return;
if (! mStack.Count())
return;
nsIRDFNode* parent = (nsIRDFNode*) mStack[mStack.Count() - 1];
nsIRDFResource* parent = (nsIRDFResource*) mStack[mStack.Count() - 1];
if (! parent)
return;
@@ -431,11 +441,14 @@ BookmarkParser::CreateBookmark(void)
NS_IF_RELEASE(mLastItem);
mLastItem = bookmark;
// XXX Implied
//NS_ADDREF(mLastItem);
//NS_RELEASE(bookmark);
}
nsresult
BookmarkParser::AssertTime(nsIRDFNode* object,
BookmarkParser::AssertTime(nsIRDFResource* object,
const nsString& predicateURI,
const nsString& time)
{
@@ -446,10 +459,17 @@ BookmarkParser::AssertTime(nsIRDFNode* object,
////////////////////////////////////////////////////////////////////////
// BookmarkDataSourceImpl
class BookmarkDataSourceImpl : public nsMemoryDataSource {
/**
* The bookmark data source uses a <tt>BookmarkParser</tt> to read the
* <tt>bookmarks.html</tt> file from the local disk and present an
* in-memory RDF graph based on it.
*/
class BookmarkDataSourceImpl : public nsIRDFDataSource {
protected:
static const char* kBookmarksFilename;
nsIRDFDataSource* mInner;
nsresult ReadBookmarks(void);
nsresult WriteBookmarks(void);
nsresult AddColumns(void);
@@ -458,6 +478,81 @@ public:
BookmarkDataSourceImpl(void);
virtual ~BookmarkDataSourceImpl(void);
// nsISupports
NS_DECL_ISUPPORTS
// nsIRDFDataSource
NS_IMETHOD Init(const char* uri) {
return mInner->Init(uri);
}
NS_IMETHOD GetSource(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFResource** source) {
return mInner->GetSource(property, target, tv, source);
}
NS_IMETHOD GetSources(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFCursor** sources) {
return mInner->GetSources(property, target, tv, sources);
}
NS_IMETHOD GetTarget(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFNode** target) {
return mInner->GetTarget(source, property, tv, target);
}
NS_IMETHOD GetTargets(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFCursor** targets) {
return mInner->GetTargets(source, property, tv, targets);
}
NS_IMETHOD Assert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv) {
return mInner->Assert(source, property, target, tv);
}
NS_IMETHOD Unassert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target) {
return mInner->Unassert(source, property, target);
}
NS_IMETHOD HasAssertion(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
PRBool* hasAssertion) {
return mInner->HasAssertion(source, property, target, tv, hasAssertion);
}
NS_IMETHOD AddObserver(nsIRDFObserver* n) {
return mInner->AddObserver(n);
}
NS_IMETHOD RemoveObserver(nsIRDFObserver* n) {
return mInner->RemoveObserver(n);
}
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
nsIRDFCursor** labels) {
return mInner->ArcLabelsIn(node, labels);
}
NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
nsIRDFCursor** labels) {
return mInner->ArcLabelsOut(source, labels);
}
NS_IMETHOD Flush(void);
};
@@ -471,15 +566,26 @@ BookmarkDataSourceImpl::BookmarkDataSourceImpl(void)
// XXX rvg there should be only one instance of this class.
// this is actually true of all datasources.
NS_INIT_REFCNT();
ReadBookmarks(); // XXX do or die, eh?
nsresult rv;
// XXX do or die, my friend...
rv = nsRepository::CreateInstance(kRDFMemoryDataSourceCID,
nsnull,
kIRDFDataSourceIID,
(void**) &mInner);
PR_ASSERT(NS_SUCCEEDED(rv));
ReadBookmarks();
Init(kURI_bookmarks);
}
BookmarkDataSourceImpl::~BookmarkDataSourceImpl(void)
{
Flush();
NS_RELEASE(mInner);
}
NS_IMPL_ISUPPORTS(BookmarkDataSourceImpl, kIRDFDataSourceIID);
NS_IMETHODIMP

View File

@@ -53,6 +53,8 @@
////////////////////////////////////////////////////////////////////////
static NS_DEFINE_IID(kIRDFResourceManagerIID, NS_IRDFRESOURCEMANAGER_IID);
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
static NS_DEFINE_CID(kRDFResourceManagerCID, NS_RDFRESOURCEMANAGER_CID);
////////////////////////////////////////////////////////////////////////
@@ -68,24 +70,24 @@ class ContainerCursorImpl : public nsIRDFCursor {
private:
nsIRDFResourceManager* mResourceMgr;
nsIRDFDataSource* mDataSource;
nsIRDFNode* mContainer;
nsIRDFResource* mContainer;
nsIRDFNode* mNext;
PRInt32 mCounter;
void SkipToNext(void);
public:
ContainerCursorImpl(nsIRDFDataSource* ds, nsIRDFNode* container);
ContainerCursorImpl(nsIRDFDataSource* ds, nsIRDFResource* container);
virtual ~ContainerCursorImpl(void);
NS_DECL_ISUPPORTS
NS_IMETHOD HasMoreElements(PRBool& result);
NS_IMETHOD GetNext(nsIRDFNode*& next, PRBool& tv);
NS_IMETHOD HasMoreElements(PRBool* result);
NS_IMETHOD GetNext(nsIRDFNode** next, PRBool* tv);
};
ContainerCursorImpl::ContainerCursorImpl(nsIRDFDataSource* ds,
nsIRDFNode* container)
nsIRDFResource* container)
: mDataSource(ds), mContainer(container), mNext(nsnull), mCounter(1)
{
NS_ASSERTION(ds != nsnull, "null ptr");
@@ -123,21 +125,27 @@ NS_IMPL_ISUPPORTS(ContainerCursorImpl, kIRDFCursorIID);
NS_IMETHODIMP
ContainerCursorImpl::HasMoreElements(PRBool& result)
ContainerCursorImpl::HasMoreElements(PRBool* result)
{
result = (mNext != nsnull);
if (! result)
return NS_ERROR_NULL_POINTER;
*result = (mNext != nsnull);
return NS_OK;
}
NS_IMETHODIMP
ContainerCursorImpl::GetNext(nsIRDFNode*& next, PRBool& tv)
ContainerCursorImpl::GetNext(nsIRDFNode** next, PRBool* tv)
{
if (!next)
return NS_ERROR_NULL_POINTER;
if (! mNext)
return NS_ERROR_UNEXPECTED;
next = mNext; // no need to addref, SkipToNext() did it
tv = PR_TRUE;
*next = mNext; // no need to addref, SkipToNext() did it
if (tv) *tv = PR_TRUE;
SkipToNext();
return NS_OK;
@@ -153,22 +161,28 @@ ContainerCursorImpl::SkipToNext(void)
nsresult rv;
mNext = nsnull;
nsIRDFNode* RDF_nextVal = nsnull;
nsIRDFNode* nextVal = nsnull;
nsIRDFResource* RDF_nextVal = nsnull;
nsIRDFNode* nextNode = nsnull;
nsIRDFLiteral* nextVal = nsnull;
const PRUnichar* s;
nsAutoString next;
PRInt32 last;
PRInt32 err;
// XXX we could cache all this crap when the cursor gets created.
if (NS_FAILED(rv = mResourceMgr->GetNode(kURIRDF_nextVal, RDF_nextVal)))
if (NS_FAILED(rv = mResourceMgr->GetResource(kURIRDF_nextVal, &RDF_nextVal)))
goto done;
if (NS_FAILED(rv = mDataSource->GetTarget(mContainer, RDF_nextVal, PR_TRUE, nextVal)))
if (NS_FAILED(rv = mDataSource->GetTarget(mContainer, RDF_nextVal, PR_TRUE, &nextNode)))
goto done;
if (NS_FAILED(rv = nextVal->GetStringValue(next)))
if (NS_FAILED(rv = nextNode->QueryInterface(kIRDFLiteralIID, (void**) &nextVal)))
goto done;
if (NS_FAILED(rv = nextVal->GetValue(&s)))
goto done;
next = s;
last = next.ToInteger(&err);
if (NS_FAILED(err))
goto done;
@@ -178,11 +192,11 @@ ContainerCursorImpl::SkipToNext(void)
next.Append("_");
next.Append(mCounter, 10);
nsIRDFNode* ordinalProperty = nsnull;
if (NS_FAILED(rv = mResourceMgr->GetNode(next, ordinalProperty)))
nsIRDFResource* ordinalProperty = nsnull;
if (NS_FAILED(rv = mResourceMgr->GetUnicodeResource(next, &ordinalProperty)))
break;
rv = mDataSource->GetTarget(mContainer, ordinalProperty, PR_TRUE, mNext);
rv = mDataSource->GetTarget(mContainer, ordinalProperty, PR_TRUE, &mNext);
NS_IF_RELEASE(ordinalProperty);
++mCounter;
@@ -196,6 +210,7 @@ ContainerCursorImpl::SkipToNext(void)
}
done:
NS_IF_RELEASE(nextNode);
NS_IF_RELEASE(nextVal);
NS_IF_RELEASE(RDF_nextVal);
}
@@ -205,14 +220,14 @@ done:
nsresult
NS_NewContainerCursor(nsIRDFDataSource* ds,
nsIRDFNode* container,
nsIRDFCursor*& cursor)
nsIRDFResource* container,
nsIRDFCursor** cursor)
{
nsIRDFCursor* result = new ContainerCursorImpl(ds, container);
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
cursor = result;
NS_ADDREF(cursor);
*cursor = result;
NS_ADDREF(result);
return NS_OK;
}

View File

@@ -33,16 +33,13 @@ public:
NS_IMETHOD QueryInterface(REFNSIID iid, void** result);
// nsIRDFCursor
NS_IMETHOD HasMoreElements(PRBool& result);
NS_IMETHOD GetNext(nsIRDFNode*& next, PRBool& tv);
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)
@@ -75,18 +72,31 @@ EmptyCursorImpl::QueryInterface(REFNSIID iid, void** result)
NS_IMETHODIMP
EmptyCursorImpl::HasMoreElements(PRBool& result)
EmptyCursorImpl::HasMoreElements(PRBool* result)
{
result = PR_FALSE;
if (! result)
return NS_ERROR_NULL_POINTER;
*result = PR_FALSE;
return NS_OK;
}
NS_IMETHODIMP
EmptyCursorImpl::GetNext(nsIRDFNode*& next, PRBool& tv)
EmptyCursorImpl::GetNext(nsIRDFNode** next, PRBool* tv)
{
next = nsnull;
if (! next)
return NS_ERROR_NULL_POINTER;
*next = nsnull;
return NS_ERROR_UNEXPECTED;
}
nsresult
NS_NewEmptyRDFCursor(nsIRDFCursor** result)
{
static EmptyCursorImpl gEmptyCursor;
*result = &gEmptyCursor;
return NS_OK;
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,97 +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 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 Init(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__

View File

@@ -59,6 +59,7 @@
#include "nsINameSpace.h"
#include "prlog.h"
#include "prmem.h"
#include "rdfutil.h"
static const char kNameSpaceSeparator[] = ":";
static const char kNameSpaceDef[] = "xmlns";
@@ -80,6 +81,7 @@ DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, bagID);
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, instanceOf);
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, li);
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, resource);
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, type);
static const char kRDFNameSpaceURI[] = RDF_NAMESPACE_URI;
@@ -241,7 +243,7 @@ rdf_FullyQualifyURI(const nsIURL* base, nsString& spec)
nsRDFContentSink::nsRDFContentSink()
: mDocumentURL(nsnull),
mRDFResourceManager(nsnull),
mResourceMgr(nsnull),
mDataSource(nsnull),
mGenSym(0),
mNameSpaceManager(nsnull),
@@ -261,8 +263,8 @@ nsRDFContentSink::~nsRDFContentSink()
{
NS_IF_RELEASE(mDocumentURL);
if (mRDFResourceManager)
nsServiceManager::ReleaseService(kRDFResourceManagerCID, mRDFResourceManager);
if (mResourceMgr)
nsServiceManager::ReleaseService(kRDFResourceManagerCID, mResourceMgr);
NS_IF_RELEASE(mDataSource);
@@ -286,7 +288,7 @@ nsRDFContentSink::~nsRDFContentSink()
// pop all the elements off the stack and release them.
PRInt32 index = mContextStack->Count();
while (0 < index--) {
nsIRDFNode* resource;
nsIRDFResource* resource;
RDFContentSinkState state;
PopContext(resource, state);
NS_IF_RELEASE(resource);
@@ -315,7 +317,7 @@ nsRDFContentSink::Init(nsIURL* aURL, nsINameSpaceManager* aNameSpaceManager)
nsresult rv;
if (NS_FAILED(rv = nsServiceManager::GetService(kRDFResourceManagerCID,
kIRDFResourceManagerIID,
(nsISupports**) &mRDFResourceManager)))
(nsISupports**) &mResourceMgr)))
return rv;
mState = eRDFContentSinkState_InProlog;
@@ -438,7 +440,7 @@ nsRDFContentSink::CloseContainer(const nsIParserNode& aNode)
{
FlushText();
nsIRDFNode* resource;
nsIRDFResource* resource;
if (NS_FAILED(PopContext(resource, mState))) {
// XXX parser didn't catch unmatched tags?
PR_ASSERT(0);
@@ -634,16 +636,31 @@ nsRDFContentSink::FlushText(PRBool aCreateTextNode, PRBool* aDidFlush)
// create a text node.
switch (mState) {
case eRDFContentSinkState_InMemberElement:
case eRDFContentSinkState_InMemberElement: {
nsAutoString value;
value.Append(mText, mTextLength);
nsIRDFLiteral* literal;
if (NS_SUCCEEDED(rv = mResourceMgr->GetLiteral(value, &literal))) {
rv = rdf_ContainerAddElement(mResourceMgr,
mDataSource,
GetContextElement(0),
literal);
NS_RELEASE(literal);
}
} break;
case eRDFContentSinkState_InPropertyElement: {
nsAutoString value;
value.Append(mText, mTextLength);
rv = Assert(GetContextElement(1),
GetContextElement(0),
value);
rv = rdf_Assert(mResourceMgr,
mDataSource,
GetContextElement(1),
GetContextElement(0),
value);
} break;
} break;
default:
// just ignore it
@@ -765,7 +782,7 @@ nsRDFContentSink::GetResourceAttribute(const nsIParserNode& aNode,
nsresult
nsRDFContentSink::AddProperties(const nsIParserNode& aNode,
nsIRDFNode* aSubject)
nsIRDFResource* aSubject)
{
// Add tag attributes to the content attributes
nsAutoString k, v;
@@ -794,7 +811,7 @@ nsRDFContentSink::AddProperties(const nsIParserNode& aNode,
k.Append(attr);
// Add the attribute to RDF
Assert(aSubject, k, v);
rdf_Assert(mResourceMgr, mDataSource, aSubject, k, v);
}
return NS_OK;
}
@@ -833,7 +850,7 @@ nsRDFContentSink::OpenObject(const nsIParserNode& aNode)
// node", or a "container", so this change the content sink's
// state appropriately.
if (! mRDFResourceManager)
if (! mResourceMgr)
return NS_ERROR_NOT_INITIALIZED;
nsAutoString tag;
@@ -847,19 +864,20 @@ nsRDFContentSink::OpenObject(const nsIParserNode& aNode)
if (NS_FAILED(rv = GetIdAboutAttribute(aNode, uri)))
return rv;
nsIRDFNode* rdfResource;
if (NS_FAILED(rv = mRDFResourceManager->GetNode(uri, rdfResource)))
nsIRDFResource* rdfResource;
if (NS_FAILED(rv = mResourceMgr->GetUnicodeResource(uri, &rdfResource)))
return rv;
// If we're in a member or property element, then this is the cue
// that we need to hook the object up into the graph via the
// member/property.
switch (mState) {
case eRDFContentSinkState_InMemberElement:
case eRDFContentSinkState_InMemberElement: {
rdf_ContainerAddElement(mResourceMgr, mDataSource, GetContextElement(0), rdfResource);
} break;
case eRDFContentSinkState_InPropertyElement: {
Assert(GetContextElement(1),
GetContextElement(0),
rdfResource);
mDataSource->Assert(GetContextElement(1), GetContextElement(0), rdfResource, PR_TRUE);
} break;
default:
@@ -883,17 +901,17 @@ nsRDFContentSink::OpenObject(const nsIParserNode& aNode)
}
else if (tag.Equals(kTagRDF_Bag)) {
// it's a bag container
Assert(rdfResource, kURIRDF_instanceOf, kURIRDF_Bag);
rdf_MakeBag(mResourceMgr, mDataSource, rdfResource);
mState = eRDFContentSinkState_InContainerElement;
}
else if (tag.Equals(kTagRDF_Seq)) {
// it's a seq container
Assert(rdfResource, kURIRDF_instanceOf, kURIRDF_Seq);
rdf_MakeSeq(mResourceMgr, mDataSource, rdfResource);
mState = eRDFContentSinkState_InContainerElement;
}
else if (tag.Equals(kTagRDF_Alt)) {
// it's an alt container
Assert(rdfResource, kURIRDF_instanceOf, kURIRDF_Alt);
rdf_MakeAlt(mResourceMgr, mDataSource, rdfResource);
mState = eRDFContentSinkState_InContainerElement;
}
else {
@@ -908,7 +926,7 @@ nsRDFContentSink::OpenObject(const nsIParserNode& aNode)
nsAutoString nameSpace;
GetNameSpaceURI(nameSpaceID, nameSpace); // XXX append ':' too?
nameSpace.Append(tag);
Assert(rdfResource, kURIRDF_instanceOf, nameSpace);
rdf_Assert(mResourceMgr, mDataSource, rdfResource, kURIRDF_type, nameSpace);
mState = eRDFContentSinkState_InDescriptionElement;
}
@@ -923,7 +941,7 @@ nsRDFContentSink::OpenObject(const nsIParserNode& aNode)
nsresult
nsRDFContentSink::OpenProperty(const nsIParserNode& aNode)
{
if (! mRDFResourceManager)
if (! mResourceMgr)
return NS_ERROR_NOT_INITIALIZED;
nsresult rv;
@@ -942,8 +960,8 @@ nsRDFContentSink::OpenProperty(const nsIParserNode& aNode)
// destructively alter "ns" to contain the fully qualified tag
// name. We can do this 'cause we don't need it anymore...
ns.Append(tag);
nsIRDFNode* rdfProperty;
if (NS_FAILED(rv = mRDFResourceManager->GetNode(ns, rdfProperty)))
nsIRDFResource* rdfProperty;
if (NS_FAILED(rv = mResourceMgr->GetUnicodeResource(ns, &rdfProperty)))
return rv;
nsAutoString resourceURI;
@@ -952,10 +970,14 @@ nsRDFContentSink::OpenProperty(const nsIParserNode& aNode)
// property. Create an RDF resource for the inline resource
// URI, add the properties to it, and attach the inline
// resource to its parent.
nsIRDFNode* rdfResource;
if (NS_SUCCEEDED(rv = mRDFResourceManager->GetNode(resourceURI, rdfResource))) {
nsIRDFResource* rdfResource;
if (NS_SUCCEEDED(rv = mResourceMgr->GetUnicodeResource(resourceURI, &rdfResource))) {
if (NS_SUCCEEDED(rv = AddProperties(aNode, rdfResource))) {
rv = Assert(GetContextElement(0), rdfProperty, rdfResource);
rv = rdf_Assert(mResourceMgr,
mDataSource,
GetContextElement(0),
rdfProperty,
rdfResource);
}
}
@@ -995,27 +1017,20 @@ nsRDFContentSink::OpenMember(const nsIParserNode& aNode)
return NS_ERROR_UNEXPECTED;
// The parent element is the container.
nsIRDFNode* contextResource = GetContextElement(0);
if (! contextResource)
nsIRDFResource* container = GetContextElement(0);
if (! container)
return NS_ERROR_NULL_POINTER;
// XXX err...figure out where we're at
PRUint32 count = 1;
nsAutoString ordinalURI(kRDFNameSpaceURI);
ordinalURI.Append('_');
ordinalURI.Append(count + 1, 10);
nsresult rv;
nsIRDFNode* ordinalResource;
if (NS_FAILED(rv = mRDFResourceManager->GetNode(ordinalURI, ordinalResource)))
return rv;
nsAutoString resourceURI;
if (NS_SUCCEEDED(GetResourceAttribute(aNode, resourceURI))) {
if (NS_SUCCEEDED(rv = GetResourceAttribute(aNode, resourceURI))) {
// Okay, this node has an RDF:resource="..." attribute. That
// means that it's a "referenced item," as covered in [6.29].
rv = Assert(contextResource, ordinalResource, resourceURI);
nsIRDFResource* resource;
if (NS_SUCCEEDED(rv = mResourceMgr->GetUnicodeResource(resourceURI, &resource))) {
rv = rdf_ContainerAddElement(mResourceMgr, mDataSource, container, resource);
}
// XXX Technically, we should _not_ fall through here and push
// the element onto the stack: this is supposed to be a closed
@@ -1023,11 +1038,8 @@ nsRDFContentSink::OpenMember(const nsIParserNode& aNode)
// Right Thing so long as the RDF is well-formed.
}
// Push it on to the content stack and change state.
PushContext(ordinalResource, mState);
// Change state.
mState = eRDFContentSinkState_InMemberElement;
ordinalResource->Release();
return rv;
}
@@ -1040,81 +1052,16 @@ nsRDFContentSink::OpenValue(const nsIParserNode& aNode)
return OpenObject(aNode);
}
////////////////////////////////////////////////////////////////////////
// RDF Helper Methods
nsresult
nsRDFContentSink::Assert(nsIRDFNode* subject, nsIRDFNode* predicate, nsIRDFNode* object)
{
if (!mDataSource)
return NS_ERROR_NOT_INITIALIZED;
#ifdef DEBUG_waterson
char buf[256];
nsAutoString s;
printf("assert [\n");
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)));
printf("]\n");
#endif
return mDataSource->Assert(subject, predicate, object);
}
nsresult
nsRDFContentSink::Assert(nsIRDFNode* subject, nsIRDFNode* predicate, const nsString& objectLiteral)
{
if (!mRDFResourceManager)
return NS_ERROR_NOT_INITIALIZED;
nsresult rv;
nsIRDFNode* object;
if (NS_FAILED(rv = mRDFResourceManager->GetNode(objectLiteral, object)))
return rv;
rv = Assert(subject, predicate, object);
NS_RELEASE(object);
return rv;
}
nsresult
nsRDFContentSink::Assert(nsIRDFNode* subject, const nsString& predicateURI, const nsString& objectLiteral)
{
if (!mRDFResourceManager)
return NS_ERROR_NOT_INITIALIZED;
nsresult rv;
nsIRDFNode* predicate;
if (NS_FAILED(rv = mRDFResourceManager->GetNode(predicateURI, predicate)))
return rv;
rv = Assert(subject, predicate, objectLiteral);
NS_RELEASE(predicate);
return rv;
}
////////////////////////////////////////////////////////////////////////
// Content stack management
struct RDFContextStackElement {
nsIRDFNode* mResource;
nsIRDFResource* mResource;
RDFContentSinkState mState;
};
nsIRDFNode*
nsIRDFResource*
nsRDFContentSink::GetContextElement(PRInt32 ancestor /* = 0 */)
{
if ((nsnull == mContextStack) ||
@@ -1129,7 +1076,7 @@ nsRDFContentSink::GetContextElement(PRInt32 ancestor /* = 0 */)
}
PRInt32
nsRDFContentSink::PushContext(nsIRDFNode *aResource, RDFContentSinkState aState)
nsRDFContentSink::PushContext(nsIRDFResource *aResource, RDFContentSinkState aState)
{
if (! mContextStack) {
mContextStack = new nsVoidArray();
@@ -1150,7 +1097,7 @@ nsRDFContentSink::PushContext(nsIRDFNode *aResource, RDFContentSinkState aState)
}
nsresult
nsRDFContentSink::PopContext(nsIRDFNode*& rResource, RDFContentSinkState& rState)
nsRDFContentSink::PopContext(nsIRDFResource*& rResource, RDFContentSinkState& rState)
{
RDFContextStackElement* e;
if ((nsnull == mContextStack) ||

View File

@@ -24,7 +24,7 @@
class nsIURL;
class nsVoidArray;
class nsIRDFNode;
class nsIRDFResource;
class nsIRDFDataSource;
class nsIRDFResourceManager;
class nsINameSpaceManager;
@@ -104,7 +104,7 @@ protected:
// 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 AddProperties(const nsIParserNode& aNode, nsIRDFResource* aSubject);
virtual nsresult OpenRDF(const nsIParserNode& aNode);
virtual nsresult OpenObject(const nsIParserNode& aNode);
@@ -112,18 +112,15 @@ protected:
virtual nsresult OpenMember(const nsIParserNode& aNode);
virtual 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);
nsIRDFResourceManager* mRDFResourceManager;
// Miscellaneous RDF junk
nsIRDFResourceManager* mResourceMgr;
nsIRDFDataSource* mDataSource;
RDFContentSinkState mState;
// content stack management
PRInt32 PushContext(nsIRDFNode *aContext, RDFContentSinkState aState);
nsresult PopContext(nsIRDFNode*& rContext, RDFContentSinkState& rState);
nsIRDFNode* GetContextElement(PRInt32 ancestor = 0);
PRInt32 PushContext(nsIRDFResource *aContext, RDFContentSinkState aState);
nsresult PopContext(nsIRDFResource*& rContext, RDFContentSinkState& rState);
nsIRDFResource* GetContextElement(PRInt32 ancestor = 0);
nsVoidArray* mContextStack;

View File

@@ -53,34 +53,36 @@
////////////////////////////////////////////////////////////////////////
static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID);
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
static NS_DEFINE_IID(kIHTMLStyleSheetIID, NS_IHTML_STYLE_SHEET_IID);
static NS_DEFINE_IID(kIParserIID, NS_IPARSER_IID);
static NS_DEFINE_IID(kIPresShellIID, NS_IPRESSHELL_IID);
static NS_DEFINE_IID(kIRDFDataBaseIID, NS_IRDFDATABASE_IID);
static NS_DEFINE_IID(kIRDFDataSourceIID, NS_IRDFDATASOURCE_IID);
static NS_DEFINE_IID(kIRDFDocumentIID, NS_IRDFDOCUMENT_IID);
static NS_DEFINE_IID(kICollectionIID, NS_ICOLLECTION_IID);
static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID);
static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID);
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
static NS_DEFINE_IID(kIHTMLStyleSheetIID, NS_IHTML_STYLE_SHEET_IID);
static NS_DEFINE_IID(kINameSpaceManagerIID, NS_INAMESPACEMANAGER_IID);
static NS_DEFINE_IID(kIParserIID, NS_IPARSER_IID);
static NS_DEFINE_IID(kIPresShellIID, NS_IPRESSHELL_IID);
static NS_DEFINE_IID(kIRDFDataBaseIID, NS_IRDFDATABASE_IID);
static NS_DEFINE_IID(kIRDFDataSourceIID, NS_IRDFDATASOURCE_IID);
static NS_DEFINE_IID(kIRDFDocumentIID, NS_IRDFDOCUMENT_IID);
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
static NS_DEFINE_IID(kIRDFResourceManagerIID, NS_IRDFRESOURCEMANAGER_IID);
static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kITextContentIID, NS_ITEXT_CONTENT_IID); // XXX grr...
static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
static NS_DEFINE_IID(kIXMLDocumentIID, NS_IXMLDOCUMENT_IID);
static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID);
static NS_DEFINE_IID(kINameSpaceManagerIID, NS_INAMESPACEMANAGER_IID);
static NS_DEFINE_IID(kICollectionIID, NS_ICOLLECTION_IID);
static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kITextContentIID, NS_ITEXT_CONTENT_IID); // XXX grr...
static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
static NS_DEFINE_IID(kIXMLDocumentIID, NS_IXMLDOCUMENT_IID);
static NS_DEFINE_CID(kHTMLStyleSheetCID, NS_HTMLSTYLESHEET_CID);
static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID);
static NS_DEFINE_CID(kParserCID, NS_PARSER_IID); // XXX
static NS_DEFINE_CID(kPresShellCID, NS_PRESSHELL_CID);
static NS_DEFINE_CID(kRDFMemoryDataSourceCID, NS_RDFMEMORYDATASOURCE_CID);
static NS_DEFINE_CID(kRDFSimpleDataBaseCID, NS_RDFSIMPLEDATABASE_CID);
static NS_DEFINE_CID(kRDFResourceManagerCID, NS_RDFRESOURCEMANAGER_CID);
static NS_DEFINE_CID(kRDFSimpleDataBaseCID, NS_RDFSIMPLEDATABASE_CID);
static NS_DEFINE_CID(kRangeListCID, NS_RANGELIST_CID);
static NS_DEFINE_CID(kTextNodeCID, NS_TEXTNODE_CID);
static NS_DEFINE_CID(kWellFormedDTDCID, NS_WELLFORMEDDTD_CID);
static NS_DEFINE_CID(kNameSpaceManagerCID, NS_NAMESPACEMANAGER_CID);
static NS_DEFINE_CID(kRangeListCID, NS_RANGELIST_CID);
////////////////////////////////////////////////////////////////////////
@@ -1046,7 +1048,7 @@ nsRDFDocument::Init(void)
}
NS_IMETHODIMP
nsRDFDocument::SetRootResource(nsIRDFNode* aResource)
nsRDFDocument::SetRootResource(nsIRDFResource* aResource)
{
nsresult rv;
@@ -1090,7 +1092,7 @@ nsRDFDocument::CreateChildren(nsIRDFContent* element)
return NS_ERROR_NOT_INITIALIZED;
nsIRDFNode* resource = nsnull;
nsIRDFResource* resource = nsnull;
nsIRDFCursor* properties = nsnull;
PRBool moreProperties;
@@ -1098,39 +1100,51 @@ nsRDFDocument::CreateChildren(nsIRDFContent* element)
goto done;
// Create a cursor that'll enumerate all of the outbound arcs
if (NS_FAILED(rv = mDB->ArcLabelsOut(resource, properties)))
if (NS_FAILED(rv = mDB->ArcLabelsOut(resource, &properties)))
goto done;
while (NS_SUCCEEDED(rv = properties->HasMoreElements(moreProperties)) && moreProperties) {
nsIRDFNode* property = nsnull;
PRBool tv;
while (NS_SUCCEEDED(rv = properties->HasMoreElements(&moreProperties)) && moreProperties) {
nsIRDFNode* node = nsnull;
nsIRDFResource* property = nsnull;
if (NS_FAILED(rv = properties->GetNext(property, tv /* ignored */)))
if (NS_FAILED(rv = properties->GetNext(&node, nsnull)))
break;
nsAutoString uri;
if (NS_FAILED(rv = property->GetStringValue(uri))) {
if (NS_FAILED(rv = node->QueryInterface(kIRDFResourceIID, (void**) &property))) {
NS_RELEASE(node);
break;
}
NS_RELEASE(node);
const char* s;
if (NS_FAILED(rv = property->GetValue(&s))) {
NS_RELEASE(property);
break;
}
nsAutoString uri(s);
// Create a second cursor that'll enumerate all of the values
// for all of the arcs.
nsIRDFCursor* values;
if (NS_FAILED(rv = mDB->GetTargets(resource, property, PR_TRUE, values))) {
if (NS_FAILED(rv = mDB->GetTargets(resource, property, PR_TRUE, &values))) {
NS_RELEASE(property);
break;
}
PRBool moreValues;
while (NS_SUCCEEDED(rv = values->HasMoreElements(moreValues)) && moreValues) {
nsIRDFNode* value = nsnull;
if (NS_SUCCEEDED(rv = values->GetNext(value, tv /* ignored */))) {
// At this point, the specific nsRDFDocument
// implementations will create an appropriate child
// element (or elements).
rv = AddChild(element, property, value);
NS_RELEASE(value);
while (NS_SUCCEEDED(rv = values->HasMoreElements(&moreValues)) && moreValues) {
nsIRDFNode* valueNode;
PRBool tv;
if (NS_SUCCEEDED(rv = values->GetNext(&valueNode, &tv))) {
if (tv) {
// At this point, the specific nsRDFDocument
// implementations will create an appropriate child
// element (or elements).
rv = AddChild(element, property, valueNode);
}
NS_RELEASE(valueNode);
}
if (NS_FAILED(rv))
@@ -1152,7 +1166,7 @@ done:
}
NS_IMETHODIMP
nsRDFDocument::AddTreeProperty(nsIRDFNode* resource)
nsRDFDocument::AddTreeProperty(nsIRDFResource* resource)
{
nsresult rv;
if (! mTreeProperties) {
@@ -1172,7 +1186,7 @@ nsRDFDocument::AddTreeProperty(nsIRDFNode* resource)
NS_IMETHODIMP
nsRDFDocument::RemoveTreeProperty(nsIRDFNode* resource)
nsRDFDocument::RemoveTreeProperty(nsIRDFResource* resource)
{
if (! mTreeProperties) {
// XXX no properties have ever been inserted!
@@ -1221,12 +1235,13 @@ nsRDFDocument::FindContent(const nsIContent* aStartNode,
PRBool
nsRDFDocument::IsTreeProperty(const nsIRDFNode* property) const
nsRDFDocument::IsTreeProperty(const nsIRDFResource* property) const
{
#define TREE_PROPERTY_HACK
#if defined(TREE_PROPERTY_HACK)
nsAutoString s;
property->GetStringValue(s);
const char* p;
property->GetValue(&p);
nsAutoString s(p);
if (s.Equals("http://home.netscape.com/NC-rdf#Bookmark") ||
s.Equals("http://home.netscape.com/NC-rdf#Folder")) {
return PR_TRUE;
@@ -1246,7 +1261,7 @@ nsRDFDocument::IsTreeProperty(const nsIRDFNode* property) const
nsresult
nsRDFDocument::NewChild(const nsString& tag,
nsIRDFNode* resource,
nsIRDFResource* resource,
nsIRDFContent*& result,
PRBool childrenMustBeGenerated)
{
@@ -1275,9 +1290,27 @@ nsRDFDocument::AttachTextNode(nsIContent* parent,
nsIContent* node = nsnull;
nsITextContent* text = nsnull;
nsIDocument* doc = nsnull;
nsIRDFResource* resource = nsnull;
nsIRDFLiteral* literal = nsnull;
if (NS_SUCCEEDED(rv = value->QueryInterface(kIRDFResourceIID, (void**) &resource))) {
const char* p;
if (NS_FAILED(rv = resource->GetValue(&p)))
goto error;
if (NS_FAILED(rv = value->GetStringValue(s)))
s = p;
}
else if (NS_SUCCEEDED(rv = value->QueryInterface(kIRDFLiteralIID, (void**) &literal))) {
const PRUnichar* p;
if (NS_FAILED(rv = literal->GetValue(&p)))
goto error;
s = p;
}
else {
PR_ASSERT(0);
goto error;
}
if (NS_FAILED(rv = nsRepository::CreateInstance(kTextNodeCID,
nsnull,

View File

@@ -28,6 +28,7 @@ class nsIArena;
class nsIParser;
class nsISupportsArray;
class nsINameSpaceManager;
class nsIRDFNode;
/**
* An NGLayout document context for displaying an RDF graph.
@@ -190,11 +191,11 @@ public:
// nsIRDFDocument interface
NS_IMETHOD Init(void);
NS_IMETHOD SetRootResource(nsIRDFNode* resource);
NS_IMETHOD SetRootResource(nsIRDFResource* resource);
NS_IMETHOD GetDataBase(nsIRDFDataBase*& result);
NS_IMETHOD CreateChildren(nsIRDFContent* element);
NS_IMETHOD AddTreeProperty(nsIRDFNode* resource);
NS_IMETHOD RemoveTreeProperty(nsIRDFNode* resource);
NS_IMETHOD AddTreeProperty(nsIRDFResource* resource);
NS_IMETHOD RemoveTreeProperty(nsIRDFResource* resource);
protected:
nsIContent*
@@ -202,18 +203,18 @@ protected:
const nsIContent* aTest1,
const nsIContent* aTest2) const;
PRBool IsTreeProperty(const nsIRDFNode* resource) const;
PRBool IsTreeProperty(const nsIRDFResource* resource) const;
nsresult AttachTextNode(nsIContent* parent,
nsIRDFNode* value);
nsresult NewChild(const nsString& tag,
nsIRDFNode* resource,
nsIRDFResource* resource,
nsIRDFContent*& result,
PRBool childrenMustBeGenerated);
virtual nsresult AddChild(nsIRDFContent* parent,
nsIRDFNode* property,
nsIRDFResource* property,
nsIRDFNode* value) = 0;
nsIArena* mArena;

View File

@@ -398,8 +398,8 @@ nsRDFDocumentContentSink::OpenObject(const nsIParserNode& aNode)
if (NS_FAILED(rv = GetIdAboutAttribute(aNode, uri)))
return rv;
nsIRDFNode* resource;
if (NS_FAILED(rv = mRDFResourceManager->GetNode(uri, resource)))
nsIRDFResource* resource;
if (NS_FAILED(rv = mResourceMgr->GetUnicodeResource(uri, &resource)))
return rv;
nsIRDFDocument* rdfDoc;

View File

@@ -1247,7 +1247,7 @@ nsRDFElement::GetNameSpaceID(PRInt32& aNameSpaceID) const
NS_IMETHODIMP
nsRDFElement::Init(nsIRDFDocument* doc,
const nsString& aTag,
nsIRDFNode* resource,
nsIRDFResource* resource,
PRBool childrenMustBeGenerated)
{
NS_PRECONDITION(doc, "null ptr");
@@ -1289,7 +1289,7 @@ nsRDFElement::SetResource(const nsString& aURI)
(nsISupports**) &mgr)))
return rv;
rv = mgr->GetNode(aURI, mResource); // implicit AddRef()
rv = mgr->GetUnicodeResource(aURI, &mResource); // implicit AddRef()
nsServiceManager::ReleaseService(kRDFResourceManagerCID, mgr);
return rv;
@@ -1301,13 +1301,18 @@ nsRDFElement::GetResource(nsString& rURI) const
if (! mResource)
return NS_ERROR_NOT_INITIALIZED;
return mResource->GetStringValue(rURI);
const char* s;
nsresult rv;
if (NS_FAILED(rv = mResource->GetValue(&s)))
return rv;
rURI = s;
return NS_OK;
}
NS_IMETHODIMP
nsRDFElement::SetResource(nsIRDFNode* aResource)
nsRDFElement::SetResource(nsIRDFResource* aResource)
{
NS_PRECONDITION(aResource, "null ptr");
NS_PRECONDITION(!mResource, "already initialized");
@@ -1325,7 +1330,7 @@ nsRDFElement::SetResource(nsIRDFNode* aResource)
NS_IMETHODIMP
nsRDFElement::GetResource(nsIRDFNode*& aResource)
nsRDFElement::GetResource(nsIRDFResource*& aResource)
{
if (! mResource)
return NS_ERROR_NOT_INITIALIZED;
@@ -1341,8 +1346,9 @@ nsRDFElement::SetProperty(const nsString& aPropertyURI, const nsString& aValue)
if (!mResource || !mDocument)
return NS_ERROR_NOT_INITIALIZED;
nsString resource;
mResource->GetStringValue(resource);
const char* s;
mResource->GetValue(&s);
nsAutoString resource = s;
#ifdef DEBUG_waterson
char buf[256];
@@ -1361,14 +1367,15 @@ nsRDFElement::SetProperty(const nsString& aPropertyURI, const nsString& aValue)
(nsISupports**) &mgr)))
return rv;
nsIRDFNode* property = nsnull;
nsIRDFNode* value = nsnull;
nsIRDFDataBase* db = nsnull;
nsIRDFResource* property = nsnull;
nsIRDFLiteral* value = nsnull;
nsIRDFDataBase* db = nsnull;
if (NS_FAILED(rv = mgr->GetNode(aPropertyURI, property)))
if (NS_FAILED(rv = mgr->GetUnicodeResource(aPropertyURI, &property)))
goto done;
if (NS_FAILED(rv = mgr->GetNode(aValue, value)))
// XXX assume it's a literal?
if (NS_FAILED(rv = mgr->GetLiteral(aValue, &value)))
goto done;
if (NS_FAILED(rv = mDocument->GetDataBase(db)))

View File

@@ -32,7 +32,6 @@ class nsIContent;
class nsIRDFDocument;
class nsIAtom;
class nsIEventListenerManager;
class nsIRDFNode;
class nsISupportsArray;
// XXX should we make this inheirit from the nsXMLElement
@@ -109,14 +108,14 @@ public:
// nsIRDFContent
NS_IMETHOD Init(nsIRDFDocument* doc,
const nsString& tag,
nsIRDFNode* resource,
nsIRDFResource* resource,
PRBool childrenMustBeGenerated);
NS_IMETHOD SetResource(const nsString& aURI);
NS_IMETHOD GetResource(nsString& rURI) const;
NS_IMETHOD SetResource(nsIRDFNode* aResource);
NS_IMETHOD GetResource(nsIRDFNode*& aResource);
NS_IMETHOD SetResource(nsIRDFResource* aResource);
NS_IMETHOD GetResource(nsIRDFResource*& aResource);
NS_IMETHOD SetProperty(const nsString& aPropertyURI, const nsString& aValue);
NS_IMETHOD GetProperty(const nsString& aPropertyURI, nsString& rValue) const;
@@ -152,7 +151,7 @@ protected:
void* mScriptObject;
/** The RDF resource that the element corresponds to */
nsIRDFNode* mResource;
nsIRDFResource* mResource;
/** An array of child nodes */
nsISupportsArray* mChildren;

View File

@@ -18,10 +18,9 @@
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsIRDFResourceManager.h"
#include "nsRDFBuiltInDataSources.h"
#include "nsRDFResourceManager.h"
#include "nsRDFDocument.h"
#include "nsRDFRegistryImpl.h"
#include "nsRDFCID.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
@@ -30,16 +29,15 @@ static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_CID(kRDFBookmarkDataSourceCID, NS_RDFBOOKMARKDATASOURCE_CID);
static NS_DEFINE_CID(kRDFHTMLDocumentCID, NS_RDFHTMLDOCUMENT_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(kRDFStreamDataSourceCID, NS_RDFSTREAMDATASOURCE_CID);
static NS_DEFINE_CID(kRDFTreeDocumentCID, NS_RDFTREEDOCUMENT_CID);
class nsRDFFactory : public nsIFactory
class RDFFactoryImpl : public nsIFactory
{
public:
nsRDFFactory(const nsCID &aClass);
RDFFactoryImpl(const nsCID &aClass);
// nsISupports methods
NS_DECL_ISUPPORTS
@@ -52,7 +50,7 @@ public:
NS_IMETHOD LockFactory(PRBool aLock);
protected:
virtual ~nsRDFFactory();
virtual ~RDFFactoryImpl();
private:
nsCID mClassID;
@@ -60,19 +58,19 @@ private:
////////////////////////////////////////////////////////////////////////
nsRDFFactory::nsRDFFactory(const nsCID &aClass)
RDFFactoryImpl::RDFFactoryImpl(const nsCID &aClass)
{
NS_INIT_REFCNT();
mClassID = aClass;
}
nsRDFFactory::~nsRDFFactory()
RDFFactoryImpl::~RDFFactoryImpl()
{
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
}
NS_IMETHODIMP
nsRDFFactory::QueryInterface(const nsIID &aIID,
RDFFactoryImpl::QueryInterface(const nsIID &aIID,
void **aResult)
{
if (! aResult)
@@ -93,12 +91,12 @@ nsRDFFactory::QueryInterface(const nsIID &aIID,
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(nsRDFFactory);
NS_IMPL_RELEASE(nsRDFFactory);
NS_IMPL_ADDREF(RDFFactoryImpl);
NS_IMPL_RELEASE(RDFFactoryImpl);
NS_IMETHODIMP
nsRDFFactory::CreateInstance(nsISupports *aOuter,
RDFFactoryImpl::CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult)
{
@@ -111,49 +109,35 @@ nsRDFFactory::CreateInstance(nsISupports *aOuter,
*aResult = nsnull;
nsresult rv;
PRBool wasRefCounted = PR_FALSE;
PRBool wasRefCounted = PR_TRUE;
nsISupports *inst = nsnull;
if (mClassID.Equals(kRDFResourceManagerCID)) {
inst = NS_STATIC_CAST(nsISupports*, new nsRDFResourceManager());
if (NS_FAILED(rv = NS_NewRDFResourceManager((nsIRDFResourceManager**) &inst)))
return rv;
}
else if (mClassID.Equals(kRDFMemoryDataSourceCID)) {
if (NS_FAILED(rv = NS_NewRDFMemoryDataSource((nsIRDFDataSource**) &inst)))
return rv;
wasRefCounted = PR_TRUE;
}
else if (mClassID.Equals(kRDFStreamDataSourceCID)) {
if (NS_FAILED(rv = NS_NewRDFStreamDataSource((nsIRDFDataSource**) &inst)))
return rv;
wasRefCounted = PR_TRUE;
}
else if (mClassID.Equals(kRDFBookmarkDataSourceCID)) {
if (NS_FAILED(rv = NS_NewRDFBookmarkDataSource((nsIRDFDataSource**) &inst)))
return rv;
wasRefCounted = PR_TRUE;
}
else if (mClassID.Equals(kRDFRegistryCID)) {
inst = NS_STATIC_CAST(nsISupports*, new nsRDFRegistryImpl());
}
else if (mClassID.Equals(kRDFSimpleDataBaseCID)) {
if (NS_FAILED(rv = NS_NewRDFSimpleDataBase((nsIRDFDataBase**) &inst)))
return rv;
wasRefCounted = PR_TRUE;
}
else if (mClassID.Equals(kRDFHTMLDocumentCID)) {
if (NS_FAILED(rv = NS_NewRDFHTMLDocument((nsIRDFDocument**) &inst)))
return rv;
wasRefCounted = PR_TRUE;
}
else if (mClassID.Equals(kRDFTreeDocumentCID)) {
if (NS_FAILED(rv = NS_NewRDFTreeDocument((nsIRDFDocument**) &inst)))
return rv;
wasRefCounted = PR_TRUE;
}
else {
return NS_ERROR_NO_INTERFACE;
@@ -172,7 +156,7 @@ nsRDFFactory::CreateInstance(nsISupports *aOuter,
return rv;
}
nsresult nsRDFFactory::LockFactory(PRBool aLock)
nsresult RDFFactoryImpl::LockFactory(PRBool aLock)
{
// Not implemented in simplest case.
return NS_OK;
@@ -189,7 +173,7 @@ NSGetFactory(const nsCID &aClass, nsIFactory **aFactory)
if (! aFactory)
return NS_ERROR_NULL_POINTER;
*aFactory = new nsRDFFactory(aClass);
*aFactory = new RDFFactoryImpl(aClass);
if (aFactory == nsnull)
return NS_ERROR_OUT_OF_MEMORY;

View File

@@ -37,14 +37,29 @@
////////////////////////////////////////////////////////////////////////
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
////////////////////////////////////////////////////////////////////////
class RDFHTMLDocumentImpl : public nsRDFDocument {
public:
RDFHTMLDocumentImpl();
virtual ~RDFHTMLDocumentImpl();
protected:
nsresult AddTreeChild(nsIRDFContent* parent,
const nsString& tag,
nsIRDFResource* property,
nsIRDFResource* value);
nsresult AddLeafChild(nsIRDFContent* parent,
const nsString& tag,
nsIRDFResource* property,
nsIRDFLiteral* value);
virtual nsresult AddChild(nsIRDFContent* parent,
nsIRDFNode* property,
nsIRDFResource* property,
nsIRDFNode* value);
};
@@ -59,60 +74,39 @@ RDFHTMLDocumentImpl::~RDFHTMLDocumentImpl(void)
}
nsresult
RDFHTMLDocumentImpl::AddChild(nsIRDFContent* parent,
nsIRDFNode* property,
nsIRDFNode* value)
RDFHTMLDocumentImpl::AddTreeChild(nsIRDFContent* parent,
const nsString& tag,
nsIRDFResource* property,
nsIRDFResource* value)
{
// If it's a tree property, then create a child element whose
// value is the value of the property. We'll also attach an "ID="
// attribute to the new child; e.g.,
//
// <parent>
// <property id="value">
// <!-- recursively generated -->
// </property>
// ...
// </parent>
nsresult rv;
const char* p;
nsAutoString s;
nsIRDFContent* child = nsnull;
// The tag we'll use for the new child will be the string value of
// the property.
nsAutoString tag;
if (NS_FAILED(rv = property->GetStringValue(tag)))
// PR_TRUE indicates that we want the child to dynamically
// generate its own kids.
if (NS_FAILED(rv = NewChild(tag, value, child, PR_TRUE)))
goto done;
if (IsTreeProperty(property) || rdf_IsContainer(mResourceMgr, mDB, value)) {
// If it's a tree property, then create a child element whose
// value is the value of the property. We'll also attach an "ID="
// attribute to the new child; e.g.,
//
// <parent>
// <property id="value">
// <!-- recursively generated -->
// </property>
// ...
// </parent>
if (NS_FAILED(rv = value->GetValue(&p)))
goto done;
nsAutoString s;
s = p;
// PR_TRUE indicates that we want the child to dynamically
// generate its own kids.
if (NS_FAILED(rv = NewChild(tag, value, child, PR_TRUE)))
goto done;
if (NS_FAILED(rv = value->GetStringValue(s)))
goto done;
if (NS_FAILED(rv = child->SetAttribute("ID", s, PR_FALSE)))
goto done;
}
else {
// Otherwise, it's not a tree property. So we'll just create a
// new element for the property, and a simple text node for
// its value; e.g.,
//
// <parent>
// <property>value</property>
// ...
// </parent>
if (NS_FAILED(rv = NewChild(tag, property, child, PR_FALSE)))
goto done;
if (NS_FAILED(rv = AttachTextNode(child, value)))
goto done;
}
if (NS_FAILED(rv = child->SetAttribute("ID", s, PR_FALSE)))
goto done;
rv = parent->AppendChildTo(child, PR_TRUE);
@@ -122,6 +116,71 @@ done:
}
nsresult
RDFHTMLDocumentImpl::AddLeafChild(nsIRDFContent* parent,
const nsString& tag,
nsIRDFResource* property,
nsIRDFLiteral* value)
{
// Otherwise, it's not a tree property. So we'll just create a
// new element for the property, and a simple text node for
// its value; e.g.,
//
// <parent>
// <property>value</property>
// ...
// </parent>
nsresult rv;
nsIRDFContent* child = nsnull;
if (NS_FAILED(rv = NewChild(tag, property, child, PR_FALSE)))
goto done;
if (NS_FAILED(rv = AttachTextNode(child, value)))
goto done;
rv = parent->AppendChildTo(child, PR_TRUE);
done:
NS_IF_RELEASE(child);
return rv;
}
nsresult
RDFHTMLDocumentImpl::AddChild(nsIRDFContent* parent,
nsIRDFResource* property,
nsIRDFNode* value)
{
nsresult rv;
// The tag we'll use for the new child will be the string value of
// the property.
const char* s;
if (NS_FAILED(rv = property->GetValue(&s)))
return rv;
nsAutoString tag = s;
nsIRDFResource* valueResource;
if (NS_SUCCEEDED(rv = value->QueryInterface(kIRDFResourceIID, (void**) &valueResource))) {
if (IsTreeProperty(property) || rdf_IsContainer(mResourceMgr, mDB, valueResource)) {
rv = AddTreeChild(parent, tag, property, valueResource);
NS_RELEASE(valueResource);
return rv;
}
NS_RELEASE(valueResource);
}
nsIRDFLiteral* valueLiteral;
if (NS_SUCCEEDED(rv = value->QueryInterface(kIRDFLiteralIID, (void**) &valueLiteral))) {
rv = AddLeafChild(parent, tag, property, valueLiteral);
NS_RELEASE(valueLiteral);
}
return rv;
}
////////////////////////////////////////////////////////////////////////
nsresult NS_NewRDFHTMLDocument(nsIRDFDocument** result)

View File

@@ -17,160 +17,312 @@
*/
#include "nsIRDFNode.h"
#include "nsRDFResourceManager.h"
#include "nsString.h"
#include "nsIAtom.h"
static NS_DEFINE_IID(kIRDFResourceManagerIID, NS_IRDFRESOURCEMANAGER_IID);
#include "nsIRDFNode.h"
#include "nsIRDFResourceManager.h"
#include "nsString.h"
#include "plhash.h"
#include "plstr.h"
////////////////////////////////////////////////////////////////////////
class RDFNodeImpl : public nsIRDFNode {
static NS_DEFINE_IID(kIRDFResourceManagerIID, NS_IRDFRESOURCEMANAGER_IID);
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
static NS_DEFINE_IID(kIRDFNodeIID, NS_IRDFNODE_IID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
////////////////////////////////////////////////////////////////////////
class ResourceImpl;
class ResourceManagerImpl : public nsIRDFResourceManager {
protected:
PLHashTable* mResources;
virtual ~ResourceManagerImpl(void);
public:
RDFNodeImpl(nsRDFResourceManager* mgr, nsIAtom* value);
virtual ~RDFNodeImpl(void);
ResourceManagerImpl(void);
// nsISupports
NS_DECL_ISUPPORTS
// nsIRDFNode
NS_IMETHOD GetStringValue(nsString& value) const;
// nsIRDFResourceManager
NS_IMETHOD GetResource(const char* uri, nsIRDFResource** resource);
NS_IMETHOD GetUnicodeResource(const PRUnichar* uri, nsIRDFResource** resource);
NS_IMETHOD GetLiteral(const PRUnichar* value, nsIRDFLiteral** literal);
NS_IMETHOD GetAtomValue(nsIAtom*& value) const;
private:
nsIAtom* mValue;
nsRDFResourceManager* mMgr;
void ReleaseNode(const ResourceImpl* resource);
};
RDFNodeImpl::RDFNodeImpl(nsRDFResourceManager* mgr, nsIAtom* value)
: mMgr(mgr), mValue(value)
////////////////////////////////////////////////////////////////////////
class ResourceImpl : public nsIRDFResource {
public:
ResourceImpl(ResourceManagerImpl* mgr, const char* uri);
virtual ~ResourceImpl(void);
// nsISupports
NS_DECL_ISUPPORTS
// nsIRDFResource
NS_IMETHOD GetValue(const char* *uri) const;
NS_IMETHOD EqualsResource(const nsIRDFResource* resource, PRBool* result) const;
NS_IMETHOD EqualsString(const char* uri, PRBool* result) const;
// Implementation methods
const char* GetURI(void) const {
return mURI;
}
private:
char* mURI;
ResourceManagerImpl* mMgr;
};
ResourceImpl::ResourceImpl(ResourceManagerImpl* mgr, const char* uri)
: mMgr(mgr)
{
NS_INIT_REFCNT();
NS_IF_ADDREF(mValue);
NS_IF_ADDREF(mMgr);
mURI = PL_strdup(uri);
}
RDFNodeImpl::~RDFNodeImpl(void)
ResourceImpl::~ResourceImpl(void)
{
mMgr->ReleaseNode(this);
NS_IF_RELEASE(mValue);
PL_strfree(mURI);
NS_IF_RELEASE(mMgr);
}
static NS_DEFINE_IID(kIRDFNodeIID, NS_IRDFNODE_IID);
NS_IMPL_ISUPPORTS(RDFNodeImpl, kIRDFNodeIID);
NS_IMPL_ADDREF(ResourceImpl);
NS_IMPL_RELEASE(ResourceImpl);
nsresult
ResourceImpl::QueryInterface(REFNSIID iid, void** result)
{
if (! result)
return NS_ERROR_NULL_POINTER;
*result = nsnull;
if (iid.Equals(kIRDFResourceIID) ||
iid.Equals(kIRDFNodeIID) ||
iid.Equals(kISupportsIID)) {
*result = NS_STATIC_CAST(nsIRDFResource*, this);
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP
RDFNodeImpl::GetStringValue(nsString& value) const
ResourceImpl::GetValue(const char* *uri) const
{
mValue->ToString(value);
if (!uri)
return NS_ERROR_NULL_POINTER;
*uri = mURI;
return NS_OK;
}
NS_IMETHODIMP
RDFNodeImpl::GetAtomValue(nsIAtom*& value) const
ResourceImpl::EqualsResource(const nsIRDFResource* resource, PRBool* result) const
{
value = mValue;
value->AddRef();
if (!resource || !result)
return NS_ERROR_NULL_POINTER;
*result = (resource == this);
return NS_OK;
}
NS_IMETHODIMP
ResourceImpl::EqualsString(const char* uri, PRBool* result) const
{
if (!uri || !result)
return NS_ERROR_NULL_POINTER;
*result = (PL_strcmp(uri, mURI) == 0);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// ResourceHashKey
class ResourceHashKey : public nsHashKey
{
private:
nsIAtom* mResource;
//
class LiteralImpl : public nsIRDFLiteral {
public:
ResourceHashKey(nsIAtom* resource) : mResource(resource) {
NS_IF_ADDREF(mResource);
}
LiteralImpl(const PRUnichar* s);
virtual ~LiteralImpl(void);
virtual ~ResourceHashKey(void) {
NS_IF_RELEASE(mResource);
}
// nsISupports
NS_DECL_ISUPPORTS
// nsHashKey pure virtual interface methods
virtual PRUint32 HashValue(void) const {
return (PRUint32) mResource;
}
// nsIRDFLiteral
NS_IMETHOD GetValue(const PRUnichar* *value) const;
NS_IMETHOD Equals(const nsIRDFLiteral* literal, PRBool* result) const;
virtual PRBool Equals(const nsHashKey* aKey) const {
ResourceHashKey* that;
// XXX like to do a dynamic_cast<> here...
that = (ResourceHashKey*) aKey;
return (that->mResource == this->mResource);
}
virtual nsHashKey* Clone(void) const {
return new ResourceHashKey(mResource);
}
private:
nsAutoString mValue;
};
////////////////////////////////////////////////////////////////////////
// nsRDFResourceManager
nsRDFResourceManager::nsRDFResourceManager(void)
LiteralImpl::LiteralImpl(const PRUnichar* s)
: mValue(s)
{
NS_INIT_REFCNT();
}
nsRDFResourceManager::~nsRDFResourceManager(void)
LiteralImpl::~LiteralImpl(void)
{
// XXX LEAK! Make sure you release the nodes!
}
NS_IMPL_ADDREF(LiteralImpl);
NS_IMPL_RELEASE(LiteralImpl);
nsresult
LiteralImpl::QueryInterface(REFNSIID iid, void** result)
{
if (! result)
return NS_ERROR_NULL_POINTER;
*result = nsnull;
if (iid.Equals(kIRDFLiteralIID) ||
iid.Equals(kIRDFNodeIID) ||
iid.Equals(kISupportsIID)) {
*result = NS_STATIC_CAST(nsIRDFLiteral*, this);
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP
LiteralImpl::GetValue(const PRUnichar* *value) const
{
NS_ASSERTION(value, "null ptr");
if (! value)
return NS_ERROR_NULL_POINTER;
*value = mValue.GetUnicode();
return NS_OK;
}
NS_IMPL_ISUPPORTS(nsRDFResourceManager, kIRDFResourceManagerIID);
NS_IMETHODIMP
LiteralImpl::Equals(const nsIRDFLiteral* literal, PRBool* result) const
{
NS_ASSERTION(literal && result, "null ptr");
if (!literal || !result)
return NS_ERROR_NULL_POINTER;
nsresult rv;
const PRUnichar* p;
if (NS_FAILED(rv = literal->GetValue(&p)))
return rv;
nsAutoString s(p);
*result = s.Equals(mValue);
return NS_OK;
}
////////////////////////////////////////////////////////////////////////
// ResourceManagerImpl
ResourceManagerImpl::ResourceManagerImpl(void)
: mResources(nsnull)
{
NS_INIT_REFCNT();
mResources = PL_NewHashTable(1023, // nbuckets
PL_HashString, // hash fn
PL_CompareStrings, // key compare fn
PL_CompareValues, // value compare fn
nsnull, nsnull); // alloc ops & priv
}
ResourceManagerImpl::~ResourceManagerImpl(void)
{
PL_HashTableDestroy(mResources);
}
NS_IMPL_ISUPPORTS(ResourceManagerImpl, kIRDFResourceManagerIID);
NS_IMETHODIMP
nsRDFResourceManager::GetNode(const nsString& uri, nsIRDFNode*& resource)
ResourceManagerImpl::GetResource(const char* uri, nsIRDFResource** resource)
{
nsIAtom* atom = NS_NewAtom(uri);
if (!atom)
return NS_ERROR_OUT_OF_MEMORY;
ResourceImpl* result =
NS_STATIC_CAST(ResourceImpl*, PL_HashTableLookup(mResources, uri));
ResourceHashKey key(atom);
if (! result) {
result = new ResourceImpl(this, uri);
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
resource = NS_STATIC_CAST(nsIRDFNode*,mResources.Get(&key));
if (! resource) {
resource = new RDFNodeImpl(this, atom);
if (resource)
mResources.Put(&key, resource);
// This is a little trick to make storage more efficient. For
// the "key" in the table, we'll use the string value that's
// stored as a member variable of the ResourceImpl object.
PL_HashTableAdd(mResources, result->GetURI(), result);
// We don't AddRef() the resource.
// *We* don't AddRef() the resource, because the resource
// AddRef()s *us*.
}
atom->Release();
result->AddRef();
*resource = result;
if (! resource)
return NS_OK;
}
NS_IMETHODIMP
ResourceManagerImpl::GetUnicodeResource(const PRUnichar* uri, nsIRDFResource** resource)
{
nsString s(uri);
char* cstr = s.ToNewCString();
nsresult rv = GetResource(cstr, resource);
delete[] cstr;
return rv;
}
NS_IMETHODIMP
ResourceManagerImpl::GetLiteral(const PRUnichar* uri, nsIRDFLiteral** literal)
{
LiteralImpl* result = new LiteralImpl(uri);
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
resource->AddRef();
*literal = result;
NS_ADDREF(result);
return NS_OK;
}
void
nsRDFResourceManager::ReleaseNode(const RDFNodeImpl* resource)
ResourceManagerImpl::ReleaseNode(const ResourceImpl* resource)
{
nsIAtom* atom;
resource->GetAtomValue(atom);
ResourceHashKey key(atom);
atom->Release();
mResources.Remove(&key);
PL_HashTableRemove(mResources, resource->GetURI());
}
////////////////////////////////////////////////////////////////////////
nsresult
NS_NewRDFResourceManager(nsIRDFResourceManager** mgr)
{
ResourceManagerImpl* result = new ResourceManagerImpl();
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
*mgr = result;
NS_ADDREF(result);
return NS_OK;
}

View File

@@ -41,6 +41,11 @@ static const char* kColumnsTag = "COLUMNS";
////////////////////////////////////////////////////////////////////////
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
////////////////////////////////////////////////////////////////////////
class RDFTreeDocumentImpl : public nsRDFDocument {
public:
RDFTreeDocumentImpl();
@@ -51,7 +56,7 @@ public:
protected:
virtual nsresult
AddChild(nsIRDFContent* parent,
nsIRDFNode* property,
nsIRDFResource* property,
nsIRDFNode* value);
/**
@@ -70,16 +75,16 @@ protected:
*/
nsresult
AddTreeChild(nsIRDFContent* parent,
nsIRDFNode* property,
nsIRDFNode* value);
nsIRDFResource* property,
nsIRDFResource* value);
/**
* Add a single column to the content model.
*/
nsresult
AddColumn(nsIContent* parent,
nsIRDFNode* property,
nsIRDFNode* title);
nsIRDFResource* property,
nsIRDFLiteral* title);
/**
@@ -87,7 +92,7 @@ protected:
*/
nsresult
AddColumnsFromContainer(nsIContent* parent,
nsIRDFNode* columns);
nsIRDFResource* columns);
/**
@@ -95,21 +100,21 @@ protected:
*/
nsresult
AddColumnsFromMultiAttributes(nsIContent* parent,
nsIRDFNode* columns);
nsIRDFResource* columns);
/**
* Add columns to the content model.
*/
nsresult
AddColumns(nsIContent* parent,
nsIRDFNode* columns);
nsIRDFResource* columns);
/**
* Add a new property element to the content model
*/
nsresult
AddPropertyChild(nsIRDFContent* parent,
nsIRDFNode* property,
nsIRDFResource* property,
nsIRDFNode* value);
};
@@ -193,8 +198,8 @@ done:
nsresult
RDFTreeDocumentImpl::AddTreeChild(nsIRDFContent* parent,
nsIRDFNode* property,
nsIRDFNode* value)
nsIRDFResource* property,
nsIRDFResource* value)
{
// If it's a tree property, then we need to add the new child
// element to a special "children" element in the parent. The
@@ -215,6 +220,7 @@ RDFTreeDocumentImpl::AddTreeChild(nsIRDFContent* parent,
nsresult rv;
nsIRDFContent* child = nsnull;
nsIContent* children = nsnull;
const char* p;
nsAutoString s;
// Ensure that the <children> element exists on the parent.
@@ -227,9 +233,11 @@ RDFTreeDocumentImpl::AddTreeChild(nsIRDFContent* parent,
if (NS_FAILED(rv = NewChild(kFolderTag, value, child, PR_TRUE)))
goto done;
if (NS_FAILED(rv = value->GetStringValue(s)))
if (NS_FAILED(rv = value->GetValue(&p)))
goto done;
s = p;
if (NS_FAILED(rv = child->SetAttribute("ID", s, PR_FALSE)))
goto done;
@@ -250,15 +258,17 @@ done:
nsresult
RDFTreeDocumentImpl::AddColumn(nsIContent* parent,
nsIRDFNode* property,
nsIRDFNode* title)
nsIRDFResource* property,
nsIRDFLiteral* title)
{
nsresult rv;
nsAutoString tag;
if (NS_FAILED(rv = property->GetStringValue(tag)))
const char* s;
if (NS_FAILED(rv = property->GetValue(&s)))
return rv;
nsAutoString tag = s;
// XXX this should be a generic XML container element, not an nsRDFElement
nsIRDFContent* column = nsnull;
@@ -317,7 +327,7 @@ done:
nsresult
RDFTreeDocumentImpl::AddColumnsFromContainer(nsIContent* parent,
nsIRDFNode* columns)
nsIRDFResource* columns)
{
nsresult rv;
@@ -325,38 +335,53 @@ RDFTreeDocumentImpl::AddColumnsFromContainer(nsIContent* parent,
if (NS_FAILED(rv = EnsureChildElement(parent, kColumnsTag, columnsElement)))
return rv;
nsIRDFNode* NC_Column = nsnull;
nsIRDFNode* NC_Title = nsnull;
nsIRDFResource* NC_Column = nsnull;
nsIRDFResource* NC_Title = nsnull;
nsIRDFCursor* cursor = nsnull;
PRBool moreElements;
if (NS_FAILED(rv = mResourceMgr->GetNode(kURINC_Column, NC_Column)))
if (NS_FAILED(rv = mResourceMgr->GetResource(kURINC_Column, &NC_Column)))
goto done;
if (NS_FAILED(rv = mResourceMgr->GetNode(kURINC_Title, NC_Title)))
if (NS_FAILED(rv = mResourceMgr->GetResource(kURINC_Title, &NC_Title)))
goto done;
if (NS_FAILED(rv = NS_NewContainerCursor(mDB, columns, cursor)))
if (NS_FAILED(rv = NS_NewContainerCursor(mDB, columns, &cursor)))
goto done;
while (NS_SUCCEEDED(rv = cursor->HasMoreElements(moreElements)) && moreElements) {
nsIRDFNode* column;
PRBool tv; /* ignored */
while (NS_SUCCEEDED(rv = cursor->HasMoreElements(&moreElements)) && moreElements) {
nsIRDFNode* columnNode;
if (NS_SUCCEEDED(rv = cursor->GetNext(&columnNode, nsnull))) {
nsIRDFResource* column;
if (NS_SUCCEEDED(rv = columnNode->QueryInterface(kIRDFResourceIID, (void**) &column))) {
// XXX okay, error recovery leaves a bit to be desired here...
nsIRDFNode* propertyNode = nsnull;
nsIRDFResource* property = nsnull;
nsIRDFNode* titleNode = nsnull;
nsIRDFLiteral* title = nsnull;
if (NS_SUCCEEDED(rv = cursor->GetNext(column, tv))) {
nsIRDFNode* property = nsnull;
nsIRDFNode* title = nsnull;
rv = mDB->GetTarget(column, NC_Column, PR_TRUE, &propertyNode);
PR_ASSERT(NS_SUCCEEDED(rv));
rv = mDB->GetTarget(column, NC_Column, PR_TRUE, property);
PR_ASSERT(NS_SUCCEEDED(rv));
rv = propertyNode->QueryInterface(kIRDFResourceIID, (void**) &property);
PR_ASSERT(NS_SUCCEEDED(rv));
rv = mDB->GetTarget(column, NC_Title, PR_TRUE, title);
PR_ASSERT(NS_SUCCEEDED(rv));
rv = mDB->GetTarget(column, NC_Title, PR_TRUE, &titleNode);
PR_ASSERT(NS_SUCCEEDED(rv));
AddColumn(columnsElement, property, title);
rv = titleNode->QueryInterface(kIRDFLiteralIID, (void**) &title);
PR_ASSERT(NS_SUCCEEDED(rv));
NS_IF_RELEASE(title);
NS_IF_RELEASE(property);
AddColumn(columnsElement, property, title);
NS_IF_RELEASE(title);
NS_IF_RELEASE(titleNode);
NS_IF_RELEASE(property);
NS_IF_RELEASE(propertyNode);
NS_RELEASE(column);
}
NS_RELEASE(columnNode);
}
if (NS_FAILED(rv))
@@ -402,7 +427,7 @@ done:
*/
nsresult
RDFTreeDocumentImpl::AddColumnsFromMultiAttributes(nsIContent* parent,
nsIRDFNode* columns)
nsIRDFResource* columns)
{
nsresult rv;
@@ -412,20 +437,30 @@ RDFTreeDocumentImpl::AddColumnsFromMultiAttributes(nsIContent* parent,
PRBool moreElements;
nsIRDFCursor* cursor = nsnull;
if (NS_FAILED(rv = mDB->ArcLabelsOut(columns, cursor)))
if (NS_FAILED(rv = mDB->ArcLabelsOut(columns, &cursor)))
goto done;
while (NS_SUCCEEDED(rv = cursor->HasMoreElements(moreElements)) && moreElements) {
nsIRDFNode* property;
PRBool tv; /* ignored */
while (NS_SUCCEEDED(rv = cursor->HasMoreElements(&moreElements)) && moreElements) {
nsIRDFNode* propertyNode;
if (NS_SUCCEEDED(rv = cursor->GetNext(property, tv))) {
nsIRDFNode* title;
if (NS_SUCCEEDED(rv = mDB->GetTarget(columns, property, PR_TRUE, title))) {
rv = AddColumn(columnsElement, property, title);
NS_RELEASE(title);
if (NS_SUCCEEDED(rv = cursor->GetNext(&propertyNode, nsnull))) {
nsIRDFResource* property;
if (NS_SUCCEEDED(rv = propertyNode->QueryInterface(kIRDFResourceIID,
(void**) &property))) {
nsIRDFNode* titleNode;
if (NS_SUCCEEDED(rv = mDB->GetTarget(columns, property, PR_TRUE, &titleNode))) {
nsIRDFLiteral* title;
if (NS_SUCCEEDED(rv = titleNode->QueryInterface(kIRDFLiteralIID,
(void**) &title))) {
rv = AddColumn(columnsElement, property, title);
NS_RELEASE(title);
}
NS_RELEASE(titleNode);
}
NS_RELEASE(property);
}
NS_RELEASE(property);
NS_RELEASE(propertyNode);
}
if (NS_FAILED(rv))
@@ -442,7 +477,7 @@ done:
nsresult
RDFTreeDocumentImpl::AddColumns(nsIContent* parent,
nsIRDFNode* columns)
nsIRDFResource* columns)
{
nsresult rv;
@@ -458,7 +493,7 @@ RDFTreeDocumentImpl::AddColumns(nsIContent* parent,
nsresult
RDFTreeDocumentImpl::AddPropertyChild(nsIRDFContent* parent,
nsIRDFNode* property,
nsIRDFResource* property,
nsIRDFNode* value)
{
// Otherwise, it's not a tree property. So we'll just create a
@@ -474,14 +509,17 @@ RDFTreeDocumentImpl::AddPropertyChild(nsIRDFContent* parent,
nsresult rv;
nsIContent* columnsElement = nsnull;
nsIRDFContent* child = nsnull;
const char* p;
nsAutoString s;
if (NS_FAILED(rv = EnsureChildElement(parent, kColumnsTag, columnsElement)))
goto done;
if (NS_FAILED(rv = property->GetStringValue(s)))
if (NS_FAILED(rv = property->GetValue(&p)))
goto done;
s = p;
// XXX this should be a generic XML element, *not* an nsRDFElement.
if (NS_FAILED(rv = NewChild(s, property, child, PR_FALSE)))
goto done;
@@ -498,36 +536,35 @@ done:
}
static PRBool
rdf_ContentResourceEquals(nsIRDFResourceManager* mgr,
nsIRDFContent* element,
const nsString& uri)
{
nsresult rv;
nsIRDFNode* resource = nsnull;
if (NS_FAILED(rv = element->GetResource(resource)))
return PR_FALSE;
PRBool result = rdf_ResourceEquals(mgr, resource, uri);
NS_RELEASE(resource);
return result;
}
nsresult
RDFTreeDocumentImpl::AddChild(nsIRDFContent* parent,
nsIRDFNode* property,
nsIRDFResource* property,
nsIRDFNode* value)
{
if (parent == mRootContent && rdf_ResourceEquals(mResourceMgr, property, kURINC_Columns)) {
return AddColumns(parent, value);
}
else if (IsTreeProperty(property) || rdf_IsContainer(mResourceMgr, mDB, value)) {
return AddTreeChild(parent, property, value);
}
else {
return AddPropertyChild(parent, property, value);
nsresult rv;
nsIRDFResource* resource;
if (NS_SUCCEEDED(rv = value->QueryInterface(kIRDFResourceIID, (void**) &resource))) {
PRBool isColumnsProperty;
if (parent == mRootContent &&
NS_SUCCEEDED(property->EqualsString(kURINC_Columns, &isColumnsProperty)) &&
isColumnsProperty) {
rv = AddColumns(parent, resource);
NS_RELEASE(resource);
return rv;
}
else if (IsTreeProperty(property) || rdf_IsContainer(mResourceMgr, mDB, resource)) {
rv = AddTreeChild(parent, property, resource);
NS_RELEASE(resource);
return rv;
}
NS_RELEASE(resource);
}
return AddPropertyChild(parent, property, value);
}

View File

@@ -75,17 +75,17 @@ public:
NS_DECL_ISUPPORTS
NS_IMETHOD HasMoreElements(PRBool& result);
NS_IMETHOD GetNext(nsIRDFNode*& next, PRBool& tv);
NS_IMETHOD HasMoreElements(PRBool* result);
NS_IMETHOD GetNext(nsIRDFNode** next, PRBool* tv);
virtual nsresult
GetCursor(nsIRDFDataSource* ds, nsIRDFCursor*& result) = 0;
GetCursor(nsIRDFDataSource* ds, nsIRDFCursor** result) = 0;
virtual nsresult
HasNegation(nsIRDFDataSource* ds0,
nsIRDFNode* nodeToTest,
PRBool tv,
PRBool& result) = 0;
PRBool* result) = 0;
};
@@ -129,7 +129,7 @@ MultiCursor::~MultiCursor(void)
NS_IMPL_ISUPPORTS(MultiCursor, kIRDFCursorIID);
NS_IMETHODIMP
MultiCursor::HasMoreElements(PRBool& result)
MultiCursor::HasMoreElements(PRBool* result)
{
nsresult rv;
if (! mDataSources)
@@ -138,19 +138,19 @@ MultiCursor::HasMoreElements(PRBool& result)
// If we've already queued up a next target, then yep, there are
// more elements.
if (mNextResult) {
result = PR_TRUE;
*result = PR_TRUE;
return NS_OK;
}
// Otherwise, we'll need to find a next target, switching cursors
// if necessary.
result = PR_FALSE;
*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);
rv = GetCursor(mDataSources[mNextDataSource], &mCurrentCursor);
if (NS_FAILED(rv))
return rv;
@@ -161,7 +161,7 @@ MultiCursor::HasMoreElements(PRBool& result)
return rv;
// Is the current cursor depleted?
if (!result)
if (!*result)
break;
// Even if the current cursor has more elements, we still
@@ -169,7 +169,7 @@ MultiCursor::HasMoreElements(PRBool& result)
// the "main" data source.
// "Peek" ahead and pull out the next target.
if (NS_FAILED(mCurrentCursor->GetNext(mNextResult, mNextTruthValue)))
if (NS_FAILED(mCurrentCursor->GetNext(&mNextResult, &mNextTruthValue)))
return rv;
// See if data source zero has the negation
@@ -179,7 +179,7 @@ MultiCursor::HasMoreElements(PRBool& result)
if (NS_FAILED(rv = HasNegation(mDataSource0,
mNextResult,
mNextTruthValue,
hasNegation)))
&hasNegation)))
return rv;
// if not, we're done
@@ -202,18 +202,18 @@ MultiCursor::HasMoreElements(PRBool& result)
NS_IMETHODIMP
MultiCursor::GetNext(nsIRDFNode*& next, PRBool& tv)
MultiCursor::GetNext(nsIRDFNode** next, PRBool* tv)
{
nsresult rv;
PRBool hasMore;
if (NS_FAILED(rv = HasMoreElements(hasMore)))
if (NS_FAILED(rv = HasMoreElements(&hasMore)))
return rv;
if (! hasMore)
return NS_ERROR_UNEXPECTED;
next = mNextResult; // no need to AddRef() again...
tv = mNextTruthValue;
*next = mNextResult; // no need to AddRef() again...
if (tv) *tv = mNextTruthValue;
mNextResult = nsnull; // ...because we'll just "transfer ownership".
return NS_OK;
@@ -225,32 +225,32 @@ MultiCursor::GetNext(nsIRDFNode*& next, PRBool& tv)
class dbNodeCursorImpl : public MultiCursor {
private:
nsIRDFNode* mSource;
nsIRDFNode* mProperty;
nsIRDFResource* mSource;
nsIRDFResource* mProperty;
PRBool mTruthValue;
public:
dbNodeCursorImpl(nsVoidArray& dataSources,
nsIRDFNode* source,
nsIRDFNode* property,
PRBool tv);
nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv);
virtual ~dbNodeCursorImpl();
virtual nsresult
GetCursor(nsIRDFDataSource* ds, nsIRDFCursor*& result);
GetCursor(nsIRDFDataSource* ds, nsIRDFCursor** result);
virtual nsresult
HasNegation(nsIRDFDataSource* ds0,
nsIRDFNode* nodeToTest,
PRBool tv,
PRBool& result);
PRBool* result);
};
dbNodeCursorImpl::dbNodeCursorImpl(nsVoidArray& dataSources,
nsIRDFNode* source,
nsIRDFNode* property,
PRBool tv)
nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv)
: MultiCursor(dataSources),
mSource(source),
mProperty(property),
@@ -268,16 +268,16 @@ dbNodeCursorImpl::~dbNodeCursorImpl(void)
}
nsresult
dbNodeCursorImpl::GetCursor(nsIRDFDataSource* ds, nsIRDFCursor*& result)
dbNodeCursorImpl::GetCursor(nsIRDFDataSource* ds, nsIRDFCursor** result)
{
return ds->GetTargets(mSource, mProperty, mTruthValue, result);
}
nsresult
dbNodeCursorImpl::HasNegation(nsIRDFDataSource* ds0,
nsIRDFNode* target,
PRBool tv,
PRBool& result)
nsIRDFNode* target,
PRBool tv,
PRBool* result)
{
return ds0->HasAssertion(mSource, mProperty, target, !tv, result);
}
@@ -287,25 +287,25 @@ dbNodeCursorImpl::HasNegation(nsIRDFDataSource* ds0,
class dbArcCursorImpl : public MultiCursor {
private:
nsIRDFNode* mSource;
nsIRDFResource* mSource;
public:
dbArcCursorImpl(nsVoidArray& dataSources, nsIRDFNode* source);
dbArcCursorImpl(nsVoidArray& dataSources, nsIRDFResource* source);
virtual ~dbArcCursorImpl();
virtual nsresult
GetCursor(nsIRDFDataSource* ds, nsIRDFCursor*& result);
GetCursor(nsIRDFDataSource* ds, nsIRDFCursor** result);
virtual nsresult
HasNegation(nsIRDFDataSource* ds0,
nsIRDFNode* nodeToTest,
PRBool tv,
PRBool& result);
PRBool* result);
};
dbArcCursorImpl::dbArcCursorImpl(nsVoidArray& dataSources,
nsIRDFNode* source)
nsIRDFResource* source)
: MultiCursor(dataSources),
mSource(source)
{
@@ -319,18 +319,18 @@ dbArcCursorImpl::~dbArcCursorImpl(void)
}
nsresult
dbArcCursorImpl::GetCursor(nsIRDFDataSource* ds, nsIRDFCursor*& result)
dbArcCursorImpl::GetCursor(nsIRDFDataSource* ds, nsIRDFCursor** result)
{
return ds->ArcLabelsOut(mSource, result);
}
nsresult
dbArcCursorImpl::HasNegation(nsIRDFDataSource* ds0,
nsIRDFNode* target,
PRBool tv,
PRBool& result)
nsIRDFNode* target,
PRBool tv,
PRBool* result)
{
result = PR_FALSE;
*result = PR_FALSE;
return NS_OK;
}
@@ -353,52 +353,52 @@ public:
NS_DECL_ISUPPORTS
// nsIRDFDataSource interface
NS_IMETHOD Init(const nsString& uri);
NS_IMETHOD Init(const char* uri);
NS_IMETHOD GetSource(nsIRDFNode* property,
NS_IMETHOD GetSource(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFNode*& source);
nsIRDFResource** source);
NS_IMETHOD GetSources(nsIRDFNode* property,
NS_IMETHOD GetSources(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFCursor*& sources);
nsIRDFCursor** sources);
NS_IMETHOD GetTarget(nsIRDFNode* source,
nsIRDFNode* property,
NS_IMETHOD GetTarget(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFNode*& target);
nsIRDFNode** target);
NS_IMETHOD GetTargets(nsIRDFNode* source,
nsIRDFNode* property,
NS_IMETHOD GetTargets(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFCursor*& targets);
nsIRDFCursor** targets);
NS_IMETHOD Assert(nsIRDFNode* source,
nsIRDFNode* property,
NS_IMETHOD Assert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv = PR_TRUE);
PRBool tv);
NS_IMETHOD Unassert(nsIRDFNode* source,
nsIRDFNode* property,
NS_IMETHOD Unassert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target);
NS_IMETHOD HasAssertion(nsIRDFNode* source,
nsIRDFNode* property,
NS_IMETHOD HasAssertion(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
PRBool& hasAssertion);
PRBool* hasAssertion);
NS_IMETHOD AddObserver(nsIRDFObserver* n);
NS_IMETHOD RemoveObserver(nsIRDFObserver* n);
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
nsIRDFCursor*& labels);
nsIRDFCursor** labels);
NS_IMETHOD ArcLabelsOut(nsIRDFNode* source,
nsIRDFCursor*& labels);
NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
nsIRDFCursor** labels);
NS_IMETHOD Flush();
@@ -466,17 +466,17 @@ SimpleDataBaseImpl::QueryInterface(REFNSIID iid, void** result)
// nsIRDFDataSource interface
NS_IMETHODIMP
SimpleDataBaseImpl::Init(const nsString& uri)
SimpleDataBaseImpl::Init(const char* uri)
{
PR_ASSERT(0);
return NS_ERROR_UNEXPECTED;
}
NS_IMETHODIMP
SimpleDataBaseImpl::GetSource(nsIRDFNode* property,
SimpleDataBaseImpl::GetSource(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFNode*& source)
nsIRDFResource** source)
{
PRInt32 count = mDataSources.Count();
for (PRInt32 i = 0; i < count; ++i) {
@@ -486,14 +486,14 @@ SimpleDataBaseImpl::GetSource(nsIRDFNode* property,
continue;
// okay, found it. make sure we don't have the opposite
// asserted in the "main" data source
// asserted in the "local" data source
nsIRDFDataSource* ds0 = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[0]);
nsIRDFNode* tmp;
if (NS_FAILED(ds->GetSource(property, target, !tv, tmp)))
nsIRDFResource* tmp;
if (NS_FAILED(ds->GetSource(property, target, !tv, &tmp)))
return NS_OK;
NS_RELEASE(tmp);
NS_RELEASE(source);
NS_RELEASE(*source);
return NS_ERROR_FAILURE;
}
@@ -501,20 +501,20 @@ SimpleDataBaseImpl::GetSource(nsIRDFNode* property,
}
NS_IMETHODIMP
SimpleDataBaseImpl::GetSources(nsIRDFNode* property,
SimpleDataBaseImpl::GetSources(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFCursor*& sources)
nsIRDFCursor** sources)
{
PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
SimpleDataBaseImpl::GetTarget(nsIRDFNode* source,
nsIRDFNode* property,
SimpleDataBaseImpl::GetTarget(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFNode*& target)
nsIRDFNode** target)
{
PRInt32 count = mDataSources.Count();
for (PRInt32 i = 0; i < count; ++i) {
@@ -524,14 +524,14 @@ SimpleDataBaseImpl::GetTarget(nsIRDFNode* source,
continue;
// okay, found it. make sure we don't have the opposite
// asserted in the "main" data source
// asserted in the "local" data source
nsIRDFDataSource* ds0 = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[0]);
nsIRDFNode* tmp;
if (NS_FAILED(ds0->GetTarget(source, property, !tv, tmp)))
if (NS_FAILED(ds0->GetTarget(source, property, !tv, &tmp)))
return NS_OK;
NS_RELEASE(tmp);
NS_RELEASE(target);
NS_RELEASE(*target);
return NS_ERROR_FAILURE;
}
@@ -539,24 +539,29 @@ SimpleDataBaseImpl::GetTarget(nsIRDFNode* source,
}
NS_IMETHODIMP
SimpleDataBaseImpl::GetTargets(nsIRDFNode* source,
nsIRDFNode* property,
PRBool tv,
nsIRDFCursor*& targets)
SimpleDataBaseImpl::GetTargets(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFCursor** targets)
{
targets = new dbNodeCursorImpl(mDataSources, source, property, tv);
if (! targets)
return NS_ERROR_NULL_POINTER;
nsIRDFCursor* result;
result = new dbNodeCursorImpl(mDataSources, source, property, tv);
if (! result)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(targets);
NS_ADDREF(result);
*targets = result;
return NS_OK;
}
NS_IMETHODIMP
SimpleDataBaseImpl::Assert(nsIRDFNode* source,
nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv)
SimpleDataBaseImpl::Assert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv)
{
nsresult rv;
@@ -564,7 +569,7 @@ SimpleDataBaseImpl::Assert(nsIRDFNode* source,
nsIRDFDataSource* ds0 = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[0]);
PRBool ds0HasNegation;
if (NS_FAILED(rv = ds0->HasAssertion(source, property, target, !tv, ds0HasNegation)))
if (NS_FAILED(rv = ds0->HasAssertion(source, property, target, !tv, &ds0HasNegation)))
return rv;
if (ds0HasNegation) {
@@ -574,7 +579,7 @@ SimpleDataBaseImpl::Assert(nsIRDFNode* source,
// Now, see if the assertion has been "unmasked"
PRBool isAlreadyAsserted;
if (NS_FAILED(rv = HasAssertion(source, property, target, tv, isAlreadyAsserted)))
if (NS_FAILED(rv = HasAssertion(source, property, target, tv, &isAlreadyAsserted)))
return rv;
if (isAlreadyAsserted)
@@ -592,8 +597,8 @@ SimpleDataBaseImpl::Assert(nsIRDFNode* source,
}
NS_IMETHODIMP
SimpleDataBaseImpl::Unassert(nsIRDFNode* source,
nsIRDFNode* property,
SimpleDataBaseImpl::Unassert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target)
{
// XXX I have no idea what this is trying to do. I'm just going to
@@ -611,17 +616,17 @@ SimpleDataBaseImpl::Unassert(nsIRDFNode* source,
if (NS_FAILED(rv)) {
nsIRDFDataSource* ds0 = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[0]);
rv = ds0->Assert(source, property, target);
rv = ds0->Assert(source, property, target, PR_FALSE);
}
return rv;
}
NS_IMETHODIMP
SimpleDataBaseImpl::HasAssertion(nsIRDFNode* source,
nsIRDFNode* property,
nsIRDFNode* target,
PRBool tv,
PRBool& hasAssertion)
SimpleDataBaseImpl::HasAssertion(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
PRBool* hasAssertion)
{
nsresult rv;
@@ -629,11 +634,11 @@ SimpleDataBaseImpl::HasAssertion(nsIRDFNode* source,
nsIRDFDataSource* ds0 = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[0]);
PRBool ds0HasNegation;
if (NS_FAILED(rv = ds0->HasAssertion(source, property, target, !tv, ds0HasNegation)))
if (NS_FAILED(rv = ds0->HasAssertion(source, property, target, !tv, &ds0HasNegation)))
return rv;
if (ds0HasNegation) {
hasAssertion = PR_FALSE;
*hasAssertion = PR_FALSE;
return NS_OK;
}
@@ -669,21 +674,25 @@ SimpleDataBaseImpl::RemoveObserver(nsIRDFObserver* n)
NS_IMETHODIMP
SimpleDataBaseImpl::ArcLabelsIn(nsIRDFNode* node,
nsIRDFCursor*& labels)
nsIRDFCursor** labels)
{
PR_ASSERT(0);
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
SimpleDataBaseImpl::ArcLabelsOut(nsIRDFNode* source,
nsIRDFCursor*& labels)
SimpleDataBaseImpl::ArcLabelsOut(nsIRDFResource* source,
nsIRDFCursor** labels)
{
labels = new dbArcCursorImpl(mDataSources, source);
if (! labels)
return NS_ERROR_NULL_POINTER;
NS_ADDREF(labels);
nsIRDFCursor* result = new dbArcCursorImpl(mDataSources, source);
if (! result)
return NS_ERROR_NULL_POINTER;
NS_ADDREF(result);
*labels = result;
return NS_OK;
}

View File

@@ -25,16 +25,17 @@
#include "nsIDTD.h"
#include "nsINameSpaceManager.h"
#include "nsIParser.h"
#include "nsIRDFDataSource.h"
#include "nsIRDFContentSink.h"
#include "nsIStreamListener.h"
#include "nsIURL.h"
#include "nsMemoryDataSource.h"
#include "nsParserCIID.h"
////////////////////////////////////////////////////////////////////////
static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID);
static NS_DEFINE_IID(kIParserIID, NS_IPARSER_IID);
static NS_DEFINE_IID(kIRDFDataSourceIID, NS_IRDFDATASOURCE_IID);
static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID);
static NS_DEFINE_CID(kParserCID, NS_PARSER_IID); // XXX
@@ -43,17 +44,89 @@ static NS_DEFINE_CID(kWellFormedDTDCID, NS_WELLFORMEDDTD_CID);
////////////////////////////////////////////////////////////////////////
class StreamDataSourceImpl : public nsMemoryDataSource
class StreamDataSourceImpl : public nsIRDFDataSource
{
protected:
nsIURL* mURL;
nsIRDFDataSource* mInner;
public:
StreamDataSourceImpl(void);
virtual ~StreamDataSourceImpl(void);
// nsIDataSource methods that are overloaded from nsMemoryDataSource
NS_IMETHOD Init(const nsString& uri);
// nsISupports
NS_DECL_ISUPPORTS
// nsIRDFDataSource
NS_IMETHOD Init(const char* uri);
NS_IMETHOD GetSource(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFResource** source) {
return mInner->GetSource(property, target, tv, source);
}
NS_IMETHOD GetSources(nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
nsIRDFCursor** sources) {
return mInner->GetSources(property, target, tv, sources);
}
NS_IMETHOD GetTarget(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFNode** target) {
return mInner->GetTarget(source, property, tv, target);
}
NS_IMETHOD GetTargets(nsIRDFResource* source,
nsIRDFResource* property,
PRBool tv,
nsIRDFCursor** targets) {
return mInner->GetTargets(source, property, tv, targets);
}
NS_IMETHOD Assert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv) {
return mInner->Assert(source, property, target, tv);
}
NS_IMETHOD Unassert(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target) {
return mInner->Unassert(source, property, target);
}
NS_IMETHOD HasAssertion(nsIRDFResource* source,
nsIRDFResource* property,
nsIRDFNode* target,
PRBool tv,
PRBool* hasAssertion) {
return mInner->HasAssertion(source, property, target, tv, hasAssertion);
}
NS_IMETHOD AddObserver(nsIRDFObserver* n) {
return mInner->AddObserver(n);
}
NS_IMETHOD RemoveObserver(nsIRDFObserver* n) {
return mInner->RemoveObserver(n);
}
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
nsIRDFCursor** labels) {
return mInner->ArcLabelsIn(node, labels);
}
NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
nsIRDFCursor** labels) {
return mInner->ArcLabelsOut(source, labels);
}
NS_IMETHOD Flush(void);
};
@@ -73,8 +146,10 @@ StreamDataSourceImpl::~StreamDataSourceImpl(void)
}
NS_IMPL_ISUPPORTS(StreamDataSourceImpl, kIRDFDataSourceIID);
NS_IMETHODIMP
StreamDataSourceImpl::Init(const nsString& uri)
StreamDataSourceImpl::Init(const char* uri)
{
nsresult rv;

View File

@@ -47,14 +47,20 @@ DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, nextVal); // ad hoc way to make contain
////////////////////////////////////////////////////////////////////////
PRBool
rdf_IsOrdinalProperty(const nsIRDFNode* property)
{
nsAutoString uri;
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
if (NS_FAILED(property->GetStringValue(uri)))
////////////////////////////////////////////////////////////////////////
PRBool
rdf_IsOrdinalProperty(const nsIRDFResource* property)
{
const char* s;
if (NS_FAILED(property->GetValue(&s)))
return PR_FALSE;
nsAutoString uri = s;
if (uri.Find(kRDFNameSpaceURI) != 0)
return PR_FALSE;
@@ -76,34 +82,33 @@ rdf_IsOrdinalProperty(const nsIRDFNode* property)
PRBool
rdf_IsContainer(nsIRDFResourceManager* mgr,
nsIRDFDataSource* ds,
nsIRDFNode* resource)
nsIRDFResource* resource)
{
PRBool result = PR_FALSE;
nsIRDFNode* RDF_instanceOf = nsnull;
nsIRDFNode* RDF_Bag = nsnull;
nsIRDFNode* RDF_Seq = nsnull;
nsIRDFResource* RDF_instanceOf = nsnull;
nsIRDFResource* RDF_Bag = nsnull;
nsIRDFResource* RDF_Seq = nsnull;
nsresult rv;
if (NS_FAILED(rv = mgr->GetNode(kURIRDF_instanceOf, RDF_instanceOf)))
if (NS_FAILED(rv = mgr->GetResource(kURIRDF_instanceOf, &RDF_instanceOf)))
goto done;
if (NS_FAILED(rv = mgr->GetNode(kURIRDF_Bag, RDF_Bag)))
if (NS_FAILED(rv = mgr->GetResource(kURIRDF_Bag, &RDF_Bag)))
goto done;
if (NS_FAILED(rv = ds->HasAssertion(resource, RDF_instanceOf, RDF_Bag, PR_TRUE, result)))
if (NS_FAILED(rv = ds->HasAssertion(resource, RDF_instanceOf, RDF_Bag, PR_TRUE, &result)))
goto done;
if (result)
goto done;
if (NS_FAILED(rv = mgr->GetNode(kURIRDF_Seq, RDF_Seq)))
if (NS_FAILED(rv = mgr->GetResource(kURIRDF_Seq, &RDF_Seq)))
goto done;
if (NS_FAILED(rv = ds->HasAssertion(resource, RDF_instanceOf, RDF_Seq, PR_TRUE, result)))
if (NS_FAILED(rv = ds->HasAssertion(resource, RDF_instanceOf, RDF_Seq, PR_TRUE, &result)))
goto done;
done:
NS_IF_RELEASE(RDF_Seq);
NS_IF_RELEASE(RDF_Bag);
@@ -114,19 +119,13 @@ done:
// A complete hack that looks at the string value of a node and
// guesses if it's a resource
PRBool
rdf_IsResource(nsIRDFNode* node)
static PRBool
rdf_IsResource(const nsString& s)
{
nsresult rv;
nsAutoString v;
if (NS_FAILED(rv = node->GetStringValue(v)))
return PR_FALSE;
PRInt32 index;
// A URI needs a colon.
index = v.Find(':');
index = s.Find(':');
if (index < 0)
return PR_FALSE;
@@ -136,19 +135,18 @@ rdf_IsResource(nsIRDFNode* node)
return PR_FALSE;
// It can't have spaces or newlines or tabs
if (v.Find(' ') > 0 || v.Find('\n') > 0 || v.Find('\t') > 0)
if (s.Find(' ') > 0 || s.Find('\n') > 0 || s.Find('\t') > 0)
return PR_FALSE;
return PR_TRUE;
}
// 0. node, node, node
nsresult
rdf_Assert(nsIRDFDataSource* ds,
nsIRDFNode* subject,
nsIRDFNode* predicate,
rdf_Assert(nsIRDFResourceManager* mgr, // unused
nsIRDFDataSource* ds,
nsIRDFResource* subject,
nsIRDFResource* predicate,
nsIRDFNode* object)
{
NS_ASSERTION(ds, "null ptr");
@@ -157,17 +155,31 @@ rdf_Assert(nsIRDFDataSource* ds,
NS_ASSERTION(object, "null ptr");
#ifdef DEBUG
char buf[1024];
nsAutoString s;
const char* 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));
subject->GetValue(&s);
printf("(%s\n", s);
predicate->GetValue(&s);
printf(" %s\n", s);
nsIRDFResource* objectResource;
nsIRDFLiteral* objectLiteral;
if (NS_SUCCEEDED(object->QueryInterface(kIRDFResourceIID, (void**) &objectResource))) {
objectResource->GetValue(&s);
printf(" %s)\n", s);
NS_RELEASE(objectResource);
}
else if (NS_SUCCEEDED(object->QueryInterface(kIRDFLiteralIID, (void**) &objectLiteral))) {
const PRUnichar* p;
objectLiteral->GetValue(&p);
nsAutoString s2(p);
char buf[1024];
printf(" %s)\n", s2.ToCString(buf, sizeof buf));
NS_RELEASE(objectLiteral);
}
#endif
return ds->Assert(subject, predicate, object);
return ds->Assert(subject, predicate, object, PR_TRUE);
}
@@ -183,8 +195,8 @@ rdf_Assert(nsIRDFResourceManager* mgr,
NS_ASSERTION(ds, "null ptr");
nsresult rv;
nsIRDFNode* subject;
if (NS_FAILED(rv = mgr->GetNode(subjectURI, subject)))
nsIRDFResource* subject;
if (NS_FAILED(rv = mgr->GetUnicodeResource(subjectURI, &subject)))
return rv;
rv = rdf_Assert(mgr, ds, subject, predicateURI, objectURI);
@@ -197,8 +209,8 @@ rdf_Assert(nsIRDFResourceManager* mgr,
nsresult
rdf_Assert(nsIRDFResourceManager* mgr,
nsIRDFDataSource* ds,
nsIRDFNode* subject,
nsIRDFNode* predicate,
nsIRDFResource* subject,
nsIRDFResource* predicate,
const nsString& objectURI)
{
NS_ASSERTION(mgr, "null ptr");
@@ -207,10 +219,25 @@ rdf_Assert(nsIRDFResourceManager* mgr,
nsresult rv;
nsIRDFNode* object;
if (NS_FAILED(rv = mgr->GetNode(objectURI, object)))
return rv;
rv = rdf_Assert(ds, subject, predicate, object);
// XXX Make a guess *here* if the object should be a resource or a
// literal. If you don't like it, then call ds->Assert() yerself.
if (rdf_IsResource(objectURI)) {
nsIRDFResource* resource;
if (NS_FAILED(rv = mgr->GetUnicodeResource(objectURI, &resource)))
return rv;
object = resource;
}
else {
nsIRDFLiteral* literal;
if (NS_FAILED(rv = mgr->GetLiteral(objectURI, &literal)))
return rv;
object = literal;
}
rv = rdf_Assert(mgr, ds, subject, predicate, object);
NS_RELEASE(object);
return rv;
@@ -221,7 +248,7 @@ rdf_Assert(nsIRDFResourceManager* mgr,
nsresult
rdf_Assert(nsIRDFResourceManager* mgr,
nsIRDFDataSource* ds,
nsIRDFNode* subject,
nsIRDFResource* subject,
const nsString& predicateURI,
const nsString& objectURI)
{
@@ -230,12 +257,12 @@ rdf_Assert(nsIRDFResourceManager* mgr,
NS_ASSERTION(subject, "null ptr");
nsresult rv;
nsIRDFNode* object;
if (NS_FAILED(rv = mgr->GetNode(objectURI, object)))
nsIRDFResource* predicate;
if (NS_FAILED(rv = mgr->GetUnicodeResource(predicateURI, &predicate)))
return rv;
rv = rdf_Assert(mgr, ds, subject, predicateURI, object);
NS_RELEASE(object);
rv = rdf_Assert(mgr, ds, subject, predicate, objectURI);
NS_RELEASE(predicate);
return rv;
}
@@ -244,7 +271,7 @@ rdf_Assert(nsIRDFResourceManager* mgr,
nsresult
rdf_Assert(nsIRDFResourceManager* mgr,
nsIRDFDataSource* ds,
nsIRDFNode* subject,
nsIRDFResource* subject,
const nsString& predicateURI,
nsIRDFNode* object)
{
@@ -254,11 +281,11 @@ rdf_Assert(nsIRDFResourceManager* mgr,
NS_ASSERTION(object, "null ptr");
nsresult rv;
nsIRDFNode* predicate;
if (NS_FAILED(rv = mgr->GetNode(predicateURI, predicate)))
nsIRDFResource* predicate;
if (NS_FAILED(rv = mgr->GetUnicodeResource(predicateURI, &predicate)))
return rv;
rv = rdf_Assert(ds, subject, predicate, object);
rv = rdf_Assert(mgr, ds, subject, predicate, object);
NS_RELEASE(predicate);
return rv;
@@ -276,8 +303,8 @@ rdf_Assert(nsIRDFResourceManager* mgr,
NS_ASSERTION(ds, "null ptr");
nsresult rv;
nsIRDFNode* subject;
if (NS_FAILED(rv = mgr->GetNode(subjectURI, subject)))
nsIRDFResource* subject;
if (NS_FAILED(rv = mgr->GetUnicodeResource(subjectURI, &subject)))
return rv;
rv = rdf_Assert(mgr, ds, subject, predicateURI, object);
@@ -289,151 +316,152 @@ rdf_Assert(nsIRDFResourceManager* mgr,
nsresult
rdf_CreateAnonymousNode(nsIRDFResourceManager* mgr,
nsIRDFNode*& result)
rdf_CreateAnonymousResource(nsIRDFResourceManager* mgr,
nsIRDFResource** result)
{
static PRUint32 gCounter = 0;
nsAutoString s = "$";
s.Append(++gCounter, 10);
return mgr->GetNode(s, result);
return mgr->GetUnicodeResource(s, result);
}
nsresult
rdf_CreateBag(nsIRDFResourceManager* mgr,
nsIRDFDataSource* ds,
nsIRDFNode*& result)
rdf_MakeBag(nsIRDFResourceManager* mgr,
nsIRDFDataSource* ds,
nsIRDFResource* bag)
{
NS_ASSERTION(mgr, "null ptr");
NS_ASSERTION(ds, "null ptr");
NS_ASSERTION(bag, "null ptr");
nsresult rv;
nsIRDFNode* bag = nsnull;
result = nsnull; // reasonable default
if (NS_FAILED(rv = rdf_CreateAnonymousNode(mgr, bag)))
goto done;
// XXX check to see if someone else has already made this into a container.
if (NS_FAILED(rv = rdf_Assert(mgr, ds, bag, kURIRDF_instanceOf, kURIRDF_Bag)))
goto done;
return rv;
if (NS_FAILED(rv = rdf_Assert(mgr, ds, bag, kURIRDF_nextVal, "1")))
goto done;
return rv;
result = bag;
NS_ADDREF(result);
done:
NS_IF_RELEASE(bag);
return rv;
return NS_OK;
}
nsresult
rdf_CreateSequence(nsIRDFResourceManager* mgr,
nsIRDFDataSource* ds,
nsIRDFNode*& result)
rdf_MakeSeq(nsIRDFResourceManager* mgr,
nsIRDFDataSource* ds,
nsIRDFResource* seq)
{
NS_ASSERTION(mgr, "null ptr");
NS_ASSERTION(ds, "null ptr");
NS_ASSERTION(seq, "null ptr");
nsresult rv;
nsIRDFNode* bag = nsnull;
result = nsnull; // reasonable default
// XXX check to see if someone else has already made this into a container.
if (NS_FAILED(rv = rdf_CreateAnonymousNode(mgr, bag)))
goto done;
if (NS_FAILED(rv = rdf_Assert(mgr, ds, seq, kURIRDF_instanceOf, kURIRDF_Seq)))
return rv;
if (NS_FAILED(rv = rdf_Assert(mgr, ds, bag, kURIRDF_instanceOf, kURIRDF_Seq)))
goto done;
if (NS_FAILED(rv = rdf_Assert(mgr, ds, seq, kURIRDF_nextVal, "1")))
return rv;
if (NS_FAILED(rv = rdf_Assert(mgr, ds, bag, kURIRDF_nextVal, "1")))
goto done;
result = bag;
NS_ADDREF(result);
done:
NS_IF_RELEASE(bag);
return rv;
return NS_OK;
}
nsresult
rdf_CreateAlternation(nsIRDFResourceManager* mgr,
nsIRDFDataSource* ds,
nsIRDFNode*& result)
rdf_MakeAlt(nsIRDFResourceManager* mgr,
nsIRDFDataSource* ds,
nsIRDFResource* alt)
{
NS_ASSERTION(mgr, "null ptr");
NS_ASSERTION(ds, "null ptr");
NS_ASSERTION(alt, "null ptr");
nsresult rv;
nsIRDFNode* bag = nsnull;
result = nsnull; // reasonable default
// XXX check to see if someone else has already made this into a container.
if (NS_FAILED(rv = rdf_CreateAnonymousNode(mgr, bag)))
goto done;
if (NS_FAILED(rv = rdf_Assert(mgr, ds, alt, kURIRDF_instanceOf, kURIRDF_Alt)))
return rv;
if (NS_FAILED(rv = rdf_Assert(mgr, ds, bag, kURIRDF_instanceOf, kURIRDF_Alt)))
goto done;
if (NS_FAILED(rv = rdf_Assert(mgr, ds, alt, kURIRDF_nextVal, "1")))
return rv;
if (NS_FAILED(rv = rdf_Assert(mgr, ds, bag, kURIRDF_nextVal, "1")))
goto done;
result = bag;
NS_ADDREF(result);
done:
NS_IF_RELEASE(bag);
return rv;
return NS_OK;
}
static nsresult
rdf_ContainerGetNextValue(nsIRDFResourceManager* mgr,
nsIRDFDataSource* ds,
nsIRDFNode* container,
PRInt32& result)
nsIRDFResource* container,
nsIRDFResource** result)
{
NS_ASSERTION(mgr, "null ptr");
NS_ASSERTION(ds, "null ptr");
NS_ASSERTION(container, "null ptr");
nsresult rv;
nsIRDFNode* nextValProperty = nsnull;
nsIRDFNode* nextValResource = nsnull;
nsAutoString nextVal;
nsIRDFResource* RDF_nextVal = nsnull;
nsIRDFNode* nextValNode = nsnull;
nsIRDFLiteral* nextValLiteral = nsnull;
const PRUnichar* s;
nsAutoString nextValStr;
PRInt32 nextVal;
PRInt32 err;
if (NS_FAILED(rv = mgr->GetNode(kURIRDF_nextVal, nextValProperty)))
// Get the next value, which hangs off of the bag via the
// RDF:nextVal property.
if (NS_FAILED(rv = mgr->GetResource(kURIRDF_nextVal, &RDF_nextVal)))
goto done;
if (NS_FAILED(rv = ds->GetTarget(container, nextValProperty, PR_TRUE, nextValResource)))
if (NS_FAILED(rv = ds->GetTarget(container, RDF_nextVal, PR_TRUE, &nextValNode)))
goto done;
if (NS_FAILED(rv = nextValResource->GetStringValue(nextVal)))
if (NS_FAILED(rv = nextValNode->QueryInterface(kIRDFLiteralIID, (void**) &nextValLiteral)))
goto done;
result = nextVal.ToInteger(&err);
if (NS_FAILED(rv = nextValLiteral->GetValue(&s)))
goto done;
nextValStr = s;
nextVal = nextValStr.ToInteger(&err);
if (NS_FAILED(err))
goto done;
if (NS_FAILED(rv = ds->Unassert(container, nextValProperty, nextValResource)))
// Generate a URI that we can return.
nextValStr = kRDFNameSpaceURI;
nextValStr.Append("_");
nextValStr.Append(nextVal, 10);
if (NS_FAILED(rv = mgr->GetUnicodeResource(nextValStr, result)))
goto done;
nextVal.Truncate();
nextVal.Append(result + 1, 10);
// Now increment the RDF:nextVal property.
if (NS_FAILED(rv = ds->Unassert(container, RDF_nextVal, nextValLiteral)))
goto done;
if (NS_FAILED(rv = rdf_Assert(mgr, ds, container, nextValProperty, nextVal)))
NS_RELEASE(nextValLiteral);
++nextVal;
nextValStr.Truncate();
nextValStr.Append(nextVal, 10);
if (NS_FAILED(rv = mgr->GetLiteral(nextValStr, &nextValLiteral)))
goto done;
if (NS_FAILED(rv = rdf_Assert(mgr, ds, container, RDF_nextVal, nextValLiteral)))
goto done;
done:
NS_IF_RELEASE(nextValResource);
NS_IF_RELEASE(nextValProperty);
NS_IF_RELEASE(nextValLiteral);
NS_IF_RELEASE(nextValNode);
NS_IF_RELEASE(RDF_nextVal);
return rv;
}
@@ -442,7 +470,7 @@ done:
nsresult
rdf_ContainerAddElement(nsIRDFResourceManager* mgr,
nsIRDFDataSource* ds,
nsIRDFNode* container,
nsIRDFResource* container,
nsIRDFNode* element)
{
NS_ASSERTION(mgr, "null ptr");
@@ -452,17 +480,12 @@ rdf_ContainerAddElement(nsIRDFResourceManager* mgr,
nsresult rv;
PRInt32 nextVal;
nsAutoString uri;
nsIRDFResource* nextVal;
if (NS_FAILED(rv = rdf_ContainerGetNextValue(mgr, ds, container, nextVal)))
if (NS_FAILED(rv = rdf_ContainerGetNextValue(mgr, ds, container, &nextVal)))
goto done;
uri = kRDFNameSpaceURI;
uri.Append("_");
uri.Append(nextVal, 10);
if (rv = rdf_Assert(mgr, ds, container, uri, element))
if (rv = rdf_Assert(mgr, ds, container, nextVal, element))
goto done;
done:
@@ -471,51 +494,3 @@ done:
nsresult
rdf_ContainerAddElement(nsIRDFResourceManager* mgr,
nsIRDFDataSource* ds,
nsIRDFNode* container,
const nsString& literalOrURI)
{
NS_ASSERTION(mgr, "null ptr");
NS_ASSERTION(ds, "null ptr");
NS_ASSERTION(container, "null ptr");
nsresult rv;
nsIRDFNode* node;
if (NS_FAILED(rv = mgr->GetNode(literalOrURI, node)))
goto done;
if (NS_FAILED(rv = rdf_ContainerAddElement(mgr, ds, container, node)))
goto done;
done:
NS_IF_RELEASE(node);
return rv;
}
PRBool
rdf_ResourceEquals(nsIRDFResourceManager* mgr,
nsIRDFNode* resource,
const nsString& uri)
{
NS_ASSERTION(mgr, "null ptr");
NS_ASSERTION(resource, "null ptr");
PRBool result = PR_FALSE;
nsresult rv;
nsIRDFNode* that = nsnull;
if (NS_FAILED(rv = mgr->GetNode(uri, that)))
goto done;
result = (that == resource);
done:
NS_IF_RELEASE(that);
return result;
}

View File

@@ -23,6 +23,7 @@
#include "prtypes.h"
class nsIRDFCursor;
class nsIRDFCursor2;
class nsIRDFDataBase;
class nsIRDFDataSource;
class nsIRDFNode;
@@ -34,7 +35,7 @@ class nsString;
* rdf:_2, etc.
*/
PRBool
rdf_IsOrdinalProperty(const nsIRDFNode* property);
rdf_IsOrdinalProperty(const nsIRDFResource* property);
/**
@@ -44,13 +45,7 @@ rdf_IsOrdinalProperty(const nsIRDFNode* property);
PRBool
rdf_IsContainer(nsIRDFResourceManager* mgr,
nsIRDFDataSource* db,
nsIRDFNode* resource);
/**
* Tries to guess whether the specified node is a resource or a literal.
*/
PRBool
rdf_IsResource(nsIRDFNode* node);
nsIRDFResource* resource);
/**
@@ -59,9 +54,10 @@ rdf_IsResource(nsIRDFNode* node);
// 0. node, node, node
nsresult
rdf_Assert(nsIRDFDataSource* ds,
nsIRDFNode* subject,
nsIRDFNode* predicate,
rdf_Assert(nsIRDFResourceManager* mgr, // unused
nsIRDFDataSource* ds,
nsIRDFResource* subject,
nsIRDFResource* predicate,
nsIRDFNode* object);
// 1. string, string, string
@@ -76,15 +72,15 @@ rdf_Assert(nsIRDFResourceManager* mgr,
nsresult
rdf_Assert(nsIRDFResourceManager* mgr,
nsIRDFDataSource* ds,
nsIRDFNode* subject,
nsIRDFNode* predicate,
nsIRDFResource* subject,
nsIRDFResource* predicate,
const nsString& objectURI);
// 3. node, string, string
nsresult
rdf_Assert(nsIRDFResourceManager* mgr,
nsIRDFDataSource* ds,
nsIRDFNode* subject,
nsIRDFResource* subject,
const nsString& predicateURI,
const nsString& objectURI);
@@ -92,7 +88,7 @@ rdf_Assert(nsIRDFResourceManager* mgr,
nsresult
rdf_Assert(nsIRDFResourceManager* mgr,
nsIRDFDataSource* ds,
nsIRDFNode* subject,
nsIRDFResource* subject,
const nsString& predicateURI,
nsIRDFNode* object);
@@ -109,33 +105,33 @@ rdf_Assert(nsIRDFResourceManager* mgr,
* resource URI.
*/
nsresult
rdf_CreateAnonymousNode(nsIRDFResourceManager* mgr,
nsIRDFNode*& result);
rdf_CreateAnonymousResource(nsIRDFResourceManager* mgr,
nsIRDFResource** result);
/**
* Create a bag resource.
*/
nsresult
rdf_CreateBag(nsIRDFResourceManager* mgr,
nsIRDFDataSource* ds,
nsIRDFNode*& result);
rdf_MakeBag(nsIRDFResourceManager* mgr,
nsIRDFDataSource* ds,
nsIRDFResource* resource);
/**
* Create a sequence resource.
*/
nsresult
rdf_CreateSequence(nsIRDFResourceManager* mgr,
nsIRDFDataSource* ds,
nsIRDFNode*& result);
rdf_MakeSeq(nsIRDFResourceManager* mgr,
nsIRDFDataSource* ds,
nsIRDFResource* resource);
/**
* Create an alternation resource.
*/
nsresult
rdf_CreateAlternation(nsIRDFResourceManager* mgr,
nsIRDFDataSource* ds,
nsIRDFNode*& result);
rdf_MakeAlt(nsIRDFResourceManager* mgr,
nsIRDFDataSource* ds,
nsIRDFResource* resource);
/**
@@ -144,35 +140,25 @@ rdf_CreateAlternation(nsIRDFResourceManager* mgr,
nsresult
rdf_ContainerAddElement(nsIRDFResourceManager* mgr,
nsIRDFDataSource* ds,
nsIRDFNode* container,
nsIRDFResource* container,
nsIRDFNode* element);
/**
* Add an element to the container.
*/
nsresult
rdf_ContainerAddElement(nsIRDFResourceManager* mgr,
nsIRDFDataSource* ds,
nsIRDFNode* container,
const nsString& literalOrURI);
/**
* Return <tt>PR_TRUE</tt> if the specified resources are equal.
*/
PRBool
rdf_ResourceEquals(nsIRDFResourceManager* mgr,
nsIRDFNode* resource,
const nsString& uri);
/**
* Create a cursor on a container that enumerates its contents in
* order
*/
nsresult
NS_NewContainerCursor(nsIRDFDataSource* ds,
nsIRDFNode* container,
nsIRDFCursor*& cursor);
nsIRDFResource* container,
nsIRDFCursor** cursor);
/**
* Create an empty nsIRDFCursor. This will *never* fail, and will *always*
* return the same object.
*/
nsresult
NS_NewEmptyRDFCursor(nsIRDFCursor** result);
// XXX need to move nsEmptyCursor stuff here.