KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > mail > handlers > multipart_mixed


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21
22 /*
23  * @(#)multipart_mixed.java 1.10 05/08/29
24  *
25  * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved.
26  */

27 package com.sun.mail.handlers;
28
29 import java.io.*;
30 import java.awt.datatransfer.DataFlavor JavaDoc;
31 import javax.activation.*;
32 import javax.mail.MessagingException JavaDoc;
33 import javax.mail.internet.*;
34
35
36 public class multipart_mixed implements DataContentHandler {
37     private ActivationDataFlavor myDF = new ActivationDataFlavor(
38         javax.mail.internet.MimeMultipart JavaDoc.class,
39         "multipart/mixed",
40         "Multipart");
41
42     /**
43      * Return the DataFlavors for this <code>DataContentHandler</code>.
44      *
45      * @return The DataFlavors
46      */

47     public DataFlavor JavaDoc[] getTransferDataFlavors() { // throws Exception;
48
return new DataFlavor JavaDoc[] { myDF };
49     }
50
51     /**
52      * Return the Transfer Data of type DataFlavor from InputStream.
53      *
54      * @param df The DataFlavor
55      * @param ins The InputStream corresponding to the data
56      * @return String object
57      */

58     public Object JavaDoc getTransferData(DataFlavor JavaDoc df, DataSource ds) {
59     // use myDF.equals to be sure to get ActivationDataFlavor.equals,
60
// which properly ignores Content-Type parameters in comparison
61
if (myDF.equals(df))
62         return getContent(ds);
63     else
64         return null;
65     }
66     
67     /**
68      * Return the content.
69      */

70     public Object JavaDoc getContent(DataSource ds) {
71     try {
72         return new MimeMultipart(ds);
73     } catch (MessagingException JavaDoc e) {
74         return null;
75     }
76     }
77     
78     /**
79      * Write the object to the output stream, using the specific MIME type.
80      */

81     public void writeTo(Object JavaDoc obj, String JavaDoc mimeType, OutputStream os)
82             throws IOException {
83     if (obj instanceof MimeMultipart) {
84         try {
85         ((MimeMultipart)obj).writeTo(os);
86         } catch (MessagingException JavaDoc e) {
87         throw new IOException(e.toString());
88         }
89     }
90     }
91 }
92
Popular Tags