1 31 32 package org.opencms.mail; 33 34 import org.opencms.file.CmsFile; 35 import org.opencms.file.CmsObject; 36 import org.opencms.file.CmsResource; 37 import org.opencms.main.CmsException; 38 import org.opencms.main.OpenCms; 39 40 import java.io.ByteArrayInputStream ; 41 import java.io.ByteArrayOutputStream ; 42 import java.io.InputStream ; 43 import java.io.OutputStream ; 44 45 import javax.activation.DataSource ; 46 47 57 public class CmsVfsDataSource implements DataSource { 58 59 60 private String m_contentType; 61 62 63 private CmsFile m_file; 64 65 73 public CmsVfsDataSource(CmsObject cms, CmsResource resource) 74 throws CmsException { 75 76 m_file = CmsFile.upgrade(resource, cms); 77 m_contentType = OpenCms.getResourceManager().getMimeType( 79 m_file.getName(), cms.getRequestContext().getEncoding()); 80 } 81 82 85 public String getContentType() { 86 87 return m_contentType; 88 } 89 90 95 public InputStream getInputStream() { 96 97 return new ByteArrayInputStream (m_file.getContents()); 98 } 99 100 105 public String getName() { 106 107 return m_file.getRootPath(); 108 } 109 110 117 public OutputStream getOutputStream() { 118 119 return new ByteArrayOutputStream (); 121 } 122 } | Popular Tags |