michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 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 nsXMLNameSpaceMap_h_ michael@0: #define nsXMLNameSpaceMap_h_ michael@0: michael@0: #include "nsString.h" michael@0: #include "nsTArray.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIAtom.h" michael@0: michael@0: struct nsNameSpaceEntry michael@0: { michael@0: nsNameSpaceEntry(nsIAtom *aPrefix) michael@0: : prefix(aPrefix) {} michael@0: michael@0: nsCOMPtr prefix; michael@0: int32_t nameSpaceID; michael@0: }; michael@0: michael@0: /** michael@0: * nsXMLNameSpaceMap contains a set of prefixes which are mapped onto michael@0: * namespaces. It allows the set to be searched by prefix or by namespace ID. michael@0: */ michael@0: class nsXMLNameSpaceMap michael@0: { michael@0: public: michael@0: /** michael@0: * Allocates a new nsXMLNameSpaceMap (with new()) and if aForXML is michael@0: * true initializes it with the xmlns and xml namespaces. michael@0: */ michael@0: static NS_HIDDEN_(nsXMLNameSpaceMap*) Create(bool aForXML); michael@0: michael@0: /** michael@0: * Add a prefix and its corresponding namespace ID to the map. michael@0: * Passing a null |aPrefix| corresponds to the default namespace, which may michael@0: * be set to something other than kNameSpaceID_None. michael@0: */ michael@0: NS_HIDDEN_(nsresult) AddPrefix(nsIAtom *aPrefix, int32_t aNameSpaceID); michael@0: michael@0: /** michael@0: * Add a prefix and a namespace URI to the map. The URI will be converted michael@0: * to its corresponding namespace ID. michael@0: */ michael@0: NS_HIDDEN_(nsresult) AddPrefix(nsIAtom *aPrefix, nsString &aURI); michael@0: michael@0: /* michael@0: * Returns the namespace ID for the given prefix, if it is in the map. michael@0: * If |aPrefix| is null and is not in the map, then a null namespace michael@0: * (kNameSpaceID_None) is returned. If |aPrefix| is non-null and is not in michael@0: * the map, then kNameSpaceID_Unknown is returned. michael@0: */ michael@0: NS_HIDDEN_(int32_t) FindNameSpaceID(nsIAtom *aPrefix) const; michael@0: michael@0: /** michael@0: * If the given namespace ID is in the map, then the first prefix which michael@0: * maps to that namespace is returned. Otherwise, null is returned. michael@0: */ michael@0: NS_HIDDEN_(nsIAtom*) FindPrefix(int32_t aNameSpaceID) const; michael@0: michael@0: /* Removes all prefix mappings. */ michael@0: NS_HIDDEN_(void) Clear(); michael@0: michael@0: ~nsXMLNameSpaceMap() { Clear(); } michael@0: michael@0: private: michael@0: nsXMLNameSpaceMap() NS_HIDDEN; // use Create() to create new instances michael@0: michael@0: nsTArray mNameSpaces; michael@0: }; michael@0: michael@0: #endif