зеркало из https://github.com/mozilla/pjs.git
Added nsRDFResource -- basic resource implementation to subclass.
This commit is contained in:
Родитель
0485f738af
Коммит
fa4dc71bd1
|
@ -36,6 +36,7 @@ EXPORTS = \
|
|||
nsIRDFService.h \
|
||||
nsIRDFXMLDataSource.h \
|
||||
nsIRDFXMLSource.h \
|
||||
nsRDFResource.h \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
||||
|
|
|
@ -33,6 +33,7 @@ EXPORTS=\
|
|||
nsIRDFService.h \
|
||||
nsIRDFXMLDataSource.h \
|
||||
nsIRDFXMLSource.h \
|
||||
nsRDFResource.h \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)/config/rules.mak>
|
||||
|
|
|
@ -184,7 +184,7 @@ public:
|
|||
* Request that a data source write it's contents out to
|
||||
* permanent storage if applicable.
|
||||
*/
|
||||
NS_IMETHOD Flush() = 0;
|
||||
NS_IMETHOD Flush(void) = 0;
|
||||
|
||||
/**
|
||||
* Determine whether the specified command is enabled for the
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsRDFResource_h__
|
||||
#define nsRDFResource_h__
|
||||
|
||||
#include "nsIRDFNode.h"
|
||||
|
||||
/**
|
||||
* This simple base class implements nsIRDFResource, and can be used as a
|
||||
* superclass for more sophisticated resource implementations.
|
||||
*/
|
||||
class nsRDFResource : public nsIRDFResource {
|
||||
public:
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIRDFNode methods:
|
||||
NS_IMETHOD EqualsNode(nsIRDFNode* node, PRBool* result) const;
|
||||
|
||||
// nsIRDFResource methods:
|
||||
NS_IMETHOD GetValue(const char* *uri) const;
|
||||
NS_IMETHOD EqualsResource(const nsIRDFResource* resource, PRBool* result) const;
|
||||
NS_IMETHOD EqualsString(const char* uri, PRBool* result) const;
|
||||
|
||||
// nsRDFResource methods:
|
||||
nsRDFResource(const char* uri);
|
||||
virtual ~nsRDFResource(void);
|
||||
|
||||
protected:
|
||||
const char* mURI;
|
||||
|
||||
};
|
||||
|
||||
#endif // nsRDFResource_h__
|
|
@ -37,6 +37,7 @@ CPPSRCS = \
|
|||
nsRDFService.cpp \
|
||||
nsRDFXMLDataSource.cpp \
|
||||
rdfutil.cpp \
|
||||
nsRDFResource.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
|
|
|
@ -26,10 +26,11 @@ CPP_OBJS=\
|
|||
.\$(OBJDIR)\nsEmptyCursor.obj \
|
||||
.\$(OBJDIR)\nsInMemoryDataSource.obj \
|
||||
.\$(OBJDIR)\nsRDFContentSink.obj \
|
||||
.\$(OBJDIR)\nsXULContentSink.obj \
|
||||
.\$(OBJDIR)\nsXULContentSink.obj \
|
||||
.\$(OBJDIR)\nsRDFService.obj \
|
||||
.\$(OBJDIR)\nsRDFXMLDataSource.obj \
|
||||
.\$(OBJDIR)\rdfutil.obj \
|
||||
.\$(OBJDIR)\nsRDFResource.obj \
|
||||
$(NULL)
|
||||
|
||||
LINCS= -I$(PUBLIC)\rdf \
|
||||
|
|
|
@ -0,0 +1,117 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsRDFResource.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
|
||||
static NS_DEFINE_IID(kIRDFNodeIID, NS_IRDFNODE_IID);
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsRDFResource::nsRDFResource(const char* uri)
|
||||
: mURI(uri)
|
||||
{
|
||||
}
|
||||
|
||||
nsRDFResource::~nsRDFResource(void)
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsRDFResource)
|
||||
NS_IMPL_RELEASE(nsRDFResource)
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsRDFResource::QueryInterface(REFNSIID iid, void** result)
|
||||
{
|
||||
if (! result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*result = nsnull;
|
||||
if (iid.Equals(kIRDFResourceIID) ||
|
||||
iid.Equals(kIRDFNodeIID) ||
|
||||
iid.Equals(kISupportsIID)) {
|
||||
*result = NS_STATIC_CAST(nsIRDFResource*, this);
|
||||
}
|
||||
|
||||
if (*result != nsnull) {
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIRDFNode methods:
|
||||
|
||||
NS_METHOD
|
||||
nsRDFResource::EqualsNode(nsIRDFNode* node, PRBool* result) const
|
||||
{
|
||||
nsresult rv;
|
||||
nsIRDFResource* resource;
|
||||
if (NS_SUCCEEDED(node->QueryInterface(kIRDFResourceIID, (void**) &resource))) {
|
||||
rv = EqualsResource(resource, result);
|
||||
NS_RELEASE(resource);
|
||||
}
|
||||
else {
|
||||
*result = PR_FALSE;
|
||||
rv = NS_OK;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIRDFResource methods:
|
||||
|
||||
NS_METHOD
|
||||
nsRDFResource::GetValue(const char* *uri) const
|
||||
{
|
||||
if (!uri)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
*uri = mURI;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsRDFResource::EqualsResource(const nsIRDFResource* resource, PRBool* result) const
|
||||
{
|
||||
if (!resource || !result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
const char *uri;
|
||||
if (NS_SUCCEEDED(resource->GetValue(&uri))) {
|
||||
return EqualsString(uri, result) ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsRDFResource::EqualsString(const char* uri, PRBool* result) const
|
||||
{
|
||||
if (!uri || !result)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
*result = nsCRT::strcmp(uri, mURI) == 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
Загрузка…
Ссылка в новой задаче