in testing/soap-testsuite/src/main/java/org/apache/axiom/ts/soap/ConvertedSOAPSampleContent.java [79:175]
private static void processSOAPElement(Element element, SOAPElementType type) {
if (type == SOAPFaultChild.NODE) {
element.getParentNode().removeChild(element);
return;
}
QName newName = type.getQName(SOAPSpec.SOAP11);
String prefix = element.getPrefix();
if (newName.getNamespaceURI().isEmpty()) {
prefix = null;
}
element =
(Element)
element.getOwnerDocument()
.renameNode(
element,
newName.getNamespaceURI(),
prefix == null
? newName.getLocalPart()
: prefix + ":" + newName.getLocalPart());
NamedNodeMap attributes = element.getAttributes();
for (int i = 0; i < attributes.getLength(); i++) {
Attr attr = (Attr) attributes.item(i);
if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(attr.getNamespaceURI())
&& attr.getValue().equals(SOAPSpec.SOAP12.getEnvelopeNamespaceURI())) {
attr.setValue(SOAPSpec.SOAP11.getEnvelopeNamespaceURI());
}
}
if (type == SOAPElementType.HEADER) {
Node child = element.getFirstChild();
while (child != null) {
Node nextChild = child.getNextSibling();
if (child.getNodeType() == Node.ELEMENT_NODE) {
Element headerBlock = (Element) child;
Attr roleAttr =
headerBlock.getAttributeNodeNS(
SOAPSpec.SOAP12.getEnvelopeNamespaceURI(),
HeaderBlockAttribute.ROLE.getName(SOAPSpec.SOAP12));
if (roleAttr != null
&& roleAttr.getValue()
.equals("http://www.w3.org/2003/05/soap-envelope/role/none")) {
element.removeChild(headerBlock);
} else {
for (HeaderBlockAttribute attribute :
Multiton.getInstances(HeaderBlockAttribute.class)) {
processAttribute(headerBlock, attribute);
}
}
}
child = nextChild;
}
} else if (type == SOAPFaultChild.CODE) {
final Element value = getChild(element, SOAPFaultChild.VALUE);
element.setTextContent(
transform(
value.getTextContent(),
new TextTransformer() {
@Override
public String transform(String in) {
int idx = in.indexOf(':');
if (idx == -1) {
return in;
}
String prefix = in.substring(0, idx);
if (!SOAPSpec.SOAP12
.getEnvelopeNamespaceURI()
.equals(value.lookupNamespaceURI(prefix))) {
return in;
}
String newCode = faultCodeMap.get(in.substring(idx + 1));
if (newCode == null) {
return in;
}
return prefix + ":" + newCode;
}
}));
} else if (type == SOAPFaultChild.REASON) {
Element text = getChild(element, SOAPFaultChild.TEXT);
element.setTextContent(text.getTextContent());
} else {
SOAPElementType[] childTypes = type.getChildTypes();
if (childTypes.length != 0) {
NodeList children = element.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
Node child = children.item(i);
if (child.getNodeType() == Node.ELEMENT_NODE) {
Element childElement = (Element) child;
for (SOAPElementType childType : childTypes) {
if (hasName(childElement, childType.getQName(SOAPSpec.SOAP12))) {
processSOAPElement(childElement, childType);
break;
}
}
}
}
}
}
}