if (ICompleteReportingTask.class.isAssignableFrom(taskClass)) {
((ICompleteReportingTask) resultTask).setCompleteSOAPAction(completeSOAPAction);
}
if (ITaskWithAttachments.class.isAssignableFrom(taskClass)) {
ITaskWithAttachments taskWithAttachments = (ITaskWithAttachments) resultTask;
if (attachmentsElement != null) {
for (int i = 0; i < attachmentsElement.sizeOfAttachmentArray(); i++) {
com.intalio.bpms.workflow.taskManagementServices20051109.Attachment attachmentElement = attachmentsElement.getAttachmentArray(i);
if (attachmentElement != null) {
// The following line has been added to handle the case
// where an attachment element is present
// but do not contain any data: no title,
// nodescription , ect...
// The reason why is this is added is to
// handle the initial initialization on
// Designer
// In which designer generates by default an
// attachment element as a part of the
// initialization of the message
// even if no attachment is used
// TODO: When Designer and Server will
// support "lazy initialization", this line
// can be omitted
XmlCursor attCursor = attachmentElement.newCursor();
try {
if (attCursor.getTextValue().trim().length() != 0) {
com.intalio.bpms.workflow.taskManagementServices20051109.AttachmentMetadata attachmentMetadata = attachmentElement
.getAttachmentMetadata();
AttachmentMetadata metadata = new AttachmentMetadata();
String mimeType = attachmentMetadata.getMimeType();
if (mimeType != null) {
metadata.setMimeType(mimeType);
}
String fileName = attachmentMetadata.getFileName();
if (fileName != null)
metadata.setFileName(fileName);
String title = attachmentMetadata.getTitle();
if (title != null)
metadata.setTitle(title);
String description2 = attachmentMetadata.getDescription();
if (description2 != null)
metadata.setDescription(description2);
try {
Calendar cal = attachmentMetadata.getCreationDate();
if ((cal != null)) {
metadata.setCreationDate(new XsdDateTime(cal.toString()).getTime());
}
} catch (Exception e) {
_logger.warn("Error in unmarshalling creation date in attachment from metadata");
metadata.setCreationDate(new Date());
}
String payloadURLStr = attachmentElement.getPayloadUrl();
URL payloadURL;
try {
payloadURL = new URL(payloadURLStr);
} catch (MalformedURLException e) {
throw new InvalidInputFormatException(e);
}
Attachment attachment = new Attachment(metadata, payloadURL);
taskWithAttachments.addAttachment(attachment);
}
} finally {
attCursor.dispose();
}
}