1 package info.magnolia.cms.mail.templates; 2 3 import java.io.File ; 4 import java.net.URL ; 5 6 import org.apache.commons.lang.StringUtils; 7 8 9 13 public class MailAttachment { 14 15 private static final String ATTACHMENT_INLINE = "inline"; 16 17 private static final String ATTACHMENT_NORMAL = "normal"; 18 19 private static final String FILE_URL_PREFIX = "file://"; 20 21 String description; 22 23 String disposition; 24 25 String name; 26 27 URL url; 28 29 public MailAttachment(File file, String name, String description, String disposition) { 30 this.setPath(file.getAbsolutePath()); 31 this.name = name; 32 this.description = description; 33 this.disposition = disposition; 34 } 35 36 public MailAttachment(URL url, String _name, String _description, String _disposition) { 37 this.url = url; 38 this.name = _name; 39 this.description = _description; 40 this.disposition = _disposition; 41 } 42 43 public MailAttachment(URL _url, String name) { 44 this.url = _url; 45 this.name = name; 46 this.disposition = ATTACHMENT_INLINE; 47 this.description = StringUtils.EMPTY; 48 } 49 50 public java.lang.String getDescription() { 51 return this.description; 52 } 53 54 public java.lang.String getDisposition() { 55 return this.disposition; 56 } 57 58 public java.lang.String getName() { 59 return this.name; 60 } 61 62 public java.lang.String getPath() { 63 return this.url.getFile(); 64 } 65 66 public java.net.URL getURL() { 67 if (this.url.getProtocol().startsWith("file:")) { 68 try { 69 return new URL ("file://" + this.url.toExternalForm()); 70 } 71 catch (Exception e) { 72 return null; 73 } 74 } 75 76 return this.url; 77 78 } 79 80 public java.io.File getFile() { 81 return new File (this.url.getFile()); 82 } 83 84 public void setDescription(java.lang.String desc) { 85 this.description = desc; 86 } 87 88 public void setDisposition(java.lang.String aDisposition) { 89 this.disposition = aDisposition; 90 } 91 92 public void setName(java.lang.String aName) { 93 this.name = aName; 94 } 95 96 public void setPath(java.lang.String aPath) { 97 try { 98 this.url = new URL (FILE_URL_PREFIX + aPath); 99 } 100 catch (Exception e) { 101 e.printStackTrace(); 102 this.url = null; 103 } 104 } 105 106 public void setURL(java.net.URL aUrl) { 107 this.url = aUrl; 108 } 109 110 public String getContentType() { 111 return MgnlEmail.map.getContentType(this.getPath()); 112 } 113 114 public String getFileName() { 115 return new File (this.url.getFile()).getName(); 116 } 117 118 } 119 | Popular Tags |