|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 #ifndef nsXMLNameSpaceMap_h_ |
|
7 #define nsXMLNameSpaceMap_h_ |
|
8 |
|
9 #include "nsString.h" |
|
10 #include "nsTArray.h" |
|
11 #include "nsCOMPtr.h" |
|
12 #include "nsIAtom.h" |
|
13 |
|
14 struct nsNameSpaceEntry |
|
15 { |
|
16 nsNameSpaceEntry(nsIAtom *aPrefix) |
|
17 : prefix(aPrefix) {} |
|
18 |
|
19 nsCOMPtr<nsIAtom> prefix; |
|
20 int32_t nameSpaceID; |
|
21 }; |
|
22 |
|
23 /** |
|
24 * nsXMLNameSpaceMap contains a set of prefixes which are mapped onto |
|
25 * namespaces. It allows the set to be searched by prefix or by namespace ID. |
|
26 */ |
|
27 class nsXMLNameSpaceMap |
|
28 { |
|
29 public: |
|
30 /** |
|
31 * Allocates a new nsXMLNameSpaceMap (with new()) and if aForXML is |
|
32 * true initializes it with the xmlns and xml namespaces. |
|
33 */ |
|
34 static NS_HIDDEN_(nsXMLNameSpaceMap*) Create(bool aForXML); |
|
35 |
|
36 /** |
|
37 * Add a prefix and its corresponding namespace ID to the map. |
|
38 * Passing a null |aPrefix| corresponds to the default namespace, which may |
|
39 * be set to something other than kNameSpaceID_None. |
|
40 */ |
|
41 NS_HIDDEN_(nsresult) AddPrefix(nsIAtom *aPrefix, int32_t aNameSpaceID); |
|
42 |
|
43 /** |
|
44 * Add a prefix and a namespace URI to the map. The URI will be converted |
|
45 * to its corresponding namespace ID. |
|
46 */ |
|
47 NS_HIDDEN_(nsresult) AddPrefix(nsIAtom *aPrefix, nsString &aURI); |
|
48 |
|
49 /* |
|
50 * Returns the namespace ID for the given prefix, if it is in the map. |
|
51 * If |aPrefix| is null and is not in the map, then a null namespace |
|
52 * (kNameSpaceID_None) is returned. If |aPrefix| is non-null and is not in |
|
53 * the map, then kNameSpaceID_Unknown is returned. |
|
54 */ |
|
55 NS_HIDDEN_(int32_t) FindNameSpaceID(nsIAtom *aPrefix) const; |
|
56 |
|
57 /** |
|
58 * If the given namespace ID is in the map, then the first prefix which |
|
59 * maps to that namespace is returned. Otherwise, null is returned. |
|
60 */ |
|
61 NS_HIDDEN_(nsIAtom*) FindPrefix(int32_t aNameSpaceID) const; |
|
62 |
|
63 /* Removes all prefix mappings. */ |
|
64 NS_HIDDEN_(void) Clear(); |
|
65 |
|
66 ~nsXMLNameSpaceMap() { Clear(); } |
|
67 |
|
68 private: |
|
69 nsXMLNameSpaceMap() NS_HIDDEN; // use Create() to create new instances |
|
70 |
|
71 nsTArray<nsNameSpaceEntry> mNameSpaces; |
|
72 }; |
|
73 |
|
74 #endif |