KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > info > magnolia > cms > mail > templates > MailAttachment


1 package info.magnolia.cms.mail.templates;
2
3 import java.io.File JavaDoc;
4 import java.net.URL JavaDoc;
5
6 import org.apache.commons.lang.StringUtils;
7
8
9 /**
10  * Date: Apr 1, 2006 Time: 8:38:07 PM
11  * @author <a HREF="mailto:niko@macnica.com">Nicolas Modrzyk</a>
12  */

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