}
ArrayList clonedTransformList = (ArrayList) transformList.clone();
if (exclTransformToBeAdded) {
// exc-14-nl must be one of the last transforms under ReferenceList by default.
String transformAlgo = MessageConstants.TRANSFORM_C14N_EXCL_OMIT_COMMENTS;
ExcC14NParameterSpec spec = null;
if((featureBinding != null && featureBinding.isBSP()) || !disableInclusivePrefix){
spec = new ExcC14NParameterSpec(getReferenceNamespacePrefixes(nodeRef));
}
Transform transform = signatureFactory.newTransform(transformAlgo,spec);
clonedTransformList.add(transform);
}
boolean w3cElem = false;
// Assume only elements with wsu:Id are signed
String id = ((Element)nodeRef).getAttributeNS(MessageConstants.WSU_NS, "Id");
if(id == null || id.equals("")){
if(nodeRef.getNamespaceURI() == MessageConstants.DSIG_NS ||
nodeRef.getNamespaceURI() == MessageConstants.XENC_NS){
w3cElem = true;
id = ((Element)nodeRef).getAttribute("Id");
}
}
if (id == null || id.equals("")) {
id = secureMessage.generateId();
if(!verify){
if(w3cElem){
XMLUtil.setIdAttr((Element)nodeRef, id);
}else{
XMLUtil.setWsuIdAttr((Element)nodeRef, id);
}
}else{
//add to context. dont modify the message.
elementCache.put(id, nodeRef);
}
}
if(logger.isLoggable(Level.FINEST))
logger.log(Level.FINEST, "SignedInfo val id "+id);
targetURI = "#"+id;
byte [] digestValue = fpContext.getDigestValue();
Reference reference = null;
if(!verify && digestValue != null){
reference = signatureFactory.newReference(targetURI,digestMethod,clonedTransformList,null,null,digestValue);
}else{
reference = signatureFactory.newReference(targetURI,digestMethod,clonedTransformList,null,null);
}
references.add(reference);
}
continue;
}else if(signatureType ==SignatureTarget.TARGET_TYPE_VALUE_URI){
targetURI = signatureTarget.getValue();
if(targetURI == null){
targetURI="";
}
if(targetURI == MessageConstants.PROCESS_ALL_ATTACHMENTS){
Iterator itr = secureMessage.getAttachments();
if ( !itr.hasNext()) {
logger.log(Level.SEVERE, LogStringsMessages.WSS_1372_NO_ATTACHMENT_FOUND());
throw new XWSSecurityException("No attachment present in the message");
//logger.log(Level.WARNING, "No Attachment Part present in the message to be secured");
//continue;
}
while(itr.hasNext()){
String cid = null;
AttachmentPart ap = (AttachmentPart)itr.next();
String _cid = ap.getContentId();
if (_cid.charAt(0) == '<' && _cid.charAt(_cid.length()-1) == '>'){
int lindex = _cid.lastIndexOf('>');
int sindex = _cid.indexOf('<');
if(lindex < sindex || lindex == sindex){
//log error
logger.log(Level.SEVERE,LogStringsMessages.WSS_1303_CID_ERROR());
}
cid = "cid:"+_cid.substring(sindex+1,lindex);
}else{
cid = "cid:"+_cid;
}
Reference reference = signatureFactory.newReference(cid,digestMethod,transformList,null,null);
references.add(reference);
}
continue;
}else{
if (exclTransformToBeAdded) {
// exc-14-n must be one of the last transforms under ReferenceList by default.
// String transformAlgo = MessageConstants.TRANSFORM_C14N_EXCL_OMIT_COMMENTS;
// ExcC14NParameterSpec spec = null;
// Transform transform = signatureFactory.newTransform(transformAlgo,spec);
// transformList.add(transform);
SOAPElement dataElement = null;
if (featureBinding != null && featureBinding.isBSP()) {
// try {
String _uri = targetURI;
if(targetURI.length() > 0 && targetURI.charAt(0)=='#'){
_uri = targetURI.substring(1);
}
dataElement =(SOAPElement) secureMessage.getElementById(_uri);
// } catch (TransformerException te) {
// logger.log(Level.SEVERE, "WSS1373.failedto.resolve.elementbyID", te);
// throw new XWSSecurityException(te.getMessage(), te);
// }
}
String transformAlgo = MessageConstants.TRANSFORM_C14N_EXCL_OMIT_COMMENTS;
ExcC14NParameterSpec spec = null;
if(dataElement != null && !disableInclusivePrefix){
spec = new ExcC14NParameterSpec(getReferenceNamespacePrefixes(dataElement));
}
Transform transform = signatureFactory.newTransform(transformAlgo,spec);
transformList.add(transform);
}
if(targetURI.equals(SignatureTarget.ALL_MESSAGE_HEADERS)){