Esempio n. 1
0
 protected Element importElement(Element element) {
   Document document = getOwnerDocument();
   Document oldDocument = element.getOwnerDocument();
   if (!oldDocument.equals(document)) {
     return (Element) document.importNode(element, true);
   } else {
     return element;
   }
 }
Esempio n. 2
0
  private static String getAttributeValueFrom(
      Element element, String uri, String localName, String prefix, String qualifiedName) {

    String nonzeroLengthUri = (uri == null || uri.length() == 0) ? null : uri;

    boolean mustUseGetAttributeNodeNS = (nonzeroLengthUri != null);

    if (mustUseGetAttributeNodeNS) {

      if (!element.hasAttributeNS(uri, localName)) {
        return null;
      }

      String attrValue = element.getAttributeNS(nonzeroLengthUri, localName);

      return attrValue;
    }

    Attr attribute = null;
    attribute = element.getAttributeNode(qualifiedName);

    return attribute == null ? null : attribute.getValue();
  }
Esempio n. 3
0
  protected static SOAPElement replaceElementWithSOAPElement(Element element, ElementImpl copy) {

    Iterator eachAttribute = getAllAttributesFrom(element);
    while (eachAttribute.hasNext()) {
      Name name = (Name) eachAttribute.next();
      copy.addAttributeBare(name, getAttributeValueFrom(element, name));
    }

    Iterator eachChild = getChildElementsFrom(element);
    while (eachChild.hasNext()) {
      Node nextChild = (Node) eachChild.next();
      copy.insertBefore(nextChild, null);
    }

    Node parent = element.getParentNode();
    if (parent != null) {
      parent.replaceChild(copy, element);
    } // XXX else throw an exception?

    return copy;
  }
Esempio n. 4
0
  protected static Iterator getAllAttributesFrom(final Element element) {
    final NamedNodeMap attributes = element.getAttributes();

    return new Iterator() {
      int attributesLength = attributes.getLength();
      int attributeIndex = 0;
      String currentName;

      public boolean hasNext() {
        return attributeIndex < attributesLength;
      }

      public Object next() {
        if (!hasNext()) {
          throw new NoSuchElementException();
        }
        Node current = attributes.item(attributeIndex++);
        currentName = current.getNodeName();

        String prefix = NameImpl.getPrefixFromTagName(currentName);
        if (prefix.length() == 0) {
          return NameImpl.createFromUnqualifiedName(currentName);
        } else {
          Name attributeName =
              NameImpl.createFromQualifiedName(currentName, current.getNamespaceURI());
          return attributeName;
        }
      }

      public void remove() {
        if (currentName == null) {
          throw new IllegalStateException();
        }
        attributes.removeNamedItem(currentName);
      }
    };
  }