1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| package org.apache.xindice.xml; |
21 |
| |
22 |
| import org.apache.xindice.xml.dom.DocumentImpl; |
23 |
| |
24 |
| import org.w3c.dom.Document; |
25 |
| import org.w3c.dom.Element; |
26 |
| import org.w3c.dom.Node; |
27 |
| |
28 |
| import java.util.*; |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
| |
37 |
| |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
| public final class NamespaceMap extends HashMap { |
45 |
| |
46 |
| private Element elem; |
47 |
| |
48 |
| |
49 |
13
| public NamespaceMap() {
|
50 |
| } |
51 |
| |
52 |
9
| public NamespaceMap(Map namespaces) {
|
53 |
9
| putAll(namespaces);
|
54 |
| } |
55 |
| |
56 |
42
| public Node getContextNode() {
|
57 |
42
| if (elem == null) {
|
58 |
21
| Document d = new DocumentImpl();
|
59 |
21
| elem = d.createElement("nsmap");
|
60 |
21
| d.appendChild(elem);
|
61 |
21
| Iterator i = entrySet().iterator();
|
62 |
21
| while (i.hasNext()) {
|
63 |
24
| Map.Entry entry = (Map.Entry) i.next();
|
64 |
24
| String pfx = (String) entry.getKey();
|
65 |
24
| String uri = (String) entry.getValue();
|
66 |
24
| if ("".equals(pfx)) {
|
67 |
3
| elem.setAttribute("xmlns", uri);
|
68 |
| } else { |
69 |
21
| elem.setAttribute("xmlns:" + pfx, uri);
|
70 |
| } |
71 |
| } |
72 |
| } |
73 |
42
| return elem;
|
74 |
| } |
75 |
| |
76 |
0
| public void clearNamespaces() {
|
77 |
0
| clear();
|
78 |
0
| elem = null;
|
79 |
| } |
80 |
| |
81 |
0
| public String getDefaultNamespaceURI() {
|
82 |
0
| return (String) get("");
|
83 |
| } |
84 |
| |
85 |
33
| public String getNamespaceURI(String prefix) {
|
86 |
33
| return (String) get(prefix);
|
87 |
| } |
88 |
| |
89 |
0
| public void setDefaultNamespace(String uri) {
|
90 |
0
| put("", uri);
|
91 |
0
| elem = null;
|
92 |
| } |
93 |
| |
94 |
1
| public void setNamespace(String prefix, String uri) {
|
95 |
1
| put(prefix, uri);
|
96 |
1
| elem = null;
|
97 |
| } |
98 |
| |
99 |
0
| public void removeDefaultNamespace() {
|
100 |
0
| remove("");
|
101 |
0
| elem = null;
|
102 |
| } |
103 |
| |
104 |
0
| public void removeNamespace(String prefix) {
|
105 |
0
| remove(prefix);
|
106 |
0
| elem = null;
|
107 |
| } |
108 |
| |
109 |
12
| public void includeNamespaces(Map nsMap, boolean override) {
|
110 |
12
| Iterator newEntries = nsMap.entrySet().iterator();
|
111 |
12
| while (newEntries.hasNext()) {
|
112 |
15
| Map.Entry entry = (Map.Entry) newEntries.next();
|
113 |
15
| if (!override && containsKey(entry.getKey())) {
|
114 |
0
| continue;
|
115 |
| } |
116 |
15
| put(entry.getKey(), entry.getValue());
|
117 |
| } |
118 |
12
| elem = null;
|
119 |
| } |
120 |
| |
121 |
| |
122 |
| |
123 |
| |
124 |
| |
125 |
25
| public Object put(Object o, Object o1) {
|
126 |
25
| return o == null ? super.put("", o1) : super.put(o, o1);
|
127 |
| } |
128 |
| |
129 |
| |
130 |
| |
131 |
| |
132 |
| |
133 |
15
| public boolean containsKey(Object o) {
|
134 |
15
| return o == null ? super.containsKey(""): super.containsKey(o);
|
135 |
| } |
136 |
| } |