Esempio n. 1
0
 void lookupPrefix(org.w3c.dom.Node node) {
   if (node == null) throw new IllegalArgumentException("node must not be null");
   String prefix = node.lookupPrefix(namespace.getUri());
   if (prefix == null) {
     //    check to see if we match the default namespace
     String defaultNamespace = node.lookupNamespaceURI(null);
     if (defaultNamespace == null) defaultNamespace = "";
     String nodeNamespace = namespace.getUri();
     if (nodeNamespace.equals(defaultNamespace)) {
       prefix = "";
     }
   }
   int i = 0;
   while (prefix == null) {
     String generatedPrefix = "e4x_" + i++;
     String generatedUri = node.lookupNamespaceURI(generatedPrefix);
     if (generatedUri == null) {
       prefix = generatedPrefix;
       org.w3c.dom.Node top = node;
       while (top.getParentNode() != null
           && top.getParentNode() instanceof org.w3c.dom.Element) {
         top = top.getParentNode();
       }
       ((org.w3c.dom.Element) top)
           .setAttributeNS(
               "http://www.w3.org/2000/xmlns/", "xmlns:" + prefix, namespace.getUri());
     }
   }
   namespace.setPrefix(prefix);
 }
Esempio n. 2
0
 String qualify(org.w3c.dom.Node node) {
   if (namespace.getPrefix() == null) {
     if (node != null) {
       lookupPrefix(node);
     } else {
       if (namespace.getUri().equals("")) {
         namespace.setPrefix("");
       } else {
         //    TODO    I am not sure this is right, but if we are creating a standalone node, I
         // think we can set the
         //            default namespace on the node itself and not worry about setting a prefix
         // for that namespace.
         namespace.setPrefix("");
       }
     }
   }
   return qualify(namespace.getPrefix(), localName);
 }
Esempio n. 3
0
 /** @deprecated Use getNamespace() */
 String getUri() {
   return namespace.getUri();
 }
Esempio n. 4
0
 void setAttribute(org.w3c.dom.Element element, String value) {
   if (namespace.getPrefix() == null) lookupPrefix(element);
   element.setAttributeNS(namespace.getUri(), qualify(namespace.getPrefix(), localName), value);
 }
Esempio n. 5
0
 private boolean namespacesEqual(Namespace one, Namespace two) {
   if (one == null && two == null) return true;
   if (one == null || two == null) return false;
   return equals(one.getUri(), two.getUri());
 }
Esempio n. 6
0
 private String getExistingPrefixFor(Namespace namespace) {
   if (getDefaultNamespace().getUri().equals(namespace.getUri())) {
     return "";
   }
   return dom.lookupPrefix(namespace.getUri());
 }