1 23 package org.infoglue.cms.applications.workflowtool.function.email; 24 25 import java.util.ArrayList ; 26 import java.util.Collection ; 27 import java.util.Iterator ; 28 29 import org.infoglue.cms.applications.workflowtool.function.ContentFunction; 30 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionController; 31 import org.infoglue.cms.entities.content.ContentVersion; 32 import org.infoglue.cms.entities.content.DigitalAsset; 33 34 import com.opensymphony.workflow.WorkflowException; 35 36 public class AttachmentsProvider extends ContentFunction 37 { 38 41 protected void execute() throws WorkflowException 42 { 43 setParameter(EmailFunction.ATTACHMENTS_PARAMETER, getAttachments()); 44 } 45 46 49 private Collection getAttachments() throws WorkflowException 50 { 51 final Collection digitalAssets = getDigitalAssets(); 52 final Collection attachments = new ArrayList (); 53 for(final Iterator i = digitalAssets.iterator(); i.hasNext(); ) 54 { 55 final DigitalAsset digitalAsset = (DigitalAsset) i.next(); 56 attachments.add(new DigitalAssetAttachment(digitalAsset.getAssetFileName(), digitalAsset.getAssetContentType(), digitalAsset.getAssetBytes())); 57 } 58 return attachments; 59 } 60 61 64 private Collection getDigitalAssets() throws WorkflowException 65 { 66 if(getContentVersionVO() != null) 67 { 68 try 69 { 70 final ContentVersion contentVersion = ContentVersionController.getContentVersionController().getReadOnlyContentVersionWithId(getContentVersionVO().getContentVersionId(), getDatabase()); 71 if(contentVersion != null) 72 { 73 return contentVersion.getDigitalAssets(); 74 } 75 } 76 catch(Exception e) 77 { 78 throwException(e); 79 } 80 } 81 return new ArrayList (); 82 } 83 } 84 | Popular Tags |