1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| package org.apache.geronimo.mail.handlers; |
17 |
| |
18 |
| import javax.activation.ActivationDataFlavor; |
19 |
| import javax.activation.DataContentHandler; |
20 |
| import javax.activation.DataSource; |
21 |
| import java.awt.datatransfer.DataFlavor; |
22 |
| import java.io.IOException; |
23 |
| import java.io.OutputStream; |
24 |
| |
25 |
| import javax.mail.internet.MimeMultipart; |
26 |
| import javax.mail.internet.MimeMessage; |
27 |
| import javax.mail.MessagingException; |
28 |
| |
29 |
| public class MultipartHandler implements DataContentHandler { |
30 |
| |
31 |
| |
32 |
| |
33 |
| ActivationDataFlavor dataFlavor; |
34 |
| |
35 |
2
| public MultipartHandler(){
|
36 |
2
| dataFlavor = new ActivationDataFlavor(javax.mail.internet.MimeMultipart.class, "multipart/mixed", "Multipart");
|
37 |
| } |
38 |
| |
39 |
| |
40 |
| |
41 |
| |
42 |
| |
43 |
| |
44 |
0
| public MultipartHandler(ActivationDataFlavor dataFlavor) {
|
45 |
0
| this.dataFlavor = dataFlavor;
|
46 |
| } |
47 |
| |
48 |
| |
49 |
| |
50 |
| |
51 |
| |
52 |
| |
53 |
0
| protected ActivationDataFlavor getDF() {
|
54 |
0
| return dataFlavor;
|
55 |
| } |
56 |
| |
57 |
| |
58 |
| |
59 |
| |
60 |
| |
61 |
| |
62 |
0
| public DataFlavor[] getTransferDataFlavors() {
|
63 |
0
| return (new DataFlavor[]{dataFlavor});
|
64 |
| } |
65 |
| |
66 |
| |
67 |
| |
68 |
| |
69 |
| |
70 |
| |
71 |
| |
72 |
| |
73 |
| |
74 |
0
| public Object getTransferData(DataFlavor dataflavor, DataSource datasource)
|
75 |
| throws IOException { |
76 |
0
| if (getDF().equals(dataflavor)) {
|
77 |
0
| return getContent(datasource);
|
78 |
| } |
79 |
0
| return null;
|
80 |
| } |
81 |
| |
82 |
| |
83 |
| |
84 |
| |
85 |
| |
86 |
| |
87 |
| |
88 |
| |
89 |
2
| public Object getContent(DataSource datasource) throws IOException {
|
90 |
2
| try {
|
91 |
2
| return new MimeMultipart(datasource);
|
92 |
| } catch (MessagingException e) { |
93 |
| |
94 |
| |
95 |
0
| return null;
|
96 |
| } |
97 |
| } |
98 |
| |
99 |
| |
100 |
| |
101 |
| |
102 |
| |
103 |
| |
104 |
| |
105 |
| |
106 |
| |
107 |
1
| public void writeTo(Object object, String s, OutputStream outputstream) throws IOException {
|
108 |
| |
109 |
1
| if (object instanceof MimeMultipart) {
|
110 |
1
| try {
|
111 |
1
| ((MimeMultipart)object).writeTo(outputstream);
|
112 |
| } catch (MessagingException e) { |
113 |
| |
114 |
0
| throw new IOException("Exception writing MimeMultipart: " + e.toString());
|
115 |
| } |
116 |
| } |
117 |
| } |
118 |
| } |