зеркало из https://github.com/mozilla/gecko-dev.git
Initial revision. Separated from mozilla/rdf/include. Not yet in the build.
This commit is contained in:
Родитель
256513d2fb
Коммит
6a227c1d03
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,29 @@
|
|||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH = ../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = public src
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
|
@ -0,0 +1,27 @@
|
|||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=../..
|
||||
|
||||
MODULE = rdf
|
||||
|
||||
DIRS=\
|
||||
public \
|
||||
src \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
|
@ -0,0 +1,9 @@
|
|||
rdf.h
|
||||
nsIRDFCursor.h
|
||||
nsIRDFDataBase.h
|
||||
nsIRDFDataSource.h
|
||||
nsIRDFNode.h
|
||||
nsIRDFObserver.h
|
||||
nsIRDFResourceManager.h
|
||||
nsIRDFXMLSource.h
|
||||
nsRDFBaseCID.h
|
|
@ -0,0 +1,43 @@
|
|||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = rdf
|
||||
|
||||
EXPORTS = \
|
||||
rdf.h \
|
||||
nsIRDFCursor.h \
|
||||
nsIRDFDataBase.h \
|
||||
nsIRDFDataSource.h \
|
||||
nsIRDFNode.h \
|
||||
nsIRDFObserver.h \
|
||||
nsIRDFResourceManager.h \
|
||||
nsIRDFXMLSource.h \
|
||||
nsRDFBaseCID.h \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
|
@ -0,0 +1,37 @@
|
|||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
|
||||
|
||||
MODULE=rdf
|
||||
|
||||
DEPTH=..\..\..
|
||||
|
||||
EXPORTS=\
|
||||
rdf.h \
|
||||
nsIRDFCursor.h \
|
||||
nsIRDFDataBase.h \
|
||||
nsIRDFDataSource.h \
|
||||
nsIRDFNode.h \
|
||||
nsIRDFObserver.h \
|
||||
nsIRDFResourceManager.h \
|
||||
nsIRDFXMLSource.h \
|
||||
nsRDFBaseCID.h \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)/config/rules.mak>
|
||||
|
|
@ -0,0 +1,166 @@
|
|||
/* -*- 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 nsIRDFCursor_h__
|
||||
#define nsIRDFCursor_h__
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "prtypes.h"
|
||||
#include "rdf.h" // for error codes
|
||||
class nsIRDFDataSource;
|
||||
class nsIRDFNode;
|
||||
class nsIRDFResource;
|
||||
|
||||
// 1c2abdb0-4cef-11d2-bc16-00805f912fe7
|
||||
#define NS_IRDFCURSOR_IID \
|
||||
{ 0x1c2abdb0, 0x4cef, 0x11d2, { 0xbc, 0x16, 0x00, 0x80, 0x5f, 0x91, 0x2f, 0xe7 } }
|
||||
|
||||
/**
|
||||
* An abstract base interface that is the basis for all RDF cursors.
|
||||
*/
|
||||
class nsIRDFCursor : public nsISupports {
|
||||
public:
|
||||
/**
|
||||
* Advance the cursor to the next element.
|
||||
* @return NS_ERROR_RDF_CURSOR_EMPTY if the cursor has reached the end
|
||||
* and there are no more elements to enumerate; otherwise, NS_OK
|
||||
* unless a catastrophic error occurs.
|
||||
*/
|
||||
NS_IMETHOD Advance(void) = 0;
|
||||
};
|
||||
|
||||
|
||||
// {1ED57100-9904-11d2-8EBA-00805F29F370}
|
||||
#define NS_IRDFASSERTIONCURSOR_IID \
|
||||
{ 0x1ed57100, 0x9904, 0x11d2, { 0x8e, 0xba, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
|
||||
|
||||
/**
|
||||
* A cursor that enumerates assertions
|
||||
* @seealso nsIRDFDataSource::GetTargetS(), nsIRDFDataSource::GetSources()
|
||||
*/
|
||||
class nsIRDFAssertionCursor : public nsIRDFCursor {
|
||||
public:
|
||||
/**
|
||||
* Retrieve the data source in which the assertion actually
|
||||
* lives.
|
||||
* XXX Is it dangerous to be exposing naked data sources like this?
|
||||
* @return NS_OK, unless a catastrophic error occurs.
|
||||
*/
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource) = 0;
|
||||
|
||||
/**
|
||||
* Retrieve the assertion's subject resource.
|
||||
* @return NS_OK, unless a catastrophic error occurs.
|
||||
*/
|
||||
NS_IMETHOD GetSubject(nsIRDFResource** aSubject) = 0;
|
||||
|
||||
/**
|
||||
* Retrieve the assertion's predicate resource.
|
||||
* @return NS_OK, unless a catastrophic error occurs.
|
||||
*/
|
||||
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate) = 0;
|
||||
|
||||
/**
|
||||
* Retrieve the assertion's object node.
|
||||
* @return NS_OK, unless a catastrophic error occurs.
|
||||
*/
|
||||
NS_IMETHOD GetObject(nsIRDFNode** aObject) = 0;
|
||||
|
||||
/**
|
||||
* Retrieve the assertion's truth value.
|
||||
* @return NS_OK, unless a catastrophic error occurs.
|
||||
*/
|
||||
NS_IMETHOD GetTruthValue(PRBool* aTruthValue) = 0;
|
||||
};
|
||||
|
||||
|
||||
// {1ED57101-9904-11d2-8EBA-00805F29F370}
|
||||
#define NS_IRDFARCSOUTCURSOR_IID \
|
||||
{ 0x1ed57101, 0x9904, 0x11d2, { 0x8e, 0xba, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
|
||||
|
||||
/**
|
||||
* A cursor that enumerates the outbound arcs from a resource node.
|
||||
* @seealso nsIRDFDataSource::ArcsOut()
|
||||
*/
|
||||
class nsIRDFArcsOutCursor : public nsIRDFCursor {
|
||||
public:
|
||||
/**
|
||||
* Retrieve the data source in which the arc is stored.
|
||||
* XXX Is it dangerous to be exposing naked data sources like this?
|
||||
* @return NS_OK, unless a catastrophic error occurs.
|
||||
*/
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource) = 0;
|
||||
|
||||
/**
|
||||
* Retrieve the "subject" node from which the arcs originate.
|
||||
* @return NS_OK, unless a catastrophic error occurs.
|
||||
*/
|
||||
NS_IMETHOD GetSubject(nsIRDFResource** aSubject) = 0;
|
||||
|
||||
/**
|
||||
* Retrieve the predicate label of the arc.
|
||||
* @return NS_OK, unless a catastrophic error occurs.
|
||||
*/
|
||||
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate) = 0;
|
||||
|
||||
/**
|
||||
* Retrieve the truth value of the arc.
|
||||
* @return NS_OK, unless a catastrophic error occurs.
|
||||
*/
|
||||
NS_IMETHOD GetTruthValue(PRBool* aTruthValue) = 0;
|
||||
};
|
||||
|
||||
|
||||
// {1ED57102-9904-11d2-8EBA-00805F29F370}
|
||||
#define NS_IRDFARCSINCURSOR_IID \
|
||||
{ 0x1ed57102, 0x9904, 0x11d2, { 0x8e, 0xba, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
|
||||
|
||||
/**
|
||||
* A cursor that enumerates the inbound arcs to a node.
|
||||
* @seealso nsIRDFDataSource::ArcsIn()
|
||||
*/
|
||||
class nsIRDFArcsInCursor : public nsIRDFCursor {
|
||||
public:
|
||||
/**
|
||||
* Retrieve the data source in which the arc is stored.
|
||||
* XXX Is it dangerous to be exposing naked data sources like this?
|
||||
* @return NS_OK, unless a catastrophic error occurs.
|
||||
*/
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource) = 0;
|
||||
|
||||
/**
|
||||
* Retrieve the "object" node in which the arc terminates.
|
||||
* @return NS_OK, unless a catastrophic error occurs.
|
||||
*/
|
||||
NS_IMETHOD GetObject(nsIRDFNode** aObject) = 0;
|
||||
|
||||
/**
|
||||
* Retrieve the predicate label of the arc
|
||||
* @return NS_OK, unless a catastrophic error occurs.
|
||||
*/
|
||||
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate) = 0;
|
||||
|
||||
/**
|
||||
* Retrieve the truth value of the arc.
|
||||
* @return NS_OK, unless a catastrophic error occurs.
|
||||
*/
|
||||
NS_IMETHOD GetTruthValue(PRBool* aTruthValue) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif /* nsIRDFCursor_h__ */
|
|
@ -0,0 +1,49 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "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 nsIRDFDataBase_h__
|
||||
#define nsIRDFDataBase_h__
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
|
||||
class nsIRDFDataSource;
|
||||
|
||||
// 96343820-307c-11d2-bc15-00805f912fe7
|
||||
#define NS_IRDFDATABASE_IID \
|
||||
{ 0x96343820, 0x307c, 0x11d2, { 0xb, 0x15, 0x00, 0x80, 0x5f, 0x91, 0x2f, 0xe7 } }
|
||||
|
||||
/**
|
||||
* An <tt>nsIRDFDataBase</tt> composes individual data sources, providing
|
||||
* the illusion of a single, coherent RDF graph.
|
||||
*/
|
||||
class nsIRDFDataBase : public nsIRDFDataSource {
|
||||
public:
|
||||
/**
|
||||
* Add a datasource the the database.
|
||||
*/
|
||||
NS_IMETHOD AddDataSource(nsIRDFDataSource* source) = 0;
|
||||
|
||||
/**
|
||||
* Remove a datasource from the database
|
||||
*/
|
||||
NS_IMETHOD RemoveDataSource(nsIRDFDataSource* source) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif /* nsIRDFDataBase_h__ */
|
|
@ -0,0 +1,170 @@
|
|||
/* -*- 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 nsIRDFDataSource_h__
|
||||
#define nsIRDFDataSource_h__
|
||||
|
||||
#include "nsISupports.h"
|
||||
|
||||
// {0F78DA58-8321-11d2-8EAC-00805F29F370}
|
||||
#define NS_IRDFDATASOURCE_IID \
|
||||
{ 0xf78da58, 0x8321, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
|
||||
|
||||
class nsIRDFAssertionCursor;
|
||||
class nsIRDFArcsInCursor;
|
||||
class nsIRDFArcsOutCursor;
|
||||
class nsIRDFDataBase;
|
||||
class nsIRDFNode;
|
||||
class nsIRDFObserver;
|
||||
class nsIRDFResource;
|
||||
|
||||
/**
|
||||
* 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 char* uri) = 0;
|
||||
|
||||
/**
|
||||
* Find an RDF resource that points to a given node over the
|
||||
* specified arc & truth value
|
||||
*
|
||||
* @return NS_ERROR_FAILURE if there is no source that leads
|
||||
* to the target with the specified property.
|
||||
*/
|
||||
NS_IMETHOD GetSource(nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
PRBool tv,
|
||||
nsIRDFResource** source /* out */) = 0;
|
||||
|
||||
/**
|
||||
* Find all RDF resources that point to a given node over the
|
||||
* specified arc & truth value
|
||||
*
|
||||
* @return NS_OK unless a catastrophic error occurs. If the
|
||||
* method returns NS_OK, you may assume that nsIRDFCursor points
|
||||
* to a valid (but possibly empty) cursor.
|
||||
*/
|
||||
NS_IMETHOD GetSources(nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor** sources /* out */) = 0;
|
||||
|
||||
/**
|
||||
* Find a child of that is related to the source by the given arc
|
||||
* arc and truth value
|
||||
*
|
||||
* @return NS_ERROR_FAILURE if there is no target accessable from the
|
||||
* source via the specified property.
|
||||
*/
|
||||
NS_IMETHOD GetTarget(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
PRBool tv,
|
||||
nsIRDFNode** target /* out */) = 0;
|
||||
|
||||
/**
|
||||
* Find all children of that are related to the source by the given arc
|
||||
* arc and truth value.
|
||||
*
|
||||
* @return NS_OK unless a catastrophic error occurs. If the
|
||||
* method returns NS_OK, you may assume that nsIRDFCursor points
|
||||
* to a valid (but possibly empty) cursor.
|
||||
*/
|
||||
NS_IMETHOD GetTargets(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor** targets /* out */) = 0;
|
||||
|
||||
/**
|
||||
* Add an assertion to the graph.
|
||||
*/
|
||||
NS_IMETHOD Assert(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
PRBool tv) = 0;
|
||||
|
||||
/**
|
||||
* Remove an assertion from the graph.
|
||||
*/
|
||||
NS_IMETHOD Unassert(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
nsIRDFNode* target) = 0;
|
||||
|
||||
/**
|
||||
* Query whether an assertion exists in this graph.
|
||||
*
|
||||
* @return NS_OK unless a catastrophic error occurs.
|
||||
*/
|
||||
NS_IMETHOD HasAssertion(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
PRBool tv,
|
||||
PRBool* hasAssertion /* out */) = 0;
|
||||
|
||||
/**
|
||||
* Add an observer to this data source.
|
||||
*/
|
||||
NS_IMETHOD AddObserver(nsIRDFObserver* n) = 0;
|
||||
|
||||
/**
|
||||
* Remove an observer from this data source
|
||||
*/
|
||||
NS_IMETHOD RemoveObserver(nsIRDFObserver* n) = 0;
|
||||
|
||||
// XXX individual resource observers?
|
||||
|
||||
/**
|
||||
* Get a cursor to iterate over all the arcs that point into a node.
|
||||
*
|
||||
* @return NS_OK unless a catastrophic error occurs. If the method
|
||||
* returns NS_OK, you may assume that labels points to a valid (but
|
||||
* possible empty) nsIRDFCursor object.
|
||||
*/
|
||||
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
|
||||
nsIRDFArcsInCursor** labels /* out */) = 0;
|
||||
|
||||
/**
|
||||
* Get a cursor to iterate over all the arcs that originate in
|
||||
* a resource.
|
||||
*
|
||||
* @return NS_OK unless a catastrophic error occurs. If the method
|
||||
* returns NS_OK, you may assume that labels points to a valid (but
|
||||
* possible empty) nsIRDFCursor object.
|
||||
*/
|
||||
NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
|
||||
nsIRDFArcsOutCursor** labels /* out */) = 0;
|
||||
|
||||
/**
|
||||
* Request that a data source write it's contents out to
|
||||
* permanent storage if applicable.
|
||||
*/
|
||||
NS_IMETHOD Flush() = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsIRDFDataSource_h__ */
|
|
@ -0,0 +1,97 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsIRDFNode_h__
|
||||
#define nsIRDFNode_h__
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
// {0F78DA50-8321-11d2-8EAC-00805F29F370}
|
||||
#define NS_IRDFNODE_IID \
|
||||
{ 0xf78da50, 0x8321, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
|
||||
|
||||
/**
|
||||
*
|
||||
* Nodes are created using an instance of 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:
|
||||
/**
|
||||
* Determine if two nodes are identical
|
||||
*/
|
||||
NS_IMETHOD EqualsNode(nsIRDFNode* that, PRBool* result) 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 EqualsLiteral(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__
|
|
@ -0,0 +1,54 @@
|
|||
/* -*- 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 nsIRDFObserver_h__
|
||||
#define nsIRDFObserver_h__
|
||||
|
||||
#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 } }
|
||||
|
||||
#endif /* nsIRDFObserver_h__ */
|
|
@ -0,0 +1,60 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsIRDFResourceManager_h__
|
||||
#define nsIRDFResourceManager_h__
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
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 } }
|
||||
|
||||
|
||||
extern nsresult
|
||||
NS_NewRDFResourceManager(nsIRDFResourceManager** result);
|
||||
|
||||
#endif // nsIRDFResourceManager_h__
|
|
@ -0,0 +1,35 @@
|
|||
/* -*- 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 nsIRDFXMLSource_h__
|
||||
#define nsIRDFXMLSource_h__
|
||||
|
||||
class nsIOutputStream;
|
||||
|
||||
// {4DA56F10-99FE-11d2-8EBB-00805F29F370}
|
||||
#define NS_IRDFXMLSOURCE_IID \
|
||||
{ 0x4da56f10, 0x99fe, 0x11d2, { 0x8e, 0xbb, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
|
||||
|
||||
|
||||
class nsIRDFXMLSource : public nsISupports
|
||||
{
|
||||
public:
|
||||
NS_IMETHOD Serialize(nsIOutputStream* stream) = 0;
|
||||
};
|
||||
|
||||
#endif // nsIRDFXMLSource_h__
|
|
@ -0,0 +1,47 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "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 nsRDFBaseCID_h__
|
||||
#define nsRDFBaseCID_h__
|
||||
|
||||
// {0F78DA56-8321-11d2-8EAC-00805F29F370}
|
||||
#define NS_RDFNODE_CID \
|
||||
{ 0xf78da56, 0x8321, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
|
||||
|
||||
// {BFD05264-834C-11d2-8EAC-00805F29F370}
|
||||
#define NS_RDFRESOURCEMANAGER_CID \
|
||||
{ 0xbfd05264, 0x834c, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
|
||||
|
||||
// {BFD0526D-834C-11d2-8EAC-00805F29F370}
|
||||
#define NS_RDFMEMORYDATASOURCE_CID \
|
||||
{ 0xbfd0526d, 0x834c, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
|
||||
|
||||
// {E638D761-8687-11d2-B530-000000000000}
|
||||
#define NS_RDFSIMPLEDATABASE_CID \
|
||||
{ 0xe638d761, 0x8687, 0x11d2, { 0xb5, 0x30, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
|
||||
|
||||
// {7BAF62E0-8E61-11d2-8EB1-00805F29F370}
|
||||
#define NS_RDFSTREAMDATASOURCE_CID \
|
||||
{ 0x7baf62e0, 0x8e61, 0x11d2, { 0x8e, 0xb1, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
|
||||
|
||||
// {0958B100-9ADA-11d2-8EBC-00805F29F370}
|
||||
#define NS_RDFCONTENTSINK_CID \
|
||||
{ 0x958b100, 0x9ada, 0x11d2, { 0x8e, 0xbc, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
|
||||
|
||||
|
||||
#endif // nsRDFBaseCID_h__
|
|
@ -0,0 +1,57 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef rdf_h___
|
||||
#define rdf_h___
|
||||
|
||||
#include "nsError.h"
|
||||
|
||||
/*
|
||||
* The following macros are to aid in vocabulary definition.
|
||||
* They creates const char*'s for "kURI[prefix]_[name]" and
|
||||
* "kTag[prefix]_[name]", with appropriate complete namespace
|
||||
* qualification on the URI, e.g.,
|
||||
*
|
||||
* #define RDF_NAMESPACE_URI "http://www.w3.org/TR/WD-rdf-syntax#"
|
||||
* DEFINE_RDF_ELEMENT(RDF_NAMESPACE_URI, RDF, ID);
|
||||
*
|
||||
* will define:
|
||||
*
|
||||
* kURIRDF_ID to be "http://www.w3.org/TR/WD-rdf-syntax#ID", and
|
||||
* kTagRDF_ID to be "ID"
|
||||
*/
|
||||
|
||||
#define DEFINE_RDF_VOCAB(namespace, prefix, name) \
|
||||
static const char* kURI##prefix##_##name = ##namespace #name ;\
|
||||
static const char* kTag##prefix##_##name = kURI##prefix##_##name## + sizeof(##namespace) - 1
|
||||
|
||||
|
||||
/**
|
||||
* @name Standard RDF error codes
|
||||
*/
|
||||
|
||||
/*@{*/
|
||||
|
||||
/* Returned from nsIRDFCursor::Advance() if the cursor has no more
|
||||
elements to enuemrate */
|
||||
#define NS_ERROR_RDF_CURSOR_EMPTY NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_RDF, 1)
|
||||
|
||||
/*@}*/
|
||||
|
||||
#endif /* rdf_h___ */
|
|
@ -0,0 +1,57 @@
|
|||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
LIBRARY_NAME = rdfbase
|
||||
|
||||
CPPSRCS = \
|
||||
nsContainerCursor.cpp \
|
||||
nsEmptyCursor.cpp \
|
||||
nsMemoryDataSource.cpp \
|
||||
nsRDFBaseFactory.cpp \
|
||||
nsRDFResourceManager.cpp \
|
||||
nsSimpleDataBase.cpp \
|
||||
rdfutil.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
||||
|
||||
MODULE = rdfbase
|
||||
|
||||
REQUIRES = dom js netlib rdf raptor xpcom
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
|
||||
export::
|
||||
|
||||
install:: $(TARGETS)
|
||||
|
||||
|
||||
clobber::
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..\..\..
|
||||
MODULE=rdfbase
|
||||
|
||||
MAKE_OBJ_TYPE=DLL
|
||||
DLLNAME=$(MODULE)
|
||||
DLL=.\$(OBJDIR)\$(DLLNAME).dll
|
||||
|
||||
CPP_OBJS=\
|
||||
.\$(OBJDIR)\nsContainerCursor.obj \
|
||||
.\$(OBJDIR)\nsEmptyCursor.obj \
|
||||
.\$(OBJDIR)\nsMemoryDataSource.obj \
|
||||
.\$(OBJDIR)\nsRDFBaseFactory.obj \
|
||||
.\$(OBJDIR)\nsRDFResourceManager.obj \
|
||||
.\$(OBJDIR)\nsSimpleDataBase.obj \
|
||||
.\$(OBJDIR)\rdfutil.obj \
|
||||
$(NULL)
|
||||
|
||||
LLIBS=\
|
||||
$(DIST)\lib\xpcom32.lib \
|
||||
$(DIST)\lib\raptorbase.lib \
|
||||
$(DIST)\lib\libplc21.lib \
|
||||
$(LIBNSPR)
|
||||
|
||||
LINCS= -I$(PUBLIC)\rdf \
|
||||
-I$(PUBLIC)\xpcom \
|
||||
-I$(PUBLIC)\netlib \
|
||||
-I$(PUBLIC)\raptor \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(DLL)
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,298 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFResourceManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsRDFBaseCID.h"
|
||||
#include "nsString.h"
|
||||
#include "prlog.h"
|
||||
#include "rdf.h"
|
||||
#include "rdfutil.h"
|
||||
|
||||
/*
|
||||
|
||||
A simple cursor that enumerates the elements of a container.
|
||||
|
||||
Caveats
|
||||
-------
|
||||
|
||||
1. This uses an implementation-specific detail to determine the
|
||||
index of the last element in the container; specifically, the RDF
|
||||
utilities maintain a counter attribute on the container that
|
||||
holds the numeric value of the next value that is to be
|
||||
assigned. So, this cursor will bust if you use it with a bag that
|
||||
hasn't been created using the RDF utility routines.
|
||||
|
||||
2. This is sort of a continuation of (1), but -- it's not smart
|
||||
enough to notice duplicates.
|
||||
|
||||
TODO. This is way too brain dead to handle aggregated RDF
|
||||
databases. It needs to be upgraded in a big way.
|
||||
|
||||
*/
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_IID(kIRDFAssertionCursorIID, NS_IRDFASSERTIONCURSOR_IID);
|
||||
static NS_DEFINE_IID(kIRDFCursorIID, NS_IRDFCURSOR_IID);
|
||||
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
|
||||
static NS_DEFINE_IID(kIRDFResourceManagerIID, NS_IRDFRESOURCEMANAGER_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
static NS_DEFINE_CID(kRDFResourceManagerCID, NS_RDFRESOURCEMANAGER_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define RDF_NAMESPACE_URI "http://www.w3.org/TR/WD-rdf-syntax#"
|
||||
static const char kRDFNameSpaceURI[] = RDF_NAMESPACE_URI;
|
||||
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, nextVal); // ad hoc way to make containers fast
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ContainerCursorImpl : public nsIRDFAssertionCursor {
|
||||
private:
|
||||
nsIRDFResourceManager* mResourceMgr;
|
||||
nsIRDFDataSource* mDataSource;
|
||||
nsIRDFResource* mContainer;
|
||||
nsIRDFNode* mNext;
|
||||
PRInt32 mCounter;
|
||||
|
||||
public:
|
||||
ContainerCursorImpl(nsIRDFDataSource* ds, nsIRDFResource* container);
|
||||
virtual ~ContainerCursorImpl(void);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD Advance(void);
|
||||
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource);
|
||||
NS_IMETHOD GetSubject(nsIRDFResource** aResource);
|
||||
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate);
|
||||
NS_IMETHOD GetObject(nsIRDFNode** aObject);
|
||||
NS_IMETHOD GetTruthValue(PRBool* aTruthValue);
|
||||
};
|
||||
|
||||
ContainerCursorImpl::ContainerCursorImpl(nsIRDFDataSource* ds,
|
||||
nsIRDFResource* container)
|
||||
: mDataSource(ds), mContainer(container), mNext(nsnull), mCounter(1)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_IF_ADDREF(mDataSource);
|
||||
NS_IF_ADDREF(mContainer);
|
||||
|
||||
nsresult rv;
|
||||
rv = nsServiceManager::GetService(kRDFResourceManagerCID,
|
||||
kIRDFResourceManagerIID,
|
||||
(nsISupports**) &mResourceMgr);
|
||||
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to acquire resource manager");
|
||||
|
||||
NS_ASSERTION(rdf_IsContainer(mResourceMgr, mDataSource, container), "not a container");
|
||||
}
|
||||
|
||||
|
||||
ContainerCursorImpl::~ContainerCursorImpl(void)
|
||||
{
|
||||
NS_IF_RELEASE(mNext);
|
||||
|
||||
if (mResourceMgr)
|
||||
nsServiceManager::ReleaseService(kRDFResourceManagerCID, mResourceMgr);
|
||||
|
||||
NS_IF_RELEASE(mContainer);
|
||||
NS_IF_RELEASE(mDataSource);
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(ContainerCursorImpl);
|
||||
NS_IMPL_RELEASE(ContainerCursorImpl);
|
||||
|
||||
NS_IMETHODIMP_(nsresult)
|
||||
ContainerCursorImpl::QueryInterface(REFNSIID iid, void** result) {
|
||||
if (! result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (iid.Equals(kIRDFAssertionCursorIID) ||
|
||||
iid.Equals(kIRDFCursorIID) ||
|
||||
iid.Equals(kISupportsIID)) {
|
||||
*result = NS_STATIC_CAST(nsIRDFAssertionCursor*, this);
|
||||
/* AddRef(); // not necessary */
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
ContainerCursorImpl::Advance(void)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// release the last value that we were holding
|
||||
NS_IF_RELEASE(mNext);
|
||||
|
||||
nsIRDFResource* RDF_nextVal = nsnull;
|
||||
nsIRDFNode* nextNode = nsnull;
|
||||
nsIRDFLiteral* nextVal = nsnull;
|
||||
const PRUnichar* p;
|
||||
nsAutoString s;
|
||||
PRInt32 last;
|
||||
PRInt32 err;
|
||||
|
||||
// XXX we could cache all this crap when the cursor gets created.
|
||||
if (NS_FAILED(rv = mResourceMgr->GetResource(kURIRDF_nextVal, &RDF_nextVal)))
|
||||
goto done;
|
||||
|
||||
if (NS_FAILED(rv = mDataSource->GetTarget(mContainer, RDF_nextVal, PR_TRUE, &nextNode)))
|
||||
goto done;
|
||||
|
||||
if (NS_FAILED(rv = nextNode->QueryInterface(kIRDFLiteralIID, (void**) &nextVal)))
|
||||
goto done;
|
||||
|
||||
if (NS_FAILED(rv = nextVal->GetValue(&p)))
|
||||
goto done;
|
||||
|
||||
s = p;
|
||||
last = s.ToInteger(&err);
|
||||
if (NS_FAILED(err))
|
||||
goto done;
|
||||
|
||||
// initialize rv to the case where mCounter has advanced past the
|
||||
// last element
|
||||
rv = NS_ERROR_RDF_CURSOR_EMPTY;
|
||||
|
||||
while (mCounter < last) {
|
||||
nsIRDFResource* ordinalProperty = nsnull;
|
||||
if (NS_FAILED(rv = GetPredicate(&ordinalProperty)))
|
||||
break;
|
||||
|
||||
rv = mDataSource->GetTarget(mContainer, ordinalProperty, PR_TRUE, &mNext);
|
||||
NS_IF_RELEASE(ordinalProperty);
|
||||
|
||||
++mCounter;
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// Don't bother releasing mNext; we'll let the AddRef
|
||||
// serve as the implicit addref that GetNext() should
|
||||
// perform.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
NS_IF_RELEASE(nextNode);
|
||||
NS_IF_RELEASE(nextVal);
|
||||
NS_IF_RELEASE(RDF_nextVal);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
ContainerCursorImpl::GetDataSource(nsIRDFDataSource** aDataSource)
|
||||
{
|
||||
NS_PRECONDITION(aDataSource != nsnull, "null ptr");
|
||||
if (! aDataSource)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_ADDREF(mDataSource);
|
||||
*aDataSource = mDataSource;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
ContainerCursorImpl::GetSubject(nsIRDFResource** aSubject)
|
||||
{
|
||||
NS_PRECONDITION(aSubject != nsnull, "null ptr");
|
||||
if (! aSubject)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_ADDREF(mContainer);
|
||||
*aSubject = mContainer;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
ContainerCursorImpl::GetPredicate(nsIRDFResource** aPredicate)
|
||||
{
|
||||
NS_PRECONDITION(aPredicate != nsnull, "null ptr");
|
||||
|
||||
nsAutoString s(kRDFNameSpaceURI);
|
||||
s.Append("_");
|
||||
s.Append(mCounter, 10);
|
||||
|
||||
// this'll AddRef(), null check, etc.
|
||||
return mResourceMgr->GetUnicodeResource(s, aPredicate);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
ContainerCursorImpl::GetObject(nsIRDFNode** aObject)
|
||||
{
|
||||
NS_PRECONDITION(aObject != nsnull, "null ptr");
|
||||
if (! aObject)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (! mNext)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
NS_ADDREF(mNext);
|
||||
*aObject = mNext;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
ContainerCursorImpl::GetTruthValue(PRBool* aTruthValue)
|
||||
{
|
||||
NS_PRECONDITION(aTruthValue != nsnull, "null ptr");
|
||||
if (! aTruthValue)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aTruthValue = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult
|
||||
NS_NewContainerCursor(nsIRDFDataSource* ds,
|
||||
nsIRDFResource* container,
|
||||
nsIRDFAssertionCursor** cursor)
|
||||
{
|
||||
NS_PRECONDITION(ds != nsnull, "null ptr");
|
||||
NS_PRECONDITION(container != nsnull, "null ptr");
|
||||
NS_PRECONDITION(cursor != nsnull, "null ptr");
|
||||
|
||||
if (!ds || !container || !cursor)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
ContainerCursorImpl* result = new ContainerCursorImpl(ds, container);
|
||||
if (! result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
*cursor = result;
|
||||
NS_ADDREF(result);
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,216 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
|
||||
static NS_DEFINE_IID(kIRDFArcsInCursorIID, NS_IRDFARCSINCURSOR_IID);
|
||||
static NS_DEFINE_IID(kIRDFArcsOutCursorIID, NS_IRDFARCSOUTCURSOR_IID);
|
||||
static NS_DEFINE_IID(kIRDFAssertionCursorIID, NS_IRDFASSERTIONCURSOR_IID);
|
||||
static NS_DEFINE_IID(kIRDFCursorIID, NS_IRDFCURSOR_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class EmptyAssertionCursorImpl : public nsIRDFAssertionCursor
|
||||
{
|
||||
public:
|
||||
EmptyAssertionCursorImpl(void) {};
|
||||
virtual ~EmptyAssertionCursorImpl(void) {};
|
||||
|
||||
// nsISupports
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
NS_IMETHOD_(nsrefcnt) Release(void) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
NS_IMETHOD QueryInterface(REFNSIID iid, void** result) {
|
||||
if (! result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (iid.Equals(kIRDFAssertionCursorIID) ||
|
||||
iid.Equals(kIRDFCursorIID) ||
|
||||
iid.Equals(kISupportsIID)) {
|
||||
*result = NS_STATIC_CAST(nsIRDFAssertionCursor*, this);
|
||||
/* AddRef(); // not necessary */
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
// nsIRDFCursor
|
||||
NS_IMETHOD Advance(void) {
|
||||
return NS_ERROR_RDF_CURSOR_EMPTY;
|
||||
}
|
||||
|
||||
// nsIRDFAssertionCursor
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetSubject(nsIRDFResource** aResource) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetObject(nsIRDFNode** aObject) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetTruthValue(PRBool* aTruthValue) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
};
|
||||
|
||||
nsresult
|
||||
NS_NewEmptyRDFAssertionCursor(nsIRDFAssertionCursor** result)
|
||||
{
|
||||
static EmptyAssertionCursorImpl gEmptyAssertionCursor;
|
||||
*result = &gEmptyAssertionCursor;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class EmptyArcsOutCursorImpl : public nsIRDFArcsOutCursor
|
||||
{
|
||||
public:
|
||||
EmptyArcsOutCursorImpl(void) {};
|
||||
virtual ~EmptyArcsOutCursorImpl(void) {};
|
||||
|
||||
// nsISupports
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
NS_IMETHOD_(nsrefcnt) Release(void) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
NS_IMETHOD QueryInterface(REFNSIID iid, void** result) {
|
||||
if (! result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (iid.Equals(kIRDFArcsOutCursorIID) ||
|
||||
iid.Equals(kIRDFCursorIID) ||
|
||||
iid.Equals(kISupportsIID)) {
|
||||
*result = NS_STATIC_CAST(nsIRDFArcsOutCursor*, this);
|
||||
/* AddRef(); // not necessary */
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
// nsIRDFCursor
|
||||
NS_IMETHOD Advance(void) {
|
||||
return NS_ERROR_RDF_CURSOR_EMPTY;
|
||||
}
|
||||
|
||||
// nsIRDFArcsOutCursor
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetSubject(nsIRDFResource** aResource) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetTruthValue(PRBool* aTruthValue) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
};
|
||||
|
||||
nsresult
|
||||
NS_NewEmptyRDFArcsOutCursor(nsIRDFArcsOutCursor** result)
|
||||
{
|
||||
static EmptyArcsOutCursorImpl gEmptyArcsOutCursor;
|
||||
*result = &gEmptyArcsOutCursor;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class EmptyArcsInCursorImpl : public nsIRDFArcsInCursor
|
||||
{
|
||||
public:
|
||||
EmptyArcsInCursorImpl(void) {};
|
||||
virtual ~EmptyArcsInCursorImpl(void) {};
|
||||
|
||||
// nsISupports
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
NS_IMETHOD_(nsrefcnt) Release(void) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
NS_IMETHOD QueryInterface(REFNSIID iid, void** result) {
|
||||
if (! result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (iid.Equals(kIRDFArcsInCursorIID) ||
|
||||
iid.Equals(kIRDFCursorIID) ||
|
||||
iid.Equals(kISupportsIID)) {
|
||||
*result = NS_STATIC_CAST(nsIRDFArcsInCursor*, this);
|
||||
/* AddRef(); // not necessary */
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
// nsIRDFCursor
|
||||
NS_IMETHOD Advance(void) {
|
||||
return NS_ERROR_RDF_CURSOR_EMPTY;
|
||||
}
|
||||
|
||||
// nsIRDFArcsInCursor
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetObject(nsIRDFNode** aNode) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetTruthValue(PRBool* aTruthValue) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
};
|
||||
|
||||
nsresult
|
||||
NS_NewEmptyRDFArcsInCursor(nsIRDFArcsInCursor** result)
|
||||
{
|
||||
static EmptyArcsInCursorImpl gEmptyArcsInCursor;
|
||||
*result = &gEmptyArcsInCursor;
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,743 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
Implementation for an in-memory RDF data store.
|
||||
|
||||
TO DO:
|
||||
|
||||
1) ArcsIn & ArcsOut cursors.
|
||||
|
||||
*/
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFObserver.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsVoidArray.h" // XXX introduces dependency on raptorbase
|
||||
//Guha --- could we ask them to move it out?
|
||||
#include "nsRDFCID.h"
|
||||
#include "rdfutil.h"
|
||||
#include "plhash.h"
|
||||
#include "plstr.h"
|
||||
|
||||
static NS_DEFINE_IID(kIRDFAssertionCursorIID, NS_IRDFASSERTIONCURSOR_IID);
|
||||
static NS_DEFINE_IID(kIRDFArcsInCursorIID, NS_IRDFARCSINCURSOR_IID);
|
||||
static NS_DEFINE_IID(kIRDFArcsOutCursorIID, NS_IRDFARCSOUTCURSOR_IID);
|
||||
static NS_DEFINE_IID(kIRDFCursorIID, NS_IRDFCURSOR_IID);
|
||||
static NS_DEFINE_IID(kIRDFDataSourceIID, NS_IRDFDATASOURCE_IID);
|
||||
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
|
||||
static NS_DEFINE_IID(kIRDFNodeIID, NS_IRDFNODE_IID);
|
||||
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
|
||||
|
||||
class Assertion
|
||||
{
|
||||
public:
|
||||
nsIRDFResource* mSource;
|
||||
nsIRDFResource* mProperty;
|
||||
nsIRDFNode* mTarget;
|
||||
PRBool mTv;
|
||||
Assertion* mNext;
|
||||
Assertion* mInvNext;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static PLHashNumber
|
||||
rdf_HashPointer(const void* key)
|
||||
{
|
||||
return (PLHashNumber) key;
|
||||
}
|
||||
|
||||
static PRIntn
|
||||
rdf_CompareNodes(const void* v1, const void* v2)
|
||||
{
|
||||
nsIRDFNode* a = (nsIRDFNode*)v1;
|
||||
nsIRDFNode* b = (nsIRDFNode*)v2;
|
||||
|
||||
PRBool result;
|
||||
if (NS_FAILED(a->EqualsNode(b, &result)))
|
||||
return 0;
|
||||
|
||||
return (PRIntn) result;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// InMemoryDataSource
|
||||
|
||||
|
||||
class InMemoryDataSource : public nsIRDFDataSource
|
||||
{
|
||||
protected:
|
||||
char* mURL;
|
||||
|
||||
|
||||
PLHashTable* mForwardArcs;
|
||||
PLHashTable* mReverseArcs;
|
||||
|
||||
nsVoidArray* mObservers;
|
||||
|
||||
static const PRInt32 kInitialTableSize;
|
||||
|
||||
public:
|
||||
InMemoryDataSource(void);
|
||||
virtual ~InMemoryDataSource(void);
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIRDFDataSource methods
|
||||
NS_IMETHOD Init(const char* uri);
|
||||
|
||||
NS_IMETHOD GetSource(nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
PRBool tv,
|
||||
nsIRDFResource** source);
|
||||
|
||||
NS_IMETHOD GetSources(nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor** sources);
|
||||
|
||||
NS_IMETHOD GetTarget(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
PRBool tv,
|
||||
nsIRDFNode** target);
|
||||
|
||||
NS_IMETHOD GetTargets(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor** targets);
|
||||
|
||||
NS_IMETHOD Assert(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
PRBool tv);
|
||||
|
||||
NS_IMETHOD Unassert(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
nsIRDFNode* target);
|
||||
|
||||
NS_IMETHOD HasAssertion(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
PRBool tv,
|
||||
PRBool* hasAssertion);
|
||||
|
||||
NS_IMETHOD AddObserver(nsIRDFObserver* n);
|
||||
|
||||
NS_IMETHOD RemoveObserver(nsIRDFObserver* n);
|
||||
|
||||
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
|
||||
nsIRDFArcsInCursor** labels);
|
||||
|
||||
NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
|
||||
nsIRDFArcsOutCursor** labels);
|
||||
|
||||
NS_IMETHOD Flush();
|
||||
|
||||
// Implemenatation methods
|
||||
|
||||
// XXX how about more descriptive names for these...
|
||||
Assertion* getArg1 (nsIRDFResource* u);
|
||||
Assertion* getArg2 (nsIRDFNode* v);
|
||||
void setArg1 (nsIRDFResource* u, Assertion* as);
|
||||
void setArg2 (nsIRDFNode* v, Assertion* as);
|
||||
};
|
||||
|
||||
const PRInt32 InMemoryDataSource::kInitialTableSize = 500;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// InMemoryAssertionCursor
|
||||
|
||||
class InMemoryAssertionCursor : public nsIRDFAssertionCursor
|
||||
{
|
||||
private:
|
||||
InMemoryDataSource* mDataSource;
|
||||
nsIRDFResource* mSource;
|
||||
nsIRDFResource* mLabel;
|
||||
nsIRDFNode* mTarget;
|
||||
nsIRDFNode* mValue;
|
||||
PRInt32 mCount;
|
||||
PRBool mTruthValue;
|
||||
PRBool mInversep;
|
||||
Assertion* mNextAssertion;
|
||||
|
||||
public:
|
||||
InMemoryAssertionCursor(InMemoryDataSource* ds,
|
||||
nsIRDFNode* u,
|
||||
nsIRDFResource* s,
|
||||
PRBool tv,
|
||||
PRBool inversep);
|
||||
|
||||
virtual ~InMemoryAssertionCursor(void);
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIRDFCursor interface
|
||||
NS_IMETHOD Advance(void);
|
||||
|
||||
// nsIRDFAssertionCursor interface
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource);
|
||||
NS_IMETHOD GetSubject(nsIRDFResource** aResource);
|
||||
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate);
|
||||
NS_IMETHOD GetObject(nsIRDFNode** aObject);
|
||||
NS_IMETHOD GetTruthValue(PRBool* aTruthValue);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
InMemoryAssertionCursor::InMemoryAssertionCursor (InMemoryDataSource* ds,
|
||||
nsIRDFNode* u,
|
||||
nsIRDFResource* label,
|
||||
PRBool tv,
|
||||
PRBool inversep)
|
||||
: mDataSource(ds),
|
||||
mLabel(label),
|
||||
mTruthValue(tv),
|
||||
mInversep(inversep),
|
||||
mCount(0),
|
||||
mNextAssertion(nsnull),
|
||||
mValue(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
mInversep = inversep;
|
||||
if (inversep) {
|
||||
mTarget = u;
|
||||
mNextAssertion = mDataSource->getArg2(u);
|
||||
} else {
|
||||
mSource = u;
|
||||
mNextAssertion = mDataSource->getArg1(mSource);
|
||||
// Dont need this ...
|
||||
// if (NS_SUCCEEDED(u->QueryInterface(kIRDFResourceIID, (void**) &mSource)))
|
||||
// mNextAssertion = mDataSource->getArg1(mSource);
|
||||
}
|
||||
}
|
||||
|
||||
InMemoryAssertionCursor::~InMemoryAssertionCursor(void)
|
||||
{
|
||||
NS_IF_RELEASE(mValue);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(InMemoryAssertionCursor, kIRDFAssertionCursorIID);
|
||||
|
||||
NS_IMETHODIMP
|
||||
InMemoryAssertionCursor::Advance(void)
|
||||
{
|
||||
// XXX I don't think that the semantics of this are quite right:
|
||||
// specifically, I think that the initial Advance() will skip the
|
||||
// first element...
|
||||
// Guha --- I am pretty sure it won't
|
||||
nsresult rv;
|
||||
|
||||
NS_IF_RELEASE(mValue);
|
||||
|
||||
while (mNextAssertion) {
|
||||
PRBool eq;
|
||||
if (NS_FAILED(rv = mLabel->EqualsResource(mNextAssertion->mProperty, &eq)))
|
||||
return rv;
|
||||
|
||||
if ((mTruthValue == mNextAssertion->mTv) && eq) {
|
||||
if (mInversep) {
|
||||
mValue = mNextAssertion->mSource;
|
||||
NS_ADDREF(mValue);
|
||||
} else {
|
||||
mValue = mNextAssertion->target;
|
||||
NS_ADDREF(mValue);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
mNextAssertion = (mInversep ? mNextAssertion->mInvNext : mNextAssertion->mNext);
|
||||
}
|
||||
|
||||
// If we get here, the cursor is empty.
|
||||
return NS_ERROR_RDF_CURSOR_EMPTY;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InMemoryAssertionCursor::GetDataSource(nsIRDFDataSource** aDataSource)
|
||||
{
|
||||
NS_PRECONDITION(aDataSource != nsnull, "null ptr");
|
||||
if (! aDataSource)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_ADDREF(mDataSource);
|
||||
*aDataSource = mDataSource;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
InMemoryAssertionCursor::GetSubject(nsIRDFResource** aSubject)
|
||||
{
|
||||
NS_PRECONDITION(aSubject != nsnull, "null ptr");
|
||||
if (! aSubject)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (mInversep) {
|
||||
if (! mValue)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
// this'll AddRef()
|
||||
return mValue->QueryInterface(kIRDFResourceIID, (void**) aSubject);
|
||||
}
|
||||
else {
|
||||
NS_ADDREF(mSource);
|
||||
*aSubject = mSource;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
InMemoryAssertionCursor::GetPredicate(nsIRDFResource** aPredicate)
|
||||
{
|
||||
NS_PRECONDITION(aPredicate != nsnull, "null ptr");
|
||||
if (! aPredicate)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_ADDREF(mLabel);
|
||||
*aPredicate = mLabel;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
InMemoryAssertionCursor::GetObject(nsIRDFNode** aObject)
|
||||
{
|
||||
NS_PRECONDITION(aObject != nsnull, "null ptr");
|
||||
if (! aObject)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (mInversep) {
|
||||
NS_ADDREF(mTarget);
|
||||
*aObject = mTarget;
|
||||
}
|
||||
else {
|
||||
if (! mValue)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
// this'll AddRef()
|
||||
*aObject = mValue;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
InMemoryAssertionCursor::GetTruthValue(PRBool* aTruthValue)
|
||||
{
|
||||
NS_PRECONDITION(aTruthValue != nsnull, "null ptr");
|
||||
if (! aTruthValue)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aTruthValue = mTruthValue;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_IMPL_ISUPPORTS(InMemoryDataSource, kIRDFDataSourceIID);
|
||||
|
||||
InMemoryDataSource::InMemoryDataSource(void)
|
||||
: mURL(nsnull),
|
||||
mForwardArcs(nsnull),
|
||||
mReverseArcs(nsnull),
|
||||
mObservers(nsnull)
|
||||
{
|
||||
mForwardArcs = PL_NewHashTable(kInitialTableSize,
|
||||
rdf_HashPointer,
|
||||
PL_CompareValues,
|
||||
PL_CompareValues,
|
||||
nsnull,
|
||||
nsnull);
|
||||
|
||||
mReverseArcs = PL_NewHashTable(kInitialTableSize,
|
||||
rdf_HashPointer,
|
||||
rdf_CompareNodes,
|
||||
PL_CompareValues,
|
||||
nsnull,
|
||||
nsnull);
|
||||
}
|
||||
|
||||
InMemoryDataSource::~InMemoryDataSource(void)
|
||||
{
|
||||
if (mForwardArcs) {
|
||||
PL_HashTableDestroy(mForwardArcs);
|
||||
mForwardArcs = nsnull;
|
||||
}
|
||||
if (mReverseArcs) {
|
||||
PL_HashTableDestroy(mReverseArcs);
|
||||
mReverseArcs = nsnull;
|
||||
}
|
||||
if (mObservers) {
|
||||
for (PRInt32 i = mObservers->Count(); i >= 0; --i) {
|
||||
nsIRDFObserver* obs = (nsIRDFObserver*) mObservers->ElementAt(i);
|
||||
NS_RELEASE(obs);
|
||||
}
|
||||
delete mObservers;
|
||||
}
|
||||
}
|
||||
|
||||
Assertion*
|
||||
InMemoryDataSource::getArg1 (nsIRDFResource* u)
|
||||
{
|
||||
// Cast is okay, we're in a closed system
|
||||
return (Assertion*) PL_HashTableLookup(mForwardArcs, u);
|
||||
}
|
||||
|
||||
Assertion*
|
||||
InMemoryDataSource::getArg2 (nsIRDFNode* v)
|
||||
{
|
||||
// Cast is okay, we're in a closed system
|
||||
return (Assertion*) PL_HashTableLookup(mReverseArcs, v);
|
||||
}
|
||||
|
||||
void
|
||||
InMemoryDataSource::setArg1 (nsIRDFResource* u, Assertion* as)
|
||||
{
|
||||
PL_HashTableAdd(mForwardArcs, u, as);
|
||||
}
|
||||
|
||||
void
|
||||
InMemoryDataSource::setArg2 (nsIRDFNode* v, Assertion* as)
|
||||
{
|
||||
PL_HashTableAdd(mReverseArcs, v, as);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InMemoryDataSource::Init(const char* uri)
|
||||
{
|
||||
if ((mURL = PL_strdup(uri)) == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InMemoryDataSource::GetSource(nsIRDFResource* property, nsIRDFNode* target,
|
||||
PRBool tv, nsIRDFResource** source)
|
||||
{
|
||||
nsresult rv;
|
||||
for (Assertion* as = getArg2(target); as != nsnull; as = as->mNext) {
|
||||
PRBool eq;
|
||||
if (NS_FAILED(rv = property->EqualsResource(as->mProperty, &eq)))
|
||||
return rv;
|
||||
|
||||
if (! eq)
|
||||
continue;
|
||||
|
||||
if (as->mTv != tv)
|
||||
continue;
|
||||
|
||||
*source = as->mSource;
|
||||
return NS_OK;
|
||||
}
|
||||
*source = nsnull;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InMemoryDataSource::GetTarget(nsIRDFResource* source, nsIRDFResource* property,
|
||||
PRBool tv, nsIRDFNode** target) {
|
||||
nsresult rv;
|
||||
for (Assertion* as = getArg1(source); as != nsnull; as = as->mNext) {
|
||||
PRBool eq;
|
||||
if (NS_FAILED(rv = property->EqualsResource(as->mProperty, &eq)))
|
||||
return rv;
|
||||
|
||||
if (! eq)
|
||||
continue;
|
||||
|
||||
if (as->mTv != tv)
|
||||
continue;
|
||||
|
||||
*target = as->target;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// If we get here, then there was no target with for the specified
|
||||
// property & truth value.
|
||||
*target = nsnull;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InMemoryDataSource::HasAssertion(nsIRDFResource* source, nsIRDFResource* property,
|
||||
nsIRDFNode* target, PRBool tv,PRBool* hasAssertion)
|
||||
{
|
||||
nsresult rv;
|
||||
for (Assertion* as = getArg1(source); as != nsnull; as = as->mNext) {
|
||||
PRBool eq;
|
||||
if (NS_FAILED(rv = property->EqualsResource(as->mProperty, &eq)))
|
||||
return rv;
|
||||
|
||||
if (! eq)
|
||||
continue;
|
||||
|
||||
if (NS_FAILED(rv = target->EqualsNode(as->target, &eq)))
|
||||
return rv;
|
||||
|
||||
if (! eq)
|
||||
continue;
|
||||
|
||||
if (as->mTv != tv)
|
||||
continue;
|
||||
|
||||
// found it!
|
||||
*hasAssertion = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// If we get here, we couldn't find the assertion
|
||||
*hasAssertion = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InMemoryDataSource::GetSources(nsIRDFResource* property, nsIRDFNode* target,
|
||||
PRBool tv, nsIRDFAssertionCursor** sources)
|
||||
{
|
||||
*sources = new InMemoryAssertionCursor (this, target, property, tv, PR_TRUE);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InMemoryDataSource::GetTargets(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
PRBool tv, nsIRDFAssertionCursor** targets)
|
||||
{
|
||||
*targets = new InMemoryAssertionCursor (this, source, property, tv, PR_FALSE);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InMemoryDataSource::Assert(nsIRDFResource* source, nsIRDFResource* property,
|
||||
nsIRDFNode* target, PRBool tv)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
Assertion* next = getArg1(source);
|
||||
Assertion* prev = next;
|
||||
Assertion* as = nsnull;
|
||||
|
||||
// Walk to the end of the linked list.
|
||||
// XXX shouldn't we just keep a pointer to the end, or insert at the front???
|
||||
while (next) {
|
||||
PRBool eq;
|
||||
|
||||
if (NS_FAILED(rv = property->EqualsResource(next->mProperty, &eq)))
|
||||
return rv;
|
||||
|
||||
if (eq) {
|
||||
if (NS_FAILED(rv = target->EqualsNode(next->target, &eq)))
|
||||
return rv;
|
||||
|
||||
if (eq) {
|
||||
// Wow, we already had the assertion. Make sure that the
|
||||
// truth values are correct and bail.
|
||||
next->mTv = tv;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
prev = next;
|
||||
next = as->mNext;
|
||||
}
|
||||
|
||||
as = new Assertion;
|
||||
if (! as)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(source);
|
||||
as->mSource = source;
|
||||
|
||||
NS_ADDREF(property);
|
||||
as->mProperty = property;
|
||||
|
||||
NS_ADDREF(target);
|
||||
as->target = target;
|
||||
|
||||
as->mTv = tv;
|
||||
|
||||
// Link it in to the "forward arcs" table
|
||||
if (!prev) {
|
||||
setArg1(source, as);
|
||||
} else {
|
||||
prev->mNext = as;
|
||||
}
|
||||
|
||||
// Link it in to the "reverse arcs" table
|
||||
prev = nsnull;
|
||||
|
||||
// XXX Shouldn't we keep a pointer to the end of the list to make
|
||||
// sure this is O(1)?
|
||||
for (next = getArg2(target); next != nsnull; next = next->mInvNext) {prev = next;}
|
||||
if (!prev) {
|
||||
setArg2(target, as);
|
||||
} else {
|
||||
prev->mInvNext = as;
|
||||
}
|
||||
|
||||
// notify observers
|
||||
if (mObservers) {
|
||||
for (PRInt32 i = mObservers->Count(); i >= 0; --i) {
|
||||
nsIRDFObserver* obs = (nsIRDFObserver*) mObservers->ElementAt(i);
|
||||
obs->OnAssert(source, property, target);
|
||||
// XXX ignore return value?
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InMemoryDataSource::Unassert(nsIRDFResource* source,
|
||||
nsIRDFResource* property, nsIRDFNode* target)
|
||||
{
|
||||
nsresult rv;
|
||||
Assertion* next = getArg1(source);
|
||||
Assertion* prev = next;
|
||||
Assertion* as = nsnull;
|
||||
|
||||
while (next) {
|
||||
PRBool eq;
|
||||
|
||||
if (NS_FAILED(rv = property->EqualsResource(next->mProperty, &eq)))
|
||||
return rv;
|
||||
|
||||
if (eq) {
|
||||
if (NS_FAILED(rv = target->EqualsNode(next->target, &eq)))
|
||||
return rv;
|
||||
|
||||
if (eq) {
|
||||
if (prev == next) {
|
||||
setArg1(source, next->mNext);
|
||||
} else {
|
||||
prev->mNext = next->mNext;
|
||||
}
|
||||
as = next;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
prev = next;
|
||||
next = as->mNext;
|
||||
}
|
||||
|
||||
// We don't even have the assertion, so just bail.
|
||||
if (!as)
|
||||
return NS_OK;
|
||||
|
||||
next = prev = getArg2(target);
|
||||
while (next) {
|
||||
if (next == as) {
|
||||
if (prev == next) {
|
||||
setArg2(target, next->mInvNext);
|
||||
} else {
|
||||
prev->mInvNext = next->mInvNext;
|
||||
}
|
||||
break;
|
||||
}
|
||||
prev = next;
|
||||
next = as->mInvNext;
|
||||
}
|
||||
|
||||
// XXX delete the assertion struct & release resources?
|
||||
|
||||
if (mObservers) {
|
||||
for (PRInt32 i = mObservers->Count(); i >= 0; --i) {
|
||||
nsIRDFObserver* obs = (nsIRDFObserver*) mObservers->ElementAt(i);
|
||||
obs->OnUnassert(source, property, target);
|
||||
// XXX ignore return value?
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
InMemoryDataSource::AddObserver(nsIRDFObserver* observer)
|
||||
{
|
||||
if (! mObservers) {
|
||||
if ((mObservers = new nsVoidArray()) == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
mObservers->AppendElement(observer);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InMemoryDataSource::RemoveObserver(nsIRDFObserver* observer)
|
||||
{
|
||||
if (! mObservers)
|
||||
return NS_OK;
|
||||
|
||||
mObservers->RemoveElement(observer);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InMemoryDataSource::ArcLabelsIn(nsIRDFNode* node, nsIRDFArcsInCursor** labels)
|
||||
{
|
||||
// XXX implement later
|
||||
return NS_ERROR_NOT_IMPLEMENTED; // XXX
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InMemoryDataSource::ArcLabelsOut(nsIRDFResource* source,nsIRDFArcsOutCursor** labels)
|
||||
{
|
||||
// XXX implement later
|
||||
return NS_ERROR_NOT_IMPLEMENTED; // XXX
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InMemoryDataSource::Flush()
|
||||
{
|
||||
// XXX nothing to flush, right?
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult
|
||||
NS_NewRDFInMemoryDataSource(nsIRDFDataSource** result)
|
||||
{
|
||||
InMemoryDataSource* ds = new InMemoryDataSource();
|
||||
if (! ds)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
*result = ds;
|
||||
NS_ADDREF(*result);
|
||||
return NS_OK;
|
||||
}
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,40 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
// This header file just contains prototypes for the factory methods
|
||||
// for "builtin" data sources that are included in rdf.dll. Each of
|
||||
// these data sources is exposed to the external world via its CID in
|
||||
// ../include/nsRDFCID.h.
|
||||
|
||||
#ifndef nsBuiltinDataSources_h__
|
||||
#define nsBuiltinDataSources_h__
|
||||
|
||||
#include "nsError.h"
|
||||
|
||||
class nsIRDFDataSource;
|
||||
class nsIRDFDataBase;
|
||||
|
||||
// in nsMemoryDataSource.cpp
|
||||
nsresult NS_NewRDFMemoryDataSource(nsIRDFDataSource** result);
|
||||
|
||||
// in nsSimpleDataBase.cpp
|
||||
nsresult NS_NewRDFSimpleDataBase(nsIRDFDataBase** result);
|
||||
|
||||
#endif // nsBuiltinDataSources_h__
|
||||
|
||||
|
|
@ -0,0 +1,161 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsIRDFResourceManager.h"
|
||||
#include "nsRDFBaseDataSources.h"
|
||||
#include "nsRDFBaseCID.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
|
||||
static NS_DEFINE_CID(kRDFMemoryDataSourceCID, NS_RDFMEMORYDATASOURCE_CID);
|
||||
static NS_DEFINE_CID(kRDFResourceManagerCID, NS_RDFRESOURCEMANAGER_CID);
|
||||
static NS_DEFINE_CID(kRDFSimpleDataBaseCID, NS_RDFSIMPLEDATABASE_CID);
|
||||
|
||||
class RDFFactoryImpl : public nsIFactory
|
||||
{
|
||||
public:
|
||||
RDFFactoryImpl(const nsCID &aClass);
|
||||
|
||||
// nsISupports methods
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIFactory methods
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
protected:
|
||||
virtual ~RDFFactoryImpl();
|
||||
|
||||
private:
|
||||
nsCID mClassID;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
RDFFactoryImpl::RDFFactoryImpl(const nsCID &aClass)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mClassID = aClass;
|
||||
}
|
||||
|
||||
RDFFactoryImpl::~RDFFactoryImpl()
|
||||
{
|
||||
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
RDFFactoryImpl::QueryInterface(const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
// Always NULL result, in case of failure
|
||||
*aResult = nsnull;
|
||||
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aResult = NS_STATIC_CAST(nsISupports*, this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
} else if (aIID.Equals(kIFactoryIID)) {
|
||||
*aResult = NS_STATIC_CAST(nsIFactory*, this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(RDFFactoryImpl);
|
||||
NS_IMPL_RELEASE(RDFFactoryImpl);
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
RDFFactoryImpl::CreateInstance(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (aOuter)
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
*aResult = nsnull;
|
||||
|
||||
nsresult rv;
|
||||
PRBool wasRefCounted = PR_TRUE;
|
||||
nsISupports *inst = nsnull;
|
||||
if (mClassID.Equals(kRDFResourceManagerCID)) {
|
||||
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;
|
||||
}
|
||||
else if (mClassID.Equals(kRDFSimpleDataBaseCID)) {
|
||||
if (NS_FAILED(rv = NS_NewRDFSimpleDataBase((nsIRDFDataBase**) &inst)))
|
||||
return rv;
|
||||
}
|
||||
else {
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
|
||||
if (! inst)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
if (NS_FAILED(rv = inst->QueryInterface(aIID, aResult)))
|
||||
// We didn't get the right interface, so clean up
|
||||
delete inst;
|
||||
|
||||
if (wasRefCounted)
|
||||
NS_IF_RELEASE(inst);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult RDFFactoryImpl::LockFactory(PRBool aLock)
|
||||
{
|
||||
// Not implemented in simplest case.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
// return the proper factory to the caller
|
||||
extern "C" PR_IMPLEMENT(nsresult)
|
||||
NSGetFactory(const nsCID &aClass, nsIFactory **aFactory)
|
||||
{
|
||||
if (! aFactory)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aFactory = new RDFFactoryImpl(aClass);
|
||||
if (aFactory == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return (*aFactory)->QueryInterface(kIFactoryIID, (void**)aFactory);
|
||||
}
|
||||
|
|
@ -0,0 +1,366 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
#include "nsIAtom.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFResourceManager.h"
|
||||
#include "nsString.h"
|
||||
#include "plhash.h"
|
||||
#include "plstr.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
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:
|
||||
ResourceManagerImpl(void);
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// 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);
|
||||
|
||||
void ReleaseNode(const ResourceImpl* resource);
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ResourceImpl : public nsIRDFResource {
|
||||
public:
|
||||
ResourceImpl(ResourceManagerImpl* mgr, const char* uri);
|
||||
virtual ~ResourceImpl(void);
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIRDFNode
|
||||
NS_IMETHOD EqualsNode(nsIRDFNode* node, PRBool* result) const;
|
||||
|
||||
// nsIRDFResource
|
||||
NS_IMETHOD GetValue(const char* *uri) const;
|
||||
NS_IMETHOD EqualsResource(const nsIRDFResource* resource, PRBool* result) const;
|
||||
NS_IMETHOD EqualsString(const char* uri, PRBool* result) const;
|
||||
|
||||
// Implementation methods
|
||||
const char* GetURI(void) const {
|
||||
return mURI;
|
||||
}
|
||||
|
||||
private:
|
||||
char* mURI;
|
||||
ResourceManagerImpl* mMgr;
|
||||
};
|
||||
|
||||
|
||||
ResourceImpl::ResourceImpl(ResourceManagerImpl* mgr, const char* uri)
|
||||
: mMgr(mgr)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_IF_ADDREF(mMgr);
|
||||
mURI = PL_strdup(uri);
|
||||
}
|
||||
|
||||
|
||||
ResourceImpl::~ResourceImpl(void)
|
||||
{
|
||||
mMgr->ReleaseNode(this);
|
||||
PL_strfree(mURI);
|
||||
NS_IF_RELEASE(mMgr);
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
ResourceImpl::EqualsNode(nsIRDFNode* node, PRBool* result) const
|
||||
{
|
||||
nsresult rv;
|
||||
nsIRDFResource* resource;
|
||||
if (NS_SUCCEEDED(node->QueryInterface(kIRDFResourceIID, (void**) &resource))) {
|
||||
rv = EqualsResource(resource, result);
|
||||
NS_RELEASE(resource);
|
||||
}
|
||||
else {
|
||||
*result = PR_FALSE;
|
||||
rv = NS_OK;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ResourceImpl::GetValue(const char* *uri) const
|
||||
{
|
||||
if (!uri)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*uri = mURI;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
ResourceImpl::EqualsResource(const nsIRDFResource* resource, PRBool* result) const
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
|
||||
class LiteralImpl : public nsIRDFLiteral {
|
||||
public:
|
||||
LiteralImpl(const PRUnichar* s);
|
||||
virtual ~LiteralImpl(void);
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIRDFNode
|
||||
NS_IMETHOD EqualsNode(nsIRDFNode* node, PRBool* result) const;
|
||||
|
||||
// nsIRDFLiteral
|
||||
NS_IMETHOD GetValue(const PRUnichar* *value) const;
|
||||
NS_IMETHOD EqualsLiteral(const nsIRDFLiteral* literal, PRBool* result) const;
|
||||
|
||||
private:
|
||||
nsAutoString mValue;
|
||||
};
|
||||
|
||||
|
||||
LiteralImpl::LiteralImpl(const PRUnichar* s)
|
||||
: mValue(s)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
LiteralImpl::~LiteralImpl(void)
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(LiteralImpl);
|
||||
NS_IMPL_RELEASE(LiteralImpl);
|
||||
|
||||
nsresult
|
||||
LiteralImpl::QueryInterface(REFNSIID iid, void** result)
|
||||
{
|
||||
if (! result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*result = nsnull;
|
||||
if (iid.Equals(kIRDFLiteralIID) ||
|
||||
iid.Equals(kIRDFNodeIID) ||
|
||||
iid.Equals(kISupportsIID)) {
|
||||
*result = NS_STATIC_CAST(nsIRDFLiteral*, this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
LiteralImpl::EqualsNode(nsIRDFNode* node, PRBool* result) const
|
||||
{
|
||||
nsresult rv;
|
||||
nsIRDFLiteral* literal;
|
||||
if (NS_SUCCEEDED(node->QueryInterface(kIRDFLiteralIID, (void**) &literal))) {
|
||||
rv = EqualsLiteral(literal, result);
|
||||
NS_RELEASE(literal);
|
||||
}
|
||||
else {
|
||||
*result = PR_FALSE;
|
||||
rv = NS_OK;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
LiteralImpl::GetValue(const PRUnichar* *value) const
|
||||
{
|
||||
NS_ASSERTION(value, "null ptr");
|
||||
if (! value)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*value = mValue.GetUnicode();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
LiteralImpl::EqualsLiteral(const nsIRDFLiteral* literal, PRBool* result) const
|
||||
{
|
||||
NS_ASSERTION(literal && result, "null ptr");
|
||||
if (!literal || !result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsresult rv;
|
||||
const PRUnichar* p;
|
||||
if (NS_FAILED(rv = literal->GetValue(&p)))
|
||||
return rv;
|
||||
|
||||
nsAutoString s(p);
|
||||
|
||||
*result = s.Equals(mValue);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// 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
|
||||
ResourceManagerImpl::GetResource(const char* uri, nsIRDFResource** resource)
|
||||
{
|
||||
ResourceImpl* result =
|
||||
NS_STATIC_CAST(ResourceImpl*, PL_HashTableLookup(mResources, uri));
|
||||
|
||||
if (! result) {
|
||||
result = new ResourceImpl(this, uri);
|
||||
if (! result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
// 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, because the resource
|
||||
// AddRef()s *us*.
|
||||
}
|
||||
|
||||
result->AddRef();
|
||||
*resource = result;
|
||||
|
||||
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;
|
||||
|
||||
*literal = result;
|
||||
NS_ADDREF(result);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ResourceManagerImpl::ReleaseNode(const ResourceImpl* resource)
|
||||
{
|
||||
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;
|
||||
}
|
|
@ -0,0 +1,912 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFDataBase.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsRepository.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "prlog.h"
|
||||
|
||||
/*
|
||||
|
||||
XXX rvg --- chris, are you happy with this (I rewrote it).
|
||||
|
||||
A simple "database" implementation. An RDF database is just a
|
||||
"strategy" pattern for combining individual data sources into a
|
||||
collective graph.
|
||||
|
||||
|
||||
1) A database is a sequence of data sources. The set of data sources
|
||||
can be specified during creation of the database. Data sources
|
||||
can also be added/deleted from a database later.
|
||||
|
||||
2) The aggregation mechanism is based on simple super-positioning of
|
||||
the graphs from the datasources. If there is a conflict (i.e.,
|
||||
data source A has a true arc from foo to bar while data source B
|
||||
has a false arc from foo to bar), the data source that it earlier
|
||||
in the sequence wins.
|
||||
|
||||
The implementation below doesn't really do this and needs to be
|
||||
fixed.
|
||||
|
||||
*/
|
||||
|
||||
static NS_DEFINE_IID(kIRDFArcsInCursorIID, NS_IRDFARCSINCURSOR_IID);
|
||||
static NS_DEFINE_IID(kIRDFArcsOutCursorIID, NS_IRDFARCSOUTCURSOR_IID);
|
||||
static NS_DEFINE_IID(kIRDFAssertionCursorIID, NS_IRDFASSERTIONCURSOR_IID);
|
||||
static NS_DEFINE_IID(kIRDFCursorIID, NS_IRDFCURSOR_IID);
|
||||
static NS_DEFINE_IID(kIRDFDataBaseIID, NS_IRDFDATABASE_IID);
|
||||
static NS_DEFINE_IID(kIRDFDataSourceIID, NS_IRDFDATASOURCE_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// MultiCursor
|
||||
//
|
||||
// This class encapsulates all of the behavior that is necessary to
|
||||
// stripe a cursor across several different data sources, including
|
||||
// checks to determine whether an negation in an "earlier" data
|
||||
// source masks an assertion in a "later" data source.
|
||||
//
|
||||
|
||||
class MultiCursor {
|
||||
private:
|
||||
nsIRDFDataSource* mDataSource0;
|
||||
nsIRDFDataSource** mDataSources;
|
||||
nsIRDFCursor* mCurrentCursor;
|
||||
nsIRDFNode* mNextResult;
|
||||
PRBool mNextTruthValue;
|
||||
PRInt32 mNextDataSource;
|
||||
PRInt32 mCount;
|
||||
|
||||
public:
|
||||
MultiCursor(nsVoidArray& dataSources);
|
||||
virtual ~MultiCursor(void);
|
||||
|
||||
NS_IMETHOD AdvanceImpl(void);
|
||||
|
||||
virtual nsresult
|
||||
GetCursor(nsIRDFDataSource* ds, nsIRDFCursor** result) = 0;
|
||||
|
||||
virtual nsresult
|
||||
IsCurrentNegatedBy(nsIRDFDataSource* ds0,
|
||||
PRBool* result) = 0;
|
||||
|
||||
nsIRDFCursor*
|
||||
GetCurrentCursor(void) {
|
||||
return mCurrentCursor;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
MultiCursor::MultiCursor(nsVoidArray& dataSources)
|
||||
: mDataSource0(nsnull),
|
||||
mDataSources(nsnull),
|
||||
mCurrentCursor(nsnull),
|
||||
mNextResult(nsnull),
|
||||
mCount(0),
|
||||
mNextDataSource(0)
|
||||
{
|
||||
mCount = dataSources.Count();
|
||||
mDataSources = new nsIRDFDataSource*[mCount];
|
||||
|
||||
PR_ASSERT(mDataSources);
|
||||
if (! mDataSources)
|
||||
return;
|
||||
|
||||
for (PRInt32 i = 0; i < mCount; ++i) {
|
||||
mDataSources[i] = NS_STATIC_CAST(nsIRDFDataSource*, dataSources[i]);
|
||||
NS_ADDREF(mDataSources[i]);
|
||||
}
|
||||
|
||||
mDataSource0 = mDataSources[0];
|
||||
NS_ADDREF(mDataSource0);
|
||||
}
|
||||
|
||||
|
||||
MultiCursor::~MultiCursor(void)
|
||||
{
|
||||
NS_IF_RELEASE(mNextResult);
|
||||
NS_IF_RELEASE(mCurrentCursor);
|
||||
for (PRInt32 i = mCount - 1; i >= 0; --i) {
|
||||
NS_IF_RELEASE(mDataSources[i]);
|
||||
}
|
||||
NS_IF_RELEASE(mDataSource0);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
MultiCursor::AdvanceImpl(void)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
while (mNextDataSource < mCount) {
|
||||
if (! mCurrentCursor) {
|
||||
// We don't have a current cursor, so create a new one on
|
||||
// the next data source.
|
||||
rv = GetCursor(mDataSources[mNextDataSource], &mCurrentCursor);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
}
|
||||
|
||||
do {
|
||||
if (NS_FAILED(rv = mCurrentCursor->Advance())) {
|
||||
// If we can't advance the current cursor, then either
|
||||
// a catastrophic error occurred, or it's depleted. If
|
||||
// it's just depleted break out of this loop and
|
||||
// advance to the next cursor.
|
||||
if (rv != NS_ERROR_RDF_CURSOR_EMPTY)
|
||||
return rv;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// Even if the current cursor has more elements, we still
|
||||
// need to check that the current element isn't masked by
|
||||
// the "main" data source.
|
||||
|
||||
// See if data source zero has the negation
|
||||
// XXX rvg --- this needs to be fixed so that we look at all the prior
|
||||
// data sources for negations
|
||||
PRBool hasNegation;
|
||||
if (NS_FAILED(rv = IsCurrentNegatedBy(mDataSource0,
|
||||
&hasNegation)))
|
||||
return rv;
|
||||
|
||||
// if not, we're done
|
||||
if (! hasNegation)
|
||||
return NS_OK;
|
||||
|
||||
// Otherwise, we found the negation in data source
|
||||
// zero. Gotta keep lookin'...
|
||||
} while (1);
|
||||
|
||||
NS_RELEASE(mCurrentCursor);
|
||||
NS_RELEASE(mDataSources[mNextDataSource]);
|
||||
++mNextDataSource;
|
||||
}
|
||||
|
||||
// if we get here, there aren't any elements left.
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// SimpleDBAssertionCursorImpl
|
||||
//
|
||||
// An assertion cursor implementation for the simple db.
|
||||
//
|
||||
class SimpleDBAssertionCursorImpl : public MultiCursor,
|
||||
public nsIRDFAssertionCursor
|
||||
{
|
||||
private:
|
||||
nsIRDFResource* mSource;
|
||||
nsIRDFResource* mProperty;
|
||||
PRBool mTruthValue;
|
||||
|
||||
public:
|
||||
SimpleDBAssertionCursorImpl(nsVoidArray& dataSources,
|
||||
nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
PRBool tv);
|
||||
|
||||
virtual ~SimpleDBAssertionCursorImpl();
|
||||
|
||||
// MultiCursor protocol methods
|
||||
virtual nsresult
|
||||
GetCursor(nsIRDFDataSource* ds, nsIRDFCursor** result);
|
||||
|
||||
virtual nsresult
|
||||
IsCurrentNegatedBy(nsIRDFDataSource* ds0,
|
||||
PRBool* result);
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIRDFAssertionCursor interface
|
||||
NS_IMETHOD Advance(void);
|
||||
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource);
|
||||
NS_IMETHOD GetSubject(nsIRDFResource** aResource);
|
||||
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate);
|
||||
NS_IMETHOD GetObject(nsIRDFNode** aObject);
|
||||
NS_IMETHOD GetTruthValue(PRBool* aTruthValue);
|
||||
};
|
||||
|
||||
SimpleDBAssertionCursorImpl::SimpleDBAssertionCursorImpl(nsVoidArray& dataSources,
|
||||
nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
PRBool tv)
|
||||
: MultiCursor(dataSources),
|
||||
mSource(source),
|
||||
mProperty(property),
|
||||
mTruthValue(tv)
|
||||
{
|
||||
NS_IF_ADDREF(mSource);
|
||||
NS_IF_ADDREF(mProperty);
|
||||
}
|
||||
|
||||
|
||||
SimpleDBAssertionCursorImpl::~SimpleDBAssertionCursorImpl(void)
|
||||
{
|
||||
NS_IF_RELEASE(mProperty);
|
||||
NS_IF_RELEASE(mSource);
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(SimpleDBAssertionCursorImpl);
|
||||
NS_IMPL_RELEASE(SimpleDBAssertionCursorImpl);
|
||||
|
||||
NS_IMETHODIMP_(nsresult)
|
||||
SimpleDBAssertionCursorImpl::QueryInterface(REFNSIID iid, void** result) {
|
||||
if (! result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (iid.Equals(kIRDFAssertionCursorIID) ||
|
||||
iid.Equals(kIRDFCursorIID) ||
|
||||
iid.Equals(kISupportsIID)) {
|
||||
*result = NS_STATIC_CAST(nsIRDFAssertionCursor*, this);
|
||||
/* AddRef(); // not necessary */
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
SimpleDBAssertionCursorImpl::GetCursor(nsIRDFDataSource* ds, nsIRDFCursor** result)
|
||||
{
|
||||
return ds->GetTargets(mSource, mProperty, mTruthValue,
|
||||
(nsIRDFAssertionCursor**) result);
|
||||
}
|
||||
|
||||
nsresult
|
||||
SimpleDBAssertionCursorImpl::IsCurrentNegatedBy(nsIRDFDataSource* ds0,
|
||||
PRBool* result)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// No need to QueryInterface() b/c this is a closed system.
|
||||
nsIRDFAssertionCursor* c =
|
||||
(nsIRDFAssertionCursor*) GetCurrentCursor();
|
||||
|
||||
PRBool tv;
|
||||
if (NS_FAILED(rv = c->GetTruthValue(&tv)))
|
||||
return rv;
|
||||
|
||||
nsIRDFNode* object;
|
||||
if (NS_FAILED(rv = c->GetObject(&object)))
|
||||
return rv;
|
||||
|
||||
rv = ds0->HasAssertion(mSource, mProperty, object, !tv, result);
|
||||
NS_RELEASE(object);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
SimpleDBAssertionCursorImpl::Advance(void)
|
||||
{
|
||||
return AdvanceImpl();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SimpleDBAssertionCursorImpl::GetDataSource(nsIRDFDataSource** aDataSource)
|
||||
{
|
||||
nsIRDFAssertionCursor* cursor =
|
||||
(nsIRDFAssertionCursor*) GetCurrentCursor();
|
||||
|
||||
if (! cursor)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
return cursor->GetDataSource(aDataSource);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SimpleDBAssertionCursorImpl::GetSubject(nsIRDFResource** aResource)
|
||||
{
|
||||
nsIRDFAssertionCursor* cursor =
|
||||
(nsIRDFAssertionCursor*) GetCurrentCursor();
|
||||
|
||||
if (! cursor)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
return cursor->GetSubject(aResource);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SimpleDBAssertionCursorImpl::GetPredicate(nsIRDFResource** aPredicate)
|
||||
{
|
||||
nsIRDFAssertionCursor* cursor =
|
||||
(nsIRDFAssertionCursor*) GetCurrentCursor();
|
||||
|
||||
if (! cursor)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
return cursor->GetPredicate(aPredicate);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SimpleDBAssertionCursorImpl::GetObject(nsIRDFNode** aObject)
|
||||
{
|
||||
nsIRDFAssertionCursor* cursor =
|
||||
(nsIRDFAssertionCursor*) GetCurrentCursor();
|
||||
|
||||
if (! cursor)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
return cursor->GetObject(aObject);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SimpleDBAssertionCursorImpl::GetTruthValue(PRBool* aTruthValue)
|
||||
{
|
||||
nsIRDFAssertionCursor* cursor =
|
||||
(nsIRDFAssertionCursor*) GetCurrentCursor();
|
||||
|
||||
if (! cursor)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
return cursor->GetTruthValue(aTruthValue);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// SimpleDBArcsOutCursorImpl
|
||||
|
||||
class SimpleDBArcsOutCursorImpl : public MultiCursor,
|
||||
public nsIRDFArcsOutCursor
|
||||
{
|
||||
private:
|
||||
nsIRDFResource* mSource;
|
||||
|
||||
public:
|
||||
SimpleDBArcsOutCursorImpl(nsVoidArray& dataSources, nsIRDFResource* source);
|
||||
|
||||
virtual ~SimpleDBArcsOutCursorImpl();
|
||||
|
||||
// MultiCursor protocol methods
|
||||
virtual nsresult
|
||||
GetCursor(nsIRDFDataSource* ds, nsIRDFCursor** result);
|
||||
|
||||
virtual nsresult
|
||||
IsCurrentNegatedBy(nsIRDFDataSource* ds0,
|
||||
PRBool* result);
|
||||
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIRDFArcsOutCursor interface
|
||||
NS_IMETHOD Advance(void);
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource);
|
||||
NS_IMETHOD GetSubject(nsIRDFResource** aSubject);
|
||||
NS_IMETHOD GetPredicate(nsIRDFResource** aPredicate);
|
||||
NS_IMETHOD GetTruthValue(PRBool* aTruthValue);
|
||||
};
|
||||
|
||||
SimpleDBArcsOutCursorImpl::SimpleDBArcsOutCursorImpl(nsVoidArray& dataSources,
|
||||
nsIRDFResource* source)
|
||||
: MultiCursor(dataSources),
|
||||
mSource(source)
|
||||
{
|
||||
NS_IF_ADDREF(mSource);
|
||||
}
|
||||
|
||||
|
||||
SimpleDBArcsOutCursorImpl::~SimpleDBArcsOutCursorImpl(void)
|
||||
{
|
||||
NS_IF_RELEASE(mSource);
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
SimpleDBArcsOutCursorImpl::GetCursor(nsIRDFDataSource* ds, nsIRDFCursor** result)
|
||||
{
|
||||
return ds->ArcLabelsOut(mSource, (nsIRDFArcsOutCursor**) result);
|
||||
}
|
||||
|
||||
nsresult
|
||||
SimpleDBArcsOutCursorImpl::IsCurrentNegatedBy(nsIRDFDataSource* ds0,
|
||||
PRBool* result)
|
||||
{
|
||||
*result = PR_FALSE; // XXX always?
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(SimpleDBArcsOutCursorImpl);
|
||||
NS_IMPL_RELEASE(SimpleDBArcsOutCursorImpl);
|
||||
|
||||
NS_IMETHODIMP_(nsresult)
|
||||
SimpleDBArcsOutCursorImpl::QueryInterface(REFNSIID iid, void** result) {
|
||||
if (! result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (iid.Equals(kIRDFAssertionCursorIID) ||
|
||||
iid.Equals(kIRDFCursorIID) ||
|
||||
iid.Equals(kISupportsIID)) {
|
||||
*result = NS_STATIC_CAST(nsIRDFArcsOutCursor*, this);
|
||||
/* AddRef(); // not necessary */
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SimpleDBArcsOutCursorImpl::Advance(void)
|
||||
{
|
||||
return AdvanceImpl();
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
SimpleDBArcsOutCursorImpl::GetDataSource(nsIRDFDataSource** aDataSource)
|
||||
{
|
||||
nsIRDFArcsOutCursor* cursor =
|
||||
(nsIRDFArcsOutCursor*) GetCurrentCursor();
|
||||
|
||||
if (! cursor)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
return cursor->GetDataSource(aDataSource);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
SimpleDBArcsOutCursorImpl::GetSubject(nsIRDFResource** aSubject)
|
||||
{
|
||||
nsIRDFArcsOutCursor* cursor =
|
||||
(nsIRDFArcsOutCursor*) GetCurrentCursor();
|
||||
|
||||
if (! cursor)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
return cursor->GetSubject(aSubject);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
SimpleDBArcsOutCursorImpl::GetPredicate(nsIRDFResource** aPredicate)
|
||||
{
|
||||
nsIRDFArcsOutCursor* cursor =
|
||||
(nsIRDFArcsOutCursor*) GetCurrentCursor();
|
||||
|
||||
if (! cursor)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
return cursor->GetPredicate(aPredicate);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
SimpleDBArcsOutCursorImpl::GetTruthValue(PRBool* aTruthValue)
|
||||
{
|
||||
nsIRDFArcsOutCursor* cursor =
|
||||
(nsIRDFArcsOutCursor*) GetCurrentCursor();
|
||||
|
||||
if (! cursor)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
return cursor->GetTruthValue(aTruthValue);
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// SimpleDataBaseImpl
|
||||
// XXX rvg --- shouldn't this take a char** argument indicating the data sources
|
||||
// we want to aggregate?
|
||||
|
||||
class SimpleDataBaseImpl : public nsIRDFDataBase {
|
||||
protected:
|
||||
nsVoidArray mDataSources;
|
||||
virtual ~SimpleDataBaseImpl(void);
|
||||
|
||||
public:
|
||||
SimpleDataBaseImpl(void);
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIRDFDataSource interface
|
||||
NS_IMETHOD Init(const char* uri);
|
||||
|
||||
NS_IMETHOD GetSource(nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
PRBool tv,
|
||||
nsIRDFResource** source);
|
||||
|
||||
NS_IMETHOD GetSources(nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor** sources);
|
||||
|
||||
NS_IMETHOD GetTarget(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
PRBool tv,
|
||||
nsIRDFNode** target);
|
||||
|
||||
NS_IMETHOD GetTargets(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor** targets);
|
||||
|
||||
NS_IMETHOD Assert(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
PRBool tv);
|
||||
|
||||
NS_IMETHOD Unassert(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
nsIRDFNode* target);
|
||||
|
||||
NS_IMETHOD HasAssertion(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
PRBool tv,
|
||||
PRBool* hasAssertion);
|
||||
|
||||
NS_IMETHOD AddObserver(nsIRDFObserver* n);
|
||||
|
||||
NS_IMETHOD RemoveObserver(nsIRDFObserver* n);
|
||||
|
||||
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
|
||||
nsIRDFArcsInCursor** labels);
|
||||
|
||||
NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
|
||||
nsIRDFArcsOutCursor** labels);
|
||||
|
||||
NS_IMETHOD Flush();
|
||||
|
||||
// nsIRDFDataBase interface
|
||||
NS_IMETHOD AddDataSource(nsIRDFDataSource* source);
|
||||
NS_IMETHOD RemoveDataSource(nsIRDFDataSource* source);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
SimpleDataBaseImpl::SimpleDataBaseImpl(void)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
|
||||
SimpleDataBaseImpl::~SimpleDataBaseImpl(void)
|
||||
{
|
||||
for (PRInt32 i = mDataSources.Count() - 1; i >= 0; --i) {
|
||||
nsIRDFDataSource* ds = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[i]);
|
||||
NS_IF_RELEASE(ds);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsISupports interface
|
||||
|
||||
NS_IMPL_ADDREF(SimpleDataBaseImpl);
|
||||
NS_IMPL_RELEASE(SimpleDataBaseImpl);
|
||||
|
||||
NS_IMETHODIMP
|
||||
SimpleDataBaseImpl::QueryInterface(REFNSIID iid, void** result)
|
||||
{
|
||||
if (! result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*result = nsnull;
|
||||
if (iid.Equals(kIRDFDataBaseIID) ||
|
||||
iid.Equals(kIRDFDataSourceIID) ||
|
||||
iid.Equals(kISupportsIID)) {
|
||||
*result = NS_STATIC_CAST(nsIRDFDataBase*, this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsIRDFDataSource interface
|
||||
|
||||
NS_IMETHODIMP
|
||||
SimpleDataBaseImpl::Init(const char* uri)
|
||||
{
|
||||
PR_ASSERT(0);
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SimpleDataBaseImpl::GetSource(nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
PRBool tv,
|
||||
nsIRDFResource** source)
|
||||
{
|
||||
PRInt32 count = mDataSources.Count();
|
||||
for (PRInt32 i = 0; i < count; ++i) {
|
||||
nsIRDFDataSource* ds = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[i]);
|
||||
|
||||
if (NS_FAILED(ds->GetSource(property, target, tv, source)))
|
||||
continue;
|
||||
|
||||
// okay, found it. make sure we don't have the opposite
|
||||
// asserted in the "local" data source
|
||||
nsIRDFDataSource* ds0 = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[0]);
|
||||
nsIRDFResource* tmp;
|
||||
if (NS_FAILED(ds->GetSource(property, target, !tv, &tmp)))
|
||||
return NS_OK;
|
||||
|
||||
NS_RELEASE(tmp);
|
||||
NS_RELEASE(*source);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SimpleDataBaseImpl::GetSources(nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor** sources)
|
||||
{
|
||||
PR_ASSERT(0);
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SimpleDataBaseImpl::GetTarget(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
PRBool tv,
|
||||
nsIRDFNode** target)
|
||||
{
|
||||
PRInt32 count = mDataSources.Count();
|
||||
for (PRInt32 i = 0; i < count; ++i) {
|
||||
nsIRDFDataSource* ds = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[i]);
|
||||
|
||||
if (NS_FAILED(ds->GetTarget(source, property, tv, target)))
|
||||
continue;
|
||||
|
||||
// okay, found it. make sure we don't have the opposite
|
||||
// asserted in the "local" data source
|
||||
nsIRDFDataSource* ds0 = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[0]);
|
||||
nsIRDFNode* tmp;
|
||||
if (NS_FAILED(ds0->GetTarget(source, property, !tv, &tmp)))
|
||||
return NS_OK;
|
||||
|
||||
NS_RELEASE(tmp);
|
||||
NS_RELEASE(*target);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SimpleDataBaseImpl::GetTargets(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor** targets)
|
||||
{
|
||||
if (! targets)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsIRDFAssertionCursor* result;
|
||||
result = new SimpleDBAssertionCursorImpl(mDataSources, source, property, tv);
|
||||
if (! result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(result);
|
||||
*targets = result;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SimpleDataBaseImpl::Assert(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
PRBool tv)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// First see if we just need to remove a negative assertion from ds0. (Sigh)
|
||||
nsIRDFDataSource* ds0 = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[0]);
|
||||
|
||||
PRBool ds0HasNegation;
|
||||
if (NS_FAILED(rv = ds0->HasAssertion(source, property, target, !tv, &ds0HasNegation)))
|
||||
return rv;
|
||||
|
||||
if (ds0HasNegation) {
|
||||
if (NS_FAILED(rv = ds0->Unassert(source, property, target)))
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Now, see if the assertion has been "unmasked"
|
||||
PRBool isAlreadyAsserted;
|
||||
if (NS_FAILED(rv = HasAssertion(source, property, target, tv, &isAlreadyAsserted)))
|
||||
return rv;
|
||||
|
||||
if (isAlreadyAsserted)
|
||||
return NS_OK;
|
||||
|
||||
// If not, iterate from the "remote-est" data source to the
|
||||
// "local-est", trying to make the assertion.
|
||||
for (PRInt32 i = mDataSources.Count() - 1; i >= 0; --i) {
|
||||
nsIRDFDataSource* ds = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[i]);
|
||||
if (NS_SUCCEEDED(ds->Assert(source, property, target, tv)))
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SimpleDataBaseImpl::Unassert(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
nsIRDFNode* target)
|
||||
{
|
||||
// XXX I have no idea what this is trying to do. I'm just going to
|
||||
// copy Guha's logic and punt.
|
||||
// xxx rvg - first need to check whether the data source does have the
|
||||
// assertion. Only then do you try to unassert it.
|
||||
nsresult rv;
|
||||
PRInt32 count = mDataSources.Count();
|
||||
|
||||
for (PRInt32 i = 0; i < count; ++i) {
|
||||
nsIRDFDataSource* ds = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[i]);
|
||||
if (NS_FAILED(rv = ds->Unassert(source, property, target)))
|
||||
break;
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
nsIRDFDataSource* ds0 = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[0]);
|
||||
rv = ds0->Assert(source, property, target, PR_FALSE);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SimpleDataBaseImpl::HasAssertion(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
PRBool tv,
|
||||
PRBool* hasAssertion)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// First check to see if ds0 has the negation...
|
||||
nsIRDFDataSource* ds0 = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[0]);
|
||||
|
||||
PRBool ds0HasNegation;
|
||||
if (NS_FAILED(rv = ds0->HasAssertion(source, property, target, !tv, &ds0HasNegation)))
|
||||
return rv;
|
||||
|
||||
if (ds0HasNegation) {
|
||||
*hasAssertion = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Otherwise, look through all the data sources to see if anyone
|
||||
// has the positive...
|
||||
PRInt32 count = mDataSources.Count();
|
||||
for (PRInt32 i = 0; i < count; ++i) {
|
||||
nsIRDFDataSource* ds = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[i]);
|
||||
if (NS_FAILED(rv = ds->HasAssertion(source, property, target, tv, hasAssertion)))
|
||||
return rv;
|
||||
|
||||
if (hasAssertion)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// If we get here, nobody had the assertion at all
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SimpleDataBaseImpl::AddObserver(nsIRDFObserver* n)
|
||||
{
|
||||
PR_ASSERT(0);
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SimpleDataBaseImpl::RemoveObserver(nsIRDFObserver* n)
|
||||
{
|
||||
PR_ASSERT(0);
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SimpleDataBaseImpl::ArcLabelsIn(nsIRDFNode* node,
|
||||
nsIRDFArcsInCursor** labels)
|
||||
{
|
||||
PR_ASSERT(0);
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SimpleDataBaseImpl::ArcLabelsOut(nsIRDFResource* source,
|
||||
nsIRDFArcsOutCursor** labels)
|
||||
{
|
||||
if (! labels)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsIRDFArcsOutCursor* result = new SimpleDBArcsOutCursorImpl(mDataSources, source);
|
||||
if (! result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_ADDREF(result);
|
||||
*labels = result;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SimpleDataBaseImpl::Flush()
|
||||
{
|
||||
for (PRInt32 i = mDataSources.Count() - 1; i >= 0; --i) {
|
||||
nsIRDFDataSource* ds = NS_STATIC_CAST(nsIRDFDataSource*, mDataSources[i]);
|
||||
ds->Flush();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsIRDFDataBase methods
|
||||
// XXX rvg We should make this take an additional argument specifying where
|
||||
// in the sequence of data sources (of the db), the new data source should
|
||||
// fit in. Right now, the new datasource gets stuck at the end.
|
||||
|
||||
NS_IMETHODIMP
|
||||
SimpleDataBaseImpl::AddDataSource(nsIRDFDataSource* source)
|
||||
{
|
||||
if (! source)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
mDataSources.InsertElementAt(source, 0);
|
||||
NS_ADDREF(source);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
SimpleDataBaseImpl::RemoveDataSource(nsIRDFDataSource* source)
|
||||
{
|
||||
if (! source)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (mDataSources.IndexOf(source) >= 0) {
|
||||
mDataSources.RemoveElement(source);
|
||||
NS_RELEASE(source);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult
|
||||
NS_NewRDFSimpleDataBase(nsIRDFDataBase** result)
|
||||
{
|
||||
SimpleDataBaseImpl* db = new SimpleDataBaseImpl();
|
||||
if (! db)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
*result = db;
|
||||
NS_ADDREF(*result);
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,496 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIRDFDataBase.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFResourceManager.h"
|
||||
#include "nsString.h"
|
||||
#include "rdfutil.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// RDF core vocabulary
|
||||
|
||||
#include "rdf.h"
|
||||
#define RDF_NAMESPACE_URI "http://www.w3.org/TR/WD-rdf-syntax#"
|
||||
static const char kRDFNameSpaceURI[] = RDF_NAMESPACE_URI;
|
||||
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, Alt);
|
||||
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, Bag);
|
||||
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, Description);
|
||||
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, ID);
|
||||
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, RDF);
|
||||
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, Seq);
|
||||
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, about);
|
||||
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, aboutEach);
|
||||
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, nextVal); // ad hoc way to make containers fast
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
|
||||
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
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;
|
||||
|
||||
nsAutoString tag(uri);
|
||||
tag.Cut(0, sizeof(kRDFNameSpaceURI) - 1);
|
||||
|
||||
if (tag[0] != '_')
|
||||
return PR_FALSE;
|
||||
|
||||
for (PRInt32 i = tag.Length() - 1; i >= 1; --i) {
|
||||
if (tag[i] < '0' || tag[i] > '9')
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
|
||||
PRBool
|
||||
rdf_IsContainer(nsIRDFResourceManager* mgr,
|
||||
nsIRDFDataSource* ds,
|
||||
nsIRDFResource* resource)
|
||||
{
|
||||
PRBool result = PR_FALSE;
|
||||
|
||||
nsIRDFResource* RDF_instanceOf = nsnull;
|
||||
nsIRDFResource* RDF_Bag = nsnull;
|
||||
nsIRDFResource* RDF_Seq = nsnull;
|
||||
|
||||
nsresult rv;
|
||||
if (NS_FAILED(rv = mgr->GetResource(kURIRDF_instanceOf, &RDF_instanceOf)))
|
||||
goto done;
|
||||
|
||||
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)))
|
||||
goto done;
|
||||
|
||||
if (result)
|
||||
goto done;
|
||||
|
||||
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)))
|
||||
goto done;
|
||||
|
||||
done:
|
||||
NS_IF_RELEASE(RDF_Seq);
|
||||
NS_IF_RELEASE(RDF_Bag);
|
||||
NS_IF_RELEASE(RDF_instanceOf);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// A complete hack that looks at the string value of a node and
|
||||
// guesses if it's a resource
|
||||
static PRBool
|
||||
rdf_IsResource(const nsString& s)
|
||||
{
|
||||
PRInt32 index;
|
||||
|
||||
// A URI needs a colon.
|
||||
index = s.Find(':');
|
||||
if (index < 0)
|
||||
return PR_FALSE;
|
||||
|
||||
// Assume some sane maximum for protocol specs
|
||||
#define MAX_PROTOCOL_SPEC 10
|
||||
if (index > MAX_PROTOCOL_SPEC)
|
||||
return PR_FALSE;
|
||||
|
||||
// It can't have spaces or newlines or tabs
|
||||
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(nsIRDFResourceManager* mgr, // unused
|
||||
nsIRDFDataSource* ds,
|
||||
nsIRDFResource* subject,
|
||||
nsIRDFResource* predicate,
|
||||
nsIRDFNode* object)
|
||||
{
|
||||
NS_ASSERTION(ds, "null ptr");
|
||||
NS_ASSERTION(subject, "null ptr");
|
||||
NS_ASSERTION(predicate, "null ptr");
|
||||
NS_ASSERTION(object, "null ptr");
|
||||
|
||||
#ifdef DEBUG
|
||||
const char* s;
|
||||
|
||||
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, PR_TRUE);
|
||||
}
|
||||
|
||||
|
||||
// 1. string, string, string
|
||||
nsresult
|
||||
rdf_Assert(nsIRDFResourceManager* mgr,
|
||||
nsIRDFDataSource* ds,
|
||||
const nsString& subjectURI,
|
||||
const nsString& predicateURI,
|
||||
const nsString& objectURI)
|
||||
{
|
||||
NS_ASSERTION(mgr, "null ptr");
|
||||
NS_ASSERTION(ds, "null ptr");
|
||||
|
||||
nsresult rv;
|
||||
nsIRDFResource* subject;
|
||||
if (NS_FAILED(rv = mgr->GetUnicodeResource(subjectURI, &subject)))
|
||||
return rv;
|
||||
|
||||
rv = rdf_Assert(mgr, ds, subject, predicateURI, objectURI);
|
||||
NS_RELEASE(subject);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
// 2. node, node, string
|
||||
nsresult
|
||||
rdf_Assert(nsIRDFResourceManager* mgr,
|
||||
nsIRDFDataSource* ds,
|
||||
nsIRDFResource* subject,
|
||||
nsIRDFResource* predicate,
|
||||
const nsString& objectURI)
|
||||
{
|
||||
NS_ASSERTION(mgr, "null ptr");
|
||||
NS_ASSERTION(ds, "null ptr");
|
||||
NS_ASSERTION(subject, "null ptr");
|
||||
|
||||
nsresult rv;
|
||||
nsIRDFNode* 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;
|
||||
}
|
||||
|
||||
|
||||
// 3. node, string, string
|
||||
nsresult
|
||||
rdf_Assert(nsIRDFResourceManager* mgr,
|
||||
nsIRDFDataSource* ds,
|
||||
nsIRDFResource* subject,
|
||||
const nsString& predicateURI,
|
||||
const nsString& objectURI)
|
||||
{
|
||||
NS_ASSERTION(mgr, "null ptr");
|
||||
NS_ASSERTION(ds, "null ptr");
|
||||
NS_ASSERTION(subject, "null ptr");
|
||||
|
||||
nsresult rv;
|
||||
nsIRDFResource* predicate;
|
||||
if (NS_FAILED(rv = mgr->GetUnicodeResource(predicateURI, &predicate)))
|
||||
return rv;
|
||||
|
||||
rv = rdf_Assert(mgr, ds, subject, predicate, objectURI);
|
||||
NS_RELEASE(predicate);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
// 4. node, string, node
|
||||
nsresult
|
||||
rdf_Assert(nsIRDFResourceManager* mgr,
|
||||
nsIRDFDataSource* ds,
|
||||
nsIRDFResource* subject,
|
||||
const nsString& predicateURI,
|
||||
nsIRDFNode* object)
|
||||
{
|
||||
NS_ASSERTION(mgr, "null ptr");
|
||||
NS_ASSERTION(ds, "null ptr");
|
||||
NS_ASSERTION(subject, "null ptr");
|
||||
NS_ASSERTION(object, "null ptr");
|
||||
|
||||
nsresult rv;
|
||||
nsIRDFResource* predicate;
|
||||
if (NS_FAILED(rv = mgr->GetUnicodeResource(predicateURI, &predicate)))
|
||||
return rv;
|
||||
|
||||
rv = rdf_Assert(mgr, ds, subject, predicate, object);
|
||||
NS_RELEASE(predicate);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
// 5. string, string, node
|
||||
nsresult
|
||||
rdf_Assert(nsIRDFResourceManager* mgr,
|
||||
nsIRDFDataSource* ds,
|
||||
const nsString& subjectURI,
|
||||
const nsString& predicateURI,
|
||||
nsIRDFNode* object)
|
||||
{
|
||||
NS_ASSERTION(mgr, "null ptr");
|
||||
NS_ASSERTION(ds, "null ptr");
|
||||
|
||||
nsresult rv;
|
||||
nsIRDFResource* subject;
|
||||
if (NS_FAILED(rv = mgr->GetUnicodeResource(subjectURI, &subject)))
|
||||
return rv;
|
||||
|
||||
rv = rdf_Assert(mgr, ds, subject, predicateURI, object);
|
||||
NS_RELEASE(subject);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
rdf_CreateAnonymousResource(nsIRDFResourceManager* mgr,
|
||||
nsIRDFResource** result)
|
||||
{
|
||||
static PRUint32 gCounter = 0;
|
||||
|
||||
nsAutoString s = "$";
|
||||
s.Append(++gCounter, 10);
|
||||
|
||||
return mgr->GetUnicodeResource(s, result);
|
||||
}
|
||||
|
||||
nsresult
|
||||
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;
|
||||
|
||||
// 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)))
|
||||
return rv;
|
||||
|
||||
if (NS_FAILED(rv = rdf_Assert(mgr, ds, bag, kURIRDF_nextVal, "1")))
|
||||
return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
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;
|
||||
|
||||
// XXX check to see if someone else has already made this into a container.
|
||||
|
||||
if (NS_FAILED(rv = rdf_Assert(mgr, ds, seq, kURIRDF_instanceOf, kURIRDF_Seq)))
|
||||
return rv;
|
||||
|
||||
if (NS_FAILED(rv = rdf_Assert(mgr, ds, seq, kURIRDF_nextVal, "1")))
|
||||
return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
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;
|
||||
|
||||
// XXX check to see if someone else has already made this into a container.
|
||||
|
||||
if (NS_FAILED(rv = rdf_Assert(mgr, ds, alt, kURIRDF_instanceOf, kURIRDF_Alt)))
|
||||
return rv;
|
||||
|
||||
if (NS_FAILED(rv = rdf_Assert(mgr, ds, alt, kURIRDF_nextVal, "1")))
|
||||
return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
static nsresult
|
||||
rdf_ContainerGetNextValue(nsIRDFResourceManager* mgr,
|
||||
nsIRDFDataSource* ds,
|
||||
nsIRDFResource* container,
|
||||
nsIRDFResource** result)
|
||||
{
|
||||
NS_ASSERTION(mgr, "null ptr");
|
||||
NS_ASSERTION(ds, "null ptr");
|
||||
NS_ASSERTION(container, "null ptr");
|
||||
|
||||
nsresult rv;
|
||||
nsIRDFResource* RDF_nextVal = nsnull;
|
||||
nsIRDFNode* nextValNode = nsnull;
|
||||
nsIRDFLiteral* nextValLiteral = nsnull;
|
||||
const PRUnichar* s;
|
||||
nsAutoString nextValStr;
|
||||
PRInt32 nextVal;
|
||||
PRInt32 err;
|
||||
|
||||
// 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, RDF_nextVal, PR_TRUE, &nextValNode)))
|
||||
goto done;
|
||||
|
||||
if (NS_FAILED(rv = nextValNode->QueryInterface(kIRDFLiteralIID, (void**) &nextValLiteral)))
|
||||
goto done;
|
||||
|
||||
if (NS_FAILED(rv = nextValLiteral->GetValue(&s)))
|
||||
goto done;
|
||||
|
||||
nextValStr = s;
|
||||
nextVal = nextValStr.ToInteger(&err);
|
||||
if (NS_FAILED(err))
|
||||
goto done;
|
||||
|
||||
// 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;
|
||||
|
||||
// Now increment the RDF:nextVal property.
|
||||
if (NS_FAILED(rv = ds->Unassert(container, RDF_nextVal, nextValLiteral)))
|
||||
goto done;
|
||||
|
||||
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(nextValLiteral);
|
||||
NS_IF_RELEASE(nextValNode);
|
||||
NS_IF_RELEASE(RDF_nextVal);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
rdf_ContainerAddElement(nsIRDFResourceManager* mgr,
|
||||
nsIRDFDataSource* ds,
|
||||
nsIRDFResource* container,
|
||||
nsIRDFNode* element)
|
||||
{
|
||||
NS_ASSERTION(mgr, "null ptr");
|
||||
NS_ASSERTION(ds, "null ptr");
|
||||
NS_ASSERTION(container, "null ptr");
|
||||
NS_ASSERTION(element, "null ptr");
|
||||
|
||||
nsresult rv;
|
||||
|
||||
nsIRDFResource* nextVal;
|
||||
|
||||
if (NS_FAILED(rv = rdf_ContainerGetNextValue(mgr, ds, container, &nextVal)))
|
||||
goto done;
|
||||
|
||||
if (rv = rdf_Assert(mgr, ds, container, nextVal, element))
|
||||
goto done;
|
||||
|
||||
done:
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,178 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
|
||||
// XXX This should really be a first-class utility interface that's
|
||||
// available via the service manager. The only reason that I'm not
|
||||
// making it so right now is to keep stuff light and easy to hack.
|
||||
|
||||
#ifndef rdfutil_h__
|
||||
#define rdfutil_h__
|
||||
|
||||
#include "prtypes.h"
|
||||
|
||||
class nsIRDFCursor;
|
||||
class nsIRDFDataBase;
|
||||
class nsIRDFDataSource;
|
||||
class nsIRDFNode;
|
||||
class nsIRDFResourceManager;
|
||||
class nsString;
|
||||
|
||||
/**
|
||||
* Returns PR_TRUE if the URI is an RDF ordinal property; e.g., rdf:_1,
|
||||
* rdf:_2, etc.
|
||||
*/
|
||||
PR_EXTERN(PRBool)
|
||||
rdf_IsOrdinalProperty(const nsIRDFResource* property);
|
||||
|
||||
|
||||
/**
|
||||
* Returns PR_TRUE if the resource is a container resource; e.g., an
|
||||
* rdf:Bag.
|
||||
*/
|
||||
PR_EXTERN(PRBool)
|
||||
rdf_IsContainer(nsIRDFResourceManager* mgr,
|
||||
nsIRDFDataSource* db,
|
||||
nsIRDFResource* resource);
|
||||
|
||||
|
||||
/**
|
||||
* Various utilities routines for making assertions in a data source
|
||||
*/
|
||||
|
||||
// 0. node, node, node
|
||||
PR_EXTERN(nsresult)
|
||||
rdf_Assert(nsIRDFResourceManager* mgr, // unused
|
||||
nsIRDFDataSource* ds,
|
||||
nsIRDFResource* subject,
|
||||
nsIRDFResource* predicate,
|
||||
nsIRDFNode* object);
|
||||
|
||||
// 1. string, string, string
|
||||
PR_EXTERN(nsresult)
|
||||
rdf_Assert(nsIRDFResourceManager* mgr,
|
||||
nsIRDFDataSource* ds,
|
||||
const nsString& subjectURI,
|
||||
const nsString& predicateURI,
|
||||
const nsString& objectURI);
|
||||
|
||||
// 2. node, node, string
|
||||
PR_EXTERN(nsresult)
|
||||
rdf_Assert(nsIRDFResourceManager* mgr,
|
||||
nsIRDFDataSource* ds,
|
||||
nsIRDFResource* subject,
|
||||
nsIRDFResource* predicate,
|
||||
const nsString& objectURI);
|
||||
|
||||
// 3. node, string, string
|
||||
PR_EXTERN(nsresult)
|
||||
rdf_Assert(nsIRDFResourceManager* mgr,
|
||||
nsIRDFDataSource* ds,
|
||||
nsIRDFResource* subject,
|
||||
const nsString& predicateURI,
|
||||
const nsString& objectURI);
|
||||
|
||||
// 4. node, string, node
|
||||
PR_EXTERN(nsresult)
|
||||
rdf_Assert(nsIRDFResourceManager* mgr,
|
||||
nsIRDFDataSource* ds,
|
||||
nsIRDFResource* subject,
|
||||
const nsString& predicateURI,
|
||||
nsIRDFNode* object);
|
||||
|
||||
// 5. string, string, node
|
||||
PR_EXTERN(nsresult)
|
||||
rdf_Assert(nsIRDFResourceManager* mgr,
|
||||
nsIRDFDataSource* ds,
|
||||
const nsString& subjectURI,
|
||||
const nsString& predicateURI,
|
||||
nsIRDFNode* object);
|
||||
|
||||
/**
|
||||
* Construct a new, "anonymous" node; that is, a node with an internal
|
||||
* resource URI.
|
||||
*/
|
||||
PR_EXTERN(nsresult)
|
||||
rdf_CreateAnonymousResource(nsIRDFResourceManager* mgr,
|
||||
nsIRDFResource** result);
|
||||
|
||||
|
||||
/**
|
||||
* Create a bag resource.
|
||||
*/
|
||||
PR_EXTERN(nsresult)
|
||||
rdf_MakeBag(nsIRDFResourceManager* mgr,
|
||||
nsIRDFDataSource* ds,
|
||||
nsIRDFResource* resource);
|
||||
|
||||
/**
|
||||
* Create a sequence resource.
|
||||
*/
|
||||
PR_EXTERN(nsresult)
|
||||
rdf_MakeSeq(nsIRDFResourceManager* mgr,
|
||||
nsIRDFDataSource* ds,
|
||||
nsIRDFResource* resource);
|
||||
|
||||
/**
|
||||
* Create an alternation resource.
|
||||
*/
|
||||
PR_EXTERN(nsresult)
|
||||
rdf_MakeAlt(nsIRDFResourceManager* mgr,
|
||||
nsIRDFDataSource* ds,
|
||||
nsIRDFResource* resource);
|
||||
|
||||
|
||||
/**
|
||||
* Add an element to the container.
|
||||
*/
|
||||
PR_EXTERN(nsresult)
|
||||
rdf_ContainerAddElement(nsIRDFResourceManager* mgr,
|
||||
nsIRDFDataSource* ds,
|
||||
nsIRDFResource* container,
|
||||
nsIRDFNode* element);
|
||||
|
||||
/**
|
||||
* Create a cursor on a container that enumerates its contents in
|
||||
* order
|
||||
*/
|
||||
PR_EXTERN(nsresult)
|
||||
NS_NewContainerCursor(nsIRDFDataSource* ds,
|
||||
nsIRDFResource* container,
|
||||
nsIRDFAssertionCursor** cursor);
|
||||
|
||||
|
||||
/**
|
||||
* Create an empty nsIRDFCursor. This will *never* fail, and will *always*
|
||||
* return the same object.
|
||||
*/
|
||||
PR_EXTERN(nsresult)
|
||||
NS_NewEmptyRDFAssertionCursor(nsIRDFAssertionCursor** result);
|
||||
|
||||
PR_EXTERN(nsresult)
|
||||
NS_NewEmptyRDFArcsInCursor(nsIRDFArcsInCursor** result);
|
||||
|
||||
PR_EXTERN(nsresult)
|
||||
NS_NewEmptyRDFArcsOutCursor(nsIRDFArcsOutCursor** result);
|
||||
|
||||
|
||||
// XXX need to move nsEmptyCursor stuff here.
|
||||
|
||||
#endif // rdfutil_h__
|
||||
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH = ../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = public src
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
|
@ -0,0 +1,27 @@
|
|||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..\..
|
||||
|
||||
MODULE = rdf
|
||||
|
||||
DIRS=\
|
||||
public \
|
||||
src \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
|
@ -0,0 +1,4 @@
|
|||
nsIRDFContent.h
|
||||
nsIRDFContentSink.h
|
||||
nsIRDFDocument.h
|
||||
nsRDFContentCID.h
|
|
@ -0,0 +1,38 @@
|
|||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH = ../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = rdf
|
||||
|
||||
EXPORTS = \
|
||||
nsIRDFContent.h \
|
||||
nsIRDFContentSink.h \
|
||||
nsIRDFDocument.h \
|
||||
nsRDFContentCID.h \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
|
@ -0,0 +1,31 @@
|
|||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
|
||||
MODULE=rdf
|
||||
|
||||
DEPTH=..\..\..
|
||||
|
||||
EXPORTS = \
|
||||
nsIRDFContent.h \
|
||||
nsIRDFContentSink.h \
|
||||
nsIRDFDocument.h \
|
||||
nsRDFContentCID.h \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)/config/rules.mak>
|
||||
|
|
@ -0,0 +1,58 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsIRDFContent_h___
|
||||
#define nsIRDFContent_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIXMLContent.h"
|
||||
|
||||
class nsIRDFContent;
|
||||
class nsIRDFDocument;
|
||||
class nsIRDFResource;
|
||||
|
||||
// {954F0810-81DC-11d2-B52A-000000000000}
|
||||
#define NS_IRDFCONTENT_IID \
|
||||
{ 0x954f0810, 0x81dc, 0x11d2, { 0xb5, 0x2a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
|
||||
|
||||
/**
|
||||
* RDF content extensions to nsIXMLContent
|
||||
*/
|
||||
class nsIRDFContent : public nsIXMLContent {
|
||||
public:
|
||||
NS_IMETHOD Init(nsIRDFDocument* doc,
|
||||
const nsString& tag,
|
||||
nsIRDFResource* resource,
|
||||
PRBool childrenMustBeGenerated) = 0;
|
||||
|
||||
NS_IMETHOD SetResource(const nsString& aURI) = 0;
|
||||
NS_IMETHOD GetResource(nsString& rURI) const = 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;
|
||||
};
|
||||
|
||||
|
||||
extern nsresult
|
||||
NS_NewRDFElement(nsIRDFContent** aResult);
|
||||
|
||||
#endif // nsIRDFContent_h___
|
|
@ -0,0 +1,69 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
#ifndef nsIRDFContentSink_h___
|
||||
#define nsIRDFContentSink_h___
|
||||
|
||||
#include "nsIXMLContentSink.h"
|
||||
class nsIRDFDataSource;
|
||||
class nsINameSpaceManager;
|
||||
|
||||
// {751843E2-8309-11d2-8EAC-00805F29F370}
|
||||
#define NS_IRDFCONTENTSINK_IID \
|
||||
{ 0x751843e2, 0x8309, 0x11d2, { 0x8e, 0xac, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
|
||||
|
||||
/**
|
||||
* This interface represents a content sink for RDF files.
|
||||
*/
|
||||
|
||||
class nsIRDFContentSink : public nsIXMLContentSink {
|
||||
public:
|
||||
/**
|
||||
* Set the content sink's RDF Data source
|
||||
*/
|
||||
NS_IMETHOD SetDataSource(nsIRDFDataSource* ds) = 0;
|
||||
|
||||
/**
|
||||
* Retrieve the content sink's RDF data source.
|
||||
*/
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource*& result) = 0;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* This constructs a content sink that is intended to be used
|
||||
* with an nsIDocument to construct a content model.
|
||||
*/
|
||||
nsresult
|
||||
NS_NewRDFDocumentContentSink(nsIRDFContentSink** aResult,
|
||||
nsIDocument* aDoc,
|
||||
nsIURL* aURL,
|
||||
nsIWebShell* aWebShell);
|
||||
|
||||
|
||||
/**
|
||||
* This constructs a content sink that can be used without a
|
||||
* document, say, to create a stand-alone in-memory graph.
|
||||
*/
|
||||
nsresult
|
||||
NS_NewRDFSimpleContentSink(nsIRDFContentSink** aResult,
|
||||
nsIURL* aURL,
|
||||
nsINameSpaceManager* aNameSpaceManager);
|
||||
|
||||
|
||||
#endif // nsIRDFContentSink_h___
|
|
@ -0,0 +1,87 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsIRDFDocument_h___
|
||||
#define nsIRDFDocument_h___
|
||||
|
||||
#include "nsIXMLDocument.h"
|
||||
|
||||
class nsIRDFContent;
|
||||
class nsIRDFDataBase;
|
||||
class nsISupportsArray;
|
||||
class nsIRDFResource;
|
||||
|
||||
// {954F0811-81DC-11d2-B52A-000000000000}
|
||||
#define NS_IRDFDOCUMENT_IID \
|
||||
{ 0x954f0811, 0x81dc, 0x11d2, { 0xb5, 0x2a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
|
||||
|
||||
/**
|
||||
* RDF document extensions to nsIDocument
|
||||
*/
|
||||
class nsIRDFDocument : public nsIXMLDocument {
|
||||
public:
|
||||
/**
|
||||
* Initialize the document object. This will force the document to create
|
||||
* its internal RDF database.
|
||||
*/
|
||||
NS_IMETHOD Init(void) = 0;
|
||||
|
||||
/**
|
||||
* Set the document's "root" resource.
|
||||
*/
|
||||
NS_IMETHOD SetRootResource(nsIRDFResource* aResource) = 0;
|
||||
|
||||
/**
|
||||
* Retrieve the document's RDF data base.
|
||||
*/
|
||||
NS_IMETHOD GetDataBase(nsIRDFDataBase*& rDataBase) = 0;
|
||||
|
||||
/**
|
||||
* Given an nsIRDFContent element in the document, create its
|
||||
* "content children," that is, a set of nsIRDFContent elements that
|
||||
* should appear as the node's children in the content model.
|
||||
*/
|
||||
NS_IMETHOD CreateChildren(nsIRDFContent* element) = 0;
|
||||
|
||||
// XXX the following two methods should probably accept strings as
|
||||
// parameters so you can mess with them via JS. Also, should they
|
||||
// take a "notify" parameter that would control whether any viewers
|
||||
// of the content model should be informed that the content model is
|
||||
// invalid?
|
||||
|
||||
/**
|
||||
* Add a property to the set of "tree properties" that the document
|
||||
* should use when constructing the content model from the RDF
|
||||
* graph.
|
||||
*/
|
||||
NS_IMETHOD AddTreeProperty(nsIRDFResource* resource) = 0;
|
||||
|
||||
/**
|
||||
* Remove a property from the set of "tree properties" that the
|
||||
* document should use when constructing the content model from the
|
||||
* RDF graph.
|
||||
*/
|
||||
NS_IMETHOD RemoveTreeProperty(nsIRDFResource* resource) = 0;
|
||||
};
|
||||
|
||||
// factory functions
|
||||
nsresult NS_NewRDFHTMLDocument(nsIRDFDocument** result);
|
||||
nsresult NS_NewRDFTreeDocument(nsIRDFDocument** result);
|
||||
|
||||
#endif // nsIRDFDocument_h___
|
|
@ -0,0 +1,35 @@
|
|||
/* -*- 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 nsRDFCID_h__
|
||||
#define nsRDFCID_h__
|
||||
|
||||
// {954F0813-81DC-11d2-B52A-000000000000}
|
||||
#define NS_RDFHTMLDOCUMENT_CID \
|
||||
{ 0x954f0813, 0x81dc, 0x11d2, { 0xb5, 0x2a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
|
||||
|
||||
// {3D262D00-8B5A-11d2-8EB0-00805F29F370}
|
||||
#define NS_RDFTREEDOCUMENT_CID \
|
||||
{ 0x3d262d00, 0x8b5a, 0x11d2, { 0x8e, 0xb0, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
|
||||
|
||||
// {0958B101-9ADA-11d2-8EBC-00805F29F370}
|
||||
#define NS_RDFDOCUMENTCONTENTSINK_CID \
|
||||
{ 0x958b101, 0x9ada, 0x11d2, { 0x8e, 0xbc, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } }
|
||||
|
||||
|
||||
#endif // nsRDFCID_h__
|
|
@ -0,0 +1,57 @@
|
|||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
LIBRARY_NAME = rdf
|
||||
|
||||
CPPSRCS = \
|
||||
nsRDFContentFactory.cpp \
|
||||
nsRDFContentSink.cpp \
|
||||
nsRDFDocument.cpp \
|
||||
nsRDFDocumentContentSink.cpp \
|
||||
nsRDFElement.cpp \
|
||||
nsRDFHTMLDocument.cpp \
|
||||
nsRDFTreeDocument.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
||||
|
||||
MODULE = rdf
|
||||
|
||||
REQUIRES = dom js netlib rdf raptor xpcom
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
|
||||
export::
|
||||
|
||||
install:: $(TARGETS)
|
||||
|
||||
|
||||
clobber::
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..\..\..
|
||||
MODULE=rdfcontent
|
||||
|
||||
MAKE_OBJ_TYPE=DLL
|
||||
DLLNAME=$(MODULE)
|
||||
DLL=.\$(OBJDIR)\$(DLLNAME).dll
|
||||
|
||||
CPP_OBJS=\
|
||||
.\$(OBJDIR)\nsRDFContentFactory.obj \
|
||||
.\$(OBJDIR)\nsRDFContentSink.obj \
|
||||
.\$(OBJDIR)\nsRDFDocument.obj \
|
||||
.\$(OBJDIR)\nsRDFDocumentContentSink.obj \
|
||||
.\$(OBJDIR)\nsRDFElement.obj \
|
||||
.\$(OBJDIR)\nsRDFHTMLDocument.obj \
|
||||
.\$(OBJDIR)\nsRDFSimpleContentSink.obj \
|
||||
.\$(OBJDIR)\nsRDFTreeDocument.obj \
|
||||
$(NULL)
|
||||
|
||||
LLIBS=\
|
||||
$(DIST)\lib\rdfbase.lib \
|
||||
$(DIST)\lib\xpcom32.lib \
|
||||
$(DIST)\lib\raptorbase.lib \
|
||||
$(DIST)\lib\raptorgfxwin.lib \
|
||||
$(DIST)\lib\netlib.lib \
|
||||
$(DIST)\lib\libplc21.lib \
|
||||
$(LIBNSPR)
|
||||
|
||||
LINCS= -I$(PUBLIC)\rdf \
|
||||
-I$(PUBLIC)\xpcom \
|
||||
-I$(PUBLIC)\netlib \
|
||||
-I$(PUBLIC)\raptor \
|
||||
-I$(PUBLIC)\js \
|
||||
-I$(PUBLIC)\dom \
|
||||
-I$(DEPTH)\rdf\base\src \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(DLL)
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,156 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsIRDFResourceManager.h"
|
||||
#include "nsRDFDocument.h"
|
||||
#include "nsRDFContentCID.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
|
||||
static NS_DEFINE_CID(kRDFHTMLDocumentCID, NS_RDFHTMLDOCUMENT_CID);
|
||||
static NS_DEFINE_CID(kRDFTreeDocumentCID, NS_RDFTREEDOCUMENT_CID);
|
||||
|
||||
class RDFFactoryImpl : public nsIFactory
|
||||
{
|
||||
public:
|
||||
RDFFactoryImpl(const nsCID &aClass);
|
||||
|
||||
// nsISupports methods
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIFactory methods
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
protected:
|
||||
virtual ~RDFFactoryImpl();
|
||||
|
||||
private:
|
||||
nsCID mClassID;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
RDFFactoryImpl::RDFFactoryImpl(const nsCID &aClass)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mClassID = aClass;
|
||||
}
|
||||
|
||||
RDFFactoryImpl::~RDFFactoryImpl()
|
||||
{
|
||||
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
RDFFactoryImpl::QueryInterface(const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
// Always NULL result, in case of failure
|
||||
*aResult = nsnull;
|
||||
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aResult = NS_STATIC_CAST(nsISupports*, this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
} else if (aIID.Equals(kIFactoryIID)) {
|
||||
*aResult = NS_STATIC_CAST(nsIFactory*, this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(RDFFactoryImpl);
|
||||
NS_IMPL_RELEASE(RDFFactoryImpl);
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
RDFFactoryImpl::CreateInstance(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (aOuter)
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
*aResult = nsnull;
|
||||
|
||||
nsresult rv;
|
||||
PRBool wasRefCounted = PR_TRUE;
|
||||
nsISupports *inst = nsnull;
|
||||
if (mClassID.Equals(kRDFHTMLDocumentCID)) {
|
||||
if (NS_FAILED(rv = NS_NewRDFHTMLDocument((nsIRDFDocument**) &inst)))
|
||||
return rv;
|
||||
}
|
||||
else if (mClassID.Equals(kRDFTreeDocumentCID)) {
|
||||
if (NS_FAILED(rv = NS_NewRDFTreeDocument((nsIRDFDocument**) &inst)))
|
||||
return rv;
|
||||
}
|
||||
else {
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
|
||||
if (! inst)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
if (NS_FAILED(rv = inst->QueryInterface(aIID, aResult)))
|
||||
// We didn't get the right interface, so clean up
|
||||
delete inst;
|
||||
|
||||
if (wasRefCounted)
|
||||
NS_IF_RELEASE(inst);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult RDFFactoryImpl::LockFactory(PRBool aLock)
|
||||
{
|
||||
// Not implemented in simplest case.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
// return the proper factory to the caller
|
||||
extern "C" PR_IMPLEMENT(nsresult)
|
||||
NSGetFactory(const nsCID &aClass, nsIFactory **aFactory)
|
||||
{
|
||||
if (! aFactory)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aFactory = new RDFFactoryImpl(aClass);
|
||||
if (aFactory == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return (*aFactory)->QueryInterface(kIFactoryIID, (void**)aFactory);
|
||||
}
|
||||
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,132 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsRDFContentSink_h__
|
||||
#define nsRDFContentSink_h__
|
||||
|
||||
#include "nsIRDFContentSink.h"
|
||||
|
||||
class nsIURL;
|
||||
class nsVoidArray;
|
||||
class nsIRDFResource;
|
||||
class nsIRDFDataSource;
|
||||
class nsIRDFResourceManager;
|
||||
class nsINameSpaceManager;
|
||||
|
||||
typedef enum {
|
||||
eRDFContentSinkState_InProlog,
|
||||
eRDFContentSinkState_InDocumentElement,
|
||||
eRDFContentSinkState_InDescriptionElement,
|
||||
eRDFContentSinkState_InContainerElement,
|
||||
eRDFContentSinkState_InPropertyElement,
|
||||
eRDFContentSinkState_InMemberElement,
|
||||
eRDFContentSinkState_InEpilog
|
||||
} RDFContentSinkState;
|
||||
|
||||
|
||||
class nsRDFContentSink : public nsIRDFContentSink
|
||||
{
|
||||
public:
|
||||
nsRDFContentSink();
|
||||
virtual ~nsRDFContentSink();
|
||||
|
||||
virtual nsresult Init(nsIURL* aURL, nsINameSpaceManager* aNameSpaceManager);
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIContentSink
|
||||
NS_IMETHOD WillBuildModel(void);
|
||||
NS_IMETHOD DidBuildModel(PRInt32 aQualityLevel);
|
||||
NS_IMETHOD WillInterrupt(void);
|
||||
NS_IMETHOD WillResume(void);
|
||||
NS_IMETHOD SetParser(nsIParser* aParser);
|
||||
NS_IMETHOD OpenContainer(const nsIParserNode& aNode);
|
||||
NS_IMETHOD CloseContainer(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddLeaf(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddComment(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode);
|
||||
NS_IMETHOD NotifyError(nsresult aErrorResult);
|
||||
|
||||
// nsIXMLContentSink
|
||||
NS_IMETHOD AddXMLDecl(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddDocTypeDecl(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddCharacterData(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddUnparsedEntity(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddNotation(const nsIParserNode& aNode);
|
||||
NS_IMETHOD AddEntityReference(const nsIParserNode& aNode);
|
||||
|
||||
// nsIRDFContentSink
|
||||
NS_IMETHOD SetDataSource(nsIRDFDataSource* ds);
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource*& ds);
|
||||
|
||||
protected:
|
||||
// Text management
|
||||
nsresult FlushText(PRBool aCreateTextNode=PR_TRUE,
|
||||
PRBool* aDidFlush=nsnull);
|
||||
|
||||
PRUnichar* mText;
|
||||
PRInt32 mTextLength;
|
||||
PRInt32 mTextSize;
|
||||
PRBool mConstrainSize;
|
||||
|
||||
// namespace management
|
||||
void PushNameSpacesFrom(const nsIParserNode& aNode);
|
||||
nsIAtom* CutNameSpacePrefix(nsString& aString);
|
||||
PRInt32 GetNameSpaceID(nsIAtom* aPrefix);
|
||||
void GetNameSpaceURI(PRInt32 aID, nsString& aURI);
|
||||
void PopNameSpaces();
|
||||
|
||||
nsINameSpaceManager* mNameSpaceManager;
|
||||
nsVoidArray* mNameSpaceStack;
|
||||
PRInt32 mRDFNameSpaceID;
|
||||
|
||||
void SplitQualifiedName(const nsString& aQualifiedName,
|
||||
PRInt32& rNameSpaceID,
|
||||
nsString& rProperty);
|
||||
|
||||
// RDF-specific parsing
|
||||
nsresult GetIdAboutAttribute(const nsIParserNode& aNode, nsString& rResource);
|
||||
nsresult GetResourceAttribute(const nsIParserNode& aNode, nsString& rResource);
|
||||
nsresult AddProperties(const nsIParserNode& aNode, nsIRDFResource* aSubject);
|
||||
|
||||
virtual nsresult OpenRDF(const nsIParserNode& aNode);
|
||||
virtual nsresult OpenObject(const nsIParserNode& aNode);
|
||||
virtual nsresult OpenProperty(const nsIParserNode& aNode);
|
||||
virtual nsresult OpenMember(const nsIParserNode& aNode);
|
||||
virtual nsresult OpenValue(const nsIParserNode& aNode);
|
||||
|
||||
// Miscellaneous RDF junk
|
||||
nsIRDFResourceManager* mResourceMgr;
|
||||
nsIRDFDataSource* mDataSource;
|
||||
RDFContentSinkState mState;
|
||||
|
||||
// content stack management
|
||||
PRInt32 PushContext(nsIRDFResource *aContext, RDFContentSinkState aState);
|
||||
nsresult PopContext(nsIRDFResource*& rContext, RDFContentSinkState& rState);
|
||||
nsIRDFResource* GetContextElement(PRInt32 ancestor = 0);
|
||||
|
||||
nsVoidArray* mContextStack;
|
||||
|
||||
nsIURL* mDocumentURL;
|
||||
PRUint32 mGenSym; // for generating anonymous resources
|
||||
};
|
||||
|
||||
|
||||
#endif // nsRDFContentSink_h__
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,242 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsRDFDocument_h___
|
||||
#define nsRDFDocument_h___
|
||||
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIRDFDocument.h"
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
class nsIArena;
|
||||
class nsIParser;
|
||||
class nsISupportsArray;
|
||||
class nsINameSpaceManager;
|
||||
class nsIRDFNode;
|
||||
|
||||
/**
|
||||
* An NGLayout document context for displaying an RDF graph.
|
||||
* XXX This should implement nsIDOMDocument, too.
|
||||
*/
|
||||
class nsRDFDocument : public nsIDocument,
|
||||
public nsIRDFDocument
|
||||
{
|
||||
public:
|
||||
nsRDFDocument();
|
||||
virtual ~nsRDFDocument();
|
||||
|
||||
// nsISupports interface
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIDocument interface
|
||||
virtual nsIArena* GetArena();
|
||||
|
||||
NS_IMETHOD StartDocumentLoad(nsIURL *aUrl,
|
||||
nsIContentViewerContainer* aContainer,
|
||||
nsIStreamListener **aDocListener,
|
||||
const char* aCommand);
|
||||
|
||||
virtual const nsString* GetDocumentTitle() const;
|
||||
|
||||
virtual nsIURL* GetDocumentURL() const;
|
||||
|
||||
virtual nsIURLGroup* GetDocumentURLGroup() const;
|
||||
|
||||
virtual nsCharSetID GetDocumentCharacterSet() const;
|
||||
|
||||
virtual void SetDocumentCharacterSet(nsCharSetID aCharSetID);
|
||||
|
||||
virtual nsresult CreateShell(nsIPresContext* aContext,
|
||||
nsIViewManager* aViewManager,
|
||||
nsIStyleSet* aStyleSet,
|
||||
nsIPresShell** aInstancePtrResult);
|
||||
|
||||
virtual PRBool DeleteShell(nsIPresShell* aShell);
|
||||
|
||||
virtual PRInt32 GetNumberOfShells();
|
||||
|
||||
virtual nsIPresShell* GetShellAt(PRInt32 aIndex);
|
||||
|
||||
virtual nsIDocument* GetParentDocument();
|
||||
|
||||
virtual void SetParentDocument(nsIDocument* aParent);
|
||||
|
||||
virtual void AddSubDocument(nsIDocument* aSubDoc);
|
||||
|
||||
virtual PRInt32 GetNumberOfSubDocuments();
|
||||
|
||||
virtual nsIDocument* GetSubDocumentAt(PRInt32 aIndex);
|
||||
|
||||
virtual nsIContent* GetRootContent();
|
||||
|
||||
virtual void SetRootContent(nsIContent* aRoot);
|
||||
|
||||
virtual PRInt32 GetNumberOfStyleSheets();
|
||||
|
||||
virtual nsIStyleSheet* GetStyleSheetAt(PRInt32 aIndex);
|
||||
|
||||
virtual void AddStyleSheet(nsIStyleSheet* aSheet);
|
||||
|
||||
virtual void SetStyleSheetDisabledState(nsIStyleSheet* aSheet,
|
||||
PRBool mDisabled);
|
||||
|
||||
virtual nsIScriptContextOwner *GetScriptContextOwner();
|
||||
|
||||
virtual void SetScriptContextOwner(nsIScriptContextOwner *aScriptContextOwner);
|
||||
|
||||
NS_IMETHOD GetNameSpaceManager(nsINameSpaceManager*& aManager);
|
||||
|
||||
virtual void AddObserver(nsIDocumentObserver* aObserver);
|
||||
|
||||
virtual PRBool RemoveObserver(nsIDocumentObserver* aObserver);
|
||||
|
||||
NS_IMETHOD BeginLoad();
|
||||
|
||||
NS_IMETHOD EndLoad();
|
||||
|
||||
NS_IMETHOD ContentChanged(nsIContent* aContent,
|
||||
nsISupports* aSubContent);
|
||||
|
||||
NS_IMETHOD AttributeChanged(nsIContent* aChild,
|
||||
nsIAtom* aAttribute,
|
||||
PRInt32 aHint); // See nsStyleConsts fot hint values
|
||||
|
||||
NS_IMETHOD ContentAppended(nsIContent* aContainer,
|
||||
PRInt32 aNewIndexInContainer);
|
||||
|
||||
NS_IMETHOD ContentInserted(nsIContent* aContainer,
|
||||
nsIContent* aChild,
|
||||
PRInt32 aIndexInContainer);
|
||||
|
||||
NS_IMETHOD ContentReplaced(nsIContent* aContainer,
|
||||
nsIContent* aOldChild,
|
||||
nsIContent* aNewChild,
|
||||
PRInt32 aIndexInContainer);
|
||||
|
||||
NS_IMETHOD ContentRemoved(nsIContent* aContainer,
|
||||
nsIContent* aChild,
|
||||
PRInt32 aIndexInContainer);
|
||||
|
||||
NS_IMETHOD StyleRuleChanged(nsIStyleSheet* aStyleSheet,
|
||||
nsIStyleRule* aStyleRule,
|
||||
PRInt32 aHint); // See nsStyleConsts fot hint values
|
||||
|
||||
NS_IMETHOD StyleRuleAdded(nsIStyleSheet* aStyleSheet,
|
||||
nsIStyleRule* aStyleRule);
|
||||
|
||||
NS_IMETHOD StyleRuleRemoved(nsIStyleSheet* aStyleSheet,
|
||||
nsIStyleRule* aStyleRule);
|
||||
|
||||
NS_IMETHOD GetSelection(nsICollection** aSelection);
|
||||
|
||||
NS_IMETHOD SelectAll();
|
||||
|
||||
NS_IMETHOD FindNext(const nsString &aSearchStr, PRBool aMatchCase, PRBool aSearchDown, PRBool &aIsFound);
|
||||
|
||||
virtual void CreateXIF(nsString & aBuffer, PRBool aUseSelection);
|
||||
|
||||
virtual void ToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode);
|
||||
|
||||
virtual void BeginConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode);
|
||||
|
||||
virtual void ConvertChildrenToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode);
|
||||
|
||||
virtual void FinishConvertToXIF(nsXIFConverter& aConverter, nsIDOMNode* aNode);
|
||||
|
||||
virtual PRBool IsInRange(const nsIContent *aStartContent, const nsIContent* aEndContent, const nsIContent* aContent) const;
|
||||
|
||||
virtual PRBool IsBefore(const nsIContent *aNewContent, const nsIContent* aCurrentContent) const;
|
||||
|
||||
virtual PRBool IsInSelection(const nsIContent *aContent) const;
|
||||
|
||||
virtual nsIContent* GetPrevContent(const nsIContent *aContent) const;
|
||||
|
||||
virtual nsIContent* GetNextContent(const nsIContent *aContent) const;
|
||||
|
||||
virtual void SetDisplaySelection(PRBool aToggle);
|
||||
|
||||
virtual PRBool GetDisplaySelection() const;
|
||||
|
||||
NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext,
|
||||
nsEvent* aEvent,
|
||||
nsIDOMEvent** aDOMEvent,
|
||||
PRUint32 aFlags,
|
||||
nsEventStatus& aEventStatus);
|
||||
|
||||
|
||||
// nsIXMLDocument interface
|
||||
NS_IMETHOD PrologElementAt(PRInt32 aOffset, nsIContent** aContent);
|
||||
NS_IMETHOD PrologCount(PRInt32* aCount);
|
||||
NS_IMETHOD AppendToProlog(nsIContent* aContent);
|
||||
|
||||
NS_IMETHOD EpilogElementAt(PRInt32 aOffset, nsIContent** aContent);
|
||||
NS_IMETHOD EpilogCount(PRInt32* aCount);
|
||||
NS_IMETHOD AppendToEpilog(nsIContent* aContent);
|
||||
|
||||
// nsIRDFDocument interface
|
||||
NS_IMETHOD Init(void);
|
||||
NS_IMETHOD SetRootResource(nsIRDFResource* resource);
|
||||
NS_IMETHOD GetDataBase(nsIRDFDataBase*& result);
|
||||
NS_IMETHOD CreateChildren(nsIRDFContent* element);
|
||||
NS_IMETHOD AddTreeProperty(nsIRDFResource* resource);
|
||||
NS_IMETHOD RemoveTreeProperty(nsIRDFResource* resource);
|
||||
|
||||
protected:
|
||||
nsIContent*
|
||||
FindContent(const nsIContent* aStartNode,
|
||||
const nsIContent* aTest1,
|
||||
const nsIContent* aTest2) const;
|
||||
|
||||
PRBool IsTreeProperty(const nsIRDFResource* resource) const;
|
||||
|
||||
nsresult AttachTextNode(nsIContent* parent,
|
||||
nsIRDFNode* value);
|
||||
|
||||
nsresult NewChild(const nsString& tag,
|
||||
nsIRDFResource* resource,
|
||||
nsIRDFContent*& result,
|
||||
PRBool childrenMustBeGenerated);
|
||||
|
||||
virtual nsresult AddChild(nsIRDFContent* parent,
|
||||
nsIRDFResource* property,
|
||||
nsIRDFNode* value) = 0;
|
||||
|
||||
nsIArena* mArena;
|
||||
nsVoidArray mObservers;
|
||||
nsAutoString mDocumentTitle;
|
||||
nsIURL* mDocumentURL;
|
||||
nsIURLGroup* mDocumentURLGroup;
|
||||
nsIContent* mRootContent;
|
||||
nsIDocument* mParentDocument;
|
||||
nsIScriptContextOwner* mScriptContextOwner;
|
||||
nsCharSetID mCharSetID;
|
||||
nsVoidArray mStyleSheets;
|
||||
nsICollection* mSelection;
|
||||
PRBool mDisplaySelection;
|
||||
nsVoidArray mPresShells;
|
||||
nsINameSpaceManager* mNameSpaceManager;
|
||||
nsIStyleSheet* mAttrStyleSheet;
|
||||
nsIParser* mParser;
|
||||
nsIRDFDataBase* mDB;
|
||||
nsIRDFResourceManager* mResourceMgr;
|
||||
nsISupportsArray* mTreeProperties;
|
||||
};
|
||||
|
||||
|
||||
#endif // nsRDFDocument_h___
|
|
@ -0,0 +1,447 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#include "nsICSSParser.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIDOMComment.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsICSSStyleSheet.h"
|
||||
#include "nsIRDFContent.h"
|
||||
#include "nsIRDFDocument.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFResourceManager.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsLayoutCID.h"
|
||||
#include "nsRDFContentSink.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_IID(kICSSParserIID, NS_ICSS_PARSER_IID); // XXX grr..
|
||||
static NS_DEFINE_IID(kIDOMCommentIID, NS_IDOMCOMMENT_IID);
|
||||
static NS_DEFINE_IID(kIRDFContentSinkIID, NS_IRDFCONTENTSINK_IID);
|
||||
static NS_DEFINE_IID(kIScrollableViewIID, NS_ISCROLLABLEVIEW_IID);
|
||||
static NS_DEFINE_IID(kIRDFDocumentIID, NS_IRDFDOCUMENT_IID);
|
||||
|
||||
static NS_DEFINE_CID(kCSSParserCID, NS_CSSPARSER_CID);
|
||||
|
||||
|
||||
class nsRDFDocumentContentSink : public nsRDFContentSink {
|
||||
public:
|
||||
nsRDFDocumentContentSink(void);
|
||||
virtual ~nsRDFDocumentContentSink(void);
|
||||
|
||||
virtual nsresult Init(nsIDocument* aDoc,
|
||||
nsIURL* aURL,
|
||||
nsIWebShell* aContainer);
|
||||
|
||||
// nsIContentSink
|
||||
NS_IMETHOD WillBuildModel(void);
|
||||
NS_IMETHOD DidBuildModel(PRInt32 aQualityLevel);
|
||||
NS_IMETHOD AddProcessingInstruction(const nsIParserNode& aNode);
|
||||
|
||||
protected:
|
||||
void StartLayout(void);
|
||||
|
||||
virtual nsresult OpenObject(const nsIParserNode& aNode);
|
||||
|
||||
// Style sheets
|
||||
nsresult LoadStyleSheet(nsIURL* aURL,
|
||||
nsIUnicharInputStream* aUIN);
|
||||
|
||||
nsIStyleSheet* mStyleSheet;
|
||||
|
||||
// Document, webshell, etc.
|
||||
nsIDocument* mDocument;
|
||||
nsIContent* mRootElement;
|
||||
nsIWebShell* mWebShell;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsRDFDocumentContentSink::nsRDFDocumentContentSink(void)
|
||||
{
|
||||
mDocument = nsnull;
|
||||
mWebShell = nsnull;
|
||||
mRootElement = nsnull;
|
||||
}
|
||||
|
||||
|
||||
nsRDFDocumentContentSink::~nsRDFDocumentContentSink(void)
|
||||
{
|
||||
NS_IF_RELEASE(mDocument);
|
||||
NS_IF_RELEASE(mWebShell);
|
||||
NS_IF_RELEASE(mRootElement);
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsRDFDocumentContentSink::Init(nsIDocument* aDoc,
|
||||
nsIURL* aURL,
|
||||
nsIWebShell* aContainer)
|
||||
{
|
||||
NS_PRECONDITION(aDoc && aContainer, "null ptr");
|
||||
if (!aDoc || !aContainer)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsINameSpaceManager* nameSpaceManager = nsnull;
|
||||
nsresult rv = aDoc->GetNameSpaceManager(nameSpaceManager);
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = nsRDFContentSink::Init(aURL, nameSpaceManager);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mDocument = aDoc;
|
||||
NS_ADDREF(aDoc);
|
||||
|
||||
mWebShell = aContainer;
|
||||
NS_ADDREF(aContainer);
|
||||
}
|
||||
NS_RELEASE(nameSpaceManager);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsRDFDocumentContentSink::StartLayout(void)
|
||||
{
|
||||
PRInt32 i, ns = mDocument->GetNumberOfShells();
|
||||
for (i = 0; i < ns; i++) {
|
||||
nsIPresShell* shell = mDocument->GetShellAt(i);
|
||||
if (nsnull != shell) {
|
||||
// Make shell an observer for next time
|
||||
shell->BeginObservingDocument();
|
||||
|
||||
// Resize-reflow this time
|
||||
nsIPresContext* cx = shell->GetPresContext();
|
||||
nsRect r;
|
||||
cx->GetVisibleArea(r);
|
||||
shell->InitialReflow(r.width, r.height);
|
||||
NS_RELEASE(cx);
|
||||
|
||||
// Now trigger a refresh
|
||||
nsIViewManager* vm = shell->GetViewManager();
|
||||
if (nsnull != vm) {
|
||||
vm->EnableRefresh();
|
||||
NS_RELEASE(vm);
|
||||
}
|
||||
|
||||
NS_RELEASE(shell);
|
||||
}
|
||||
}
|
||||
|
||||
// If the document we are loading has a reference or it is a top level
|
||||
// frameset document, disable the scroll bars on the views.
|
||||
const char* ref;
|
||||
(void)mDocumentURL->GetRef(&ref);
|
||||
PRBool topLevelFrameset = PR_FALSE;
|
||||
if (mWebShell) {
|
||||
nsIWebShell* rootWebShell;
|
||||
mWebShell->GetRootWebShell(rootWebShell);
|
||||
if (mWebShell == rootWebShell) {
|
||||
topLevelFrameset = PR_TRUE;
|
||||
}
|
||||
NS_IF_RELEASE(rootWebShell);
|
||||
}
|
||||
|
||||
if ((nsnull != ref) || topLevelFrameset) {
|
||||
// XXX support more than one presentation-shell here
|
||||
|
||||
// Get initial scroll preference and save it away; disable the
|
||||
// scroll bars.
|
||||
PRInt32 i, ns = mDocument->GetNumberOfShells();
|
||||
for (i = 0; i < ns; i++) {
|
||||
nsIPresShell* shell = mDocument->GetShellAt(i);
|
||||
if (nsnull != shell) {
|
||||
nsIViewManager* vm = shell->GetViewManager();
|
||||
if (nsnull != vm) {
|
||||
nsIView* rootView = nsnull;
|
||||
vm->GetRootView(rootView);
|
||||
if (nsnull != rootView) {
|
||||
nsIScrollableView* sview = nsnull;
|
||||
rootView->QueryInterface(kIScrollableViewIID, (void**) &sview);
|
||||
if (nsnull != sview) {
|
||||
#if 0
|
||||
if (topLevelFrameset)
|
||||
mOriginalScrollPreference = nsScrollPreference_kNeverScroll;
|
||||
else
|
||||
sview->GetScrollPreference(mOriginalScrollPreference);
|
||||
#endif
|
||||
sview->SetScrollPreference(nsScrollPreference_kNeverScroll);
|
||||
}
|
||||
}
|
||||
NS_RELEASE(vm);
|
||||
}
|
||||
NS_RELEASE(shell);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// XXX Borrowed from HTMLContentSink. Should be shared.
|
||||
nsresult
|
||||
nsRDFDocumentContentSink::LoadStyleSheet(nsIURL* aURL,
|
||||
nsIUnicharInputStream* aUIN)
|
||||
{
|
||||
nsresult rv;
|
||||
nsICSSParser* parser;
|
||||
rv = nsRepository::CreateInstance(kCSSParserCID,
|
||||
nsnull,
|
||||
kICSSParserIID,
|
||||
(void**) &parser);
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsICSSStyleSheet* sheet = nsnull;
|
||||
// XXX note: we are ignoring rv until the error code stuff in the
|
||||
// input routines is converted to use nsresult's
|
||||
parser->SetCaseSensitive(PR_TRUE);
|
||||
parser->Parse(aUIN, aURL, sheet);
|
||||
if (nsnull != sheet) {
|
||||
mDocument->AddStyleSheet(sheet);
|
||||
NS_RELEASE(sheet);
|
||||
rv = NS_OK;
|
||||
} else {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;/* XXX */
|
||||
}
|
||||
NS_RELEASE(parser);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsIContentSink interface
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFDocumentContentSink::WillBuildModel(void)
|
||||
{
|
||||
// Notify document that the load is beginning
|
||||
mDocument->BeginLoad();
|
||||
nsresult result = NS_OK;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFDocumentContentSink::DidBuildModel(PRInt32 aQualityLevel)
|
||||
{
|
||||
// XXX this is silly; who cares?
|
||||
PRInt32 i, ns = mDocument->GetNumberOfShells();
|
||||
for (i = 0; i < ns; i++) {
|
||||
nsIPresShell* shell = mDocument->GetShellAt(i);
|
||||
if (nsnull != shell) {
|
||||
nsIViewManager* vm = shell->GetViewManager();
|
||||
if(vm) {
|
||||
vm->SetQuality(nsContentQuality(aQualityLevel));
|
||||
}
|
||||
NS_RELEASE(vm);
|
||||
NS_RELEASE(shell);
|
||||
}
|
||||
}
|
||||
|
||||
StartLayout();
|
||||
|
||||
// XXX Should scroll to ref when that makes sense
|
||||
// ScrollToRef();
|
||||
|
||||
mDocument->EndLoad();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
static nsresult
|
||||
rdf_GetQuotedAttributeValue(nsString& aSource,
|
||||
const nsString& aAttribute,
|
||||
nsString& aValue)
|
||||
{
|
||||
static const char kQuote = '\"';
|
||||
static const char kApostrophe = '\'';
|
||||
|
||||
PRInt32 offset;
|
||||
PRInt32 endOffset = -1;
|
||||
nsresult result = NS_OK;
|
||||
|
||||
offset = aSource.Find(aAttribute);
|
||||
if (-1 != offset) {
|
||||
offset = aSource.Find('=', offset);
|
||||
|
||||
PRUnichar next = aSource.CharAt(++offset);
|
||||
if (kQuote == next) {
|
||||
endOffset = aSource.Find(kQuote, ++offset);
|
||||
}
|
||||
else if (kApostrophe == next) {
|
||||
endOffset = aSource.Find(kApostrophe, ++offset);
|
||||
}
|
||||
|
||||
if (-1 != endOffset) {
|
||||
aSource.Mid(aValue, offset, endOffset-offset);
|
||||
}
|
||||
else {
|
||||
// Mismatched quotes - return an error
|
||||
result = NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
aValue.Truncate();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFDocumentContentSink::AddProcessingInstruction(const nsIParserNode& aNode)
|
||||
{
|
||||
static const char kStyleSheetPI[] = "<?xml-stylesheet";
|
||||
static const char kCSSType[] = "text/css";
|
||||
|
||||
nsresult rv;
|
||||
if (NS_FAILED(rv = nsRDFContentSink::AddProcessingInstruction(aNode)))
|
||||
return rv;
|
||||
|
||||
// XXX For now, we don't add the PI to the content model.
|
||||
// We just check for a style sheet PI
|
||||
nsAutoString text, type, href;
|
||||
PRInt32 offset;
|
||||
|
||||
text = aNode.GetText();
|
||||
|
||||
offset = text.Find(kStyleSheetPI);
|
||||
|
||||
// If it's a stylesheet PI...
|
||||
if (0 == offset) {
|
||||
rv = rdf_GetQuotedAttributeValue(text, "href", href);
|
||||
// If there was an error or there's no href, we can't do
|
||||
// anything with this PI
|
||||
if ((NS_OK != rv) || (0 == href.Length())) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = rdf_GetQuotedAttributeValue(text, "type", type);
|
||||
if (NS_OK != rv) {
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (type.Equals(kCSSType)) {
|
||||
nsIURL* url = nsnull;
|
||||
nsIUnicharInputStream* uin = nsnull;
|
||||
nsAutoString absURL;
|
||||
nsIURL* docURL = mDocument->GetDocumentURL();
|
||||
nsAutoString emptyURL;
|
||||
emptyURL.Truncate();
|
||||
rv = NS_MakeAbsoluteURL(docURL, emptyURL, href, absURL);
|
||||
if (NS_OK != rv) {
|
||||
return rv;
|
||||
}
|
||||
NS_RELEASE(docURL);
|
||||
rv = NS_NewURL(&url, absURL);
|
||||
if (NS_OK != rv) {
|
||||
return rv;
|
||||
}
|
||||
nsIInputStream* iin;
|
||||
rv = NS_OpenURL(url, &iin);
|
||||
if (NS_OK != rv) {
|
||||
NS_RELEASE(url);
|
||||
return rv;
|
||||
}
|
||||
rv = NS_NewConverterStream(&uin, nsnull, iin);
|
||||
NS_RELEASE(iin);
|
||||
if (NS_OK != rv) {
|
||||
NS_RELEASE(url);
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = LoadStyleSheet(url, uin);
|
||||
NS_RELEASE(uin);
|
||||
NS_RELEASE(url);
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsRDFDocumentContentSink::OpenObject(const nsIParserNode& aNode)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
if (NS_FAILED(rv = nsRDFContentSink::OpenObject(aNode)))
|
||||
return rv;
|
||||
|
||||
// Arbitrarily make the document root be the first container
|
||||
// element in the RDF.
|
||||
if (! mRootElement) {
|
||||
nsAutoString uri;
|
||||
if (NS_FAILED(rv = GetIdAboutAttribute(aNode, uri)))
|
||||
return rv;
|
||||
|
||||
nsIRDFResource* resource;
|
||||
if (NS_FAILED(rv = mResourceMgr->GetUnicodeResource(uri, &resource)))
|
||||
return rv;
|
||||
|
||||
nsIRDFDocument* rdfDoc;
|
||||
if (NS_SUCCEEDED(rv = mDocument->QueryInterface(kIRDFDocumentIID, (void**) &rdfDoc))) {
|
||||
if (NS_SUCCEEDED(rv = rdfDoc->SetRootResource(resource))) {
|
||||
mRootElement = mDocument->GetRootContent();
|
||||
}
|
||||
NS_RELEASE(rdfDoc);
|
||||
}
|
||||
|
||||
NS_RELEASE(resource);
|
||||
|
||||
// don't release the rdfElement since we're keeping
|
||||
// a reference to it in mRootElement
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult
|
||||
NS_NewRDFDocumentContentSink(nsIRDFContentSink** aResult,
|
||||
nsIDocument* aDoc,
|
||||
nsIURL* aURL,
|
||||
nsIWebShell* aWebShell)
|
||||
{
|
||||
NS_PRECONDITION(aResult, "null ptr");
|
||||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsRDFDocumentContentSink* it;
|
||||
NS_NEWXPCOM(it, nsRDFDocumentContentSink);
|
||||
if (! it)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult rv = it->Init(aDoc, aURL, aWebShell);
|
||||
if (NS_FAILED(rv)) {
|
||||
delete it;
|
||||
return rv;
|
||||
}
|
||||
return it->QueryInterface(kIRDFContentSinkIID, (void **)aResult);
|
||||
}
|
||||
|
||||
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,181 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsRDFElement_h___
|
||||
#define nsRDFElement_h___
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "nsIRDFContent.h"
|
||||
#include "nsIJSScriptObject.h"
|
||||
|
||||
class nsHashtable;
|
||||
class nsIContent;
|
||||
class nsIRDFDocument;
|
||||
class nsIAtom;
|
||||
class nsIEventListenerManager;
|
||||
class nsISupportsArray;
|
||||
|
||||
// XXX should we make this inheirit from the nsXMLElement
|
||||
// implementation???
|
||||
|
||||
class nsRDFElement : public nsIDOMElement,
|
||||
public nsIDOMEventReceiver,
|
||||
public nsIScriptObjectOwner,
|
||||
public nsIJSScriptObject,
|
||||
public nsIRDFContent
|
||||
{
|
||||
public:
|
||||
nsRDFElement(void);
|
||||
~nsRDFElement(void);
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIDOMNode (from nsIDOMElement)
|
||||
NS_DECL_IDOMNODE
|
||||
|
||||
// nsIDOMElement
|
||||
NS_DECL_IDOMELEMENT
|
||||
|
||||
// nsIScriptObjectOwner
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext* aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void *aScriptObject);
|
||||
|
||||
// nsIContent (from nsIRDFContent via nsIXMLContent)
|
||||
|
||||
// Any of the nsIContent methods that directly manipulate content
|
||||
// (e.g., AppendChildTo()), are assumed to "know what they're
|
||||
// doing" to the content model. No attempt is made to muck with
|
||||
// the underlying RDF representation.
|
||||
NS_IMETHOD GetDocument(nsIDocument*& aResult) const;
|
||||
NS_IMETHOD SetDocument(nsIDocument* aDocument, PRBool aDeep);
|
||||
NS_IMETHOD GetParent(nsIContent*& aResult) const;
|
||||
NS_IMETHOD SetParent(nsIContent* aParent);
|
||||
NS_IMETHOD CanContainChildren(PRBool& aResult) const;
|
||||
NS_IMETHOD ChildCount(PRInt32& aResult) const;
|
||||
NS_IMETHOD ChildAt(PRInt32 aIndex, nsIContent*& aResult) const;
|
||||
NS_IMETHOD IndexOf(nsIContent* aPossibleChild, PRInt32& aResult) const;
|
||||
NS_IMETHOD InsertChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify);
|
||||
NS_IMETHOD ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify);
|
||||
NS_IMETHOD AppendChildTo(nsIContent* aKid, PRBool aNotify);
|
||||
NS_IMETHOD RemoveChildAt(PRInt32 aIndex, PRBool aNotify);
|
||||
NS_IMETHOD IsSynthetic(PRBool& aResult);
|
||||
NS_IMETHOD GetTag(nsIAtom*& aResult) const;
|
||||
NS_IMETHOD SetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, const nsString& aValue, PRBool aNotify);
|
||||
NS_IMETHOD GetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, nsString& aResult) const;
|
||||
NS_IMETHOD UnsetAttribute(PRInt32 aNameSpaceID, nsIAtom* aName, PRBool aNotify);
|
||||
NS_IMETHOD GetAttributeNameAt(PRInt32 aIndex, PRInt32& aNameSpaceID,
|
||||
nsIAtom*& aName) const;
|
||||
NS_IMETHOD GetAttributeCount(PRInt32& aResult) const;
|
||||
NS_IMETHOD List(FILE* out, PRInt32 aIndent) const;
|
||||
NS_IMETHOD BeginConvertToXIF(nsXIFConverter& aConverter) const;
|
||||
NS_IMETHOD ConvertContentToXIF(nsXIFConverter& aConverter) const;
|
||||
NS_IMETHOD FinishConvertToXIF(nsXIFConverter& aConverter) const;
|
||||
NS_IMETHOD SizeOf(nsISizeOfHandler* aHandler) const;
|
||||
NS_IMETHOD HandleDOMEvent(nsIPresContext& aPresContext,
|
||||
nsEvent* aEvent,
|
||||
nsIDOMEvent** aDOMEvent,
|
||||
PRUint32 aFlags,
|
||||
nsEventStatus& aEventStatus);
|
||||
NS_IMETHOD RangeAdd(nsIDOMRange& aRange);
|
||||
NS_IMETHOD RangeRemove(nsIDOMRange& aRange);
|
||||
NS_IMETHOD GetRangeList(nsVoidArray*& aResult) const;
|
||||
|
||||
// nsIXMLContent (from nsIRDFContent)
|
||||
NS_IMETHOD SetNameSpacePrefix(nsIAtom* aNameSpace);
|
||||
NS_IMETHOD GetNameSpacePrefix(nsIAtom*& aNameSpace) const;
|
||||
NS_IMETHOD SetNameSpaceID(PRInt32 aNameSpaceID);
|
||||
NS_IMETHOD GetNameSpaceID(PRInt32& aNameSpeceID) const;
|
||||
|
||||
// nsIRDFContent
|
||||
NS_IMETHOD Init(nsIRDFDocument* doc,
|
||||
const nsString& tag,
|
||||
nsIRDFResource* resource,
|
||||
PRBool childrenMustBeGenerated);
|
||||
|
||||
NS_IMETHOD SetResource(const nsString& aURI);
|
||||
NS_IMETHOD GetResource(nsString& rURI) const;
|
||||
|
||||
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;
|
||||
|
||||
// nsIDOMEventReceiver
|
||||
NS_IMETHOD AddEventListener(nsIDOMEventListener *aListener, const nsIID& aIID);
|
||||
NS_IMETHOD RemoveEventListener(nsIDOMEventListener *aListener, const nsIID& aIID);
|
||||
NS_IMETHOD GetListenerManager(nsIEventListenerManager** aInstancePtrResult);
|
||||
NS_IMETHOD GetNewListenerManager(nsIEventListenerManager **aInstancePtrResult);
|
||||
|
||||
|
||||
// nsIJSScriptObject
|
||||
virtual PRBool AddProperty(JSContext *aContext, jsval aID, jsval *aVp);
|
||||
virtual PRBool DeleteProperty(JSContext *aContext, jsval aID, jsval *aVp);
|
||||
virtual PRBool GetProperty(JSContext *aContext, jsval aID, jsval *aVp);
|
||||
virtual PRBool SetProperty(JSContext *aContext, jsval aID, jsval *aVp);
|
||||
virtual PRBool EnumerateProperty(JSContext *aContext);
|
||||
virtual PRBool Resolve(JSContext *aContext, jsval aID);
|
||||
virtual PRBool Convert(JSContext *aContext, jsval aID);
|
||||
virtual void Finalize(JSContext *aContext);
|
||||
|
||||
protected:
|
||||
/** The document in which the element lives. */
|
||||
nsIRDFDocument* mDocument;
|
||||
|
||||
/** The tag's namespace prefix */
|
||||
nsIAtom* mNameSpacePrefix;
|
||||
|
||||
/** The tag's namespace ID */
|
||||
PRInt32 mNameSpaceID;
|
||||
|
||||
/** XXX */
|
||||
void* mScriptObject;
|
||||
|
||||
/** The RDF resource that the element corresponds to */
|
||||
nsIRDFResource* mResource;
|
||||
|
||||
/** An array of child nodes */
|
||||
nsISupportsArray* mChildren;
|
||||
|
||||
/** On initialization, set to PR_TRUE if the child nodes must
|
||||
be generated by walking the RDF graph. Set to PR_FALSE if
|
||||
the constructor will do it "by hand". */
|
||||
PRBool mChildrenMustBeGenerated;
|
||||
|
||||
/** The element's parent. NOT refcounted. */
|
||||
nsIContent* mParent;
|
||||
|
||||
/** The element's tag */
|
||||
nsAutoString mTag;
|
||||
|
||||
/** An array of attribute data. Instantiated
|
||||
lazily if attributes are required */
|
||||
nsVoidArray* mAttributes;
|
||||
|
||||
/**
|
||||
* Dynamically generate the element's children from the RDF graph
|
||||
*/
|
||||
nsresult GenerateChildren(void) const;
|
||||
};
|
||||
|
||||
#endif // nsRDFElement_h___
|
|
@ -0,0 +1,206 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
This builds an HTML-like model, complete with text nodes, that can
|
||||
be displayed in a vanilla HTML content viewer. You can apply CSS2
|
||||
styles to the text, etc.
|
||||
|
||||
*/
|
||||
|
||||
#include "nsIRDFContent.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIRDFDataBase.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFResourceManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsRDFDocument.h"
|
||||
#include "rdfutil.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
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,
|
||||
nsIRDFResource* property,
|
||||
nsIRDFNode* value);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static nsIAtom* kIdAtom;
|
||||
|
||||
RDFHTMLDocumentImpl::RDFHTMLDocumentImpl(void)
|
||||
{
|
||||
if (nsnull == kIdAtom) {
|
||||
kIdAtom = NS_NewAtom("ID");
|
||||
}
|
||||
else {
|
||||
NS_ADDREF(kIdAtom);
|
||||
}
|
||||
}
|
||||
|
||||
RDFHTMLDocumentImpl::~RDFHTMLDocumentImpl(void)
|
||||
{
|
||||
nsrefcnt refcnt;
|
||||
NS_RELEASE2(kIdAtom, refcnt);
|
||||
}
|
||||
|
||||
nsresult
|
||||
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;
|
||||
|
||||
// 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->GetValue(&p)))
|
||||
goto done;
|
||||
|
||||
s = p;
|
||||
|
||||
if (NS_FAILED(rv = child->SetAttribute(kNameSpaceID_HTML, kIdAtom, s, PR_FALSE)))
|
||||
goto done;
|
||||
|
||||
rv = parent->AppendChildTo(child, PR_TRUE);
|
||||
|
||||
done:
|
||||
NS_IF_RELEASE(child);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
nsIRDFDocument* doc = new RDFHTMLDocumentImpl();
|
||||
if (! doc)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(doc);
|
||||
*result = doc;
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#include "nsRDFContentSink.h"
|
||||
static NS_DEFINE_IID(kIRDFContentSinkIID, NS_IRDFCONTENTSINK_IID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsRDFSimpleContentSink : public nsRDFContentSink {
|
||||
public:
|
||||
nsRDFSimpleContentSink(void) {};
|
||||
virtual ~nsRDFSimpleContentSink(void) {};
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult
|
||||
NS_NewRDFSimpleContentSink(nsIRDFContentSink** aResult,
|
||||
nsIURL* aURL,
|
||||
nsINameSpaceManager* aNameSpaceManager)
|
||||
{
|
||||
NS_PRECONDITION(aResult, "null ptr");
|
||||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsRDFSimpleContentSink* it;
|
||||
NS_NEWXPCOM(it, nsRDFSimpleContentSink);
|
||||
if (! it)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult rv = it->Init(aURL, aNameSpaceManager);
|
||||
if (NS_FAILED(rv)) {
|
||||
delete it;
|
||||
return rv;
|
||||
}
|
||||
return it->QueryInterface(kIRDFContentSinkIID, (void **)aResult);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,599 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and limitations
|
||||
* under the License.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
|
||||
#include "nsIRDFContent.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIRDFDataBase.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFResourceManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsRDFDocument.h"
|
||||
#include "rdf.h"
|
||||
#include "rdfutil.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define NC_NAMESPACE_URI "http://home.netscape.com/NC-rdf#"
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Columns);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Column);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Title);
|
||||
|
||||
static const char* kChildrenTag = "CHILDREN";
|
||||
static const char* kFolderTag = "FOLDER";
|
||||
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();
|
||||
virtual ~RDFTreeDocumentImpl();
|
||||
|
||||
//NS_IMETHOD SetRootResource(nsIRDFNode* resource);
|
||||
|
||||
protected:
|
||||
virtual nsresult
|
||||
AddChild(nsIRDFContent* parent,
|
||||
nsIRDFResource* property,
|
||||
nsIRDFNode* value);
|
||||
|
||||
/**
|
||||
* Ensure that the specified <tt>tag</tt> exists as a child of the
|
||||
* <tt>parent</tt> element.
|
||||
*/
|
||||
nsresult
|
||||
EnsureChildElement(nsIContent* parent,
|
||||
const nsString& tag,
|
||||
nsIContent*& result);
|
||||
|
||||
/**
|
||||
* Add a new child to the content model from a tree property. This creates
|
||||
* the necessary cruft in the content model to ensure that content will
|
||||
* recursively be generated as the content model is descended.
|
||||
*/
|
||||
nsresult
|
||||
AddTreeChild(nsIRDFContent* parent,
|
||||
nsIRDFResource* property,
|
||||
nsIRDFResource* value);
|
||||
|
||||
/**
|
||||
* Add a single column to the content model.
|
||||
*/
|
||||
nsresult
|
||||
AddColumn(nsIContent* parent,
|
||||
nsIRDFResource* property,
|
||||
nsIRDFLiteral* title);
|
||||
|
||||
|
||||
/**
|
||||
* Add columns to the content model from an RDF container (sequence or bag)
|
||||
*/
|
||||
nsresult
|
||||
AddColumnsFromContainer(nsIContent* parent,
|
||||
nsIRDFResource* columns);
|
||||
|
||||
|
||||
/**
|
||||
* Add columns to the content model from a set of multi-attributes
|
||||
*/
|
||||
nsresult
|
||||
AddColumnsFromMultiAttributes(nsIContent* parent,
|
||||
nsIRDFResource* columns);
|
||||
|
||||
/**
|
||||
* Add columns to the content model.
|
||||
*/
|
||||
nsresult
|
||||
AddColumns(nsIContent* parent,
|
||||
nsIRDFResource* columns);
|
||||
|
||||
/**
|
||||
* Add a new property element to the content model
|
||||
*/
|
||||
nsresult
|
||||
AddPropertyChild(nsIRDFContent* parent,
|
||||
nsIRDFResource* property,
|
||||
nsIRDFNode* value);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static nsIAtom* kIdAtom;
|
||||
static nsIAtom* kOpenAtom;
|
||||
|
||||
RDFTreeDocumentImpl::RDFTreeDocumentImpl(void)
|
||||
{
|
||||
if (nsnull == kIdAtom) {
|
||||
kIdAtom = NS_NewAtom("ID");
|
||||
kOpenAtom = NS_NewAtom("open");
|
||||
}
|
||||
else {
|
||||
NS_ADDREF(kIdAtom);
|
||||
NS_ADDREF(kOpenAtom);
|
||||
}
|
||||
}
|
||||
|
||||
RDFTreeDocumentImpl::~RDFTreeDocumentImpl(void)
|
||||
{
|
||||
nsrefcnt refcnt;
|
||||
NS_RELEASE2(kIdAtom, refcnt);
|
||||
NS_RELEASE2(kOpenAtom, refcnt);
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
RDFTreeDocumentImpl::EnsureChildElement(nsIContent* parent,
|
||||
const nsString& tag,
|
||||
nsIContent*& result)
|
||||
{
|
||||
nsresult rv;
|
||||
result = nsnull; // reasonable default
|
||||
|
||||
nsIAtom* tagAtom = NS_NewAtom(tag);
|
||||
if (! tagAtom)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
PRInt32 count;
|
||||
if (NS_FAILED(rv = parent->ChildCount(count))) {
|
||||
NS_RELEASE(tagAtom);
|
||||
return rv;
|
||||
}
|
||||
|
||||
for (PRInt32 i = 0; i < count; ++i) {
|
||||
nsIContent* kid;
|
||||
if (NS_FAILED(rv = parent->ChildAt(i, kid)))
|
||||
break;
|
||||
|
||||
nsIAtom* kidTagAtom;
|
||||
if (NS_FAILED(rv = kid->GetTag(kidTagAtom))) {
|
||||
NS_RELEASE(kid);
|
||||
break;
|
||||
}
|
||||
|
||||
if (kidTagAtom == tagAtom) {
|
||||
NS_RELEASE(kidTagAtom);
|
||||
NS_RELEASE(tagAtom);
|
||||
result = kid; // no need to addref, got it from ChildAt().
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_RELEASE(kidTagAtom);
|
||||
NS_RELEASE(kid);
|
||||
}
|
||||
|
||||
NS_RELEASE(tagAtom);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
// if we get here, we need to construct a new <children> element.
|
||||
|
||||
// XXX this should be a generic XML container element, not an nsRDFElement
|
||||
nsIRDFContent* children = nsnull;
|
||||
|
||||
if (NS_FAILED(rv = NS_NewRDFElement(&children)))
|
||||
goto done;
|
||||
|
||||
if (NS_FAILED(rv = children->Init(this, tag, nsnull /* XXX */, PR_FALSE)))
|
||||
goto done;
|
||||
|
||||
if (NS_FAILED(rv = parent->AppendChildTo(children, PR_FALSE)))
|
||||
goto done;
|
||||
|
||||
result = children;
|
||||
NS_ADDREF(result);
|
||||
|
||||
done:
|
||||
NS_IF_RELEASE(children);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
RDFTreeDocumentImpl::AddTreeChild(nsIRDFContent* parent,
|
||||
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
|
||||
// child element's value will be the value of the
|
||||
// property. We'll also attach an "ID=" attribute to the new
|
||||
// child; e.g.,
|
||||
//
|
||||
// <parent>
|
||||
// ...
|
||||
// <children>
|
||||
// <item id="value">
|
||||
// <!-- recursively generated -->
|
||||
// </item>
|
||||
// </children>
|
||||
// ...
|
||||
// </parent>
|
||||
|
||||
nsresult rv;
|
||||
nsIRDFContent* child = nsnull;
|
||||
nsIContent* children = nsnull;
|
||||
const char* p;
|
||||
nsAutoString s;
|
||||
|
||||
// Ensure that the <children> element exists on the parent.
|
||||
if (NS_FAILED(rv = EnsureChildElement(parent, kChildrenTag, children)))
|
||||
goto done;
|
||||
|
||||
// Create a new child that represents the "value"
|
||||
// resource. PR_TRUE indicates that we want the child to
|
||||
// dynamically generate its own kids.
|
||||
if (NS_FAILED(rv = NewChild(kFolderTag, value, child, PR_TRUE)))
|
||||
goto done;
|
||||
|
||||
if (NS_FAILED(rv = value->GetValue(&p)))
|
||||
goto done;
|
||||
|
||||
s = p;
|
||||
|
||||
if (NS_FAILED(rv = child->SetAttribute(kNameSpaceID_HTML, kIdAtom, s, PR_FALSE)))
|
||||
goto done;
|
||||
|
||||
#define ALL_NODES_OPEN_HACK
|
||||
#ifdef ALL_NODES_OPEN_HACK
|
||||
if (NS_FAILED(rv = child->SetAttribute(kNameSpaceID_None, kOpenAtom, "TRUE", PR_FALSE)))
|
||||
goto done;
|
||||
#endif
|
||||
|
||||
// Finally, add the thing to the <children> element.
|
||||
children->AppendChildTo(child, PR_TRUE);
|
||||
|
||||
done:
|
||||
NS_IF_RELEASE(child);
|
||||
NS_IF_RELEASE(children);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
RDFTreeDocumentImpl::AddColumn(nsIContent* parent,
|
||||
nsIRDFResource* property,
|
||||
nsIRDFLiteral* title)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
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;
|
||||
|
||||
if (NS_FAILED(rv = NS_NewRDFElement(&column)))
|
||||
goto done;
|
||||
|
||||
if (NS_FAILED(rv = column->Init(this, tag, nsnull /* XXX */, PR_FALSE)))
|
||||
goto done;
|
||||
|
||||
if (NS_FAILED(rv = parent->AppendChildTo(column, PR_FALSE)))
|
||||
goto done;
|
||||
|
||||
rv = AttachTextNode(column, title);
|
||||
|
||||
done:
|
||||
NS_IF_RELEASE(column);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
||||
When columns are specified using a container, the data model is
|
||||
assumed to look something like the following example:
|
||||
|
||||
<RDF:RDF>
|
||||
<RDF:Description RDF:about="nc:history">
|
||||
<NC:Columns>
|
||||
<RDF:Seq>
|
||||
<RDF:li>
|
||||
<NC:Description
|
||||
NC:Column="http://home.netscape.com/NC-rdf#LastVisitDate"
|
||||
NC:Title="Date Last Visited"/>
|
||||
</RDF:li>
|
||||
|
||||
<RDF:li>
|
||||
<NC:Description
|
||||
NC:Column="http://home.netscape.com/NC-rdf#URL"
|
||||
NC:Title="URL"/>
|
||||
</RDF:li>
|
||||
|
||||
<RDF:li>
|
||||
<NC:Description
|
||||
NC:Column="http://home.netscape.com/NC-rdf#Title"
|
||||
NC:Title="Title"/>
|
||||
</RDF:li>
|
||||
</RDF:Seq>
|
||||
</NC:Columns>
|
||||
|
||||
<!-- ...whatever... -->
|
||||
|
||||
</RDF:Description>
|
||||
</RDF:RDF>
|
||||
|
||||
*/
|
||||
|
||||
nsresult
|
||||
RDFTreeDocumentImpl::AddColumnsFromContainer(nsIContent* parent,
|
||||
nsIRDFResource* columns)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsIContent* columnsElement;
|
||||
if (NS_FAILED(rv = EnsureChildElement(parent, kColumnsTag, columnsElement)))
|
||||
return rv;
|
||||
|
||||
nsIRDFResource* NC_Column = nsnull;
|
||||
nsIRDFResource* NC_Title = nsnull;
|
||||
nsIRDFAssertionCursor* cursor = nsnull;
|
||||
|
||||
if (NS_FAILED(rv = mResourceMgr->GetResource(kURINC_Column, &NC_Column)))
|
||||
goto done;
|
||||
|
||||
if (NS_FAILED(rv = mResourceMgr->GetResource(kURINC_Title, &NC_Title)))
|
||||
goto done;
|
||||
|
||||
if (NS_FAILED(rv = NS_NewContainerCursor(mDB, columns, &cursor)))
|
||||
goto done;
|
||||
|
||||
while (NS_SUCCEEDED(rv = cursor->Advance())) {
|
||||
nsIRDFNode* columnNode;
|
||||
if (NS_SUCCEEDED(rv = cursor->GetObject(&columnNode))) {
|
||||
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;
|
||||
|
||||
rv = mDB->GetTarget(column, NC_Column, PR_TRUE, &propertyNode);
|
||||
PR_ASSERT(NS_SUCCEEDED(rv));
|
||||
|
||||
rv = propertyNode->QueryInterface(kIRDFResourceIID, (void**) &property);
|
||||
PR_ASSERT(NS_SUCCEEDED(rv));
|
||||
|
||||
rv = mDB->GetTarget(column, NC_Title, PR_TRUE, &titleNode);
|
||||
PR_ASSERT(NS_SUCCEEDED(rv));
|
||||
|
||||
rv = titleNode->QueryInterface(kIRDFLiteralIID, (void**) &title);
|
||||
PR_ASSERT(NS_SUCCEEDED(rv));
|
||||
|
||||
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))
|
||||
break;
|
||||
}
|
||||
|
||||
if (rv == NS_ERROR_RDF_CURSOR_EMPTY)
|
||||
// This is a "normal" return code from nsIRDFCursor::Advance().
|
||||
rv = NS_OK;
|
||||
|
||||
done:
|
||||
NS_IF_RELEASE(cursor);
|
||||
NS_IF_RELEASE(NC_Title);
|
||||
NS_IF_RELEASE(NC_Column);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
When the columns are specified using multi-attributes, the data
|
||||
model assumed to look something like the following example:
|
||||
|
||||
<RDF:RDF>
|
||||
<RDF:Description RDF:about="nc:history">
|
||||
<NC:Columns>
|
||||
<NC:LastVisitDate RDF:ID="#001">Date Last Visited</NC:LastVisitDate>
|
||||
<NC:URL RDF:ID="#002">URL</NC:URL>
|
||||
<NC:Title RDF:ID="#003">Title</NC:URL>
|
||||
<NC:Order>
|
||||
<RDF:Seq>
|
||||
<RDF:li RDF:resource="#003"/>
|
||||
<RDF:li RDF:resource="#002"/>
|
||||
<RDF:li RDF:resource="#001"/>
|
||||
</RDF:Seq>
|
||||
</NC:Order>
|
||||
</NC:Columns>
|
||||
|
||||
<!-- ...whatever... -->
|
||||
|
||||
</RDF:Description>
|
||||
</RDF:RDF>
|
||||
|
||||
TODO: implement the NC:Order property on the column set. This is not
|
||||
exactly a slam dunk; it requires getting reification working
|
||||
properly in the RDF content sink.
|
||||
|
||||
*/
|
||||
nsresult
|
||||
RDFTreeDocumentImpl::AddColumnsFromMultiAttributes(nsIContent* parent,
|
||||
nsIRDFResource* columns)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsIContent* columnsElement;
|
||||
if (NS_FAILED(rv = EnsureChildElement(parent, kColumnsTag, columnsElement)))
|
||||
return rv;
|
||||
|
||||
nsIRDFArcsOutCursor* cursor = nsnull;
|
||||
if (NS_FAILED(rv = mDB->ArcLabelsOut(columns, &cursor)))
|
||||
goto done;
|
||||
|
||||
while (NS_SUCCEEDED(rv = cursor->Advance())) {
|
||||
nsIRDFResource* property;
|
||||
if (NS_SUCCEEDED(rv = cursor->GetPredicate(&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);
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
}
|
||||
|
||||
if (rv == NS_ERROR_RDF_CURSOR_EMPTY)
|
||||
// This is a reasonable return code from nsIRDFCursor::Advance()
|
||||
rv = NS_OK;
|
||||
|
||||
// XXX Now search for an "order" property and apply it to the
|
||||
// above to sort them...
|
||||
|
||||
done:
|
||||
NS_IF_RELEASE(cursor);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
RDFTreeDocumentImpl::AddColumns(nsIContent* parent,
|
||||
nsIRDFResource* columns)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
if (rdf_IsContainer(mResourceMgr, mDB, columns)) {
|
||||
rv = AddColumnsFromContainer(parent, columns);
|
||||
}
|
||||
else {
|
||||
rv = AddColumnsFromMultiAttributes(parent, columns);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
RDFTreeDocumentImpl::AddPropertyChild(nsIRDFContent* parent,
|
||||
nsIRDFResource* property,
|
||||
nsIRDFNode* 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>
|
||||
// <columns>
|
||||
// <folder>value</folder>
|
||||
// </columns>
|
||||
// ...
|
||||
// </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->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;
|
||||
|
||||
if (NS_FAILED(rv = AttachTextNode(child, value)))
|
||||
goto done;
|
||||
|
||||
rv = columnsElement->AppendChildTo(child, PR_TRUE);
|
||||
|
||||
done:
|
||||
NS_IF_RELEASE(columnsElement);
|
||||
NS_IF_RELEASE(child);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
RDFTreeDocumentImpl::AddChild(nsIRDFContent* parent,
|
||||
nsIRDFResource* property,
|
||||
nsIRDFNode* 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);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult NS_NewRDFTreeDocument(nsIRDFDocument** result)
|
||||
{
|
||||
nsIRDFDocument* doc = new RDFTreeDocumentImpl();
|
||||
if (! doc)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(doc);
|
||||
*result = doc;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,29 @@
|
|||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH = ..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = public src
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
|
@ -0,0 +1,27 @@
|
|||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..
|
||||
|
||||
MODULE = rdf
|
||||
|
||||
DIRS=\
|
||||
public \
|
||||
src \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
|
@ -0,0 +1 @@
|
|||
nsRDFDataSourceCID.h
|
|
@ -0,0 +1,36 @@
|
|||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH = ../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = rdf
|
||||
|
||||
EXPORTS = \
|
||||
rdf.h \
|
||||
nsRDFDataSourceCID.h \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
|
@ -0,0 +1,28 @@
|
|||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
|
||||
MODULE=rdf
|
||||
|
||||
DEPTH=..\..\..
|
||||
|
||||
EXPORTS = \
|
||||
nsRDFDataSourceCID.h \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)/config/rules.mak>
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
/* -*- 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 nsRDFCID_h__
|
||||
#define nsRDFCID_h__
|
||||
|
||||
// {E638D760-8687-11d2-B530-000000000000}
|
||||
#define NS_RDFBOOKMARKDATASOURCE_CID \
|
||||
{ 0xe638d760, 0x8687, 0x11d2, { 0xb5, 0x30, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }
|
||||
|
||||
#endif // nsRDFCID_h__
|
|
@ -0,0 +1,52 @@
|
|||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
LIBRARY_NAME = rdf
|
||||
|
||||
CPPSRCS = \
|
||||
nsBookmarkDataSource.cpp \
|
||||
nsRDFDataSourceFactory.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
||||
|
||||
MODULE = rdf
|
||||
|
||||
REQUIRES = dom js netlib rdf raptor xpcom
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
|
||||
export::
|
||||
|
||||
install:: $(TARGETS)
|
||||
|
||||
|
||||
clobber::
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..\..\..
|
||||
MODULE=rdfdatasource
|
||||
|
||||
MAKE_OBJ_TYPE=DLL
|
||||
DLLNAME=$(MODULE)
|
||||
DLL=.\$(OBJDIR)\$(DLLNAME).dll
|
||||
|
||||
CPP_OBJS=\
|
||||
.\$(OBJDIR)\nsBookmarkDataSource.obj \
|
||||
.\$(OBJDIR)\nsRDFDataSourceFactory.obj \
|
||||
$(NULL)
|
||||
|
||||
LLIBS=\
|
||||
$(DIST)\lib\rdfbase.lib \
|
||||
$(DIST)\lib\xpcom32.lib \
|
||||
$(DIST)\lib\raptorbase.lib \
|
||||
$(DIST)\lib\raptorgfxwin.lib \
|
||||
$(DIST)\lib\netlib.lib \
|
||||
$(DIST)\lib\libplc21.lib \
|
||||
$(LIBNSPR)
|
||||
|
||||
LINCS= -I$(PUBLIC)\rdf \
|
||||
-I$(PUBLIC)\xpcom \
|
||||
-I$(PUBLIC)\netlib \
|
||||
-I$(PUBLIC)\raptor \
|
||||
-I$(PUBLIC)\js \
|
||||
-I$(PUBLIC)\dom \
|
||||
-I$(DEPTH)\rdf\base\src \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(DLL)
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,731 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsIRDFDataSource.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFResourceManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsRDFBaseCID.h"
|
||||
#include "nsString.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "prio.h"
|
||||
#include "rdf.h"
|
||||
#include "rdfutil.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_IID(kIRDFDataSourceIID, NS_IRDFDATASOURCE_IID);
|
||||
static NS_DEFINE_IID(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?
|
||||
|
||||
#define NC_NAMESPACE_URI "http://home.netscape.com/NC-rdf#"
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Bookmark);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, BookmarkAddDate);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Description);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Folder);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Name);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, PersonalToolbarFolderCategory);
|
||||
|
||||
// XXX these are here until we can undo the hard-coding of the column
|
||||
// info in the data source. See BookmarkParser::AddColumns() for more
|
||||
// info.
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Column);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Columns);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Title);
|
||||
|
||||
|
||||
#define WEB_NAMESPACE_URI "http://home.netscape.com/WEB-rdf#"
|
||||
DEFINE_RDF_VOCAB(WEB_NAMESPACE_URI, WEB, LastVisitDate);
|
||||
DEFINE_RDF_VOCAB(WEB_NAMESPACE_URI, WEB, LastModifiedDate);
|
||||
|
||||
|
||||
#define RDF_NAMESPACE_URI "http://www.w3.org/TR/WD-rdf-syntax#"
|
||||
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, instanceOf);
|
||||
|
||||
static const char kPersonalToolbar[] = "Personal Toolbar";
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* The bookmark parser knows how to read <tt>bookmarks.html</tt> and convert it
|
||||
* into an RDF graph.
|
||||
*/
|
||||
class BookmarkParser {
|
||||
protected:
|
||||
static const char* kBRString;
|
||||
static const char* kCloseDLString;
|
||||
static const char* kDDString;
|
||||
static const char* kOpenAnchorString;
|
||||
static const char* kOpenDLString;
|
||||
static const char* kOpenH3String;
|
||||
static const char* kOpenTitleString;
|
||||
static const char* kSeparatorString;
|
||||
|
||||
enum BookmarkParserState {
|
||||
eBookmarkParserState_Initial,
|
||||
eBookmarkParserState_InTitle,
|
||||
eBookmarkParserState_InH3,
|
||||
eBookmarkParserState_InItemTitle,
|
||||
eBookmarkParserState_InItemDescription
|
||||
};
|
||||
|
||||
nsIRDFResourceManager* mResourceMgr;
|
||||
nsIRDFDataSource* mDataSource;
|
||||
nsVoidArray mStack;
|
||||
nsIRDFResource* mLastItem;
|
||||
nsAutoString mLine;
|
||||
PRInt32 mCounter;
|
||||
nsAutoString mFolderDate;
|
||||
BookmarkParserState mState;
|
||||
|
||||
void Tokenize(const char* buf, PRInt32 size);
|
||||
void NextToken(void);
|
||||
void DoStateTransition(void);
|
||||
void CreateBookmark(void);
|
||||
|
||||
nsresult AssertTime(nsIRDFResource* subject,
|
||||
const nsString& predicateURI,
|
||||
const nsString& time);
|
||||
|
||||
nsresult AddColumns(void);
|
||||
|
||||
public:
|
||||
BookmarkParser(void);
|
||||
~BookmarkParser();
|
||||
|
||||
nsresult Parse(PRFileDesc* file, nsIRDFDataSource* dataSource);
|
||||
};
|
||||
|
||||
|
||||
const char* BookmarkParser::kBRString = "<BR>";
|
||||
const char* BookmarkParser::kCloseDLString = "</DL>";
|
||||
const char* BookmarkParser::kDDString = "<DD>";
|
||||
const char* BookmarkParser::kOpenAnchorString = "<A";
|
||||
const char* BookmarkParser::kOpenDLString = "<DL>";
|
||||
const char* BookmarkParser::kOpenH3String = "<H3";
|
||||
const char* BookmarkParser::kOpenTitleString = "<TITLE>";
|
||||
const char* BookmarkParser::kSeparatorString = "<HR>";
|
||||
|
||||
|
||||
BookmarkParser::BookmarkParser(void)
|
||||
: mResourceMgr(nsnull), mDataSource(nsnull)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = nsServiceManager::GetService(kRDFResourceManagerCID,
|
||||
kIRDFResourceManagerIID,
|
||||
(nsISupports**) &mResourceMgr);
|
||||
|
||||
PR_ASSERT(NS_SUCCEEDED(rv));
|
||||
}
|
||||
|
||||
BookmarkParser::~BookmarkParser(void)
|
||||
{
|
||||
if (mResourceMgr)
|
||||
nsServiceManager::ReleaseService(kRDFResourceManagerCID, mResourceMgr);
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
BookmarkParser::Parse(PRFileDesc* file, nsIRDFDataSource* dataSource)
|
||||
{
|
||||
NS_PRECONDITION(file && dataSource && mResourceMgr, "null ptr");
|
||||
if (! file)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (! dataSource)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (! mResourceMgr)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
// Initialize the parser for a run...
|
||||
mDataSource = dataSource;
|
||||
mState = eBookmarkParserState_Initial;
|
||||
mCounter = 0;
|
||||
mLastItem = nsnull;
|
||||
mLine.Truncate();
|
||||
|
||||
nsresult rv;
|
||||
char buf[1024];
|
||||
PRInt32 len;
|
||||
|
||||
while ((len = PR_Read(file, buf, sizeof(buf))) > 0)
|
||||
Tokenize(buf, len);
|
||||
|
||||
NS_IF_RELEASE(mLastItem);
|
||||
|
||||
rv = AddColumns();
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
BookmarkParser::AddColumns(void)
|
||||
{
|
||||
// XXX this is unsavory. I really don't like hard-coding the
|
||||
// columns that should be displayed here. What we should do is
|
||||
// merge in a "style" graph that contains just a wee bit of
|
||||
// information about columns, etc.
|
||||
nsresult rv;
|
||||
|
||||
nsIRDFResource* columns = nsnull;
|
||||
|
||||
static const char* gColumnTitles[] = {
|
||||
"Name",
|
||||
"Date Added",
|
||||
"Last Visited",
|
||||
"Last Modified",
|
||||
nsnull
|
||||
};
|
||||
|
||||
static const char* gColumnURIs[] = {
|
||||
kURINC_Name,
|
||||
kURINC_BookmarkAddDate,
|
||||
kURIWEB_LastVisitDate,
|
||||
kURIWEB_LastModifiedDate,
|
||||
nsnull
|
||||
};
|
||||
|
||||
const char* const* columnTitle = gColumnTitles;
|
||||
const char* const* columnURI = gColumnURIs;
|
||||
|
||||
if (NS_FAILED(rv = rdf_CreateAnonymousResource(mResourceMgr, &columns)))
|
||||
goto done;
|
||||
|
||||
if (NS_FAILED(rv = rdf_MakeSeq(mResourceMgr, mDataSource, columns)))
|
||||
goto done;
|
||||
|
||||
while (*columnTitle && *columnURI) {
|
||||
nsIRDFResource* column = nsnull;
|
||||
|
||||
if (NS_SUCCEEDED(rv = rdf_CreateAnonymousResource(mResourceMgr, &column))) {
|
||||
rdf_Assert(mResourceMgr, mDataSource, column, kURINC_Title, *columnTitle);
|
||||
rdf_Assert(mResourceMgr, mDataSource, column, kURINC_Column, *columnURI);
|
||||
|
||||
rdf_ContainerAddElement(mResourceMgr, mDataSource, columns, column);
|
||||
NS_IF_RELEASE(column);
|
||||
}
|
||||
|
||||
++columnTitle;
|
||||
++columnURI;
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
}
|
||||
|
||||
rdf_Assert(mResourceMgr, mDataSource, kURI_bookmarks, kURINC_Columns, columns);
|
||||
|
||||
done:
|
||||
NS_IF_RELEASE(columns);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
BookmarkParser::Tokenize(const char* buf, PRInt32 size)
|
||||
{
|
||||
for (PRInt32 i = 0; i < size; ++i) {
|
||||
char c = buf[i];
|
||||
if (c == '<') {
|
||||
if (mLine.Length() > 0) {
|
||||
NextToken();
|
||||
mLine.Truncate();
|
||||
}
|
||||
}
|
||||
mLine.Append(c);
|
||||
if (c == '>') {
|
||||
if (mLine.Length() > 0) {
|
||||
NextToken();
|
||||
mLine.Truncate();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
BookmarkParser::NextToken(void)
|
||||
{
|
||||
if (mLine[0] == '<') {
|
||||
DoStateTransition();
|
||||
return;
|
||||
}
|
||||
|
||||
// ok, we have a piece of content. can be the title, or a
|
||||
// description
|
||||
if ((mState == eBookmarkParserState_InTitle) ||
|
||||
(mState == eBookmarkParserState_InH3)) {
|
||||
nsIRDFResource* folder;
|
||||
|
||||
if (mStack.Count() > 0) {
|
||||
// a regular old folder
|
||||
|
||||
nsAutoString folderURI(kURI_bookmarks);
|
||||
folderURI.Append('#');
|
||||
folderURI.Append(++mCounter, 10);
|
||||
|
||||
if (NS_FAILED(mResourceMgr->GetUnicodeResource(folderURI, &folder)))
|
||||
return;
|
||||
|
||||
nsIRDFResource* parent = (nsIRDFResource*) mStack[mStack.Count() - 1];
|
||||
rdf_Assert(mResourceMgr, mDataSource, parent, kURINC_Folder, folder);
|
||||
}
|
||||
else {
|
||||
// it's the root
|
||||
if (NS_FAILED(mResourceMgr->GetResource(kURI_bookmarks, &folder)))
|
||||
return;
|
||||
}
|
||||
|
||||
if (mFolderDate.Length()) {
|
||||
AssertTime(folder, kURINC_BookmarkAddDate, mFolderDate);
|
||||
mFolderDate.Truncate();
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(mLastItem);
|
||||
mLastItem = folder;
|
||||
// XXX Implied
|
||||
//NS_ADDREF(mLastItem);
|
||||
//NS_RELEASE(folder);
|
||||
|
||||
if (mState != eBookmarkParserState_InTitle)
|
||||
rdf_Assert(mResourceMgr, mDataSource, mLastItem, kURINC_Name, mLine);
|
||||
|
||||
if (mLine.Find(kPersonalToolbar) == 0)
|
||||
rdf_Assert(mResourceMgr, mDataSource, mLastItem, kURIRDF_instanceOf, kURINC_PersonalToolbarFolderCategory);
|
||||
}
|
||||
else if (mState == eBookmarkParserState_InItemTitle) {
|
||||
PR_ASSERT(mLastItem);
|
||||
if (! mLastItem)
|
||||
return;
|
||||
|
||||
rdf_Assert(mResourceMgr, mDataSource, mLastItem, kURINC_Name, mLine);
|
||||
NS_IF_RELEASE(mLastItem);
|
||||
}
|
||||
else if (mState == eBookmarkParserState_InItemDescription) {
|
||||
rdf_Assert(mResourceMgr, mDataSource, mLastItem, kURINC_Description, mLine);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
BookmarkParser::DoStateTransition(void)
|
||||
{
|
||||
if (mLine.Find(kOpenAnchorString) == 0) {
|
||||
CreateBookmark();
|
||||
mState = eBookmarkParserState_InItemTitle;
|
||||
}
|
||||
else if (mLine.Find(kOpenH3String) == 0) {
|
||||
PRInt32 start = mLine.Find('"');
|
||||
PRInt32 end = mLine.RFind('"');
|
||||
if (start >= 0 && end >= 0)
|
||||
mLine.Mid(mFolderDate, start + 1, end - start - 1);
|
||||
mState = eBookmarkParserState_InH3;
|
||||
}
|
||||
else if (mLine.Find(kOpenTitleString) == 0) {
|
||||
mState = eBookmarkParserState_InTitle;
|
||||
}
|
||||
else if (mLine.Find(kDDString) == 0) {
|
||||
#if 0 // XXX if it doesn't already have a description? Huh?
|
||||
if (remoteStoreGetSlotValue(gLocalStore, mLastItem, gWebData->RDF_description,
|
||||
RDF_STRING_TYPE, false, true)
|
||||
== nsnull)
|
||||
#endif
|
||||
mState = eBookmarkParserState_InItemDescription;
|
||||
}
|
||||
else if (mLine.Find(kOpenDLString) == 0) {
|
||||
mStack.AppendElement(mLastItem);
|
||||
NS_ADDREF(mLastItem);
|
||||
}
|
||||
else if (mLine.Find(kCloseDLString) == 0) {
|
||||
PRInt32 count = mStack.Count();
|
||||
if (count) {
|
||||
nsIRDFNode* top = NS_STATIC_CAST(nsIRDFNode*, mStack[--count]);
|
||||
mStack.RemoveElementAt(count);
|
||||
NS_IF_RELEASE(top);
|
||||
}
|
||||
}
|
||||
else if (mLine.Find(kSeparatorString) == 0) {
|
||||
#if FIXME // separators
|
||||
addSlotValue(f, createSeparator(), gCoreVocab->RDF_parent, mStack[mStack.Count() - 1],
|
||||
RDF_RESOURCE_TYPE, nsnull);
|
||||
#endif
|
||||
mState = eBookmarkParserState_Initial;
|
||||
}
|
||||
else if ((mState == eBookmarkParserState_InItemDescription) &&
|
||||
(mLine.Find(kBRString) == 0)) {
|
||||
// XXX in the original bmk2rdf.c, we only added the
|
||||
// description in the case that it wasn't set already...why?
|
||||
rdf_Assert(mResourceMgr, mDataSource, mLastItem, kURINC_Description, mLine);
|
||||
}
|
||||
else {
|
||||
mState = eBookmarkParserState_Initial;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
BookmarkParser::CreateBookmark(void)
|
||||
{
|
||||
enum {
|
||||
eBmkAttribute_URL = 0,
|
||||
eBmkAttribute_AddDate = 1,
|
||||
eBmkAttribute_LastVisit = 2,
|
||||
eBmkAttribute_LastModified = 3
|
||||
};
|
||||
|
||||
nsAutoString values[4];
|
||||
PRInt32 index = 0;
|
||||
for (PRInt32 i = 0; i < 4; ++i) {
|
||||
PRInt32 start = mLine.Find('"', index);
|
||||
if (start == -1)
|
||||
break;
|
||||
|
||||
++start; // past the first quote
|
||||
|
||||
PRInt32 end = mLine.Find('"', start);
|
||||
PR_ASSERT(end > 0); // unterminated
|
||||
if (end == -1)
|
||||
end = mLine.Length();
|
||||
|
||||
mLine.Mid(values[i], start, end - start);
|
||||
index = end + 1;
|
||||
}
|
||||
|
||||
if (values[eBmkAttribute_URL].Length() == 0)
|
||||
return;
|
||||
|
||||
nsIRDFResource* bookmark;
|
||||
if (NS_FAILED(mResourceMgr->GetUnicodeResource(values[eBmkAttribute_URL], &bookmark)))
|
||||
return;
|
||||
|
||||
if (! mStack.Count())
|
||||
return;
|
||||
|
||||
nsIRDFResource* parent = (nsIRDFResource*) mStack[mStack.Count() - 1];
|
||||
if (! parent)
|
||||
return;
|
||||
|
||||
rdf_Assert(mResourceMgr, mDataSource, parent, kURINC_Bookmark, bookmark);
|
||||
|
||||
if (values[eBmkAttribute_AddDate].Length() > 0)
|
||||
AssertTime(bookmark, kURINC_BookmarkAddDate, values[eBmkAttribute_AddDate]);
|
||||
|
||||
if (values[eBmkAttribute_LastVisit].Length() > 0)
|
||||
AssertTime(bookmark, kURIWEB_LastVisitDate, values[eBmkAttribute_LastVisit]);
|
||||
|
||||
if (values[eBmkAttribute_LastModified].Length() > 0)
|
||||
AssertTime(bookmark, kURIWEB_LastModifiedDate, values[eBmkAttribute_LastModified]);
|
||||
|
||||
NS_IF_RELEASE(mLastItem);
|
||||
mLastItem = bookmark;
|
||||
// XXX Implied
|
||||
//NS_ADDREF(mLastItem);
|
||||
//NS_RELEASE(bookmark);
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
BookmarkParser::AssertTime(nsIRDFResource* object,
|
||||
const nsString& predicateURI,
|
||||
const nsString& time)
|
||||
{
|
||||
// XXX
|
||||
return rdf_Assert(mResourceMgr, mDataSource, object, predicateURI, time);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// BookmarkDataSourceImpl
|
||||
|
||||
/**
|
||||
* The bookmark data source uses a <tt>BookmarkParser</tt> to read the
|
||||
* <tt>bookmarks.html</tt> file from the local disk and present an
|
||||
* in-memory RDF graph based on it.
|
||||
*/
|
||||
class BookmarkDataSourceImpl : public nsIRDFDataSource {
|
||||
protected:
|
||||
static const char* kBookmarksFilename;
|
||||
|
||||
nsIRDFDataSource* mInner;
|
||||
|
||||
nsresult ReadBookmarks(void);
|
||||
nsresult WriteBookmarks(void);
|
||||
nsresult AddColumns(void);
|
||||
|
||||
public:
|
||||
BookmarkDataSourceImpl(void);
|
||||
virtual ~BookmarkDataSourceImpl(void);
|
||||
|
||||
// nsISupports
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIRDFDataSource
|
||||
NS_IMETHOD Init(const char* uri) {
|
||||
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,
|
||||
nsIRDFAssertionCursor** sources) {
|
||||
return mInner->GetSources(property, target, tv, sources);
|
||||
}
|
||||
|
||||
NS_IMETHOD GetTarget(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
PRBool tv,
|
||||
nsIRDFNode** target) {
|
||||
return mInner->GetTarget(source, property, tv, target);
|
||||
}
|
||||
|
||||
NS_IMETHOD GetTargets(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor** targets) {
|
||||
return mInner->GetTargets(source, property, tv, targets);
|
||||
}
|
||||
|
||||
NS_IMETHOD Assert(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
PRBool tv) {
|
||||
return mInner->Assert(source, property, target, tv);
|
||||
}
|
||||
|
||||
NS_IMETHOD Unassert(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
nsIRDFNode* target) {
|
||||
return mInner->Unassert(source, property, target);
|
||||
}
|
||||
|
||||
NS_IMETHOD HasAssertion(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
PRBool tv,
|
||||
PRBool* hasAssertion) {
|
||||
return mInner->HasAssertion(source, property, target, tv, hasAssertion);
|
||||
}
|
||||
|
||||
NS_IMETHOD AddObserver(nsIRDFObserver* n) {
|
||||
return mInner->AddObserver(n);
|
||||
}
|
||||
|
||||
NS_IMETHOD RemoveObserver(nsIRDFObserver* n) {
|
||||
return mInner->RemoveObserver(n);
|
||||
}
|
||||
|
||||
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
|
||||
nsIRDFArcsInCursor** labels) {
|
||||
return mInner->ArcLabelsIn(node, labels);
|
||||
}
|
||||
|
||||
NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
|
||||
nsIRDFArcsOutCursor** labels) {
|
||||
return mInner->ArcLabelsOut(source, labels);
|
||||
}
|
||||
|
||||
NS_IMETHOD Flush(void);
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// XXX we should get this from prefs.
|
||||
const char* BookmarkDataSourceImpl::kBookmarksFilename = "bookmarks.html";
|
||||
|
||||
BookmarkDataSourceImpl::BookmarkDataSourceImpl(void)
|
||||
{
|
||||
// XXX rvg there should be only one instance of this class.
|
||||
// this is actually true of all datasources.
|
||||
NS_INIT_REFCNT();
|
||||
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
|
||||
BookmarkDataSourceImpl::Flush(void)
|
||||
{
|
||||
return WriteBookmarks();
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
BookmarkDataSourceImpl::ReadBookmarks(void)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
PRFileDesc* f;
|
||||
if ((f = PR_Open(kBookmarksFilename, PR_RDONLY, 0644))) {
|
||||
BookmarkParser parser;
|
||||
rv = parser.Parse(f, this);
|
||||
PR_Close(f);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
BookmarkDataSourceImpl::WriteBookmarks(void)
|
||||
{
|
||||
//PR_ASSERT(0);
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
#if FIXME
|
||||
|
||||
static const nsString&
|
||||
rdf_NumericDate(const nsString& url)
|
||||
{
|
||||
nsAutoString result;
|
||||
PRInt32 len = url.Length();
|
||||
PRInt32 index = 0;
|
||||
|
||||
while (index < len && url[index] < '0' && url[index] > '9')
|
||||
++index;
|
||||
|
||||
if (index >= len)
|
||||
return result;
|
||||
|
||||
while (index < len && url[index] >= '0' && url[index] <= '9')
|
||||
result.Append(url[index++]);
|
||||
|
||||
result;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
HT_WriteOutAsBookmarks1 (RDF rdf, PRFileDesc *fp, RDF_Resource u, RDF_Resource top, int indent)
|
||||
{
|
||||
RDF_Cursor c = RDF_GetSources(rdf, u, gCoreVocab->RDF_parent, RDF_RESOURCE_TYPE, true);
|
||||
RDF_Resource next;
|
||||
char *date, *name, *url;
|
||||
int loop;
|
||||
|
||||
if (c == nsnull) return;
|
||||
if (u == top) {
|
||||
name = RDF_GetResourceName(rdf, u);
|
||||
ht_rjcprintf(fp, "<!DOCTYPE NETSCAPE-Bookmark-file-1>\n", nsnull);
|
||||
ht_rjcprintf(fp, "<!-- This is an automatically generated file.\n", nsnull);
|
||||
ht_rjcprintf(fp, "It will be read and overwritten.\n", nsnull);
|
||||
ht_rjcprintf(fp, "Do Not Edit! -->\n", nsnull);
|
||||
|
||||
ht_rjcprintf(fp, "<TITLE>%s</TITLE>\n", (name) ? name:"");
|
||||
ht_rjcprintf(fp, "<H1>%s</H1>\n<DL><p>\n", (name) ? name:"");
|
||||
}
|
||||
while ((next = RDF_NextValue(c)) != nsnull) {
|
||||
|
||||
url = resourceID(next);
|
||||
if (containerp(next) && (!startsWith("ftp:",url)) && (!startsWith("file:",url))
|
||||
&& (!startsWith("IMAP:", url)) && (!startsWith("nes:", url))
|
||||
&& (!startsWith("mail:", url)) && (!startsWith("cache:", url))
|
||||
&& (!startsWith("ldap:", url))) {
|
||||
for (loop=0; loop<indent; loop++) ht_rjcprintf(fp, " ", nsnull);
|
||||
|
||||
date = numericDate(resourceID(next));
|
||||
ht_rjcprintf(fp, "<DT><H3 ADD_DATE=\"%s\">", (date) ? date:"");
|
||||
if (date) freeMem(date);
|
||||
name = RDF_GetResourceName(rdf, next);
|
||||
ht_rjcprintf(fp, "%s</H3>\n", name);
|
||||
|
||||
for (loop=0; loop<indent; loop++) ht_rjcprintf(fp, " ", nsnull);
|
||||
ht_rjcprintf(fp, "<DL><p>\n", nsnull);
|
||||
HT_WriteOutAsBookmarks1(rdf, fp, next, top, indent+1);
|
||||
|
||||
for (loop=0; loop<indent; loop++) ht_rjcprintf(fp, " ", nsnull);
|
||||
|
||||
ht_rjcprintf(fp, "</DL><p>\n", nsnull);
|
||||
}
|
||||
else if (isSeparator(next)) {
|
||||
for (loop=0; loop<indent; loop++) ht_rjcprintf(fp, " ", nsnull);
|
||||
ht_rjcprintf(fp, "<HR>\n", nsnull);
|
||||
}
|
||||
else {
|
||||
char* bkAddDate = (char*)RDF_GetSlotValue(rdf, next,
|
||||
gNavCenter->RDF_bookmarkAddDate,
|
||||
RDF_STRING_TYPE, false, true);
|
||||
|
||||
for (loop=0; loop<indent; loop++) ht_rjcprintf(fp, " ", nsnull);
|
||||
|
||||
ht_rjcprintf(fp, "<DT><A HREF=\"%s\" ", resourceID(next));
|
||||
date = numericDate(bkAddDate);
|
||||
ht_rjcprintf(fp, "ADD_DATE=\"%s\" ", (date) ? date: "");
|
||||
if (date) freeMem(date);
|
||||
ht_rjcprintf(fp, "LAST_VISIT=\"%s\" ", resourceLastVisitDate(rdf, next));
|
||||
ht_rjcprintf(fp, "LAST_MODIFIED=\"%s\">", resourceLastModifiedDate(rdf, next));
|
||||
ht_rjcprintf(fp, "%s</A>\n", RDF_GetResourceName(rdf, next));
|
||||
|
||||
if (resourceDescription(rdf, next) != nsnull) {
|
||||
ht_rjcprintf(fp, "<DD>%s\n", resourceDescription(rdf, next));
|
||||
}
|
||||
}
|
||||
}
|
||||
RDF_DisposeCursor(c);
|
||||
if (u == top) {
|
||||
ht_rjcprintf(fp, "</DL>\n", nsnull);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult
|
||||
NS_NewRDFBookmarkDataSource(nsIRDFDataSource** result)
|
||||
{
|
||||
BookmarkDataSourceImpl* ds = new BookmarkDataSourceImpl();
|
||||
if (! ds)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*result = ds;
|
||||
NS_ADDREF(*result);
|
||||
return NS_OK;
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
// This header file just contains prototypes for the factory methods
|
||||
// for "builtin" data sources that are included in rdf.dll. Each of
|
||||
// these data sources is exposed to the external world via its CID in
|
||||
// ../include/nsRDFCID.h.
|
||||
|
||||
#ifndef nsBuiltinDataSources_h__
|
||||
#define nsBuiltinDataSources_h__
|
||||
|
||||
#include "nsError.h"
|
||||
|
||||
class nsIRDFDataSource;
|
||||
class nsIRDFDataBase;
|
||||
|
||||
// in nsBookmarkDataSource.cpp
|
||||
nsresult NS_NewRDFBookmarkDataSource(nsIRDFDataSource** result);
|
||||
|
||||
// in nsMemoryDataSource.cpp
|
||||
nsresult NS_NewRDFMemoryDataSource(nsIRDFDataSource** result);
|
||||
|
||||
// in nsSimpleDataBase.cpp
|
||||
nsresult NS_NewRDFSimpleDataBase(nsIRDFDataBase** result);
|
||||
|
||||
// in nsStreamDataSource.cpp
|
||||
nsresult NS_NewRDFStreamDataSource(nsIRDFDataSource** result);
|
||||
|
||||
#endif // nsBuiltinDataSources_h__
|
||||
|
||||
|
|
@ -0,0 +1,151 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsIRDFResourceManager.h"
|
||||
#include "nsRDFBuiltInDataSources.h"
|
||||
#include "nsRDFDataSourceCID.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
|
||||
static NS_DEFINE_CID(kRDFBookmarkDataSourceCID, NS_RDFBOOKMARKDATASOURCE_CID);
|
||||
|
||||
class RDFFactoryImpl : public nsIFactory
|
||||
{
|
||||
public:
|
||||
RDFFactoryImpl(const nsCID &aClass);
|
||||
|
||||
// nsISupports methods
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIFactory methods
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
protected:
|
||||
virtual ~RDFFactoryImpl();
|
||||
|
||||
private:
|
||||
nsCID mClassID;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
RDFFactoryImpl::RDFFactoryImpl(const nsCID &aClass)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mClassID = aClass;
|
||||
}
|
||||
|
||||
RDFFactoryImpl::~RDFFactoryImpl()
|
||||
{
|
||||
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
RDFFactoryImpl::QueryInterface(const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
// Always NULL result, in case of failure
|
||||
*aResult = nsnull;
|
||||
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aResult = NS_STATIC_CAST(nsISupports*, this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
} else if (aIID.Equals(kIFactoryIID)) {
|
||||
*aResult = NS_STATIC_CAST(nsIFactory*, this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(RDFFactoryImpl);
|
||||
NS_IMPL_RELEASE(RDFFactoryImpl);
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
RDFFactoryImpl::CreateInstance(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (aOuter)
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
*aResult = nsnull;
|
||||
|
||||
nsresult rv;
|
||||
PRBool wasRefCounted = PR_TRUE;
|
||||
nsISupports *inst = nsnull;
|
||||
if (mClassID.Equals(kRDFBookmarkDataSourceCID)) {
|
||||
if (NS_FAILED(rv = NS_NewRDFBookmarkDataSource((nsIRDFDataSource**) &inst)))
|
||||
return rv;
|
||||
}
|
||||
else {
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
|
||||
if (! inst)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
if (NS_FAILED(rv = inst->QueryInterface(aIID, aResult)))
|
||||
// We didn't get the right interface, so clean up
|
||||
delete inst;
|
||||
|
||||
if (wasRefCounted)
|
||||
NS_IF_RELEASE(inst);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult RDFFactoryImpl::LockFactory(PRBool aLock)
|
||||
{
|
||||
// Not implemented in simplest case.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
// return the proper factory to the caller
|
||||
extern "C" PR_IMPLEMENT(nsresult)
|
||||
NSGetFactory(const nsCID &aClass, nsIFactory **aFactory)
|
||||
{
|
||||
if (! aFactory)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aFactory = new RDFFactoryImpl(aClass);
|
||||
if (aFactory == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return (*aFactory)->QueryInterface(kIFactoryIID, (void**)aFactory);
|
||||
}
|
||||
|
|
@ -0,0 +1,239 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
A data source that can read itself from and write itself to a stream.
|
||||
|
||||
*/
|
||||
|
||||
#include "nsIDTD.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIParser.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
#include "nsIRDFContentSink.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsParserCIID.h"
|
||||
#include "nsRDFBaseCID.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID);
|
||||
static NS_DEFINE_IID(kIParserIID, NS_IPARSER_IID);
|
||||
static NS_DEFINE_IID(kIRDFContentSinkIID, NS_IRDFCONTENTSINK_IID);
|
||||
static NS_DEFINE_IID(kIRDFDataSourceIID, NS_IRDFDATASOURCE_IID);
|
||||
static NS_DEFINE_IID(kIStreamListenerIID, NS_ISTREAMLISTENER_IID);
|
||||
|
||||
static NS_DEFINE_CID(kParserCID, NS_PARSER_IID); // XXX
|
||||
static NS_DEFINE_CID(kRDFContentSinkCID, NS_RDFCONTENTSINK_CID);
|
||||
static NS_DEFINE_CID(kWellFormedDTDCID, NS_WELLFORMEDDTD_CID);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class StreamDataSourceImpl : public nsIRDFDataSource
|
||||
{
|
||||
protected:
|
||||
nsIURL* mURL;
|
||||
nsIRDFDataSource* mInner;
|
||||
|
||||
public:
|
||||
StreamDataSourceImpl(void);
|
||||
virtual ~StreamDataSourceImpl(void);
|
||||
|
||||
// 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,
|
||||
nsIRDFAssertionCursor** sources) {
|
||||
return mInner->GetSources(property, target, tv, sources);
|
||||
}
|
||||
|
||||
NS_IMETHOD GetTarget(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
PRBool tv,
|
||||
nsIRDFNode** target) {
|
||||
return mInner->GetTarget(source, property, tv, target);
|
||||
}
|
||||
|
||||
NS_IMETHOD GetTargets(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor** targets) {
|
||||
return mInner->GetTargets(source, property, tv, targets);
|
||||
}
|
||||
|
||||
NS_IMETHOD Assert(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
PRBool tv) {
|
||||
return mInner->Assert(source, property, target, tv);
|
||||
}
|
||||
|
||||
NS_IMETHOD Unassert(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
nsIRDFNode* target) {
|
||||
return mInner->Unassert(source, property, target);
|
||||
}
|
||||
|
||||
NS_IMETHOD HasAssertion(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
PRBool tv,
|
||||
PRBool* hasAssertion) {
|
||||
return mInner->HasAssertion(source, property, target, tv, hasAssertion);
|
||||
}
|
||||
|
||||
NS_IMETHOD AddObserver(nsIRDFObserver* n) {
|
||||
return mInner->AddObserver(n);
|
||||
}
|
||||
|
||||
NS_IMETHOD RemoveObserver(nsIRDFObserver* n) {
|
||||
return mInner->RemoveObserver(n);
|
||||
}
|
||||
|
||||
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
|
||||
nsIRDFArcsInCursor** labels) {
|
||||
return mInner->ArcLabelsIn(node, labels);
|
||||
}
|
||||
|
||||
NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
|
||||
nsIRDFArcsOutCursor** labels) {
|
||||
return mInner->ArcLabelsOut(source, labels);
|
||||
}
|
||||
|
||||
NS_IMETHOD Flush(void);
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
StreamDataSourceImpl::StreamDataSourceImpl(void)
|
||||
: mURL(nsnull)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
StreamDataSourceImpl::~StreamDataSourceImpl(void)
|
||||
{
|
||||
NS_IF_RELEASE(mURL);
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(StreamDataSourceImpl, kIRDFDataSourceIID);
|
||||
|
||||
NS_IMETHODIMP
|
||||
StreamDataSourceImpl::Init(const char* uri)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
if (NS_FAILED(rv = NS_NewURL(&mURL, uri)))
|
||||
return rv;
|
||||
|
||||
nsINameSpaceManager* ns = nsnull;
|
||||
nsIRDFContentSink* sink = nsnull;
|
||||
nsIParser* parser = nsnull;
|
||||
nsIDTD* dtd = nsnull;
|
||||
nsIStreamListener* lsnr = nsnull;
|
||||
|
||||
// XXX Get a namespace manager *here*
|
||||
PR_ASSERT(0);
|
||||
|
||||
if (NS_FAILED(rv = nsRepository::CreateInstance(kRDFContentSinkCID,
|
||||
nsnull,
|
||||
kIRDFContentSinkIID,
|
||||
(void**) &sink)))
|
||||
goto done;
|
||||
|
||||
if (NS_FAILED(rv = sink->Init(mURL, ns)))
|
||||
goto done;
|
||||
|
||||
if (NS_FAILED(rv = sink->SetDataSource(this)))
|
||||
goto done;
|
||||
|
||||
if (NS_FAILED(rv = nsRepository::CreateInstance(kParserCID,
|
||||
nsnull,
|
||||
kIParserIID,
|
||||
(void**) &parser)))
|
||||
goto done;
|
||||
|
||||
parser->SetContentSink(sink);
|
||||
|
||||
if (NS_FAILED(rv = nsRepository::CreateInstance(kWellFormedDTDCID,
|
||||
nsnull,
|
||||
kIDTDIID,
|
||||
(void**) &dtd)))
|
||||
goto done;
|
||||
|
||||
parser->RegisterDTD(dtd);
|
||||
|
||||
if (NS_FAILED(rv = parser->QueryInterface(kIStreamListenerIID, (void**) &lsnr)))
|
||||
goto done;
|
||||
|
||||
// XXX This _can't_ be all I need to do -- how do I start the parser?
|
||||
if (NS_FAILED(parser->Parse(mURL)))
|
||||
goto done;
|
||||
|
||||
if (NS_FAILED(NS_OpenURL(mURL, lsnr)))
|
||||
goto done;
|
||||
|
||||
done:
|
||||
NS_IF_RELEASE(lsnr);
|
||||
NS_IF_RELEASE(dtd);
|
||||
NS_IF_RELEASE(parser);
|
||||
NS_IF_RELEASE(sink);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
StreamDataSourceImpl::Flush(void)
|
||||
{
|
||||
// XXX walk through all the resources, writing <RDF:Description>
|
||||
// elements with properties for each.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult
|
||||
NS_NewRDFStreamDataSource(nsIRDFDataSource** result)
|
||||
{
|
||||
StreamDataSourceImpl* ds = new StreamDataSourceImpl();
|
||||
if (! ds)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*result = ds;
|
||||
NS_ADDREF(*result);
|
||||
return NS_OK;
|
||||
}
|
Загрузка…
Ссылка в новой задаче