michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsRDFXMLSerializer_h__ michael@0: #define nsRDFXMLSerializer_h__ michael@0: michael@0: #include "nsIRDFLiteral.h" michael@0: #include "nsIRDFXMLSerializer.h" michael@0: #include "nsIRDFXMLSource.h" michael@0: #include "nsNameSpaceMap.h" michael@0: #include "nsXPIDLString.h" michael@0: michael@0: #include "nsDataHashtable.h" michael@0: #include "rdfITripleVisitor.h" michael@0: michael@0: class nsString; michael@0: class nsIOutputStream; michael@0: class nsIRDFContainerUtils; michael@0: michael@0: /** michael@0: * A helper class that can serialize RDF/XML from a michael@0: * datasource. Implements both nsIRDFXMLSerializer and michael@0: * nsIRDFXMLSource. michael@0: */ michael@0: class nsRDFXMLSerializer : public nsIRDFXMLSerializer, michael@0: public nsIRDFXMLSource michael@0: { michael@0: public: michael@0: static nsresult michael@0: Create(nsISupports* aOuter, REFNSIID aIID, void** aResult); michael@0: michael@0: NS_DECL_ISUPPORTS michael@0: NS_DECL_NSIRDFXMLSERIALIZER michael@0: NS_DECL_NSIRDFXMLSOURCE michael@0: michael@0: protected: michael@0: nsRDFXMLSerializer(); michael@0: virtual ~nsRDFXMLSerializer(); michael@0: michael@0: // Implementation methods michael@0: nsresult michael@0: RegisterQName(nsIRDFResource* aResource); michael@0: nsresult michael@0: GetQName(nsIRDFResource* aResource, nsCString& aQName); michael@0: already_AddRefed michael@0: EnsureNewPrefix(); michael@0: michael@0: nsresult michael@0: SerializeInlineAssertion(nsIOutputStream* aStream, michael@0: nsIRDFResource* aResource, michael@0: nsIRDFResource* aProperty, michael@0: nsIRDFLiteral* aValue); michael@0: michael@0: nsresult michael@0: SerializeChildAssertion(nsIOutputStream* aStream, michael@0: nsIRDFResource* aResource, michael@0: nsIRDFResource* aProperty, michael@0: nsIRDFNode* aValue); michael@0: michael@0: nsresult michael@0: SerializeProperty(nsIOutputStream* aStream, michael@0: nsIRDFResource* aResource, michael@0: nsIRDFResource* aProperty, michael@0: bool aInline, michael@0: int32_t* aSkipped); michael@0: michael@0: bool michael@0: IsContainerProperty(nsIRDFResource* aProperty); michael@0: michael@0: nsresult michael@0: SerializeDescription(nsIOutputStream* aStream, michael@0: nsIRDFResource* aResource); michael@0: michael@0: nsresult michael@0: SerializeMember(nsIOutputStream* aStream, michael@0: nsIRDFResource* aContainer, michael@0: nsIRDFNode* aMember); michael@0: michael@0: nsresult michael@0: SerializeContainer(nsIOutputStream* aStream, michael@0: nsIRDFResource* aContainer); michael@0: michael@0: nsresult michael@0: SerializePrologue(nsIOutputStream* aStream); michael@0: michael@0: nsresult michael@0: SerializeEpilogue(nsIOutputStream* aStream); michael@0: michael@0: nsresult michael@0: CollectNamespaces(); michael@0: michael@0: bool michael@0: IsA(nsIRDFDataSource* aDataSource, nsIRDFResource* aResource, nsIRDFResource* aType); michael@0: michael@0: nsCOMPtr mDataSource; michael@0: nsNameSpaceMap mNameSpaces; michael@0: nsXPIDLCString mBaseURLSpec; michael@0: michael@0: // hash mapping resources to utf8-encoded QNames michael@0: nsDataHashtable mQNames; michael@0: friend class QNameCollector; michael@0: michael@0: uint32_t mPrefixID; michael@0: michael@0: static int32_t gRefCnt; michael@0: static nsIRDFResource* kRDF_instanceOf; michael@0: static nsIRDFResource* kRDF_type; michael@0: static nsIRDFResource* kRDF_nextVal; michael@0: static nsIRDFResource* kRDF_Bag; michael@0: static nsIRDFResource* kRDF_Seq; michael@0: static nsIRDFResource* kRDF_Alt; michael@0: static nsIRDFContainerUtils* gRDFC; michael@0: }; michael@0: michael@0: #endif // nsRDFXMLSerializer_h__