001    /****************************************************************
002     * Licensed to the Apache Software Foundation (ASF) under one   *
003     * or more contributor license agreements.  See the NOTICE file *
004     * distributed with this work for additional information        *
005     * regarding copyright ownership.  The ASF licenses this file   *
006     * to you under the Apache License, Version 2.0 (the            *
007     * "License"); you may not use this file except in compliance   *
008     * with the License.  You may obtain a copy of the License at   *
009     *                                                              *
010     *   http://www.apache.org/licenses/LICENSE-2.0                 *
011     *                                                              *
012     * Unless required by applicable law or agreed to in writing,   *
013     * software distributed under the License is distributed on an  *
014     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
015     * KIND, either express or implied.  See the License for the    *
016     * specific language governing permissions and limitations      *
017     * under the License.                                           *
018     ****************************************************************/
019    
020    package org.apache.mailet.base.mail;
021    
022    import java.io.IOException;
023    import java.io.OutputStream;
024    
025    import javax.activation.ActivationDataFlavor;
026    import javax.activation.DataSource;
027    import javax.mail.MessagingException;
028    
029    
030    /**
031     * <p>Data Content Handler for...</p>
032     * <dl>
033     * <dt>MIME type name</dt><dd>multipart</dd>
034     * <dt>MIME subtype name</dt><dd>report</dd>
035     * </dl>
036     */
037    public class multipart_report extends AbstractDataContentHandler
038    {
039        /**
040         * Default constructor.
041         */
042        public multipart_report()
043        {
044            super();
045        }
046    
047        /**
048         * @see org.apache.mailet.base.mail.AbstractDataContentHandler#computeDataFlavor()
049         */
050        protected ActivationDataFlavor computeDataFlavor()
051        {
052            return new ActivationDataFlavor(MimeMultipartReport.class,
053                    "multipart/report", "Multipart Report");
054        }
055    
056        /**
057         * @see javax.activation.DataContentHandler#writeTo(java.lang.Object,
058         *      java.lang.String, java.io.OutputStream)
059         */
060        public void writeTo(Object aPart, String aMimeType, OutputStream aStream)
061                throws IOException
062        {
063            if (!(aPart instanceof MimeMultipartReport))
064                throw new IOException("Type \"" + aPart.getClass().getName()
065                        + "\" is not supported.");
066            try
067            {
068                ((MimeMultipartReport) aPart).writeTo(aStream);
069            }
070            catch (MessagingException e)
071            {
072                throw new IOException(e.getMessage());
073            }
074        }
075    
076        /**
077         * @see org.apache.mailet.base.mail.AbstractDataContentHandler#computeContent(javax.activation.DataSource)
078         */
079        protected Object computeContent(DataSource aDataSource)
080                throws MessagingException
081        {
082            return new MimeMultipartReport(aDataSource);
083        }
084    }