Clover coverage report - Maven Clover report
Coverage timestamp: Sun Aug 20 2006 04:01:04 PDT
file stats: LOC: 118   Methods: 7
NCLOC: 48   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
MultipartHandler.java 25% 42.9% 42.9% 40%
coverage coverage
 1    /*
 2    * Copyright 2004,2005 The Apache Software Foundation.
 3    *
 4    * Licensed under the Apache License, Version 2.0 (the "License");
 5    * you may not use this file except in compliance with the License.
 6    * You may obtain a copy of the License at
 7    *
 8    * http://www.apache.org/licenses/LICENSE-2.0
 9    *
 10    * Unless required by applicable law or agreed to in writing, software
 11    * distributed under the License is distributed on an "AS IS" BASIS,
 12    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13    * See the License for the specific language governing permissions and
 14    * limitations under the License.
 15    */
 16    package org.apache.geronimo.mail.handlers;
 17   
 18    import javax.activation.ActivationDataFlavor;
 19    import javax.activation.DataContentHandler;
 20    import javax.activation.DataSource;
 21    import java.awt.datatransfer.DataFlavor;
 22    import java.io.IOException;
 23    import java.io.OutputStream;
 24   
 25    import javax.mail.internet.MimeMultipart;
 26    import javax.mail.internet.MimeMessage;
 27    import javax.mail.MessagingException;
 28   
 29    public class MultipartHandler implements DataContentHandler {
 30    /**
 31    * Field dataFlavor
 32    */
 33    ActivationDataFlavor dataFlavor;
 34   
 35  2 public MultipartHandler(){
 36  2 dataFlavor = new ActivationDataFlavor(javax.mail.internet.MimeMultipart.class, "multipart/mixed", "Multipart");
 37    }
 38   
 39    /**
 40    * Constructor TextHandler
 41    *
 42    * @param dataFlavor
 43    */
 44  0 public MultipartHandler(ActivationDataFlavor dataFlavor) {
 45  0 this.dataFlavor = dataFlavor;
 46    }
 47   
 48    /**
 49    * Method getDF
 50    *
 51    * @return dataflavor
 52    */
 53  0 protected ActivationDataFlavor getDF() {
 54  0 return dataFlavor;
 55    }
 56   
 57    /**
 58    * Method getTransferDataFlavors
 59    *
 60    * @return dataflavors
 61    */
 62  0 public DataFlavor[] getTransferDataFlavors() {
 63  0 return (new DataFlavor[]{dataFlavor});
 64    }
 65   
 66    /**
 67    * Method getTransferData
 68    *
 69    * @param dataflavor
 70    * @param datasource
 71    * @return
 72    * @throws IOException
 73    */
 74  0 public Object getTransferData(DataFlavor dataflavor, DataSource datasource)
 75    throws IOException {
 76  0 if (getDF().equals(dataflavor)) {
 77  0 return getContent(datasource);
 78    }
 79  0 return null;
 80    }
 81   
 82    /**
 83    * Method getContent
 84    *
 85    * @param datasource
 86    * @return
 87    * @throws IOException
 88    */
 89  2 public Object getContent(DataSource datasource) throws IOException {
 90  2 try {
 91  2 return new MimeMultipart(datasource);
 92    } catch (MessagingException e) {
 93    // if there is a syntax error from the datasource parsing, the content is
 94    // just null.
 95  0 return null;
 96    }
 97    }
 98   
 99    /**
 100    * Method writeTo
 101    *
 102    * @param object
 103    * @param s
 104    * @param outputstream
 105    * @throws IOException
 106    */
 107  1 public void writeTo(Object object, String s, OutputStream outputstream) throws IOException {
 108    // if this object is a MimeMultipart, then delegate to the part.
 109  1 if (object instanceof MimeMultipart) {
 110  1 try {
 111  1 ((MimeMultipart)object).writeTo(outputstream);
 112    } catch (MessagingException e) {
 113    // we need to transform any exceptions into an IOException.
 114  0 throw new IOException("Exception writing MimeMultipart: " + e.toString());
 115    }
 116    }
 117    }
 118    }