2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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/. */
|
2005-02-18 22:18:37 +03:00
|
|
|
|
2005-02-19 03:10:38 +03:00
|
|
|
#ifndef nsXMLNameSpaceMap_h_
|
|
|
|
#define nsXMLNameSpaceMap_h_
|
2005-02-18 22:18:37 +03:00
|
|
|
|
2009-03-20 11:15:35 +03:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsTArray.h"
|
2009-03-26 11:29:49 +03:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIAtom.h"
|
2005-02-18 22:18:37 +03:00
|
|
|
|
2009-03-26 11:29:49 +03:00
|
|
|
struct nsNameSpaceEntry
|
|
|
|
{
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit nsNameSpaceEntry(nsIAtom* aPrefix)
|
2009-03-26 11:29:49 +03:00
|
|
|
: prefix(aPrefix) {}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> prefix;
|
2016-07-27 15:15:00 +03:00
|
|
|
MOZ_INIT_OUTSIDE_CTOR int32_t nameSpaceID;
|
2009-03-26 11:29:49 +03:00
|
|
|
};
|
2005-02-18 22:18:37 +03:00
|
|
|
|
|
|
|
/**
|
2005-02-19 03:10:38 +03:00
|
|
|
* nsXMLNameSpaceMap contains a set of prefixes which are mapped onto
|
|
|
|
* namespaces. It allows the set to be searched by prefix or by namespace ID.
|
2005-02-18 22:18:37 +03:00
|
|
|
*/
|
2005-02-19 03:10:38 +03:00
|
|
|
class nsXMLNameSpaceMap
|
2005-02-18 22:18:37 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2009-10-30 04:47:48 +03:00
|
|
|
* Allocates a new nsXMLNameSpaceMap (with new()) and if aForXML is
|
|
|
|
* true initializes it with the xmlns and xml namespaces.
|
2005-02-18 22:18:37 +03:00
|
|
|
*/
|
2014-06-02 16:08:21 +04:00
|
|
|
static nsXMLNameSpaceMap* Create(bool aForXML);
|
2005-02-18 22:18:37 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a prefix and its corresponding namespace ID to the map.
|
|
|
|
* Passing a null |aPrefix| corresponds to the default namespace, which may
|
|
|
|
* be set to something other than kNameSpaceID_None.
|
|
|
|
*/
|
2014-06-02 16:08:21 +04:00
|
|
|
nsresult AddPrefix(nsIAtom *aPrefix, int32_t aNameSpaceID);
|
2005-02-18 22:18:37 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a prefix and a namespace URI to the map. The URI will be converted
|
|
|
|
* to its corresponding namespace ID.
|
|
|
|
*/
|
2014-06-02 16:08:21 +04:00
|
|
|
nsresult AddPrefix(nsIAtom *aPrefix, nsString &aURI);
|
2005-02-18 22:18:37 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns the namespace ID for the given prefix, if it is in the map.
|
|
|
|
* If |aPrefix| is null and is not in the map, then a null namespace
|
|
|
|
* (kNameSpaceID_None) is returned. If |aPrefix| is non-null and is not in
|
|
|
|
* the map, then kNameSpaceID_Unknown is returned.
|
|
|
|
*/
|
2014-06-02 16:08:21 +04:00
|
|
|
int32_t FindNameSpaceID(nsIAtom *aPrefix) const;
|
2005-02-18 22:18:37 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If the given namespace ID is in the map, then the first prefix which
|
|
|
|
* maps to that namespace is returned. Otherwise, null is returned.
|
|
|
|
*/
|
2014-06-02 16:08:21 +04:00
|
|
|
nsIAtom* FindPrefix(int32_t aNameSpaceID) const;
|
2005-02-18 22:18:37 +03:00
|
|
|
|
|
|
|
/* Removes all prefix mappings. */
|
2014-06-02 16:08:21 +04:00
|
|
|
void Clear();
|
2005-02-18 22:18:37 +03:00
|
|
|
|
2005-02-19 03:10:38 +03:00
|
|
|
~nsXMLNameSpaceMap() { Clear(); }
|
2005-02-18 22:18:37 +03:00
|
|
|
|
|
|
|
private:
|
2014-06-02 16:08:24 +04:00
|
|
|
nsXMLNameSpaceMap(); // use Create() to create new instances
|
2005-02-18 22:18:37 +03:00
|
|
|
|
2009-03-26 11:29:49 +03:00
|
|
|
nsTArray<nsNameSpaceEntry> mNameSpaces;
|
2005-02-18 22:18:37 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|