1 19 package org.netbeans.tax; 20 21 import java.util.Map ; 22 import java.util.HashMap ; 23 import java.util.Iterator ; 24 25 34 public class TreeNamespaceContext { 35 36 40 private TreeElement element; 41 42 51 private static Map definedNS = new HashMap (); 52 53 static { 54 TreeNamespace namespace; 55 56 namespace = TreeNamespace.XML_NAMESPACE; 57 definedNS.put (namespace.getPrefix (), namespace); 58 59 namespace = TreeNamespace.XMLNS_NAMESPACE; 60 definedNS.put (namespace.getPrefix (), namespace); 61 } 62 63 64 68 72 protected TreeNamespaceContext (TreeElement element) { 73 this.element = element; 74 } 75 76 77 82 public String getURI (String prefix) { 83 84 86 TreeNamespace ns = (TreeNamespace)definedNS.get (prefix); 87 if (ns != null) { 88 return ns.getURI (); 89 } 90 91 94 TreeNamedObjectMap attrs = element.getAttributes (); 95 if (attrs != null) { 96 Iterator it = attrs.iterator (); 97 while (it.hasNext ()) { 98 TreeAttribute next = (TreeAttribute) it.next (); 99 TreeName name = next.getTreeName (); 100 if ("xmlns".equals (name.getPrefix ())) { if (prefix.equals (name.getName ())) { 102 return next.getValue (); 103 } 104 } else if ("xmlns".equals (name.getQualifiedName ())) { return next.getValue (); 106 } 107 } 108 } 109 110 112 TreeParentNode parentNode = element.getParentNode (); 113 if ( parentNode instanceof TreeElement ) { 114 TreeElement parentElement = (TreeElement)parentNode; 115 if (parentElement != null) { 116 return parentElement.getNamespaceContext ().getURI (prefix); 117 } 118 } 119 return null; 120 } 121 122 } 123 | Popular Tags |