protected Element getParentOfSignature(Message inMessage, Node messageBodyNode) throws Exception { //NOPMD
if (getConfiguration().getParentLocalName() == null) {
return null;
}
if (messageBodyNode.getParentNode() == null || messageBodyNode.getParentNode().getNodeType() != Node.DOCUMENT_NODE) {
throw new XmlSignatureFormatException(
"Incomming message has wrong format: It is not an XML document. Cannot create an enveloped XML signature.");
}
Document doc = (Document) messageBodyNode.getParentNode();
NodeList parents = doc.getElementsByTagNameNS(getConfiguration().getParentNamespace(), getConfiguration().getParentLocalName());
if (parents == null || parents.getLength() == 0) {
throw new XmlSignatureFormatException(
String.format(
"Incoming message has wrong format: The parent element with the local name %s and the namespace %s was not found in the message to build an enveloped XML signature.",
getConfiguration().getParentLocalName(), getConfiguration().getParentNamespace()));
}
// return the first element