| 1 19 20 package gnu.mail.handler; 21 22 import java.awt.datatransfer.DataFlavor ; 23 import java.awt.datatransfer.UnsupportedFlavorException ; 24 import java.io.*; 25 import javax.activation.*; 26 import javax.mail.MessagingException ; 27 import javax.mail.internet.MimeMultipart ; 28 29 36 public abstract class Multipart 37 implements DataContentHandler 38 { 39 40 43 protected DataFlavor flavor; 44 45 50 protected Multipart(String mimeType, String description) 51 { 52 flavor = new ActivationDataFlavor(javax.mail.internet.MimeMultipart .class, 53 mimeType, description); 54 } 55 56 61 public DataFlavor [] getTransferDataFlavors() 62 { 63 DataFlavor [] flavors = new DataFlavor [1]; 64 flavors[0] = flavor; 65 return flavors; 66 } 67 68 76 public Object getTransferData(DataFlavor flavor, DataSource source) 77 throws UnsupportedFlavorException , IOException 78 { 79 if (this.flavor.equals(flavor)) 80 return getContent(source); 81 return null; 82 } 83 84 91 public Object getContent(DataSource source) 92 throws IOException 93 { 94 try 95 { 96 return new MimeMultipart (source); 97 } 98 catch (MessagingException e) 99 { 100 101 throw new IOException(e.getMessage()); 102 } 103 } 104 105 112 public void writeTo(Object object, String mimeType, OutputStream out) 113 throws IOException 114 { 115 if (object instanceof MimeMultipart ) 116 { 117 try 118 { 119 ((MimeMultipart )object).writeTo(out); 120 } 121 catch (MessagingException e) 122 { 123 124 throw new IOException(e.getMessage()); 125 } 126 } 127 else 128 throw new UnsupportedDataTypeException(); 129 } 130 131 } 132 | Popular Tags |