rdf/base/nsRDFXMLSerializer.h
author Gabor Krizsanits <gkrizsanits@mozilla.com>
Tue, 24 Mar 2015 15:29:16 +0100
changeset 264194 90d9af9b861a816df7da099934525c8ead0ae270
parent 217211 12285ae78c93b17e7b5676c5655061b34ea63445
child 270306 d47f66ce3822cd4b95c99b3c0b123584486d119c
permissions -rw-r--r--
Bug 1126014 - DomainPolicy support for e10s. r=mrbkap

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 *
 * 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/. */

#ifndef nsRDFXMLSerializer_h__
#define nsRDFXMLSerializer_h__

#include "nsIRDFLiteral.h"
#include "nsIRDFXMLSerializer.h"
#include "nsIRDFXMLSource.h"
#include "nsNameSpaceMap.h"
#include "nsXPIDLString.h"

#include "nsDataHashtable.h"
#include "rdfITripleVisitor.h"

class nsString;
class nsIOutputStream;
class nsIRDFContainerUtils;

/**
 * A helper class that can serialize RDF/XML from a
 * datasource. Implements both nsIRDFXMLSerializer and
 * nsIRDFXMLSource.
 */
class nsRDFXMLSerializer : public nsIRDFXMLSerializer,
                           public nsIRDFXMLSource
{
public:
    static nsresult
    Create(nsISupports* aOuter, REFNSIID aIID, void** aResult);

    NS_DECL_ISUPPORTS
    NS_DECL_NSIRDFXMLSERIALIZER
    NS_DECL_NSIRDFXMLSOURCE

protected:
    nsRDFXMLSerializer();
    virtual ~nsRDFXMLSerializer();

    // Implementation methods
    nsresult
    RegisterQName(nsIRDFResource* aResource);
    nsresult
    GetQName(nsIRDFResource* aResource, nsCString& aQName);
    already_AddRefed<nsIAtom>
    EnsureNewPrefix();

    nsresult
    SerializeInlineAssertion(nsIOutputStream* aStream,
                             nsIRDFResource* aResource,
                             nsIRDFResource* aProperty,
                             nsIRDFLiteral* aValue);

    nsresult
    SerializeChildAssertion(nsIOutputStream* aStream,
                            nsIRDFResource* aResource,
                            nsIRDFResource* aProperty,
                            nsIRDFNode* aValue);

    nsresult
    SerializeProperty(nsIOutputStream* aStream,
                      nsIRDFResource* aResource,
                      nsIRDFResource* aProperty,
                      bool aInline,
                      int32_t* aSkipped);

    bool
    IsContainerProperty(nsIRDFResource* aProperty);

    nsresult
    SerializeDescription(nsIOutputStream* aStream,
                         nsIRDFResource* aResource);

    nsresult
    SerializeMember(nsIOutputStream* aStream,
                    nsIRDFResource* aContainer,
                    nsIRDFNode* aMember);

    nsresult
    SerializeContainer(nsIOutputStream* aStream,
                       nsIRDFResource* aContainer);

    nsresult
    SerializePrologue(nsIOutputStream* aStream);

    nsresult
    SerializeEpilogue(nsIOutputStream* aStream);

    nsresult
    CollectNamespaces();

    bool
    IsA(nsIRDFDataSource* aDataSource, nsIRDFResource* aResource, nsIRDFResource* aType);

    nsCOMPtr<nsIRDFDataSource> mDataSource;
    nsNameSpaceMap mNameSpaces;
    nsXPIDLCString mBaseURLSpec;

    // hash mapping resources to utf8-encoded QNames
    nsDataHashtable<nsISupportsHashKey, nsCString> mQNames;
    friend class QNameCollector;

    uint32_t mPrefixID;

    static int32_t gRefCnt;
    static nsIRDFResource* kRDF_instanceOf;
    static nsIRDFResource* kRDF_type;
    static nsIRDFResource* kRDF_nextVal;
    static nsIRDFResource* kRDF_Bag;
    static nsIRDFResource* kRDF_Seq;
    static nsIRDFResource* kRDF_Alt;
    static nsIRDFContainerUtils* gRDFC;
};

#endif // nsRDFXMLSerializer_h__