Clover coverage report - Ant Coverage
Coverage timestamp: Tue Apr 8 2003 20:43:55 EST
file stats: LOC: 180   Methods: 9
NCLOC: 54   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
Message.java 0% 0% 0% 0%
 1   
 /*
 2   
  * The Apache Software License, Version 1.1
 3   
  *
 4   
  * Copyright (c) 2002-2003 The Apache Software Foundation.  All rights
 5   
  * reserved.
 6   
  *
 7   
  * Redistribution and use in source and binary forms, with or without
 8   
  * modification, are permitted provided that the following conditions
 9   
  * are met:
 10   
  *
 11   
  * 1. Redistributions of source code must retain the above copyright
 12   
  *    notice, this list of conditions and the following disclaimer.
 13   
  *
 14   
  * 2. Redistributions in binary form must reproduce the above copyright
 15   
  *    notice, this list of conditions and the following disclaimer in
 16   
  *    the documentation and/or other materials provided with the
 17   
  *    distribution.
 18   
  *
 19   
  * 3. The end-user documentation included with the redistribution, if
 20   
  *    any, must include the following acknowlegement:
 21   
  *       "This product includes software developed by the
 22   
  *        Apache Software Foundation (http://www.apache.org/)."
 23   
  *    Alternately, this acknowlegement may appear in the software itself,
 24   
  *    if and wherever such third-party acknowlegements normally appear.
 25   
  *
 26   
  * 4. The names "Ant" and "Apache Software
 27   
  *    Foundation" must not be used to endorse or promote products derived
 28   
  *    from this software without prior written permission. For written
 29   
  *    permission, please contact apache@apache.org.
 30   
  *
 31   
  * 5. Products derived from this software may not be called "Apache"
 32   
  *    nor may "Apache" appear in their names without prior written
 33   
  *    permission of the Apache Group.
 34   
  *
 35   
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 36   
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 37   
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 38   
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 39   
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 40   
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 41   
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 42   
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 43   
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 44   
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 45   
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 46   
  * SUCH DAMAGE.
 47   
  * ====================================================================
 48   
  *
 49   
  * This software consists of voluntary contributions made by many
 50   
  * individuals on behalf of the Apache Software Foundation.  For more
 51   
  * information on the Apache Software Foundation, please see
 52   
  * <http://www.apache.org/>.
 53   
  */
 54   
 package org.apache.tools.ant.taskdefs.email;
 55   
 
 56   
 import java.io.BufferedReader;
 57   
 import java.io.File;
 58   
 import java.io.FileReader;
 59   
 import java.io.IOException;
 60   
 import java.io.PrintStream;
 61   
 import org.apache.tools.ant.ProjectComponent;
 62   
 
 63   
 /**
 64   
  * Class representing an email message.
 65   
  *
 66   
  * @author roxspring@yahoo.com Rob Oxspring
 67   
  * @since Ant 1.5
 68   
  */
 69   
 public class Message extends ProjectComponent {
 70   
     private File messageSource = null;
 71   
     private StringBuffer buffer = new StringBuffer();
 72   
     private String mimeType = "text/plain";
 73   
     private boolean specified = false;
 74   
 
 75   
 
 76   
     /** Creates a new empty message  */
 77  0
     public Message() {
 78   
     }
 79   
 
 80   
 
 81   
     /**
 82   
      * Creates a new message based on the given string
 83   
      *
 84   
      * @param text the message
 85   
      */
 86  0
     public Message(String text) {
 87  0
         addText(text);
 88   
     }
 89   
 
 90   
 
 91   
     /**
 92   
      * Creates a new message using the contents of the given file.
 93   
      *
 94   
      * @param file the source of the message
 95   
      */
 96  0
     public Message(File file) {
 97  0
         messageSource = file;
 98   
     }
 99   
 
 100   
 
 101   
     /**
 102   
      * Adds a textual part of the message
 103   
      *
 104   
      * @param text some text to add
 105   
      */
 106  0
     public void addText(String text) {
 107  0
         buffer.append(text);
 108   
     }
 109   
 
 110   
 
 111   
     /**
 112   
      * Sets the source file of the message
 113   
      *
 114   
      * @param src the source of the message
 115   
      */
 116  0
     public void setSrc(File src) {
 117  0
         this.messageSource = src;
 118   
     }
 119   
 
 120   
 
 121   
     /**
 122   
      * Sets the content type for the message
 123   
      *
 124   
      * @param mimeType a mime type e.g. "text/plain"
 125   
      */
 126  0
     public void setMimeType(String mimeType) {
 127  0
         this.mimeType = mimeType;
 128  0
         specified = true;
 129   
     }
 130   
 
 131   
 
 132   
     /**
 133   
      * Returns the content type
 134   
      *
 135   
      * @return the mime type
 136   
      */
 137  0
     public String getMimeType() {
 138  0
         return mimeType;
 139   
     }
 140   
 
 141   
 
 142   
     /**
 143   
      * Prints the message onto an output stream
 144   
      *
 145   
      * @param out The print stream to write to
 146   
      * @throws IOException if an error occurs
 147   
      */
 148  0
     public void print(PrintStream out)
 149   
          throws IOException {
 150  0
         if (messageSource != null) {
 151   
             // Read message from a file
 152  0
             FileReader freader = new FileReader(messageSource);
 153   
 
 154  0
             try {
 155  0
                 BufferedReader in = new BufferedReader(freader);
 156  0
                 String line = null;
 157   
 
 158  0
                 while ((line = in.readLine()) != null) {
 159  0
                     out.println(getProject().replaceProperties(line));
 160   
                 }
 161   
             } finally {
 162  0
                 freader.close();
 163   
             }
 164   
         } else {
 165  0
             out.println(getProject().replaceProperties(buffer.substring(0)));
 166   
         }
 167   
     }
 168   
 
 169   
 
 170   
     /**
 171   
      * Returns true if the mimeType has been set.
 172   
      *
 173   
      * @return false if the default value is in use
 174   
      */
 175  0
     public boolean isMimeTypeSpecified() {
 176  0
         return specified;
 177   
     }
 178   
 }
 179   
 
 180