KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > mail > dsn > multipart_report


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_report.java 1.3 06/02/27
24  *
25  * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
26  */

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

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

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

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

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