|
Packit |
f0b94e |
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
Packit |
f0b94e |
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
Packit |
f0b94e |
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
Packit |
f0b94e |
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
Packit |
f0b94e |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
#ifndef nsXMLNameSpaceMap_h_
|
|
Packit |
f0b94e |
#define nsXMLNameSpaceMap_h_
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
#include "nsString.h"
|
|
Packit |
f0b94e |
#include "nsTArray.h"
|
|
Packit |
f0b94e |
#include "nsCOMPtr.h"
|
|
Packit |
f0b94e |
#include "nsAtom.h"
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
struct nsNameSpaceEntry {
|
|
Packit |
f0b94e |
explicit nsNameSpaceEntry(nsAtom *aPrefix) : prefix(aPrefix) {}
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
RefPtr<nsAtom> prefix;
|
|
Packit |
f0b94e |
MOZ_INIT_OUTSIDE_CTOR int32_t nameSpaceID;
|
|
Packit |
f0b94e |
};
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
/**
|
|
Packit |
f0b94e |
* nsXMLNameSpaceMap contains a set of prefixes which are mapped onto
|
|
Packit |
f0b94e |
* namespaces. It allows the set to be searched by prefix or by namespace ID.
|
|
Packit |
f0b94e |
*/
|
|
Packit |
f0b94e |
class nsXMLNameSpaceMap {
|
|
Packit |
f0b94e |
public:
|
|
Packit |
f0b94e |
/**
|
|
Packit |
f0b94e |
* Allocates a new nsXMLNameSpaceMap (with new()) and if aForXML is
|
|
Packit |
f0b94e |
* true initializes it with the xmlns and xml namespaces.
|
|
Packit |
f0b94e |
*/
|
|
Packit |
f0b94e |
static nsXMLNameSpaceMap *Create(bool aForXML);
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
/**
|
|
Packit |
f0b94e |
* Add a prefix and its corresponding namespace ID to the map.
|
|
Packit |
f0b94e |
* Passing a null |aPrefix| corresponds to the default namespace, which may
|
|
Packit |
f0b94e |
* be set to something other than kNameSpaceID_None.
|
|
Packit |
f0b94e |
*/
|
|
Packit |
f0b94e |
nsresult AddPrefix(nsAtom *aPrefix, int32_t aNameSpaceID);
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
/**
|
|
Packit |
f0b94e |
* Add a prefix and a namespace URI to the map. The URI will be converted
|
|
Packit |
f0b94e |
* to its corresponding namespace ID.
|
|
Packit |
f0b94e |
*/
|
|
Packit |
f0b94e |
nsresult AddPrefix(nsAtom *aPrefix, nsString &aURI);
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
/*
|
|
Packit |
f0b94e |
* Returns the namespace ID for the given prefix, if it is in the map.
|
|
Packit |
f0b94e |
* If |aPrefix| is null and is not in the map, then a null namespace
|
|
Packit |
f0b94e |
* (kNameSpaceID_None) is returned. If |aPrefix| is non-null and is not in
|
|
Packit |
f0b94e |
* the map, then kNameSpaceID_Unknown is returned.
|
|
Packit |
f0b94e |
*/
|
|
Packit |
f0b94e |
int32_t FindNameSpaceID(nsAtom *aPrefix) const;
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
/**
|
|
Packit |
f0b94e |
* If the given namespace ID is in the map, then the first prefix which
|
|
Packit |
f0b94e |
* maps to that namespace is returned. Otherwise, null is returned.
|
|
Packit |
f0b94e |
*/
|
|
Packit |
f0b94e |
nsAtom *FindPrefix(int32_t aNameSpaceID) const;
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
/* Removes all prefix mappings. */
|
|
Packit |
f0b94e |
void Clear();
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
~nsXMLNameSpaceMap() { Clear(); }
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
private:
|
|
Packit |
f0b94e |
nsXMLNameSpaceMap(); // use Create() to create new instances
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
nsTArray<nsNameSpaceEntry> mNameSpaces;
|
|
Packit |
f0b94e |
};
|
|
Packit |
f0b94e |
|
|
Packit |
f0b94e |
#endif
|