View Javadoc

1   /************************************************************************
2    * Copyright (c) 2003-2006 The Apache Software Foundation.             *
3    * All rights reserved.                                                *
4    * ------------------------------------------------------------------- *
5    * Licensed under the Apache License, Version 2.0 (the "License"); you *
6    * may not use this file except in compliance with the License. You    *
7    * may obtain a copy of the License at:                                *
8    *                                                                     *
9    *     http://www.apache.org/licenses/LICENSE-2.0                      *
10   *                                                                     *
11   * Unless required by applicable law or agreed to in writing, software *
12   * distributed under the License is distributed on an "AS IS" BASIS,   *
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
14   * implied.  See the License for the specific language governing       *
15   * permissions and limitations under the License.                      *
16   ***********************************************************************/
17  package org.apache.james.util.mail.handlers;
18  
19  import java.io.IOException;
20  import java.io.OutputStream;
21  
22  import javax.activation.ActivationDataFlavor;
23  import javax.activation.DataSource;
24  import javax.mail.MessagingException;
25  
26  import org.apache.james.util.mail.MimeMultipartReport;
27  
28  /***
29   * <p>Data Content Handler for...</p>
30   * <dl>
31   * <dt>MIME type name</dt><dd>multipart</dd>
32   * <dt>MIME subtype name</dt><dd>report</dd>
33   * </dl>
34   */
35  public class multipart_report extends AbstractDataContentHandler
36  {
37      /***
38       * Default constructor.
39       */
40      public multipart_report()
41      {
42          super();
43      }
44  
45      /***
46       * @see org.apache.james.util.mail.handlers.AbstractDataContentHandler#computeDataFlavor()
47       */
48      protected ActivationDataFlavor computeDataFlavor()
49      {
50          return new ActivationDataFlavor(MimeMultipartReport.class,
51                  "multipart/report", "Multipart Report");
52      }
53  
54      /***
55       * @see javax.activation.DataContentHandler#writeTo(java.lang.Object,
56       *      java.lang.String, java.io.OutputStream)
57       */
58      public void writeTo(Object aPart, String aMimeType, OutputStream aStream)
59              throws IOException
60      {
61          if (!(aPart instanceof MimeMultipartReport))
62              throw new IOException("Type \"" + aPart.getClass().getName()
63                      + "\" is not supported.");
64          try
65          {
66              ((MimeMultipartReport) aPart).writeTo(aStream);
67          }
68          catch (MessagingException e)
69          {
70              throw new IOException(e.getMessage());
71          }
72      }
73  
74      /***
75       * @see org.apache.james.util.mail.handlers.AbstractDataContentHandler#computeContent(javax.activation.DataSource)
76       */
77      protected Object computeContent(DataSource aDataSource)
78              throws MessagingException
79      {
80          return new MimeMultipartReport(aDataSource);
81      }
82  }