mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
The Great Cursor Excorcism. Removed cursors in favor of enumerators. Misc updates to purge the xpidl stubs stuff in preparation for XPConnect. Details on RDF_19990422_BRANCH.
This commit is contained in:
parent
f34899c1ac
commit
4dac3b7dc6
@ -28,7 +28,6 @@
|
||||
#include "nsRDFCID.h"
|
||||
#include "nsIRDFResource.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsHashtable.h"
|
||||
#include "nsString.h"
|
||||
#include "nsXPIDLString.h"
|
||||
@ -75,7 +74,7 @@ public:
|
||||
NS_IMETHOD GetSources(nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor** sources /* out */) ;
|
||||
nsISimpleEnumerator** sources /* out */) ;
|
||||
NS_IMETHOD GetTarget(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
PRBool tv,
|
||||
@ -83,7 +82,7 @@ public:
|
||||
NS_IMETHOD GetTargets(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor** targets /* out */) ;
|
||||
nsISimpleEnumerator** targets /* out */) ;
|
||||
NS_IMETHOD Assert(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
@ -99,10 +98,10 @@ public:
|
||||
NS_IMETHOD AddObserver(nsIRDFObserver* n) ;
|
||||
NS_IMETHOD RemoveObserver(nsIRDFObserver* n) ;
|
||||
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
|
||||
nsIRDFArcsInCursor** labels /* out */) ;
|
||||
nsISimpleEnumerator** labels /* out */) ;
|
||||
NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
|
||||
nsIRDFArcsOutCursor** labels /* out */) ;
|
||||
NS_IMETHOD GetAllResources(nsIRDFResourceCursor** aCursor) ;
|
||||
nsISimpleEnumerator** labels /* out */) ;
|
||||
NS_IMETHOD GetAllResources(nsISimpleEnumerator** aResult) ;
|
||||
NS_IMETHOD Flush(void) ;
|
||||
NS_IMETHOD GetAllCommands(nsIRDFResource* source,
|
||||
nsIEnumerator/*<nsIRDFResource>*/** commands) ;
|
||||
@ -493,7 +492,7 @@ NS_IMETHODIMP
|
||||
nsChromeRegistry::GetSources(nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor** sources /* out */)
|
||||
nsISimpleEnumerator** sources /* out */)
|
||||
{
|
||||
return mInner->GetSources(property, target, tv, sources);
|
||||
}
|
||||
@ -512,7 +511,7 @@ NS_IMETHODIMP
|
||||
nsChromeRegistry::GetTargets(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor** targets /* out */)
|
||||
nsISimpleEnumerator** targets /* out */)
|
||||
{
|
||||
return mInner->GetTargets(source, property, tv, targets);
|
||||
}
|
||||
@ -555,18 +554,18 @@ NS_IMETHODIMP nsChromeRegistry::RemoveObserver(nsIRDFObserver* n)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsChromeRegistry::ArcLabelsIn(nsIRDFNode* node,
|
||||
nsIRDFArcsInCursor** labels /* out */)
|
||||
nsISimpleEnumerator** labels /* out */)
|
||||
{
|
||||
return mInner->ArcLabelsIn(node, labels);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsChromeRegistry::ArcLabelsOut(nsIRDFResource* source,
|
||||
nsIRDFArcsOutCursor** labels /* out */)
|
||||
nsISimpleEnumerator** labels /* out */)
|
||||
{
|
||||
return mInner->ArcLabelsOut(source, labels);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsChromeRegistry::GetAllResources(nsIRDFResourceCursor** aCursor)
|
||||
NS_IMETHODIMP nsChromeRegistry::GetAllResources(nsISimpleEnumerator** aCursor)
|
||||
{
|
||||
return mInner->GetAllResources(aCursor);
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ private:
|
||||
nsIAtom* aName,
|
||||
const nsString& aValue);
|
||||
|
||||
~nsXULAttribute();
|
||||
virtual ~nsXULAttribute();
|
||||
|
||||
friend nsresult
|
||||
NS_NewXULAttribute(nsXULAttribute** aResult,
|
||||
|
@ -60,7 +60,6 @@
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIRDFCompositeDataSource.h"
|
||||
#include "nsIRDFContentModelBuilder.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIRDFDocument.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFService.h"
|
||||
|
@ -58,7 +58,6 @@
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIRDFCompositeDataSource.h"
|
||||
#include "nsIRDFContentModelBuilder.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
#include "nsIRDFDocument.h"
|
||||
#include "nsIRDFNode.h"
|
||||
@ -2590,16 +2589,6 @@ XULDocumentImpl::GetStyleSheets(nsIDOMStyleSheetCollection** aStyleSheets)
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsIDOMXULDocument interface
|
||||
|
||||
NS_IMETHODIMP
|
||||
XULDocumentImpl::GetRdf(nsIRDFService** aRDFService)
|
||||
{
|
||||
// XXX this is a temporary hack until the component manager starts
|
||||
// to work.
|
||||
return nsServiceManager::GetService(kRDFServiceCID,
|
||||
nsIRDFService::GetIID(),
|
||||
(nsISupports**) aRDFService);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
XULDocumentImpl::GetElementById(const nsString& aId, nsIDOMElement** aReturn)
|
||||
{
|
||||
@ -3058,25 +3047,6 @@ XULDocumentImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObjec
|
||||
|
||||
if (nsnull == mScriptObject) {
|
||||
res = NS_NewScriptXULDocument(aContext, (nsISupports *)(nsIDOMXULDocument *)this, global, (void**)&mScriptObject);
|
||||
|
||||
#if defined(XPIDL_JS_STUBS)
|
||||
JSContext* cx = (JSContext*) aContext->GetNativeContext();
|
||||
nsIRDFNode::InitJSClass(cx);
|
||||
nsIRDFResource::InitJSClass(cx);
|
||||
nsIRDFLiteral::InitJSClass(cx);
|
||||
nsIRDFDate::InitJSClass(cx);
|
||||
nsIRDFInt::InitJSClass(cx);
|
||||
nsIRDFCursor::InitJSClass(cx);
|
||||
nsIRDFAssertionCursor::InitJSClass(cx);
|
||||
nsIRDFArcsInCursor::InitJSClass(cx);
|
||||
nsIRDFArcsOutCursor::InitJSClass(cx);
|
||||
nsIRDFResourceCursor::InitJSClass(cx);
|
||||
nsIRDFObserver::InitJSClass(cx);
|
||||
nsIRDFDataSource::InitJSClass(cx);
|
||||
nsIRDFCompositeDataSource::InitJSClass(cx);
|
||||
nsIRDFService::InitJSClass(cx);
|
||||
#endif
|
||||
|
||||
}
|
||||
*aScriptObject = mScriptObject;
|
||||
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include "nsIDocument.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIRDFContentModelBuilder.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIRDFCompositeDataSource.h"
|
||||
#include "nsIRDFDocument.h"
|
||||
#include "nsIRDFNode.h"
|
||||
|
@ -45,7 +45,6 @@
|
||||
#include "nsIDocument.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIRDFContentModelBuilder.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIRDFCompositeDataSource.h"
|
||||
#include "nsIRDFDocument.h"
|
||||
#include "nsIRDFNode.h"
|
||||
@ -479,9 +478,9 @@ RDFGenericBuilderImpl::CreateContents(nsIContent* aElement)
|
||||
// handles multi-attributes. For performance...
|
||||
|
||||
// Create a cursor that'll enumerate all of the outbound arcs
|
||||
nsCOMPtr<nsIRDFArcsOutCursor> properties;
|
||||
if (NS_FAILED(rv = mDB->ArcLabelsOut(resource, getter_AddRefs(properties))))
|
||||
return rv;
|
||||
nsCOMPtr<nsISimpleEnumerator> properties;
|
||||
rv = mDB->ArcLabelsOut(resource, getter_AddRefs(properties));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// rjc - sort
|
||||
nsISupportsArray *tempArray;
|
||||
@ -489,17 +488,18 @@ RDFGenericBuilderImpl::CreateContents(nsIContent* aElement)
|
||||
return(rv);
|
||||
|
||||
while (1) {
|
||||
rv = properties->Advance();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
PRBool hasMore;
|
||||
rv = properties->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (rv == NS_RDF_CURSOR_EMPTY)
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> property;
|
||||
nsCOMPtr<nsISupports> isupports;
|
||||
rv = properties->GetNext(getter_AddRefs(isupports));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (NS_FAILED(rv = properties->GetLabel(getter_AddRefs(property))))
|
||||
break;
|
||||
nsCOMPtr<nsIRDFResource> property = do_QueryInterface(isupports);
|
||||
|
||||
// If it's not a widget item property, then it doesn't specify an
|
||||
// object that is member of the current container element;
|
||||
@ -510,42 +510,33 @@ RDFGenericBuilderImpl::CreateContents(nsIContent* aElement)
|
||||
|
||||
// Create a second cursor that'll enumerate all of the values
|
||||
// for all of the arcs.
|
||||
nsCOMPtr<nsIRDFAssertionCursor> assertions;
|
||||
if (NS_FAILED(rv = mDB->GetTargets(resource, property, PR_TRUE, getter_AddRefs(assertions)))) {
|
||||
NS_ERROR("unable to get targets for property");
|
||||
return rv;
|
||||
}
|
||||
nsCOMPtr<nsISimpleEnumerator> targets;
|
||||
rv = mDB->GetTargets(resource, property, PR_TRUE, getter_AddRefs(targets));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
while (1) {
|
||||
rv = assertions->Advance();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
PRBool hasMore;
|
||||
rv = targets->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (rv == NS_RDF_CURSOR_EMPTY)
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsCOMPtr<nsIRDFNode> value;
|
||||
if (NS_FAILED(rv = assertions->GetValue(getter_AddRefs(value)))) {
|
||||
NS_ERROR("unable to get cursor value");
|
||||
// return rv;
|
||||
break;
|
||||
}
|
||||
nsCOMPtr<nsISupports> isupports;
|
||||
rv = targets->GetNext(getter_AddRefs(isupports));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> valueResource;
|
||||
if (NS_SUCCEEDED(value->QueryInterface(kIRDFResourceIID, (void**) getter_AddRefs(valueResource)))
|
||||
&& IsContainmentProperty(aElement, property)) {
|
||||
nsCOMPtr<nsIRDFResource> valueResource = do_QueryInterface(isupports);
|
||||
if (valueResource && IsContainmentProperty(aElement, property)) {
|
||||
/* XXX hack: always append value resource 1st!
|
||||
due to sort callback implementation */
|
||||
tempArray->AppendElement(valueResource);
|
||||
tempArray->AppendElement(property);
|
||||
}
|
||||
else {
|
||||
/* if (NS_FAILED(rv = SetCellValue(aElement, property, value))) {
|
||||
NS_ERROR("unable to set cell value");
|
||||
// return rv;
|
||||
break;
|
||||
XXX Dave - WHY IS THIS HERE?
|
||||
}*/
|
||||
nsCOMPtr<nsIRDFNode> value = do_QueryInterface(isupports);
|
||||
rv = SetWidgetAttribute(aElement, property, value);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1316,33 +1307,42 @@ RDFGenericBuilderImpl::IsContainmentProperty(nsIContent* aElement, nsIRDFResourc
|
||||
PRBool
|
||||
RDFGenericBuilderImpl::IsContainer(nsIContent* aElement, nsIRDFResource* aResource)
|
||||
{
|
||||
PRBool result = PR_FALSE;
|
||||
nsCOMPtr<nsIRDFArcsOutCursor> arcs;
|
||||
if (NS_FAILED(mDB->ArcLabelsOut(aResource, getter_AddRefs(arcs)))) {
|
||||
NS_ERROR("unable to get arcs out");
|
||||
return result;
|
||||
}
|
||||
// Look at all of the arcs extending _out_ of the resource: if any
|
||||
// of them are that "containment" property, then we know we'll
|
||||
// have children.
|
||||
|
||||
// XXX Per Bug 3367, this'll have to be fixed.
|
||||
nsCOMPtr<nsISimpleEnumerator> arcs;
|
||||
nsresult rv;
|
||||
|
||||
rv = mDB->ArcLabelsOut(aResource, getter_AddRefs(arcs));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get arcs out");
|
||||
if (NS_FAILED(rv))
|
||||
return PR_FALSE;
|
||||
|
||||
while (1) {
|
||||
nsresult rv = arcs->Advance();
|
||||
PRBool hasMore;
|
||||
nsresult rv = arcs->HasMoreElements(&hasMore);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "severe error advancing cursor");
|
||||
if (NS_FAILED(rv))
|
||||
return PR_FALSE;
|
||||
|
||||
if (rv == NS_RDF_CURSOR_EMPTY)
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> property;
|
||||
if (NS_FAILED(arcs->GetLabel(getter_AddRefs(property)))) {
|
||||
NS_ERROR("unable to get cursor value");
|
||||
return result;
|
||||
}
|
||||
nsCOMPtr<nsISupports> isupports;
|
||||
rv = arcs->GetNext(getter_AddRefs(isupports));
|
||||
if (NS_FAILED(rv))
|
||||
return PR_FALSE;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> property = do_QueryInterface(isupports);
|
||||
|
||||
// Ignore properties that are used to indicate "tree-ness"
|
||||
if (IsContainmentProperty(aElement, property))
|
||||
return PR_TRUE;
|
||||
}
|
||||
return result;
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
|
@ -3,8 +3,6 @@ interface XULDocument : Document {
|
||||
/* IID: { 0x17ddd8c0, 0xc5f8, 0x11d2, \
|
||||
{ 0xa6, 0xae, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } } */
|
||||
|
||||
readonly attribute xpidl nsIRDFService rdf;
|
||||
|
||||
Element getElementById(in DOMString id);
|
||||
|
||||
NodeList getElementsByAttribute(in DOMString name, in DOMString value);
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include "nsIScriptContext.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
|
||||
class nsIRDFService;
|
||||
class nsIDOMElement;
|
||||
class nsIDOMNodeList;
|
||||
|
||||
@ -37,8 +36,6 @@ class nsIDOMXULDocument : public nsIDOMDocument {
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IDOMXULDOCUMENT_IID; return iid; }
|
||||
|
||||
NS_IMETHOD GetRdf(nsIRDFService** aRdf)=0;
|
||||
|
||||
NS_IMETHOD GetElementById(const nsString& aId, nsIDOMElement** aReturn)=0;
|
||||
|
||||
NS_IMETHOD GetElementsByAttribute(const nsString& aName, const nsString& aValue, nsIDOMNodeList** aReturn)=0;
|
||||
@ -46,14 +43,12 @@ public:
|
||||
|
||||
|
||||
#define NS_DECL_IDOMXULDOCUMENT \
|
||||
NS_IMETHOD GetRdf(nsIRDFService** aRdf); \
|
||||
NS_IMETHOD GetElementById(const nsString& aId, nsIDOMElement** aReturn); \
|
||||
NS_IMETHOD GetElementsByAttribute(const nsString& aName, const nsString& aValue, nsIDOMNodeList** aReturn); \
|
||||
|
||||
|
||||
|
||||
#define NS_FORWARD_IDOMXULDOCUMENT(_to) \
|
||||
NS_IMETHOD GetRdf(nsIRDFService** aRdf) { return _to GetRdf(aRdf); } \
|
||||
NS_IMETHOD GetElementById(const nsString& aId, nsIDOMElement** aReturn) { return _to GetElementById(aId, aReturn); } \
|
||||
NS_IMETHOD GetElementsByAttribute(const nsString& aName, const nsString& aValue, nsIDOMNodeList** aReturn) { return _to GetElementsByAttribute(aName, aValue, aReturn); } \
|
||||
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIRDFService.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMXULDocument.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
@ -35,22 +34,14 @@
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
|
||||
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
|
||||
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
|
||||
static NS_DEFINE_IID(kIElementIID, NS_IDOMELEMENT_IID);
|
||||
static NS_DEFINE_IID(kIXULDocumentIID, NS_IDOMXULDOCUMENT_IID);
|
||||
static NS_DEFINE_IID(kINodeListIID, NS_IDOMNODELIST_IID);
|
||||
|
||||
NS_DEF_PTR(nsIRDFService);
|
||||
NS_DEF_PTR(nsIDOMElement);
|
||||
NS_DEF_PTR(nsIDOMXULDocument);
|
||||
NS_DEF_PTR(nsIDOMNodeList);
|
||||
|
||||
//
|
||||
// XULDocument property ids
|
||||
//
|
||||
enum XULDocument_slots {
|
||||
XULDOCUMENT_RDF = -1
|
||||
};
|
||||
|
||||
/***********************************************************************/
|
||||
//
|
||||
@ -68,18 +59,7 @@ GetXULDocumentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
|
||||
if (JSVAL_IS_INT(id)) {
|
||||
switch(JSVAL_TO_INT(id)) {
|
||||
case XULDOCUMENT_RDF:
|
||||
{
|
||||
nsIRDFService* prop;
|
||||
if (NS_OK == a->GetRdf(&prop)) {
|
||||
// get the js object
|
||||
*vp = OBJECT_TO_JSVAL(nsIRDFService::GetJSObject(cx, prop));
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 0:
|
||||
default:
|
||||
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
|
||||
}
|
||||
@ -250,7 +230,6 @@ JSClass XULDocumentClass = {
|
||||
//
|
||||
static JSPropertySpec XULDocumentProperties[] =
|
||||
{
|
||||
{"rdf", XULDOCUMENT_RDF, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{0}
|
||||
};
|
||||
|
||||
|
@ -73,7 +73,11 @@ GetXULElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
nsIRDFResource* prop;
|
||||
if (NS_OK == a->GetResource(&prop)) {
|
||||
// get the js object
|
||||
#ifdef XPIDL_JS_STUBS
|
||||
*vp = OBJECT_TO_JSVAL(nsIRDFResource::GetJSObject(cx, prop));
|
||||
#else
|
||||
nsJSUtils::nsConvertXPCObjectToJSVal(prop, nsIRDFResource::GetIID(), cx, vp);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
|
@ -67,7 +67,11 @@ GetXULTreeElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
nsIRDFCompositeDataSource* prop;
|
||||
if (NS_OK == a->GetDatabase(&prop)) {
|
||||
// get the js object
|
||||
#ifdef XPIDL_JS_STUBS
|
||||
*vp = OBJECT_TO_JSVAL(nsIRDFCompositeDataSource::GetJSObject(cx, prop));
|
||||
#else
|
||||
nsJSUtils::nsConvertXPCObjectToJSVal(prop, nsIRDFCompositeDataSource::GetIID(), cx, vp);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
|
@ -33,11 +33,11 @@ nsRDFInterfaces.h: nsRDFInterfaces.idl
|
||||
@echo +++ make: generating XPIDL headers
|
||||
$(XPIDL) -m header $(XPIDL_INCLUDES) $**
|
||||
|
||||
nsRDFInterfaces.cpp: nsRDFInterfaces.idl
|
||||
@echo +++ make: generating XPIDL stubs
|
||||
$(XPIDL) -m stub $(XPIDL_INCLUDES) $**
|
||||
nsRDFInterfaces.xpt: nsRDFInterfaces.idl
|
||||
@echo +++ make: generating XPIDL typelib
|
||||
$(XPIDL) -m typelib $(XPIDL_INCLUDES) $**
|
||||
|
||||
export:: nsRDFInterfaces.h nsRDFInterfaces.cpp
|
||||
export:: nsRDFInterfaces.h nsRDFInterfaces.xpt
|
||||
$(MAKE_INSTALL) nsRDFInterfaces.h $(DEPTH)\rdf\base\public
|
||||
$(MAKE_INSTALL) nsRDFInterfaces.cpp $(DEPTH)\rdf\base\src
|
||||
$(MAKE_INSTALL) nsRDFInterfaces.xpt $(DEPTH)\rdf\build
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
*/
|
||||
|
||||
#include "nsIEnumerator.idl"
|
||||
#include "nsISimpleEnumerator.idl"
|
||||
#include "nsISupports.idl"
|
||||
#include "nsISupportsArray.idl"
|
||||
|
||||
@ -96,75 +97,6 @@ interface nsIRDFInt : nsIRDFNode {
|
||||
|
||||
interface nsIRDFDataSource;
|
||||
|
||||
// An enumeration interface
|
||||
[scriptable, uuid(1C2ABDB0-4CEF-11D2-BC16-00805F912FE7)]
|
||||
interface nsIRDFCursor : nsISupports {
|
||||
// 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.
|
||||
void Advance();
|
||||
|
||||
// The data source from which the current item was obtained.
|
||||
readonly attribute nsIRDFDataSource DataSource;
|
||||
|
||||
// Irrespective of the query, a cursor is an interator over a set;
|
||||
// this member is the current value of the cursor.
|
||||
readonly attribute nsIRDFNode Value;
|
||||
};
|
||||
|
||||
// An nsIRDFAssertionCursor is an iterator over a set of assertions,
|
||||
// each of which has a source node, a target node, an arc label, and a
|
||||
// truth value.
|
||||
[scriptable, uuid(1ED57100-9904-11d2-8EBA-00805F29F370)]
|
||||
interface nsIRDFAssertionCursor : nsIRDFCursor {
|
||||
|
||||
// The source node of the current assertion.
|
||||
readonly attribute nsIRDFResource Source;
|
||||
|
||||
// The label of the current assertion
|
||||
readonly attribute nsIRDFResource Label;
|
||||
|
||||
// The target node of the current assertion
|
||||
readonly attribute nsIRDFNode Target;
|
||||
|
||||
// The truth value of the current assertion
|
||||
readonly attribute boolean TruthValue;
|
||||
};
|
||||
|
||||
|
||||
// An nsIRDFArcsInCursor enumerates the unique labels of
|
||||
// the arcs that terminate ("point in to") a node.
|
||||
[scriptable, uuid(1ED57102-9904-11d2-8EBA-00805F29F370)]
|
||||
interface nsIRDFArcsInCursor : nsIRDFCursor {
|
||||
// The label of the current arc
|
||||
readonly attribute nsIRDFResource Label;
|
||||
|
||||
// The target of the current arc (always the same for a given
|
||||
// arcs-in cursor).
|
||||
readonly attribute nsIRDFNode Target;
|
||||
};
|
||||
|
||||
// An nsIRDFArcsOutCursor enumerates the unique labels of
|
||||
// arcs that original ("point out of") a resource.
|
||||
[scriptable, uuid(1ED57101-9904-11d2-8EBA-00805F29F370)]
|
||||
interface nsIRDFArcsOutCursor : nsIRDFCursor {
|
||||
// The source of the current arc (always the same for a give
|
||||
// arcs-out cursor).
|
||||
readonly attribute nsIRDFResource Source;
|
||||
|
||||
// The label of the current arc
|
||||
readonly attribute nsIRDFResource Label;
|
||||
};
|
||||
|
||||
// An nsIRDFResourceCursor enumerats a set of resources
|
||||
[scriptable, uuid(C2850C10-B0CF-11d2-A684-00104BDE6048)]
|
||||
interface nsIRDFResourceCursor : nsIRDFCursor {
|
||||
// The current resource
|
||||
readonly attribute nsIRDFResource Resource;
|
||||
};
|
||||
|
||||
// An nsIRDFObserver object is an observer that will be notified
|
||||
// when assertions are made or removed from a datasource
|
||||
[scriptable, uuid(3CC75360-484A-11D2-BC16-00805F912FE7)]
|
||||
@ -206,11 +138,11 @@ interface nsIRDFDataSource : nsISupports {
|
||||
// specified arc & truth value
|
||||
//
|
||||
// @return NS_OK unless a catastrophic error occurs. If the
|
||||
// method returns NS_OK, you may assume that nsIRDFCursor points
|
||||
// method returns NS_OK, you may assume that nsISimpleEnumerator points
|
||||
// to a valid (but possibly empty) cursor.
|
||||
nsIRDFAssertionCursor GetSources(in nsIRDFResource aProperty,
|
||||
in nsIRDFNode aTarget,
|
||||
in boolean aTruthValue);
|
||||
nsISimpleEnumerator GetSources(in nsIRDFResource aProperty,
|
||||
in nsIRDFNode aTarget,
|
||||
in boolean aTruthValue);
|
||||
|
||||
// Find a child of that is related to the source by the given arc
|
||||
// arc and truth value
|
||||
@ -225,11 +157,11 @@ interface nsIRDFDataSource : nsISupports {
|
||||
// arc and truth value.
|
||||
//
|
||||
// @return NS_OK unless a catastrophic error occurs. If the
|
||||
// method returns NS_OK, you may assume that nsIRDFCursor points
|
||||
// method returns NS_OK, you may assume that nsISimpleEnumerator points
|
||||
// to a valid (but possibly empty) cursor.
|
||||
nsIRDFAssertionCursor GetTargets(in nsIRDFResource aSource,
|
||||
in nsIRDFResource aProperty,
|
||||
in boolean aTruthValue);
|
||||
nsISimpleEnumerator GetTargets(in nsIRDFResource aSource,
|
||||
in nsIRDFResource aProperty,
|
||||
in boolean aTruthValue);
|
||||
|
||||
// Add an assertion to the graph.
|
||||
void Assert(in nsIRDFResource aSource,
|
||||
@ -258,20 +190,20 @@ interface nsIRDFDataSource : nsISupports {
|
||||
//
|
||||
// @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.
|
||||
nsIRDFArcsInCursor ArcLabelsIn(in nsIRDFNode aNode);
|
||||
// possible empty) nsISimpleEnumerator object.
|
||||
nsISimpleEnumerator ArcLabelsIn(in nsIRDFNode aNode);
|
||||
|
||||
// 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.
|
||||
nsIRDFArcsOutCursor ArcLabelsOut(in nsIRDFResource aSource);
|
||||
// possible empty) nsISimpleEnumerator object.
|
||||
nsISimpleEnumerator ArcLabelsOut(in nsIRDFResource aSource);
|
||||
|
||||
// Retrieve all of the resources that the data source currently
|
||||
// refers to.
|
||||
nsIRDFResourceCursor GetAllResources();
|
||||
nsISimpleEnumerator GetAllResources();
|
||||
|
||||
// Request that a data source write it's contents out to
|
||||
// permanent storage if applicable.
|
||||
|
@ -1,7 +1,6 @@
|
||||
rdf.h
|
||||
nsIRDFCompositeDataSource.h
|
||||
nsIRDFContentSink.h
|
||||
nsIRDFCursor.h
|
||||
nsIRDFDataSource.h
|
||||
nsIRDFNode.h
|
||||
nsIRDFObserver.h
|
||||
@ -11,4 +10,3 @@ nsIRDFService.h
|
||||
nsIRDFXMLDataSource.h
|
||||
nsIRDFXMLSource.h
|
||||
nsRDFInterfaces.h
|
||||
rdf_qsort.h
|
||||
|
@ -28,7 +28,6 @@ EXPORTS = \
|
||||
rdf.h \
|
||||
nsIRDFCompositeDataSource.h \
|
||||
nsIRDFContentSink.h \
|
||||
nsIRDFCursor.h \
|
||||
nsIRDFDataSource.h \
|
||||
nsIRDFNode.h \
|
||||
nsIRDFObserver.h \
|
||||
|
@ -25,7 +25,6 @@ EXPORTS=\
|
||||
rdf.h \
|
||||
nsIRDFCompositeDataSource.h \
|
||||
nsIRDFContentSink.h \
|
||||
nsIRDFCursor.h \
|
||||
nsIRDFDataSource.h \
|
||||
nsIRDFNode.h \
|
||||
nsIRDFObserver.h \
|
||||
|
@ -1,32 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
Interfaces for RDF cursors, including nsIRDFCursor,
|
||||
nsIRDFAssertionCursor, nsIRDFArcsInCursor, nsIRDFArcsOutCursor,
|
||||
nad nsIRDFResourceCursor.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef nsIRDFCursor_h__
|
||||
#define nsIRDFCursor_h__
|
||||
|
||||
#include "nsRDFInterfaces.h"
|
||||
|
||||
#endif /* nsIRDFCursor_h__ */
|
@ -9,7 +9,7 @@
|
||||
#include "nsISupportsArray.h" /* interface nsISupportsArray */
|
||||
#include "nsICollection.h" /* interface nsICollection */
|
||||
#include "nsIEnumerator.h" /* interface nsIEnumerator */
|
||||
#include "nsID.h" /* interface nsID */
|
||||
#include "nsrootidl.h" /* interface nsrootidl */
|
||||
|
||||
#ifdef XPIDL_JS_STUBS
|
||||
#include "jsapi.h"
|
||||
@ -141,132 +141,6 @@ class nsIRDFInt : public nsIRDFNode {
|
||||
};
|
||||
class nsIRDFDataSource; /* forward decl */
|
||||
|
||||
/* starting interface: nsIRDFCursor */
|
||||
|
||||
/* {1C2ABDB0-4CEF-11D2-BC16-00805F912FE7} */
|
||||
#define NS_IRDFCURSOR_IID_STR "1C2ABDB0-4CEF-11D2-BC16-00805F912FE7"
|
||||
#define NS_IRDFCURSOR_IID \
|
||||
{0x1C2ABDB0, 0x4CEF, 0x11D2, \
|
||||
{ 0xBC, 0x16, 0x00, 0x80, 0x5F, 0x91, 0x2F, 0xE7 }}
|
||||
|
||||
class nsIRDFCursor : public nsISupports {
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IRDFCURSOR_IID)
|
||||
|
||||
/* void Advance (); */
|
||||
NS_IMETHOD Advance() = 0;
|
||||
|
||||
/* readonly attribute nsIRDFDataSource DataSource; */
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource * *aDataSource) = 0;
|
||||
|
||||
/* readonly attribute nsIRDFNode Value; */
|
||||
NS_IMETHOD GetValue(nsIRDFNode * *aValue) = 0;
|
||||
|
||||
#ifdef XPIDL_JS_STUBS
|
||||
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
|
||||
static NS_EXPORT_(JSObject *) GetJSObject(JSContext *cx, nsIRDFCursor *priv);
|
||||
#endif
|
||||
};
|
||||
|
||||
/* starting interface: nsIRDFAssertionCursor */
|
||||
|
||||
/* {1ED57100-9904-11d2-8EBA-00805F29F370} */
|
||||
#define NS_IRDFASSERTIONCURSOR_IID_STR "1ED57100-9904-11d2-8EBA-00805F29F370"
|
||||
#define NS_IRDFASSERTIONCURSOR_IID \
|
||||
{0x1ED57100, 0x9904, 0x11d2, \
|
||||
{ 0x8E, 0xBA, 0x00, 0x80, 0x5F, 0x29, 0xF3, 0x70 }}
|
||||
|
||||
class nsIRDFAssertionCursor : public nsIRDFCursor {
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IRDFASSERTIONCURSOR_IID)
|
||||
|
||||
/* readonly attribute nsIRDFResource Source; */
|
||||
NS_IMETHOD GetSource(nsIRDFResource * *aSource) = 0;
|
||||
|
||||
/* readonly attribute nsIRDFResource Label; */
|
||||
NS_IMETHOD GetLabel(nsIRDFResource * *aLabel) = 0;
|
||||
|
||||
/* readonly attribute nsIRDFNode Target; */
|
||||
NS_IMETHOD GetTarget(nsIRDFNode * *aTarget) = 0;
|
||||
|
||||
/* readonly attribute boolean TruthValue; */
|
||||
NS_IMETHOD GetTruthValue(PRBool *aTruthValue) = 0;
|
||||
|
||||
#ifdef XPIDL_JS_STUBS
|
||||
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
|
||||
static NS_EXPORT_(JSObject *) GetJSObject(JSContext *cx, nsIRDFAssertionCursor *priv);
|
||||
#endif
|
||||
};
|
||||
|
||||
/* starting interface: nsIRDFArcsInCursor */
|
||||
|
||||
/* {1ED57102-9904-11d2-8EBA-00805F29F370} */
|
||||
#define NS_IRDFARCSINCURSOR_IID_STR "1ED57102-9904-11d2-8EBA-00805F29F370"
|
||||
#define NS_IRDFARCSINCURSOR_IID \
|
||||
{0x1ED57102, 0x9904, 0x11d2, \
|
||||
{ 0x8E, 0xBA, 0x00, 0x80, 0x5F, 0x29, 0xF3, 0x70 }}
|
||||
|
||||
class nsIRDFArcsInCursor : public nsIRDFCursor {
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IRDFARCSINCURSOR_IID)
|
||||
|
||||
/* readonly attribute nsIRDFResource Label; */
|
||||
NS_IMETHOD GetLabel(nsIRDFResource * *aLabel) = 0;
|
||||
|
||||
/* readonly attribute nsIRDFNode Target; */
|
||||
NS_IMETHOD GetTarget(nsIRDFNode * *aTarget) = 0;
|
||||
|
||||
#ifdef XPIDL_JS_STUBS
|
||||
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
|
||||
static NS_EXPORT_(JSObject *) GetJSObject(JSContext *cx, nsIRDFArcsInCursor *priv);
|
||||
#endif
|
||||
};
|
||||
|
||||
/* starting interface: nsIRDFArcsOutCursor */
|
||||
|
||||
/* {1ED57101-9904-11d2-8EBA-00805F29F370} */
|
||||
#define NS_IRDFARCSOUTCURSOR_IID_STR "1ED57101-9904-11d2-8EBA-00805F29F370"
|
||||
#define NS_IRDFARCSOUTCURSOR_IID \
|
||||
{0x1ED57101, 0x9904, 0x11d2, \
|
||||
{ 0x8E, 0xBA, 0x00, 0x80, 0x5F, 0x29, 0xF3, 0x70 }}
|
||||
|
||||
class nsIRDFArcsOutCursor : public nsIRDFCursor {
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IRDFARCSOUTCURSOR_IID)
|
||||
|
||||
/* readonly attribute nsIRDFResource Source; */
|
||||
NS_IMETHOD GetSource(nsIRDFResource * *aSource) = 0;
|
||||
|
||||
/* readonly attribute nsIRDFResource Label; */
|
||||
NS_IMETHOD GetLabel(nsIRDFResource * *aLabel) = 0;
|
||||
|
||||
#ifdef XPIDL_JS_STUBS
|
||||
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
|
||||
static NS_EXPORT_(JSObject *) GetJSObject(JSContext *cx, nsIRDFArcsOutCursor *priv);
|
||||
#endif
|
||||
};
|
||||
|
||||
/* starting interface: nsIRDFResourceCursor */
|
||||
|
||||
/* {C2850C10-B0CF-11d2-A684-00104BDE6048} */
|
||||
#define NS_IRDFRESOURCECURSOR_IID_STR "C2850C10-B0CF-11d2-A684-00104BDE6048"
|
||||
#define NS_IRDFRESOURCECURSOR_IID \
|
||||
{0xC2850C10, 0xB0CF, 0x11d2, \
|
||||
{ 0xA6, 0x84, 0x00, 0x10, 0x4B, 0xDE, 0x60, 0x48 }}
|
||||
|
||||
class nsIRDFResourceCursor : public nsIRDFCursor {
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IRDFRESOURCECURSOR_IID)
|
||||
|
||||
/* readonly attribute nsIRDFResource Resource; */
|
||||
NS_IMETHOD GetResource(nsIRDFResource * *aResource) = 0;
|
||||
|
||||
#ifdef XPIDL_JS_STUBS
|
||||
static NS_EXPORT_(JSObject *) InitJSClass(JSContext *cx);
|
||||
static NS_EXPORT_(JSObject *) GetJSObject(JSContext *cx, nsIRDFResourceCursor *priv);
|
||||
#endif
|
||||
};
|
||||
|
||||
/* starting interface: nsIRDFObserver */
|
||||
|
||||
/* {3CC75360-484A-11D2-BC16-00805F912FE7} */
|
||||
@ -312,14 +186,14 @@ class nsIRDFDataSource : public nsISupports {
|
||||
/* nsIRDFResource GetSource (in nsIRDFResource aProperty, in nsIRDFNode aTarget, in boolean aTruthValue); */
|
||||
NS_IMETHOD GetSource(nsIRDFResource *aProperty, nsIRDFNode *aTarget, PRBool aTruthValue, nsIRDFResource **_retval) = 0;
|
||||
|
||||
/* nsIRDFAssertionCursor GetSources (in nsIRDFResource aProperty, in nsIRDFNode aTarget, in boolean aTruthValue); */
|
||||
NS_IMETHOD GetSources(nsIRDFResource *aProperty, nsIRDFNode *aTarget, PRBool aTruthValue, nsIRDFAssertionCursor **_retval) = 0;
|
||||
/* nsISimpleEnumerator GetSources (in nsIRDFResource aProperty, in nsIRDFNode aTarget, in boolean aTruthValue); */
|
||||
NS_IMETHOD GetSources(nsIRDFResource *aProperty, nsIRDFNode *aTarget, PRBool aTruthValue, nsISimpleEnumerator **_retval) = 0;
|
||||
|
||||
/* nsIRDFNode GetTarget (in nsIRDFResource aSource, in nsIRDFResource aProperty, in boolean aTruthValue); */
|
||||
NS_IMETHOD GetTarget(nsIRDFResource *aSource, nsIRDFResource *aProperty, PRBool aTruthValue, nsIRDFNode **_retval) = 0;
|
||||
|
||||
/* nsIRDFAssertionCursor GetTargets (in nsIRDFResource aSource, in nsIRDFResource aProperty, in boolean aTruthValue); */
|
||||
NS_IMETHOD GetTargets(nsIRDFResource *aSource, nsIRDFResource *aProperty, PRBool aTruthValue, nsIRDFAssertionCursor **_retval) = 0;
|
||||
/* nsISimpleEnumerator GetTargets (in nsIRDFResource aSource, in nsIRDFResource aProperty, in boolean aTruthValue); */
|
||||
NS_IMETHOD GetTargets(nsIRDFResource *aSource, nsIRDFResource *aProperty, PRBool aTruthValue, nsISimpleEnumerator **_retval) = 0;
|
||||
|
||||
/* void Assert (in nsIRDFResource aSource, in nsIRDFResource aProperty, in nsIRDFNode aTarget, in boolean aTruthValue); */
|
||||
NS_IMETHOD Assert(nsIRDFResource *aSource, nsIRDFResource *aProperty, nsIRDFNode *aTarget, PRBool aTruthValue) = 0;
|
||||
@ -336,14 +210,14 @@ class nsIRDFDataSource : public nsISupports {
|
||||
/* void RemoveObserver (in nsIRDFObserver aObserver); */
|
||||
NS_IMETHOD RemoveObserver(nsIRDFObserver *aObserver) = 0;
|
||||
|
||||
/* nsIRDFArcsInCursor ArcLabelsIn (in nsIRDFNode aNode); */
|
||||
NS_IMETHOD ArcLabelsIn(nsIRDFNode *aNode, nsIRDFArcsInCursor **_retval) = 0;
|
||||
/* nsISimpleEnumerator ArcLabelsIn (in nsIRDFNode aNode); */
|
||||
NS_IMETHOD ArcLabelsIn(nsIRDFNode *aNode, nsISimpleEnumerator **_retval) = 0;
|
||||
|
||||
/* nsIRDFArcsOutCursor ArcLabelsOut (in nsIRDFResource aSource); */
|
||||
NS_IMETHOD ArcLabelsOut(nsIRDFResource *aSource, nsIRDFArcsOutCursor **_retval) = 0;
|
||||
/* nsISimpleEnumerator ArcLabelsOut (in nsIRDFResource aSource); */
|
||||
NS_IMETHOD ArcLabelsOut(nsIRDFResource *aSource, nsISimpleEnumerator **_retval) = 0;
|
||||
|
||||
/* nsIRDFResourceCursor GetAllResources (); */
|
||||
NS_IMETHOD GetAllResources(nsIRDFResourceCursor **_retval) = 0;
|
||||
/* nsISimpleEnumerator GetAllResources (); */
|
||||
NS_IMETHOD GetAllResources(nsISimpleEnumerator **_retval) = 0;
|
||||
|
||||
/* void Flush (); */
|
||||
NS_IMETHOD Flush() = 0;
|
||||
|
@ -28,27 +28,24 @@
|
||||
|
||||
#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.,
|
||||
/**
|
||||
* The following macros are to aid in vocabulary definition. They
|
||||
* creates const char*'s for "kURI[prefix]_[name]", 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"
|
||||
* kURIRDF_ID to be "http://www.w3.org/TR/WD-rdf-syntax#ID"
|
||||
*/
|
||||
|
||||
#define DEFINE_RDF_VOCAB(ns, prefix, name) \
|
||||
static const char* kURI##prefix##_##name = ns #name ;\
|
||||
static const char* kTag##prefix##_##name = #name
|
||||
static const char* kURI##prefix##_##name = ns #name
|
||||
|
||||
/**
|
||||
* Core RDF vocabularies that we use to infer semantic actions
|
||||
* Core RDF vocabularies that we use to define semantics
|
||||
*/
|
||||
|
||||
#define RDF_NAMESPACE_URI "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
|
@ -1,42 +0,0 @@
|
||||
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
/* We need this because Solaris' version of qsort is broken and
|
||||
* causes array bounds reads.
|
||||
*/
|
||||
|
||||
#ifndef rdf_qsort_h___
|
||||
#define rdf_qsort_h___
|
||||
|
||||
/* Had to pull the following define out of xp_core.h
|
||||
* to avoid including xp_core.h.
|
||||
* That brought in too many header file dependencies.
|
||||
*/
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void rdf_qsort(void *, size_t, size_t,
|
||||
int (*)(const void *, const void *, void *), void *);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* rdf_qsort_h___ */
|
@ -28,15 +28,13 @@ LIBRARY_NAME = rdfbase_s
|
||||
|
||||
CPPSRCS = \
|
||||
nsCompositeDataSource.cpp \
|
||||
nsContainerCursor.cpp \
|
||||
nsContainerEnumerator.cpp \
|
||||
nsDefaultResourceFactory.cpp \
|
||||
nsEmptyCursor.cpp \
|
||||
nsInMemoryDataSource.cpp \
|
||||
nsRDFContentSink.cpp \
|
||||
nsRDFParserUtils.cpp \
|
||||
nsRDFService.cpp \
|
||||
nsRDFXMLDataSource.cpp \
|
||||
nsRDFInterfaces.cpp \
|
||||
rdfutil.cpp \
|
||||
$(NULL)
|
||||
|
||||
@ -51,8 +49,6 @@ REQUIRES = netlib rdf rdfutil raptor xpcom
|
||||
|
||||
MKSHLIB :=
|
||||
|
||||
DEFINES += -DXPIDL_JS_STUBS
|
||||
|
||||
# we don't want the shared lib, but we want to force the creation of a static lib.
|
||||
override NO_SHARED_LIB=1
|
||||
override NO_STATIC_LIB=
|
||||
|
@ -17,19 +17,17 @@
|
||||
|
||||
DEPTH=..\..\..
|
||||
|
||||
LCFLAGS=-DXPIDL_JS_STUBS
|
||||
LCFLAGS=
|
||||
|
||||
MODULE=rdf
|
||||
LIBRARY_NAME=rdfbase_s
|
||||
|
||||
CPP_OBJS=\
|
||||
.\$(OBJDIR)\nsCompositeDataSource.obj \
|
||||
.\$(OBJDIR)\nsContainerCursor.obj \
|
||||
.\$(OBJDIR)\nsContainerEnumerator.obj \
|
||||
.\$(OBJDIR)\nsDefaultResourceFactory.obj \
|
||||
.\$(OBJDIR)\nsEmptyCursor.obj \
|
||||
.\$(OBJDIR)\nsInMemoryDataSource.obj \
|
||||
.\$(OBJDIR)\nsRDFContentSink.obj \
|
||||
.\$(OBJDIR)\nsRDFInterfaces.obj \
|
||||
.\$(OBJDIR)\nsRDFParserUtils.obj \
|
||||
.\$(OBJDIR)\nsRDFService.obj \
|
||||
.\$(OBJDIR)\nsRDFXMLDataSource.obj \
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,344 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
A simple cursor that enumerates the elements of an RDF container
|
||||
(RDF:Bag, RDF:Seq, or RDF:Alt).
|
||||
|
||||
Caveats
|
||||
-------
|
||||
|
||||
1. This uses an implementation-specific detail to determine the
|
||||
index of the last element in the container; specifically, the RDF
|
||||
utilities maintain a counter attribute on the container that
|
||||
holds the numeric value of the next value that is to be
|
||||
assigned. So, this cursor will bust if you use it with a bag that
|
||||
hasn't been created using the RDF utility routines.
|
||||
|
||||
2. This is sort of a continuation of (1), but -- it's not smart
|
||||
enough to notice duplicates.
|
||||
|
||||
TODO. This is way too brain dead to handle aggregated RDF
|
||||
databases. It needs to be upgraded in a big way.
|
||||
|
||||
*/
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsRDFCID.h"
|
||||
#include "nsString.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "prlog.h"
|
||||
#include "rdf.h"
|
||||
#include "rdfutil.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_IID(kIRDFAssertionCursorIID, NS_IRDFASSERTIONCURSOR_IID);
|
||||
static NS_DEFINE_IID(kIRDFCursorIID, NS_IRDFCURSOR_IID);
|
||||
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
|
||||
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static const char kRDFNameSpaceURI[] = RDF_NAMESPACE_URI;
|
||||
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, nextVal); // ad hoc way to make containers fast
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ContainerCursorImpl : public nsIRDFAssertionCursor {
|
||||
private:
|
||||
// pseudo-constants
|
||||
static nsrefcnt gRefCnt;
|
||||
static nsIRDFResource* kRDF_nextVal;
|
||||
|
||||
nsIRDFDataSource* mDataSource;
|
||||
nsIRDFResource* mContainer;
|
||||
nsIRDFNode* mCurrent;
|
||||
nsIRDFResource* mOrdinalProperty;
|
||||
PRInt32 mNextIndex;
|
||||
|
||||
public:
|
||||
ContainerCursorImpl(nsIRDFDataSource* ds, nsIRDFResource* container);
|
||||
virtual ~ContainerCursorImpl(void);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD Advance(void);
|
||||
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource);
|
||||
NS_IMETHOD GetSource(nsIRDFResource** aResource);
|
||||
NS_IMETHOD GetLabel(nsIRDFResource** aPredicate);
|
||||
NS_IMETHOD GetTarget(nsIRDFNode** aObject);
|
||||
NS_IMETHOD GetTruthValue(PRBool* aTruthValue);
|
||||
NS_IMETHOD GetValue(nsIRDFNode** aValue);
|
||||
};
|
||||
|
||||
nsrefcnt ContainerCursorImpl::gRefCnt;
|
||||
nsIRDFResource* ContainerCursorImpl::kRDF_nextVal;
|
||||
|
||||
ContainerCursorImpl::ContainerCursorImpl(nsIRDFDataSource* ds,
|
||||
nsIRDFResource* container)
|
||||
: mDataSource(ds),
|
||||
mContainer(container),
|
||||
mCurrent(nsnull),
|
||||
mOrdinalProperty(nsnull),
|
||||
mNextIndex(1)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_IF_ADDREF(mDataSource);
|
||||
NS_IF_ADDREF(mContainer);
|
||||
|
||||
if (gRefCnt++ == 0) {
|
||||
nsresult rv;
|
||||
nsIRDFService* service;
|
||||
rv = nsServiceManager::GetService(kRDFServiceCID,
|
||||
kIRDFServiceIID,
|
||||
(nsISupports**) &service);
|
||||
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to acquire resource manager");
|
||||
if (! service)
|
||||
return;
|
||||
|
||||
NS_VERIFY(NS_SUCCEEDED(rv = service->GetResource(kURIRDF_nextVal, &kRDF_nextVal)),
|
||||
"unable to get resource");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ContainerCursorImpl::~ContainerCursorImpl(void)
|
||||
{
|
||||
NS_IF_RELEASE(mCurrent);
|
||||
NS_IF_RELEASE(mOrdinalProperty);
|
||||
|
||||
NS_IF_RELEASE(mContainer);
|
||||
NS_IF_RELEASE(mDataSource);
|
||||
|
||||
if (--gRefCnt == 0) {
|
||||
NS_IF_RELEASE(kRDF_nextVal);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(ContainerCursorImpl);
|
||||
NS_IMPL_RELEASE(ContainerCursorImpl);
|
||||
|
||||
NS_IMETHODIMP_(nsresult)
|
||||
ContainerCursorImpl::QueryInterface(REFNSIID iid, void** result) {
|
||||
if (! result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (iid.Equals(kIRDFAssertionCursorIID) ||
|
||||
iid.Equals(kIRDFCursorIID) ||
|
||||
iid.Equals(kISupportsIID)) {
|
||||
*result = NS_STATIC_CAST(nsIRDFAssertionCursor*, this);
|
||||
/* AddRef(); // not necessary */
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
ContainerCursorImpl::Advance(void)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// release the last value that we were holding
|
||||
NS_IF_RELEASE(mCurrent);
|
||||
|
||||
nsIRDFNode* nextNode = nsnull;
|
||||
nsIRDFLiteral* nextVal = nsnull;
|
||||
nsXPIDLString p;
|
||||
nsAutoString s;
|
||||
PRInt32 last;
|
||||
PRInt32 err;
|
||||
|
||||
// Figure out the upper bound so we'll know when we're done.
|
||||
|
||||
// XXX we could cache all this crap when the cursor gets created.
|
||||
if (NS_FAILED(rv = mDataSource->GetTarget(mContainer, kRDF_nextVal, PR_TRUE, &nextNode)))
|
||||
goto done;
|
||||
|
||||
if (rv == NS_RDF_NO_VALUE)
|
||||
goto done;
|
||||
|
||||
if (NS_FAILED(rv = nextNode->QueryInterface(kIRDFLiteralIID, (void**) &nextVal)))
|
||||
goto done;
|
||||
|
||||
if (NS_FAILED(rv = nextVal->GetValue(getter_Copies(p))))
|
||||
goto done;
|
||||
|
||||
s = p;
|
||||
last = s.ToInteger(&err);
|
||||
if (NS_FAILED(err))
|
||||
goto done;
|
||||
|
||||
// initialize rv to the case where mNextIndex has advanced past the
|
||||
// last element
|
||||
rv = NS_RDF_CURSOR_EMPTY;
|
||||
|
||||
while (mNextIndex < last) {
|
||||
NS_IF_RELEASE(mOrdinalProperty);
|
||||
if (NS_FAILED(rv = rdf_IndexToOrdinalResource(mNextIndex, &mOrdinalProperty)))
|
||||
break;
|
||||
|
||||
rv = mDataSource->GetTarget(mContainer, mOrdinalProperty, PR_TRUE, &mCurrent);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
++mNextIndex;
|
||||
|
||||
if (rv == NS_OK) {
|
||||
// Don't bother releasing mCurrent; we'll let the AddRef
|
||||
// serve as the implicit addref that GetNext() should
|
||||
// perform.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
NS_IF_RELEASE(nextNode);
|
||||
NS_IF_RELEASE(nextVal);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
ContainerCursorImpl::GetDataSource(nsIRDFDataSource** aDataSource)
|
||||
{
|
||||
NS_PRECONDITION(aDataSource != nsnull, "null ptr");
|
||||
if (! aDataSource)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_ADDREF(mDataSource);
|
||||
*aDataSource = mDataSource;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
ContainerCursorImpl::GetSource(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::GetLabel(nsIRDFResource** aPredicate)
|
||||
{
|
||||
NS_PRECONDITION(aPredicate != nsnull, "null ptr");
|
||||
if (! aPredicate)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(mOrdinalProperty, "unexpected");
|
||||
if (! mOrdinalProperty)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
NS_ADDREF(mOrdinalProperty);
|
||||
*aPredicate = mOrdinalProperty;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
ContainerCursorImpl::GetTarget(nsIRDFNode** aObject)
|
||||
{
|
||||
NS_PRECONDITION(aObject != nsnull, "null ptr");
|
||||
if (! aObject)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(mCurrent, "unexpected");
|
||||
if (! mCurrent)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
NS_ADDREF(mCurrent);
|
||||
*aObject = mCurrent;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
ContainerCursorImpl::GetValue(nsIRDFNode** aObject)
|
||||
{
|
||||
NS_PRECONDITION(aObject != nsnull, "null ptr");
|
||||
if (! aObject)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (! mCurrent)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
NS_ADDREF(mCurrent);
|
||||
*aObject = mCurrent;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
ContainerCursorImpl::GetTruthValue(PRBool* aTruthValue)
|
||||
{
|
||||
NS_PRECONDITION(aTruthValue != nsnull, "null ptr");
|
||||
if (! aTruthValue)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aTruthValue = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult
|
||||
NS_NewContainerCursor(nsIRDFDataSource* ds,
|
||||
nsIRDFResource* container,
|
||||
nsIRDFAssertionCursor** cursor)
|
||||
{
|
||||
NS_PRECONDITION(ds != nsnull, "null ptr");
|
||||
NS_PRECONDITION(container != nsnull, "null ptr");
|
||||
NS_PRECONDITION(cursor != nsnull, "null ptr");
|
||||
|
||||
if (!ds || !container || !cursor)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_ASSERTION(rdf_IsContainer(ds, container), "not a container");
|
||||
if (! rdf_IsContainer(ds, container))
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
|
||||
ContainerCursorImpl* result = new ContainerCursorImpl(ds, container);
|
||||
if (! result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
*cursor = result;
|
||||
NS_ADDREF(result);
|
||||
return NS_OK;
|
||||
}
|
243
rdf/base/src/nsContainerEnumerator.cpp
Normal file
243
rdf/base/src/nsContainerEnumerator.cpp
Normal file
@ -0,0 +1,243 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
A simple cursor that enumerates the elements of an RDF container
|
||||
(RDF:Bag, RDF:Seq, or RDF:Alt).
|
||||
|
||||
Caveats
|
||||
-------
|
||||
|
||||
1. This uses an implementation-specific detail to determine the
|
||||
index of the last element in the container; specifically, the RDF
|
||||
utilities maintain a counter attribute on the container that
|
||||
holds the numeric value of the next value that is to be
|
||||
assigned. So, this cursor will bust if you use it with a bag that
|
||||
hasn't been created using the RDF utility routines.
|
||||
|
||||
*/
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsRDFCID.h"
|
||||
#include "nsString.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "prlog.h"
|
||||
#include "rdf.h"
|
||||
#include "rdfutil.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ContainerEnumeratorImpl : public nsISimpleEnumerator {
|
||||
private:
|
||||
// pseudo-constants
|
||||
static nsrefcnt gRefCnt;
|
||||
static nsIRDFResource* kRDF_nextVal;
|
||||
|
||||
nsCOMPtr<nsIRDFDataSource> mDataSource;
|
||||
nsCOMPtr<nsIRDFResource> mContainer;
|
||||
nsCOMPtr<nsIRDFResource> mOrdinalProperty;
|
||||
|
||||
nsISimpleEnumerator* mCurrent;
|
||||
nsIRDFNode* mResult;
|
||||
PRInt32 mNextIndex;
|
||||
|
||||
public:
|
||||
ContainerEnumeratorImpl(nsIRDFDataSource* ds, nsIRDFResource* container);
|
||||
virtual ~ContainerEnumeratorImpl(void);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD HasMoreElements(PRBool* aResult);
|
||||
NS_IMETHOD GetNext(nsISupports** aResult);
|
||||
};
|
||||
|
||||
nsrefcnt ContainerEnumeratorImpl::gRefCnt;
|
||||
nsIRDFResource* ContainerEnumeratorImpl::kRDF_nextVal;
|
||||
|
||||
ContainerEnumeratorImpl::ContainerEnumeratorImpl(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aContainer)
|
||||
: mCurrent(nsnull),
|
||||
mResult(nsnull),
|
||||
mNextIndex(1)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
mDataSource = dont_QueryInterface(aDataSource);
|
||||
mContainer = dont_QueryInterface(aContainer);
|
||||
|
||||
if (gRefCnt++ == 0) {
|
||||
nsresult rv;
|
||||
nsIRDFService* service;
|
||||
rv = nsServiceManager::GetService(kRDFServiceCID,
|
||||
nsIRDFService::GetIID(),
|
||||
(nsISupports**) &service);
|
||||
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to acquire resource manager");
|
||||
if (! service)
|
||||
return;
|
||||
|
||||
rv = service->GetResource(RDF_NAMESPACE_URI "nextVal", &kRDF_nextVal);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get resource");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ContainerEnumeratorImpl::~ContainerEnumeratorImpl(void)
|
||||
{
|
||||
NS_IF_RELEASE(mResult);
|
||||
NS_IF_RELEASE(mCurrent);
|
||||
|
||||
if (--gRefCnt == 0) {
|
||||
NS_IF_RELEASE(kRDF_nextVal);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(ContainerEnumeratorImpl, nsISimpleEnumerator::GetIID());
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
ContainerEnumeratorImpl::HasMoreElements(PRBool* aResult)
|
||||
{
|
||||
NS_PRECONDITION(aResult != nsnull, "null ptr");
|
||||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsresult rv;
|
||||
|
||||
// If we've already queued up a next value, then we know there are more elements.
|
||||
if (mResult) {
|
||||
*aResult = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// Otherwise, we need to grovel
|
||||
|
||||
// Figure out the upper bound so we'll know when we're done.
|
||||
PRInt32 count;
|
||||
rv = rdf_ContainerGetCount(mDataSource, mContainer, &count);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get upper bound on container");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
while (mNextIndex < count) {
|
||||
if (! mCurrent) {
|
||||
|
||||
rv = rdf_IndexToOrdinalResource(mNextIndex, getter_AddRefs(mOrdinalProperty));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = mDataSource->GetTargets(mContainer, mOrdinalProperty, PR_TRUE, &mCurrent);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
++mNextIndex;
|
||||
}
|
||||
|
||||
do {
|
||||
PRBool hasMore;
|
||||
rv = mCurrent->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Is the current enumerator depleted?
|
||||
if (! hasMore) {
|
||||
NS_RELEASE(mCurrent);
|
||||
break;
|
||||
}
|
||||
|
||||
// "Peek" ahead and pull out the next target.
|
||||
nsCOMPtr<nsISupports> result;
|
||||
rv = mCurrent->GetNext(getter_AddRefs(result));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = result->QueryInterface(nsIRDFNode::GetIID(), (void**) &mResult);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*aResult = PR_TRUE;
|
||||
return NS_OK;
|
||||
} while (1);
|
||||
}
|
||||
|
||||
// If we get here, we ran out of elements. The cursor is empty.
|
||||
*aResult = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
ContainerEnumeratorImpl::GetNext(nsISupports** aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
PRBool hasMore;
|
||||
rv = HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (! hasMore)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
// Don't AddRef: we "transfer" ownership to the caller
|
||||
*aResult = mResult;
|
||||
mResult = nsnull;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult
|
||||
NS_NewContainerEnumerator(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aContainer,
|
||||
nsISimpleEnumerator** aResult)
|
||||
{
|
||||
NS_PRECONDITION(aDataSource != nsnull, "null ptr");
|
||||
if (! aDataSource)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(aContainer != nsnull, "null ptr");
|
||||
if (! aContainer)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(aResult != nsnull, "null ptr");
|
||||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
PRBool isContainer = rdf_IsContainer(aDataSource, aContainer);
|
||||
|
||||
NS_ASSERTION(isContainer, "not a container");
|
||||
if (! isContainer)
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
|
||||
ContainerEnumeratorImpl* result = new ContainerEnumeratorImpl(aDataSource, aContainer);
|
||||
if (! result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(result);
|
||||
*aResult = result;
|
||||
|
||||
return NS_OK;
|
||||
}
|
@ -1,241 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
A set of "empty cursors" (nsIRDFAssertionCursor,
|
||||
nsIRDFArcsOutCursor, nsIRDFArcsInCursor) that can be used to ensure
|
||||
that the data source methods which return a cursor always return
|
||||
*something*.
|
||||
|
||||
*/
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "rdf.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_RDF_CURSOR_EMPTY;
|
||||
}
|
||||
|
||||
// nsIRDFAssertionCursor
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetSource(nsIRDFResource** aResource) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetLabel(nsIRDFResource** aPredicate) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetTarget(nsIRDFNode** aObject) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetTruthValue(PRBool* aTruthValue) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetValue(nsIRDFNode** aValue) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
nsresult
|
||||
NS_NewEmptyRDFAssertionCursor(nsIRDFAssertionCursor** result)
|
||||
{
|
||||
static EmptyAssertionCursorImpl gEmptyAssertionCursor;
|
||||
*result = &gEmptyAssertionCursor;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class EmptyArcsOutCursorImpl : public nsIRDFArcsOutCursor
|
||||
{
|
||||
public:
|
||||
EmptyArcsOutCursorImpl(void) {};
|
||||
virtual ~EmptyArcsOutCursorImpl(void) {};
|
||||
|
||||
// nsISupports
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
NS_IMETHOD_(nsrefcnt) Release(void) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
NS_IMETHOD QueryInterface(REFNSIID iid, void** result) {
|
||||
if (! result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (iid.Equals(kIRDFArcsOutCursorIID) ||
|
||||
iid.Equals(kIRDFCursorIID) ||
|
||||
iid.Equals(kISupportsIID)) {
|
||||
*result = NS_STATIC_CAST(nsIRDFArcsOutCursor*, this);
|
||||
/* AddRef(); // not necessary */
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
// nsIRDFCursor
|
||||
NS_IMETHOD Advance(void) {
|
||||
return NS_RDF_CURSOR_EMPTY;
|
||||
}
|
||||
|
||||
// nsIRDFArcsOutCursor
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetSource(nsIRDFResource** aResource) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetLabel(nsIRDFResource** aPredicate) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetTruthValue(PRBool* aTruthValue) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetValue(nsIRDFNode** aValue) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
nsresult
|
||||
NS_NewEmptyRDFArcsOutCursor(nsIRDFArcsOutCursor** result)
|
||||
{
|
||||
static EmptyArcsOutCursorImpl gEmptyArcsOutCursor;
|
||||
*result = &gEmptyArcsOutCursor;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class EmptyArcsInCursorImpl : public nsIRDFArcsInCursor
|
||||
{
|
||||
public:
|
||||
EmptyArcsInCursorImpl(void) {};
|
||||
virtual ~EmptyArcsInCursorImpl(void) {};
|
||||
|
||||
// nsISupports
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
NS_IMETHOD_(nsrefcnt) Release(void) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
NS_IMETHOD QueryInterface(REFNSIID iid, void** result) {
|
||||
if (! result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (iid.Equals(kIRDFArcsInCursorIID) ||
|
||||
iid.Equals(kIRDFCursorIID) ||
|
||||
iid.Equals(kISupportsIID)) {
|
||||
*result = NS_STATIC_CAST(nsIRDFArcsInCursor*, this);
|
||||
/* AddRef(); // not necessary */
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
// nsIRDFCursor
|
||||
NS_IMETHOD Advance(void) {
|
||||
return NS_RDF_CURSOR_EMPTY;
|
||||
}
|
||||
|
||||
// nsIRDFArcsInCursor
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetLabel(nsIRDFResource** aPredicate) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetTarget(nsIRDFNode** aNode) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetTruthValue(PRBool* aTruthValue) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
NS_IMETHOD GetValue(nsIRDFNode** aValue) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
nsresult
|
||||
NS_NewEmptyRDFArcsInCursor(nsIRDFArcsInCursor** result)
|
||||
{
|
||||
static EmptyArcsInCursorImpl gEmptyArcsInCursor;
|
||||
*result = &gEmptyArcsInCursor;
|
||||
return NS_OK;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -49,7 +49,6 @@
|
||||
#include "nsIOutputStream.h"
|
||||
#include "nsIParser.h"
|
||||
#include "nsIRDFContentSink.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFService.h"
|
||||
#include "nsIRDFXMLDataSource.h"
|
||||
@ -202,7 +201,7 @@ public:
|
||||
NS_IMETHOD GetSources(nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor** sources) {
|
||||
nsISimpleEnumerator** sources) {
|
||||
return mInner->GetSources(property, target, tv, sources);
|
||||
}
|
||||
|
||||
@ -216,7 +215,7 @@ public:
|
||||
NS_IMETHOD GetTargets(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor** targets) {
|
||||
nsISimpleEnumerator** targets) {
|
||||
return mInner->GetTargets(source, property, tv, targets);
|
||||
}
|
||||
|
||||
@ -246,17 +245,17 @@ public:
|
||||
}
|
||||
|
||||
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
|
||||
nsIRDFArcsInCursor** labels) {
|
||||
nsISimpleEnumerator** labels) {
|
||||
return mInner->ArcLabelsIn(node, labels);
|
||||
}
|
||||
|
||||
NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
|
||||
nsIRDFArcsOutCursor** labels) {
|
||||
nsISimpleEnumerator** labels) {
|
||||
return mInner->ArcLabelsOut(source, labels);
|
||||
}
|
||||
|
||||
NS_IMETHOD GetAllResources(nsIRDFResourceCursor** aCursor) {
|
||||
return mInner->GetAllResources(aCursor);
|
||||
NS_IMETHOD GetAllResources(nsISimpleEnumerator** aResult) {
|
||||
return mInner->GetAllResources(aResult);
|
||||
}
|
||||
|
||||
NS_IMETHOD Flush(void);
|
||||
@ -1125,21 +1124,21 @@ RDFXMLDataSourceImpl::SerializeProperty(nsIOutputStream* aStream,
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIRDFAssertionCursor> assertions;
|
||||
nsCOMPtr<nsISimpleEnumerator> assertions;
|
||||
if (NS_FAILED(rv = mInner->GetTargets(aResource, aProperty, PR_TRUE, getter_AddRefs(assertions))))
|
||||
return rv;
|
||||
|
||||
while (1) {
|
||||
rv = assertions->Advance();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
PRBool hasMore;
|
||||
rv = assertions->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (rv == NS_RDF_CURSOR_EMPTY)
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsIRDFNode* value;
|
||||
if (NS_FAILED(rv = assertions->GetValue(&value)))
|
||||
break;
|
||||
rv = assertions->GetNext((nsISupports**) &value);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = SerializeAssertion(aStream, aResource, aProperty, value);
|
||||
NS_RELEASE(value);
|
||||
@ -1182,21 +1181,21 @@ static const char kRDFDescription3[] = " </RDF:Description>\n";
|
||||
rdf_BlockingWrite(aStream, uri);
|
||||
rdf_BlockingWrite(aStream, kRDFDescription2, sizeof(kRDFDescription2) - 1);
|
||||
|
||||
nsCOMPtr<nsIRDFArcsOutCursor> arcs;
|
||||
if (NS_FAILED(rv = mInner->ArcLabelsOut(aResource, getter_AddRefs(arcs))))
|
||||
return rv;
|
||||
nsCOMPtr<nsISimpleEnumerator> arcs;
|
||||
rv = mInner->ArcLabelsOut(aResource, getter_AddRefs(arcs));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
while (1) {
|
||||
rv = arcs->Advance();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
PRBool hasMore;
|
||||
rv = arcs->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (rv == NS_RDF_CURSOR_EMPTY)
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsIRDFResource* property;
|
||||
if (NS_FAILED(rv = arcs->GetLabel(&property)))
|
||||
break;
|
||||
rv = arcs->GetNext((nsISupports**) &property);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = SerializeProperty(aStream, aResource, property);
|
||||
NS_RELEASE(property);
|
||||
@ -1220,29 +1219,24 @@ RDFXMLDataSourceImpl::SerializeMember(nsIOutputStream* aStream,
|
||||
// there may for some random reason be two or more elements with
|
||||
// the same ordinal value. Okay, I'm paranoid.
|
||||
|
||||
nsCOMPtr<nsIRDFAssertionCursor> cursor;
|
||||
if (NS_FAILED(rv = mInner->GetTargets(aContainer, aProperty, PR_TRUE, getter_AddRefs(cursor))))
|
||||
return rv;
|
||||
nsCOMPtr<nsISimpleEnumerator> cursor;
|
||||
rv = mInner->GetTargets(aContainer, aProperty, PR_TRUE, getter_AddRefs(cursor));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsXPIDLCString docURI;
|
||||
mInner->GetURI(getter_Copies(docURI));
|
||||
|
||||
while (1) {
|
||||
rv = cursor->Advance();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
PRBool hasMore;
|
||||
rv = cursor->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (rv == NS_RDF_CURSOR_EMPTY)
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsIRDFNode* node;
|
||||
|
||||
if (NS_FAILED(rv = cursor->GetTarget(&node)))
|
||||
break;
|
||||
|
||||
NS_ASSERTION(rv != NS_RDF_NO_VALUE, "null item in cursor");
|
||||
if (rv == NS_RDF_NO_VALUE)
|
||||
continue;
|
||||
rv = cursor->GetNext((nsISupports**) &node);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// If it's a resource, then output a "<RDF:li resource=... />"
|
||||
// tag, because we'll be dumping the resource separately. (We
|
||||
@ -1348,22 +1342,21 @@ static const char kRDFAlt[] = "RDF:Alt";
|
||||
// We iterate through all of the arcs, in case someone has applied
|
||||
// properties to the bag itself.
|
||||
|
||||
nsCOMPtr<nsIRDFArcsOutCursor> arcs;
|
||||
if (NS_FAILED(rv = mInner->ArcLabelsOut(aContainer, getter_AddRefs(arcs))))
|
||||
return rv;
|
||||
nsCOMPtr<nsISimpleEnumerator> arcs;
|
||||
rv = mInner->ArcLabelsOut(aContainer, getter_AddRefs(arcs));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
while (1) {
|
||||
rv = arcs->Advance();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
PRBool hasMore;
|
||||
rv = arcs->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (rv == NS_RDF_CURSOR_EMPTY)
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsIRDFResource* property;
|
||||
|
||||
if (NS_FAILED(rv = arcs->GetLabel(&property)))
|
||||
break;
|
||||
rv = arcs->GetNext((nsISupports**) &property);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// If it's a membership property, then output a "LI"
|
||||
// tag. Otherwise, output a property.
|
||||
@ -1461,26 +1454,26 @@ NS_IMETHODIMP
|
||||
RDFXMLDataSourceImpl::Serialize(nsIOutputStream* aStream)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIRDFResourceCursor> resources;
|
||||
nsCOMPtr<nsISimpleEnumerator> resources;
|
||||
|
||||
rv = mInner->GetAllResources(getter_AddRefs(resources));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = SerializePrologue(aStream);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
while (1) {
|
||||
rv = resources->Advance();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
PRBool hasMore;
|
||||
rv = resources->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (rv == NS_RDF_CURSOR_EMPTY)
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsIRDFResource* resource;
|
||||
if (NS_FAILED(rv = resources->GetResource(&resource)))
|
||||
rv = resources->GetNext((nsISupports**) &resource);
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
|
||||
if (rdf_IsContainer(mInner, resource)) {
|
||||
|
@ -34,7 +34,6 @@
|
||||
*/
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFService.h"
|
||||
@ -475,70 +474,111 @@ rdf_ContainerGetNextValue(nsIRDFDataSource* aDataSource,
|
||||
if (! aContainer)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(aResult != nsnull, "null ptr");
|
||||
if (! aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsresult rv;
|
||||
rv = rdf_EnsureRDFService();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsIRDFNode* nextValNode = nsnull;
|
||||
nsIRDFLiteral* nextValLiteral = nsnull;
|
||||
nsXPIDLString 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 = aDataSource->GetTarget(aContainer, kRDF_nextVal, PR_TRUE, &nextValNode)))
|
||||
goto done;
|
||||
nsCOMPtr<nsIRDFNode> nextValNode;
|
||||
rv = aDataSource->GetTarget(aContainer, kRDF_nextVal, PR_TRUE, getter_AddRefs(nextValNode));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (rv == NS_RDF_NO_VALUE) {
|
||||
rv = NS_ERROR_UNEXPECTED;
|
||||
goto done;
|
||||
}
|
||||
if (rv == NS_RDF_NO_VALUE)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
if (NS_FAILED(rv = nextValNode->QueryInterface(kIRDFLiteralIID, (void**) &nextValLiteral)))
|
||||
goto done;
|
||||
nsCOMPtr<nsIRDFLiteral> nextValLiteral;
|
||||
rv = nextValNode->QueryInterface(kIRDFLiteralIID, getter_AddRefs(nextValLiteral));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (NS_FAILED(rv = nextValLiteral->GetValue( getter_Copies(s) )))
|
||||
goto done;
|
||||
nsXPIDLString s;
|
||||
rv = nextValLiteral->GetValue( getter_Copies(s) );
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nextValStr = (const PRUnichar*) s;
|
||||
nextVal = nextValStr.ToInteger(&err);
|
||||
nsAutoString nextValStr = (const PRUnichar*) s;
|
||||
|
||||
PRInt32 err;
|
||||
PRInt32 nextVal = nextValStr.ToInteger(&err);
|
||||
if (NS_FAILED(err))
|
||||
goto done;
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
// Generate a URI that we can return.
|
||||
nextValStr = kRDFNameSpaceURI;
|
||||
nextValStr.Append("_");
|
||||
nextValStr.Append(nextVal, 10);
|
||||
|
||||
if (NS_FAILED(rv = gRDFService->GetUnicodeResource(nextValStr.GetUnicode(), aResult)))
|
||||
goto done;
|
||||
rv = gRDFService->GetUnicodeResource(nextValStr.GetUnicode(), aResult);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Now increment the RDF:nextVal property.
|
||||
if (NS_FAILED(rv = aDataSource->Unassert(aContainer, kRDF_nextVal, nextValLiteral)))
|
||||
goto done;
|
||||
|
||||
NS_RELEASE(nextValLiteral);
|
||||
rv = aDataSource->Unassert(aContainer, kRDF_nextVal, nextValLiteral);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
++nextVal;
|
||||
nextValStr.Truncate();
|
||||
nextValStr.Append(nextVal, 10);
|
||||
|
||||
if (NS_FAILED(rv = gRDFService->GetLiteral(nextValStr.GetUnicode(), &nextValLiteral)))
|
||||
goto done;
|
||||
rv = gRDFService->GetLiteral(nextValStr.GetUnicode(), getter_AddRefs(nextValLiteral));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (NS_FAILED(rv = aDataSource->Assert(aContainer, kRDF_nextVal, nextValLiteral, PR_TRUE)))
|
||||
goto done;
|
||||
rv = aDataSource->Assert(aContainer, kRDF_nextVal, nextValLiteral, PR_TRUE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
done:
|
||||
NS_IF_RELEASE(nextValLiteral);
|
||||
NS_IF_RELEASE(nextValNode);
|
||||
return rv;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
rdf_ContainerGetCount(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aContainer,
|
||||
PRInt32* aCount)
|
||||
{
|
||||
NS_PRECONDITION(aDataSource != nsnull, "null ptr");
|
||||
if (! aDataSource)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(aContainer != nsnull, "null ptr");
|
||||
if (! aContainer)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
NS_PRECONDITION(aCount != nsnull, "null ptr");
|
||||
if (! aCount)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsresult rv;
|
||||
rv = rdf_EnsureRDFService();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Get the next value, which hangs off of the bag via the
|
||||
// RDF:nextVal property.
|
||||
nsCOMPtr<nsIRDFNode> nextValNode;
|
||||
rv = aDataSource->GetTarget(aContainer, kRDF_nextVal, PR_TRUE, getter_AddRefs(nextValNode));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (rv == NS_RDF_NO_VALUE)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsCOMPtr<nsIRDFLiteral> nextValLiteral;
|
||||
rv = nextValNode->QueryInterface(kIRDFLiteralIID, getter_AddRefs(nextValLiteral));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsXPIDLString s;
|
||||
rv = nextValLiteral->GetValue( getter_Copies(s) );
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsAutoString nextValStr = (const PRUnichar*) s;
|
||||
|
||||
PRInt32 err;
|
||||
*aCount = nextValStr.ToInteger(&err);
|
||||
if (NS_FAILED(err))
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
@ -572,11 +612,74 @@ rdf_ContainerAppendElement(nsIRDFDataSource* aDataSource,
|
||||
}
|
||||
|
||||
|
||||
static nsresult
|
||||
rdf_ContainerRenumber(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aContainer,
|
||||
PRInt32 aStartIndex)
|
||||
{
|
||||
// Renumber the elements in the container
|
||||
nsresult rv;
|
||||
|
||||
PRInt32 count;
|
||||
rv = rdf_ContainerGetCount(aDataSource, aContainer, &count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRInt32 oldIndex = aStartIndex;
|
||||
PRInt32 newIndex = aStartIndex;
|
||||
while (oldIndex < count) {
|
||||
nsCOMPtr<nsIRDFResource> oldOrdinal;
|
||||
rv = rdf_IndexToOrdinalResource(oldIndex, getter_AddRefs(oldOrdinal));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Because of aggregation, we need to be paranoid about
|
||||
// the possibility that >1 element may be present per
|
||||
// ordinal.
|
||||
nsCOMPtr<nsISimpleEnumerator> targets;
|
||||
rv = aDataSource->GetTargets(aContainer, oldOrdinal, PR_TRUE, getter_AddRefs(targets));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
while (1) {
|
||||
PRBool hasMore;
|
||||
rv = targets->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsCOMPtr<nsISupports> isupports;
|
||||
rv = targets->GetNext(getter_AddRefs(isupports));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFNode> element( do_QueryInterface(isupports) );
|
||||
NS_ASSERTION(element != nsnull, "something funky in the enumerator");
|
||||
if (! element)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
rv = aDataSource->Unassert(aContainer, oldOrdinal, element);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> newOrdinal;
|
||||
rv = rdf_IndexToOrdinalResource(++newIndex, getter_AddRefs(newOrdinal));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = aDataSource->Assert(aContainer, newOrdinal, element, PR_TRUE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
}
|
||||
|
||||
// Update the container's nextVal to reflect the renumbering
|
||||
rv = rdf_ContainerSetNextValue(aDataSource, aContainer, ++newIndex);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
rdf_ContainerRemoveElement(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aContainer,
|
||||
nsIRDFNode* aElement)
|
||||
nsIRDFNode* aElement,
|
||||
PRBool aRenumber)
|
||||
{
|
||||
NS_PRECONDITION(aDataSource != nsnull, "null ptr");
|
||||
if (! aDataSource)
|
||||
@ -592,117 +695,31 @@ rdf_ContainerRemoveElement(nsIRDFDataSource* aDataSource,
|
||||
|
||||
nsresult rv;
|
||||
|
||||
// Create a cursor and grovel through the container looking for
|
||||
// the specified element.
|
||||
nsCOMPtr<nsIRDFAssertionCursor> elements;
|
||||
if (NS_FAILED(rv = NS_NewContainerCursor(aDataSource,
|
||||
aContainer,
|
||||
getter_AddRefs(elements)))) {
|
||||
NS_ERROR("unable to create container cursor");
|
||||
return rv;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
rv = elements->Advance();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (rv == NS_RDF_CURSOR_EMPTY)
|
||||
break;
|
||||
|
||||
nsCOMPtr<nsIRDFNode> element;
|
||||
if (NS_FAILED(rv = elements->GetTarget(getter_AddRefs(element)))) {
|
||||
NS_ERROR("unable to read cursor");
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_ASSERTION(rv != NS_RDF_NO_VALUE, "null item in cursor");
|
||||
if (rv == NS_RDF_NO_VALUE)
|
||||
continue;
|
||||
|
||||
PRBool eq;
|
||||
if (NS_FAILED(rv = element->EqualsNode(aElement, &eq))) {
|
||||
NS_ERROR("severe error on equality check");
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (! eq)
|
||||
continue;
|
||||
|
||||
// Okay, we've found it.
|
||||
|
||||
// What was it's index?
|
||||
nsCOMPtr<nsIRDFResource> ordinal;
|
||||
if (NS_FAILED(rv = elements->GetLabel(getter_AddRefs(ordinal)))) {
|
||||
NS_ERROR("unable to get element's ordinal index");
|
||||
return rv;
|
||||
}
|
||||
|
||||
// First, remove the element.
|
||||
if (NS_FAILED(rv = aDataSource->Unassert(aContainer, ordinal, element))) {
|
||||
NS_ERROR("unable to remove element from the container");
|
||||
return rv;
|
||||
}
|
||||
|
||||
PRInt32 index;
|
||||
if (NS_FAILED(rv = rdf_OrdinalResourceToIndex(ordinal, &index))) {
|
||||
NS_ERROR("unable to convert ordinal URI to index");
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Now slide the rest of the collection backwards to fill in
|
||||
// the gap.
|
||||
while (1) {
|
||||
rv = elements->Advance();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (rv == NS_RDF_CURSOR_EMPTY)
|
||||
break;
|
||||
|
||||
if (NS_FAILED(rv = elements->GetTarget(getter_AddRefs(element)))) {
|
||||
NS_ERROR("unable to get element from cursor");
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_ASSERTION(rv != NS_RDF_NO_VALUE, "null value in cursor");
|
||||
if (rv == NS_RDF_NO_VALUE)
|
||||
continue;
|
||||
|
||||
if (NS_FAILED(rv = elements->GetLabel(getter_AddRefs(ordinal)))) {
|
||||
NS_ERROR("unable to get element's ordinal index");
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv = aDataSource->Unassert(aContainer, ordinal, element))) {
|
||||
NS_ERROR("unable to remove element from the container");
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv = rdf_IndexToOrdinalResource(index, getter_AddRefs(ordinal)))) {
|
||||
NS_ERROR("unable to construct ordinal resource");
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = aDataSource->Assert(aContainer, ordinal, element, PR_TRUE);
|
||||
if (rv != NS_RDF_ASSERTION_ACCEPTED) {
|
||||
NS_ERROR("unable to add element to the container");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
++index;
|
||||
}
|
||||
|
||||
// Update the container's nextVal to reflect this mumbo jumbo
|
||||
if (NS_FAILED(rv = rdf_ContainerSetNextValue(aDataSource, aContainer, index))) {
|
||||
NS_ERROR("unable to update container's nextVal");
|
||||
return rv;
|
||||
}
|
||||
PRInt32 index;
|
||||
rv = rdf_ContainerIndexOf(aDataSource, aContainer, aElement, &index);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (index < 0) {
|
||||
NS_WARNING("attempt to remove non-existant element");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_WARNING("attempt to remove non-existant element from container");
|
||||
// Remove the element.
|
||||
nsCOMPtr<nsIRDFResource> ordinal;
|
||||
rv = rdf_IndexToOrdinalResource(index, getter_AddRefs(ordinal));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = aDataSource->Unassert(aContainer, ordinal, aElement);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (aRenumber) {
|
||||
// Now slide the rest of the collection backwards to fill in
|
||||
// the gap. This will have the side effect of completely
|
||||
// renumber the container from index to the end.
|
||||
rv = rdf_ContainerRenumber(aDataSource, aContainer, index);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@ -712,7 +729,8 @@ nsresult
|
||||
rdf_ContainerInsertElementAt(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aContainer,
|
||||
nsIRDFNode* aElement,
|
||||
PRInt32 aIndex)
|
||||
PRInt32 aIndex,
|
||||
PRBool aRenumber)
|
||||
{
|
||||
NS_PRECONDITION(aDataSource != nsnull, "null ptr");
|
||||
if (! aDataSource)
|
||||
@ -732,125 +750,28 @@ rdf_ContainerInsertElementAt(nsIRDFDataSource* aDataSource,
|
||||
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIRDFAssertionCursor> elements;
|
||||
PRInt32 count;
|
||||
rv = rdf_ContainerGetCount(aDataSource, aContainer, &count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (NS_FAILED(rv = NS_NewContainerCursor(aDataSource,
|
||||
aContainer,
|
||||
getter_AddRefs(elements)))) {
|
||||
NS_ERROR("unable to create container cursor");
|
||||
return rv;
|
||||
NS_ASSERTION(aIndex <= count, "illegal value");
|
||||
if (aIndex > count)
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
|
||||
if (aRenumber) {
|
||||
// Make a hole for the element. This will have the side effect of
|
||||
// completely renumbering the container from 'aIndex' to 'count',
|
||||
// and will spew assertions.
|
||||
rv = rdf_ContainerRenumber(aDataSource, aContainer, aIndex);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIRDFResource> ordinal;
|
||||
PRInt32 index = 1;
|
||||
rv = rdf_IndexToOrdinalResource(aIndex, getter_AddRefs(ordinal));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Advance the cursor to the aIndex'th element.
|
||||
while (1) {
|
||||
rv = elements->Advance();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (rv == NS_RDF_CURSOR_EMPTY)
|
||||
break;
|
||||
|
||||
if (NS_FAILED(rv = elements->GetLabel(getter_AddRefs(ordinal)))) {
|
||||
NS_ERROR("unable to get element's ordinal index");
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv = rdf_OrdinalResourceToIndex(ordinal, &index))) {
|
||||
NS_ERROR("unable to convert ordinal resource to index");
|
||||
return rv;
|
||||
}
|
||||
|
||||
// XXX Use >= in case any "holes" exist...
|
||||
if (index >= aIndex)
|
||||
break;
|
||||
}
|
||||
|
||||
// Remember if we've exhausted the cursor: if so, this degenerates
|
||||
// into a simple "append" operation.
|
||||
PRBool cursorExhausted = (rv == NS_RDF_CURSOR_EMPTY);
|
||||
|
||||
// XXX Be paranoid: there may have been a "hole"
|
||||
if (index > aIndex)
|
||||
index = aIndex;
|
||||
|
||||
// If we ran all the way to the end of the cursor, then "index"
|
||||
// will contain the ordinal value of the last element in the
|
||||
// container. Increment it by one to get the position at which
|
||||
// we'll want to insert it into the container.
|
||||
if (cursorExhausted && aIndex > index) {
|
||||
if (index != aIndex) {
|
||||
// Sanity check only: aIndex was _way_ too large...
|
||||
NS_WARNING("out of bounds");
|
||||
}
|
||||
|
||||
++index;
|
||||
}
|
||||
|
||||
// At this point "index" contains the index at which we want to
|
||||
// insert the new element.
|
||||
if (NS_FAILED(rv = rdf_IndexToOrdinalResource(index, getter_AddRefs(ordinal)))) {
|
||||
NS_ERROR("unable to convert index to ordinal resource");
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Insert it!
|
||||
if (NS_FAILED(rv = aDataSource->Assert(aContainer, ordinal, aElement, PR_TRUE))) {
|
||||
NS_ERROR("unable to add element to container");
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Now slide the rest of the container "up" by one...
|
||||
if (! cursorExhausted) {
|
||||
do {
|
||||
if (NS_FAILED(rv = elements->GetLabel(getter_AddRefs(ordinal)))) {
|
||||
NS_ERROR("unable to get element's ordinal index");
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIRDFNode> element;
|
||||
if (NS_FAILED(rv = elements->GetTarget(getter_AddRefs(element)))) {
|
||||
NS_ERROR("unable to get element from cursor");
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_ASSERTION(rv != NS_RDF_NO_VALUE, "null value in cursor");
|
||||
if (rv == NS_RDF_NO_VALUE)
|
||||
continue;
|
||||
|
||||
if (NS_FAILED(rv = aDataSource->Unassert(aContainer, ordinal, element))) {
|
||||
NS_ERROR("unable to remove element from container");
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv = rdf_IndexToOrdinalResource(++index, getter_AddRefs(ordinal)))) {
|
||||
NS_ERROR("unable to convert index to ordinal resource");
|
||||
return rv;
|
||||
}
|
||||
|
||||
rv = aDataSource->Assert(aContainer, ordinal, element, PR_TRUE);
|
||||
if (rv != NS_RDF_ASSERTION_ACCEPTED) {
|
||||
NS_ERROR("unable to add element to container");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
rv = elements->Advance();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (rv == NS_RDF_CURSOR_EMPTY)
|
||||
break;
|
||||
}
|
||||
while (1);
|
||||
}
|
||||
|
||||
// Now update the container's nextVal
|
||||
if (NS_FAILED(rv = rdf_ContainerSetNextValue(aDataSource, aContainer, ++index))) {
|
||||
NS_ERROR("unable to update container's nextVal");
|
||||
return rv;
|
||||
}
|
||||
rv = aDataSource->Assert(aContainer, ordinal, aElement, PR_TRUE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@ -880,52 +801,45 @@ rdf_ContainerIndexOf(nsIRDFDataSource* aDataSource,
|
||||
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIRDFAssertionCursor> elements;
|
||||
if (NS_FAILED(rv = NS_NewContainerCursor(aDataSource,
|
||||
aContainer,
|
||||
getter_AddRefs(elements)))) {
|
||||
NS_ERROR("unable to create container cursor");
|
||||
return rv;
|
||||
}
|
||||
PRInt32 count;
|
||||
rv = rdf_ContainerGetCount(aDataSource, aContainer, &count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
// Advance the cursor until we find the element we want
|
||||
while (1) {
|
||||
rv = elements->Advance();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (rv == NS_RDF_CURSOR_EMPTY)
|
||||
break;
|
||||
|
||||
nsCOMPtr<nsIRDFNode> element;
|
||||
if (NS_FAILED(rv = elements->GetTarget(getter_AddRefs(element)))) {
|
||||
NS_ERROR("unable to get element from cursor");
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_ASSERTION(rv != NS_RDF_NO_VALUE, "null value in cursor");
|
||||
if (rv == NS_RDF_NO_VALUE)
|
||||
continue;
|
||||
|
||||
// Okay, we've found it.
|
||||
for (PRInt32 index = 0; index < count; ++index) {
|
||||
nsCOMPtr<nsIRDFResource> ordinal;
|
||||
if (NS_FAILED(rv = elements->GetLabel(getter_AddRefs(ordinal)))) {
|
||||
NS_ERROR("unable to get element's ordinal index");
|
||||
return rv;
|
||||
rv = rdf_IndexToOrdinalResource(index, getter_AddRefs(ordinal));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Get all of the elements in the container with the specified
|
||||
// ordinal. This is an ultra-paranoid way to do it, but -- due
|
||||
// to aggregation, we may end up with a container that has >1
|
||||
// element for the same ordinal.
|
||||
nsCOMPtr<nsISimpleEnumerator> targets;
|
||||
rv = aDataSource->GetTargets(aContainer, ordinal, PR_TRUE, getter_AddRefs(targets));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
while (1) {
|
||||
PRBool hasMore;
|
||||
rv = targets->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsCOMPtr<nsISupports> isupports;
|
||||
rv = targets->GetNext(getter_AddRefs(isupports));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to read cursor");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFNode> element = do_QueryInterface(isupports);
|
||||
|
||||
if (element.get() != aElement)
|
||||
continue;
|
||||
|
||||
// Okay, we've found it!
|
||||
*aIndex = index;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRInt32 index;
|
||||
if (NS_FAILED(rv = rdf_OrdinalResourceToIndex(ordinal, &index))) {
|
||||
NS_ERROR("unable to convert ordinal resource to index");
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (element != nsCOMPtr<nsIRDFNode>( do_QueryInterface(aElement)) )
|
||||
continue;
|
||||
|
||||
*aIndex = index;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_WARNING("element not found");
|
||||
|
@ -41,11 +41,8 @@
|
||||
|
||||
#include "prtypes.h"
|
||||
|
||||
class nsIRDFArcsInCursor;
|
||||
class nsIRDFArcsOutCursor;
|
||||
class nsIRDFAssertionCursor;
|
||||
class nsIRDFCursor;
|
||||
class nsIRDFDataSource;
|
||||
class nsISimpleEnumerator;
|
||||
class nsIRDFResource;
|
||||
class nsIRDFNode;
|
||||
class nsIRDFResource;
|
||||
@ -139,6 +136,13 @@ PR_EXTERN(nsresult)
|
||||
rdf_MakeAlt(nsIRDFDataSource* ds,
|
||||
nsIRDFResource* resource);
|
||||
|
||||
/**
|
||||
* Get the current upper bound of the container
|
||||
*/
|
||||
PR_EXTERN(nsresult)
|
||||
rdf_ContainerGetCount(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aContainer,
|
||||
PRInt32* aCount);
|
||||
|
||||
/**
|
||||
* Add an element to the end of container.
|
||||
@ -155,7 +159,8 @@ rdf_ContainerAppendElement(nsIRDFDataSource* ds,
|
||||
PR_EXTERN(nsresult)
|
||||
rdf_ContainerRemoveElement(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aContainer,
|
||||
nsIRDFNode* aElement);
|
||||
nsIRDFNode* aElement,
|
||||
PRBool aRenumber);
|
||||
|
||||
|
||||
/**
|
||||
@ -165,7 +170,8 @@ PR_EXTERN(nsresult)
|
||||
rdf_ContainerInsertElementAt(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aContainer,
|
||||
nsIRDFNode* aElement,
|
||||
PRInt32 aIndex);
|
||||
PRInt32 aIndex,
|
||||
PRBool aRenumber);
|
||||
|
||||
/**
|
||||
* Determine the index of an element in a container.
|
||||
@ -182,26 +188,12 @@ rdf_ContainerIndexOf(nsIRDFDataSource* aDataSource,
|
||||
* order
|
||||
*/
|
||||
PR_EXTERN(nsresult)
|
||||
NS_NewContainerCursor(nsIRDFDataSource* ds,
|
||||
nsIRDFResource* container,
|
||||
nsIRDFAssertionCursor** cursor);
|
||||
NS_NewContainerEnumerator(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* aContainer,
|
||||
nsISimpleEnumerator** aResult);
|
||||
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
PR_EXTERN(void) SHTtest ();
|
||||
// XXX need to move nsEmptyCursor stuff here.
|
||||
|
||||
#endif // rdfutil_h__
|
||||
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include "nsRDFCID.h"
|
||||
#include "nsIRDFResource.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsHashtable.h"
|
||||
#include "nsString.h"
|
||||
#include "nsXPIDLString.h"
|
||||
@ -401,37 +400,41 @@ nsBrowsingProfile::CountPageVisit(const char* initialURL)
|
||||
nsIRDFResource* urlRes;
|
||||
rv = gRDFService->GetResource(url, &urlRes);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsIRDFAssertionCursor* cursor;
|
||||
rv = gCategoryDB->GetSources(kOPENDIR_narrow, urlRes, PR_TRUE, &cursor);
|
||||
nsISimpleEnumerator* sources;
|
||||
rv = gCategoryDB->GetSources(kOPENDIR_narrow, urlRes, PR_TRUE, &sources);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
while (1) {
|
||||
rv = cursor->Advance();
|
||||
PRBool hasMore;
|
||||
rv = sources->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv)) {
|
||||
done = PR_TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
if (rv == NS_RDF_CURSOR_EMPTY)
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsIRDFResource* category;
|
||||
rv = cursor->GetSource(&category);
|
||||
nsISupports* isupports;
|
||||
rv = sources->GetNext(&isupports);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// found this page in a category -- count it
|
||||
PRUint16 id;
|
||||
rv = GetCategoryID(category, &id);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsXPIDLCString catURI;
|
||||
rv = category->GetValue( getter_Copies(catURI) );
|
||||
nsCOMPtr<nsIRDFResource> category = do_QueryInterface(isupports);
|
||||
if (category) {
|
||||
// found this page in a category -- count it
|
||||
PRUint16 id;
|
||||
rv = GetCategoryID(category, &id);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = RecordHit(catURI, id);
|
||||
nsXPIDLCString catURI;
|
||||
rv = category->GetValue( getter_Copies(catURI) );
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = RecordHit(catURI, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
NS_RELEASE(category);
|
||||
NS_RELEASE(isupports);
|
||||
done = PR_TRUE;
|
||||
}
|
||||
}
|
||||
NS_RELEASE(cursor);
|
||||
NS_RELEASE(sources);
|
||||
}
|
||||
NS_RELEASE(urlRes);
|
||||
}
|
||||
|
@ -46,13 +46,11 @@ void XXXNeverCalled()
|
||||
rdf_MakeSeq(nsnull, nsnull);
|
||||
rdf_MakeAlt(nsnull, nsnull);
|
||||
rdf_ContainerAppendElement(nsnull, nsnull, nsnull);
|
||||
rdf_ContainerRemoveElement(nsnull, nsnull, nsnull);
|
||||
rdf_ContainerInsertElementAt(nsnull, nsnull, nsnull, 0);
|
||||
rdf_ContainerRemoveElement(nsnull, nsnull, nsnull, PR_FALSE);
|
||||
rdf_ContainerInsertElementAt(nsnull, nsnull, nsnull, 0, PR_FALSE);
|
||||
rdf_ContainerIndexOf(nsnull, nsnull, nsnull, nsnull);
|
||||
NS_NewContainerCursor(nsnull, nsnull, nsnull);
|
||||
NS_NewEmptyRDFAssertionCursor(nsnull);
|
||||
NS_NewEmptyRDFArcsInCursor(nsnull);
|
||||
NS_NewEmptyRDFArcsOutCursor(nsnull);
|
||||
NS_NewContainerEnumerator(nsnull, nsnull, nsnull);
|
||||
NS_NewEmptyEnumerator(nsnull);
|
||||
|
||||
// nsRDFResource
|
||||
nsRDFResource r();
|
||||
|
@ -69,6 +69,7 @@ include <$(DEPTH)\config\rules.mak>
|
||||
install:: $(DLL)
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib
|
||||
$(MAKE_INSTALL) nsRDFInterfaces.xpt $(DIST)\bin\components
|
||||
$(MAKE_INSTALL) ..\resources\sidebar.xul $(DIST)\bin\res\rdf
|
||||
$(MAKE_INSTALL) ..\resources\sidebar.css $(DIST)\bin\res\rdf
|
||||
$(MAKE_INSTALL) ..\resources\bm-props.xul $(DIST)\bin\res\rdf
|
||||
|
BIN
rdf/build/nsRDFInterfaces.xpt
Normal file
BIN
rdf/build/nsRDFInterfaces.xpt
Normal file
Binary file not shown.
@ -28,7 +28,6 @@
|
||||
#include "nsRDFCID.h"
|
||||
#include "nsIRDFResource.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsHashtable.h"
|
||||
#include "nsString.h"
|
||||
#include "nsXPIDLString.h"
|
||||
@ -75,7 +74,7 @@ public:
|
||||
NS_IMETHOD GetSources(nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor** sources /* out */) ;
|
||||
nsISimpleEnumerator** sources /* out */) ;
|
||||
NS_IMETHOD GetTarget(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
PRBool tv,
|
||||
@ -83,7 +82,7 @@ public:
|
||||
NS_IMETHOD GetTargets(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor** targets /* out */) ;
|
||||
nsISimpleEnumerator** targets /* out */) ;
|
||||
NS_IMETHOD Assert(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
@ -99,10 +98,10 @@ public:
|
||||
NS_IMETHOD AddObserver(nsIRDFObserver* n) ;
|
||||
NS_IMETHOD RemoveObserver(nsIRDFObserver* n) ;
|
||||
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
|
||||
nsIRDFArcsInCursor** labels /* out */) ;
|
||||
nsISimpleEnumerator** labels /* out */) ;
|
||||
NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
|
||||
nsIRDFArcsOutCursor** labels /* out */) ;
|
||||
NS_IMETHOD GetAllResources(nsIRDFResourceCursor** aCursor) ;
|
||||
nsISimpleEnumerator** labels /* out */) ;
|
||||
NS_IMETHOD GetAllResources(nsISimpleEnumerator** aResult) ;
|
||||
NS_IMETHOD Flush(void) ;
|
||||
NS_IMETHOD GetAllCommands(nsIRDFResource* source,
|
||||
nsIEnumerator/*<nsIRDFResource>*/** commands) ;
|
||||
@ -493,7 +492,7 @@ NS_IMETHODIMP
|
||||
nsChromeRegistry::GetSources(nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor** sources /* out */)
|
||||
nsISimpleEnumerator** sources /* out */)
|
||||
{
|
||||
return mInner->GetSources(property, target, tv, sources);
|
||||
}
|
||||
@ -512,7 +511,7 @@ NS_IMETHODIMP
|
||||
nsChromeRegistry::GetTargets(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor** targets /* out */)
|
||||
nsISimpleEnumerator** targets /* out */)
|
||||
{
|
||||
return mInner->GetTargets(source, property, tv, targets);
|
||||
}
|
||||
@ -555,18 +554,18 @@ NS_IMETHODIMP nsChromeRegistry::RemoveObserver(nsIRDFObserver* n)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsChromeRegistry::ArcLabelsIn(nsIRDFNode* node,
|
||||
nsIRDFArcsInCursor** labels /* out */)
|
||||
nsISimpleEnumerator** labels /* out */)
|
||||
{
|
||||
return mInner->ArcLabelsIn(node, labels);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsChromeRegistry::ArcLabelsOut(nsIRDFResource* source,
|
||||
nsIRDFArcsOutCursor** labels /* out */)
|
||||
nsISimpleEnumerator** labels /* out */)
|
||||
{
|
||||
return mInner->ArcLabelsOut(source, labels);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsChromeRegistry::GetAllResources(nsIRDFResourceCursor** aCursor)
|
||||
NS_IMETHODIMP nsChromeRegistry::GetAllResources(nsISimpleEnumerator** aCursor)
|
||||
{
|
||||
return mInner->GetAllResources(aCursor);
|
||||
}
|
||||
|
@ -3,8 +3,6 @@ interface XULDocument : Document {
|
||||
/* IID: { 0x17ddd8c0, 0xc5f8, 0x11d2, \
|
||||
{ 0xa6, 0xae, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } } */
|
||||
|
||||
readonly attribute xpidl nsIRDFService rdf;
|
||||
|
||||
Element getElementById(in DOMString id);
|
||||
|
||||
NodeList getElementsByAttribute(in DOMString name, in DOMString value);
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include "nsIScriptContext.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
|
||||
class nsIRDFService;
|
||||
class nsIDOMElement;
|
||||
class nsIDOMNodeList;
|
||||
|
||||
@ -37,8 +36,6 @@ class nsIDOMXULDocument : public nsIDOMDocument {
|
||||
public:
|
||||
static const nsIID& GetIID() { static nsIID iid = NS_IDOMXULDOCUMENT_IID; return iid; }
|
||||
|
||||
NS_IMETHOD GetRdf(nsIRDFService** aRdf)=0;
|
||||
|
||||
NS_IMETHOD GetElementById(const nsString& aId, nsIDOMElement** aReturn)=0;
|
||||
|
||||
NS_IMETHOD GetElementsByAttribute(const nsString& aName, const nsString& aValue, nsIDOMNodeList** aReturn)=0;
|
||||
@ -46,14 +43,12 @@ public:
|
||||
|
||||
|
||||
#define NS_DECL_IDOMXULDOCUMENT \
|
||||
NS_IMETHOD GetRdf(nsIRDFService** aRdf); \
|
||||
NS_IMETHOD GetElementById(const nsString& aId, nsIDOMElement** aReturn); \
|
||||
NS_IMETHOD GetElementsByAttribute(const nsString& aName, const nsString& aValue, nsIDOMNodeList** aReturn); \
|
||||
|
||||
|
||||
|
||||
#define NS_FORWARD_IDOMXULDOCUMENT(_to) \
|
||||
NS_IMETHOD GetRdf(nsIRDFService** aRdf) { return _to GetRdf(aRdf); } \
|
||||
NS_IMETHOD GetElementById(const nsString& aId, nsIDOMElement** aReturn) { return _to GetElementById(aId, aReturn); } \
|
||||
NS_IMETHOD GetElementsByAttribute(const nsString& aName, const nsString& aValue, nsIDOMNodeList** aReturn) { return _to GetElementsByAttribute(aName, aValue, aReturn); } \
|
||||
|
||||
|
@ -68,8 +68,6 @@ INCLUDES += -I$(srcdir)/../../../layout/html/base/src
|
||||
|
||||
MKSHLIB :=
|
||||
|
||||
DEFINES += -DXPIDL_JS_STUBS
|
||||
|
||||
# we don't want the shared lib, but we want to force the creation of a static lib.
|
||||
override NO_SHARED_LIB=1
|
||||
override NO_STATIC_LIB=
|
||||
|
@ -19,7 +19,7 @@ DEPTH=..\..\..
|
||||
MODULE=rdf
|
||||
LIBRARY_NAME=rdfcontent_s
|
||||
|
||||
DEFINES=-D_IMPL_NS_DOM -DXPIDL_JS_STUBS
|
||||
DEFINES=-D_IMPL_NS_DOM
|
||||
|
||||
LCFLAGS = \
|
||||
$(LCFLAGS) \
|
||||
@ -56,7 +56,7 @@ LINCS= -I$(PUBLIC)\rdf \
|
||||
-I$(PUBLIC)\xpcom \
|
||||
-I$(PUBLIC)\netlib \
|
||||
-I$(PUBLIC)\raptor \
|
||||
-I$(PUBLIC)\lwbrk \
|
||||
-I$(PUBLIC)\lwbrk \
|
||||
-I$(PUBLIC)\js \
|
||||
-I$(PUBLIC)\dom \
|
||||
-I$(DEPTH)\rdf\base\src \
|
||||
|
@ -26,7 +26,6 @@
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIRDFService.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMXULDocument.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
@ -35,22 +34,14 @@
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
|
||||
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
|
||||
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
|
||||
static NS_DEFINE_IID(kIElementIID, NS_IDOMELEMENT_IID);
|
||||
static NS_DEFINE_IID(kIXULDocumentIID, NS_IDOMXULDOCUMENT_IID);
|
||||
static NS_DEFINE_IID(kINodeListIID, NS_IDOMNODELIST_IID);
|
||||
|
||||
NS_DEF_PTR(nsIRDFService);
|
||||
NS_DEF_PTR(nsIDOMElement);
|
||||
NS_DEF_PTR(nsIDOMXULDocument);
|
||||
NS_DEF_PTR(nsIDOMNodeList);
|
||||
|
||||
//
|
||||
// XULDocument property ids
|
||||
//
|
||||
enum XULDocument_slots {
|
||||
XULDOCUMENT_RDF = -1
|
||||
};
|
||||
|
||||
/***********************************************************************/
|
||||
//
|
||||
@ -68,18 +59,7 @@ GetXULDocumentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
|
||||
if (JSVAL_IS_INT(id)) {
|
||||
switch(JSVAL_TO_INT(id)) {
|
||||
case XULDOCUMENT_RDF:
|
||||
{
|
||||
nsIRDFService* prop;
|
||||
if (NS_OK == a->GetRdf(&prop)) {
|
||||
// get the js object
|
||||
*vp = OBJECT_TO_JSVAL(nsIRDFService::GetJSObject(cx, prop));
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 0:
|
||||
default:
|
||||
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
|
||||
}
|
||||
@ -250,7 +230,6 @@ JSClass XULDocumentClass = {
|
||||
//
|
||||
static JSPropertySpec XULDocumentProperties[] =
|
||||
{
|
||||
{"rdf", XULDOCUMENT_RDF, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{0}
|
||||
};
|
||||
|
||||
|
@ -73,7 +73,11 @@ GetXULElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
nsIRDFResource* prop;
|
||||
if (NS_OK == a->GetResource(&prop)) {
|
||||
// get the js object
|
||||
#ifdef XPIDL_JS_STUBS
|
||||
*vp = OBJECT_TO_JSVAL(nsIRDFResource::GetJSObject(cx, prop));
|
||||
#else
|
||||
nsJSUtils::nsConvertXPCObjectToJSVal(prop, nsIRDFResource::GetIID(), cx, vp);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
|
@ -67,7 +67,11 @@ GetXULTreeElementProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
nsIRDFCompositeDataSource* prop;
|
||||
if (NS_OK == a->GetDatabase(&prop)) {
|
||||
// get the js object
|
||||
#ifdef XPIDL_JS_STUBS
|
||||
*vp = OBJECT_TO_JSVAL(nsIRDFCompositeDataSource::GetJSObject(cx, prop));
|
||||
#else
|
||||
nsJSUtils::nsConvertXPCObjectToJSVal(prop, nsIRDFCompositeDataSource::GetIID(), cx, vp);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
|
@ -60,7 +60,6 @@
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIRDFCompositeDataSource.h"
|
||||
#include "nsIRDFContentModelBuilder.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIRDFDocument.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFService.h"
|
||||
|
@ -45,7 +45,6 @@
|
||||
#include "nsIDocument.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIRDFContentModelBuilder.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIRDFCompositeDataSource.h"
|
||||
#include "nsIRDFDocument.h"
|
||||
#include "nsIRDFNode.h"
|
||||
@ -479,9 +478,9 @@ RDFGenericBuilderImpl::CreateContents(nsIContent* aElement)
|
||||
// handles multi-attributes. For performance...
|
||||
|
||||
// Create a cursor that'll enumerate all of the outbound arcs
|
||||
nsCOMPtr<nsIRDFArcsOutCursor> properties;
|
||||
if (NS_FAILED(rv = mDB->ArcLabelsOut(resource, getter_AddRefs(properties))))
|
||||
return rv;
|
||||
nsCOMPtr<nsISimpleEnumerator> properties;
|
||||
rv = mDB->ArcLabelsOut(resource, getter_AddRefs(properties));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// rjc - sort
|
||||
nsISupportsArray *tempArray;
|
||||
@ -489,17 +488,18 @@ RDFGenericBuilderImpl::CreateContents(nsIContent* aElement)
|
||||
return(rv);
|
||||
|
||||
while (1) {
|
||||
rv = properties->Advance();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
PRBool hasMore;
|
||||
rv = properties->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (rv == NS_RDF_CURSOR_EMPTY)
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> property;
|
||||
nsCOMPtr<nsISupports> isupports;
|
||||
rv = properties->GetNext(getter_AddRefs(isupports));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (NS_FAILED(rv = properties->GetLabel(getter_AddRefs(property))))
|
||||
break;
|
||||
nsCOMPtr<nsIRDFResource> property = do_QueryInterface(isupports);
|
||||
|
||||
// If it's not a widget item property, then it doesn't specify an
|
||||
// object that is member of the current container element;
|
||||
@ -510,42 +510,33 @@ RDFGenericBuilderImpl::CreateContents(nsIContent* aElement)
|
||||
|
||||
// Create a second cursor that'll enumerate all of the values
|
||||
// for all of the arcs.
|
||||
nsCOMPtr<nsIRDFAssertionCursor> assertions;
|
||||
if (NS_FAILED(rv = mDB->GetTargets(resource, property, PR_TRUE, getter_AddRefs(assertions)))) {
|
||||
NS_ERROR("unable to get targets for property");
|
||||
return rv;
|
||||
}
|
||||
nsCOMPtr<nsISimpleEnumerator> targets;
|
||||
rv = mDB->GetTargets(resource, property, PR_TRUE, getter_AddRefs(targets));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
while (1) {
|
||||
rv = assertions->Advance();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
PRBool hasMore;
|
||||
rv = targets->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (rv == NS_RDF_CURSOR_EMPTY)
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsCOMPtr<nsIRDFNode> value;
|
||||
if (NS_FAILED(rv = assertions->GetValue(getter_AddRefs(value)))) {
|
||||
NS_ERROR("unable to get cursor value");
|
||||
// return rv;
|
||||
break;
|
||||
}
|
||||
nsCOMPtr<nsISupports> isupports;
|
||||
rv = targets->GetNext(getter_AddRefs(isupports));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> valueResource;
|
||||
if (NS_SUCCEEDED(value->QueryInterface(kIRDFResourceIID, (void**) getter_AddRefs(valueResource)))
|
||||
&& IsContainmentProperty(aElement, property)) {
|
||||
nsCOMPtr<nsIRDFResource> valueResource = do_QueryInterface(isupports);
|
||||
if (valueResource && IsContainmentProperty(aElement, property)) {
|
||||
/* XXX hack: always append value resource 1st!
|
||||
due to sort callback implementation */
|
||||
tempArray->AppendElement(valueResource);
|
||||
tempArray->AppendElement(property);
|
||||
}
|
||||
else {
|
||||
/* if (NS_FAILED(rv = SetCellValue(aElement, property, value))) {
|
||||
NS_ERROR("unable to set cell value");
|
||||
// return rv;
|
||||
break;
|
||||
XXX Dave - WHY IS THIS HERE?
|
||||
}*/
|
||||
nsCOMPtr<nsIRDFNode> value = do_QueryInterface(isupports);
|
||||
rv = SetWidgetAttribute(aElement, property, value);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1316,33 +1307,42 @@ RDFGenericBuilderImpl::IsContainmentProperty(nsIContent* aElement, nsIRDFResourc
|
||||
PRBool
|
||||
RDFGenericBuilderImpl::IsContainer(nsIContent* aElement, nsIRDFResource* aResource)
|
||||
{
|
||||
PRBool result = PR_FALSE;
|
||||
nsCOMPtr<nsIRDFArcsOutCursor> arcs;
|
||||
if (NS_FAILED(mDB->ArcLabelsOut(aResource, getter_AddRefs(arcs)))) {
|
||||
NS_ERROR("unable to get arcs out");
|
||||
return result;
|
||||
}
|
||||
// Look at all of the arcs extending _out_ of the resource: if any
|
||||
// of them are that "containment" property, then we know we'll
|
||||
// have children.
|
||||
|
||||
// XXX Per Bug 3367, this'll have to be fixed.
|
||||
nsCOMPtr<nsISimpleEnumerator> arcs;
|
||||
nsresult rv;
|
||||
|
||||
rv = mDB->ArcLabelsOut(aResource, getter_AddRefs(arcs));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get arcs out");
|
||||
if (NS_FAILED(rv))
|
||||
return PR_FALSE;
|
||||
|
||||
while (1) {
|
||||
nsresult rv = arcs->Advance();
|
||||
PRBool hasMore;
|
||||
nsresult rv = arcs->HasMoreElements(&hasMore);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "severe error advancing cursor");
|
||||
if (NS_FAILED(rv))
|
||||
return PR_FALSE;
|
||||
|
||||
if (rv == NS_RDF_CURSOR_EMPTY)
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> property;
|
||||
if (NS_FAILED(arcs->GetLabel(getter_AddRefs(property)))) {
|
||||
NS_ERROR("unable to get cursor value");
|
||||
return result;
|
||||
}
|
||||
nsCOMPtr<nsISupports> isupports;
|
||||
rv = arcs->GetNext(getter_AddRefs(isupports));
|
||||
if (NS_FAILED(rv))
|
||||
return PR_FALSE;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> property = do_QueryInterface(isupports);
|
||||
|
||||
// Ignore properties that are used to indicate "tree-ness"
|
||||
if (IsContainmentProperty(aElement, property))
|
||||
return PR_TRUE;
|
||||
}
|
||||
return result;
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
|
@ -30,7 +30,6 @@
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIRDFCompositeDataSource.h"
|
||||
#include "nsIRDFContentModelBuilder.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIRDFDocument.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFService.h"
|
||||
|
@ -29,7 +29,6 @@
|
||||
#include "nsIDocument.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIRDFContentModelBuilder.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIRDFCompositeDataSource.h"
|
||||
#include "nsIRDFDocument.h"
|
||||
#include "nsIRDFNode.h"
|
||||
@ -260,25 +259,27 @@ RDFMenuBuilderImpl::AddWidgetItem(nsIContent* aElement,
|
||||
|
||||
// Add miscellaneous attributes by iterating _all_ of the
|
||||
// properties out of the resource.
|
||||
nsCOMPtr<nsIRDFArcsOutCursor> arcs;
|
||||
if (NS_FAILED(rv = mDB->ArcLabelsOut(aValue, getter_AddRefs(arcs)))) {
|
||||
NS_ERROR("unable to get arcs out");
|
||||
return rv;
|
||||
}
|
||||
|
||||
// XXX Per Bug 3367, this'll have to be fixed.
|
||||
nsCOMPtr<nsISimpleEnumerator> arcs;
|
||||
rv = mDB->ArcLabelsOut(aValue, getter_AddRefs(arcs));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get arcs out");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
while (1) {
|
||||
rv = arcs->Advance();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
PRBool hasMore;
|
||||
rv = arcs->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (rv == NS_RDF_CURSOR_EMPTY)
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> property;
|
||||
if (NS_FAILED(rv = arcs->GetLabel(getter_AddRefs(property)))) {
|
||||
NS_ERROR("unable to get cursor value");
|
||||
return rv;
|
||||
}
|
||||
nsCOMPtr<nsISupports> isupports;
|
||||
rv = arcs->GetNext(getter_AddRefs(isupports));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get cursor value");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> property = do_QueryInterface(isupports);
|
||||
|
||||
// Ignore properties that are used to indicate containment
|
||||
if (IsContainmentProperty(aElement, property))
|
||||
|
@ -30,7 +30,6 @@
|
||||
#include "nsIDocument.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIRDFContentModelBuilder.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIRDFCompositeDataSource.h"
|
||||
#include "nsIRDFDocument.h"
|
||||
#include "nsIRDFNode.h"
|
||||
@ -251,25 +250,27 @@ RDFToolbarBuilderImpl::AddWidgetItem(nsIContent* aElement,
|
||||
|
||||
// Add miscellaneous attributes by iterating _all_ of the
|
||||
// properties out of the resource.
|
||||
nsCOMPtr<nsIRDFArcsOutCursor> arcs;
|
||||
if (NS_FAILED(rv = mDB->ArcLabelsOut(aValue, getter_AddRefs(arcs)))) {
|
||||
NS_ERROR("unable to get arcs out");
|
||||
return rv;
|
||||
}
|
||||
|
||||
// XXX Per Bug 3367, this'll have to be fixed.
|
||||
nsCOMPtr<nsISimpleEnumerator> arcs;
|
||||
rv = mDB->ArcLabelsOut(aValue, getter_AddRefs(arcs));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get arcs out");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
while (1) {
|
||||
rv = arcs->Advance();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
PRBool hasMore;
|
||||
rv = arcs->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (rv == NS_RDF_CURSOR_EMPTY)
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> property;
|
||||
if (NS_FAILED(rv = arcs->GetLabel(getter_AddRefs(property)))) {
|
||||
NS_ERROR("unable to get cursor value");
|
||||
return rv;
|
||||
}
|
||||
nsCOMPtr<nsISupports> isupports;
|
||||
rv = arcs->GetNext(getter_AddRefs(isupports));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get cursor value");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> property = do_QueryInterface(isupports);
|
||||
|
||||
// Ignore properties that are used to indicate containment
|
||||
if (IsContainmentProperty(aElement, property))
|
||||
|
@ -44,7 +44,6 @@
|
||||
#include "nsIDocument.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIRDFContentModelBuilder.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIRDFCompositeDataSource.h"
|
||||
#include "nsIRDFDocument.h"
|
||||
#include "nsIRDFNode.h"
|
||||
@ -463,28 +462,31 @@ RDFTreeBuilderImpl::CheckRDFGraphForUpdates(nsIContent *container)
|
||||
nsCOMPtr<nsIRDFResource> res;
|
||||
if (NS_SUCCEEDED(rv = domElement->GetResource(getter_AddRefs(res))))
|
||||
{
|
||||
nsCOMPtr<nsIRDFArcsOutCursor> arcs;
|
||||
if (NS_FAILED(rv = mDB->ArcLabelsOut(res, getter_AddRefs(arcs))))
|
||||
{
|
||||
NS_ERROR("unable to get arcs out");
|
||||
return (rv);
|
||||
}
|
||||
// XXX Per Bug 3367, this'll have to be fixed.
|
||||
nsCOMPtr<nsISimpleEnumerator> arcs;
|
||||
rv = mDB->ArcLabelsOut(res, getter_AddRefs(arcs));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get arcs out");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
while (PR_TRUE)
|
||||
{
|
||||
rv = arcs->Advance();
|
||||
if (NS_FAILED(rv)) return(rv);
|
||||
if (rv == NS_RDF_CURSOR_EMPTY) break;
|
||||
while (1) {
|
||||
PRBool hasMore;
|
||||
rv = arcs->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> property;
|
||||
if (NS_FAILED(rv = arcs->GetLabel(getter_AddRefs(property))))
|
||||
{
|
||||
NS_ERROR("unable to get cursor value");
|
||||
return(rv);
|
||||
}
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsCOMPtr<nsISupports> isupports;
|
||||
rv = arcs->GetNext(getter_AddRefs(isupports));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get cursor value");
|
||||
if(NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> property = do_QueryInterface(isupports);
|
||||
|
||||
if (!IsContainmentProperty(container, property)) continue;
|
||||
|
||||
// XXX this seems gratuitous? why is it here?
|
||||
PRInt32 nameSpaceID;
|
||||
nsCOMPtr<nsIAtom> tag;
|
||||
if (NS_FAILED(rv = mDocument->SplitProperty(property, &nameSpaceID, getter_AddRefs(tag))))
|
||||
@ -493,28 +495,26 @@ RDFTreeBuilderImpl::CheckRDFGraphForUpdates(nsIContent *container)
|
||||
return(rv);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIRDFAssertionCursor> assertions;
|
||||
if (NS_FAILED(rv = db->GetTargets(res, property, PR_TRUE, getter_AddRefs(assertions))))
|
||||
{
|
||||
NS_ERROR("unable to get targets for property");
|
||||
return rv;
|
||||
}
|
||||
while (PR_TRUE)
|
||||
{
|
||||
rv = assertions->Advance();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (rv == NS_RDF_CURSOR_EMPTY) break;
|
||||
nsCOMPtr<nsISimpleEnumerator> targets;
|
||||
rv = db->GetTargets(res, property, PR_TRUE, getter_AddRefs(targets));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get targets for property");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFNode> value;
|
||||
if (NS_FAILED(rv = assertions->GetValue(getter_AddRefs(value))))
|
||||
{
|
||||
NS_ERROR("unable to get cursor value");
|
||||
break;
|
||||
}
|
||||
nsCOMPtr<nsIRDFResource> valueResource;
|
||||
if (NS_SUCCEEDED(rv = value->QueryInterface(kIRDFResourceIID, (void**) getter_AddRefs(valueResource)) &&
|
||||
(rv != NS_RDF_NO_VALUE)))
|
||||
{
|
||||
while (1) {
|
||||
PRBool hasMore;
|
||||
rv = targets->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsCOMPtr<nsISupports> isupports;
|
||||
rv = targets->GetNext(getter_AddRefs(isupports));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get cursor value");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> valueResource = do_QueryInterface(isupports);
|
||||
if (valueResource) {
|
||||
// Note: hack, storing value then property in array
|
||||
childArray.AppendElement(valueResource.get());
|
||||
childArray.AppendElement(property.get());
|
||||
@ -944,7 +944,7 @@ RDFTreeBuilderImpl::OnRemoveChild(nsIDOMNode* aParent, nsIDOMNode* aOldChild)
|
||||
// tinkering with an RDF container...
|
||||
if (rdf_IsContainer(mDB, resource) &&
|
||||
rdf_IsOrdinalProperty(property)) {
|
||||
rv = rdf_ContainerRemoveElement(mDB, resource, target);
|
||||
rv = rdf_ContainerRemoveElement(mDB, resource, target, PR_TRUE);
|
||||
}
|
||||
else {
|
||||
rv = mDB->Unassert(resource, property, target);
|
||||
@ -1106,25 +1106,25 @@ RDFTreeBuilderImpl::AddWidgetItem(nsIContent* aElement,
|
||||
|
||||
// Add miscellaneous attributes by iterating _all_ of the
|
||||
// properties out of the resource.
|
||||
nsCOMPtr<nsIRDFArcsOutCursor> arcs;
|
||||
if (NS_FAILED(rv = mDB->ArcLabelsOut(aValue, getter_AddRefs(arcs)))) {
|
||||
NS_ERROR("unable to get arcs out");
|
||||
return rv;
|
||||
}
|
||||
nsCOMPtr<nsISimpleEnumerator> arcs;
|
||||
rv = mDB->ArcLabelsOut(aValue, getter_AddRefs(arcs));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get arcs out");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
while (1) {
|
||||
rv = arcs->Advance();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
PRBool hasMore;
|
||||
rv = arcs->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (rv == NS_RDF_CURSOR_EMPTY)
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> property;
|
||||
if (NS_FAILED(rv = arcs->GetLabel(getter_AddRefs(property)))) {
|
||||
NS_ERROR("unable to get cursor value");
|
||||
return rv;
|
||||
}
|
||||
nsCOMPtr<nsISupports> isupports;
|
||||
rv = arcs->GetNext(getter_AddRefs(isupports));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get cursor value");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> property = do_QueryInterface(isupports);
|
||||
|
||||
// Ignore properties that are used to indicate "tree-ness"
|
||||
if (IsContainmentProperty(aElement, property))
|
||||
|
@ -48,7 +48,6 @@
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIRDFCompositeDataSource.h"
|
||||
#include "nsIRDFContentModelBuilder.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIRDFDocument.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFObserver.h"
|
||||
@ -582,34 +581,29 @@ RDFXULBuilderImpl::CreateContents(nsIContent* aElement)
|
||||
|
||||
// Iterate through all of the element's children, and construct
|
||||
// appropriate children for each arc.
|
||||
nsCOMPtr<nsIRDFAssertionCursor> children;
|
||||
if (NS_FAILED(rv = NS_NewContainerCursor(mDB, resource, getter_AddRefs(children)))) {
|
||||
NS_ERROR("unable to create cursor for children");
|
||||
return rv;
|
||||
}
|
||||
nsCOMPtr<nsISimpleEnumerator> children;
|
||||
rv = NS_NewContainerEnumerator(mDB, resource, getter_AddRefs(children));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create cursor for children");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
while (1) {
|
||||
rv = children->Advance();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
PRBool hasMore;
|
||||
rv = children->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (rv == NS_RDF_CURSOR_EMPTY)
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsCOMPtr<nsIRDFNode> child;
|
||||
if (NS_FAILED(rv = children->GetTarget(getter_AddRefs(child)))) {
|
||||
NS_ERROR("error reading cursor");
|
||||
return rv;
|
||||
}
|
||||
nsCOMPtr<nsISupports> isupports;
|
||||
rv = children->GetNext(getter_AddRefs(isupports));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "error reading cursor");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_ASSERTION(rv != NS_RDF_NO_VALUE, "null value in cursor");
|
||||
if (rv == NS_RDF_NO_VALUE)
|
||||
continue;
|
||||
nsCOMPtr<nsIRDFNode> child = do_QueryInterface(isupports);
|
||||
|
||||
if (NS_FAILED(AppendChild(containingNameSpace, aElement, child))) {
|
||||
NS_ERROR("problem appending child to content model");
|
||||
return rv;
|
||||
}
|
||||
rv = AppendChild(containingNameSpace, aElement, child);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "problem appending child to content model");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
// Now that we've built the children, check to see if the includesrc attribute
|
||||
@ -981,7 +975,7 @@ RDFXULBuilderImpl::OnInsertBefore(nsIDOMNode* aParent, nsIDOMNode* aNewChild, ns
|
||||
|
||||
if (isXULElement) {
|
||||
// remove the child from the old collection
|
||||
rv = rdf_ContainerRemoveElement(mDB, oldParent, newChild);
|
||||
rv = rdf_ContainerRemoveElement(mDB, oldParent, newChild, PR_TRUE);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to remove newChild from oldParent");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
@ -1011,7 +1005,7 @@ RDFXULBuilderImpl::OnInsertBefore(nsIDOMNode* aParent, nsIDOMNode* aNewChild, ns
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// ...and insert the newChild before it.
|
||||
rv = rdf_ContainerInsertElementAt(mDB, parent, newChild, index);
|
||||
rv = rdf_ContainerInsertElementAt(mDB, parent, newChild, index, PR_TRUE);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to insert new element into container");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
@ -1076,12 +1070,12 @@ RDFXULBuilderImpl::OnReplaceChild(nsIDOMNode* aParent, nsIDOMNode* aNewChild, ns
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// ...then remove the old child from the old collection...
|
||||
rv = rdf_ContainerRemoveElement(mDB, parent, oldChild);
|
||||
rv = rdf_ContainerRemoveElement(mDB, parent, oldChild, PR_TRUE);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to remove old child from container");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// ...and add the new child to the collection at the old child's index
|
||||
rv = rdf_ContainerInsertElementAt(mDB, parent, newChild, index);
|
||||
rv = rdf_ContainerInsertElementAt(mDB, parent, newChild, index, PR_TRUE);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to add new child to container");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
@ -1129,7 +1123,7 @@ RDFXULBuilderImpl::OnRemoveChild(nsIDOMNode* aParent, nsIDOMNode* aOldChild)
|
||||
|
||||
if (isXULElement) {
|
||||
// ...then remove it from the container
|
||||
rv = rdf_ContainerRemoveElement(mDB, parent, oldChild);
|
||||
rv = rdf_ContainerRemoveElement(mDB, parent, oldChild, PR_TRUE);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to insert new element into container");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
@ -1181,7 +1175,7 @@ RDFXULBuilderImpl::OnAppendChild(nsIDOMNode* aParent, nsIDOMNode* aNewChild)
|
||||
|
||||
if (isXULElement) {
|
||||
// remove the child from the old collection
|
||||
rv = rdf_ContainerRemoveElement(mDB, oldParent, newChild);
|
||||
rv = rdf_ContainerRemoveElement(mDB, oldParent, newChild, PR_TRUE);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to remove newChild from oldParent");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
@ -1665,27 +1659,26 @@ RDFXULBuilderImpl::CreateHTMLElement(nsINameSpace* aContainingNameSpace,
|
||||
// attributes on the element. First, create a cursor that'll
|
||||
// iterate through all the properties that lead out of this
|
||||
// resource.
|
||||
nsCOMPtr<nsIRDFArcsOutCursor> properties;
|
||||
if (NS_FAILED(rv = mDB->ArcLabelsOut(aResource, getter_AddRefs(properties)))) {
|
||||
NS_ERROR("unable to create arcs-out cursor");
|
||||
return rv;
|
||||
}
|
||||
nsCOMPtr<nsISimpleEnumerator> properties;
|
||||
rv = mDB->ArcLabelsOut(aResource, getter_AddRefs(properties));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create arcs-out cursor");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Advance that cursor 'til it runs outta steam
|
||||
while (1) {
|
||||
rv = properties->Advance();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
PRBool hasMore;
|
||||
rv = properties->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (rv == NS_RDF_CURSOR_EMPTY)
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> property;
|
||||
nsCOMPtr<nsISupports> isupports;
|
||||
rv = properties->GetNext(getter_AddRefs(isupports));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get property from cursor");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (NS_FAILED(rv = properties->GetLabel(getter_AddRefs(property)))) {
|
||||
NS_ERROR("unable to get property from cursor");
|
||||
return rv;
|
||||
}
|
||||
nsCOMPtr<nsIRDFResource> property = do_QueryInterface(isupports);
|
||||
|
||||
// These are special beacuse they're used to specify the tree
|
||||
// structure of the XUL: ignore them b/c they're not attributes
|
||||
@ -1805,25 +1798,25 @@ RDFXULBuilderImpl::CreateHTMLContents(nsINameSpace* aContainingNameSpace,
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIRDFAssertionCursor> children;
|
||||
if (NS_FAILED(rv = NS_NewContainerCursor(mDB, aResource, getter_AddRefs(children)))) {
|
||||
NS_ERROR("unable to create cursor for children");
|
||||
return rv;
|
||||
}
|
||||
nsCOMPtr<nsISimpleEnumerator> children;
|
||||
rv = NS_NewContainerEnumerator(mDB, aResource, getter_AddRefs(children));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create cursor for children");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
while (1) {
|
||||
rv = children->Advance();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
PRBool hasMore;
|
||||
rv = children->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (rv == NS_RDF_CURSOR_EMPTY)
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsCOMPtr<nsIRDFNode> child;
|
||||
if (NS_FAILED(rv = children->GetTarget(getter_AddRefs(child)))) {
|
||||
NS_ERROR("error reading cursor");
|
||||
return rv;
|
||||
}
|
||||
nsCOMPtr<nsISupports> isupports;
|
||||
rv = children->GetNext(getter_AddRefs(isupports));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "error reading cursor");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFNode> child = do_QueryInterface(isupports);
|
||||
|
||||
rv = AppendChild(aContainingNameSpace, aElement, child);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "problem appending child to content model");
|
||||
@ -1867,27 +1860,26 @@ RDFXULBuilderImpl::CreateXULElement(nsINameSpace* aContainingNameSpace,
|
||||
// attributes on the element. First, create a cursor that'll
|
||||
// iterate through all the properties that lead out of this
|
||||
// resource.
|
||||
nsCOMPtr<nsIRDFArcsOutCursor> properties;
|
||||
if (NS_FAILED(rv = mDB->ArcLabelsOut(aResource, getter_AddRefs(properties)))) {
|
||||
NS_ERROR("unable to create arcs-out cursor");
|
||||
return rv;
|
||||
}
|
||||
nsCOMPtr<nsISimpleEnumerator> properties;
|
||||
rv = mDB->ArcLabelsOut(aResource, getter_AddRefs(properties));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create arcs-out cursor");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Advance that cursor 'til it runs outta steam
|
||||
while (1) {
|
||||
rv = properties->Advance();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
PRBool hasMore;
|
||||
rv = properties->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (rv == NS_RDF_CURSOR_EMPTY)
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> property;
|
||||
nsCOMPtr<nsISupports> isupports;
|
||||
rv = properties->GetNext(getter_AddRefs(isupports));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get property from cursor");
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (NS_FAILED(rv = properties->GetLabel(getter_AddRefs(property)))) {
|
||||
NS_ERROR("unable to get property from cursor");
|
||||
return rv;
|
||||
}
|
||||
nsCOMPtr<nsIRDFResource> property = do_QueryInterface(isupports);
|
||||
|
||||
// These are special beacuse they're used to specify the tree
|
||||
// structure of the XUL: ignore them b/c they're not attributes
|
||||
|
@ -75,7 +75,7 @@ private:
|
||||
nsIAtom* aName,
|
||||
const nsString& aValue);
|
||||
|
||||
~nsXULAttribute();
|
||||
virtual ~nsXULAttribute();
|
||||
|
||||
friend nsresult
|
||||
NS_NewXULAttribute(nsXULAttribute** aResult,
|
||||
|
@ -58,7 +58,6 @@
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIRDFCompositeDataSource.h"
|
||||
#include "nsIRDFContentModelBuilder.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
#include "nsIRDFDocument.h"
|
||||
#include "nsIRDFNode.h"
|
||||
@ -2590,16 +2589,6 @@ XULDocumentImpl::GetStyleSheets(nsIDOMStyleSheetCollection** aStyleSheets)
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsIDOMXULDocument interface
|
||||
|
||||
NS_IMETHODIMP
|
||||
XULDocumentImpl::GetRdf(nsIRDFService** aRDFService)
|
||||
{
|
||||
// XXX this is a temporary hack until the component manager starts
|
||||
// to work.
|
||||
return nsServiceManager::GetService(kRDFServiceCID,
|
||||
nsIRDFService::GetIID(),
|
||||
(nsISupports**) aRDFService);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
XULDocumentImpl::GetElementById(const nsString& aId, nsIDOMElement** aReturn)
|
||||
{
|
||||
@ -3058,25 +3047,6 @@ XULDocumentImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObjec
|
||||
|
||||
if (nsnull == mScriptObject) {
|
||||
res = NS_NewScriptXULDocument(aContext, (nsISupports *)(nsIDOMXULDocument *)this, global, (void**)&mScriptObject);
|
||||
|
||||
#if defined(XPIDL_JS_STUBS)
|
||||
JSContext* cx = (JSContext*) aContext->GetNativeContext();
|
||||
nsIRDFNode::InitJSClass(cx);
|
||||
nsIRDFResource::InitJSClass(cx);
|
||||
nsIRDFLiteral::InitJSClass(cx);
|
||||
nsIRDFDate::InitJSClass(cx);
|
||||
nsIRDFInt::InitJSClass(cx);
|
||||
nsIRDFCursor::InitJSClass(cx);
|
||||
nsIRDFAssertionCursor::InitJSClass(cx);
|
||||
nsIRDFArcsInCursor::InitJSClass(cx);
|
||||
nsIRDFArcsOutCursor::InitJSClass(cx);
|
||||
nsIRDFResourceCursor::InitJSClass(cx);
|
||||
nsIRDFObserver::InitJSClass(cx);
|
||||
nsIRDFDataSource::InitJSClass(cx);
|
||||
nsIRDFCompositeDataSource::InitJSClass(cx);
|
||||
nsIRDFService::InitJSClass(cx);
|
||||
#endif
|
||||
|
||||
}
|
||||
*aScriptObject = mScriptObject;
|
||||
|
||||
|
@ -60,7 +60,6 @@
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIRDFCompositeDataSource.h"
|
||||
#include "nsIRDFContentModelBuilder.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIRDFDocument.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFService.h"
|
||||
|
@ -31,7 +31,6 @@
|
||||
#include "nsIDocument.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIRDFContentModelBuilder.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIRDFCompositeDataSource.h"
|
||||
#include "nsIRDFDocument.h"
|
||||
#include "nsIRDFNode.h"
|
||||
|
@ -45,7 +45,6 @@
|
||||
#include "nsIDocument.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIRDFContentModelBuilder.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIRDFCompositeDataSource.h"
|
||||
#include "nsIRDFDocument.h"
|
||||
#include "nsIRDFNode.h"
|
||||
@ -479,9 +478,9 @@ RDFGenericBuilderImpl::CreateContents(nsIContent* aElement)
|
||||
// handles multi-attributes. For performance...
|
||||
|
||||
// Create a cursor that'll enumerate all of the outbound arcs
|
||||
nsCOMPtr<nsIRDFArcsOutCursor> properties;
|
||||
if (NS_FAILED(rv = mDB->ArcLabelsOut(resource, getter_AddRefs(properties))))
|
||||
return rv;
|
||||
nsCOMPtr<nsISimpleEnumerator> properties;
|
||||
rv = mDB->ArcLabelsOut(resource, getter_AddRefs(properties));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// rjc - sort
|
||||
nsISupportsArray *tempArray;
|
||||
@ -489,17 +488,18 @@ RDFGenericBuilderImpl::CreateContents(nsIContent* aElement)
|
||||
return(rv);
|
||||
|
||||
while (1) {
|
||||
rv = properties->Advance();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
PRBool hasMore;
|
||||
rv = properties->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (rv == NS_RDF_CURSOR_EMPTY)
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> property;
|
||||
nsCOMPtr<nsISupports> isupports;
|
||||
rv = properties->GetNext(getter_AddRefs(isupports));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (NS_FAILED(rv = properties->GetLabel(getter_AddRefs(property))))
|
||||
break;
|
||||
nsCOMPtr<nsIRDFResource> property = do_QueryInterface(isupports);
|
||||
|
||||
// If it's not a widget item property, then it doesn't specify an
|
||||
// object that is member of the current container element;
|
||||
@ -510,42 +510,33 @@ RDFGenericBuilderImpl::CreateContents(nsIContent* aElement)
|
||||
|
||||
// Create a second cursor that'll enumerate all of the values
|
||||
// for all of the arcs.
|
||||
nsCOMPtr<nsIRDFAssertionCursor> assertions;
|
||||
if (NS_FAILED(rv = mDB->GetTargets(resource, property, PR_TRUE, getter_AddRefs(assertions)))) {
|
||||
NS_ERROR("unable to get targets for property");
|
||||
return rv;
|
||||
}
|
||||
nsCOMPtr<nsISimpleEnumerator> targets;
|
||||
rv = mDB->GetTargets(resource, property, PR_TRUE, getter_AddRefs(targets));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
while (1) {
|
||||
rv = assertions->Advance();
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
PRBool hasMore;
|
||||
rv = targets->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (rv == NS_RDF_CURSOR_EMPTY)
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsCOMPtr<nsIRDFNode> value;
|
||||
if (NS_FAILED(rv = assertions->GetValue(getter_AddRefs(value)))) {
|
||||
NS_ERROR("unable to get cursor value");
|
||||
// return rv;
|
||||
break;
|
||||
}
|
||||
nsCOMPtr<nsISupports> isupports;
|
||||
rv = targets->GetNext(getter_AddRefs(isupports));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> valueResource;
|
||||
if (NS_SUCCEEDED(value->QueryInterface(kIRDFResourceIID, (void**) getter_AddRefs(valueResource)))
|
||||
&& IsContainmentProperty(aElement, property)) {
|
||||
nsCOMPtr<nsIRDFResource> valueResource = do_QueryInterface(isupports);
|
||||
if (valueResource && IsContainmentProperty(aElement, property)) {
|
||||
/* XXX hack: always append value resource 1st!
|
||||
due to sort callback implementation */
|
||||
tempArray->AppendElement(valueResource);
|
||||
tempArray->AppendElement(property);
|
||||
}
|
||||
else {
|
||||
/* if (NS_FAILED(rv = SetCellValue(aElement, property, value))) {
|
||||
NS_ERROR("unable to set cell value");
|
||||
// return rv;
|
||||
break;
|
||||
XXX Dave - WHY IS THIS HERE?
|
||||
}*/
|
||||
nsCOMPtr<nsIRDFNode> value = do_QueryInterface(isupports);
|
||||
rv = SetWidgetAttribute(aElement, property, value);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1316,33 +1307,42 @@ RDFGenericBuilderImpl::IsContainmentProperty(nsIContent* aElement, nsIRDFResourc
|
||||
PRBool
|
||||
RDFGenericBuilderImpl::IsContainer(nsIContent* aElement, nsIRDFResource* aResource)
|
||||
{
|
||||
PRBool result = PR_FALSE;
|
||||
nsCOMPtr<nsIRDFArcsOutCursor> arcs;
|
||||
if (NS_FAILED(mDB->ArcLabelsOut(aResource, getter_AddRefs(arcs)))) {
|
||||
NS_ERROR("unable to get arcs out");
|
||||
return result;
|
||||
}
|
||||
// Look at all of the arcs extending _out_ of the resource: if any
|
||||
// of them are that "containment" property, then we know we'll
|
||||
// have children.
|
||||
|
||||
// XXX Per Bug 3367, this'll have to be fixed.
|
||||
nsCOMPtr<nsISimpleEnumerator> arcs;
|
||||
nsresult rv;
|
||||
|
||||
rv = mDB->ArcLabelsOut(aResource, getter_AddRefs(arcs));
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get arcs out");
|
||||
if (NS_FAILED(rv))
|
||||
return PR_FALSE;
|
||||
|
||||
while (1) {
|
||||
nsresult rv = arcs->Advance();
|
||||
PRBool hasMore;
|
||||
nsresult rv = arcs->HasMoreElements(&hasMore);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "severe error advancing cursor");
|
||||
if (NS_FAILED(rv))
|
||||
return PR_FALSE;
|
||||
|
||||
if (rv == NS_RDF_CURSOR_EMPTY)
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> property;
|
||||
if (NS_FAILED(arcs->GetLabel(getter_AddRefs(property)))) {
|
||||
NS_ERROR("unable to get cursor value");
|
||||
return result;
|
||||
}
|
||||
nsCOMPtr<nsISupports> isupports;
|
||||
rv = arcs->GetNext(getter_AddRefs(isupports));
|
||||
if (NS_FAILED(rv))
|
||||
return PR_FALSE;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> property = do_QueryInterface(isupports);
|
||||
|
||||
// Ignore properties that are used to indicate "tree-ness"
|
||||
if (IsContainmentProperty(aElement, property))
|
||||
return PR_TRUE;
|
||||
}
|
||||
return result;
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
|
@ -19,7 +19,7 @@ DEPTH=..\..\..
|
||||
MODULE=rdf
|
||||
LIBRARY_NAME=rdfdatasource_s
|
||||
|
||||
LCFLAGS=-DXPIDL_JS_STUBS -DMOZ_BRPROF
|
||||
LCFLAGS=-DMOZ_BRPROF
|
||||
|
||||
CPP_OBJS=\
|
||||
.\$(OBJDIR)\nsBookmarkDataSource.obj \
|
||||
@ -38,6 +38,7 @@ CPP_OBJS=\
|
||||
# "real live" XPCOM interface.
|
||||
|
||||
LINCS= -I$(PUBLIC)\rdf \
|
||||
-I$(PUBLIC)\rdfutil \
|
||||
-I$(PUBLIC)\xpcom \
|
||||
-I$(PUBLIC)\netlib \
|
||||
-I$(PUBLIC)\raptor \
|
||||
|
@ -732,7 +732,7 @@ public:
|
||||
NS_IMETHOD GetSources(nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor** sources) {
|
||||
nsISimpleEnumerator** sources) {
|
||||
return mInner->GetSources(property, target, tv, sources);
|
||||
}
|
||||
|
||||
@ -744,7 +744,7 @@ public:
|
||||
NS_IMETHOD GetTargets(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor** targets) {
|
||||
nsISimpleEnumerator** targets) {
|
||||
return mInner->GetTargets(source, property, tv, targets);
|
||||
}
|
||||
|
||||
@ -774,17 +774,17 @@ public:
|
||||
}
|
||||
|
||||
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
|
||||
nsIRDFArcsInCursor** labels) {
|
||||
nsISimpleEnumerator** labels) {
|
||||
return mInner->ArcLabelsIn(node, labels);
|
||||
}
|
||||
|
||||
NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
|
||||
nsIRDFArcsOutCursor** labels) {
|
||||
nsISimpleEnumerator** labels) {
|
||||
return mInner->ArcLabelsOut(source, labels);
|
||||
}
|
||||
|
||||
NS_IMETHOD GetAllResources(nsIRDFResourceCursor** aCursor) {
|
||||
return mInner->GetAllResources(aCursor);
|
||||
NS_IMETHOD GetAllResources(nsISimpleEnumerator** aResult) {
|
||||
return mInner->GetAllResources(aResult);
|
||||
}
|
||||
|
||||
NS_IMETHOD Flush(void);
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
/* -*- 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
|
||||
@ -23,12 +23,12 @@
|
||||
#include <ctype.h> // for toupper()
|
||||
#include <stdio.h>
|
||||
#include "nscore.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFObserver.h"
|
||||
#include "nsIRDFResourceFactory.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsEnumeratorUtils.h"
|
||||
#include "nsString.h"
|
||||
#include "nsVoidArray.h" // XXX introduces dependency on raptorbase
|
||||
#include "nsXPIDLString.h"
|
||||
@ -47,32 +47,134 @@
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIRDFFTP.h"
|
||||
#include "nsFTPDataSource.h"
|
||||
|
||||
|
||||
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
|
||||
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
|
||||
static NS_DEFINE_IID(kIRDFDataSourceIID, NS_IRDFDATASOURCE_IID);
|
||||
static NS_DEFINE_IID(kIRDFFTPDataSourceIID, NS_IRDFFTPDATAOURCE_IID);
|
||||
static NS_DEFINE_IID(kIRDFAssertionCursorIID, NS_IRDFASSERTIONCURSOR_IID);
|
||||
static NS_DEFINE_IID(kIRDFCursorIID, NS_IRDFCURSOR_IID);
|
||||
static NS_DEFINE_IID(kIRDFArcsOutCursorIID, NS_IRDFARCSOUTCURSOR_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
|
||||
static NS_DEFINE_IID(kIRDFNodeIID, NS_IRDFNODE_IID);
|
||||
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
|
||||
static NS_DEFINE_IID(kIRDFFTPDataSourceCallbackIID, NS_IRDFFTPDATASOURCECALLBACK_IID);
|
||||
|
||||
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, child);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Name);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, URL);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, FTPObject);
|
||||
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, instanceOf);
|
||||
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, type);
|
||||
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, Seq);
|
||||
|
||||
|
||||
|
||||
class FTPDataSourceCallback : public nsIStreamListener
|
||||
{
|
||||
private:
|
||||
nsIRDFDataSource *mDataSource;
|
||||
nsIRDFResource *mParent;
|
||||
static PRInt32 gRefCnt;
|
||||
|
||||
// pseudo-constants
|
||||
static nsIRDFResource *kNC_Child;
|
||||
|
||||
char *mLine;
|
||||
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
FTPDataSourceCallback(nsIRDFDataSource *ds, nsIRDFResource *parent);
|
||||
virtual ~FTPDataSourceCallback(void);
|
||||
|
||||
// stream observer
|
||||
|
||||
NS_IMETHOD OnStartBinding(nsIURL *aURL, const char *aContentType);
|
||||
NS_IMETHOD OnProgress(nsIURL* aURL, PRUint32 aProgress, PRUint32 aProgressMax);
|
||||
NS_IMETHOD OnStatus(nsIURL* aURL, const PRUnichar* aMsg);
|
||||
NS_IMETHOD OnStopBinding(nsIURL* aURL, nsresult aStatus, const PRUnichar* aMsg);
|
||||
|
||||
// stream listener
|
||||
NS_IMETHOD GetBindInfo(nsIURL* aURL, nsStreamBindingInfo* aInfo);
|
||||
NS_IMETHOD OnDataAvailable(nsIURL* aURL, nsIInputStream *aIStream,
|
||||
PRUint32 aLength);
|
||||
};
|
||||
|
||||
|
||||
|
||||
class FTPDataSource : public nsIRDFFTPDataSource
|
||||
{
|
||||
private:
|
||||
char *mURI;
|
||||
|
||||
static PRInt32 gRefCnt;
|
||||
|
||||
// pseudo-constants
|
||||
static nsIRDFResource *kNC_Child;
|
||||
static nsIRDFResource *kNC_Name;
|
||||
static nsIRDFResource *kNC_URL;
|
||||
static nsIRDFResource *kNC_FTPObject;
|
||||
static nsIRDFResource *kRDF_InstanceOf;
|
||||
static nsIRDFResource *kRDF_type;
|
||||
|
||||
NS_METHOD GetFTPListing(nsIRDFResource *source, nsISimpleEnumerator** aResult);
|
||||
NS_METHOD GetURL(nsIRDFResource *source, nsIRDFLiteral** aResult);
|
||||
NS_METHOD GetName(nsIRDFResource *source, nsIRDFLiteral** aResult);
|
||||
|
||||
protected:
|
||||
nsIRDFDataSource *mInner;
|
||||
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
FTPDataSource(void);
|
||||
virtual ~FTPDataSource(void);
|
||||
|
||||
//friend class FTPDataSourceCallback;
|
||||
|
||||
// nsIRDFDataSource methods
|
||||
|
||||
NS_IMETHOD Init(const char *uri);
|
||||
NS_IMETHOD GetURI(char **uri);
|
||||
NS_IMETHOD GetSource(nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
nsIRDFResource **source /* out */);
|
||||
NS_IMETHOD GetSources(nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
nsISimpleEnumerator **sources /* out */);
|
||||
NS_IMETHOD GetTarget(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
PRBool tv,
|
||||
nsIRDFNode **target /* out */);
|
||||
NS_IMETHOD GetTargets(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
PRBool tv,
|
||||
nsISimpleEnumerator **targets /* out */);
|
||||
NS_IMETHOD Assert(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv);
|
||||
NS_IMETHOD Unassert(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
nsIRDFNode *target);
|
||||
NS_IMETHOD HasAssertion(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
PRBool *hasAssertion /* out */);
|
||||
NS_IMETHOD ArcLabelsIn(nsIRDFNode *node,
|
||||
nsISimpleEnumerator **labels /* out */);
|
||||
NS_IMETHOD ArcLabelsOut(nsIRDFResource *source,
|
||||
nsISimpleEnumerator **labels /* out */);
|
||||
NS_IMETHOD GetAllResources(nsISimpleEnumerator** aCursor);
|
||||
NS_IMETHOD AddObserver(nsIRDFObserver *n);
|
||||
NS_IMETHOD RemoveObserver(nsIRDFObserver *n);
|
||||
NS_IMETHOD Flush();
|
||||
NS_IMETHOD GetAllCommands(nsIRDFResource* source,
|
||||
nsIEnumerator/*<nsIRDFResource>*/** commands);
|
||||
NS_IMETHOD IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
|
||||
nsIRDFResource* aCommand,
|
||||
nsISupportsArray/*<nsIRDFResource>*/* aArguments,
|
||||
PRBool* aResult);
|
||||
NS_IMETHOD DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
|
||||
nsIRDFResource* aCommand,
|
||||
nsISupportsArray/*<nsIRDFResource>*/* aArguments);
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
static nsIRDFService *gRDFService = nsnull;
|
||||
@ -92,22 +194,6 @@ nsIRDFResource *FTPDataSourceCallback::kNC_Child;
|
||||
|
||||
|
||||
|
||||
static PRBool
|
||||
peq(nsIRDFResource* r1, nsIRDFResource* r2)
|
||||
{
|
||||
PRBool retVal=PR_FALSE, result;
|
||||
|
||||
if (NS_SUCCEEDED(r1->EqualsResource(r2, &result)))
|
||||
{
|
||||
if (result)
|
||||
{
|
||||
retVal = PR_TRUE;
|
||||
}
|
||||
}
|
||||
return(retVal);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static PRBool
|
||||
isFTPURI(nsIRDFResource *r)
|
||||
@ -156,17 +242,17 @@ FTPDataSource::FTPDataSource(void)
|
||||
if (gRefCnt++ == 0)
|
||||
{
|
||||
nsresult rv = nsServiceManager::GetService(kRDFServiceCID,
|
||||
kIRDFServiceIID,
|
||||
nsIRDFService::GetIID(),
|
||||
(nsISupports**) &gRDFService);
|
||||
|
||||
PR_ASSERT(NS_SUCCEEDED(rv));
|
||||
|
||||
gRDFService->GetResource(kURINC_child, &kNC_Child);
|
||||
gRDFService->GetResource(kURINC_Name, &kNC_Name);
|
||||
gRDFService->GetResource(kURINC_URL, &kNC_URL);
|
||||
gRDFService->GetResource(kURINC_FTPObject, &kNC_FTPObject);
|
||||
gRDFService->GetResource(kURIRDF_instanceOf, &kRDF_InstanceOf);
|
||||
gRDFService->GetResource(kURIRDF_type, &kRDF_type);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "child", &kNC_Child);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "Name", &kNC_Name);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "URL", &kNC_URL);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "FTPObject", &kNC_FTPObject);
|
||||
gRDFService->GetResource(RDF_NAMESPACE_URI "instanceOf", &kRDF_InstanceOf);
|
||||
gRDFService->GetResource(RDF_NAMESPACE_URI "type", &kRDF_type);
|
||||
|
||||
gFTPDataSource = this;
|
||||
}
|
||||
@ -199,7 +285,7 @@ FTPDataSource::~FTPDataSource (void)
|
||||
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(FTPDataSource, kIRDFDataSourceIID);
|
||||
NS_IMPL_ISUPPORTS(FTPDataSource, nsIRDFDataSource::GetIID());
|
||||
|
||||
|
||||
|
||||
@ -209,7 +295,7 @@ FTPDataSource::Init(const char *uri)
|
||||
nsresult rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRDFInMemoryDataSourceCID,
|
||||
nsnull, kIRDFDataSourceIID, (void **)&mInner)))
|
||||
nsnull, nsIRDFDataSource::GetIID(), (void **)&mInner)))
|
||||
return rv;
|
||||
if (NS_FAILED(rv = mInner->Init(uri)))
|
||||
return rv;
|
||||
@ -251,7 +337,7 @@ NS_IMETHODIMP
|
||||
FTPDataSource::GetSources(nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor **sources /* out */)
|
||||
nsISimpleEnumerator **sources /* out */)
|
||||
{
|
||||
return mInner->GetSources(property, target, tv, sources);
|
||||
}
|
||||
@ -259,39 +345,35 @@ FTPDataSource::GetSources(nsIRDFResource *property,
|
||||
|
||||
|
||||
NS_METHOD
|
||||
FTPDataSource::GetURL(nsIRDFResource *source, nsVoidArray **array)
|
||||
FTPDataSource::GetURL(nsIRDFResource *source, nsIRDFLiteral** aResult)
|
||||
{
|
||||
nsVoidArray *urlArray = new nsVoidArray();
|
||||
*array = urlArray;
|
||||
if (nsnull == urlArray)
|
||||
{
|
||||
return(NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
nsresult rv;
|
||||
|
||||
nsXPIDLCString uri;
|
||||
rv = source->GetValue( getter_Copies(uri) );
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsXPIDLCString uri;
|
||||
source->GetValue( getter_Copies(uri) );
|
||||
nsAutoString url(uri);
|
||||
|
||||
nsIRDFLiteral *literal;
|
||||
gRDFService->GetLiteral(url.GetUnicode(), &literal);
|
||||
urlArray->AppendElement(literal);
|
||||
return(NS_OK);
|
||||
rv = gRDFService->GetLiteral(url.GetUnicode(), &literal);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*aResult = literal;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_METHOD
|
||||
FTPDataSource::GetName(nsIRDFResource *source, nsVoidArray **array)
|
||||
FTPDataSource::GetName(nsIRDFResource *source, nsIRDFLiteral** aResult)
|
||||
{
|
||||
nsVoidArray *urlArray = new nsVoidArray();
|
||||
*array = urlArray;
|
||||
if (nsnull == urlArray)
|
||||
{
|
||||
return(NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
nsresult rv;
|
||||
|
||||
nsXPIDLCString uri;
|
||||
rv = source->GetValue( getter_Copies(uri) );
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsXPIDLCString uri;
|
||||
source->GetValue( getter_Copies(uri) );
|
||||
nsAutoString url(uri);
|
||||
|
||||
// strip off trailing slash, if its a directory
|
||||
@ -313,9 +395,11 @@ FTPDataSource::GetName(nsIRDFResource *source, nsVoidArray **array)
|
||||
// XXX To Do: unescape basename
|
||||
|
||||
nsIRDFLiteral *literal;
|
||||
gRDFService->GetLiteral(url.GetUnicode(), &literal);
|
||||
urlArray->AppendElement(literal);
|
||||
return(NS_OK);
|
||||
rv = gRDFService->GetLiteral(url.GetUnicode(), &literal);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*aResult = literal;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
@ -334,43 +418,45 @@ FTPDataSource::GetTarget(nsIRDFResource *source,
|
||||
|
||||
if (isFTPURI(source))
|
||||
{
|
||||
nsVoidArray *array = nsnull;
|
||||
if (property == kNC_Name)
|
||||
{
|
||||
nsIRDFLiteral* name;
|
||||
rv = GetName(source, &name);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (peq(property, kNC_Name))
|
||||
{
|
||||
rv = GetName(source, &array);
|
||||
rv = name->QueryInterface(nsIRDFNode::GetIID(), (void**) target);
|
||||
NS_RELEASE(name);
|
||||
|
||||
return rv;
|
||||
}
|
||||
else if (peq(property, kNC_URL))
|
||||
else if (property == kNC_URL)
|
||||
{
|
||||
rv = GetURL(source, &array);
|
||||
nsIRDFLiteral* url;
|
||||
rv = GetURL(source, &url);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = url->QueryInterface(nsIRDFNode::GetIID(), (void**) target);
|
||||
NS_RELEASE(url);
|
||||
|
||||
return rv;
|
||||
}
|
||||
else if (peq(property, kRDF_type))
|
||||
else if (property == kRDF_type)
|
||||
{
|
||||
nsXPIDLCString uri;
|
||||
kNC_FTPObject->GetValue( getter_Copies(uri) );
|
||||
if (uri)
|
||||
{
|
||||
nsAutoString url(uri);
|
||||
nsIRDFLiteral *literal;
|
||||
gRDFService->GetLiteral(url.GetUnicode(), &literal);
|
||||
*target = literal;
|
||||
rv = NS_OK;
|
||||
}
|
||||
return(rv);
|
||||
}
|
||||
if (array != nsnull)
|
||||
{
|
||||
nsIRDFLiteral *literal = (nsIRDFLiteral *)(array->ElementAt(0));
|
||||
*target = (nsIRDFNode *)literal;
|
||||
delete array;
|
||||
rv = NS_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = NS_RDF_NO_VALUE;
|
||||
nsXPIDLCString uri;
|
||||
rv = kNC_FTPObject->GetValue( getter_Copies(uri) );
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsAutoString url(uri);
|
||||
nsIRDFLiteral *literal;
|
||||
rv = gRDFService->GetLiteral(url.GetUnicode(), &literal);
|
||||
|
||||
rv = literal->QueryInterface(nsIRDFNode::GetIID(), (void**) target);
|
||||
NS_RELEASE(literal);
|
||||
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
return(rv);
|
||||
return NS_RDF_NO_VALUE;
|
||||
}
|
||||
|
||||
|
||||
@ -391,12 +477,12 @@ FTPDataSourceCallback::FTPDataSourceCallback(nsIRDFDataSource *ds, nsIRDFResourc
|
||||
if (gRefCnt++ == 0)
|
||||
{
|
||||
nsresult rv = nsServiceManager::GetService(kRDFServiceCID,
|
||||
kIRDFServiceIID,
|
||||
nsIRDFService::GetIID(),
|
||||
(nsISupports**) &gRDFService);
|
||||
|
||||
PR_ASSERT(NS_SUCCEEDED(rv));
|
||||
|
||||
gRDFService->GetResource(kURINC_child, &kNC_Child);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "child", &kNC_Child);
|
||||
}
|
||||
}
|
||||
|
||||
@ -562,7 +648,7 @@ FTPDataSourceCallback::OnDataAvailable(nsIURL* aURL, nsIInputStream *aIStream, P
|
||||
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(FTPDataSourceCallback, kIRDFFTPDataSourceCallbackIID);
|
||||
NS_IMPL_ISUPPORTS(FTPDataSourceCallback, nsIRDFFTPDataSourceCallback::GetIID());
|
||||
#if 0
|
||||
NS_IMPL_ADDREF(FTPDataSourceCallback);
|
||||
NS_IMPL_RELEASE(FTPDataSourceCallback);
|
||||
@ -588,19 +674,13 @@ FTPDataSourceCallback::QueryInterface(REFNSIID iid, void **result)
|
||||
|
||||
|
||||
NS_METHOD
|
||||
FTPDataSource::GetFTPListing(nsIRDFResource *source, nsVoidArray **array)
|
||||
FTPDataSource::GetFTPListing(nsIRDFResource *source, nsISimpleEnumerator** aResult)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
nsVoidArray *urlArray = new nsVoidArray();
|
||||
*array = urlArray;
|
||||
if (nsnull == urlArray)
|
||||
{
|
||||
return(NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
if (isFTPDirectory(source))
|
||||
{
|
||||
nsXPIDLCString ftpURL;
|
||||
nsXPIDLCString ftpURL;
|
||||
source->GetValue( getter_Copies(ftpURL) );
|
||||
|
||||
nsIURL *url;
|
||||
@ -613,7 +693,8 @@ FTPDataSource::GetFTPListing(nsIRDFResource *source, nsVoidArray **array)
|
||||
}
|
||||
}
|
||||
}
|
||||
return(rv);
|
||||
|
||||
return NS_NewEmptyEnumerator(aResult);
|
||||
}
|
||||
|
||||
|
||||
@ -622,51 +703,51 @@ NS_IMETHODIMP
|
||||
FTPDataSource::GetTargets(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor **targets /* out */)
|
||||
nsISimpleEnumerator **targets /* out */)
|
||||
{
|
||||
nsVoidArray *array = nsnull;
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
// we only have positive assertions in the FTP data source.
|
||||
|
||||
if ((tv) && isFTPURI(source))
|
||||
{
|
||||
if (peq(property, kNC_Child))
|
||||
if (property == kNC_Child)
|
||||
{
|
||||
rv = GetFTPListing(source, &array);
|
||||
return GetFTPListing(source, targets);
|
||||
}
|
||||
else if (peq(property, kNC_Name))
|
||||
else if (property == kNC_Name)
|
||||
{
|
||||
// rv = getFindName(source, &array);
|
||||
}
|
||||
else if (peq(property, kRDF_type))
|
||||
else if (property == kRDF_type)
|
||||
{
|
||||
nsXPIDLCString uri;
|
||||
kNC_FTPObject->GetValue( getter_Copies(uri) );
|
||||
if (uri)
|
||||
{
|
||||
nsAutoString url(uri);
|
||||
nsIRDFLiteral *literal;
|
||||
gRDFService->GetLiteral(url.GetUnicode(), &literal);
|
||||
array = new nsVoidArray();
|
||||
if (array)
|
||||
{
|
||||
array->AppendElement(literal);
|
||||
rv = NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((rv == NS_OK) && (nsnull != array))
|
||||
{
|
||||
*targets = new FTPCursor(source, property, PR_FALSE, array);
|
||||
NS_ADDREF(*targets);
|
||||
nsXPIDLCString uri;
|
||||
rv = kNC_FTPObject->GetValue( getter_Copies(uri) );
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsAutoString url(uri);
|
||||
nsIRDFLiteral *literal;
|
||||
rv = gRDFService->GetLiteral(url.GetUnicode(), &literal);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsISimpleEnumerator* result = new nsSingletonEnumerator(literal);
|
||||
|
||||
NS_RELEASE(literal);
|
||||
|
||||
if (! result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(result);
|
||||
*targets = result;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = mInner->GetTargets(source, property, tv, targets);
|
||||
return mInner->GetTargets(source, property, tv, targets);
|
||||
}
|
||||
return(rv);
|
||||
|
||||
return NS_NewEmptyEnumerator(targets);
|
||||
}
|
||||
|
||||
|
||||
@ -710,9 +791,9 @@ FTPDataSource::HasAssertion(nsIRDFResource *source,
|
||||
|
||||
if ((tv) && isFTPURI(source))
|
||||
{
|
||||
if (peq(property, kRDF_type))
|
||||
if (property == kRDF_type)
|
||||
{
|
||||
if (peq((nsIRDFResource *)target, kRDF_type))
|
||||
if ((nsIRDFResource *)target == kRDF_type)
|
||||
{
|
||||
*hasAssertion = PR_TRUE;
|
||||
}
|
||||
@ -730,7 +811,7 @@ FTPDataSource::HasAssertion(nsIRDFResource *source,
|
||||
|
||||
NS_IMETHODIMP
|
||||
FTPDataSource::ArcLabelsIn(nsIRDFNode *node,
|
||||
nsIRDFArcsInCursor ** labels /* out */)
|
||||
nsISimpleEnumerator ** labels /* out */)
|
||||
{
|
||||
return mInner->ArcLabelsIn(node, labels);
|
||||
}
|
||||
@ -739,37 +820,28 @@ FTPDataSource::ArcLabelsIn(nsIRDFNode *node,
|
||||
|
||||
NS_IMETHODIMP
|
||||
FTPDataSource::ArcLabelsOut(nsIRDFResource *source,
|
||||
nsIRDFArcsOutCursor **labels /* out */)
|
||||
nsISimpleEnumerator **labels /* out */)
|
||||
{
|
||||
nsresult rv = NS_RDF_NO_VALUE;
|
||||
|
||||
*labels = nsnull;
|
||||
|
||||
if (isFTPURI(source) && isFTPDirectory(source))
|
||||
{
|
||||
nsVoidArray *temp = new nsVoidArray();
|
||||
if (nsnull == temp)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
temp->AppendElement(kNC_Child);
|
||||
*labels = new FTPCursor(source, kNC_Child, PR_TRUE, temp);
|
||||
if (nsnull != *labels)
|
||||
{
|
||||
NS_ADDREF(*labels);
|
||||
rv = NS_OK;
|
||||
}
|
||||
nsISimpleEnumerator* result = new nsSingletonEnumerator(kNC_Child);
|
||||
if (! result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(result);
|
||||
*labels = result;
|
||||
return NS_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = mInner->ArcLabelsOut(source, labels);
|
||||
return mInner->ArcLabelsOut(source, labels);
|
||||
}
|
||||
return(rv);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FTPDataSource::GetAllResources(nsIRDFResourceCursor** aCursor)
|
||||
FTPDataSource::GetAllResources(nsISimpleEnumerator** aCursor)
|
||||
{
|
||||
return mInner->GetAllResources(aCursor);
|
||||
}
|
||||
@ -853,148 +925,3 @@ NS_NewRDFFTPDataSource(nsIRDFDataSource **result)
|
||||
|
||||
|
||||
|
||||
FTPCursor::FTPCursor(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
PRBool isArcsOut,
|
||||
nsVoidArray *array)
|
||||
: mSource(source),
|
||||
mProperty(property),
|
||||
mArcsOut(isArcsOut),
|
||||
mArray(array),
|
||||
mCount(0),
|
||||
mTarget(nsnull),
|
||||
mValue(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF(mSource);
|
||||
NS_ADDREF(mProperty);
|
||||
}
|
||||
|
||||
|
||||
|
||||
FTPCursor::~FTPCursor(void)
|
||||
{
|
||||
NS_IF_RELEASE(mSource);
|
||||
NS_IF_RELEASE(mValue);
|
||||
NS_IF_RELEASE(mProperty);
|
||||
NS_IF_RELEASE(mTarget);
|
||||
if (nsnull != mArray)
|
||||
{
|
||||
delete mArray;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FTPCursor::Advance(void)
|
||||
{
|
||||
if (!mArray)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (mArray->Count() <= mCount)
|
||||
return NS_RDF_CURSOR_EMPTY;
|
||||
NS_IF_RELEASE(mValue);
|
||||
mTarget = mValue = (nsIRDFNode *)mArray->ElementAt(mCount++);
|
||||
NS_ADDREF(mValue);
|
||||
NS_ADDREF(mTarget);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FTPCursor::GetValue(nsIRDFNode **aValue)
|
||||
{
|
||||
if (nsnull == mValue)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
NS_ADDREF(mValue);
|
||||
*aValue = mValue;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FTPCursor::GetDataSource(nsIRDFDataSource **aDataSource)
|
||||
{
|
||||
NS_ADDREF(gFTPDataSource);
|
||||
*aDataSource = gFTPDataSource;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FTPCursor::GetSource(nsIRDFResource **aResource)
|
||||
{
|
||||
NS_ADDREF(mSource);
|
||||
*aResource = mSource;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FTPCursor::GetLabel(nsIRDFResource **aPredicate)
|
||||
{
|
||||
if (mArcsOut == PR_FALSE)
|
||||
{
|
||||
NS_ADDREF(mProperty);
|
||||
*aPredicate = mProperty;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (nsnull == mValue)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
NS_ADDREF(mValue);
|
||||
*(nsIRDFNode **)aPredicate = mValue;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FTPCursor::GetTarget(nsIRDFNode **aObject)
|
||||
{
|
||||
if (nsnull != mTarget)
|
||||
NS_ADDREF(mTarget);
|
||||
*aObject = mTarget;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FTPCursor::GetTruthValue(PRBool *aTruthValue)
|
||||
{
|
||||
*aTruthValue = 1;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(FTPCursor);
|
||||
NS_IMPL_RELEASE(FTPCursor);
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FTPCursor::QueryInterface(REFNSIID iid, void **result)
|
||||
{
|
||||
if (! result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*result = nsnull;
|
||||
if (iid.Equals(kIRDFAssertionCursorIID) ||
|
||||
iid.Equals(kIRDFCursorIID) ||
|
||||
iid.Equals(kIRDFArcsOutCursorIID) ||
|
||||
iid.Equals(kISupportsIID))
|
||||
{
|
||||
*result = NS_STATIC_CAST(nsIRDFAssertionCursor *, this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return(NS_NOINTERFACE);
|
||||
}
|
||||
|
||||
|
@ -1,220 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsFTPDataSource_h__
|
||||
#define nsFTPDataSource_h__
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// NS_DECL_IRDFRESOURCE, NS_IMPL_IRDFRESOURCE
|
||||
//
|
||||
// Convenience macros for implementing the RDF resource interface.
|
||||
//
|
||||
// XXX It might make sense to move these macros to nsIRDFResource.h?
|
||||
|
||||
#define NS_DECL_IRDFRESOURCE \
|
||||
NS_IMETHOD EqualsNode(nsIRDFNode* node, PRBool* result) const;\
|
||||
NS_IMETHOD GetValue(const char* *uri) const;\
|
||||
NS_IMETHOD EqualsResource(const nsIRDFResource* resource, PRBool* result) const;\
|
||||
NS_IMETHOD EqualsString(const char* uri, PRBool* result) const;
|
||||
|
||||
|
||||
#define NS_IMPL_IRDFRESOURCE(__class) \
|
||||
NS_IMETHODIMP \
|
||||
__class::EqualsNode(nsIRDFNode* node, PRBool* result) const {\
|
||||
nsresult rv;\
|
||||
nsIRDFResource* resource;\
|
||||
if (NS_SUCCEEDED(node->QueryInterface(kIRDFResourceIID, (void**) &resource))) {\
|
||||
rv = EqualsResource(resource, result);\
|
||||
NS_RELEASE(resource);\
|
||||
}\
|
||||
else {\
|
||||
*result = PR_FALSE;\
|
||||
rv = NS_OK;\
|
||||
}\
|
||||
return rv;\
|
||||
}\
|
||||
NS_IMETHODIMP \
|
||||
__class::GetValue(const char* *uri) const{\
|
||||
if (!uri)\
|
||||
return NS_ERROR_NULL_POINTER;\
|
||||
*uri = mURI;\
|
||||
return NS_OK;\
|
||||
}\
|
||||
NS_IMETHODIMP \
|
||||
__class::EqualsResource(const nsIRDFResource* resource, PRBool* result) const {\
|
||||
if (!resource || !result) return NS_ERROR_NULL_POINTER;\
|
||||
*result = (resource == (nsIRDFResource*) this);\
|
||||
return NS_OK;\
|
||||
}\
|
||||
NS_IMETHODIMP \
|
||||
__class::EqualsString(const char* uri, PRBool* result) const {\
|
||||
if (!uri || !result) return NS_ERROR_NULL_POINTER;\
|
||||
*result = (PL_strcmp(uri, mURI) == 0);\
|
||||
return NS_OK;\
|
||||
}
|
||||
|
||||
|
||||
|
||||
class FTPDataSourceCallback : public nsIStreamListener
|
||||
{
|
||||
private:
|
||||
nsIRDFDataSource *mDataSource;
|
||||
nsIRDFResource *mParent;
|
||||
static PRInt32 gRefCnt;
|
||||
|
||||
// pseudo-constants
|
||||
static nsIRDFResource *kNC_Child;
|
||||
|
||||
char *mLine;
|
||||
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
FTPDataSourceCallback(nsIRDFDataSource *ds, nsIRDFResource *parent);
|
||||
virtual ~FTPDataSourceCallback(void);
|
||||
|
||||
// stream observer
|
||||
|
||||
NS_IMETHOD OnStartBinding(nsIURL *aURL, const char *aContentType);
|
||||
NS_IMETHOD OnProgress(nsIURL* aURL, PRUint32 aProgress, PRUint32 aProgressMax);
|
||||
NS_IMETHOD OnStatus(nsIURL* aURL, const PRUnichar* aMsg);
|
||||
NS_IMETHOD OnStopBinding(nsIURL* aURL, nsresult aStatus, const PRUnichar* aMsg);
|
||||
|
||||
// stream listener
|
||||
NS_IMETHOD GetBindInfo(nsIURL* aURL, nsStreamBindingInfo* aInfo);
|
||||
NS_IMETHOD OnDataAvailable(nsIURL* aURL, nsIInputStream *aIStream,
|
||||
PRUint32 aLength);
|
||||
};
|
||||
|
||||
|
||||
|
||||
class FTPDataSource : public nsIRDFFTPDataSource
|
||||
{
|
||||
private:
|
||||
char *mURI;
|
||||
|
||||
static PRInt32 gRefCnt;
|
||||
|
||||
// pseudo-constants
|
||||
static nsIRDFResource *kNC_Child;
|
||||
static nsIRDFResource *kNC_Name;
|
||||
static nsIRDFResource *kNC_URL;
|
||||
static nsIRDFResource *kNC_FTPObject;
|
||||
static nsIRDFResource *kRDF_InstanceOf;
|
||||
static nsIRDFResource *kRDF_type;
|
||||
|
||||
NS_METHOD GetFTPListing(nsIRDFResource *source, nsVoidArray **array);
|
||||
NS_METHOD GetURL(nsIRDFResource *source, nsVoidArray **array);
|
||||
NS_METHOD GetName(nsIRDFResource *source, nsVoidArray **array);
|
||||
|
||||
protected:
|
||||
nsIRDFDataSource *mInner;
|
||||
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
FTPDataSource(void);
|
||||
virtual ~FTPDataSource(void);
|
||||
|
||||
//friend class FTPDataSourceCallback;
|
||||
|
||||
// nsIRDFDataSource methods
|
||||
|
||||
NS_IMETHOD Init(const char *uri);
|
||||
NS_IMETHOD GetURI(char **uri);
|
||||
NS_IMETHOD GetSource(nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
nsIRDFResource **source /* out */);
|
||||
NS_IMETHOD GetSources(nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor **sources /* out */);
|
||||
NS_IMETHOD GetTarget(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
PRBool tv,
|
||||
nsIRDFNode **target /* out */);
|
||||
NS_IMETHOD GetTargets(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor **targets /* out */);
|
||||
NS_IMETHOD Assert(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv);
|
||||
NS_IMETHOD Unassert(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
nsIRDFNode *target);
|
||||
NS_IMETHOD HasAssertion(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
PRBool *hasAssertion /* out */);
|
||||
NS_IMETHOD ArcLabelsIn(nsIRDFNode *node,
|
||||
nsIRDFArcsInCursor **labels /* out */);
|
||||
NS_IMETHOD ArcLabelsOut(nsIRDFResource *source,
|
||||
nsIRDFArcsOutCursor **labels /* out */);
|
||||
NS_IMETHOD GetAllResources(nsIRDFResourceCursor** aCursor);
|
||||
NS_IMETHOD AddObserver(nsIRDFObserver *n);
|
||||
NS_IMETHOD RemoveObserver(nsIRDFObserver *n);
|
||||
NS_IMETHOD Flush();
|
||||
NS_IMETHOD GetAllCommands(nsIRDFResource* source,
|
||||
nsIEnumerator/*<nsIRDFResource>*/** commands);
|
||||
NS_IMETHOD IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
|
||||
nsIRDFResource* aCommand,
|
||||
nsISupportsArray/*<nsIRDFResource>*/* aArguments,
|
||||
PRBool* aResult);
|
||||
NS_IMETHOD DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
|
||||
nsIRDFResource* aCommand,
|
||||
nsISupportsArray/*<nsIRDFResource>*/* aArguments);
|
||||
};
|
||||
|
||||
|
||||
|
||||
class FTPCursor : public nsIRDFAssertionCursor, public nsIRDFArcsOutCursor
|
||||
{
|
||||
private:
|
||||
nsIRDFNode *mValue;
|
||||
nsIRDFResource *mSource;
|
||||
nsIRDFResource *mProperty;
|
||||
nsIRDFNode *mTarget;
|
||||
int mCount;
|
||||
nsVoidArray *mArray;
|
||||
PRBool mArcsOut;
|
||||
|
||||
public:
|
||||
FTPCursor(nsIRDFResource *source, nsIRDFResource *property, PRBool isArcsOut, nsVoidArray *array);
|
||||
virtual ~FTPCursor(void);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD Advance(void);
|
||||
NS_IMETHOD GetValue(nsIRDFNode **aValue);
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource **aDataSource);
|
||||
NS_IMETHOD GetSource(nsIRDFResource **aResource);
|
||||
NS_IMETHOD GetLabel(nsIRDFResource **aPredicate);
|
||||
NS_IMETHOD GetTarget(nsIRDFNode **aObject);
|
||||
NS_IMETHOD GetTruthValue(PRBool *aTruthValue);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // nsFTPDataSource_h__
|
@ -23,7 +23,8 @@
|
||||
#include <ctype.h> // for toupper()
|
||||
#include <stdio.h>
|
||||
#include "nscore.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIEnumerator.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFObserver.h"
|
||||
@ -44,8 +45,8 @@
|
||||
#include "rdf.h"
|
||||
#include "nsFileSpec.h"
|
||||
#include "nsIRDFFileSystem.h"
|
||||
#include "nsFileSystemDataSource.h"
|
||||
#include "nsFileSpec.h"
|
||||
#include "nsEnumeratorUtils.h"
|
||||
|
||||
|
||||
#ifdef XP_WIN
|
||||
@ -56,28 +57,99 @@
|
||||
|
||||
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
|
||||
static NS_DEFINE_IID(kIRDFDataSourceIID, NS_IRDFDATASOURCE_IID);
|
||||
static NS_DEFINE_IID(kIRDFFileSystemDataSourceIID, NS_IRDFFILESYSTEMDATAOURCE_IID);
|
||||
static NS_DEFINE_IID(kIRDFAssertionCursorIID, NS_IRDFASSERTIONCURSOR_IID);
|
||||
static NS_DEFINE_IID(kIRDFCursorIID, NS_IRDFCURSOR_IID);
|
||||
static NS_DEFINE_IID(kIRDFArcsOutCursorIID, NS_IRDFARCSOUTCURSOR_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
|
||||
static NS_DEFINE_IID(kIRDFNodeIID, NS_IRDFNODE_IID);
|
||||
|
||||
|
||||
|
||||
static const char kURINC_FileSystemRoot[] = "NC:FilesRoot";
|
||||
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, child);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Name);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, URL);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, FileSystemObject);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, pulse);
|
||||
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, instanceOf);
|
||||
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, type);
|
||||
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, Seq);
|
||||
class FileSystemDataSource : public nsIRDFFileSystemDataSource
|
||||
{
|
||||
private:
|
||||
char *mURI;
|
||||
nsVoidArray *mObservers;
|
||||
|
||||
static PRInt32 gRefCnt;
|
||||
|
||||
// pseudo-constants
|
||||
static nsIRDFResource *kNC_FileSystemRoot;
|
||||
static nsIRDFResource *kNC_Child;
|
||||
static nsIRDFResource *kNC_Name;
|
||||
static nsIRDFResource *kNC_URL;
|
||||
static nsIRDFResource *kNC_FileSystemObject;
|
||||
static nsIRDFResource *kNC_pulse;
|
||||
static nsIRDFResource *kRDF_InstanceOf;
|
||||
static nsIRDFResource *kRDF_type;
|
||||
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
FileSystemDataSource(void);
|
||||
virtual ~FileSystemDataSource(void);
|
||||
|
||||
// nsIRDFDataSource methods
|
||||
|
||||
NS_IMETHOD Init(const char *uri);
|
||||
NS_IMETHOD GetURI(char **uri);
|
||||
NS_IMETHOD GetSource(nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
nsIRDFResource **source /* out */);
|
||||
NS_IMETHOD GetSources(nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
nsISimpleEnumerator **sources /* out */);
|
||||
NS_IMETHOD GetTarget(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
PRBool tv,
|
||||
nsIRDFNode **target /* out */);
|
||||
NS_IMETHOD GetTargets(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
PRBool tv,
|
||||
nsISimpleEnumerator **targets /* out */);
|
||||
NS_IMETHOD Assert(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv);
|
||||
NS_IMETHOD Unassert(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
nsIRDFNode *target);
|
||||
NS_IMETHOD HasAssertion(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
PRBool *hasAssertion /* out */);
|
||||
NS_IMETHOD ArcLabelsIn(nsIRDFNode *node,
|
||||
nsISimpleEnumerator **labels /* out */);
|
||||
NS_IMETHOD ArcLabelsOut(nsIRDFResource *source,
|
||||
nsISimpleEnumerator **labels /* out */);
|
||||
NS_IMETHOD GetAllResources(nsISimpleEnumerator** aResult);
|
||||
NS_IMETHOD AddObserver(nsIRDFObserver *n);
|
||||
NS_IMETHOD RemoveObserver(nsIRDFObserver *n);
|
||||
NS_IMETHOD Flush();
|
||||
NS_IMETHOD GetAllCommands(nsIRDFResource* source,
|
||||
nsIEnumerator/*<nsIRDFResource>*/** commands);
|
||||
|
||||
NS_IMETHOD IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
|
||||
nsIRDFResource* aCommand,
|
||||
nsISupportsArray/*<nsIRDFResource>*/* aArguments,
|
||||
PRBool* aResult);
|
||||
|
||||
NS_IMETHOD DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
|
||||
nsIRDFResource* aCommand,
|
||||
nsISupportsArray/*<nsIRDFResource>*/* aArguments);
|
||||
|
||||
|
||||
// helper methods
|
||||
static PRBool isFileURI(nsIRDFResource* aResource);
|
||||
|
||||
static nsresult GetVolumeList(nsISimpleEnumerator **aResult);
|
||||
static nsresult GetFolderList(nsIRDFResource *source, nsISimpleEnumerator **aResult);
|
||||
static nsresult GetName(nsIRDFResource *source, nsIRDFLiteral** aResult);
|
||||
static nsresult GetURL(nsIRDFResource *source, nsIRDFLiteral** aResult);
|
||||
static PRBool isVisible(const nsNativeFileSpec& file);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
static nsIRDFService *gRDFService = nsnull;
|
||||
@ -96,24 +168,9 @@ nsIRDFResource *FileSystemDataSource::kRDF_type;
|
||||
|
||||
|
||||
|
||||
static PRBool
|
||||
peq(nsIRDFResource* r1, nsIRDFResource* r2)
|
||||
{
|
||||
PRBool retVal=PR_FALSE, result;
|
||||
|
||||
if (NS_SUCCEEDED(r1->EqualsResource(r2, &result)))
|
||||
{
|
||||
if (result)
|
||||
{
|
||||
retVal = PR_TRUE;
|
||||
}
|
||||
}
|
||||
return(retVal);
|
||||
}
|
||||
|
||||
|
||||
static PRBool
|
||||
isFileURI(nsIRDFResource *r)
|
||||
PRBool
|
||||
FileSystemDataSource::isFileURI(nsIRDFResource *r)
|
||||
{
|
||||
PRBool isFileURI = PR_FALSE;
|
||||
nsXPIDLCString uri;
|
||||
@ -140,20 +197,20 @@ FileSystemDataSource::FileSystemDataSource(void)
|
||||
|
||||
if (gRefCnt++ == 0) {
|
||||
nsresult rv = nsServiceManager::GetService(kRDFServiceCID,
|
||||
kIRDFServiceIID,
|
||||
nsIRDFService::GetIID(),
|
||||
(nsISupports**) &gRDFService);
|
||||
|
||||
PR_ASSERT(NS_SUCCEEDED(rv));
|
||||
|
||||
gRDFService->GetResource(kURINC_FileSystemRoot, &kNC_FileSystemRoot);
|
||||
gRDFService->GetResource(kURINC_child, &kNC_Child);
|
||||
gRDFService->GetResource(kURINC_Name, &kNC_Name);
|
||||
gRDFService->GetResource(kURINC_URL, &kNC_URL);
|
||||
gRDFService->GetResource(kURINC_FileSystemObject, &kNC_FileSystemObject);
|
||||
gRDFService->GetResource(kURINC_pulse, &kNC_pulse);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "FileSystemRoot", &kNC_FileSystemRoot);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "Child", &kNC_Child);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "Name", &kNC_Name);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "URL", &kNC_URL);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "FileSystemObject", &kNC_FileSystemObject);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "pulse", &kNC_pulse);
|
||||
|
||||
gRDFService->GetResource(kURIRDF_instanceOf, &kRDF_InstanceOf);
|
||||
gRDFService->GetResource(kURIRDF_type, &kRDF_type);
|
||||
gRDFService->GetResource(RDF_NAMESPACE_URI "instanceOf", &kRDF_InstanceOf);
|
||||
gRDFService->GetResource(RDF_NAMESPACE_URI "type", &kRDF_type);
|
||||
|
||||
gFileSystemDataSource = this;
|
||||
}
|
||||
@ -193,12 +250,7 @@ FileSystemDataSource::~FileSystemDataSource (void)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// NS_IMPL_ISUPPORTS(FileSystemDataSource, kIRDFFileSystemDataSourceIID);
|
||||
NS_IMPL_ISUPPORTS(FileSystemDataSource, kIRDFDataSourceIID);
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(FileSystemDataSource, nsIRDFDataSource::GetIID());
|
||||
|
||||
NS_IMETHODIMP
|
||||
FileSystemDataSource::Init(const char *uri)
|
||||
@ -242,7 +294,7 @@ NS_IMETHODIMP
|
||||
FileSystemDataSource::GetSources(nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor **sources /* out */)
|
||||
nsISimpleEnumerator **sources /* out */)
|
||||
{
|
||||
PR_ASSERT(0);
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
@ -250,177 +302,185 @@ FileSystemDataSource::GetSources(nsIRDFResource *property,
|
||||
|
||||
|
||||
|
||||
nsresult GetVolumeList(nsVoidArray **array);
|
||||
nsresult GetFolderList(nsIRDFResource *source, nsVoidArray **array /* out */);
|
||||
nsresult GetName(nsIRDFResource *source, nsVoidArray **array);
|
||||
nsresult GetURL(nsIRDFResource *source, nsVoidArray **array);
|
||||
PRBool isVisible(nsNativeFileSpec file);
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FileSystemDataSource::GetTarget(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
PRBool tv,
|
||||
nsIRDFNode **target /* out */)
|
||||
nsIRDFResource *property,
|
||||
PRBool tv,
|
||||
nsIRDFNode **target /* out */)
|
||||
{
|
||||
nsresult rv = NS_RDF_NO_VALUE;
|
||||
nsVoidArray *array = nsnull;
|
||||
|
||||
// we only have positive assertions in the file system data source.
|
||||
if (! tv)
|
||||
return rv;
|
||||
return NS_RDF_NO_VALUE;
|
||||
|
||||
if (peq(source, kNC_FileSystemRoot))
|
||||
if (source == kNC_FileSystemRoot)
|
||||
{
|
||||
if (peq(property, kNC_pulse))
|
||||
if (property == kNC_pulse)
|
||||
{
|
||||
nsAutoString pulse("12");
|
||||
nsIRDFLiteral *pulseLiteral;
|
||||
gRDFService->GetLiteral(pulse.GetUnicode(), &pulseLiteral);
|
||||
array = new nsVoidArray();
|
||||
if (array)
|
||||
{
|
||||
array->AppendElement(pulseLiteral);
|
||||
rv = NS_OK;
|
||||
}
|
||||
*target = pulseLiteral;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
else if (isFileURI(source))
|
||||
{
|
||||
if (peq(property, kNC_Name))
|
||||
if (property == kNC_Name)
|
||||
{
|
||||
rv = GetName(source, &array);
|
||||
nsCOMPtr<nsIRDFLiteral> name;
|
||||
rv = GetName(source, getter_AddRefs(name));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return name->QueryInterface(nsIRDFNode::GetIID(), (void**) target);
|
||||
}
|
||||
else if (peq(property, kNC_URL))
|
||||
else if (property == kNC_URL)
|
||||
{
|
||||
rv = GetURL(source, &array);
|
||||
nsCOMPtr<nsIRDFLiteral> url;
|
||||
rv = GetURL(source, getter_AddRefs(url));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return url->QueryInterface(nsIRDFNode::GetIID(), (void**) target);
|
||||
}
|
||||
else if (peq(property, kRDF_type))
|
||||
else if (property == kRDF_type)
|
||||
{
|
||||
nsXPIDLCString uri;
|
||||
kNC_FileSystemObject->GetValue( getter_Copies(uri) );
|
||||
if (uri)
|
||||
{
|
||||
nsAutoString url(uri);
|
||||
nsIRDFLiteral *literal;
|
||||
gRDFService->GetLiteral(url.GetUnicode(), &literal);
|
||||
*target = literal;
|
||||
rv = NS_OK;
|
||||
}
|
||||
return(rv);
|
||||
rv = kNC_FileSystemObject->GetValue( getter_Copies(uri) );
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsAutoString url(uri);
|
||||
nsIRDFLiteral *literal;
|
||||
gRDFService->GetLiteral(url.GetUnicode(), &literal);
|
||||
rv = literal->QueryInterface(nsIRDFNode::GetIID(), (void**) target);
|
||||
NS_RELEASE(literal);
|
||||
return rv;
|
||||
}
|
||||
else if (peq(property, kNC_pulse))
|
||||
else if (property == kNC_pulse)
|
||||
{
|
||||
nsAutoString pulse("12");
|
||||
nsIRDFLiteral *pulseLiteral;
|
||||
gRDFService->GetLiteral(pulse.GetUnicode(), &pulseLiteral);
|
||||
array = new nsVoidArray();
|
||||
if (array)
|
||||
{
|
||||
array->AppendElement(pulseLiteral);
|
||||
rv = NS_OK;
|
||||
}
|
||||
rv = pulseLiteral->QueryInterface(nsIRDFNode::GetIID(), (void**) target);
|
||||
NS_RELEASE(pulseLiteral);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
if (array != nsnull)
|
||||
{
|
||||
nsIRDFLiteral *literal = (nsIRDFLiteral *)(array->ElementAt(0));
|
||||
*target = (nsIRDFNode *)literal;
|
||||
delete array;
|
||||
rv = NS_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = NS_RDF_NO_VALUE;
|
||||
}
|
||||
return(rv);
|
||||
}
|
||||
|
||||
return NS_RDF_NO_VALUE;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FileSystemDataSource::GetTargets(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor **targets /* out */)
|
||||
nsISimpleEnumerator **targets /* out */)
|
||||
{
|
||||
nsVoidArray *array = nsnull;
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
// we only have positive assertions in the file system data source.
|
||||
if (! tv)
|
||||
return rv;
|
||||
return NS_RDF_NO_VALUE;
|
||||
|
||||
if (peq(source, kNC_FileSystemRoot))
|
||||
nsresult rv;
|
||||
|
||||
if (source == kNC_FileSystemRoot)
|
||||
{
|
||||
if (peq(property, kNC_Child))
|
||||
if (property == kNC_Child)
|
||||
{
|
||||
rv = GetVolumeList(&array);
|
||||
return GetVolumeList(targets);
|
||||
}
|
||||
else if (peq(property, kNC_pulse))
|
||||
else if (property == kNC_pulse)
|
||||
{
|
||||
nsAutoString pulse("12");
|
||||
nsIRDFLiteral *pulseLiteral;
|
||||
gRDFService->GetLiteral(pulse.GetUnicode(), &pulseLiteral);
|
||||
array = new nsVoidArray();
|
||||
if (array)
|
||||
{
|
||||
array->AppendElement(pulseLiteral);
|
||||
rv = NS_OK;
|
||||
}
|
||||
nsISimpleEnumerator* result = new nsSingletonEnumerator(pulseLiteral);
|
||||
NS_RELEASE(pulseLiteral);
|
||||
|
||||
if (! result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(result);
|
||||
*targets = result;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
else if (isFileURI(source))
|
||||
{
|
||||
if (peq(property, kNC_Child))
|
||||
if (property == kNC_Child)
|
||||
{
|
||||
rv = GetFolderList(source, &array);
|
||||
return GetFolderList(source, targets);
|
||||
}
|
||||
else if (peq(property, kNC_Name))
|
||||
else if (property == kNC_Name)
|
||||
{
|
||||
rv = GetName(source, &array);
|
||||
nsCOMPtr<nsIRDFLiteral> name;
|
||||
rv = GetName(source, getter_AddRefs(name));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsISimpleEnumerator* result = new nsSingletonEnumerator(name);
|
||||
if (! result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(result);
|
||||
*targets = result;
|
||||
return NS_OK;
|
||||
}
|
||||
else if (peq(property, kNC_URL))
|
||||
else if (property == kNC_URL)
|
||||
{
|
||||
rv = GetURL(source, &array);
|
||||
nsCOMPtr<nsIRDFLiteral> url;
|
||||
rv = GetURL(source, getter_AddRefs(url));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsISimpleEnumerator* result = new nsSingletonEnumerator(url);
|
||||
if (! result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(result);
|
||||
*targets = result;
|
||||
return NS_OK;
|
||||
}
|
||||
else if (peq(property, kRDF_type))
|
||||
else if (property == kRDF_type)
|
||||
{
|
||||
nsXPIDLCString uri;
|
||||
kNC_FileSystemObject->GetValue( getter_Copies(uri) );
|
||||
if (uri)
|
||||
{
|
||||
nsAutoString url(uri);
|
||||
nsIRDFLiteral *literal;
|
||||
gRDFService->GetLiteral(url.GetUnicode(), &literal);
|
||||
array = new nsVoidArray();
|
||||
if (array)
|
||||
{
|
||||
array->AppendElement(literal);
|
||||
rv = NS_OK;
|
||||
}
|
||||
}
|
||||
rv = kNC_FileSystemObject->GetValue( getter_Copies(uri) );
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsAutoString url(uri);
|
||||
nsIRDFLiteral *literal;
|
||||
|
||||
rv = gRDFService->GetLiteral(url.GetUnicode(), &literal);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsISimpleEnumerator* result = new nsSingletonEnumerator(literal);
|
||||
NS_RELEASE(literal);
|
||||
|
||||
if (! result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(result);
|
||||
*targets = result;
|
||||
return NS_OK;
|
||||
}
|
||||
else if (peq(property, kNC_pulse))
|
||||
else if (property == kNC_pulse)
|
||||
{
|
||||
nsAutoString pulse("12");
|
||||
nsIRDFLiteral *pulseLiteral;
|
||||
gRDFService->GetLiteral(pulse.GetUnicode(), &pulseLiteral);
|
||||
array = new nsVoidArray();
|
||||
if (array)
|
||||
{
|
||||
array->AppendElement(pulseLiteral);
|
||||
rv = NS_OK;
|
||||
}
|
||||
rv = gRDFService->GetLiteral(pulse.GetUnicode(), &pulseLiteral);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsISimpleEnumerator* result = new nsSingletonEnumerator(pulseLiteral);
|
||||
NS_RELEASE(pulseLiteral);
|
||||
|
||||
if (! result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(result);
|
||||
*targets = result;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
if ((rv == NS_OK) && (nsnull != array))
|
||||
{
|
||||
*targets = new FileSystemCursor(source, property, PR_FALSE, array);
|
||||
NS_ADDREF(*targets);
|
||||
}
|
||||
return(rv);
|
||||
|
||||
return NS_NewEmptyEnumerator(targets);
|
||||
}
|
||||
|
||||
|
||||
@ -455,33 +515,33 @@ FileSystemDataSource::HasAssertion(nsIRDFResource *source,
|
||||
PRBool tv,
|
||||
PRBool *hasAssertion /* out */)
|
||||
{
|
||||
PRBool retVal = PR_FALSE;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
*hasAssertion = PR_FALSE;
|
||||
|
||||
// we only have positive assertions in the file system data source.
|
||||
if (! tv)
|
||||
return rv;
|
||||
if (! tv) {
|
||||
*hasAssertion = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (peq(source, kNC_FileSystemRoot) || isFileURI(source))
|
||||
if ((source == kNC_FileSystemRoot) || isFileURI(source))
|
||||
{
|
||||
if (peq(property, kRDF_type))
|
||||
if (property == kRDF_type)
|
||||
{
|
||||
if (peq((nsIRDFResource *)target, kRDF_type))
|
||||
{
|
||||
*hasAssertion = PR_TRUE;
|
||||
}
|
||||
nsCOMPtr<nsIRDFResource> resource( do_QueryInterface(target) );
|
||||
if (resource.get() == kRDF_type) {
|
||||
*hasAssertion = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
return (rv);
|
||||
|
||||
*hasAssertion = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FileSystemDataSource::ArcLabelsIn(nsIRDFNode *node,
|
||||
nsIRDFArcsInCursor ** labels /* out */)
|
||||
nsISimpleEnumerator ** labels /* out */)
|
||||
{
|
||||
PR_ASSERT(0);
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
@ -491,62 +551,62 @@ FileSystemDataSource::ArcLabelsIn(nsIRDFNode *node,
|
||||
|
||||
NS_IMETHODIMP
|
||||
FileSystemDataSource::ArcLabelsOut(nsIRDFResource *source,
|
||||
nsIRDFArcsOutCursor **labels /* out */)
|
||||
nsISimpleEnumerator **labels /* out */)
|
||||
{
|
||||
nsresult rv = NS_RDF_NO_VALUE;
|
||||
nsresult rv;
|
||||
|
||||
*labels = nsnull;
|
||||
|
||||
if (peq(source, kNC_FileSystemRoot))
|
||||
if (source == kNC_FileSystemRoot)
|
||||
{
|
||||
nsVoidArray *temp = new nsVoidArray();
|
||||
if (nsnull == temp)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
nsCOMPtr<nsISupportsArray> array;
|
||||
rv = NS_NewISupportsArray(getter_AddRefs(array));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
temp->AppendElement(kNC_Child);
|
||||
temp->AppendElement(kNC_pulse);
|
||||
*labels = new FileSystemCursor(source, kNC_Child, PR_TRUE, temp);
|
||||
if (nsnull != *labels)
|
||||
{
|
||||
NS_ADDREF(*labels);
|
||||
rv = NS_OK;
|
||||
}
|
||||
array->AppendElement(kNC_Child);
|
||||
array->AppendElement(kNC_pulse);
|
||||
|
||||
nsISimpleEnumerator* result = new nsArrayEnumerator(array);
|
||||
if (! result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(result);
|
||||
*labels = result;
|
||||
return NS_OK;
|
||||
}
|
||||
else if (isFileURI(source))
|
||||
{
|
||||
nsVoidArray *temp = new nsVoidArray();
|
||||
if (nsnull == temp)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
nsCOMPtr<nsISupportsArray> array;
|
||||
rv = NS_NewISupportsArray(getter_AddRefs(array));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsXPIDLCString uri;
|
||||
source->GetValue( getter_Copies(uri) );
|
||||
if (uri)
|
||||
{
|
||||
nsFileURL fileURL(uri);
|
||||
nsFileSpec fileSpec(fileURL);
|
||||
if (fileSpec.IsDirectory())
|
||||
{
|
||||
temp->AppendElement(kNC_Child);
|
||||
temp->AppendElement(kNC_pulse);
|
||||
}
|
||||
}
|
||||
nsXPIDLCString uri;
|
||||
rv = source->GetValue( getter_Copies(uri) );
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
temp->AppendElement(kRDF_type);
|
||||
*labels = new FileSystemCursor(source, kRDF_type, PR_TRUE, temp);
|
||||
if (nsnull != *labels)
|
||||
{
|
||||
NS_ADDREF(*labels);
|
||||
rv = NS_OK;
|
||||
}
|
||||
nsFileURL fileURL(uri);
|
||||
nsFileSpec fileSpec(fileURL);
|
||||
if (fileSpec.IsDirectory()) {
|
||||
array->AppendElement(kNC_Child);
|
||||
array->AppendElement(kNC_pulse);
|
||||
}
|
||||
|
||||
array->AppendElement(kRDF_type);
|
||||
|
||||
nsISimpleEnumerator* result = new nsArrayEnumerator(array);
|
||||
if (! result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(result);
|
||||
*labels = result;
|
||||
return NS_OK;
|
||||
}
|
||||
return(rv);
|
||||
|
||||
return NS_NewEmptyEnumerator(labels);
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FileSystemDataSource::GetAllResources(nsIRDFResourceCursor** aCursor)
|
||||
FileSystemDataSource::GetAllResources(nsISimpleEnumerator** aCursor)
|
||||
{
|
||||
NS_NOTYETIMPLEMENTED("sorry!");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
@ -637,17 +697,15 @@ NS_NewRDFFileSystemDataSource(nsIRDFDataSource **result)
|
||||
|
||||
|
||||
nsresult
|
||||
GetVolumeList(nsVoidArray **array)
|
||||
FileSystemDataSource::GetVolumeList(nsISimpleEnumerator** aResult)
|
||||
{
|
||||
nsVoidArray *volumes = new nsVoidArray();
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsISupportsArray> volumes;
|
||||
|
||||
*array = volumes;
|
||||
if (nsnull == *array)
|
||||
{
|
||||
return(NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
rv = NS_NewISupportsArray(getter_AddRefs(volumes));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsIRDFResource *vol;
|
||||
nsCOMPtr<nsIRDFResource> vol;
|
||||
|
||||
#ifdef XP_MAC
|
||||
StrFileName fname;
|
||||
@ -660,11 +718,10 @@ GetVolumeList(nsVoidArray **array)
|
||||
if (PBHGetVInfo(&pb,FALSE) != noErr)
|
||||
break;
|
||||
nsFileSpec fss(pb.volumeParam.ioVRefNum, fsRtParID, fname);
|
||||
if (NS_SUCCEEDED(gRDFService->GetResource(nsFileURL(fss).GetAsString(), (nsIRDFResource**)&vol)))
|
||||
{
|
||||
NS_ADDREF(vol);
|
||||
volumes->AppendElement(vol);
|
||||
}
|
||||
rv = gRDFService->GetResource(nsFileURL(fss).GetAsString(), getter_AddRefs(vol));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
volumes->AppendElement(vol);
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -682,175 +739,34 @@ GetVolumeList(nsVoidArray **array)
|
||||
{
|
||||
if (nsnull != (url = PR_smprintf("file:///%c|/", volNum + 'A')))
|
||||
{
|
||||
gRDFService->GetResource(url, (nsIRDFResource **)&vol);
|
||||
NS_ADDREF(vol);
|
||||
volumes->AppendElement(vol);
|
||||
PR_Free(url);
|
||||
rv = gRDFService->GetResource(url, getter_AddRefs(vol));
|
||||
PR_Free(url);
|
||||
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
volumes->AppendElement(vol);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef XP_UNIX
|
||||
gRDFService->GetResource("file:///", (nsIRDFResource **)&vol);
|
||||
NS_ADDREF(vol);
|
||||
gRDFService->GetResource("file:///", getter_AddRefs(vol));
|
||||
volumes->AppendElement(vol);
|
||||
#endif
|
||||
|
||||
nsISimpleEnumerator* result = new nsArrayEnumerator(volumes);
|
||||
if (! result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(result);
|
||||
*aResult = result;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
FileSystemCursor::FileSystemCursor(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
PRBool isArcsOut,
|
||||
nsVoidArray *array)
|
||||
: mSource(source),
|
||||
mProperty(property),
|
||||
mArcsOut(isArcsOut),
|
||||
mArray(array),
|
||||
mCount(0),
|
||||
mTarget(nsnull),
|
||||
mValue(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF(mSource);
|
||||
NS_ADDREF(mProperty);
|
||||
}
|
||||
|
||||
|
||||
|
||||
FileSystemCursor::~FileSystemCursor(void)
|
||||
{
|
||||
NS_IF_RELEASE(mSource);
|
||||
NS_IF_RELEASE(mValue);
|
||||
NS_IF_RELEASE(mProperty);
|
||||
NS_IF_RELEASE(mTarget);
|
||||
if (nsnull != mArray)
|
||||
{
|
||||
delete mArray;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FileSystemCursor::Advance(void)
|
||||
{
|
||||
if (!mArray)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (mArray->Count() <= mCount)
|
||||
return NS_RDF_CURSOR_EMPTY;
|
||||
NS_IF_RELEASE(mValue);
|
||||
mTarget = mValue = (nsIRDFNode *)mArray->ElementAt(mCount++);
|
||||
NS_ADDREF(mValue);
|
||||
NS_ADDREF(mTarget);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FileSystemCursor::GetValue(nsIRDFNode **aValue)
|
||||
{
|
||||
if (nsnull == mValue)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
NS_ADDREF(mValue);
|
||||
*aValue = mValue;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FileSystemCursor::GetDataSource(nsIRDFDataSource **aDataSource)
|
||||
{
|
||||
NS_ADDREF(gFileSystemDataSource);
|
||||
*aDataSource = gFileSystemDataSource;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FileSystemCursor::GetSource(nsIRDFResource **aResource)
|
||||
{
|
||||
NS_ADDREF(mSource);
|
||||
*aResource = mSource;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FileSystemCursor::GetLabel(nsIRDFResource **aPredicate)
|
||||
{
|
||||
if (mArcsOut == PR_FALSE)
|
||||
{
|
||||
NS_ADDREF(mProperty);
|
||||
*aPredicate = mProperty;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (nsnull == mValue)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
NS_ADDREF(mValue);
|
||||
*(nsIRDFNode **)aPredicate = mValue;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FileSystemCursor::GetTarget(nsIRDFNode **aObject)
|
||||
{
|
||||
if (nsnull != mTarget)
|
||||
NS_ADDREF(mTarget);
|
||||
*aObject = mTarget;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FileSystemCursor::GetTruthValue(PRBool *aTruthValue)
|
||||
{
|
||||
*aTruthValue = 1;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(FileSystemCursor);
|
||||
NS_IMPL_RELEASE(FileSystemCursor);
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FileSystemCursor::QueryInterface(REFNSIID iid, void **result)
|
||||
{
|
||||
if (! result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*result = nsnull;
|
||||
if (iid.Equals(kIRDFAssertionCursorIID) ||
|
||||
iid.Equals(kIRDFCursorIID) ||
|
||||
iid.Equals(kIRDFArcsOutCursorIID) ||
|
||||
iid.Equals(kISupportsIID))
|
||||
{
|
||||
*result = NS_STATIC_CAST(nsIRDFAssertionCursor *, this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return(NS_NOINTERFACE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
PRBool
|
||||
isVisible(nsNativeFileSpec file)
|
||||
FileSystemDataSource::isVisible(const nsNativeFileSpec& file)
|
||||
{
|
||||
PRBool isVisible = PR_TRUE;
|
||||
|
||||
@ -892,21 +808,16 @@ isVisible(nsNativeFileSpec file)
|
||||
|
||||
|
||||
nsresult
|
||||
GetFolderList(nsIRDFResource *source, nsVoidArray **array /* out */)
|
||||
FileSystemDataSource::GetFolderList(nsIRDFResource *source, nsISimpleEnumerator** aResult)
|
||||
{
|
||||
nsVoidArray *nameArray = new nsVoidArray();
|
||||
*array = nameArray;
|
||||
if (nsnull == nameArray)
|
||||
{
|
||||
return(NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsISupportsArray> nameArray;
|
||||
rv = NS_NewISupportsArray(getter_AddRefs(nameArray));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsXPIDLCString uri;
|
||||
source->GetValue( getter_Copies(uri) );
|
||||
if (! uri)
|
||||
{
|
||||
return(NS_ERROR_FAILURE);
|
||||
}
|
||||
rv = source->GetValue( getter_Copies(uri) );
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsFileURL parentDir(uri);
|
||||
nsNativeFileSpec nativeDir(parentDir);
|
||||
@ -918,60 +829,58 @@ GetFolderList(nsIRDFResource *source, nsVoidArray **array /* out */)
|
||||
const char *childURL = fileURL.GetAsString();
|
||||
if (childURL != nsnull)
|
||||
{
|
||||
nsIRDFResource *file;
|
||||
gRDFService->GetResource(childURL, (nsIRDFResource **)&file);
|
||||
nsCOMPtr<nsIRDFResource> file;
|
||||
gRDFService->GetResource(childURL, getter_AddRefs(file));
|
||||
nameArray->AppendElement(file);
|
||||
}
|
||||
}
|
||||
return(NS_OK);
|
||||
|
||||
nsISimpleEnumerator* result = new nsArrayEnumerator(nameArray);
|
||||
if (! result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(result);
|
||||
*aResult = result;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
GetName(nsIRDFResource *source, nsVoidArray **array)
|
||||
FileSystemDataSource::GetName(nsIRDFResource *source, nsIRDFLiteral **aResult)
|
||||
{
|
||||
nsVoidArray *nameArray = new nsVoidArray();
|
||||
*array = nameArray;
|
||||
if (nsnull == nameArray)
|
||||
{
|
||||
return(NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
nsXPIDLCString uri;
|
||||
source->GetValue( getter_Copies(uri) );
|
||||
nsFileURL url(uri);
|
||||
nsNativeFileSpec native(url);
|
||||
char *basename = native.GetLeafName();
|
||||
if (basename)
|
||||
{
|
||||
nsAutoString name(basename);
|
||||
nsIRDFLiteral *literal;
|
||||
gRDFService->GetLiteral(name.GetUnicode(), &literal);
|
||||
nameArray->AppendElement(literal);
|
||||
delete []basename;
|
||||
}
|
||||
return(NS_OK);
|
||||
|
||||
if (! basename)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsAutoString name(basename);
|
||||
nsIRDFLiteral *literal;
|
||||
gRDFService->GetLiteral(name.GetUnicode(), &literal);
|
||||
*aResult = literal;
|
||||
delete []basename;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
GetURL(nsIRDFResource *source, nsVoidArray **array)
|
||||
FileSystemDataSource::GetURL(nsIRDFResource *source, nsIRDFLiteral** aResult)
|
||||
{
|
||||
nsVoidArray *urlArray = new nsVoidArray();
|
||||
*array = urlArray;
|
||||
if (nsnull == urlArray)
|
||||
{
|
||||
return(NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
nsXPIDLCString uri;
|
||||
source->GetValue( getter_Copies(uri) );
|
||||
nsAutoString url(uri);
|
||||
|
||||
nsIRDFLiteral *literal;
|
||||
gRDFService->GetLiteral(url.GetUnicode(), &literal);
|
||||
urlArray->AppendElement(literal);
|
||||
return(NS_OK);
|
||||
*aResult = literal;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,182 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsFileSystemDataSource_h__
|
||||
#define nsFileSystemDataSource_h__
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// NS_DECL_IRDFRESOURCE, NS_IMPL_IRDFRESOURCE
|
||||
//
|
||||
// Convenience macros for implementing the RDF resource interface.
|
||||
//
|
||||
// XXX It might make sense to move these macros to nsIRDFResource.h?
|
||||
|
||||
#define NS_DECL_IRDFRESOURCE \
|
||||
NS_IMETHOD EqualsNode(nsIRDFNode* node, PRBool* result) const;\
|
||||
NS_IMETHOD GetValue(const char* *uri) const;\
|
||||
NS_IMETHOD EqualsResource(const nsIRDFResource* resource, PRBool* result) const;\
|
||||
NS_IMETHOD EqualsString(const char* uri, PRBool* result) const;
|
||||
|
||||
|
||||
#define NS_IMPL_IRDFRESOURCE(__class) \
|
||||
NS_IMETHODIMP \
|
||||
__class::EqualsNode(nsIRDFNode* node, PRBool* result) const {\
|
||||
nsresult rv;\
|
||||
nsIRDFResource* resource;\
|
||||
if (NS_SUCCEEDED(node->QueryInterface(kIRDFResourceIID, (void**) &resource))) {\
|
||||
rv = EqualsResource(resource, result);\
|
||||
NS_RELEASE(resource);\
|
||||
}\
|
||||
else {\
|
||||
*result = PR_FALSE;\
|
||||
rv = NS_OK;\
|
||||
}\
|
||||
return rv;\
|
||||
}\
|
||||
NS_IMETHODIMP \
|
||||
__class::GetValue(const char* *uri) const{\
|
||||
if (!uri)\
|
||||
return NS_ERROR_NULL_POINTER;\
|
||||
*uri = mURI;\
|
||||
return NS_OK;\
|
||||
}\
|
||||
NS_IMETHODIMP \
|
||||
__class::EqualsResource(const nsIRDFResource* resource, PRBool* result) const {\
|
||||
if (!resource || !result) return NS_ERROR_NULL_POINTER;\
|
||||
*result = (resource == (nsIRDFResource*) this);\
|
||||
return NS_OK;\
|
||||
}\
|
||||
NS_IMETHODIMP \
|
||||
__class::EqualsString(const char* uri, PRBool* result) const {\
|
||||
if (!uri || !result) return NS_ERROR_NULL_POINTER;\
|
||||
*result = (PL_strcmp(uri, mURI) == 0);\
|
||||
return NS_OK;\
|
||||
}
|
||||
|
||||
|
||||
|
||||
class FileSystemDataSource : public nsIRDFFileSystemDataSource
|
||||
{
|
||||
private:
|
||||
char *mURI;
|
||||
nsVoidArray *mObservers;
|
||||
|
||||
static PRInt32 gRefCnt;
|
||||
|
||||
// pseudo-constants
|
||||
static nsIRDFResource *kNC_FileSystemRoot;
|
||||
static nsIRDFResource *kNC_Child;
|
||||
static nsIRDFResource *kNC_Name;
|
||||
static nsIRDFResource *kNC_URL;
|
||||
static nsIRDFResource *kNC_FileSystemObject;
|
||||
static nsIRDFResource *kNC_pulse;
|
||||
static nsIRDFResource *kRDF_InstanceOf;
|
||||
static nsIRDFResource *kRDF_type;
|
||||
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
FileSystemDataSource(void);
|
||||
virtual ~FileSystemDataSource(void);
|
||||
|
||||
// nsIRDFDataSource methods
|
||||
|
||||
NS_IMETHOD Init(const char *uri);
|
||||
NS_IMETHOD GetURI(char **uri);
|
||||
NS_IMETHOD GetSource(nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
nsIRDFResource **source /* out */);
|
||||
NS_IMETHOD GetSources(nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor **sources /* out */);
|
||||
NS_IMETHOD GetTarget(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
PRBool tv,
|
||||
nsIRDFNode **target /* out */);
|
||||
NS_IMETHOD GetTargets(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor **targets /* out */);
|
||||
NS_IMETHOD Assert(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv);
|
||||
NS_IMETHOD Unassert(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
nsIRDFNode *target);
|
||||
NS_IMETHOD HasAssertion(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
PRBool *hasAssertion /* out */);
|
||||
NS_IMETHOD ArcLabelsIn(nsIRDFNode *node,
|
||||
nsIRDFArcsInCursor **labels /* out */);
|
||||
NS_IMETHOD ArcLabelsOut(nsIRDFResource *source,
|
||||
nsIRDFArcsOutCursor **labels /* out */);
|
||||
NS_IMETHOD GetAllResources(nsIRDFResourceCursor** aCursor);
|
||||
NS_IMETHOD AddObserver(nsIRDFObserver *n);
|
||||
NS_IMETHOD RemoveObserver(nsIRDFObserver *n);
|
||||
NS_IMETHOD Flush();
|
||||
NS_IMETHOD GetAllCommands(nsIRDFResource* source,
|
||||
nsIEnumerator/*<nsIRDFResource>*/** commands);
|
||||
|
||||
NS_IMETHOD IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
|
||||
nsIRDFResource* aCommand,
|
||||
nsISupportsArray/*<nsIRDFResource>*/* aArguments,
|
||||
PRBool* aResult);
|
||||
|
||||
NS_IMETHOD DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
|
||||
nsIRDFResource* aCommand,
|
||||
nsISupportsArray/*<nsIRDFResource>*/* aArguments);
|
||||
};
|
||||
|
||||
|
||||
|
||||
class FileSystemCursor : public nsIRDFAssertionCursor, public nsIRDFArcsOutCursor
|
||||
{
|
||||
private:
|
||||
nsIRDFNode *mValue;
|
||||
nsIRDFResource *mSource;
|
||||
nsIRDFResource *mProperty;
|
||||
nsIRDFNode *mTarget;
|
||||
int mCount;
|
||||
nsVoidArray *mArray;
|
||||
PRBool mArcsOut;
|
||||
|
||||
public:
|
||||
FileSystemCursor(nsIRDFResource *source, nsIRDFResource *property, PRBool isArcsOut, nsVoidArray *array);
|
||||
virtual ~FileSystemCursor(void);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD Advance(void);
|
||||
NS_IMETHOD GetValue(nsIRDFNode **aValue);
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource **aDataSource);
|
||||
NS_IMETHOD GetSource(nsIRDFResource **aResource);
|
||||
NS_IMETHOD GetLabel(nsIRDFResource **aPredicate);
|
||||
NS_IMETHOD GetTarget(nsIRDFNode **aObject);
|
||||
NS_IMETHOD GetTruthValue(PRBool *aTruthValue);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // nsFileSystemDataSource_h__
|
@ -23,12 +23,14 @@
|
||||
#include <ctype.h> // for toupper()
|
||||
#include <stdio.h>
|
||||
#include "nscore.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFObserver.h"
|
||||
#include "nsIRDFResourceFactory.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsEnumeratorUtils.h"
|
||||
#include "nsString.h"
|
||||
#include "nsVoidArray.h" // XXX introduces dependency on raptorbase
|
||||
#include "nsXPIDLString.h"
|
||||
@ -43,32 +45,104 @@
|
||||
#include "prio.h"
|
||||
#include "rdf.h"
|
||||
#include "nsIRDFFind.h"
|
||||
#include "nsFindDataSource.h"
|
||||
|
||||
|
||||
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
|
||||
static NS_DEFINE_IID(kIRDFDataSourceIID, NS_IRDFDATASOURCE_IID);
|
||||
static NS_DEFINE_IID(kIRDFFindDataSourceIID, NS_IRDFFINDDATAOURCE_IID);
|
||||
static NS_DEFINE_IID(kIRDFAssertionCursorIID, NS_IRDFASSERTIONCURSOR_IID);
|
||||
static NS_DEFINE_IID(kIRDFCursorIID, NS_IRDFCURSOR_IID);
|
||||
static NS_DEFINE_IID(kIRDFArcsOutCursorIID, NS_IRDFARCSOUTCURSOR_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
|
||||
static NS_DEFINE_IID(kIRDFNodeIID, NS_IRDFNODE_IID);
|
||||
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
|
||||
|
||||
|
||||
typedef struct _findTokenStruct
|
||||
{
|
||||
char *token;
|
||||
char *value;
|
||||
} findTokenStruct, *findTokenPtr;
|
||||
|
||||
|
||||
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, child);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Name);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, URL);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, FindObject);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, pulse);
|
||||
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, instanceOf);
|
||||
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, type);
|
||||
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, Seq);
|
||||
class FindDataSource : public nsIRDFFindDataSource
|
||||
{
|
||||
private:
|
||||
char *mURI;
|
||||
nsVoidArray *mObservers;
|
||||
|
||||
static PRInt32 gRefCnt;
|
||||
|
||||
// pseudo-constants
|
||||
static nsIRDFResource *kNC_Child;
|
||||
static nsIRDFResource *kNC_Name;
|
||||
static nsIRDFResource *kNC_URL;
|
||||
static nsIRDFResource *kNC_FindObject;
|
||||
static nsIRDFResource *kNC_pulse;
|
||||
static nsIRDFResource *kRDF_InstanceOf;
|
||||
static nsIRDFResource *kRDF_type;
|
||||
|
||||
NS_METHOD getFindResults(nsIRDFResource *source, nsISimpleEnumerator** aResult);
|
||||
|
||||
NS_METHOD getFindName(nsIRDFResource *source, nsIRDFLiteral** aResult);
|
||||
|
||||
NS_METHOD parseResourceIntoFindTokens(nsIRDFResource *u,
|
||||
findTokenPtr tokens);
|
||||
NS_METHOD doMatch(nsIRDFLiteral *literal, char *matchMethod,
|
||||
char *matchText);
|
||||
NS_METHOD parseFindURL(nsIRDFResource *u,
|
||||
nsISupportsArray *array);
|
||||
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
FindDataSource(void);
|
||||
virtual ~FindDataSource(void);
|
||||
|
||||
// nsIRDFDataSource methods
|
||||
|
||||
NS_IMETHOD Init(const char *uri);
|
||||
NS_IMETHOD GetURI(char **uri);
|
||||
NS_IMETHOD GetSource(nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
nsIRDFResource **source /* out */);
|
||||
NS_IMETHOD GetSources(nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
nsISimpleEnumerator **sources /* out */);
|
||||
NS_IMETHOD GetTarget(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
PRBool tv,
|
||||
nsIRDFNode **target /* out */);
|
||||
NS_IMETHOD GetTargets(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
PRBool tv,
|
||||
nsISimpleEnumerator **targets /* out */);
|
||||
NS_IMETHOD Assert(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv);
|
||||
NS_IMETHOD Unassert(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
nsIRDFNode *target);
|
||||
NS_IMETHOD HasAssertion(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
PRBool *hasAssertion /* out */);
|
||||
NS_IMETHOD ArcLabelsIn(nsIRDFNode *node,
|
||||
nsISimpleEnumerator **labels /* out */);
|
||||
NS_IMETHOD ArcLabelsOut(nsIRDFResource *source,
|
||||
nsISimpleEnumerator **labels /* out */);
|
||||
NS_IMETHOD GetAllResources(nsISimpleEnumerator** aCursor);
|
||||
NS_IMETHOD AddObserver(nsIRDFObserver *n);
|
||||
NS_IMETHOD RemoveObserver(nsIRDFObserver *n);
|
||||
NS_IMETHOD Flush();
|
||||
NS_IMETHOD GetAllCommands(nsIRDFResource* source,
|
||||
nsIEnumerator/*<nsIRDFResource>*/** commands);
|
||||
NS_IMETHOD IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
|
||||
nsIRDFResource* aCommand,
|
||||
nsISupportsArray/*<nsIRDFResource>*/* aArguments,
|
||||
PRBool* aResult);
|
||||
NS_IMETHOD DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
|
||||
nsIRDFResource* aCommand,
|
||||
nsISupportsArray/*<nsIRDFResource>*/* aArguments);
|
||||
};
|
||||
|
||||
|
||||
static nsIRDFService *gRDFService = nsnull;
|
||||
@ -86,22 +160,6 @@ nsIRDFResource *FindDataSource::kRDF_type;
|
||||
|
||||
|
||||
|
||||
static PRBool
|
||||
peq(nsIRDFResource* r1, nsIRDFResource* r2)
|
||||
{
|
||||
PRBool retVal=PR_FALSE, result;
|
||||
|
||||
if (NS_SUCCEEDED(r1->EqualsResource(r2, &result)))
|
||||
{
|
||||
if (result)
|
||||
{
|
||||
retVal = PR_TRUE;
|
||||
}
|
||||
}
|
||||
return(retVal);
|
||||
}
|
||||
|
||||
|
||||
static PRBool
|
||||
isFindURI(nsIRDFResource *r)
|
||||
{
|
||||
@ -126,18 +184,19 @@ FindDataSource::FindDataSource(void)
|
||||
|
||||
if (gRefCnt++ == 0) {
|
||||
nsresult rv = nsServiceManager::GetService(kRDFServiceCID,
|
||||
kIRDFServiceIID,
|
||||
nsIRDFService::GetIID(),
|
||||
(nsISupports**) &gRDFService);
|
||||
|
||||
PR_ASSERT(NS_SUCCEEDED(rv));
|
||||
|
||||
gRDFService->GetResource(kURINC_child, &kNC_Child);
|
||||
gRDFService->GetResource(kURINC_Name, &kNC_Name);
|
||||
gRDFService->GetResource(kURINC_URL, &kNC_URL);
|
||||
gRDFService->GetResource(kURINC_FindObject, &kNC_FindObject);
|
||||
gRDFService->GetResource(kURINC_FindObject, &kNC_pulse);
|
||||
gRDFService->GetResource(kURIRDF_instanceOf, &kRDF_InstanceOf);
|
||||
gRDFService->GetResource(kURIRDF_type, &kRDF_type);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "child", &kNC_Child);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "Name", &kNC_Name);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "URL", &kNC_URL);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "FindObject", &kNC_FindObject);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "FindObject", &kNC_pulse);
|
||||
|
||||
gRDFService->GetResource(RDF_NAMESPACE_URI "instanceOf", &kRDF_InstanceOf);
|
||||
gRDFService->GetResource(RDF_NAMESPACE_URI "type", &kRDF_type);
|
||||
|
||||
gFindDataSource = this;
|
||||
}
|
||||
@ -179,8 +238,7 @@ FindDataSource::~FindDataSource (void)
|
||||
|
||||
|
||||
|
||||
// NS_IMPL_ISUPPORTS(FindDataSource, kIRDFFindDataSourceIID);
|
||||
NS_IMPL_ISUPPORTS(FindDataSource, kIRDFDataSourceIID);
|
||||
NS_IMPL_ISUPPORTS(FindDataSource, nsIRDFDataSource::GetIID());
|
||||
|
||||
|
||||
|
||||
@ -226,7 +284,7 @@ NS_IMETHODIMP
|
||||
FindDataSource::GetSources(nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor **sources /* out */)
|
||||
nsISimpleEnumerator **sources /* out */)
|
||||
{
|
||||
PR_ASSERT(0);
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
@ -248,13 +306,11 @@ FindDataSource::GetTarget(nsIRDFResource *source,
|
||||
|
||||
if (isFindURI(source))
|
||||
{
|
||||
nsVoidArray *array = nsnull;
|
||||
|
||||
if (peq(property, kNC_Name))
|
||||
if (property == kNC_Name)
|
||||
{
|
||||
// rv = GetName(source, &array);
|
||||
}
|
||||
else if (peq(property, kNC_URL))
|
||||
else if (property == kNC_URL)
|
||||
{
|
||||
// note: lie and say there is no URL
|
||||
// rv = GetURL(source, &array);
|
||||
@ -264,45 +320,31 @@ FindDataSource::GetTarget(nsIRDFResource *source,
|
||||
*target = literal;
|
||||
rv = NS_OK;
|
||||
}
|
||||
else if (peq(property, kRDF_type))
|
||||
else if (property == kRDF_type)
|
||||
{
|
||||
nsXPIDLCString uri;
|
||||
kNC_FindObject->GetValue( getter_Copies(uri) );
|
||||
if (uri)
|
||||
{
|
||||
nsAutoString url(uri);
|
||||
nsIRDFLiteral *literal;
|
||||
gRDFService->GetLiteral(url.GetUnicode(), &literal);
|
||||
*target = literal;
|
||||
rv = NS_OK;
|
||||
}
|
||||
return(rv);
|
||||
nsXPIDLCString uri;
|
||||
rv = kNC_FindObject->GetValue( getter_Copies(uri) );
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsAutoString url(uri);
|
||||
nsIRDFLiteral *literal;
|
||||
gRDFService->GetLiteral(url.GetUnicode(), &literal);
|
||||
|
||||
*target = literal;
|
||||
return NS_OK;
|
||||
}
|
||||
else if (peq(property, kNC_pulse))
|
||||
else if (property == kNC_pulse)
|
||||
{
|
||||
nsAutoString pulse("15");
|
||||
nsIRDFLiteral *pulseLiteral;
|
||||
gRDFService->GetLiteral(pulse.GetUnicode(), &pulseLiteral);
|
||||
array = new nsVoidArray();
|
||||
if (array)
|
||||
{
|
||||
array->AppendElement(pulseLiteral);
|
||||
rv = NS_OK;
|
||||
}
|
||||
}
|
||||
if (array != nsnull)
|
||||
{
|
||||
nsIRDFLiteral *literal = (nsIRDFLiteral *)(array->ElementAt(0));
|
||||
*target = (nsIRDFNode *)literal;
|
||||
delete array;
|
||||
rv = NS_OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = NS_RDF_NO_VALUE;
|
||||
rv = gRDFService->GetLiteral(pulse.GetUnicode(), &pulseLiteral);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*target = pulseLiteral;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
return(rv);
|
||||
return NS_RDF_NO_VALUE;
|
||||
}
|
||||
|
||||
|
||||
@ -401,7 +443,7 @@ FindDataSource::doMatch(nsIRDFLiteral *literal, char *matchMethod, char *matchTe
|
||||
|
||||
|
||||
NS_METHOD
|
||||
FindDataSource::parseFindURL(nsIRDFResource *u, nsVoidArray *array)
|
||||
FindDataSource::parseFindURL(nsIRDFResource *u, nsISupportsArray *array)
|
||||
{
|
||||
findTokenStruct tokens[5];
|
||||
nsresult rv;
|
||||
@ -420,25 +462,27 @@ FindDataSource::parseFindURL(nsIRDFResource *u, nsVoidArray *array)
|
||||
nsIRDFDataSource *datasource;
|
||||
if (NS_SUCCEEDED(rv = gRDFService->GetDataSource(tokens[0].value, &datasource)))
|
||||
{
|
||||
nsIRDFResourceCursor *cursor = nsnull;
|
||||
nsISimpleEnumerator *cursor = nsnull;
|
||||
if (NS_SUCCEEDED(rv = datasource->GetAllResources(&cursor)))
|
||||
{
|
||||
while (1)
|
||||
{
|
||||
rv = cursor->Advance();
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
PRBool hasMore;
|
||||
rv = cursor->HasMoreElements(&hasMore);
|
||||
if (NS_FAILED(rv))
|
||||
break;
|
||||
|
||||
if (rv == NS_RDF_CURSOR_EMPTY)
|
||||
break;
|
||||
if (! hasMore)
|
||||
break;
|
||||
|
||||
nsIRDFNode *node = nsnull;
|
||||
if (NS_SUCCEEDED(rv = cursor->GetValue(&node)))
|
||||
nsCOMPtr<nsISupports> isupports;
|
||||
rv = cursor->GetNext(getter_AddRefs(isupports));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsIRDFResource *source = nsnull;
|
||||
if (NS_SUCCEEDED(rv = node->QueryInterface(kIRDFResourceIID, (void **)&source)))
|
||||
if (NS_SUCCEEDED(rv = isupports->QueryInterface(nsIRDFResource::GetIID(), (void **)&source)))
|
||||
{
|
||||
nsXPIDLCString uri;
|
||||
nsXPIDLCString uri;
|
||||
source->GetValue( getter_Copies(uri) );
|
||||
if (PL_strncmp(uri, "find:", PL_strlen("find:"))) // never match against a "find:" URI
|
||||
{
|
||||
@ -451,16 +495,15 @@ FindDataSource::parseFindURL(nsIRDFResource *u, nsVoidArray *array)
|
||||
(rv != NS_RDF_NO_VALUE) && (nsnull != value))
|
||||
{
|
||||
nsIRDFLiteral *literal = nsnull;
|
||||
if (NS_SUCCEEDED(rv = value->QueryInterface(kIRDFLiteralIID, (void **)&literal)) &&
|
||||
if (NS_SUCCEEDED(rv = value->QueryInterface(nsIRDFLiteral::GetIID(), (void **)&literal)) &&
|
||||
(rv != NS_RDF_NO_VALUE) && (nsnull != literal))
|
||||
{
|
||||
if (PR_TRUE == doMatch(literal, tokens[2].value, tokens[3].value))
|
||||
{
|
||||
array->AppendElement(node);
|
||||
array->AppendElement(source);
|
||||
}
|
||||
NS_RELEASE(literal);
|
||||
}
|
||||
NS_RELEASE(node);
|
||||
}
|
||||
NS_RELEASE(property);
|
||||
}
|
||||
@ -493,26 +536,33 @@ FindDataSource::parseFindURL(nsIRDFResource *u, nsVoidArray *array)
|
||||
|
||||
|
||||
NS_METHOD
|
||||
FindDataSource::getFindResults(nsIRDFResource *source, nsVoidArray **array /* out */)
|
||||
FindDataSource::getFindResults(nsIRDFResource *source, nsISimpleEnumerator** aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
nsVoidArray *nameArray = new nsVoidArray();
|
||||
*array = nameArray;
|
||||
if (nsnull == nameArray)
|
||||
{
|
||||
return(NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
rv = parseFindURL(source, *array);
|
||||
return(rv);
|
||||
nsCOMPtr<nsISupportsArray> nameArray;
|
||||
rv = NS_NewISupportsArray( getter_AddRefs(nameArray) );
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = parseFindURL(source, nameArray);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsISimpleEnumerator* result = new nsArrayEnumerator(nameArray);
|
||||
if (! result)
|
||||
NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(result);
|
||||
*aResult = result;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_METHOD
|
||||
FindDataSource::getFindName(nsIRDFResource *source, nsVoidArray **array /* out */)
|
||||
FindDataSource::getFindName(nsIRDFResource *source, nsIRDFLiteral** aResult)
|
||||
{
|
||||
// XXX construct find URI human-readable name
|
||||
*array = nsnull;
|
||||
*aResult = nsnull;
|
||||
return(NS_OK);
|
||||
}
|
||||
|
||||
@ -522,9 +572,8 @@ NS_IMETHODIMP
|
||||
FindDataSource::GetTargets(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor **targets /* out */)
|
||||
nsISimpleEnumerator **targets /* out */)
|
||||
{
|
||||
nsVoidArray *array = nsnull;
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
// we only have positive assertions in the find data source.
|
||||
@ -533,50 +582,71 @@ FindDataSource::GetTargets(nsIRDFResource *source,
|
||||
|
||||
if (isFindURI(source))
|
||||
{
|
||||
if (peq(property, kNC_Child))
|
||||
if (property == kNC_Child)
|
||||
{
|
||||
rv = getFindResults(source, &array);
|
||||
return getFindResults(source, targets);
|
||||
}
|
||||
else if (peq(property, kNC_Name))
|
||||
else if (property == kNC_Name)
|
||||
{
|
||||
rv = getFindName(source, &array);
|
||||
nsCOMPtr<nsIRDFLiteral> name;
|
||||
rv = getFindName(source, getter_AddRefs(name));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsISimpleEnumerator* result =
|
||||
new nsSingletonEnumerator(name);
|
||||
|
||||
if (! result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(result);
|
||||
*targets = result;
|
||||
return NS_OK;
|
||||
}
|
||||
else if (peq(property, kRDF_type))
|
||||
else if (property == kRDF_type)
|
||||
{
|
||||
nsXPIDLCString uri;
|
||||
kNC_FindObject->GetValue( getter_Copies(uri) );
|
||||
if (uri)
|
||||
{
|
||||
nsAutoString url(uri);
|
||||
nsIRDFLiteral *literal;
|
||||
gRDFService->GetLiteral(url.GetUnicode(), &literal);
|
||||
array = new nsVoidArray();
|
||||
if (array)
|
||||
{
|
||||
array->AppendElement(literal);
|
||||
rv = NS_OK;
|
||||
}
|
||||
}
|
||||
rv = kNC_FindObject->GetValue( getter_Copies(uri) );
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsAutoString url(uri);
|
||||
nsIRDFLiteral *literal;
|
||||
rv = gRDFService->GetLiteral(url.GetUnicode(), &literal);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsISimpleEnumerator* result =
|
||||
new nsSingletonEnumerator(literal);
|
||||
|
||||
NS_RELEASE(literal);
|
||||
|
||||
if (! result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(result);
|
||||
*targets = result;
|
||||
return NS_OK;
|
||||
}
|
||||
else if (peq(property, kNC_pulse))
|
||||
else if (property == kNC_pulse)
|
||||
{
|
||||
nsAutoString pulse("15");
|
||||
nsIRDFLiteral *pulseLiteral;
|
||||
gRDFService->GetLiteral(pulse.GetUnicode(), &pulseLiteral);
|
||||
array = new nsVoidArray();
|
||||
if (array)
|
||||
{
|
||||
array->AppendElement(pulseLiteral);
|
||||
rv = NS_OK;
|
||||
}
|
||||
rv = gRDFService->GetLiteral(pulse.GetUnicode(), &pulseLiteral);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsISimpleEnumerator* result =
|
||||
new nsSingletonEnumerator(pulseLiteral);
|
||||
|
||||
NS_RELEASE(pulseLiteral);
|
||||
|
||||
if (! result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(result);
|
||||
*targets = result;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
if ((rv == NS_OK) && (nsnull != array))
|
||||
{
|
||||
*targets = new FindCursor(source, property, PR_FALSE, array);
|
||||
NS_ADDREF(*targets);
|
||||
}
|
||||
return(rv);
|
||||
|
||||
return NS_NewEmptyEnumerator(targets);
|
||||
}
|
||||
|
||||
|
||||
@ -622,9 +692,9 @@ FindDataSource::HasAssertion(nsIRDFResource *source,
|
||||
|
||||
if (isFindURI(source))
|
||||
{
|
||||
if (peq(property, kRDF_type))
|
||||
if (property == kRDF_type)
|
||||
{
|
||||
if (peq((nsIRDFResource *)target, kRDF_type))
|
||||
if ((nsIRDFResource *)target == kRDF_type)
|
||||
{
|
||||
*hasAssertion = PR_TRUE;
|
||||
}
|
||||
@ -637,7 +707,7 @@ FindDataSource::HasAssertion(nsIRDFResource *source,
|
||||
|
||||
NS_IMETHODIMP
|
||||
FindDataSource::ArcLabelsIn(nsIRDFNode *node,
|
||||
nsIRDFArcsInCursor ** labels /* out */)
|
||||
nsISimpleEnumerator ** labels /* out */)
|
||||
{
|
||||
PR_ASSERT(0);
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
@ -647,34 +717,36 @@ FindDataSource::ArcLabelsIn(nsIRDFNode *node,
|
||||
|
||||
NS_IMETHODIMP
|
||||
FindDataSource::ArcLabelsOut(nsIRDFResource *source,
|
||||
nsIRDFArcsOutCursor **labels /* out */)
|
||||
nsISimpleEnumerator **labels /* out */)
|
||||
{
|
||||
nsresult rv = NS_RDF_NO_VALUE;
|
||||
|
||||
*labels = nsnull;
|
||||
nsresult rv;
|
||||
|
||||
if (isFindURI(source))
|
||||
{
|
||||
nsVoidArray *temp = new nsVoidArray();
|
||||
if (nsnull == temp)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
temp->AppendElement(kNC_Child);
|
||||
temp->AppendElement(kNC_pulse);
|
||||
*labels = new FindCursor(source, kNC_Child, PR_TRUE, temp);
|
||||
if (nsnull != *labels)
|
||||
{
|
||||
NS_ADDREF(*labels);
|
||||
rv = NS_OK;
|
||||
}
|
||||
}
|
||||
return(rv);
|
||||
nsCOMPtr<nsISupportsArray> array;
|
||||
rv = NS_NewISupportsArray( getter_AddRefs(array) );
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
array->AppendElement(kNC_Child);
|
||||
array->AppendElement(kNC_pulse);
|
||||
|
||||
nsISimpleEnumerator* result = new nsArrayEnumerator(array);
|
||||
if (! result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(result);
|
||||
*labels = result;
|
||||
return NS_OK;
|
||||
}
|
||||
else {
|
||||
return NS_NewEmptyEnumerator(labels);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FindDataSource::GetAllResources(nsIRDFResourceCursor** aCursor)
|
||||
FindDataSource::GetAllResources(nsISimpleEnumerator** aCursor)
|
||||
{
|
||||
NS_NOTYETIMPLEMENTED("sorry!");
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
@ -769,147 +841,3 @@ NS_NewRDFFindDataSource(nsIRDFDataSource **result)
|
||||
|
||||
|
||||
|
||||
FindCursor::FindCursor(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
PRBool isArcsOut,
|
||||
nsVoidArray *array)
|
||||
: mSource(source),
|
||||
mProperty(property),
|
||||
mArcsOut(isArcsOut),
|
||||
mArray(array),
|
||||
mCount(0),
|
||||
mTarget(nsnull),
|
||||
mValue(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF(mSource);
|
||||
NS_ADDREF(mProperty);
|
||||
}
|
||||
|
||||
|
||||
|
||||
FindCursor::~FindCursor(void)
|
||||
{
|
||||
NS_IF_RELEASE(mSource);
|
||||
NS_IF_RELEASE(mValue);
|
||||
NS_IF_RELEASE(mProperty);
|
||||
NS_IF_RELEASE(mTarget);
|
||||
if (nsnull != mArray)
|
||||
{
|
||||
delete mArray;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FindCursor::Advance(void)
|
||||
{
|
||||
if (!mArray)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (mArray->Count() <= mCount)
|
||||
return NS_RDF_CURSOR_EMPTY;
|
||||
NS_IF_RELEASE(mValue);
|
||||
mTarget = mValue = (nsIRDFNode *)mArray->ElementAt(mCount++);
|
||||
NS_ADDREF(mValue);
|
||||
NS_ADDREF(mTarget);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FindCursor::GetValue(nsIRDFNode **aValue)
|
||||
{
|
||||
if (nsnull == mValue)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
NS_ADDREF(mValue);
|
||||
*aValue = mValue;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FindCursor::GetDataSource(nsIRDFDataSource **aDataSource)
|
||||
{
|
||||
NS_ADDREF(gFindDataSource);
|
||||
*aDataSource = gFindDataSource;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FindCursor::GetSource(nsIRDFResource **aResource)
|
||||
{
|
||||
NS_ADDREF(mSource);
|
||||
*aResource = mSource;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FindCursor::GetLabel(nsIRDFResource **aPredicate)
|
||||
{
|
||||
if (mArcsOut == PR_FALSE)
|
||||
{
|
||||
NS_ADDREF(mProperty);
|
||||
*aPredicate = mProperty;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (nsnull == mValue)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
NS_ADDREF(mValue);
|
||||
*(nsIRDFNode **)aPredicate = mValue;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FindCursor::GetTarget(nsIRDFNode **aObject)
|
||||
{
|
||||
if (nsnull != mTarget)
|
||||
NS_ADDREF(mTarget);
|
||||
*aObject = mTarget;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FindCursor::GetTruthValue(PRBool *aTruthValue)
|
||||
{
|
||||
*aTruthValue = 1;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(FindCursor);
|
||||
NS_IMPL_RELEASE(FindCursor);
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
FindCursor::QueryInterface(REFNSIID iid, void **result)
|
||||
{
|
||||
if (! result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*result = nsnull;
|
||||
if (iid.Equals(kIRDFAssertionCursorIID) ||
|
||||
iid.Equals(kIRDFCursorIID) ||
|
||||
iid.Equals(kIRDFArcsOutCursorIID) ||
|
||||
iid.Equals(kISupportsIID))
|
||||
{
|
||||
*result = NS_STATIC_CAST(nsIRDFAssertionCursor *, this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return(NS_NOINTERFACE);
|
||||
}
|
||||
|
@ -1,198 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsFindDataSource_h__
|
||||
#define nsFindDataSource_h__
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// NS_DECL_IRDFRESOURCE, NS_IMPL_IRDFRESOURCE
|
||||
//
|
||||
// Convenience macros for implementing the RDF resource interface.
|
||||
//
|
||||
// XXX It might make sense to move these macros to nsIRDFResource.h?
|
||||
|
||||
#define NS_DECL_IRDFRESOURCE \
|
||||
NS_IMETHOD EqualsNode(nsIRDFNode* node, PRBool* result) const;\
|
||||
NS_IMETHOD GetValue(const char* *uri) const;\
|
||||
NS_IMETHOD EqualsResource(const nsIRDFResource* resource, PRBool* result) const;\
|
||||
NS_IMETHOD EqualsString(const char* uri, PRBool* result) const;
|
||||
|
||||
|
||||
#define NS_IMPL_IRDFRESOURCE(__class) \
|
||||
NS_IMETHODIMP \
|
||||
__class::EqualsNode(nsIRDFNode* node, PRBool* result) const {\
|
||||
nsresult rv;\
|
||||
nsIRDFResource* resource;\
|
||||
if (NS_SUCCEEDED(node->QueryInterface(kIRDFResourceIID, (void**) &resource))) {\
|
||||
rv = EqualsResource(resource, result);\
|
||||
NS_RELEASE(resource);\
|
||||
}\
|
||||
else {\
|
||||
*result = PR_FALSE;\
|
||||
rv = NS_OK;\
|
||||
}\
|
||||
return rv;\
|
||||
}\
|
||||
NS_IMETHODIMP \
|
||||
__class::GetValue(const char* *uri) const{\
|
||||
if (!uri)\
|
||||
return NS_ERROR_NULL_POINTER;\
|
||||
*uri = mURI;\
|
||||
return NS_OK;\
|
||||
}\
|
||||
NS_IMETHODIMP \
|
||||
__class::EqualsResource(const nsIRDFResource* resource, PRBool* result) const {\
|
||||
if (!resource || !result) return NS_ERROR_NULL_POINTER;\
|
||||
*result = (resource == (nsIRDFResource*) this);\
|
||||
return NS_OK;\
|
||||
}\
|
||||
NS_IMETHODIMP \
|
||||
__class::EqualsString(const char* uri, PRBool* result) const {\
|
||||
if (!uri || !result) return NS_ERROR_NULL_POINTER;\
|
||||
*result = (PL_strcmp(uri, mURI) == 0);\
|
||||
return NS_OK;\
|
||||
}
|
||||
|
||||
|
||||
|
||||
typedef struct _findTokenStruct
|
||||
{
|
||||
char *token;
|
||||
char *value;
|
||||
} findTokenStruct, *findTokenPtr;
|
||||
|
||||
|
||||
|
||||
class FindDataSource : public nsIRDFFindDataSource
|
||||
{
|
||||
private:
|
||||
char *mURI;
|
||||
nsVoidArray *mObservers;
|
||||
|
||||
static PRInt32 gRefCnt;
|
||||
|
||||
// pseudo-constants
|
||||
static nsIRDFResource *kNC_Child;
|
||||
static nsIRDFResource *kNC_Name;
|
||||
static nsIRDFResource *kNC_URL;
|
||||
static nsIRDFResource *kNC_FindObject;
|
||||
static nsIRDFResource *kNC_pulse;
|
||||
static nsIRDFResource *kRDF_InstanceOf;
|
||||
static nsIRDFResource *kRDF_type;
|
||||
|
||||
NS_METHOD getFindResults(nsIRDFResource *source,
|
||||
nsVoidArray **array /* out */);
|
||||
NS_METHOD getFindName(nsIRDFResource *source,
|
||||
nsVoidArray **array /* out */);
|
||||
NS_METHOD parseResourceIntoFindTokens(nsIRDFResource *u,
|
||||
findTokenPtr tokens);
|
||||
NS_METHOD doMatch(nsIRDFLiteral *literal, char *matchMethod,
|
||||
char *matchText);
|
||||
NS_METHOD parseFindURL(nsIRDFResource *u,
|
||||
nsVoidArray *array);
|
||||
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
FindDataSource(void);
|
||||
virtual ~FindDataSource(void);
|
||||
|
||||
// nsIRDFDataSource methods
|
||||
|
||||
NS_IMETHOD Init(const char *uri);
|
||||
NS_IMETHOD GetURI(char **uri);
|
||||
NS_IMETHOD GetSource(nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
nsIRDFResource **source /* out */);
|
||||
NS_IMETHOD GetSources(nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor **sources /* out */);
|
||||
NS_IMETHOD GetTarget(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
PRBool tv,
|
||||
nsIRDFNode **target /* out */);
|
||||
NS_IMETHOD GetTargets(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor **targets /* out */);
|
||||
NS_IMETHOD Assert(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv);
|
||||
NS_IMETHOD Unassert(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
nsIRDFNode *target);
|
||||
NS_IMETHOD HasAssertion(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
PRBool *hasAssertion /* out */);
|
||||
NS_IMETHOD ArcLabelsIn(nsIRDFNode *node,
|
||||
nsIRDFArcsInCursor **labels /* out */);
|
||||
NS_IMETHOD ArcLabelsOut(nsIRDFResource *source,
|
||||
nsIRDFArcsOutCursor **labels /* out */);
|
||||
NS_IMETHOD GetAllResources(nsIRDFResourceCursor** aCursor);
|
||||
NS_IMETHOD AddObserver(nsIRDFObserver *n);
|
||||
NS_IMETHOD RemoveObserver(nsIRDFObserver *n);
|
||||
NS_IMETHOD Flush();
|
||||
NS_IMETHOD GetAllCommands(nsIRDFResource* source,
|
||||
nsIEnumerator/*<nsIRDFResource>*/** commands);
|
||||
NS_IMETHOD IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
|
||||
nsIRDFResource* aCommand,
|
||||
nsISupportsArray/*<nsIRDFResource>*/* aArguments,
|
||||
PRBool* aResult);
|
||||
NS_IMETHOD DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
|
||||
nsIRDFResource* aCommand,
|
||||
nsISupportsArray/*<nsIRDFResource>*/* aArguments);
|
||||
};
|
||||
|
||||
|
||||
|
||||
class FindCursor : public nsIRDFAssertionCursor, public nsIRDFArcsOutCursor
|
||||
{
|
||||
private:
|
||||
nsIRDFNode *mValue;
|
||||
nsIRDFResource *mSource;
|
||||
nsIRDFResource *mProperty;
|
||||
nsIRDFNode *mTarget;
|
||||
int mCount;
|
||||
nsVoidArray *mArray;
|
||||
PRBool mArcsOut;
|
||||
|
||||
public:
|
||||
FindCursor(nsIRDFResource *source, nsIRDFResource *property, PRBool isArcsOut, nsVoidArray *array);
|
||||
virtual ~FindCursor(void);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD Advance(void);
|
||||
NS_IMETHOD GetValue(nsIRDFNode **aValue);
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource **aDataSource);
|
||||
NS_IMETHOD GetSource(nsIRDFResource **aResource);
|
||||
NS_IMETHOD GetLabel(nsIRDFResource **aPredicate);
|
||||
NS_IMETHOD GetTarget(nsIRDFNode **aObject);
|
||||
NS_IMETHOD GetTruthValue(PRBool *aTruthValue);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // nsFindDataSource_h__
|
@ -25,7 +25,6 @@
|
||||
#include <ctype.h> // for toupper()
|
||||
#include <stdio.h>
|
||||
#include "nscore.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFObserver.h"
|
||||
#include "nsIRDFResourceFactory.h"
|
||||
@ -63,15 +62,6 @@
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// Interface IDs
|
||||
|
||||
static NS_DEFINE_IID(kIRDFArcsInCursorIID, NS_IRDFARCSINCURSOR_IID);
|
||||
static NS_DEFINE_IID(kIRDFArcsOutCursorIID, NS_IRDFARCSOUTCURSOR_IID);
|
||||
static NS_DEFINE_IID(kIRDFAssertionCursorIID, NS_IRDFASSERTIONCURSOR_IID);
|
||||
static NS_DEFINE_IID(kIRDFCursorIID, NS_IRDFCURSOR_IID);
|
||||
static NS_DEFINE_IID(kIRDFDataSourceIID, NS_IRDFDATASOURCE_IID);
|
||||
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
|
||||
static NS_DEFINE_IID(kIRDFNodeIID, NS_IRDFNODE_IID);
|
||||
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
|
||||
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
|
||||
@ -189,7 +179,7 @@ public:
|
||||
|
||||
NS_IMETHOD GetSources(nsIRDFResource* property,
|
||||
nsIRDFNode* target, PRBool tv,
|
||||
nsIRDFAssertionCursor** sources) {
|
||||
nsISimpleEnumerator** sources) {
|
||||
return mInner->GetSources(property, target, tv, sources);
|
||||
}
|
||||
|
||||
@ -225,7 +215,7 @@ public:
|
||||
NS_IMETHOD GetTargets(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor** targets) {
|
||||
nsISimpleEnumerator** targets) {
|
||||
return mInner->GetTargets(source, property, tv, targets);
|
||||
}
|
||||
|
||||
@ -260,12 +250,12 @@ public:
|
||||
}
|
||||
|
||||
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
|
||||
nsIRDFArcsInCursor** labels) {
|
||||
nsISimpleEnumerator** labels) {
|
||||
return mInner->ArcLabelsIn(node, labels);
|
||||
}
|
||||
|
||||
NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
|
||||
nsIRDFArcsOutCursor** labels) {
|
||||
nsISimpleEnumerator** labels) {
|
||||
return mInner->ArcLabelsOut(source, labels);
|
||||
}
|
||||
|
||||
@ -293,8 +283,8 @@ public:
|
||||
return mInner->DoCommand(aSources, aCommand, aArguments);
|
||||
}
|
||||
|
||||
NS_IMETHOD GetAllResources(nsIRDFResourceCursor** aCursor) {
|
||||
return mInner->GetAllResources(aCursor);
|
||||
NS_IMETHOD GetAllResources(nsISimpleEnumerator** aResult) {
|
||||
return mInner->GetAllResources(aResult);
|
||||
}
|
||||
|
||||
NS_IMETHOD AddPage (const char* aURI, const char* aRefererURI, PRTime aTime);
|
||||
@ -355,7 +345,8 @@ nsHistoryDataSource::nsHistoryDataSource(void)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = nsServiceManager::GetService(kRDFServiceCID,
|
||||
kIRDFServiceIID, (nsISupports**) &gRDFService);
|
||||
nsIRDFService::GetIID(),
|
||||
(nsISupports**) &gRDFService);
|
||||
|
||||
PR_ASSERT(NS_SUCCEEDED(rv));
|
||||
|
||||
@ -440,7 +431,7 @@ nsHistoryDataSource::Init(const char* uri)
|
||||
{
|
||||
nsresult rv;
|
||||
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRDFInMemoryDataSourceCID,
|
||||
nsnull, kIRDFDataSourceIID, (void**) &mInner)))
|
||||
nsnull, nsIRDFDataSource::GetIID(), (void**) &mInner)))
|
||||
return rv;
|
||||
|
||||
if (NS_FAILED(rv = mInner->Init(uri)))
|
||||
|
@ -70,7 +70,7 @@ public:
|
||||
NS_IMETHOD GetSources(nsIRDFResource* aProperty,
|
||||
nsIRDFNode* aTarget,
|
||||
PRBool aTruthValue,
|
||||
nsIRDFAssertionCursor** aSources) {
|
||||
nsISimpleEnumerator** aSources) {
|
||||
return mInner->GetSources(aProperty, aTarget, aTruthValue, aSources);
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ public:
|
||||
NS_IMETHOD GetTargets(nsIRDFResource* aSource,
|
||||
nsIRDFResource* aProperty,
|
||||
PRBool aTruthValue,
|
||||
nsIRDFAssertionCursor** aTargets) {
|
||||
nsISimpleEnumerator** aTargets) {
|
||||
return mInner->GetTargets(aSource, aProperty, aTruthValue, aTargets);
|
||||
}
|
||||
|
||||
@ -118,17 +118,17 @@ public:
|
||||
}
|
||||
|
||||
NS_IMETHOD ArcLabelsIn(nsIRDFNode* aNode,
|
||||
nsIRDFArcsInCursor** aLabels) {
|
||||
nsISimpleEnumerator** aLabels) {
|
||||
return mInner->ArcLabelsIn(aNode, aLabels);
|
||||
}
|
||||
|
||||
NS_IMETHOD ArcLabelsOut(nsIRDFResource* aSource,
|
||||
nsIRDFArcsOutCursor** aLabels) {
|
||||
nsISimpleEnumerator** aLabels) {
|
||||
return mInner->ArcLabelsOut(aSource, aLabels);
|
||||
}
|
||||
|
||||
NS_IMETHOD GetAllResources(nsIRDFResourceCursor** aCursor) {
|
||||
return mInner->GetAllResources(aCursor);
|
||||
NS_IMETHOD GetAllResources(nsISimpleEnumerator** aResult) {
|
||||
return mInner->GetAllResources(aResult);
|
||||
}
|
||||
|
||||
NS_IMETHOD Flush(void) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
/* -*- 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
|
||||
@ -24,12 +24,12 @@
|
||||
#include <ctype.h> // for toupper()
|
||||
#include <stdio.h>
|
||||
#include "nscore.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFObserver.h"
|
||||
#include "nsIRDFResourceFactory.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsEnumeratorUtils.h"
|
||||
#include "nsString.h"
|
||||
#include "nsVoidArray.h" // XXX introduces dependency on raptorbase
|
||||
#include "nsXPIDLString.h"
|
||||
@ -48,34 +48,135 @@
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIRelatedLinksDataSource.h"
|
||||
#include "nsRelatedLinksDataSource.h"
|
||||
|
||||
|
||||
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
|
||||
static NS_DEFINE_IID(kIRDFServiceIID, NS_IRDFSERVICE_IID);
|
||||
static NS_DEFINE_IID(kIRDFDataSourceIID, NS_IRDFDATASOURCE_IID);
|
||||
static NS_DEFINE_IID(kIRDFRelatedLinksDataSourceIID, NS_IRDFRELATEDLINKSDATAOURCE_IID);
|
||||
static NS_DEFINE_IID(kIRDFAssertionCursorIID, NS_IRDFASSERTIONCURSOR_IID);
|
||||
static NS_DEFINE_IID(kIRDFCursorIID, NS_IRDFCURSOR_IID);
|
||||
static NS_DEFINE_IID(kIRDFArcsOutCursorIID, NS_IRDFARCSOUTCURSOR_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
|
||||
static NS_DEFINE_IID(kIRDFNodeIID, NS_IRDFNODE_IID);
|
||||
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
|
||||
static NS_DEFINE_IID(kIRDFRelatedLinksDataSourceCallbackIID, NS_IRDFRELATEDLINKSDATASOURCECALLBACK_IID);
|
||||
|
||||
static const char kURINC_RelatedLinksRoot[] = "NC:RelatedLinks";
|
||||
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, child);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, Name);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, URL);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, pulse);
|
||||
DEFINE_RDF_VOCAB(NC_NAMESPACE_URI, NC, FTPObject);
|
||||
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, instanceOf);
|
||||
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, type);
|
||||
DEFINE_RDF_VOCAB(RDF_NAMESPACE_URI, RDF, Seq);
|
||||
class RelatedLinksDataSourceCallback : public nsIStreamListener
|
||||
{
|
||||
private:
|
||||
nsIRDFDataSource *mDataSource;
|
||||
nsIRDFResource *mParent;
|
||||
static PRInt32 gRefCnt;
|
||||
nsVoidArray *mParentArray;
|
||||
|
||||
// pseudo-constants
|
||||
static nsIRDFResource *kNC_Child;
|
||||
static nsIRDFResource *kNC_Name;
|
||||
static nsIRDFResource *kNC_RelatedLinksRoot;
|
||||
|
||||
char *mLine;
|
||||
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
RelatedLinksDataSourceCallback(nsIRDFDataSource *ds, nsIRDFResource *parent);
|
||||
virtual ~RelatedLinksDataSourceCallback(void);
|
||||
|
||||
// stream observer
|
||||
|
||||
NS_IMETHOD OnStartBinding(nsIURL *aURL, const char *aContentType);
|
||||
NS_IMETHOD OnProgress(nsIURL* aURL, PRUint32 aProgress, PRUint32 aProgressMax);
|
||||
NS_IMETHOD OnStatus(nsIURL* aURL, const PRUnichar* aMsg);
|
||||
NS_IMETHOD OnStopBinding(nsIURL* aURL, nsresult aStatus, const PRUnichar* aMsg);
|
||||
|
||||
// stream listener
|
||||
NS_IMETHOD GetBindInfo(nsIURL* aURL, nsStreamBindingInfo* aInfo);
|
||||
NS_IMETHOD OnDataAvailable(nsIURL* aURL, nsIInputStream *aIStream,
|
||||
PRUint32 aLength);
|
||||
};
|
||||
|
||||
|
||||
|
||||
class RelatedLinksDataSource : public nsIRDFRelatedLinksDataSource
|
||||
{
|
||||
private:
|
||||
char *mURI;
|
||||
char *mRelatedLinksURL;
|
||||
PRBool mPerformQuery;
|
||||
static PRInt32 gRefCnt;
|
||||
|
||||
// pseudo-constants
|
||||
static nsIRDFResource *kNC_RelatedLinksRoot;
|
||||
static nsIRDFResource *kNC_Child;
|
||||
static nsIRDFResource *kNC_Name;
|
||||
static nsIRDFResource *kNC_URL;
|
||||
static nsIRDFResource *kNC_pulse;
|
||||
static nsIRDFResource *kNC_FTPObject;
|
||||
static nsIRDFResource *kRDF_InstanceOf;
|
||||
static nsIRDFResource *kRDF_type;
|
||||
|
||||
NS_METHOD SetRelatedLinksURL(const char *url);
|
||||
NS_METHOD GetRelatedLinksListing(nsIRDFResource *source);
|
||||
// NS_METHOD GetURL(nsIRDFResource *source, nsVoidArray **array);
|
||||
// NS_METHOD GetName(nsIRDFResource *source, nsVoidArray **array);
|
||||
|
||||
protected:
|
||||
nsIRDFDataSource *mInner;
|
||||
nsVoidArray *mObservers;
|
||||
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
RelatedLinksDataSource(void);
|
||||
virtual ~RelatedLinksDataSource(void);
|
||||
|
||||
// nsIRDFDataSource methods
|
||||
|
||||
NS_IMETHOD Init(const char *uri);
|
||||
NS_IMETHOD GetURI(char **uri);
|
||||
NS_IMETHOD GetSource(nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
nsIRDFResource **source /* out */);
|
||||
NS_IMETHOD GetSources(nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
nsISimpleEnumerator **sources /* out */);
|
||||
NS_IMETHOD GetTarget(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
PRBool tv,
|
||||
nsIRDFNode **target /* out */);
|
||||
NS_IMETHOD GetTargets(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
PRBool tv,
|
||||
nsISimpleEnumerator **targets /* out */);
|
||||
NS_IMETHOD Assert(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv);
|
||||
NS_IMETHOD Unassert(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
nsIRDFNode *target);
|
||||
NS_IMETHOD HasAssertion(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
PRBool *hasAssertion /* out */);
|
||||
NS_IMETHOD ArcLabelsIn(nsIRDFNode *node,
|
||||
nsISimpleEnumerator **labels /* out */);
|
||||
NS_IMETHOD ArcLabelsOut(nsIRDFResource *source,
|
||||
nsISimpleEnumerator **labels /* out */);
|
||||
NS_IMETHOD GetAllResources(nsISimpleEnumerator** aCursor);
|
||||
NS_IMETHOD AddObserver(nsIRDFObserver *n);
|
||||
NS_IMETHOD RemoveObserver(nsIRDFObserver *n);
|
||||
NS_IMETHOD Flush();
|
||||
NS_IMETHOD GetAllCommands(nsIRDFResource* source,
|
||||
nsIEnumerator/*<nsIRDFResource>*/** commands);
|
||||
NS_IMETHOD IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
|
||||
nsIRDFResource* aCommand,
|
||||
nsISupportsArray/*<nsIRDFResource>*/* aArguments,
|
||||
PRBool* aResult);
|
||||
NS_IMETHOD DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
|
||||
nsIRDFResource* aCommand,
|
||||
nsISupportsArray/*<nsIRDFResource>*/* aArguments);
|
||||
};
|
||||
|
||||
|
||||
|
||||
static nsIRDFService *gRDFService = nsnull;
|
||||
@ -98,23 +199,6 @@ nsIRDFResource *RelatedLinksDataSourceCallback::kNC_RelatedLinksRoot;
|
||||
|
||||
|
||||
|
||||
static PRBool
|
||||
peq(nsIRDFResource* r1, nsIRDFResource* r2)
|
||||
{
|
||||
PRBool retVal=PR_FALSE, result;
|
||||
|
||||
if (NS_SUCCEEDED(r1->EqualsResource(r2, &result)))
|
||||
{
|
||||
if (result)
|
||||
{
|
||||
retVal = PR_TRUE;
|
||||
}
|
||||
}
|
||||
return(retVal);
|
||||
}
|
||||
|
||||
|
||||
|
||||
RelatedLinksDataSource::RelatedLinksDataSource(void)
|
||||
: mURI(nsnull),
|
||||
mRelatedLinksURL(nsnull),
|
||||
@ -127,18 +211,18 @@ RelatedLinksDataSource::RelatedLinksDataSource(void)
|
||||
if (gRefCnt++ == 0)
|
||||
{
|
||||
nsresult rv = nsServiceManager::GetService(kRDFServiceCID,
|
||||
kIRDFServiceIID,
|
||||
nsIRDFService::GetIID(),
|
||||
(nsISupports**) &gRDFService);
|
||||
PR_ASSERT(NS_SUCCEEDED(rv));
|
||||
|
||||
gRDFService->GetResource(kURINC_RelatedLinksRoot, &kNC_RelatedLinksRoot);
|
||||
gRDFService->GetResource(kURINC_child, &kNC_Child);
|
||||
gRDFService->GetResource(kURINC_Name, &kNC_Name);
|
||||
gRDFService->GetResource(kURINC_URL, &kNC_URL);
|
||||
gRDFService->GetResource(kURINC_pulse, &kNC_pulse);
|
||||
gRDFService->GetResource(kURINC_FTPObject, &kNC_FTPObject);
|
||||
gRDFService->GetResource(kURIRDF_instanceOf, &kRDF_InstanceOf);
|
||||
gRDFService->GetResource(kURIRDF_type, &kRDF_type);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "RelatedLinksRoot", &kNC_RelatedLinksRoot);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "child", &kNC_Child);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "Name", &kNC_Name);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "URL", &kNC_URL);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "pulse", &kNC_pulse);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "FTPObject", &kNC_FTPObject);
|
||||
gRDFService->GetResource(RDF_NAMESPACE_URI "instanceOf", &kRDF_InstanceOf);
|
||||
gRDFService->GetResource(RDF_NAMESPACE_URI "type", &kRDF_type);
|
||||
}
|
||||
}
|
||||
|
||||
@ -231,7 +315,7 @@ RelatedLinksDataSource::Init(const char *uri)
|
||||
return(rv);
|
||||
|
||||
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRDFInMemoryDataSourceCID,
|
||||
nsnull, kIRDFDataSourceIID, (void **)&mInner)))
|
||||
nsnull, nsIRDFDataSource::GetIID(), (void **)&mInner)))
|
||||
return(rv);
|
||||
if (NS_FAILED(rv = mInner->Init(mURI)))
|
||||
return(rv);
|
||||
@ -274,7 +358,7 @@ NS_IMETHODIMP
|
||||
RelatedLinksDataSource::GetSources(nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor **sources /* out */)
|
||||
nsISimpleEnumerator **sources /* out */)
|
||||
{
|
||||
nsresult result = NS_RDF_NO_VALUE;
|
||||
if (mInner) result = mInner->GetSources(property, target, tv, sources);
|
||||
@ -296,9 +380,9 @@ RelatedLinksDataSource::GetTarget(nsIRDFResource *source,
|
||||
return rv;
|
||||
|
||||
nsVoidArray *array = nsnull;
|
||||
if (peq(source, kNC_RelatedLinksRoot))
|
||||
if (source == kNC_RelatedLinksRoot)
|
||||
{
|
||||
if (peq(property, kNC_pulse))
|
||||
if (property == kNC_pulse)
|
||||
{
|
||||
nsAutoString pulse("15");
|
||||
nsIRDFLiteral *pulseLiteral;
|
||||
@ -310,7 +394,7 @@ RelatedLinksDataSource::GetTarget(nsIRDFResource *source,
|
||||
rv = NS_OK;
|
||||
}
|
||||
}
|
||||
else if (peq(property, kRDF_type))
|
||||
else if (property == kRDF_type)
|
||||
{
|
||||
nsXPIDLCString uri;
|
||||
kNC_FTPObject->GetValue( getter_Copies(uri) );
|
||||
@ -359,14 +443,14 @@ RelatedLinksDataSourceCallback::RelatedLinksDataSourceCallback(nsIRDFDataSource
|
||||
if (gRefCnt++ == 0)
|
||||
{
|
||||
nsresult rv = nsServiceManager::GetService(kRDFServiceCID,
|
||||
kIRDFServiceIID,
|
||||
nsIRDFService::GetIID(),
|
||||
(nsISupports**) &gRDFService);
|
||||
|
||||
PR_ASSERT(NS_SUCCEEDED(rv));
|
||||
|
||||
gRDFService->GetResource(kURINC_child, &kNC_Child);
|
||||
gRDFService->GetResource(kURINC_Name, &kNC_Name);
|
||||
gRDFService->GetResource(kURINC_RelatedLinksRoot, &kNC_RelatedLinksRoot);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "child", &kNC_Child);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "Name", &kNC_Name);
|
||||
gRDFService->GetResource(NC_NAMESPACE_URI "RelatedLinksRoot", &kNC_RelatedLinksRoot);
|
||||
|
||||
if (nsnull != (mParentArray = new nsVoidArray()))
|
||||
{
|
||||
@ -544,7 +628,7 @@ RelatedLinksDataSourceCallback::OnDataAvailable(nsIURL* aURL, nsIInputStream *aI
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIRDFResource> newTopic;
|
||||
nsAutoString rlRoot(kURINC_RelatedLinksRoot);
|
||||
nsAutoString rlRoot(NC_NAMESPACE_URI "RelatedLinksRoot");
|
||||
if (NS_SUCCEEDED(rv = rdf_CreateAnonymousResource(rlRoot, getter_AddRefs(newTopic))))
|
||||
{
|
||||
if (title.Length() > 0)
|
||||
@ -602,7 +686,7 @@ RelatedLinksDataSourceCallback::OnDataAvailable(nsIURL* aURL, nsIInputStream *aI
|
||||
PRInt32 numParents = mParentArray->Count();
|
||||
if (numParents > 1)
|
||||
{
|
||||
nsAutoString rlRoot(kURINC_RelatedLinksRoot);
|
||||
nsAutoString rlRoot(NC_NAMESPACE_URI "RelatedLinksRoot");
|
||||
rv = rdf_CreateAnonymousResource(rlRoot, getter_AddRefs(relatedLinksChild));
|
||||
}
|
||||
else
|
||||
@ -645,7 +729,7 @@ RelatedLinksDataSourceCallback::OnDataAvailable(nsIURL* aURL, nsIInputStream *aI
|
||||
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(RelatedLinksDataSourceCallback, kIRDFRelatedLinksDataSourceCallbackIID);
|
||||
NS_IMPL_ISUPPORTS(RelatedLinksDataSourceCallback, nsIRDFRelatedLinksDataSourceCallback::GetIID());
|
||||
|
||||
|
||||
|
||||
@ -687,61 +771,66 @@ NS_IMETHODIMP
|
||||
RelatedLinksDataSource::GetTargets(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor **targets /* out */)
|
||||
nsISimpleEnumerator **targets /* out */)
|
||||
{
|
||||
nsVoidArray *array = nsnull;
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
// we only have positive assertions in the Related Links data source.
|
||||
|
||||
*targets = nsnull;
|
||||
if ((tv) && peq(source, kNC_RelatedLinksRoot))
|
||||
if ((tv) && (source == kNC_RelatedLinksRoot))
|
||||
{
|
||||
if (peq(property, kNC_Child))
|
||||
if (property == kNC_Child)
|
||||
{
|
||||
rv = GetRelatedLinksListing(source);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_NewEmptyEnumerator(targets);
|
||||
}
|
||||
else if (peq(property, kNC_pulse))
|
||||
else if (property == kNC_pulse)
|
||||
{
|
||||
nsAutoString pulse("15");
|
||||
nsIRDFLiteral *pulseLiteral;
|
||||
gRDFService->GetLiteral(pulse.GetUnicode(), &pulseLiteral);
|
||||
array = new nsVoidArray();
|
||||
if (array)
|
||||
{
|
||||
array->AppendElement(pulseLiteral);
|
||||
rv = NS_OK;
|
||||
}
|
||||
rv = gRDFService->GetLiteral(pulse.GetUnicode(), &pulseLiteral);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsISimpleEnumerator* result = new nsSingletonEnumerator(pulseLiteral);
|
||||
NS_RELEASE(pulseLiteral);
|
||||
if (! result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(result);
|
||||
*targets = result;
|
||||
return NS_OK;
|
||||
}
|
||||
else if (peq(property, kRDF_type))
|
||||
else if (property == kRDF_type)
|
||||
{
|
||||
nsXPIDLCString uri;
|
||||
kNC_FTPObject->GetValue( getter_Copies(uri) );
|
||||
if (uri)
|
||||
{
|
||||
nsAutoString url(uri);
|
||||
nsIRDFLiteral *literal;
|
||||
gRDFService->GetLiteral(url.GetUnicode(), &literal);
|
||||
array = new nsVoidArray();
|
||||
if (array)
|
||||
{
|
||||
array->AppendElement(literal);
|
||||
rv = NS_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((rv == NS_OK) && (nsnull != array))
|
||||
{
|
||||
*targets = new RelatedLinksCursor(this, source, property, PR_FALSE, array);
|
||||
NS_ADDREF(*targets);
|
||||
rv = kNC_FTPObject->GetValue( getter_Copies(uri) );
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsAutoString url(uri);
|
||||
nsIRDFLiteral *literal;
|
||||
rv = gRDFService->GetLiteral(url.GetUnicode(), &literal);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsISimpleEnumerator* result = new nsSingletonEnumerator(literal);
|
||||
NS_RELEASE(literal);
|
||||
if (! result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(result);
|
||||
*targets = result;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
if (nsnull == *targets)
|
||||
{
|
||||
rv = NS_RDF_NO_VALUE;
|
||||
if (mInner) rv = mInner->GetTargets(source, property, tv, targets);
|
||||
|
||||
if (mInner) {
|
||||
return mInner->GetTargets(source, property, tv, targets);
|
||||
}
|
||||
return(rv);
|
||||
else {
|
||||
return NS_NewEmptyEnumerator(targets);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -783,11 +872,11 @@ RelatedLinksDataSource::HasAssertion(nsIRDFResource *source,
|
||||
|
||||
// we only have positive assertions in the Related Links data source.
|
||||
|
||||
if ((tv) && peq(source, kNC_RelatedLinksRoot))
|
||||
if ((tv) && (source == kNC_RelatedLinksRoot))
|
||||
{
|
||||
if (peq(property, kRDF_type))
|
||||
if (property == kRDF_type)
|
||||
{
|
||||
if (peq((nsIRDFResource *)target, kRDF_type))
|
||||
if ((nsIRDFResource *)target == kRDF_type)
|
||||
{
|
||||
*hasAssertion = PR_TRUE;
|
||||
}
|
||||
@ -804,7 +893,7 @@ RelatedLinksDataSource::HasAssertion(nsIRDFResource *source,
|
||||
|
||||
NS_IMETHODIMP
|
||||
RelatedLinksDataSource::ArcLabelsIn(nsIRDFNode *node,
|
||||
nsIRDFArcsInCursor ** labels /* out */)
|
||||
nsISimpleEnumerator ** labels /* out */)
|
||||
{
|
||||
nsresult result = NS_RDF_NO_VALUE;
|
||||
if (mInner) result = mInner->ArcLabelsIn(node, labels);
|
||||
@ -815,38 +904,41 @@ RelatedLinksDataSource::ArcLabelsIn(nsIRDFNode *node,
|
||||
|
||||
NS_IMETHODIMP
|
||||
RelatedLinksDataSource::ArcLabelsOut(nsIRDFResource *source,
|
||||
nsIRDFArcsOutCursor **labels /* out */)
|
||||
nsISimpleEnumerator **labels /* out */)
|
||||
{
|
||||
nsresult rv = NS_RDF_NO_VALUE;
|
||||
|
||||
*labels = nsnull;
|
||||
|
||||
if (peq(source, kNC_RelatedLinksRoot))
|
||||
if (source == kNC_RelatedLinksRoot)
|
||||
{
|
||||
nsVoidArray *temp = new nsVoidArray();
|
||||
if (nsnull == temp)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
temp->AppendElement(kNC_Child);
|
||||
temp->AppendElement(kNC_pulse);
|
||||
*labels = new RelatedLinksCursor(this, source, kNC_Child, PR_TRUE, temp);
|
||||
if (nsnull != *labels)
|
||||
{
|
||||
NS_ADDREF(*labels);
|
||||
rv = NS_OK;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mInner) rv = mInner->ArcLabelsOut(source, labels);
|
||||
}
|
||||
return(rv);
|
||||
nsCOMPtr<nsISupportsArray> array;
|
||||
rv = NS_NewISupportsArray(getter_AddRefs(array));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
array->AppendElement(kNC_Child);
|
||||
array->AppendElement(kNC_pulse);
|
||||
|
||||
nsISimpleEnumerator* result = new nsArrayEnumerator(array);
|
||||
if (! result)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(result);
|
||||
*labels = result;
|
||||
return NS_OK;
|
||||
}
|
||||
else if (mInner) {
|
||||
return mInner->ArcLabelsOut(source, labels);
|
||||
}
|
||||
else {
|
||||
return NS_NewEmptyEnumerator(labels);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
RelatedLinksDataSource::GetAllResources(nsIRDFResourceCursor** aCursor)
|
||||
RelatedLinksDataSource::GetAllResources(nsISimpleEnumerator** aCursor)
|
||||
{
|
||||
nsresult result;
|
||||
if (mInner) result = mInner->GetAllResources(aCursor);
|
||||
@ -960,7 +1052,7 @@ RelatedLinksDataSource::SetRelatedLinksURL(const char *url)
|
||||
// now, create a new in-memory data source
|
||||
nsresult rv;
|
||||
if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRDFInMemoryDataSourceCID,
|
||||
nsnull, kIRDFDataSourceIID, (void **)&mInner)))
|
||||
nsnull, nsIRDFDataSource::GetIID(), (void **)&mInner)))
|
||||
{
|
||||
return(rv);
|
||||
}
|
||||
@ -1004,151 +1096,3 @@ NS_NewRDFRelatedLinksDataSource(nsIRDFDataSource **result)
|
||||
|
||||
|
||||
|
||||
RelatedLinksCursor::RelatedLinksCursor(nsIRDFDataSource *ds,
|
||||
nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
PRBool isArcsOut,
|
||||
nsVoidArray *array)
|
||||
: mDataSource(ds),
|
||||
mSource(source),
|
||||
mProperty(property),
|
||||
mArcsOut(isArcsOut),
|
||||
mArray(array),
|
||||
mCount(0),
|
||||
mTarget(nsnull),
|
||||
mValue(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF(mDataSource);
|
||||
NS_ADDREF(mSource);
|
||||
NS_ADDREF(mProperty);
|
||||
}
|
||||
|
||||
|
||||
|
||||
RelatedLinksCursor::~RelatedLinksCursor(void)
|
||||
{
|
||||
NS_IF_RELEASE(mDataSource);
|
||||
NS_IF_RELEASE(mSource);
|
||||
NS_IF_RELEASE(mValue);
|
||||
NS_IF_RELEASE(mProperty);
|
||||
NS_IF_RELEASE(mTarget);
|
||||
if (nsnull != mArray)
|
||||
{
|
||||
delete mArray;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
RelatedLinksCursor::Advance(void)
|
||||
{
|
||||
if (!mArray)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (mArray->Count() <= mCount)
|
||||
return NS_RDF_CURSOR_EMPTY;
|
||||
NS_IF_RELEASE(mValue);
|
||||
mTarget = mValue = (nsIRDFNode *)mArray->ElementAt(mCount++);
|
||||
NS_ADDREF(mValue);
|
||||
NS_ADDREF(mTarget);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
RelatedLinksCursor::GetValue(nsIRDFNode **aValue)
|
||||
{
|
||||
if (nsnull == mValue)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
NS_ADDREF(mValue);
|
||||
*aValue = mValue;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
RelatedLinksCursor::GetDataSource(nsIRDFDataSource **aDataSource)
|
||||
{
|
||||
NS_ADDREF(mDataSource);
|
||||
*aDataSource = mDataSource;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
RelatedLinksCursor::GetSource(nsIRDFResource **aResource)
|
||||
{
|
||||
NS_ADDREF(mSource);
|
||||
*aResource = mSource;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
RelatedLinksCursor::GetLabel(nsIRDFResource **aPredicate)
|
||||
{
|
||||
if (mArcsOut == PR_FALSE)
|
||||
{
|
||||
NS_ADDREF(mProperty);
|
||||
*aPredicate = mProperty;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (nsnull == mValue)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
NS_ADDREF(mValue);
|
||||
*(nsIRDFNode **)aPredicate = mValue;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
RelatedLinksCursor::GetTarget(nsIRDFNode **aObject)
|
||||
{
|
||||
if (nsnull != mTarget)
|
||||
NS_ADDREF(mTarget);
|
||||
*aObject = mTarget;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
RelatedLinksCursor::GetTruthValue(PRBool *aTruthValue)
|
||||
{
|
||||
*aTruthValue = 1;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
NS_IMPL_ADDREF(RelatedLinksCursor);
|
||||
NS_IMPL_RELEASE(RelatedLinksCursor);
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
RelatedLinksCursor::QueryInterface(REFNSIID iid, void **result)
|
||||
{
|
||||
if (! result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*result = nsnull;
|
||||
if (iid.Equals(kIRDFAssertionCursorIID) ||
|
||||
iid.Equals(kIRDFCursorIID) ||
|
||||
iid.Equals(kIRDFArcsOutCursorIID) ||
|
||||
iid.Equals(kISupportsIID))
|
||||
{
|
||||
*result = NS_STATIC_CAST(nsIRDFAssertionCursor *, this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return(NS_NOINTERFACE);
|
||||
}
|
||||
|
@ -1,227 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsRelatedLinksDataSource_h__
|
||||
#define nsRelatedLinksDataSource_h__
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// NS_DECL_IRDFRESOURCE, NS_IMPL_IRDFRESOURCE
|
||||
//
|
||||
// Convenience macros for implementing the RDF resource interface.
|
||||
//
|
||||
// XXX It might make sense to move these macros to nsIRDFResource.h?
|
||||
|
||||
#define NS_DECL_IRDFRESOURCE \
|
||||
NS_IMETHOD EqualsNode(nsIRDFNode* node, PRBool* result) const;\
|
||||
NS_IMETHOD GetValue(const char* *uri) const;\
|
||||
NS_IMETHOD EqualsResource(const nsIRDFResource* resource, PRBool* result) const;\
|
||||
NS_IMETHOD EqualsString(const char* uri, PRBool* result) const;
|
||||
|
||||
|
||||
#define NS_IMPL_IRDFRESOURCE(__class) \
|
||||
NS_IMETHODIMP \
|
||||
__class::EqualsNode(nsIRDFNode* node, PRBool* result) const {\
|
||||
nsresult rv;\
|
||||
nsIRDFResource* resource;\
|
||||
if (NS_SUCCEEDED(node->QueryInterface(kIRDFResourceIID, (void**) &resource))) {\
|
||||
rv = EqualsResource(resource, result);\
|
||||
NS_RELEASE(resource);\
|
||||
}\
|
||||
else {\
|
||||
*result = PR_FALSE;\
|
||||
rv = NS_OK;\
|
||||
}\
|
||||
return rv;\
|
||||
}\
|
||||
NS_IMETHODIMP \
|
||||
__class::GetValue(const char* *uri) const{\
|
||||
if (!uri)\
|
||||
return NS_ERROR_NULL_POINTER;\
|
||||
*uri = mURI;\
|
||||
return NS_OK;\
|
||||
}\
|
||||
NS_IMETHODIMP \
|
||||
__class::EqualsResource(const nsIRDFResource* resource, PRBool* result) const {\
|
||||
if (!resource || !result) return NS_ERROR_NULL_POINTER;\
|
||||
*result = (resource == (nsIRDFResource*) this);\
|
||||
return NS_OK;\
|
||||
}\
|
||||
NS_IMETHODIMP \
|
||||
__class::EqualsString(const char* uri, PRBool* result) const {\
|
||||
if (!uri || !result) return NS_ERROR_NULL_POINTER;\
|
||||
*result = (PL_strcmp(uri, mURI) == 0);\
|
||||
return NS_OK;\
|
||||
}
|
||||
|
||||
|
||||
|
||||
class RelatedLinksDataSourceCallback : public nsIStreamListener
|
||||
{
|
||||
private:
|
||||
nsIRDFDataSource *mDataSource;
|
||||
nsIRDFResource *mParent;
|
||||
static PRInt32 gRefCnt;
|
||||
nsVoidArray *mParentArray;
|
||||
|
||||
// pseudo-constants
|
||||
static nsIRDFResource *kNC_Child;
|
||||
static nsIRDFResource *kNC_Name;
|
||||
static nsIRDFResource *kNC_RelatedLinksRoot;
|
||||
|
||||
char *mLine;
|
||||
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
RelatedLinksDataSourceCallback(nsIRDFDataSource *ds, nsIRDFResource *parent);
|
||||
virtual ~RelatedLinksDataSourceCallback(void);
|
||||
|
||||
// stream observer
|
||||
|
||||
NS_IMETHOD OnStartBinding(nsIURL *aURL, const char *aContentType);
|
||||
NS_IMETHOD OnProgress(nsIURL* aURL, PRUint32 aProgress, PRUint32 aProgressMax);
|
||||
NS_IMETHOD OnStatus(nsIURL* aURL, const PRUnichar* aMsg);
|
||||
NS_IMETHOD OnStopBinding(nsIURL* aURL, nsresult aStatus, const PRUnichar* aMsg);
|
||||
|
||||
// stream listener
|
||||
NS_IMETHOD GetBindInfo(nsIURL* aURL, nsStreamBindingInfo* aInfo);
|
||||
NS_IMETHOD OnDataAvailable(nsIURL* aURL, nsIInputStream *aIStream,
|
||||
PRUint32 aLength);
|
||||
};
|
||||
|
||||
|
||||
|
||||
class RelatedLinksDataSource : public nsIRDFRelatedLinksDataSource
|
||||
{
|
||||
private:
|
||||
char *mURI;
|
||||
char *mRelatedLinksURL;
|
||||
PRBool mPerformQuery;
|
||||
static PRInt32 gRefCnt;
|
||||
|
||||
// pseudo-constants
|
||||
static nsIRDFResource *kNC_RelatedLinksRoot;
|
||||
static nsIRDFResource *kNC_Child;
|
||||
static nsIRDFResource *kNC_Name;
|
||||
static nsIRDFResource *kNC_URL;
|
||||
static nsIRDFResource *kNC_pulse;
|
||||
static nsIRDFResource *kNC_FTPObject;
|
||||
static nsIRDFResource *kRDF_InstanceOf;
|
||||
static nsIRDFResource *kRDF_type;
|
||||
|
||||
NS_METHOD SetRelatedLinksURL(const char *url);
|
||||
NS_METHOD GetRelatedLinksListing(nsIRDFResource *source);
|
||||
// NS_METHOD GetURL(nsIRDFResource *source, nsVoidArray **array);
|
||||
// NS_METHOD GetName(nsIRDFResource *source, nsVoidArray **array);
|
||||
|
||||
protected:
|
||||
nsIRDFDataSource *mInner;
|
||||
nsVoidArray *mObservers;
|
||||
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
RelatedLinksDataSource(void);
|
||||
virtual ~RelatedLinksDataSource(void);
|
||||
|
||||
// nsIRDFDataSource methods
|
||||
|
||||
NS_IMETHOD Init(const char *uri);
|
||||
NS_IMETHOD GetURI(char **uri);
|
||||
NS_IMETHOD GetSource(nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
nsIRDFResource **source /* out */);
|
||||
NS_IMETHOD GetSources(nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor **sources /* out */);
|
||||
NS_IMETHOD GetTarget(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
PRBool tv,
|
||||
nsIRDFNode **target /* out */);
|
||||
NS_IMETHOD GetTargets(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor **targets /* out */);
|
||||
NS_IMETHOD Assert(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv);
|
||||
NS_IMETHOD Unassert(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
nsIRDFNode *target);
|
||||
NS_IMETHOD HasAssertion(nsIRDFResource *source,
|
||||
nsIRDFResource *property,
|
||||
nsIRDFNode *target,
|
||||
PRBool tv,
|
||||
PRBool *hasAssertion /* out */);
|
||||
NS_IMETHOD ArcLabelsIn(nsIRDFNode *node,
|
||||
nsIRDFArcsInCursor **labels /* out */);
|
||||
NS_IMETHOD ArcLabelsOut(nsIRDFResource *source,
|
||||
nsIRDFArcsOutCursor **labels /* out */);
|
||||
NS_IMETHOD GetAllResources(nsIRDFResourceCursor** aCursor);
|
||||
NS_IMETHOD AddObserver(nsIRDFObserver *n);
|
||||
NS_IMETHOD RemoveObserver(nsIRDFObserver *n);
|
||||
NS_IMETHOD Flush();
|
||||
NS_IMETHOD GetAllCommands(nsIRDFResource* source,
|
||||
nsIEnumerator/*<nsIRDFResource>*/** commands);
|
||||
NS_IMETHOD IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
|
||||
nsIRDFResource* aCommand,
|
||||
nsISupportsArray/*<nsIRDFResource>*/* aArguments,
|
||||
PRBool* aResult);
|
||||
NS_IMETHOD DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
|
||||
nsIRDFResource* aCommand,
|
||||
nsISupportsArray/*<nsIRDFResource>*/* aArguments);
|
||||
};
|
||||
|
||||
|
||||
|
||||
class RelatedLinksCursor : public nsIRDFAssertionCursor, public nsIRDFArcsOutCursor
|
||||
{
|
||||
private:
|
||||
nsIRDFDataSource *mDataSource;
|
||||
nsIRDFNode *mValue;
|
||||
nsIRDFResource *mSource;
|
||||
nsIRDFResource *mProperty;
|
||||
nsIRDFNode *mTarget;
|
||||
int mCount;
|
||||
nsVoidArray *mArray;
|
||||
PRBool mArcsOut;
|
||||
|
||||
public:
|
||||
RelatedLinksCursor(nsIRDFDataSource *ds, nsIRDFResource *source, nsIRDFResource *property, PRBool isArcsOut, nsVoidArray *array);
|
||||
virtual ~RelatedLinksCursor(void);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD Advance(void);
|
||||
NS_IMETHOD GetValue(nsIRDFNode **aValue);
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource **aDataSource);
|
||||
NS_IMETHOD GetSource(nsIRDFResource **aResource);
|
||||
NS_IMETHOD GetLabel(nsIRDFResource **aPredicate);
|
||||
NS_IMETHOD GetTarget(nsIRDFNode **aObject);
|
||||
NS_IMETHOD GetTruthValue(PRBool *aTruthValue);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // nsRelatedLinksDataSource_h__
|
@ -36,7 +36,6 @@
|
||||
#include "nsIOutputStream.h"
|
||||
#include "nsIParser.h"
|
||||
#include "nsIRDFContentSink.h"
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsIRDFService.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
@ -135,7 +134,7 @@ public:
|
||||
NS_IMETHOD GetSources(nsIRDFResource* property,
|
||||
nsIRDFNode* target,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor** sources) {
|
||||
nsISimpleEnumerator** sources) {
|
||||
return mInner->GetSources(property, target, tv, sources);
|
||||
}
|
||||
|
||||
@ -149,7 +148,7 @@ public:
|
||||
NS_IMETHOD GetTargets(nsIRDFResource* source,
|
||||
nsIRDFResource* property,
|
||||
PRBool tv,
|
||||
nsIRDFAssertionCursor** targets) {
|
||||
nsISimpleEnumerator** targets) {
|
||||
return mInner->GetTargets(source, property, tv, targets);
|
||||
}
|
||||
|
||||
@ -183,17 +182,17 @@ public:
|
||||
}
|
||||
|
||||
NS_IMETHOD ArcLabelsIn(nsIRDFNode* node,
|
||||
nsIRDFArcsInCursor** labels) {
|
||||
nsISimpleEnumerator** labels) {
|
||||
return mInner->ArcLabelsIn(node, labels);
|
||||
}
|
||||
|
||||
NS_IMETHOD ArcLabelsOut(nsIRDFResource* source,
|
||||
nsIRDFArcsOutCursor** labels) {
|
||||
nsISimpleEnumerator** labels) {
|
||||
return mInner->ArcLabelsOut(source, labels);
|
||||
}
|
||||
|
||||
NS_IMETHOD GetAllResources(nsIRDFResourceCursor** aCursor) {
|
||||
return mInner->GetAllResources(aCursor);
|
||||
NS_IMETHOD GetAllResources(nsISimpleEnumerator** aResult) {
|
||||
return mInner->GetAllResources(aResult);
|
||||
}
|
||||
|
||||
NS_IMETHOD Flush(void);
|
||||
|
Binary file not shown.
@ -1,2 +1 @@
|
||||
#define XPIDL_JS_STUBS 1
|
||||
#include "MacPrefix.h"
|
||||
|
@ -1,3 +1,2 @@
|
||||
#define DEBUG 1
|
||||
#define XPIDL_JS_STUBS 1
|
||||
#include "MacPrefix_debug.h"
|
||||
|
@ -1,2 +1 @@
|
||||
nsRDFCursorUtils.h
|
||||
nsRDFResource.h
|
||||
|
@ -26,7 +26,6 @@ MODULE = rdfutil
|
||||
|
||||
EXPORTS = \
|
||||
nsRDFResource.h \
|
||||
nsRDFCursorUtils.h \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
||||
|
@ -23,7 +23,6 @@ DEPTH=..\..\..
|
||||
|
||||
EXPORTS=\
|
||||
nsRDFResource.h \
|
||||
nsRDFCursorUtils.h \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)/config/rules.mak>
|
||||
|
@ -1,382 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsRDFCursorUtils_h__
|
||||
#define nsRDFCursorUtils_h__
|
||||
|
||||
#include "nsIRDFCursor.h"
|
||||
#include "nsIRDFNode.h"
|
||||
#include "nsSupportsArrayEnumerator.h"
|
||||
#include "nsIEnumerator.h"
|
||||
#include "rdf.h"
|
||||
|
||||
class NS_RDF nsRDFArrayCursor : public nsSupportsArrayEnumerator,
|
||||
public nsIRDFCursor
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// nsIRDFCursor methods:
|
||||
NS_IMETHOD Advance(void);
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource);
|
||||
NS_IMETHOD GetValue(nsIRDFNode** aValue);
|
||||
|
||||
// nsRDFArrayCursor methods:
|
||||
nsRDFArrayCursor(nsIRDFDataSource* aDataSource,
|
||||
nsISupportsArray* valueArray);
|
||||
virtual ~nsRDFArrayCursor(void);
|
||||
|
||||
protected:
|
||||
nsIRDFDataSource* mDataSource;
|
||||
PRBool mStarted;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class NS_RDF nsRDFArrayAssertionCursor : public nsRDFArrayCursor,
|
||||
public nsIRDFAssertionCursor
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// nsIRDFCursor methods:
|
||||
NS_IMETHOD Advance(void) {
|
||||
return nsRDFArrayCursor::Advance();
|
||||
}
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource) {
|
||||
return nsRDFArrayCursor::GetDataSource(aDataSource);
|
||||
}
|
||||
NS_IMETHOD GetValue(nsIRDFNode** aValue) {
|
||||
return nsRDFArrayCursor::GetValue(aValue);
|
||||
}
|
||||
|
||||
// nsIRDFAssertionCursor methods:
|
||||
NS_IMETHOD GetSource(nsIRDFResource* *aSubject);
|
||||
NS_IMETHOD GetLabel(nsIRDFResource* *aPredicate);
|
||||
NS_IMETHOD GetTarget(nsIRDFNode* *aObject);
|
||||
NS_IMETHOD GetTruthValue(PRBool *aTruthValue);
|
||||
|
||||
// nsRDFArrayAssertionCursor methods:
|
||||
nsRDFArrayAssertionCursor(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* subject,
|
||||
nsIRDFResource* predicate,
|
||||
nsISupportsArray* objectsArray,
|
||||
PRBool truthValue = PR_TRUE);
|
||||
virtual ~nsRDFArrayAssertionCursor();
|
||||
|
||||
protected:
|
||||
nsIRDFResource* mSubject;
|
||||
nsIRDFResource* mPredicate;
|
||||
PRBool mTruthValue;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class NS_RDF nsRDFSingletonAssertionCursor : public nsIRDFAssertionCursor
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIRDFCursor methods:
|
||||
NS_IMETHOD Advance(void);
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource);
|
||||
NS_IMETHOD GetValue(nsIRDFNode** aValue);
|
||||
|
||||
// nsIRDFAssertionCursor methods:
|
||||
NS_IMETHOD GetSource(nsIRDFResource* *aSubject);
|
||||
NS_IMETHOD GetLabel(nsIRDFResource* *aPredicate);
|
||||
NS_IMETHOD GetTarget(nsIRDFNode* *aObject);
|
||||
NS_IMETHOD GetTruthValue(PRBool *aTruthValue);
|
||||
|
||||
// nsRDFSingletonAssertionCursor methods:
|
||||
|
||||
// node == subject if inverse == false
|
||||
// node == target if inverse == true
|
||||
// value computed when accessed from datasource
|
||||
nsRDFSingletonAssertionCursor(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFNode* node,
|
||||
nsIRDFResource* predicate,
|
||||
PRBool inverse = PR_FALSE,
|
||||
PRBool truthValue = PR_TRUE);
|
||||
virtual ~nsRDFSingletonAssertionCursor();
|
||||
|
||||
protected:
|
||||
nsIRDFDataSource* mDataSource;
|
||||
nsIRDFNode* mNode;
|
||||
nsIRDFResource* mPredicate;
|
||||
nsIRDFNode* mValue;
|
||||
PRBool mInverse;
|
||||
PRBool mTruthValue;
|
||||
PRBool mConsumed;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class NS_RDF nsRDFArrayArcsCursor : public nsRDFArrayCursor
|
||||
{
|
||||
public:
|
||||
// nsRDFArrayArcsCursor methods:
|
||||
nsRDFArrayArcsCursor(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFNode* node,
|
||||
nsISupportsArray* arcs);
|
||||
virtual ~nsRDFArrayArcsCursor();
|
||||
|
||||
protected:
|
||||
nsresult GetLabel(nsIRDFResource** aPredicate) {
|
||||
return GetValue((nsIRDFNode**)aPredicate);
|
||||
}
|
||||
|
||||
nsresult GetNode(nsIRDFNode* *result) {
|
||||
*result = mNode;
|
||||
NS_ADDREF(mNode);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIRDFNode* mNode;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class NS_RDF nsRDFArrayArcsOutCursor : public nsRDFArrayArcsCursor,
|
||||
public nsIRDFArcsOutCursor
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// nsIRDFCursor methods:
|
||||
NS_IMETHOD Advance(void) {
|
||||
return nsRDFArrayArcsCursor::Advance();
|
||||
}
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource) {
|
||||
return nsRDFArrayArcsCursor::GetDataSource(aDataSource);
|
||||
}
|
||||
NS_IMETHOD GetValue(nsIRDFNode** aValue) {
|
||||
return nsRDFArrayArcsCursor::GetValue(aValue);
|
||||
}
|
||||
|
||||
// nsIRDFArcsOutCursor methods:
|
||||
NS_IMETHOD GetSource(nsIRDFResource** aSubject) {
|
||||
return GetNode((nsIRDFNode**)aSubject);
|
||||
}
|
||||
NS_IMETHOD GetLabel(nsIRDFResource** aPredicate) {
|
||||
return nsRDFArrayArcsCursor::GetLabel(aPredicate);
|
||||
}
|
||||
|
||||
// nsRDFArrayArcsOutCursor methods:
|
||||
nsRDFArrayArcsOutCursor(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* subject,
|
||||
nsISupportsArray* arcs)
|
||||
: nsRDFArrayArcsCursor(aDataSource, subject, arcs) {}
|
||||
virtual ~nsRDFArrayArcsOutCursor() {}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class NS_RDF nsRDFArrayArcsInCursor : public nsRDFArrayArcsCursor,
|
||||
public nsIRDFArcsInCursor
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// nsIRDFCursor methods:
|
||||
NS_IMETHOD Advance(void) {
|
||||
return nsRDFArrayArcsCursor::Advance();
|
||||
}
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource) {
|
||||
return nsRDFArrayArcsCursor::GetDataSource(aDataSource);
|
||||
}
|
||||
NS_IMETHOD GetValue(nsIRDFNode** aValue) {
|
||||
return nsRDFArrayArcsCursor::GetValue(aValue);
|
||||
}
|
||||
|
||||
// nsIRDFArcsInCursor methods:
|
||||
NS_IMETHOD GetTarget(nsIRDFNode** aObject) {
|
||||
return GetNode(aObject);
|
||||
}
|
||||
NS_IMETHOD GetLabel(nsIRDFResource** aPredicate) {
|
||||
return nsRDFArrayArcsCursor::GetLabel(aPredicate);
|
||||
}
|
||||
|
||||
// nsRDFArrayArcsInCursor methods:
|
||||
nsRDFArrayArcsInCursor(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFNode* object,
|
||||
nsISupportsArray* arcs)
|
||||
: nsRDFArrayArcsCursor(aDataSource, object, arcs) {}
|
||||
virtual ~nsRDFArrayArcsInCursor() {}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class NS_RDF nsRDFEnumeratorCursor : public nsIRDFCursor
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIRDFCursor methods:
|
||||
NS_IMETHOD Advance(void);
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource);
|
||||
NS_IMETHOD GetValue(nsIRDFNode** aValue);
|
||||
|
||||
// nsRDFEnumeratorCursor methods:
|
||||
nsRDFEnumeratorCursor(nsIRDFDataSource* aDataSource,
|
||||
nsIEnumerator* valueEnumerator);
|
||||
virtual ~nsRDFEnumeratorCursor(void);
|
||||
|
||||
protected:
|
||||
nsIRDFDataSource* mDataSource;
|
||||
nsIEnumerator* mEnum;
|
||||
PRBool mStarted;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class NS_RDF nsRDFEnumeratorAssertionCursor : public nsRDFEnumeratorCursor,
|
||||
public nsIRDFAssertionCursor
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// nsIRDFCursor methods:
|
||||
NS_IMETHOD Advance(void) {
|
||||
return nsRDFEnumeratorCursor::Advance();
|
||||
}
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource) {
|
||||
return nsRDFEnumeratorCursor::GetDataSource(aDataSource);
|
||||
}
|
||||
NS_IMETHOD GetValue(nsIRDFNode** aValue) {
|
||||
return nsRDFEnumeratorCursor::GetValue(aValue);
|
||||
}
|
||||
|
||||
// nsIRDFAssertionCursor methods:
|
||||
NS_IMETHOD GetSource(nsIRDFResource* *aSubject);
|
||||
NS_IMETHOD GetLabel(nsIRDFResource* *aPredicate);
|
||||
NS_IMETHOD GetTarget(nsIRDFNode* *aObject);
|
||||
NS_IMETHOD GetTruthValue(PRBool *aTruthValue);
|
||||
|
||||
// nsRDFEnumeratorAssertionCursor methods:
|
||||
nsRDFEnumeratorAssertionCursor(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* subject,
|
||||
nsIRDFResource* predicate,
|
||||
nsIEnumerator* objectsEnumerator,
|
||||
PRBool truthValue = PR_TRUE);
|
||||
virtual ~nsRDFEnumeratorAssertionCursor();
|
||||
|
||||
protected:
|
||||
nsIRDFResource* mSubject;
|
||||
nsIRDFResource* mPredicate;
|
||||
PRBool mTruthValue;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class NS_RDF nsRDFEnumeratorArcsCursor : public nsRDFEnumeratorCursor
|
||||
{
|
||||
public:
|
||||
// nsRDFEnumeratorArcsOutCursor methods:
|
||||
nsRDFEnumeratorArcsCursor(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFNode* node,
|
||||
nsIEnumerator* arcs);
|
||||
virtual ~nsRDFEnumeratorArcsCursor();
|
||||
|
||||
protected:
|
||||
nsresult GetLabel(nsIRDFResource** aPredicate) {
|
||||
return GetValue((nsIRDFNode**)aPredicate);
|
||||
}
|
||||
|
||||
nsresult GetNode(nsIRDFNode* *result) {
|
||||
*result = mNode;
|
||||
NS_ADDREF(mNode);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIRDFNode* mNode;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class NS_RDF nsRDFEnumeratorArcsOutCursor : public nsRDFEnumeratorArcsCursor,
|
||||
public nsIRDFArcsOutCursor
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// nsIRDFCursor methods:
|
||||
NS_IMETHOD Advance(void) {
|
||||
return nsRDFEnumeratorArcsCursor::Advance();
|
||||
}
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource) {
|
||||
return nsRDFEnumeratorArcsCursor::GetDataSource(aDataSource);
|
||||
}
|
||||
NS_IMETHOD GetValue(nsIRDFNode** aValue) {
|
||||
return nsRDFEnumeratorArcsCursor::GetValue(aValue);
|
||||
}
|
||||
|
||||
// nsIRDFArcsOutCursor methods:
|
||||
NS_IMETHOD GetSource(nsIRDFResource** aSubject) {
|
||||
return GetNode((nsIRDFNode**)aSubject);
|
||||
}
|
||||
NS_IMETHOD GetLabel(nsIRDFResource** aPredicate) {
|
||||
return nsRDFEnumeratorArcsCursor::GetLabel(aPredicate);
|
||||
}
|
||||
|
||||
// nsRDFEnumeratorArcsOutCursor methods:
|
||||
nsRDFEnumeratorArcsOutCursor(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* subject,
|
||||
nsIEnumerator* arcs)
|
||||
: nsRDFEnumeratorArcsCursor(aDataSource, subject, arcs) {}
|
||||
virtual ~nsRDFEnumeratorArcsOutCursor() {}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class NS_RDF nsRDFEnumeratorArcsInCursor : public nsRDFEnumeratorArcsCursor,
|
||||
public nsIRDFArcsInCursor
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// nsIRDFCursor methods:
|
||||
NS_IMETHOD Advance(void) {
|
||||
return nsRDFEnumeratorArcsCursor::Advance();
|
||||
}
|
||||
NS_IMETHOD GetDataSource(nsIRDFDataSource** aDataSource) {
|
||||
return nsRDFEnumeratorArcsCursor::GetDataSource(aDataSource);
|
||||
}
|
||||
NS_IMETHOD GetValue(nsIRDFNode** aValue) {
|
||||
return nsRDFEnumeratorArcsCursor::GetValue(aValue);
|
||||
}
|
||||
|
||||
// nsIRDFArcsInCursor methods:
|
||||
NS_IMETHOD GetTarget(nsIRDFNode** aObject) {
|
||||
return GetNode(aObject);
|
||||
}
|
||||
NS_IMETHOD GetLabel(nsIRDFResource** aPredicate) {
|
||||
return nsRDFEnumeratorArcsCursor::GetLabel(aPredicate);
|
||||
}
|
||||
|
||||
// nsRDFEnumeratorArcsInCursor methods:
|
||||
nsRDFEnumeratorArcsInCursor(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFNode* object,
|
||||
nsIEnumerator* arcs)
|
||||
: nsRDFEnumeratorArcsCursor(aDataSource, object, arcs) {}
|
||||
virtual ~nsRDFEnumeratorArcsInCursor() {}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif /* nsRDFCursorUtils_h__ */
|
@ -27,7 +27,6 @@ include $(topsrcdir)/config/config.mk
|
||||
LIBRARY_NAME = rdfutil_s
|
||||
|
||||
CPPSRCS = \
|
||||
nsRDFCursorUtils.cpp \
|
||||
nsRDFResource.cpp \
|
||||
$(NULL)
|
||||
|
||||
|
@ -23,7 +23,6 @@ MODULE=rdfutil
|
||||
LIBRARY_NAME=rdfutil_s
|
||||
|
||||
CPP_OBJS=\
|
||||
.\$(OBJDIR)\nsRDFCursorUtils.obj \
|
||||
.\$(OBJDIR)\nsRDFResource.obj \
|
||||
$(NULL)
|
||||
|
||||
|
@ -1,402 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsRDFCursorUtils.h"
|
||||
#include "nsIRDFDataSource.h"
|
||||
#include "nscore.h"
|
||||
|
||||
nsRDFArrayCursor::nsRDFArrayCursor(nsIRDFDataSource* aDataSource,
|
||||
nsISupportsArray* valueArray)
|
||||
: nsSupportsArrayEnumerator(valueArray), mDataSource(aDataSource),
|
||||
mStarted(PR_FALSE)
|
||||
{
|
||||
NS_IF_ADDREF(mDataSource);
|
||||
}
|
||||
|
||||
nsRDFArrayCursor::~nsRDFArrayCursor(void)
|
||||
{
|
||||
NS_IF_RELEASE(mDataSource);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED(nsRDFArrayCursor,
|
||||
nsSupportsArrayEnumerator,
|
||||
nsIRDFCursor);
|
||||
|
||||
NS_IMETHODIMP nsRDFArrayCursor::Advance(void)
|
||||
{
|
||||
if (!mStarted) {
|
||||
mStarted = PR_TRUE;
|
||||
nsresult rv = First();
|
||||
if (NS_FAILED(rv)) return NS_RDF_CURSOR_EMPTY;
|
||||
}
|
||||
else {
|
||||
nsresult rv = Next();
|
||||
if (NS_FAILED(rv)) return NS_RDF_CURSOR_EMPTY;
|
||||
}
|
||||
return IsDone() == NS_OK ? NS_RDF_CURSOR_EMPTY : NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRDFArrayCursor::GetDataSource(nsIRDFDataSource** aDataSource)
|
||||
{
|
||||
*aDataSource = mDataSource;
|
||||
NS_IF_ADDREF(mDataSource);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRDFArrayCursor::GetValue(nsIRDFNode** aValue)
|
||||
{
|
||||
return CurrentItem((nsISupports**)aValue);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsRDFArrayAssertionCursor::nsRDFArrayAssertionCursor(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* subject,
|
||||
nsIRDFResource* predicate,
|
||||
nsISupportsArray* objectsArray,
|
||||
PRBool truthValue)
|
||||
: nsRDFArrayCursor(aDataSource, objectsArray),
|
||||
mSubject(subject), mPredicate(predicate), mTruthValue(truthValue)
|
||||
{
|
||||
NS_ADDREF(mSubject);
|
||||
NS_ADDREF(mPredicate);
|
||||
}
|
||||
|
||||
nsRDFArrayAssertionCursor::~nsRDFArrayAssertionCursor()
|
||||
{
|
||||
NS_RELEASE(mSubject);
|
||||
NS_RELEASE(mPredicate);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED(nsRDFArrayAssertionCursor,
|
||||
nsRDFArrayCursor,
|
||||
nsIRDFAssertionCursor);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFArrayAssertionCursor::GetSource(nsIRDFResource* *aSubject)
|
||||
{
|
||||
*aSubject = mSubject;
|
||||
NS_ADDREF(mSubject);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRDFArrayAssertionCursor::GetLabel(nsIRDFResource* *aPredicate)
|
||||
{
|
||||
*aPredicate = mPredicate;
|
||||
NS_ADDREF(mPredicate);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRDFArrayAssertionCursor::GetTarget(nsIRDFNode* *aObject)
|
||||
{
|
||||
return nsRDFArrayCursor::GetValue(aObject);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRDFArrayAssertionCursor::GetTruthValue(PRBool *aTruthValue)
|
||||
{
|
||||
*aTruthValue = mTruthValue;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsRDFSingletonAssertionCursor::nsRDFSingletonAssertionCursor(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFNode* node,
|
||||
nsIRDFResource* predicate,
|
||||
PRBool inverse,
|
||||
PRBool truthValue)
|
||||
: mDataSource(aDataSource), mNode(node), mPredicate(predicate),
|
||||
mValue(nsnull), mInverse(inverse), mTruthValue(truthValue), mConsumed(PR_FALSE)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_ADDREF(mDataSource);
|
||||
NS_ADDREF(mNode);
|
||||
NS_ADDREF(mPredicate);
|
||||
}
|
||||
|
||||
nsRDFSingletonAssertionCursor::~nsRDFSingletonAssertionCursor()
|
||||
{
|
||||
NS_RELEASE(mDataSource);
|
||||
NS_RELEASE(mNode);
|
||||
NS_RELEASE(mPredicate);
|
||||
NS_IF_RELEASE(mValue);
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsRDFSingletonAssertionCursor);
|
||||
NS_IMPL_RELEASE(nsRDFSingletonAssertionCursor);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFSingletonAssertionCursor::QueryInterface(REFNSIID iid, void** result)
|
||||
{
|
||||
if (!result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (iid.Equals(nsIRDFAssertionCursor::GetIID()) ||
|
||||
iid.Equals(nsIRDFCursor::GetIID()) ||
|
||||
iid.Equals(::nsISupports::GetIID())) {
|
||||
*result = NS_STATIC_CAST(nsIRDFAssertionCursor*, this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRDFSingletonAssertionCursor::Advance(void)
|
||||
{
|
||||
if (!mConsumed) {
|
||||
mConsumed = PR_TRUE;
|
||||
return NS_RDF_CURSOR_EMPTY;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRDFSingletonAssertionCursor::GetDataSource(nsIRDFDataSource** aDataSource)
|
||||
{
|
||||
*aDataSource = mDataSource;
|
||||
NS_ADDREF(mDataSource);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRDFSingletonAssertionCursor::GetValue(nsIRDFNode** aValue)
|
||||
{
|
||||
if (mConsumed)
|
||||
return NS_RDF_CURSOR_EMPTY;
|
||||
if (mValue == nsnull) {
|
||||
if (mInverse)
|
||||
return mDataSource->GetSource(mPredicate, mNode, mTruthValue,
|
||||
(nsIRDFResource**)&mValue);
|
||||
else
|
||||
return mDataSource->GetTarget(NS_STATIC_CAST(nsIRDFResource*, mNode),
|
||||
mPredicate, mTruthValue, &mValue);
|
||||
}
|
||||
*aValue = mValue;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRDFSingletonAssertionCursor::GetSource(nsIRDFResource* *aSubject)
|
||||
{
|
||||
if (mConsumed)
|
||||
return NS_RDF_CURSOR_EMPTY;
|
||||
if (mInverse) {
|
||||
return GetValue((nsIRDFNode**)aSubject);
|
||||
}
|
||||
else {
|
||||
*aSubject = NS_STATIC_CAST(nsIRDFResource*, mNode);
|
||||
NS_ADDREF(mNode);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRDFSingletonAssertionCursor::GetLabel(nsIRDFResource* *aPredicate)
|
||||
{
|
||||
if (mConsumed)
|
||||
return NS_RDF_CURSOR_EMPTY;
|
||||
*aPredicate = mPredicate;
|
||||
NS_ADDREF(mPredicate);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRDFSingletonAssertionCursor::GetTarget(nsIRDFNode* *aObject)
|
||||
{
|
||||
if (mConsumed)
|
||||
return NS_RDF_CURSOR_EMPTY;
|
||||
if (mInverse) {
|
||||
*aObject = mNode;
|
||||
NS_ADDREF(mNode);
|
||||
return NS_OK;
|
||||
}
|
||||
else {
|
||||
return GetValue(aObject);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRDFSingletonAssertionCursor::GetTruthValue(PRBool *aTruthValue)
|
||||
{
|
||||
if (mConsumed)
|
||||
return NS_RDF_CURSOR_EMPTY;
|
||||
*aTruthValue = mTruthValue;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsRDFArrayArcsCursor::nsRDFArrayArcsCursor(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFNode* node,
|
||||
nsISupportsArray* arcs)
|
||||
: nsRDFArrayCursor(aDataSource, arcs), mNode(node)
|
||||
{
|
||||
NS_ADDREF(mNode);
|
||||
}
|
||||
|
||||
nsRDFArrayArcsCursor::~nsRDFArrayArcsCursor()
|
||||
{
|
||||
NS_RELEASE(mNode);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED(nsRDFArrayArcsOutCursor,
|
||||
nsRDFArrayArcsCursor,
|
||||
nsIRDFArcsOutCursor);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED(nsRDFArrayArcsInCursor,
|
||||
nsRDFArrayArcsCursor,
|
||||
nsIRDFArcsInCursor);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsRDFEnumeratorCursor::nsRDFEnumeratorCursor(nsIRDFDataSource* aDataSource,
|
||||
nsIEnumerator* valueEnumerator)
|
||||
: mDataSource(aDataSource), mEnum(valueEnumerator), mStarted(PR_FALSE)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
NS_IF_ADDREF(mEnum);
|
||||
NS_IF_ADDREF(mDataSource);
|
||||
}
|
||||
|
||||
nsRDFEnumeratorCursor::~nsRDFEnumeratorCursor(void)
|
||||
{
|
||||
NS_IF_RELEASE(mEnum);
|
||||
NS_IF_RELEASE(mDataSource);
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsRDFEnumeratorCursor);
|
||||
NS_IMPL_RELEASE(nsRDFEnumeratorCursor);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFEnumeratorCursor::QueryInterface(REFNSIID iid, void** result)
|
||||
{
|
||||
if (!result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (iid.Equals(nsIRDFCursor::GetIID()) ||
|
||||
iid.Equals(::nsISupports::GetIID())) {
|
||||
*result = NS_STATIC_CAST(nsIRDFCursor*, this);
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRDFEnumeratorCursor::Advance(void)
|
||||
{
|
||||
if (!mStarted) {
|
||||
mStarted = PR_TRUE;
|
||||
nsresult rv = mEnum->First();
|
||||
if (NS_FAILED(rv)) return NS_RDF_CURSOR_EMPTY;
|
||||
}
|
||||
else {
|
||||
nsresult rv = mEnum->Next();
|
||||
if (NS_FAILED(rv)) return NS_RDF_CURSOR_EMPTY;
|
||||
}
|
||||
return mEnum->IsDone() == NS_OK ? NS_RDF_CURSOR_EMPTY : NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRDFEnumeratorCursor::GetDataSource(nsIRDFDataSource** aDataSource)
|
||||
{
|
||||
*aDataSource = mDataSource;
|
||||
NS_IF_ADDREF(mDataSource);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRDFEnumeratorCursor::GetValue(nsIRDFNode** aValue)
|
||||
{
|
||||
return mEnum->CurrentItem((nsISupports**)aValue);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsRDFEnumeratorAssertionCursor::nsRDFEnumeratorAssertionCursor(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFResource* subject,
|
||||
nsIRDFResource* predicate,
|
||||
nsIEnumerator* objectsEnumerator,
|
||||
PRBool truthValue)
|
||||
: nsRDFEnumeratorCursor(aDataSource, objectsEnumerator),
|
||||
mSubject(subject), mPredicate(predicate), mTruthValue(truthValue)
|
||||
{
|
||||
NS_ADDREF(mSubject);
|
||||
NS_ADDREF(mPredicate);
|
||||
}
|
||||
|
||||
nsRDFEnumeratorAssertionCursor::~nsRDFEnumeratorAssertionCursor()
|
||||
{
|
||||
NS_RELEASE(mSubject);
|
||||
NS_RELEASE(mPredicate);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED(nsRDFEnumeratorAssertionCursor,
|
||||
nsRDFEnumeratorCursor,
|
||||
nsIRDFAssertionCursor);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFEnumeratorAssertionCursor::GetSource(nsIRDFResource* *aSubject)
|
||||
{
|
||||
*aSubject = mSubject;
|
||||
NS_ADDREF(mSubject);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRDFEnumeratorAssertionCursor::GetLabel(nsIRDFResource* *aPredicate)
|
||||
{
|
||||
*aPredicate = mPredicate;
|
||||
NS_ADDREF(mPredicate);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRDFEnumeratorAssertionCursor::GetTarget(nsIRDFNode* *aObject)
|
||||
{
|
||||
return nsRDFEnumeratorCursor::GetValue(aObject);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRDFEnumeratorAssertionCursor::GetTruthValue(PRBool *aTruthValue)
|
||||
{
|
||||
*aTruthValue = mTruthValue;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsRDFEnumeratorArcsCursor::nsRDFEnumeratorArcsCursor(nsIRDFDataSource* aDataSource,
|
||||
nsIRDFNode* node,
|
||||
nsIEnumerator* arcs)
|
||||
: nsRDFEnumeratorCursor(aDataSource, arcs), mNode(node)
|
||||
{
|
||||
NS_ADDREF(mNode);
|
||||
}
|
||||
|
||||
nsRDFEnumeratorArcsCursor::~nsRDFEnumeratorArcsCursor()
|
||||
{
|
||||
NS_RELEASE(mNode);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED(nsRDFEnumeratorArcsOutCursor,
|
||||
nsRDFEnumeratorArcsCursor,
|
||||
nsIRDFArcsOutCursor);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED(nsRDFEnumeratorArcsInCursor,
|
||||
nsRDFEnumeratorArcsCursor,
|
||||
nsIRDFArcsInCursor);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
Loading…
Reference in New Issue
Block a user