01: /*
02: * Copyright 2008 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.outerj.daisy.xmlutil;
17:
18: import javax.xml.namespace.NamespaceContext;
19: import javax.xml.XMLConstants;
20: import java.util.Iterator;
21: import java.util.Map;
22: import java.util.HashMap;
23:
24: public class SimpleNamespaceContext implements NamespaceContext {
25: private Map<String, String> prefixToUri = new HashMap<String, String>();
26:
27: public void addPrefix(String prefix, String uri) {
28: prefixToUri.put(prefix, uri);
29: }
30:
31: public String getNamespaceURI(String prefix) {
32: if (prefix == null)
33: throw new IllegalArgumentException("NUll argument: prefix");
34:
35: if (prefix.equals(XMLConstants.XML_NS_PREFIX))
36: return XMLConstants.XML_NS_URI;
37: else if (prefix.equals(XMLConstants.XMLNS_ATTRIBUTE))
38: return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
39:
40: String uri = prefixToUri.get(prefix);
41: if (uri != null)
42: return uri;
43: else
44: return XMLConstants.NULL_NS_URI;
45: }
46:
47: public String getPrefix(String namespaceURI) {
48: throw new RuntimeException("Not implemented.");
49: }
50:
51: public Iterator getPrefixes(String namespaceURI) {
52: throw new RuntimeException("Not implemented.");
53: }
54: }
|