final SecurePart securePart = securePartEntry.getValue();
final String externalReference = securePart.getExternalReference();
if (externalReference != null) {
ResourceResolver resourceResolver = ResourceResolverMapper.getResourceResolver(externalReference, outputProcessorChain.getDocumentContext().getBaseURI());
DigestOutputStream digestOutputStream = createMessageDigestOutputStream(securePart.getDigestMethod());
InputStream inputStream = resourceResolver.getInputStreamFromExternalReference();
SignaturePartDef signaturePartDef = new SignaturePartDef();
signaturePartDef.setSecurePart(securePart);
signaturePartDef.setSigRefId(externalReference);
signaturePartDef.setExternalResource(true);
signaturePartDef.setTransforms(securePart.getTransforms());
String digestMethod = securePart.getDigestMethod();
if (digestMethod == null) {
digestMethod = getSecurityProperties().getSignatureDigestAlgorithm();
}
signaturePartDef.setDigestAlgo(digestMethod);
signaturePartDefs.add(signaturePartDef);
try {
if (securePart.getTransforms() != null) {
signaturePartDef.setExcludeVisibleC14Nprefixes(true);
Transformer transformer = buildTransformerChain(digestOutputStream, signaturePartDef, null);
transformer.transform(inputStream);
transformer.doFinal();
} else {
XMLSecurityUtils.copy(inputStream, digestOutputStream);
}
digestOutputStream.close();
} catch (IOException e) {
throw new XMLSecurityException(e);
}
String calculatedDigest = new String(Base64.encodeBase64(digestOutputStream.getDigestValue()));
if (logger.isDebugEnabled()) {
logger.debug("Calculated Digest: " + calculatedDigest);
}
signaturePartDef.setDigestValue(calculatedDigest);