示例#1
0
 private Namespace getNodeNamespace() {
   String uri = dom.getNamespaceURI();
   String prefix = dom.getPrefix();
   if (uri == null) uri = "";
   if (prefix == null) prefix = "";
   return Namespace.create(prefix, uri);
 }
示例#2
0
 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);
 }
示例#3
0
 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()));
     }
   }
 }
示例#4
0
  private void exportToScope(boolean sealed) {
    xmlPrototype = newXML(XmlNode.createText(options, ""));
    xmlListPrototype = newXMLList();
    namespacePrototype = Namespace.create(this.globalScope, null, XmlNode.Namespace.GLOBAL);
    qnamePrototype =
        QName.create(
            this, this.globalScope, null, XmlNode.QName.create(XmlNode.Namespace.create(""), ""));

    xmlPrototype.exportAsJSClass(sealed);
    xmlListPrototype.exportAsJSClass(sealed);
    namespacePrototype.exportAsJSClass(sealed);
    qnamePrototype.exportAsJSClass(sealed);
  }
示例#5
0
 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]);
 }
示例#6
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;
  }
示例#7
0
 /** @deprecated */
 static QName create(String uri, String localName, String prefix) {
   return create(Namespace.create(prefix, uri), localName);
 }
示例#8
0
 private Namespace getDefaultNamespace() {
   String prefix = "";
   String uri = (dom.lookupNamespaceURI(null) == null) ? "" : dom.lookupNamespaceURI(null);
   return Namespace.create(prefix, uri);
 }
示例#9
0
 Namespace getNamespace(String prefix) {
   if (map.get(prefix) == null) return null;
   return Namespace.create(prefix, (String) map.get(prefix));
 }
示例#10
0
 Namespace getNamespaceByUri(String uri) {
   if (uriToPrefix.get(uri) == null) return null;
   return Namespace.create(uri, (String) uriToPrefix.get(uri));
 }