FileDocCategorySizeDatePackage
Message.javaAPI DocApache Ant 1.704462Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.taskdefs.email

Message

public class Message extends org.apache.tools.ant.ProjectComponent
Class representing an email message.
since
Ant 1.5

Fields Summary
private File
messageSource
private StringBuffer
buffer
private String
mimeType
private boolean
specified
private String
charset
Constructors Summary
public Message()
Creates a new empty message


           
      
    
public Message(String text)
Creates a new message based on the given string

param
text the message

        addText(text);
    
public Message(File file)
Creates a new message using the contents of the given file.

param
file the source of the message

        messageSource = file;
    
Methods Summary
public voidaddText(java.lang.String text)
Adds a textual part of the message

param
text some text to add

        buffer.append(text);
    
public java.lang.StringgetCharset()
Returns the charset of mail message.

return
Charset of mail message.
since
Ant 1.6

      return charset;
    
public java.lang.StringgetMimeType()
Returns the content type

return
the mime type

        return mimeType;
    
public booleanisMimeTypeSpecified()
Returns true if the mimeType has been set.

return
false if the default value is in use

        return specified;
    
public voidprint(java.io.PrintStream ps)
Prints the message onto an output stream

param
ps The print stream to write to
throws
IOException if an error occurs

        // We need character encoding aware printing here.
        // So, using PrintWriter over OutputStreamWriter instead of PrintStream
        PrintWriter out
            = charset != null ? new PrintWriter(new OutputStreamWriter(ps, charset))
                              : new PrintWriter(ps);
        if (messageSource != null) {
            // Read message from a file
            FileReader freader = new FileReader(messageSource);

            try {
                BufferedReader in = new BufferedReader(freader);
                String line = null;
                while ((line = in.readLine()) != null) {
                    out.println(getProject().replaceProperties(line));
                }
            } finally {
                freader.close();
            }
        } else {
            out.println(getProject().replaceProperties(buffer.substring(0)));
        }
        out.flush();
    
public voidsetCharset(java.lang.String charset)
Sets the character set of mail message. Will be ignored if mimeType contains ....; Charset=... substring.

param
charset the character set name.
since
Ant 1.6

      this.charset = charset;
    
public voidsetMimeType(java.lang.String mimeType)
Sets the content type for the message

param
mimeType a mime type e.g. "text/plain"

        this.mimeType = mimeType;
        specified = true;
    
public voidsetSrc(java.io.File src)
Sets the source file of the message

param
src the source of the message

        this.messageSource = src;