1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ken.util;
17
18 import java.util.ArrayList;
19 import java.util.Iterator;
20 import java.util.List;
21
22 import javax.xml.namespace.NamespaceContext;
23
24
25
26
27
28
29 public class CompoundNamespaceContext implements NamespaceContext {
30 private final List<NamespaceContext> contexts;
31
32
33
34
35
36
37 public CompoundNamespaceContext(NamespaceContext first, NamespaceContext second) {
38 this.contexts = new ArrayList<NamespaceContext>(2);
39 this.contexts.add(first);
40 this.contexts.add(second);
41 }
42
43
44
45
46
47 public CompoundNamespaceContext(List<NamespaceContext> contexts) {
48 this.contexts = contexts;
49 }
50
51
52
53
54 public String getNamespaceURI(String prefix) {
55 if (prefix == null) {
56 throw new IllegalArgumentException("The prefix cannot be null.");
57 }
58 for (NamespaceContext nc: contexts) {
59 String uri = nc.getNamespaceURI(prefix);
60 if (uri != null) {
61 return uri;
62 }
63 }
64 return null;
65 }
66
67
68
69
70 public String getPrefix(String namespaceURI) {
71 if (namespaceURI == null) {
72 throw new IllegalArgumentException("The namespace uri cannot be null.");
73 }
74 for (NamespaceContext nc: contexts) {
75 String prefix = nc.getPrefix(namespaceURI);
76 if (prefix != null) {
77 return prefix;
78 }
79 }
80 return null;
81 }
82
83
84
85
86 public Iterator getPrefixes(String namespaceURI) {
87 if (namespaceURI == null) {
88 throw new IllegalArgumentException("The namespace uri cannot be null.");
89 }
90 for (NamespaceContext nc: contexts) {
91 Iterator prefixes = nc.getPrefixes(namespaceURI);
92 if (prefixes != null) {
93 return prefixes;
94 }
95 }
96 return null;
97 }
98 }