1 18 package org.apache.tools.ant.taskdefs.email; 19 20 import java.io.BufferedReader ; 21 import java.io.File ; 22 import java.io.FileReader ; 23 import java.io.IOException ; 24 import java.io.OutputStreamWriter ; 25 import java.io.PrintStream ; 26 import java.io.PrintWriter ; 27 28 import org.apache.tools.ant.ProjectComponent; 29 30 35 public class Message extends ProjectComponent { 36 private File messageSource = null; 37 private StringBuffer buffer = new StringBuffer (); 38 private String mimeType = "text/plain"; 39 private boolean specified = false; 40 private String charset = null; 41 42 43 public Message() { 44 } 45 46 47 52 public Message(String text) { 53 addText(text); 54 } 55 56 57 62 public Message(File file) { 63 messageSource = file; 64 } 65 66 67 72 public void addText(String text) { 73 buffer.append(text); 74 } 75 76 77 82 public void setSrc(File src) { 83 this.messageSource = src; 84 } 85 86 87 92 public void setMimeType(String mimeType) { 93 this.mimeType = mimeType; 94 specified = true; 95 } 96 97 98 103 public String getMimeType() { 104 return mimeType; 105 } 106 107 108 114 public void print(PrintStream ps) 115 throws IOException { 116 PrintWriter out 119 = charset != null ? new PrintWriter (new OutputStreamWriter (ps, charset)) 120 : new PrintWriter (ps); 121 if (messageSource != null) { 122 FileReader freader = new FileReader (messageSource); 124 125 try { 126 BufferedReader in = new BufferedReader (freader); 127 String line = null; 128 while ((line = in.readLine()) != null) { 129 out.println(getProject().replaceProperties(line)); 130 } 131 } finally { 132 freader.close(); 133 } 134 } else { 135 out.println(getProject().replaceProperties(buffer.substring(0))); 136 } 137 out.flush(); 138 } 139 140 141 146 public boolean isMimeTypeSpecified() { 147 return specified; 148 } 149 150 156 public void setCharset(String charset) { 157 this.charset = charset; 158 } 159 165 public String getCharset() { 166 return charset; 167 } 168 } 169 170 | Popular Tags |