in modules/rampart-core/src/main/java/org/apache/rampart/util/RampartUtil.java [1163:1286]
public static List<WSEncryptionPart> getPartsAndElements(boolean sign, SOAPEnvelope envelope, boolean includeBody,
List<WSEncryptionPart> parts, List<String> elements,
HashMap decNamespaces) {
List<OMElement> found = new ArrayList<OMElement>();
List<WSEncryptionPart> result = new ArrayList<WSEncryptionPart>();
// check body
if(includeBody) {
String wsuId = addWsuIdToElement(envelope.getBody());
if( sign ) {
result.add(createEncryptionPart(envelope.getBody().getLocalName(), wsuId,
null, null));
} else {
result.add(createEncryptionPart(envelope.getBody().getLocalName(), wsuId, null, "Content"));
}
// TODO can we remove this ?
found.add( envelope.getBody() );
}
// Search envelope header for 'parts' from Policy (SignedParts/EncryptedParts)
SOAPHeader header = envelope.getHeader();
for (WSEncryptionPart part : parts) {
if (part.getName() == null) {
// NO name - search by namespace
ArrayList headerList = header.getHeaderBlocksWithNSURI(part.getNamespace());
for (Object aHeaderList : headerList) {
SOAPHeaderBlock shb = (SOAPHeaderBlock) aHeaderList;
// find reference in envelope
OMElement e = header.getFirstChildWithName(shb.getQName());
if (!found.contains(e)) {
// found new
found.add(e);
if (sign) {
result.add(createEncryptionPart(e.getLocalName(), null,
part.getNamespace(), "Content"));
} else {
OMAttribute wsuIdAttribute = e.getAttribute(new QName(WSConstants.WSU_NS, "Id"));
String wsuId = null;
if (wsuIdAttribute != null) {
wsuId = wsuIdAttribute.getAttributeValue();
}
result.add(createEncryptionPart(e.getLocalName(),wsuId,
part.getNamespace(), "Element"));
}
}
}
} else {
// try to find
OMElement e = header.getFirstChildWithName(new QName(part.getNamespace(), part.getName()));
if (e != null) {
if (!found.contains(e)) {
// found new (reuse wsep)
found.add(e);
OMAttribute wsuId = e.getAttribute(new QName(WSConstants.WSU_NS, "Id"));
if (wsuId != null) {
part.setEncId(wsuId.getAttributeValue());
}
result.add(part);
}
}
}
}
// ?? Search for 'Elements' here
// decide what exactly is going to be used - only the default namespaces, or the list of all declared namespaces in the message !
Set namespaces = findAllPrefixNamespaces(envelope, decNamespaces);
for (String expression : elements) {
try {
XPath xp = new AXIOMXPath(expression);
for (Object objectNamespace : namespaces) {
OMNamespace tmpNs = (OMNamespace) objectNamespace;
xp.addNamespace(tmpNs.getPrefix(), tmpNs.getNamespaceURI());
}
List selectedNodes = xp.selectNodes(envelope);
for (Object selectedNode : selectedNodes) {
OMElement e = (OMElement) selectedNode;
String localName = e.getLocalName();
String namespace = e.getNamespace() != null ? e.getNamespace().getNamespaceURI() : null;
if (sign) {
result.add(createEncryptionPart(localName, null, namespace, "Content", expression));
} else {
OMAttribute wsuIdAttribute = e.getAttribute(new QName(WSConstants.WSU_NS, "Id"));
String wsuId = null;
if (wsuIdAttribute != null) {
wsuId = wsuIdAttribute.getAttributeValue();
}
result.add(createEncryptionPart(localName, wsuId, namespace, "Element", expression));
}
}
} catch (JaxenException e) {
// This has to be changed to propagate an instance of a RampartException up
throw new RuntimeException(e);
}
}
return result;
}