1 19 20 package org.netbeans.modules.xml.xdm.visitor; 21 22 import java.util.Collections ; 23 import java.util.HashMap ; 24 import java.util.Iterator ; 25 import java.util.Map ; 26 import java.util.Map.Entry; 27 import javax.xml.namespace.NamespaceContext ; 28 29 public class HashNamespaceResolver implements NamespaceContext { 30 private Map <String , String > prefixes; private Map <String , String > namespaces; 33 public HashNamespaceResolver(Map <String ,String > nsTable) { 34 namespaces = nsTable; 35 prefixes = new HashMap <String ,String >(); 36 for (Entry<String ,String > e : namespaces.entrySet()) { 37 prefixes.put(e.getValue(), e.getKey()); 38 } 39 } 40 41 public HashNamespaceResolver(Map <String ,String > namespaces, Map <String ,String > prefixes) { 42 this.namespaces = namespaces; 43 this.prefixes = prefixes; 44 } 45 46 public Iterator getPrefixes(String namespaceURI) { 47 return Collections.singletonList(getPrefix(namespaceURI)).iterator(); 48 } 49 50 public String getPrefix(String namespaceURI) { 51 return prefixes.get(namespaceURI); 52 } 53 54 public String getNamespaceURI(String prefix) { 55 return namespaces.get(prefix); 56 } 57 58 } | Popular Tags |