View Javadoc

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