private Namespace getNodeNamespace() {
   String uri = dom.getNamespaceURI();
   String prefix = dom.getPrefix();
   if (uri == null) uri = "";
   if (prefix == null) prefix = "";
   return Namespace.create(prefix, uri);
 }
 Namespace getNamespaceDeclaration(String prefix) {
   if (prefix.equals("") && dom instanceof Attr) {
     //    Default namespaces do not apply to attributes; see XML Namespaces section 5.2
     return Namespace.create("", "");
   }
   Namespaces rv = getAllNamespaces();
   return rv.getNamespace(prefix);
 }
 private void addNamespaces(Namespaces rv, Element element) {
   if (element == null) throw new RuntimeException("element must not be null");
   String myDefaultNamespace = toUri(element.lookupNamespaceURI(null));
   String parentDefaultNamespace = "";
   if (element.getParentNode() != null) {
     parentDefaultNamespace = toUri(element.getParentNode().lookupNamespaceURI(null));
   }
   if (!myDefaultNamespace.equals(parentDefaultNamespace)
       || !(element.getParentNode() instanceof Element)) {
     rv.declare(Namespace.create("", myDefaultNamespace));
   }
   NamedNodeMap attributes = element.getAttributes();
   for (int i = 0; i < attributes.getLength(); i++) {
     Attr attr = (Attr) attributes.item(i);
     if (attr.getPrefix() != null && attr.getPrefix().equals("xmlns")) {
       rv.declare(Namespace.create(attr.getLocalName(), attr.getValue()));
     }
   }
 }
 Namespace[] getNamespaces() {
   Iterator i = map.keySet().iterator();
   ArrayList rv = new ArrayList();
   while (i.hasNext()) {
     String prefix = (String) i.next();
     String uri = (String) map.get(prefix);
     Namespace n = Namespace.create(prefix, uri);
     if (!n.isEmpty()) {
       rv.add(n);
     }
   }
   return (Namespace[]) rv.toArray(new Namespace[0]);
 }
  private Namespaces getAllNamespaces() {
    Namespaces rv = new Namespaces();

    Node target = this.dom;
    if (target instanceof Attr) {
      target = ((Attr) target).getOwnerElement();
    }
    while (target != null) {
      if (target instanceof Element) {
        addNamespaces(rv, (Element) target);
      }
      target = target.getParentNode();
    }
    //    Fallback in case no namespace was declared
    rv.declare(Namespace.create("", ""));
    return rv;
  }
 /** @deprecated */
 static QName create(String uri, String localName, String prefix) {
   return create(Namespace.create(prefix, uri), localName);
 }
 private Namespace getDefaultNamespace() {
   String prefix = "";
   String uri = (dom.lookupNamespaceURI(null) == null) ? "" : dom.lookupNamespaceURI(null);
   return Namespace.create(prefix, uri);
 }
 Namespace getNamespace(String prefix) {
   if (map.get(prefix) == null) return null;
   return Namespace.create(prefix, (String) map.get(prefix));
 }
 Namespace getNamespaceByUri(String uri) {
   if (uriToPrefix.get(uri) == null) return null;
   return Namespace.create(uri, (String) uriToPrefix.get(uri));
 }