1
2
3
4
5
6
7
8
9
10
11
12
13
14 package uk.nhs.interoperability.util.xml;
15
16 import java.util.ArrayList;
17 import java.util.HashMap;
18 import java.util.Iterator;
19 import java.util.List;
20 import java.util.Map;
21
22 import javax.xml.namespace.NamespaceContext;
23
24 import uk.nhs.interoperability.util.Logger;
25
26
27
28
29
30
31
32
33 public class XMLNamespaceContext implements NamespaceContext {
34
35
36 public static final String HL7NAMESPACE = "urn:hl7-org:v3";
37
38
39 public static final String HL7NAMESPACE_DEFAULY_PREFIX = "hl7";
40
41
42 public static final String SOAPENVNAMESPACE = "http://schemas.xmlsoap.org/soap/envelope/";
43
44
45 public static final String SOAPENVNAMESPACE_DEFAULT_PREFIX = "SOAP";
46
47
48 public static final String HL7V2NAMESPACE = "urn:hl7-org:v2xml";
49
50
51 public static final String HL7V2NAMESPACE_DEFAULT_PREFIX = "hl7v2";
52
53
54 public static final String ITKNAMESPACE = "urn:nhs-itk:ns:201005";
55
56
57 public static final String ITKNAMESPACE_DEFAULT_PREFIX = "itk";
58
59
60 public static final String WSANAMESPACE = "http://www.w3.org/2005/08/addressing";
61
62
63 public static final String WSANAMESPACE_DEFAULT_PREFIX = "wsa";
64
65
66 public static final String WSSENAMESPACE = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
67
68
69 public static final String WSSENAMESPACE_DEFAULT_PREFIX = "wsse";
70
71
72 public static final String WSUNAMESPACE = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
73
74
75 public static final String WSUNAMESPACE_DEFAULT_PREFIX = "wsu";
76
77
78 public static Map<String, String> namespaces = new HashMap<String, String>();
79
80 static {
81 namespaces.put(HL7NAMESPACE_DEFAULY_PREFIX, HL7NAMESPACE);
82 namespaces.put(SOAPENVNAMESPACE_DEFAULT_PREFIX, SOAPENVNAMESPACE);
83 namespaces.put(HL7V2NAMESPACE_DEFAULT_PREFIX, HL7V2NAMESPACE);
84 namespaces.put(ITKNAMESPACE_DEFAULT_PREFIX, ITKNAMESPACE);
85 namespaces.put(WSANAMESPACE_DEFAULT_PREFIX, WSANAMESPACE);
86 namespaces.put(WSSENAMESPACE_DEFAULT_PREFIX, WSSENAMESPACE);
87 namespaces.put(WSUNAMESPACE_DEFAULT_PREFIX, WSUNAMESPACE);
88
89 }
90
91
92
93
94 @Override
95 public String getNamespaceURI(String prefix) {
96 return namespaces.get(prefix);
97 }
98
99
100
101
102 @Override
103 public String getPrefix(String namespaceURI) {
104 for (Map.Entry<String, String> entry : namespaces.entrySet()) {
105 if (entry.getValue().equals(namespaceURI)) {
106 return entry.getKey();
107 }
108 }
109 Logger.warn("No prefix found for namespace: " + namespaceURI);
110 return null;
111 }
112
113
114
115
116 @SuppressWarnings("rawtypes")
117 @Override
118 public Iterator getPrefixes(String namespaceURI) {
119 List<String> prefixes = new ArrayList<String>();
120 for (Map.Entry<String, String> entry : namespaces.entrySet()) {
121 if (entry.getValue().equals(namespaceURI)) {
122 prefixes.add(entry.getKey());
123 }
124 }
125 return prefixes.iterator();
126 }
127
128
129
130 }