2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1998-12-24 08:07:14 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
1999-01-06 00:57:59 +03:00
|
|
|
An implementation for an NGLayout-style content sink that knows how
|
|
|
|
to build an RDF content model from XML-serialized RDF.
|
1998-12-24 08:07:14 +03:00
|
|
|
|
1999-06-09 12:29:51 +04:00
|
|
|
For more information on the RDF/XML syntax,
|
|
|
|
see http://www.w3.org/TR/REC-rdf-syntax/
|
1998-12-24 08:07:14 +03:00
|
|
|
|
1999-06-09 12:29:51 +04:00
|
|
|
This code is based on the final W3C Recommendation,
|
|
|
|
http://www.w3.org/TR/1999/REC-rdf-syntax-19990222.
|
1998-12-24 08:07:14 +03:00
|
|
|
|
|
|
|
Open Issues ------------------
|
|
|
|
|
|
|
|
1) factoring code with nsXMLContentSink - There's some amount of
|
|
|
|
common code between this and the HTML content sink. This will
|
|
|
|
increase as we support more and more HTML elements. How can code
|
|
|
|
from XML/HTML be factored?
|
|
|
|
|
1999-06-09 12:29:51 +04:00
|
|
|
2) We don't support the `parseType' attribute on the Description
|
|
|
|
tag; therefore, it is impossible to "inline" raw XML in this
|
|
|
|
implemenation.
|
1998-12-24 08:07:14 +03:00
|
|
|
|
1999-06-09 12:29:51 +04:00
|
|
|
3) We don't build the reifications at parse time due to the
|
|
|
|
footprint overhead it would incur for large RDF documents. (It
|
|
|
|
may be possible to attach a "reification" wrapper datasource that
|
|
|
|
would present this information at query-time.) Because of this,
|
|
|
|
the `bagID' attribute is not processed correctly.
|
1998-12-24 08:07:14 +03:00
|
|
|
|
1999-06-09 12:29:51 +04:00
|
|
|
4) No attempt is made to `resolve URIs' to a canonical form (the
|
|
|
|
specification hints that an implementation should do this). This
|
|
|
|
is omitted for the obvious reason that we can ill afford to
|
|
|
|
resolve each URI reference.
|
1998-12-24 08:07:14 +03:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
1999-04-17 04:10:18 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2006-03-07 18:43:26 +03:00
|
|
|
#include "nsInterfaceHashtable.h"
|
1999-01-14 13:55:08 +03:00
|
|
|
#include "nsIContentSink.h"
|
1999-04-27 09:54:18 +04:00
|
|
|
#include "nsIRDFContainer.h"
|
1999-05-05 07:09:12 +04:00
|
|
|
#include "nsIRDFContainerUtils.h"
|
1999-01-14 13:55:08 +03:00
|
|
|
#include "nsIRDFContentSink.h"
|
1998-12-24 08:07:14 +03:00
|
|
|
#include "nsIRDFNode.h"
|
1999-01-05 06:53:15 +03:00
|
|
|
#include "nsIRDFService.h"
|
1999-06-24 04:22:58 +04:00
|
|
|
#include "nsIRDFXMLSink.h"
|
1998-12-24 08:07:14 +03:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIURL.h"
|
1999-01-14 13:55:08 +03:00
|
|
|
#include "nsIXMLContentSink.h"
|
|
|
|
#include "nsRDFCID.h"
|
2009-04-22 12:43:15 +04:00
|
|
|
#include "nsTArray.h"
|
1999-04-03 00:46:41 +04:00
|
|
|
#include "nsXPIDLString.h"
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
1999-04-21 04:09:41 +04:00
|
|
|
#include "rdf.h"
|
1998-12-24 08:07:14 +03:00
|
|
|
#include "rdfutil.h"
|
2000-12-13 00:58:13 +03:00
|
|
|
#include "nsReadableUtils.h"
|
2002-01-09 04:37:50 +03:00
|
|
|
#include "nsIExpatSink.h"
|
2002-05-15 22:55:21 +04:00
|
|
|
#include "nsCRT.h"
|
2002-07-25 22:31:10 +04:00
|
|
|
#include "nsIAtom.h"
|
2003-04-16 02:19:01 +04:00
|
|
|
#include "nsStaticAtom.h"
|
2006-08-25 20:34:57 +04:00
|
|
|
#include "nsIScriptError.h"
|
2009-06-24 01:22:16 +04:00
|
|
|
#include "nsIDTD.h"
|
1999-01-05 11:44:40 +03:00
|
|
|
|
2011-10-11 09:50:08 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
|
1999-02-17 14:09:57 +03:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
1998-12-24 08:07:14 +03:00
|
|
|
|
2002-01-15 04:56:15 +03:00
|
|
|
enum RDFContentSinkState {
|
1999-01-14 13:55:08 +03:00
|
|
|
eRDFContentSinkState_InProlog,
|
|
|
|
eRDFContentSinkState_InDocumentElement,
|
|
|
|
eRDFContentSinkState_InDescriptionElement,
|
|
|
|
eRDFContentSinkState_InContainerElement,
|
|
|
|
eRDFContentSinkState_InPropertyElement,
|
|
|
|
eRDFContentSinkState_InMemberElement,
|
|
|
|
eRDFContentSinkState_InEpilog
|
2002-01-15 04:56:15 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
enum RDFContentSinkParseMode {
|
|
|
|
eRDFContentSinkParseMode_Resource,
|
|
|
|
eRDFContentSinkParseMode_Literal,
|
|
|
|
eRDFContentSinkParseMode_Int,
|
|
|
|
eRDFContentSinkParseMode_Date
|
|
|
|
};
|
1999-01-14 13:55:08 +03:00
|
|
|
|
2003-09-15 08:20:20 +04:00
|
|
|
typedef
|
|
|
|
NS_STDCALL_FUNCPROTO(nsresult,
|
|
|
|
nsContainerTestFn,
|
|
|
|
nsIRDFContainerUtils, IsAlt,
|
2011-09-29 10:19:26 +04:00
|
|
|
(nsIRDFDataSource*, nsIRDFResource*, bool*));
|
2003-09-15 08:20:20 +04:00
|
|
|
|
|
|
|
typedef
|
|
|
|
NS_STDCALL_FUNCPROTO(nsresult,
|
|
|
|
nsMakeContainerFn,
|
|
|
|
nsIRDFContainerUtils, MakeAlt,
|
|
|
|
(nsIRDFDataSource*, nsIRDFResource*, nsIRDFContainer**));
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
class RDFContentSinkImpl : public nsIRDFContentSink,
|
|
|
|
public nsIExpatSink
|
1999-01-14 13:55:08 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
RDFContentSinkImpl();
|
|
|
|
|
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS
|
2002-01-09 04:37:50 +03:00
|
|
|
NS_DECL_NSIEXPATSINK
|
1999-01-14 13:55:08 +03:00
|
|
|
|
|
|
|
// nsIContentSink
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD WillParse(void) override;
|
|
|
|
NS_IMETHOD WillBuildModel(nsDTDMode aDTDMode) override;
|
|
|
|
NS_IMETHOD DidBuildModel(bool aTerminated) override;
|
|
|
|
NS_IMETHOD WillInterrupt(void) override;
|
|
|
|
NS_IMETHOD WillResume(void) override;
|
|
|
|
NS_IMETHOD SetParser(nsParserBase* aParser) override;
|
|
|
|
virtual void FlushPendingNotifications(mozFlushType aType) override { }
|
|
|
|
NS_IMETHOD SetDocumentCharset(nsACString& aCharset) override { return NS_OK; }
|
|
|
|
virtual nsISupports *GetTarget() override { return nullptr; }
|
1999-01-14 13:55:08 +03:00
|
|
|
|
|
|
|
// nsIRDFContentSink
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD Init(nsIURI* aURL) override;
|
|
|
|
NS_IMETHOD SetDataSource(nsIRDFDataSource* aDataSource) override;
|
|
|
|
NS_IMETHOD GetDataSource(nsIRDFDataSource*& aDataSource) override;
|
1999-01-14 13:55:08 +03:00
|
|
|
|
1999-04-17 04:10:18 +04:00
|
|
|
// pseudo constants
|
2012-08-22 19:56:38 +04:00
|
|
|
static int32_t gRefCnt;
|
1999-04-17 04:10:18 +04:00
|
|
|
static nsIRDFService* gRDFService;
|
1999-04-27 09:54:18 +04:00
|
|
|
static nsIRDFContainerUtils* gRDFContainerUtils;
|
1999-04-17 04:10:18 +04:00
|
|
|
static nsIRDFResource* kRDF_type;
|
1999-09-30 00:25:41 +04:00
|
|
|
static nsIRDFResource* kRDF_instanceOf; // XXX should be RDF:type
|
|
|
|
static nsIRDFResource* kRDF_Alt;
|
|
|
|
static nsIRDFResource* kRDF_Bag;
|
|
|
|
static nsIRDFResource* kRDF_Seq;
|
|
|
|
static nsIRDFResource* kRDF_nextVal;
|
1999-04-17 04:10:18 +04:00
|
|
|
|
2010-03-08 18:44:59 +03:00
|
|
|
#define RDF_ATOM(name_, value_) static nsIAtom* name_;
|
|
|
|
#include "nsRDFContentSinkAtomList.h"
|
|
|
|
#undef RDF_ATOM
|
2003-03-12 11:26:03 +03:00
|
|
|
|
|
|
|
typedef struct ContainerInfo {
|
|
|
|
nsIRDFResource** mType;
|
|
|
|
nsContainerTestFn mTestFn;
|
|
|
|
nsMakeContainerFn mMakeFn;
|
|
|
|
} ContainerInfo;
|
|
|
|
|
1999-09-30 00:25:41 +04:00
|
|
|
protected:
|
2014-07-01 02:11:50 +04:00
|
|
|
virtual ~RDFContentSinkImpl();
|
|
|
|
|
1999-01-14 13:55:08 +03:00
|
|
|
// Text management
|
2002-01-15 04:56:15 +03:00
|
|
|
void ParseText(nsIRDFNode **aResult);
|
|
|
|
|
2007-06-27 08:22:35 +04:00
|
|
|
nsresult FlushText();
|
2014-01-04 19:02:17 +04:00
|
|
|
nsresult AddText(const char16_t* aText, int32_t aLength);
|
2002-01-09 04:37:50 +03:00
|
|
|
|
|
|
|
// RDF-specific parsing
|
2014-01-04 19:02:17 +04:00
|
|
|
nsresult OpenRDF(const char16_t* aName);
|
|
|
|
nsresult OpenObject(const char16_t* aName ,const char16_t** aAttributes);
|
|
|
|
nsresult OpenProperty(const char16_t* aName, const char16_t** aAttributes);
|
|
|
|
nsresult OpenMember(const char16_t* aName, const char16_t** aAttributes);
|
|
|
|
nsresult OpenValue(const char16_t* aName, const char16_t** aAttributes);
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
nsresult GetIdAboutAttribute(const char16_t** aAttributes, nsIRDFResource** aResource, bool* aIsAnonymous = nullptr);
|
|
|
|
nsresult GetResourceAttribute(const char16_t** aAttributes, nsIRDFResource** aResource);
|
|
|
|
nsresult AddProperties(const char16_t** aAttributes, nsIRDFResource* aSubject, int32_t* aCount = nullptr);
|
|
|
|
void SetParseMode(const char16_t **aAttributes);
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t* mText;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mTextLength;
|
|
|
|
int32_t mTextSize;
|
1999-01-14 13:55:08 +03:00
|
|
|
|
2005-02-04 22:43:25 +03:00
|
|
|
/**
|
|
|
|
* From the set of given attributes, this method extracts the
|
|
|
|
* namespace definitions and feeds them to the datasource.
|
|
|
|
* These can then be suggested to the serializer to be used again.
|
|
|
|
* Hopefully, this will keep namespace definitions intact in a
|
|
|
|
* parse - serialize cycle.
|
|
|
|
*/
|
2014-01-04 19:02:17 +04:00
|
|
|
void RegisterNamespaces(const char16_t **aAttributes);
|
2005-02-04 22:43:25 +03:00
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
/**
|
|
|
|
* Extracts the localname from aExpatName, the name that the Expat parser
|
2005-02-04 22:43:25 +03:00
|
|
|
* passes us.
|
|
|
|
* aLocalName will contain the localname in aExpatName.
|
|
|
|
* The return value is a dependent string containing just the namespace.
|
2004-12-15 18:37:23 +03:00
|
|
|
*/
|
2014-01-04 19:02:17 +04:00
|
|
|
const nsDependentSubstring SplitExpatName(const char16_t *aExpatName,
|
2005-02-04 22:43:25 +03:00
|
|
|
nsIAtom **aLocalName);
|
1999-01-14 13:55:08 +03:00
|
|
|
|
1999-09-30 00:25:41 +04:00
|
|
|
enum eContainerType { eBag, eSeq, eAlt };
|
|
|
|
nsresult InitContainer(nsIRDFResource* aContainerType, nsIRDFResource* aContainer);
|
|
|
|
nsresult ReinitContainer(nsIRDFResource* aContainerType, nsIRDFResource* aContainer);
|
|
|
|
|
1999-06-24 04:22:58 +04:00
|
|
|
// The datasource in which we're assigning assertions
|
|
|
|
nsCOMPtr<nsIRDFDataSource> mDataSource;
|
|
|
|
|
2006-03-07 18:43:26 +03:00
|
|
|
// A hash of all the node IDs referred to
|
|
|
|
nsInterfaceHashtable<nsStringHashKey, nsIRDFResource> mNodeIDMap;
|
|
|
|
|
1999-06-24 04:22:58 +04:00
|
|
|
// The current state of the content sink
|
|
|
|
RDFContentSinkState mState;
|
2002-01-15 04:56:15 +03:00
|
|
|
RDFContentSinkParseMode mParseMode;
|
1999-01-14 13:55:08 +03:00
|
|
|
|
|
|
|
// content stack management
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2002-01-15 04:56:15 +03:00
|
|
|
PushContext(nsIRDFResource *aContext,
|
|
|
|
RDFContentSinkState aState,
|
|
|
|
RDFContentSinkParseMode aParseMode);
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
PopContext(nsIRDFResource *&aContext,
|
|
|
|
RDFContentSinkState &aState,
|
|
|
|
RDFContentSinkParseMode &aParseMode);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
nsIRDFResource* GetContextElement(int32_t ancestor = 0);
|
1999-01-14 13:55:08 +03:00
|
|
|
|
2009-04-22 12:43:15 +04:00
|
|
|
|
|
|
|
struct RDFContextStackElement {
|
|
|
|
nsCOMPtr<nsIRDFResource> mResource;
|
|
|
|
RDFContentSinkState mState;
|
|
|
|
RDFContentSinkParseMode mParseMode;
|
|
|
|
};
|
|
|
|
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<RDFContextStackElement, 8>* mContextStack;
|
1999-01-14 13:55:08 +03:00
|
|
|
|
2015-08-12 07:12:05 +03:00
|
|
|
nsCOMPtr<nsIURI> mDocumentURL;
|
2013-12-01 09:42:59 +04:00
|
|
|
|
|
|
|
private:
|
2016-01-29 21:15:38 +03:00
|
|
|
static PRLogModuleInfo* gLog;
|
1999-01-14 13:55:08 +03:00
|
|
|
};
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t RDFContentSinkImpl::gRefCnt = 0;
|
1999-04-17 04:10:18 +04:00
|
|
|
nsIRDFService* RDFContentSinkImpl::gRDFService;
|
1999-04-27 09:54:18 +04:00
|
|
|
nsIRDFContainerUtils* RDFContentSinkImpl::gRDFContainerUtils;
|
1999-04-17 04:10:18 +04:00
|
|
|
nsIRDFResource* RDFContentSinkImpl::kRDF_type;
|
1999-09-30 00:25:41 +04:00
|
|
|
nsIRDFResource* RDFContentSinkImpl::kRDF_instanceOf;
|
|
|
|
nsIRDFResource* RDFContentSinkImpl::kRDF_Alt;
|
|
|
|
nsIRDFResource* RDFContentSinkImpl::kRDF_Bag;
|
|
|
|
nsIRDFResource* RDFContentSinkImpl::kRDF_Seq;
|
|
|
|
nsIRDFResource* RDFContentSinkImpl::kRDF_nextVal;
|
1999-04-17 04:10:18 +04:00
|
|
|
|
2016-01-29 21:15:38 +03:00
|
|
|
PRLogModuleInfo* RDFContentSinkImpl::gLog;
|
2013-12-01 09:42:59 +04:00
|
|
|
|
1999-01-14 13:55:08 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
2010-03-08 18:44:59 +03:00
|
|
|
|
|
|
|
#define RDF_ATOM(name_, value_) nsIAtom* RDFContentSinkImpl::name_;
|
|
|
|
#include "nsRDFContentSinkAtomList.h"
|
|
|
|
#undef RDF_ATOM
|
|
|
|
|
|
|
|
#define RDF_ATOM(name_, value_) NS_STATIC_ATOM_BUFFER(name_##_buffer, value_)
|
|
|
|
#include "nsRDFContentSinkAtomList.h"
|
|
|
|
#undef RDF_ATOM
|
|
|
|
|
2003-04-16 02:19:01 +04:00
|
|
|
static const nsStaticAtom rdf_atoms[] = {
|
2010-03-08 18:44:59 +03:00
|
|
|
#define RDF_ATOM(name_, value_) NS_STATIC_ATOM(name_##_buffer, &RDFContentSinkImpl::name_),
|
|
|
|
#include "nsRDFContentSinkAtomList.h"
|
|
|
|
#undef RDF_ATOM
|
2003-04-16 02:19:01 +04:00
|
|
|
};
|
1999-10-07 05:51:30 +04:00
|
|
|
|
1999-01-14 13:55:08 +03:00
|
|
|
RDFContentSinkImpl::RDFContentSinkImpl()
|
2012-07-30 18:20:58 +04:00
|
|
|
: mText(nullptr),
|
1999-07-03 08:31:43 +04:00
|
|
|
mTextLength(0),
|
|
|
|
mTextSize(0),
|
|
|
|
mState(eRDFContentSinkState_InProlog),
|
2002-01-15 04:56:15 +03:00
|
|
|
mParseMode(eRDFContentSinkParseMode_Literal),
|
2015-08-12 07:12:05 +03:00
|
|
|
mContextStack(nullptr)
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
1999-04-17 04:10:18 +04:00
|
|
|
if (gRefCnt++ == 0) {
|
2013-12-11 00:25:55 +04:00
|
|
|
NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
|
|
|
nsresult rv = CallGetService(kRDFServiceCID, &gRDFService);
|
1999-04-17 04:10:18 +04:00
|
|
|
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service");
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2003-02-25 22:02:00 +03:00
|
|
|
rv = gRDFService->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "type"),
|
|
|
|
&kRDF_type);
|
|
|
|
rv = gRDFService->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "instanceOf"),
|
|
|
|
&kRDF_instanceOf);
|
|
|
|
rv = gRDFService->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "Alt"),
|
|
|
|
&kRDF_Alt);
|
|
|
|
rv = gRDFService->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "Bag"),
|
|
|
|
&kRDF_Bag);
|
|
|
|
rv = gRDFService->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "Seq"),
|
|
|
|
&kRDF_Seq);
|
|
|
|
rv = gRDFService->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "nextVal"),
|
|
|
|
&kRDF_nextVal);
|
1999-04-17 04:10:18 +04:00
|
|
|
}
|
1999-04-21 04:09:41 +04:00
|
|
|
|
2013-12-11 00:25:55 +04:00
|
|
|
NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID);
|
|
|
|
rv = CallGetService(kRDFContainerUtilsCID, &gRDFContainerUtils);
|
1999-04-27 09:54:18 +04:00
|
|
|
|
2012-03-09 06:22:57 +04:00
|
|
|
NS_RegisterStaticAtoms(rdf_atoms);
|
1999-04-17 04:10:18 +04:00
|
|
|
}
|
2016-01-29 21:15:38 +03:00
|
|
|
|
|
|
|
if (! gLog)
|
|
|
|
gLog = PR_NewLogModule("nsRDFContentSink");
|
1998-12-24 08:07:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-01-14 13:55:08 +03:00
|
|
|
RDFContentSinkImpl::~RDFContentSinkImpl()
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
1999-10-07 05:51:30 +04:00
|
|
|
#ifdef DEBUG_REFS
|
|
|
|
--gInstanceCount;
|
2000-10-29 02:17:53 +04:00
|
|
|
fprintf(stdout, "%d - RDF: RDFContentSinkImpl\n", gInstanceCount);
|
1999-10-07 05:51:30 +04:00
|
|
|
#endif
|
|
|
|
|
1998-12-24 08:07:14 +03:00
|
|
|
if (mContextStack) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Warning,
|
1999-04-21 04:09:41 +04:00
|
|
|
("rdfxml: warning! unclosed tag"));
|
1998-12-24 08:07:14 +03:00
|
|
|
|
|
|
|
// XXX we should never need to do this, but, we'll write the
|
|
|
|
// code all the same. If someone left the content stack dirty,
|
|
|
|
// pop all the elements off the stack and release them.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t i = mContextStack->Length();
|
1999-07-03 08:31:43 +04:00
|
|
|
while (0 < i--) {
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIRDFResource* resource = nullptr;
|
1998-12-24 08:07:14 +03:00
|
|
|
RDFContentSinkState state;
|
2002-01-15 04:56:15 +03:00
|
|
|
RDFContentSinkParseMode parseMode;
|
|
|
|
PopContext(resource, state, parseMode);
|
1999-04-03 00:46:41 +04:00
|
|
|
|
|
|
|
// print some fairly useless debugging info
|
|
|
|
// XXX we should save line numbers on the context stack: this'd
|
|
|
|
// be about 1000x more helpful.
|
2015-06-04 01:25:57 +03:00
|
|
|
if (resource && MOZ_LOG_TEST(gLog, LogLevel::Debug)) {
|
1999-04-03 00:46:41 +04:00
|
|
|
nsXPIDLCString uri;
|
|
|
|
resource->GetValue(getter_Copies(uri));
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Debug,
|
1999-04-03 00:46:41 +04:00
|
|
|
("rdfxml: uri=%s", (const char*) uri));
|
|
|
|
}
|
|
|
|
|
1998-12-24 08:07:14 +03:00
|
|
|
NS_IF_RELEASE(resource);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete mContextStack;
|
|
|
|
}
|
2015-02-19 07:51:06 +03:00
|
|
|
free(mText);
|
1999-04-17 04:10:18 +04:00
|
|
|
|
|
|
|
|
|
|
|
if (--gRefCnt == 0) {
|
2004-11-08 02:59:35 +03:00
|
|
|
NS_IF_RELEASE(gRDFService);
|
|
|
|
NS_IF_RELEASE(gRDFContainerUtils);
|
1999-04-17 04:10:18 +04:00
|
|
|
NS_IF_RELEASE(kRDF_type);
|
1999-11-24 01:30:27 +03:00
|
|
|
NS_IF_RELEASE(kRDF_instanceOf);
|
|
|
|
NS_IF_RELEASE(kRDF_Alt);
|
|
|
|
NS_IF_RELEASE(kRDF_Bag);
|
|
|
|
NS_IF_RELEASE(kRDF_Seq);
|
|
|
|
NS_IF_RELEASE(kRDF_nextVal);
|
1999-04-17 04:10:18 +04:00
|
|
|
}
|
1998-12-24 08:07:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsISupports interface
|
|
|
|
|
2003-09-08 04:18:24 +04:00
|
|
|
NS_IMPL_ADDREF(RDFContentSinkImpl)
|
|
|
|
NS_IMPL_RELEASE(RDFContentSinkImpl)
|
1998-12-24 08:07:14 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-01-14 13:55:08 +03:00
|
|
|
RDFContentSinkImpl::QueryInterface(REFNSIID iid, void** result)
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(result, "null ptr");
|
|
|
|
if (! result)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2013-12-01 09:42:59 +04:00
|
|
|
NS_DEFINE_IID(kIContentSinkIID, NS_ICONTENT_SINK_IID);
|
|
|
|
NS_DEFINE_IID(kIExpatSinkIID, NS_IEXPATSINK_IID);
|
|
|
|
NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|
|
|
NS_DEFINE_IID(kIXMLContentSinkIID, NS_IXMLCONTENT_SINK_IID);
|
|
|
|
NS_DEFINE_IID(kIRDFContentSinkIID, NS_IRDFCONTENTSINK_IID);
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
*result = nullptr;
|
1998-12-24 08:07:14 +03:00
|
|
|
if (iid.Equals(kIRDFContentSinkIID) ||
|
|
|
|
iid.Equals(kIXMLContentSinkIID) ||
|
|
|
|
iid.Equals(kIContentSinkIID) ||
|
2013-12-11 00:25:55 +04:00
|
|
|
iid.Equals(kISupportsIID)) {
|
2007-07-08 11:08:04 +04:00
|
|
|
*result = static_cast<nsIXMLContentSink*>(this);
|
1998-12-24 08:07:14 +03:00
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-01-09 04:37:50 +03:00
|
|
|
else if (iid.Equals(kIExpatSinkIID)) {
|
2007-07-08 11:08:04 +04:00
|
|
|
*result = static_cast<nsIExpatSink*>(this);
|
2002-01-09 04:37:50 +03:00
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
1999-06-24 04:22:58 +04:00
|
|
|
}
|
2002-01-09 04:37:50 +03:00
|
|
|
return NS_NOINTERFACE;
|
1998-12-24 08:07:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-04 19:02:17 +04:00
|
|
|
RDFContentSinkImpl::HandleStartElement(const char16_t *aName,
|
|
|
|
const char16_t **aAtts,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aAttsCount,
|
|
|
|
uint32_t aLineNumber)
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
2002-01-09 04:37:50 +03:00
|
|
|
FlushText();
|
1998-12-24 08:07:14 +03:00
|
|
|
|
2003-09-27 08:18:26 +04:00
|
|
|
nsresult rv = NS_ERROR_UNEXPECTED; // XXX
|
1998-12-24 08:07:14 +03:00
|
|
|
|
2005-02-04 22:43:25 +03:00
|
|
|
RegisterNamespaces(aAtts);
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
switch (mState) {
|
|
|
|
case eRDFContentSinkState_InProlog:
|
|
|
|
rv = OpenRDF(aName);
|
|
|
|
break;
|
1998-12-24 08:07:14 +03:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
case eRDFContentSinkState_InDocumentElement:
|
|
|
|
rv = OpenObject(aName,aAtts);
|
|
|
|
break;
|
1998-12-24 08:07:14 +03:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
case eRDFContentSinkState_InDescriptionElement:
|
|
|
|
rv = OpenProperty(aName,aAtts);
|
|
|
|
break;
|
1998-12-24 08:07:14 +03:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
case eRDFContentSinkState_InContainerElement:
|
|
|
|
rv = OpenMember(aName,aAtts);
|
|
|
|
break;
|
1998-12-24 08:07:14 +03:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
case eRDFContentSinkState_InPropertyElement:
|
|
|
|
case eRDFContentSinkState_InMemberElement:
|
|
|
|
rv = OpenValue(aName,aAtts);
|
|
|
|
break;
|
1998-12-24 08:07:14 +03:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
case eRDFContentSinkState_InEpilog:
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Warning,
|
2002-01-09 04:37:50 +03:00
|
|
|
("rdfxml: unexpected content in epilog at line %d",
|
|
|
|
aLineNumber));
|
|
|
|
break;
|
|
|
|
}
|
1998-12-24 08:07:14 +03:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
return rv;
|
1998-12-24 08:07:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-04 19:02:17 +04:00
|
|
|
RDFContentSinkImpl::HandleEndElement(const char16_t *aName)
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
2002-01-09 04:37:50 +03:00
|
|
|
FlushText();
|
1998-12-24 08:07:14 +03:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
nsIRDFResource* resource;
|
2002-01-15 04:56:15 +03:00
|
|
|
if (NS_FAILED(PopContext(resource, mState, mParseMode))) {
|
2002-01-09 04:37:50 +03:00
|
|
|
// XXX parser didn't catch unmatched tags?
|
2015-06-04 01:25:57 +03:00
|
|
|
if (MOZ_LOG_TEST(gLog, LogLevel::Warning)) {
|
2002-01-09 04:37:50 +03:00
|
|
|
nsAutoString tagStr(aName);
|
|
|
|
char* tagCStr = ToNewCString(tagStr);
|
1999-04-21 04:09:41 +04:00
|
|
|
|
2004-06-25 04:51:24 +04:00
|
|
|
PR_LogPrint
|
2002-01-09 04:37:50 +03:00
|
|
|
("rdfxml: extra close tag '%s' at line %d",
|
2004-06-25 04:51:24 +04:00
|
|
|
tagCStr, 0/*XXX fix me */);
|
1999-04-21 04:09:41 +04:00
|
|
|
|
2015-04-01 08:29:55 +03:00
|
|
|
free(tagCStr);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
1999-04-21 04:09:41 +04:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
return NS_ERROR_UNEXPECTED; // XXX
|
|
|
|
}
|
1998-12-24 08:07:14 +03:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
// If we've just popped a member or property element, _now_ is the
|
|
|
|
// time to add that element to the graph.
|
|
|
|
switch (mState) {
|
|
|
|
case eRDFContentSinkState_InMemberElement:
|
|
|
|
{
|
1999-07-20 02:02:22 +04:00
|
|
|
nsCOMPtr<nsIRDFContainer> container;
|
|
|
|
NS_NewRDFContainer(getter_AddRefs(container));
|
|
|
|
container->Init(mDataSource, GetContextElement(1));
|
|
|
|
container->AppendElement(resource);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
break;
|
1999-07-20 02:02:22 +04:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
case eRDFContentSinkState_InPropertyElement:
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mDataSource->Assert(GetContextElement(1), GetContextElement(0), resource, true);
|
2002-01-09 04:37:50 +03:00
|
|
|
} break;
|
1999-07-20 02:02:22 +04:00
|
|
|
default:
|
2002-01-09 04:37:50 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-04-22 12:43:15 +04:00
|
|
|
if (mContextStack->IsEmpty())
|
2002-01-09 04:37:50 +03:00
|
|
|
mState = eRDFContentSinkState_InEpilog;
|
1998-12-24 08:07:14 +03:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
NS_IF_RELEASE(resource);
|
|
|
|
return NS_OK;
|
1998-12-24 08:07:14 +03:00
|
|
|
}
|
2002-01-09 04:37:50 +03:00
|
|
|
|
1998-12-24 08:07:14 +03:00
|
|
|
NS_IMETHODIMP
|
2014-01-04 19:02:17 +04:00
|
|
|
RDFContentSinkImpl::HandleComment(const char16_t *aName)
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
NS_IMETHODIMP
|
2014-01-04 19:02:17 +04:00
|
|
|
RDFContentSinkImpl::HandleCDataSection(const char16_t *aData,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aLength)
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
2002-02-15 02:52:17 +03:00
|
|
|
return aData ? AddText(aData, aLength) : NS_OK;
|
1998-12-24 08:07:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-05-22 04:46:16 +04:00
|
|
|
RDFContentSinkImpl::HandleDoctypeDecl(const nsAString & aSubset,
|
|
|
|
const nsAString & aName,
|
|
|
|
const nsAString & aSystemId,
|
|
|
|
const nsAString & aPublicId,
|
|
|
|
nsISupports* aCatalogData)
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-04 19:02:17 +04:00
|
|
|
RDFContentSinkImpl::HandleCharacterData(const char16_t *aData,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aLength)
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
2002-02-15 02:52:17 +03:00
|
|
|
return aData ? AddText(aData, aLength) : NS_OK;
|
1998-12-24 08:07:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-04 19:02:17 +04:00
|
|
|
RDFContentSinkImpl::HandleProcessingInstruction(const char16_t *aTarget,
|
|
|
|
const char16_t *aData)
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
1999-05-05 07:09:12 +04:00
|
|
|
return NS_OK;
|
1998-12-24 08:07:14 +03:00
|
|
|
}
|
|
|
|
|
2002-08-13 22:41:16 +04:00
|
|
|
NS_IMETHODIMP
|
2014-01-04 19:02:17 +04:00
|
|
|
RDFContentSinkImpl::HandleXMLDeclaration(const char16_t *aVersion,
|
|
|
|
const char16_t *aEncoding,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t aStandalone)
|
2002-08-13 22:41:16 +04:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
NS_IMETHODIMP
|
2014-01-04 19:02:17 +04:00
|
|
|
RDFContentSinkImpl::ReportError(const char16_t* aErrorText,
|
|
|
|
const char16_t* aSourceText,
|
2006-08-25 20:34:57 +04:00
|
|
|
nsIScriptError *aError,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool *_retval)
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
2006-08-25 20:34:57 +04:00
|
|
|
NS_PRECONDITION(aError && aSourceText && aErrorText, "Check arguments!!!");
|
|
|
|
|
|
|
|
// The expat driver should report the error.
|
2011-10-17 18:59:28 +04:00
|
|
|
*_retval = true;
|
2002-01-09 04:37:50 +03:00
|
|
|
return NS_OK;
|
1998-12-24 08:07:14 +03:00
|
|
|
}
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIContentSink interface
|
1998-12-24 08:07:14 +03:00
|
|
|
|
2007-01-31 00:21:06 +03:00
|
|
|
NS_IMETHODIMP
|
2008-10-31 00:31:00 +03:00
|
|
|
RDFContentSinkImpl::WillParse(void)
|
2007-01-31 00:21:06 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-12-24 08:07:14 +03:00
|
|
|
NS_IMETHODIMP
|
2009-06-24 01:22:16 +04:00
|
|
|
RDFContentSinkImpl::WillBuildModel(nsDTDMode)
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
2002-01-09 04:37:50 +03:00
|
|
|
if (mDataSource) {
|
|
|
|
nsCOMPtr<nsIRDFXMLSink> sink = do_QueryInterface(mDataSource);
|
|
|
|
if (sink)
|
|
|
|
return sink->BeginLoad();
|
1998-12-24 08:07:14 +03:00
|
|
|
}
|
2002-01-09 04:37:50 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-12-24 08:07:14 +03:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
RDFContentSinkImpl::DidBuildModel(bool aTerminated)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
|
|
|
if (mDataSource) {
|
|
|
|
nsCOMPtr<nsIRDFXMLSink> sink = do_QueryInterface(mDataSource);
|
|
|
|
if (sink)
|
|
|
|
return sink->EndLoad();
|
1998-12-24 08:07:14 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-01-09 04:37:50 +03:00
|
|
|
RDFContentSinkImpl::WillInterrupt(void)
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
2002-01-09 04:37:50 +03:00
|
|
|
if (mDataSource) {
|
|
|
|
nsCOMPtr<nsIRDFXMLSink> sink = do_QueryInterface(mDataSource);
|
|
|
|
if (sink)
|
|
|
|
return sink->Interrupt();
|
|
|
|
}
|
1998-12-24 08:07:14 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-01-09 04:37:50 +03:00
|
|
|
RDFContentSinkImpl::WillResume(void)
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
2002-01-09 04:37:50 +03:00
|
|
|
if (mDataSource) {
|
|
|
|
nsCOMPtr<nsIRDFXMLSink> sink = do_QueryInterface(mDataSource);
|
|
|
|
if (sink)
|
|
|
|
return sink->Resume();
|
|
|
|
}
|
1998-12-24 08:07:14 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-01-20 15:16:27 +04:00
|
|
|
RDFContentSinkImpl::SetParser(nsParserBase* aParser)
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIRDFContentSink interface
|
|
|
|
|
1998-12-24 09:57:19 +03:00
|
|
|
NS_IMETHODIMP
|
2000-07-26 18:08:05 +04:00
|
|
|
RDFContentSinkImpl::Init(nsIURI* aURL)
|
1998-12-24 09:57:19 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(aURL != nullptr, "null ptr");
|
2000-07-26 18:08:05 +04:00
|
|
|
if (! aURL)
|
1998-12-24 09:57:19 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
mDocumentURL = aURL;
|
|
|
|
mState = eRDFContentSinkState_InProlog;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-12-24 08:07:14 +03:00
|
|
|
NS_IMETHODIMP
|
1999-06-24 04:22:58 +04:00
|
|
|
RDFContentSinkImpl::SetDataSource(nsIRDFDataSource* aDataSource)
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(aDataSource != nullptr, "SetDataSource null ptr");
|
2003-06-21 04:15:41 +04:00
|
|
|
mDataSource = aDataSource;
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(mDataSource != nullptr,"Couldn't QI RDF DataSource");
|
1998-12-24 08:07:14 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-06-24 04:22:58 +04:00
|
|
|
RDFContentSinkImpl::GetDataSource(nsIRDFDataSource*& aDataSource)
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
1999-06-24 04:22:58 +04:00
|
|
|
aDataSource = mDataSource;
|
|
|
|
NS_IF_ADDREF(aDataSource);
|
1998-12-24 08:07:14 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Text buffering
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2014-01-04 19:02:17 +04:00
|
|
|
rdf_IsDataInBuffer(char16_t* buffer, int32_t length)
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0; i < length; ++i) {
|
1998-12-24 08:07:14 +03:00
|
|
|
if (buffer[i] == ' ' ||
|
|
|
|
buffer[i] == '\t' ||
|
|
|
|
buffer[i] == '\n' ||
|
|
|
|
buffer[i] == '\r')
|
|
|
|
continue;
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
1998-12-24 08:07:14 +03:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
1998-12-24 08:07:14 +03:00
|
|
|
}
|
|
|
|
|
2002-01-15 04:56:15 +03:00
|
|
|
void
|
|
|
|
RDFContentSinkImpl::ParseText(nsIRDFNode **aResult)
|
|
|
|
{
|
|
|
|
// XXXwaterson wasteful, but we'd need to make a copy anyway to be
|
|
|
|
// able to call nsIRDFService::Get[Resource|Literal|...]().
|
|
|
|
nsAutoString value;
|
|
|
|
value.Append(mText, mTextLength);
|
|
|
|
value.Trim(" \t\n\r");
|
|
|
|
|
|
|
|
switch (mParseMode) {
|
|
|
|
case eRDFContentSinkParseMode_Literal:
|
|
|
|
{
|
|
|
|
nsIRDFLiteral *result;
|
|
|
|
gRDFService->GetLiteral(value.get(), &result);
|
|
|
|
*aResult = result;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eRDFContentSinkParseMode_Resource:
|
|
|
|
{
|
|
|
|
nsIRDFResource *result;
|
2003-02-25 22:02:00 +03:00
|
|
|
gRDFService->GetUnicodeResource(value, &result);
|
2002-01-15 04:56:15 +03:00
|
|
|
*aResult = result;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eRDFContentSinkParseMode_Int:
|
|
|
|
{
|
2012-07-27 17:59:29 +04:00
|
|
|
nsresult err;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t i = value.ToInteger(&err);
|
2002-01-15 04:56:15 +03:00
|
|
|
nsIRDFInt *result;
|
|
|
|
gRDFService->GetIntLiteral(i, &result);
|
|
|
|
*aResult = result;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case eRDFContentSinkParseMode_Date:
|
|
|
|
{
|
2006-02-03 17:18:39 +03:00
|
|
|
PRTime t = rdf_ParseDate(nsDependentCString(NS_LossyConvertUTF16toASCII(value).get(), value.Length()));
|
2002-01-15 04:56:15 +03:00
|
|
|
nsIRDFDate *result;
|
|
|
|
gRDFService->GetDateLiteral(t, &result);
|
|
|
|
*aResult = result;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("unknown parse type");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1998-12-24 08:07:14 +03:00
|
|
|
|
|
|
|
nsresult
|
2007-06-27 08:22:35 +04:00
|
|
|
RDFContentSinkImpl::FlushText()
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (0 != mTextLength) {
|
2007-06-27 08:22:35 +04:00
|
|
|
if (rdf_IsDataInBuffer(mText, mTextLength)) {
|
1998-12-24 08:07:14 +03:00
|
|
|
// XXX if there's anything but whitespace, then we'll
|
|
|
|
// create a text node.
|
|
|
|
|
|
|
|
switch (mState) {
|
|
|
|
case eRDFContentSinkState_InMemberElement: {
|
2002-01-15 04:56:15 +03:00
|
|
|
nsCOMPtr<nsIRDFNode> node;
|
|
|
|
ParseText(getter_AddRefs(node));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRDFContainer> container;
|
|
|
|
NS_NewRDFContainer(getter_AddRefs(container));
|
|
|
|
container->Init(mDataSource, GetContextElement(1));
|
|
|
|
|
|
|
|
container->AppendElement(node);
|
1998-12-24 08:07:14 +03:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case eRDFContentSinkState_InPropertyElement: {
|
2002-01-15 04:56:15 +03:00
|
|
|
nsCOMPtr<nsIRDFNode> node;
|
|
|
|
ParseText(getter_AddRefs(node));
|
1998-12-24 08:07:14 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mDataSource->Assert(GetContextElement(1), GetContextElement(0), node, true);
|
1998-12-24 08:07:14 +03:00
|
|
|
} break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// just ignore it
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mTextLength = 0;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
RDFContentSinkImpl::AddText(const char16_t* aText, int32_t aLength)
|
1999-04-21 04:09:41 +04:00
|
|
|
{
|
2003-08-02 01:59:48 +04:00
|
|
|
// Create buffer when we first need it
|
|
|
|
if (0 == mTextSize) {
|
2015-02-19 07:51:06 +03:00
|
|
|
mText = (char16_t *) malloc(sizeof(char16_t) * 4096);
|
2003-08-02 01:59:48 +04:00
|
|
|
if (!mText) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
mTextSize = 4096;
|
|
|
|
}
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2003-08-02 01:59:48 +04:00
|
|
|
// Copy data from string into our buffer; grow the buffer as needed.
|
|
|
|
// It never shrinks, but since the content sink doesn't stick around,
|
|
|
|
// this shouldn't be a bloat issue.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t amount = mTextSize - mTextLength;
|
2003-08-02 01:59:48 +04:00
|
|
|
if (amount < aLength) {
|
|
|
|
// Grow the buffer by at least a factor of two to prevent thrashing.
|
|
|
|
// Since PR_REALLOC will leave mText intact if the call fails,
|
|
|
|
// don't clobber mText or mTextSize until the new mem is allocated.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t newSize = (2 * mTextSize > (mTextSize + aLength)) ?
|
2003-08-02 01:59:48 +04:00
|
|
|
(2 * mTextSize) : (mTextSize + aLength);
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t* newText =
|
2015-02-19 07:51:06 +03:00
|
|
|
(char16_t *) realloc(mText, sizeof(char16_t) * newSize);
|
2003-08-02 01:59:48 +04:00
|
|
|
if (!newText)
|
2002-01-09 04:37:50 +03:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2003-08-02 01:59:48 +04:00
|
|
|
mTextSize = newSize;
|
|
|
|
mText = newText;
|
1999-04-21 04:09:41 +04:00
|
|
|
}
|
2014-01-04 19:02:17 +04:00
|
|
|
memcpy(&mText[mTextLength], aText, sizeof(char16_t) * aLength);
|
2003-08-02 01:59:48 +04:00
|
|
|
mTextLength += aLength;
|
1999-04-21 04:09:41 +04:00
|
|
|
|
2003-08-02 01:59:48 +04:00
|
|
|
return NS_OK;
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
1999-04-21 04:09:41 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2005-11-18 23:34:19 +03:00
|
|
|
rdf_RequiresAbsoluteURI(const nsString& uri)
|
|
|
|
{
|
|
|
|
// cheap shot at figuring out if this requires an absolute url translation
|
|
|
|
return !(StringBeginsWith(uri, NS_LITERAL_STRING("urn:")) ||
|
|
|
|
StringBeginsWith(uri, NS_LITERAL_STRING("chrome:")));
|
|
|
|
}
|
|
|
|
|
1998-12-24 08:07:14 +03:00
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
RDFContentSinkImpl::GetIdAboutAttribute(const char16_t** aAttributes,
|
2000-08-30 04:55:46 +04:00
|
|
|
nsIRDFResource** aResource,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool* aIsAnonymous)
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
|
|
|
// This corresponds to the dirty work of production [6.5]
|
2006-04-18 02:39:20 +04:00
|
|
|
nsresult rv = NS_OK;
|
1998-12-24 08:07:14 +03:00
|
|
|
|
2006-03-07 18:43:26 +03:00
|
|
|
nsAutoString nodeID;
|
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
nsCOMPtr<nsIAtom> localName;
|
2002-01-09 04:37:50 +03:00
|
|
|
for (; *aAttributes; aAttributes += 2) {
|
2004-12-15 18:37:23 +03:00
|
|
|
const nsDependentSubstring& nameSpaceURI =
|
2005-02-04 22:43:25 +03:00
|
|
|
SplitExpatName(aAttributes[0], getter_AddRefs(localName));
|
1999-04-21 04:09:41 +04:00
|
|
|
|
2000-07-26 18:08:05 +04:00
|
|
|
// We'll accept either `ID' or `rdf:ID' (ibid with `about' or
|
|
|
|
// `rdf:about') in the spirit of being liberal towards the
|
|
|
|
// input that we receive.
|
2004-12-15 18:37:23 +03:00
|
|
|
if (!nameSpaceURI.IsEmpty() &&
|
|
|
|
!nameSpaceURI.EqualsLiteral(RDF_NAMESPACE_URI)) {
|
2002-01-09 04:37:50 +03:00
|
|
|
continue;
|
|
|
|
}
|
1998-12-24 08:07:14 +03:00
|
|
|
|
|
|
|
// XXX you can't specify both, but we'll just pick up the
|
|
|
|
// first thing that was specified and ignore the other.
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
if (localName == kAboutAtom) {
|
2000-08-30 04:55:46 +04:00
|
|
|
if (aIsAnonymous)
|
2011-10-17 18:59:28 +04:00
|
|
|
*aIsAnonymous = false;
|
2000-08-30 04:55:46 +04:00
|
|
|
|
2005-11-18 23:34:19 +03:00
|
|
|
nsAutoString relURI(aAttributes[1]);
|
|
|
|
if (rdf_RequiresAbsoluteURI(relURI)) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString uri;
|
2006-02-03 17:18:39 +03:00
|
|
|
rv = mDocumentURL->Resolve(NS_ConvertUTF16toUTF8(aAttributes[1]), uri);
|
2005-11-18 23:34:19 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return gRDFService->GetResource(uri,
|
|
|
|
aResource);
|
|
|
|
}
|
2006-02-03 17:18:39 +03:00
|
|
|
return gRDFService->GetResource(NS_ConvertUTF16toUTF8(aAttributes[1]),
|
2005-11-18 23:34:19 +03:00
|
|
|
aResource);
|
1998-12-24 08:07:14 +03:00
|
|
|
}
|
2004-12-15 18:37:23 +03:00
|
|
|
else if (localName == kIdAtom) {
|
2000-08-30 04:55:46 +04:00
|
|
|
if (aIsAnonymous)
|
2011-10-17 18:59:28 +04:00
|
|
|
*aIsAnonymous = false;
|
2000-12-01 00:45:56 +03:00
|
|
|
// In the spirit of leniency, we do not bother trying to
|
|
|
|
// enforce that this be a valid "XML Name" (see
|
|
|
|
// http://www.w3.org/TR/REC-xml#NT-Nmtoken), as per
|
|
|
|
// 6.21. If we wanted to, this would be where to do it.
|
1998-12-24 08:07:14 +03:00
|
|
|
|
1999-06-09 12:29:51 +04:00
|
|
|
// Construct an in-line resource whose URI is the
|
|
|
|
// document's URI plus the XML name specified in the ID
|
|
|
|
// attribute.
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString name;
|
|
|
|
nsAutoCString ref('#');
|
2005-11-18 23:34:19 +03:00
|
|
|
AppendUTF16toUTF8(aAttributes[1], ref);
|
|
|
|
|
|
|
|
rv = mDocumentURL->Resolve(ref, name);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-01-22 09:48:25 +03:00
|
|
|
|
2005-11-18 23:34:19 +03:00
|
|
|
return gRDFService->GetResource(name, aResource);
|
1998-12-24 08:07:14 +03:00
|
|
|
}
|
2006-03-07 18:43:26 +03:00
|
|
|
else if (localName == kNodeIdAtom) {
|
|
|
|
nodeID.Assign(aAttributes[1]);
|
|
|
|
}
|
2004-12-15 18:37:23 +03:00
|
|
|
else if (localName == kAboutEachAtom) {
|
1999-01-22 09:48:25 +03:00
|
|
|
// XXX we don't deal with aboutEach...
|
2015-06-04 01:25:57 +03:00
|
|
|
//MOZ_LOG(gLog, LogLevel::Warning,
|
2002-01-09 04:37:50 +03:00
|
|
|
// ("rdfxml: ignoring aboutEach at line %d",
|
|
|
|
// aNode.GetSourceLineNumber()));
|
1999-01-22 09:48:25 +03:00
|
|
|
}
|
1998-12-24 08:07:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, we couldn't find anything, so just gensym one...
|
2000-08-30 04:55:46 +04:00
|
|
|
if (aIsAnonymous)
|
2011-10-17 18:59:28 +04:00
|
|
|
*aIsAnonymous = true;
|
2000-08-30 04:55:46 +04:00
|
|
|
|
2006-03-07 18:43:26 +03:00
|
|
|
// If nodeID is present, check if we already know about it. If we've seen
|
|
|
|
// the nodeID before, use the same resource, otherwise generate a new one.
|
|
|
|
if (!nodeID.IsEmpty()) {
|
|
|
|
mNodeIDMap.Get(nodeID,aResource);
|
|
|
|
|
|
|
|
if (!*aResource) {
|
|
|
|
rv = gRDFService->GetAnonymousResource(aResource);
|
|
|
|
mNodeIDMap.Put(nodeID,*aResource);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = gRDFService->GetAnonymousResource(aResource);
|
|
|
|
}
|
|
|
|
|
1999-06-26 10:36:26 +04:00
|
|
|
return rv;
|
1998-12-24 08:07:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
RDFContentSinkImpl::GetResourceAttribute(const char16_t** aAttributes,
|
1999-01-22 09:48:25 +03:00
|
|
|
nsIRDFResource** aResource)
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
2004-12-15 18:37:23 +03:00
|
|
|
nsCOMPtr<nsIAtom> localName;
|
2006-03-07 18:43:26 +03:00
|
|
|
|
|
|
|
nsAutoString nodeID;
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
for (; *aAttributes; aAttributes += 2) {
|
2004-12-15 18:37:23 +03:00
|
|
|
const nsDependentSubstring& nameSpaceURI =
|
2005-02-04 22:43:25 +03:00
|
|
|
SplitExpatName(aAttributes[0], getter_AddRefs(localName));
|
2002-01-09 04:37:50 +03:00
|
|
|
|
|
|
|
// We'll accept `resource' or `rdf:resource', under the spirit
|
|
|
|
// that we should be liberal towards the input that we
|
|
|
|
// receive.
|
2004-12-15 18:37:23 +03:00
|
|
|
if (!nameSpaceURI.IsEmpty() &&
|
|
|
|
!nameSpaceURI.EqualsLiteral(RDF_NAMESPACE_URI)) {
|
2002-01-09 04:37:50 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX you can't specify both, but we'll just pick up the
|
|
|
|
// first thing that was specified and ignore the other.
|
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
if (localName == kResourceAtom) {
|
2002-01-09 04:37:50 +03:00
|
|
|
// XXX Take the URI and make it fully qualified by
|
|
|
|
// sticking it into the document's URL. This may not be
|
|
|
|
// appropriate...
|
2005-11-18 23:34:19 +03:00
|
|
|
nsAutoString relURI(aAttributes[1]);
|
|
|
|
if (rdf_RequiresAbsoluteURI(relURI)) {
|
|
|
|
nsresult rv;
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString uri;
|
2005-11-18 23:34:19 +03:00
|
|
|
|
2006-02-03 17:18:39 +03:00
|
|
|
rv = mDocumentURL->Resolve(NS_ConvertUTF16toUTF8(aAttributes[1]), uri);
|
2005-11-18 23:34:19 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return gRDFService->GetResource(uri, aResource);
|
|
|
|
}
|
2006-02-03 17:18:39 +03:00
|
|
|
return gRDFService->GetResource(NS_ConvertUTF16toUTF8(aAttributes[1]),
|
2005-11-18 23:34:19 +03:00
|
|
|
aResource);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2006-03-07 18:43:26 +03:00
|
|
|
else if (localName == kNodeIdAtom) {
|
|
|
|
nodeID.Assign(aAttributes[1]);
|
|
|
|
}
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
2006-03-07 18:43:26 +03:00
|
|
|
|
|
|
|
// If nodeID is present, check if we already know about it. If we've seen
|
|
|
|
// the nodeID before, use the same resource, otherwise generate a new one.
|
|
|
|
if (!nodeID.IsEmpty()) {
|
|
|
|
mNodeIDMap.Get(nodeID,aResource);
|
|
|
|
|
|
|
|
if (!*aResource) {
|
2008-12-08 14:26:52 +03:00
|
|
|
nsresult rv;
|
|
|
|
rv = gRDFService->GetAnonymousResource(aResource);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2006-03-07 18:43:26 +03:00
|
|
|
mNodeIDMap.Put(nodeID,*aResource);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
1998-12-24 08:07:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
RDFContentSinkImpl::AddProperties(const char16_t** aAttributes,
|
2000-08-30 04:55:46 +04:00
|
|
|
nsIRDFResource* aSubject,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t* aCount)
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
2002-01-09 04:37:50 +03:00
|
|
|
if (aCount)
|
|
|
|
*aCount = 0;
|
1998-12-24 08:07:14 +03:00
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
nsCOMPtr<nsIAtom> localName;
|
2002-01-09 04:37:50 +03:00
|
|
|
for (; *aAttributes; aAttributes += 2) {
|
2004-12-15 18:37:23 +03:00
|
|
|
const nsDependentSubstring& nameSpaceURI =
|
2005-02-04 22:43:25 +03:00
|
|
|
SplitExpatName(aAttributes[0], getter_AddRefs(localName));
|
1999-04-17 04:10:18 +04:00
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
// skip 'xmlns' directives, these are "meta" information
|
2004-12-15 18:37:23 +03:00
|
|
|
if (nameSpaceURI.EqualsLiteral("http://www.w3.org/2000/xmlns/")) {
|
2002-01-09 04:37:50 +03:00
|
|
|
continue;
|
|
|
|
}
|
2000-07-26 18:08:05 +04:00
|
|
|
|
2006-03-07 18:43:26 +03:00
|
|
|
// skip `about', `ID', `resource', and 'nodeID' attributes (either with or
|
2002-01-15 04:56:15 +03:00
|
|
|
// without the `rdf:' prefix); these are all "special" and
|
2002-01-09 04:37:50 +03:00
|
|
|
// should've been dealt with by the caller.
|
2004-12-15 18:37:23 +03:00
|
|
|
if (localName == kAboutAtom || localName == kIdAtom ||
|
2006-03-07 18:43:26 +03:00
|
|
|
localName == kResourceAtom || localName == kNodeIdAtom) {
|
2004-12-15 18:37:23 +03:00
|
|
|
if (nameSpaceURI.IsEmpty() ||
|
|
|
|
nameSpaceURI.EqualsLiteral(RDF_NAMESPACE_URI))
|
2002-01-15 04:56:15 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Skip `parseType', `RDF:parseType', and `NC:parseType'. This
|
|
|
|
// is meta-information that will be handled in SetParseMode.
|
2004-12-15 18:37:23 +03:00
|
|
|
if (localName == kParseTypeAtom) {
|
|
|
|
if (nameSpaceURI.IsEmpty() ||
|
|
|
|
nameSpaceURI.EqualsLiteral(RDF_NAMESPACE_URI) ||
|
|
|
|
nameSpaceURI.EqualsLiteral(NC_NAMESPACE_URI)) {
|
2002-01-15 04:56:15 +03:00
|
|
|
continue;
|
|
|
|
}
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
1999-09-30 00:25:41 +04:00
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
NS_ConvertUTF16toUTF8 propertyStr(nameSpaceURI);
|
2010-03-08 18:45:00 +03:00
|
|
|
propertyStr.Append(nsAtomCString(localName));
|
2002-01-09 04:37:50 +03:00
|
|
|
|
|
|
|
// Add the assertion to RDF
|
|
|
|
nsCOMPtr<nsIRDFResource> property;
|
2003-02-25 22:02:00 +03:00
|
|
|
gRDFService->GetResource(propertyStr, getter_AddRefs(property));
|
2002-01-09 04:37:50 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIRDFLiteral> target;
|
2005-11-18 23:34:19 +03:00
|
|
|
gRDFService->GetLiteral(aAttributes[1],
|
|
|
|
getter_AddRefs(target));
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mDataSource->Assert(aSubject, property, target, true);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
1999-09-30 00:25:41 +04:00
|
|
|
}
|
|
|
|
|
2002-01-15 04:56:15 +03:00
|
|
|
void
|
2014-01-04 19:02:17 +04:00
|
|
|
RDFContentSinkImpl::SetParseMode(const char16_t **aAttributes)
|
2002-01-15 04:56:15 +03:00
|
|
|
{
|
2004-12-15 18:37:23 +03:00
|
|
|
nsCOMPtr<nsIAtom> localName;
|
2002-01-15 04:56:15 +03:00
|
|
|
for (; *aAttributes; aAttributes += 2) {
|
2004-12-15 18:37:23 +03:00
|
|
|
const nsDependentSubstring& nameSpaceURI =
|
2005-02-04 22:43:25 +03:00
|
|
|
SplitExpatName(aAttributes[0], getter_AddRefs(localName));
|
2002-01-15 04:56:15 +03:00
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
if (localName == kParseTypeAtom) {
|
2005-11-18 23:34:19 +03:00
|
|
|
nsDependentString v(aAttributes[1]);
|
2002-01-15 04:56:15 +03:00
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
if (nameSpaceURI.IsEmpty() ||
|
|
|
|
nameSpaceURI.EqualsLiteral(RDF_NAMESPACE_URI)) {
|
2004-05-23 02:15:22 +04:00
|
|
|
if (v.EqualsLiteral("Resource"))
|
2002-01-15 04:56:15 +03:00
|
|
|
mParseMode = eRDFContentSinkParseMode_Resource;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2004-12-15 18:37:23 +03:00
|
|
|
else if (nameSpaceURI.EqualsLiteral(NC_NAMESPACE_URI)) {
|
2004-05-23 02:15:22 +04:00
|
|
|
if (v.EqualsLiteral("Date"))
|
2002-01-15 04:56:15 +03:00
|
|
|
mParseMode = eRDFContentSinkParseMode_Date;
|
2004-05-23 02:15:22 +04:00
|
|
|
else if (v.EqualsLiteral("Integer"))
|
2002-01-15 04:56:15 +03:00
|
|
|
mParseMode = eRDFContentSinkParseMode_Int;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-24 08:07:14 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// RDF-specific routines used to build the model
|
|
|
|
|
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
RDFContentSinkImpl::OpenRDF(const char16_t* aName)
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
|
|
|
// ensure that we're actually reading RDF by making sure that the
|
|
|
|
// opening tag is <rdf:RDF>, where "rdf:" corresponds to whatever
|
|
|
|
// they've declared the standard RDF namespace to be.
|
2004-12-15 18:37:23 +03:00
|
|
|
nsCOMPtr<nsIAtom> localName;
|
|
|
|
const nsDependentSubstring& nameSpaceURI =
|
|
|
|
SplitExpatName(aName, getter_AddRefs(localName));
|
1999-04-21 04:09:41 +04:00
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
if (!nameSpaceURI.EqualsLiteral(RDF_NAMESPACE_URI) || localName != kRDFAtom) {
|
2015-06-04 01:25:57 +03:00
|
|
|
// MOZ_LOG(gLog, LogLevel::Info,
|
2002-01-09 04:37:50 +03:00
|
|
|
// ("rdfxml: expected RDF:RDF at line %d",
|
|
|
|
// aNode.GetSourceLineNumber()));
|
1998-12-24 08:07:14 +03:00
|
|
|
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
1999-04-21 04:09:41 +04:00
|
|
|
}
|
1998-12-24 08:07:14 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
PushContext(nullptr, mState, mParseMode);
|
1998-12-24 08:07:14 +03:00
|
|
|
mState = eRDFContentSinkState_InDocumentElement;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
RDFContentSinkImpl::OpenObject(const char16_t* aName,
|
|
|
|
const char16_t** aAttributes)
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
|
|
|
// an "object" non-terminal is either a "description", a "typed
|
|
|
|
// node", or a "container", so this change the content sink's
|
|
|
|
// state appropriately.
|
2004-12-15 18:37:23 +03:00
|
|
|
nsCOMPtr<nsIAtom> localName;
|
|
|
|
const nsDependentSubstring& nameSpaceURI =
|
|
|
|
SplitExpatName(aName, getter_AddRefs(localName));
|
1998-12-24 08:07:14 +03:00
|
|
|
|
|
|
|
// Figure out the URI of this object, and create an RDF node for it.
|
2000-07-26 18:08:05 +04:00
|
|
|
nsCOMPtr<nsIRDFResource> source;
|
2002-01-09 04:37:50 +03:00
|
|
|
GetIdAboutAttribute(aAttributes, getter_AddRefs(source));
|
2000-07-26 18:08:05 +04:00
|
|
|
|
|
|
|
// If there is no `ID' or `about', then there's not much we can do.
|
|
|
|
if (! source)
|
|
|
|
return NS_ERROR_FAILURE;
|
1998-12-24 08:07:14 +03:00
|
|
|
|
|
|
|
// Push the element onto the context stack
|
2002-01-15 04:56:15 +03:00
|
|
|
PushContext(source, mState, mParseMode);
|
1998-12-24 08:07:14 +03:00
|
|
|
|
|
|
|
// Now figure out what kind of state transition we need to
|
|
|
|
// make. We'll either be going into a mode where we parse a
|
|
|
|
// description or a container.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isaTypedNode = true;
|
1998-12-24 08:07:14 +03:00
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
if (nameSpaceURI.EqualsLiteral(RDF_NAMESPACE_URI)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
isaTypedNode = false;
|
1998-12-24 08:07:14 +03:00
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
if (localName == kDescriptionAtom) {
|
1998-12-24 08:07:14 +03:00
|
|
|
// it's a description
|
|
|
|
mState = eRDFContentSinkState_InDescriptionElement;
|
|
|
|
}
|
2004-12-15 18:37:23 +03:00
|
|
|
else if (localName == kBagAtom) {
|
1998-12-24 08:07:14 +03:00
|
|
|
// it's a bag container
|
2000-07-26 18:08:05 +04:00
|
|
|
InitContainer(kRDF_Bag, source);
|
1998-12-24 08:07:14 +03:00
|
|
|
mState = eRDFContentSinkState_InContainerElement;
|
|
|
|
}
|
2004-12-15 18:37:23 +03:00
|
|
|
else if (localName == kSeqAtom) {
|
1998-12-24 08:07:14 +03:00
|
|
|
// it's a seq container
|
2000-07-26 18:08:05 +04:00
|
|
|
InitContainer(kRDF_Seq, source);
|
1998-12-24 08:07:14 +03:00
|
|
|
mState = eRDFContentSinkState_InContainerElement;
|
|
|
|
}
|
2004-12-15 18:37:23 +03:00
|
|
|
else if (localName == kAltAtom) {
|
1998-12-24 08:07:14 +03:00
|
|
|
// it's an alt container
|
2000-07-26 18:08:05 +04:00
|
|
|
InitContainer(kRDF_Alt, source);
|
1998-12-24 08:07:14 +03:00
|
|
|
mState = eRDFContentSinkState_InContainerElement;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// heh, that's not *in* the RDF namespace: just treat it
|
|
|
|
// like a typed node
|
2011-10-17 18:59:28 +04:00
|
|
|
isaTypedNode = true;
|
1998-12-24 08:07:14 +03:00
|
|
|
}
|
|
|
|
}
|
2000-07-26 18:08:05 +04:00
|
|
|
|
1998-12-24 08:07:14 +03:00
|
|
|
if (isaTypedNode) {
|
2004-12-15 18:37:23 +03:00
|
|
|
NS_ConvertUTF16toUTF8 typeStr(nameSpaceURI);
|
2010-03-08 18:45:00 +03:00
|
|
|
typeStr.Append(nsAtomCString(localName));
|
1999-04-17 04:10:18 +04:00
|
|
|
|
1999-04-21 04:09:41 +04:00
|
|
|
nsCOMPtr<nsIRDFResource> type;
|
2004-12-15 18:37:23 +03:00
|
|
|
nsresult rv = gRDFService->GetResource(typeStr, getter_AddRefs(type));
|
1999-04-17 04:10:18 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = mDataSource->Assert(source, kRDF_type, type, true);
|
1999-04-17 04:10:18 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1998-12-24 08:07:14 +03:00
|
|
|
|
|
|
|
mState = eRDFContentSinkState_InDescriptionElement;
|
|
|
|
}
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
AddProperties(aAttributes, source);
|
1998-12-24 08:07:14 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
RDFContentSinkImpl::OpenProperty(const char16_t* aName, const char16_t** aAttributes)
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// an "object" non-terminal is either a "description", a "typed
|
|
|
|
// node", or a "container", so this change the content sink's
|
|
|
|
// state appropriately.
|
2004-12-15 18:37:23 +03:00
|
|
|
nsCOMPtr<nsIAtom> localName;
|
|
|
|
const nsDependentSubstring& nameSpaceURI =
|
|
|
|
SplitExpatName(aName, getter_AddRefs(localName));
|
1998-12-24 08:07:14 +03:00
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
NS_ConvertUTF16toUTF8 propertyStr(nameSpaceURI);
|
2010-03-08 18:45:00 +03:00
|
|
|
propertyStr.Append(nsAtomCString(localName));
|
1999-08-21 11:07:00 +04:00
|
|
|
|
1999-04-17 04:10:18 +04:00
|
|
|
nsCOMPtr<nsIRDFResource> property;
|
2003-02-25 22:02:00 +03:00
|
|
|
rv = gRDFService->GetResource(propertyStr, getter_AddRefs(property));
|
1999-04-17 04:10:18 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1998-12-24 08:07:14 +03:00
|
|
|
|
2000-08-30 04:55:46 +04:00
|
|
|
// See if they've specified a 'resource' attribute, in which case
|
|
|
|
// they mean *that* to be the object of this property.
|
1999-04-17 04:10:18 +04:00
|
|
|
nsCOMPtr<nsIRDFResource> target;
|
2002-01-09 04:37:50 +03:00
|
|
|
GetResourceAttribute(aAttributes, getter_AddRefs(target));
|
2000-08-30 04:55:46 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isAnonymous = false;
|
2000-08-30 04:55:46 +04:00
|
|
|
|
|
|
|
if (! target) {
|
|
|
|
// See if an 'ID' attribute has been specified, in which case
|
|
|
|
// this corresponds to the fourth form of [6.12].
|
|
|
|
|
|
|
|
// XXX strictly speaking, we should reject the RDF/XML as
|
|
|
|
// invalid if they've specified both an 'ID' and a 'resource'
|
|
|
|
// attribute. Bah.
|
|
|
|
|
|
|
|
// XXX strictly speaking, 'about=' isn't allowed here, but
|
|
|
|
// what the hell.
|
2002-01-09 04:37:50 +03:00
|
|
|
GetIdAboutAttribute(aAttributes, getter_AddRefs(target), &isAnonymous);
|
2000-08-30 04:55:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (target) {
|
1998-12-24 08:07:14 +03:00
|
|
|
// They specified an inline resource for the value of this
|
|
|
|
// property. Create an RDF resource for the inline resource
|
|
|
|
// URI, add the properties to it, and attach the inline
|
|
|
|
// resource to its parent.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t count;
|
2002-01-09 04:37:50 +03:00
|
|
|
rv = AddProperties(aAttributes, target, &count);
|
1999-01-22 09:48:25 +03:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "problem adding properties");
|
1999-04-17 04:10:18 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-08-30 04:55:46 +04:00
|
|
|
if (count || !isAnonymous) {
|
|
|
|
// If the resource was "anonymous" (i.e., they hadn't
|
|
|
|
// explicitly set an ID or resource attribute), then we'll
|
|
|
|
// only assert this property from the context element *if*
|
|
|
|
// there were properties specified on the anonymous
|
|
|
|
// resource.
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = mDataSource->Assert(GetContextElement(0), property, target, true);
|
2000-08-30 04:55:46 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
1998-12-24 08:07:14 +03:00
|
|
|
|
|
|
|
// XXX Technically, we should _not_ fall through here and push
|
|
|
|
// the element onto the stack: this is supposed to be a closed
|
|
|
|
// node. But right now I'm lazy and the code will just Do The
|
|
|
|
// Right Thing so long as the RDF is well-formed.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Push the element onto the context stack and change state.
|
2002-01-15 04:56:15 +03:00
|
|
|
PushContext(property, mState, mParseMode);
|
1998-12-24 08:07:14 +03:00
|
|
|
mState = eRDFContentSinkState_InPropertyElement;
|
2002-01-15 04:56:15 +03:00
|
|
|
SetParseMode(aAttributes);
|
1998-12-24 08:07:14 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
RDFContentSinkImpl::OpenMember(const char16_t* aName,
|
|
|
|
const char16_t** aAttributes)
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
|
|
|
// ensure that we're actually reading a member element by making
|
|
|
|
// sure that the opening tag is <rdf:li>, where "rdf:" corresponds
|
|
|
|
// to whatever they've declared the standard RDF namespace to be.
|
1999-04-21 04:09:41 +04:00
|
|
|
nsresult rv;
|
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
nsCOMPtr<nsIAtom> localName;
|
|
|
|
const nsDependentSubstring& nameSpaceURI =
|
|
|
|
SplitExpatName(aName, getter_AddRefs(localName));
|
1998-12-24 08:07:14 +03:00
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
if (!nameSpaceURI.EqualsLiteral(RDF_NAMESPACE_URI) ||
|
|
|
|
localName != kLiAtom) {
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Error,
|
1999-04-21 04:09:41 +04:00
|
|
|
("rdfxml: expected RDF:li at line %d",
|
2002-01-09 04:37:50 +03:00
|
|
|
-1)); // XXX pass in line number
|
1998-12-24 08:07:14 +03:00
|
|
|
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
1999-04-21 04:09:41 +04:00
|
|
|
}
|
1998-12-24 08:07:14 +03:00
|
|
|
|
|
|
|
// The parent element is the container.
|
|
|
|
nsIRDFResource* container = GetContextElement(0);
|
|
|
|
if (! container)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
1999-01-22 09:48:25 +03:00
|
|
|
nsIRDFResource* resource;
|
2002-01-09 04:37:50 +03:00
|
|
|
if (NS_SUCCEEDED(rv = GetResourceAttribute(aAttributes, &resource))) {
|
1998-12-24 08:07:14 +03:00
|
|
|
// Okay, this node has an RDF:resource="..." attribute. That
|
|
|
|
// means that it's a "referenced item," as covered in [6.29].
|
1999-04-27 09:54:18 +04:00
|
|
|
nsCOMPtr<nsIRDFContainer> c;
|
|
|
|
NS_NewRDFContainer(getter_AddRefs(c));
|
|
|
|
c->Init(mDataSource, container);
|
|
|
|
c->AppendElement(resource);
|
1998-12-24 08:07:14 +03:00
|
|
|
|
|
|
|
// XXX Technically, we should _not_ fall through here and push
|
|
|
|
// the element onto the stack: this is supposed to be a closed
|
|
|
|
// node. But right now I'm lazy and the code will just Do The
|
|
|
|
// Right Thing so long as the RDF is well-formed.
|
1999-01-22 09:48:25 +03:00
|
|
|
NS_RELEASE(resource);
|
1998-12-24 08:07:14 +03:00
|
|
|
}
|
|
|
|
|
1999-01-07 21:43:03 +03:00
|
|
|
// Change state. Pushing a null context element is a bit weird,
|
|
|
|
// but the idea is that there really is _no_ context "property".
|
1999-04-27 09:54:18 +04:00
|
|
|
// The contained element will use nsIRDFContainer::AppendElement() to add
|
1999-01-07 21:43:03 +03:00
|
|
|
// the element to the container, which requires only the container
|
|
|
|
// and the element to be added.
|
2012-07-30 18:20:58 +04:00
|
|
|
PushContext(nullptr, mState, mParseMode);
|
1998-12-24 08:07:14 +03:00
|
|
|
mState = eRDFContentSinkState_InMemberElement;
|
2002-01-15 04:56:15 +03:00
|
|
|
SetParseMode(aAttributes);
|
|
|
|
|
1999-01-07 21:43:03 +03:00
|
|
|
return NS_OK;
|
1998-12-24 08:07:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
RDFContentSinkImpl::OpenValue(const char16_t* aName, const char16_t** aAttributes)
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
|
|
|
// a "value" can either be an object or a string: we'll only get
|
|
|
|
// *here* if it's an object, as raw text is added as a leaf.
|
2002-01-09 04:37:50 +03:00
|
|
|
return OpenObject(aName,aAttributes);
|
|
|
|
}
|
|
|
|
|
2005-02-04 22:43:25 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// namespace resolution
|
|
|
|
void
|
2014-01-04 19:02:17 +04:00
|
|
|
RDFContentSinkImpl::RegisterNamespaces(const char16_t **aAttributes)
|
2005-02-04 22:43:25 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIRDFXMLSink> sink = do_QueryInterface(mDataSource);
|
|
|
|
if (!sink) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
NS_NAMED_LITERAL_STRING(xmlns, "http://www.w3.org/2000/xmlns/");
|
|
|
|
for (; *aAttributes; aAttributes += 2) {
|
|
|
|
// check the namespace
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* attr = aAttributes[0];
|
|
|
|
const char16_t* xmlnsP = xmlns.BeginReading();
|
2005-02-04 22:43:25 +03:00
|
|
|
while (*attr == *xmlnsP) {
|
|
|
|
++attr;
|
|
|
|
++xmlnsP;
|
|
|
|
}
|
|
|
|
if (*attr != 0xFFFF ||
|
|
|
|
xmlnsP != xmlns.EndReading()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// get the localname (or "xmlns" for the default namespace)
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* endLocal = ++attr;
|
2005-02-04 22:43:25 +03:00
|
|
|
while (*endLocal && *endLocal != 0xFFFF) {
|
|
|
|
++endLocal;
|
|
|
|
}
|
|
|
|
nsDependentSubstring lname(attr, endLocal);
|
|
|
|
nsCOMPtr<nsIAtom> preferred = do_GetAtom(lname);
|
|
|
|
if (preferred == kXMLNSAtom) {
|
2012-07-30 18:20:58 +04:00
|
|
|
preferred = nullptr;
|
2005-02-04 22:43:25 +03:00
|
|
|
}
|
|
|
|
sink->AddNameSpace(preferred, nsDependentString(aAttributes[1]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Qualified name resolution
|
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
const nsDependentSubstring
|
2014-01-04 19:02:17 +04:00
|
|
|
RDFContentSinkImpl::SplitExpatName(const char16_t *aExpatName,
|
2005-02-04 22:43:25 +03:00
|
|
|
nsIAtom **aLocalName)
|
2002-01-09 04:37:50 +03:00
|
|
|
{
|
2004-12-15 18:37:23 +03:00
|
|
|
/**
|
|
|
|
* Expat can send the following:
|
|
|
|
* localName
|
|
|
|
* namespaceURI<separator>localName
|
|
|
|
* namespaceURI<separator>localName<separator>prefix
|
|
|
|
*
|
|
|
|
* and we use 0xFFFF for the <separator>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *uriEnd = aExpatName;
|
|
|
|
const char16_t *nameStart = aExpatName;
|
|
|
|
const char16_t *pos;
|
2004-12-15 18:37:23 +03:00
|
|
|
for (pos = aExpatName; *pos; ++pos) {
|
|
|
|
if (*pos == 0xFFFF) {
|
|
|
|
if (uriEnd != aExpatName) {
|
|
|
|
break;
|
|
|
|
}
|
2002-01-09 04:37:50 +03:00
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
uriEnd = pos;
|
|
|
|
nameStart = pos + 1;
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-15 18:37:23 +03:00
|
|
|
const nsDependentSubstring& nameSpaceURI = Substring(aExpatName, uriEnd);
|
2014-03-15 23:00:15 +04:00
|
|
|
*aLocalName = NS_NewAtom(Substring(nameStart, pos)).take();
|
2004-12-15 18:37:23 +03:00
|
|
|
return nameSpaceURI;
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
RDFContentSinkImpl::InitContainer(nsIRDFResource* aContainerType, nsIRDFResource* aContainer)
|
|
|
|
{
|
|
|
|
// Do the right kind of initialization based on the container
|
|
|
|
// 'type' resource, and the state of the container (i.e., 'make' a
|
|
|
|
// new container vs. 'reinitialize' the container).
|
|
|
|
nsresult rv;
|
|
|
|
|
2003-03-12 11:26:03 +03:00
|
|
|
static const ContainerInfo gContainerInfo[] = {
|
|
|
|
{ &RDFContentSinkImpl::kRDF_Alt, &nsIRDFContainerUtils::IsAlt, &nsIRDFContainerUtils::MakeAlt },
|
|
|
|
{ &RDFContentSinkImpl::kRDF_Bag, &nsIRDFContainerUtils::IsBag, &nsIRDFContainerUtils::MakeBag },
|
|
|
|
{ &RDFContentSinkImpl::kRDF_Seq, &nsIRDFContainerUtils::IsSeq, &nsIRDFContainerUtils::MakeSeq },
|
|
|
|
{ 0, 0, 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const ContainerInfo* info = gContainerInfo; info->mType != 0; ++info) {
|
2002-01-09 04:37:50 +03:00
|
|
|
if (*info->mType != aContainerType)
|
|
|
|
continue;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isContainer;
|
2002-01-09 04:37:50 +03:00
|
|
|
rv = (gRDFContainerUtils->*(info->mTestFn))(mDataSource, aContainer, &isContainer);
|
|
|
|
if (isContainer) {
|
|
|
|
rv = ReinitContainer(aContainerType, aContainer);
|
|
|
|
}
|
|
|
|
else {
|
2012-07-30 18:20:58 +04:00
|
|
|
rv = (gRDFContainerUtils->*(info->mMakeFn))(mDataSource, aContainer, nullptr);
|
2002-01-09 04:37:50 +03:00
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_NOTREACHED("not an RDF container type");
|
|
|
|
return NS_ERROR_FAILURE;
|
1998-12-24 08:07:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-09 04:37:50 +03:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
RDFContentSinkImpl::ReinitContainer(nsIRDFResource* aContainerType, nsIRDFResource* aContainer)
|
|
|
|
{
|
|
|
|
// Mega-kludge to deal with the fact that Make[Seq|Alt|Bag] is
|
|
|
|
// idempotent, and as such, containers will have state (e.g.,
|
|
|
|
// RDF:nextVal) maintained in the graph across loads. This
|
|
|
|
// re-initializes each container's RDF:nextVal to '1', and 'marks'
|
|
|
|
// the container as such.
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIRDFLiteral> one;
|
2013-12-13 05:50:01 +04:00
|
|
|
rv = gRDFService->GetLiteral(MOZ_UTF16("1"), getter_AddRefs(one));
|
2002-01-09 04:37:50 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// Re-initialize the 'nextval' property
|
|
|
|
nsCOMPtr<nsIRDFNode> nextval;
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = mDataSource->GetTarget(aContainer, kRDF_nextVal, true, getter_AddRefs(nextval));
|
2002-01-09 04:37:50 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = mDataSource->Change(aContainer, kRDF_nextVal, nextval, one);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// Re-mark as a container. XXX should be kRDF_type
|
2011-10-17 18:59:28 +04:00
|
|
|
rv = mDataSource->Assert(aContainer, kRDF_instanceOf, aContainerType, true);
|
2002-01-09 04:37:50 +03:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to mark container as such");
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-12-24 08:07:14 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Content stack management
|
|
|
|
|
|
|
|
nsIRDFResource*
|
2012-08-22 19:56:38 +04:00
|
|
|
RDFContentSinkImpl::GetContextElement(int32_t ancestor /* = 0 */)
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
if ((nullptr == mContextStack) ||
|
2012-08-22 19:56:38 +04:00
|
|
|
(uint32_t(ancestor) >= mContextStack->Length())) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
1998-12-24 08:07:14 +03:00
|
|
|
}
|
|
|
|
|
2009-04-22 12:43:15 +04:00
|
|
|
return mContextStack->ElementAt(
|
|
|
|
mContextStack->Length()-ancestor-1).mResource;
|
1998-12-24 08:07:14 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2002-01-15 04:56:15 +03:00
|
|
|
RDFContentSinkImpl::PushContext(nsIRDFResource *aResource,
|
|
|
|
RDFContentSinkState aState,
|
|
|
|
RDFContentSinkParseMode aParseMode)
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
|
|
|
if (! mContextStack) {
|
2016-02-02 18:36:30 +03:00
|
|
|
mContextStack = new AutoTArray<RDFContextStackElement, 8>();
|
1998-12-24 08:07:14 +03:00
|
|
|
if (! mContextStack)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-22 12:43:15 +04:00
|
|
|
RDFContextStackElement* e = mContextStack->AppendElement();
|
1998-12-24 08:07:14 +03:00
|
|
|
if (! e)
|
2009-04-22 12:43:15 +04:00
|
|
|
return mContextStack->Length();
|
1998-12-24 08:07:14 +03:00
|
|
|
|
2002-01-15 04:56:15 +03:00
|
|
|
e->mResource = aResource;
|
|
|
|
e->mState = aState;
|
|
|
|
e->mParseMode = aParseMode;
|
1998-12-24 08:07:14 +03:00
|
|
|
|
2009-04-22 12:43:15 +04:00
|
|
|
return mContextStack->Length();
|
1998-12-24 08:07:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2002-01-15 04:56:15 +03:00
|
|
|
RDFContentSinkImpl::PopContext(nsIRDFResource *&aResource,
|
|
|
|
RDFContentSinkState &aState,
|
|
|
|
RDFContentSinkParseMode &aParseMode)
|
1998-12-24 08:07:14 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
if ((nullptr == mContextStack) ||
|
2009-04-22 12:43:15 +04:00
|
|
|
(mContextStack->IsEmpty())) {
|
1998-12-24 08:07:14 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i = mContextStack->Length() - 1;
|
2009-04-22 12:43:15 +04:00
|
|
|
RDFContextStackElement &e = mContextStack->ElementAt(i);
|
1998-12-24 08:07:14 +03:00
|
|
|
|
2009-04-22 12:43:15 +04:00
|
|
|
aResource = e.mResource;
|
|
|
|
NS_IF_ADDREF(aResource);
|
|
|
|
aState = e.mState;
|
|
|
|
aParseMode = e.mParseMode;
|
1998-12-24 08:07:14 +03:00
|
|
|
|
2009-04-22 12:43:15 +04:00
|
|
|
mContextStack->RemoveElementAt(i);
|
1998-12-24 08:07:14 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-01-14 13:55:08 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewRDFContentSink(nsIRDFContentSink** aResult)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(aResult != nullptr, "null ptr");
|
1999-01-14 13:55:08 +03:00
|
|
|
if (! aResult)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
RDFContentSinkImpl* sink = new RDFContentSinkImpl();
|
|
|
|
if (! sink)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
NS_ADDREF(sink);
|
|
|
|
*aResult = sink;
|
|
|
|
return NS_OK;
|
|
|
|
}
|