1 23 package org.infoglue.cms.applications.workflowtool.function; 24 25 import java.io.ByteArrayInputStream ; 26 import java.io.InputStream ; 27 import java.util.ArrayList ; 28 import java.util.Collection ; 29 import java.util.Iterator ; 30 31 import org.apache.log4j.Logger; 32 import org.infoglue.cms.applications.workflowtool.condition.InfoglueCondition; 33 import org.infoglue.cms.applications.workflowtool.function.email.Attachment; 34 import org.infoglue.cms.controllers.kernel.impl.simple.DigitalAssetController; 35 import org.infoglue.cms.entities.content.DigitalAssetVO; 36 import org.infoglue.cms.util.CmsPropertyHandler; 37 38 import com.opensymphony.workflow.WorkflowException; 39 40 43 public class Attach extends ContentFunction 44 { 45 private final static Logger logger = Logger.getLogger(Attach.class.getName()); 46 47 50 private static final String ATTACHMENTS_PARAMETER = "attachments"; 51 52 55 private Collection attachments; 56 57 60 public Attach() 61 { 62 super(); 63 } 64 65 68 protected void execute() throws WorkflowException 69 { 70 if(getContentVersion() != null) 71 { 72 try 73 { 74 for(final Iterator i = attachments.iterator(); i.hasNext(); ) 75 { 76 final Attachment attachment = (Attachment) i.next(); 77 logger.debug("Adding attachment : " + attachment); 78 DigitalAssetController.create(createDigitalAssetVO(attachment), getInputStream(attachment), getContentVersion(), getDatabase()); 79 } 80 } 81 catch(Exception e) 82 { 83 throwException(e); 84 } 85 } 86 } 87 88 91 private DigitalAssetVO createDigitalAssetVO(final Attachment attachment) 92 { 93 final DigitalAssetVO digitalAssetVO = new DigitalAssetVO(); 94 digitalAssetVO.setAssetContentType(attachment.getContentType()); 95 digitalAssetVO.setAssetKey(attachment.getName()); 96 digitalAssetVO.setAssetFileName(attachment.getName()); 97 digitalAssetVO.setAssetFilePath(getDigitalAssetsDirectory()); 98 digitalAssetVO.setAssetFileSize(new Integer (attachment.getSize())); 99 return digitalAssetVO; 100 } 101 102 105 private InputStream getInputStream(final Attachment attachment) 106 { 107 return new ByteArrayInputStream (attachment.getBytes()); 108 } 109 110 113 private String getDigitalAssetsDirectory() 114 { 115 return CmsPropertyHandler.getDigitalAssetPath(); 116 } 117 118 124 protected void initialize() throws WorkflowException 125 { 126 super.initialize(); 127 this.attachments = (Collection ) getParameter(ATTACHMENTS_PARAMETER, new ArrayList ()); 128 } 129 } 130 | Popular Tags |