Clover coverage report - JFox Service-Oriented Application Framework - 1.0-RC3
Coverage timestamp: 星期三 二月 15 2006 18:10:22 CST
file stats: LOC: 276   Methods: 18
NCLOC: 161   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
MailMessageImpl.java 0% 0% 0% 0%
coverage
 1   
 /**
 2   
  * @(#)MailMessageImpl.java
 3   
  * 
 4   
  * JFoxSOAF, Service-Oriented Application Framework
 5   
  * 
 6   
  * Copyright(c) JFoxSOAF Team
 7   
  * 
 8   
  * Licensed under the GNU LGPL, Version 2.1 (the "License"); 
 9   
  * you may not use this file except in compliance with the License. 
 10   
  * You may obtain a copy of the License at  
 11   
  * 
 12   
  * http://www.gnu.org/copyleft/lesser.html
 13   
  * 
 14   
  * Unless required by applicable law or agreed to in writing, software
 15   
  * distributed under the License is distributed on an "AS IS" BASIS, 
 16   
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 17   
  * See the License for the specific language governing permissions and 
 18   
  * limitations under the License. 
 19   
  * 
 20   
  * For more information, please visit:
 21   
  * http://www.jfox.cn/confluence/display/JFoxSOAF/Home
 22   
  * http://www.huihoo.org/jfox/jfoxsoaf
 23   
  */
 24   
 
 25   
 package org.huihoo.jfox.soaf.services.mail;
 26   
 
 27   
 import java.io.UnsupportedEncodingException;
 28   
 import java.util.Date;
 29   
 import java.util.List;
 30   
 
 31   
 import javax.mail.Message;
 32   
 import javax.mail.MessagingException;
 33   
 import javax.mail.Multipart;
 34   
 import javax.mail.Session;
 35   
 import javax.mail.internet.InternetAddress;
 36   
 import javax.mail.internet.MimeBodyPart;
 37   
 import javax.mail.internet.MimeMessage;
 38   
 import javax.mail.internet.MimeMultipart;
 39   
 
 40   
 import org.huihoo.jfox.soaf.exception.MailException;
 41   
 
 42   
 /**
 43   
  * <p>
 44   
  * Implementation of the MailMessage interface.
 45   
  * </p>
 46   
  * 
 47   
  * @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
 48   
  * @version $Revision: 1.1 $ $Date: 2005/05/22 06:50:11 $
 49   
  * @version Revision: 1.0
 50   
  */
 51   
 
 52   
 public class MailMessageImpl implements MailMessage {
 53   
 
 54   
     private MimeMessage mimeMessage;
 55   
 
 56   
     private static final String CONTENT_TYPE_HTML = "text/html";
 57   
 
 58   
     private static final String CONTENT_TYPE_CHARSET_SUFFIX = ";charset=";
 59   
 
 60   
     /**
 61   
      * @param session
 62   
      */
 63  0
     public MailMessageImpl(Session session) {
 64  0
         this.mimeMessage = new MimeMessage(session);
 65   
     }
 66   
 
 67   
     /**
 68   
      * @see org.huihoo.jfox.soaf.services.mail.MailMessage#setFrom(java.lang.String,
 69   
      *      java.lang.String)
 70   
      */
 71  0
     public void setFrom(String from, String personal) throws MailException {
 72  0
         try {
 73  0
             this.mimeMessage.setFrom(new InternetAddress(from, personal));
 74   
         } catch (UnsupportedEncodingException e) {
 75  0
             throw new MailException(e);
 76   
         } catch (MessagingException e) {
 77  0
             throw new MailException(e);
 78   
         }
 79   
     }
 80   
 
 81   
     /**
 82   
      * @see org.huihoo.jfox.soaf.services.mail.MailMessage#setFrom(java.lang.String)
 83   
      */
 84  0
     public void setFrom(String from) throws MailException {
 85  0
         try {
 86  0
             this.mimeMessage.setFrom(new InternetAddress(from));
 87   
         } catch (MessagingException e) {
 88  0
             throw new MailException(e);
 89   
         }
 90   
     }
 91   
 
 92   
     /**
 93   
      * @see org.huihoo.jfox.soaf.services.mail.MailMessage#setReplyTo(java.lang.String)
 94   
      */
 95  0
     public void setReplyTo(String replyTo) throws MailException {
 96  0
         try {
 97  0
             this.mimeMessage
 98   
                     .setReplyTo(new InternetAddress[] { new InternetAddress(
 99   
                             replyTo) });
 100   
         } catch (MessagingException e) {
 101  0
             throw new MailException(e);
 102   
         }
 103   
     }
 104   
 
 105   
     /**
 106   
      * @see org.huihoo.jfox.soaf.services.mail.MailMessage#setTo(java.lang.String)
 107   
      */
 108  0
     public void setTo(String to) throws MailException {
 109  0
         try {
 110  0
             this.mimeMessage.setRecipient(Message.RecipientType.TO,
 111   
                     new InternetAddress(to));
 112   
         } catch (MessagingException e) {
 113  0
             throw new MailException(e);
 114   
         }
 115   
     }
 116   
 
 117   
     /**
 118   
      * @see org.huihoo.jfox.soaf.services.mail.MailMessage#setTo(java.util.List)
 119   
      */
 120  0
     public void setTo(List toList) throws MailException {
 121  0
         try {
 122  0
             this.mimeMessage.setRecipients(Message.RecipientType.TO,
 123   
                     toInternetAddressArray(toList));
 124   
         } catch (MessagingException e) {
 125  0
             throw new MailException(e);
 126   
         }
 127   
 
 128   
     }
 129   
 
 130   
     /**
 131   
      * @see org.huihoo.jfox.soaf.services.mail.MailMessage#setCc(java.lang.String)
 132   
      */
 133  0
     public void setCc(String cc) throws MailException {
 134  0
         try {
 135  0
             this.mimeMessage.setRecipient(Message.RecipientType.CC,
 136   
                     new InternetAddress(cc));
 137   
         } catch (MessagingException e) {
 138  0
             throw new MailException(e);
 139   
         }
 140   
     }
 141   
 
 142   
     /**
 143   
      * @see org.huihoo.jfox.soaf.services.mail.MailMessage#setCc(java.util.List)
 144   
      */
 145  0
     public void setCc(List ccList) throws MailException {
 146  0
         try {
 147  0
             this.mimeMessage.setRecipients(Message.RecipientType.CC,
 148   
                     toInternetAddressArray(ccList));
 149   
         } catch (MessagingException e) {
 150  0
             throw new MailException(e);
 151   
         }
 152   
     }
 153   
 
 154   
     /**
 155   
      * @see org.huihoo.jfox.soaf.services.mail.MailMessage#setBcc(java.lang.String)
 156   
      */
 157  0
     public void setBcc(String bcc) throws MailException {
 158  0
         try {
 159  0
             this.mimeMessage.setRecipient(Message.RecipientType.BCC,
 160   
                     new InternetAddress(bcc));
 161   
         } catch (MessagingException e) {
 162  0
             throw new MailException(e);
 163   
         }
 164   
     }
 165   
 
 166   
     /**
 167   
      * @see org.huihoo.jfox.soaf.services.mail.MailMessage#setBcc(java.util.List)
 168   
      */
 169  0
     public void setBcc(List bccList) throws MailException {
 170  0
         try {
 171  0
             this.mimeMessage.setRecipients(Message.RecipientType.BCC,
 172   
                     toInternetAddressArray(bccList));
 173   
         } catch (MessagingException e) {
 174  0
             throw new MailException(e);
 175   
         }
 176   
     }
 177   
 
 178   
     /**
 179   
      * @see org.huihoo.jfox.soaf.services.mail.MailMessage#setSentDate(java.util.Date)
 180   
      */
 181  0
     public void setSentDate(Date sentDate) throws MailException {
 182  0
         try {
 183  0
             this.mimeMessage.setSentDate(sentDate);
 184   
         } catch (MessagingException e) {
 185  0
             throw new MailException(e);
 186   
         }
 187   
 
 188   
     }
 189   
 
 190   
     /**
 191   
      * @see org.huihoo.jfox.soaf.services.mail.MailMessage#setSubject(java.lang.String)
 192   
      */
 193  0
     public void setSubject(String subject) throws MailException {
 194  0
         try {
 195  0
             this.mimeMessage.setSubject(subject);
 196   
         } catch (MessagingException e) {
 197  0
             throw new MailException(e);
 198   
         }
 199   
     }
 200   
 
 201   
     /**
 202   
      * @see org.huihoo.jfox.soaf.services.mail.MailMessage#setSubject(java.lang.String)
 203   
      */
 204  0
     public void setSubject(String subject, String charset) throws MailException {
 205  0
         try {
 206  0
             this.mimeMessage.setSubject(subject, charset);
 207   
         } catch (MessagingException e) {
 208  0
             throw new MailException(e);
 209   
         }
 210   
     }
 211   
 
 212   
     /**
 213   
      * @see org.huihoo.jfox.soaf.services.mail.MailMessage#setText(java.lang.String)
 214   
      */
 215  0
     public void setText(String text, boolean html) throws MailException {
 216  0
         try {
 217  0
             Multipart multipt = new MimeMultipart();
 218  0
             MimeBodyPart msgbody = new MimeBodyPart();
 219  0
             msgbody.setText(text);
 220  0
             multipt.addBodyPart(msgbody);
 221  0
             if (html) {
 222  0
                 this.mimeMessage.setContent(multipt, CONTENT_TYPE_HTML);
 223   
             } else {
 224  0
                 this.mimeMessage.setContent(multipt);
 225   
             }
 226   
         } catch (MessagingException e) {
 227  0
             throw new MailException(e);
 228   
         }
 229   
     }
 230   
 
 231   
     /**
 232   
      * @see org.huihoo.jfox.soaf.services.mail.MailMessage#setText(java.lang.String)
 233   
      */
 234  0
     public void setText(String text, String charset, boolean html)
 235   
             throws MailException {
 236  0
         try {
 237  0
             Multipart multipt = new MimeMultipart();
 238  0
             MimeBodyPart msgbody = new MimeBodyPart();
 239  0
             msgbody.setText(text, charset);
 240  0
             multipt.addBodyPart(msgbody);
 241  0
             if (html) {
 242  0
                 this.mimeMessage.setContent(multipt, CONTENT_TYPE_HTML
 243   
                         + CONTENT_TYPE_CHARSET_SUFFIX + charset);
 244   
             } else {
 245  0
                 this.mimeMessage.setContent(multipt);
 246   
             }
 247   
         } catch (MessagingException e) {
 248  0
             throw new MailException(e);
 249   
         }
 250   
     }
 251   
 
 252  0
     protected InternetAddress[] toInternetAddressArray(List aList) {
 253  0
         InternetAddress[] ia = (InternetAddress[]) aList
 254   
                 .toArray(new InternetAddress[0]);
 255  0
         return ia;
 256   
     }
 257   
 
 258   
     /**
 259   
      * @see org.huihoo.jfox.soaf.services.mail.MailMessage#setContentLanguage(java.lang.String[])
 260   
      */
 261  0
     public void setContentLanguage(String[] langs) throws MailException {
 262  0
         try {
 263  0
             this.mimeMessage.setContentLanguage(langs);
 264   
         } catch (MessagingException e) {
 265  0
             throw new MailException(e);
 266   
         }
 267   
     }
 268   
 
 269   
     /**
 270   
      * see org.huihoo.jfox.soaf.services.mail.MailMessage#getMimeMessage()
 271   
      */
 272  0
     public MimeMessage getMimeMessage() {
 273  0
         return this.mimeMessage;
 274   
     }
 275   
 
 276   
 }