001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/framework/mail/EMailMessage.java $ 002 /*---------------- FILE HEADER ------------------------------------------ 003 004 This file is part of deegree. 005 Copyright (C) 2001-2006 by: 006 EXSE, Department of Geography, University of Bonn 007 http://www.giub.uni-bonn.de/deegree/ 008 lat/lon GmbH 009 http://www.lat-lon.de 010 011 This library is free software; you can redistribute it and/or 012 modify it under the terms of the GNU Lesser General Public 013 License as published by the Free Software Foundation; either 014 version 2.1 of the License, or (at your option) any later version. 015 016 This library is distributed in the hope that it will be useful, 017 but WITHOUT ANY WARRANTY; without even the implied warranty of 018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 019 Lesser General Public License for more details. 020 021 You should have received a copy of the GNU Lesser General Public 022 License along with this library; if not, write to the Free Software 023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 024 025 Contact: 026 027 Andreas Poth 028 lat/lon GmbH 029 Aennchenstr. 19 030 53115 Bonn 031 Germany 032 E-Mail: poth@lat-lon.de 033 034 Prof. Dr. Klaus Greve 035 Department of Geography 036 University of Bonn 037 Meckenheimer Allee 166 038 53115 Bonn 039 Germany 040 E-Mail: greve@giub.uni-bonn.de 041 042 043 ---------------------------------------------------------------------------*/ 044 package org.deegree.framework.mail; 045 046 /** 047 * This class encapsulates all the info need to send an email message. This object is passed to the 048 * MailerEJB sendMail(...) method. 049 * 050 * 051 * @author <a href="mailto:tfr@users.sourceforge.net">Torsten Friebe</A> 052 * @author last edited by: $Author: apoth $ 053 * 054 * @version $Revision: 6455 $,$Date: 2007-03-29 13:50:50 +0200 (Do, 29 Mär 2007) $ 055 */ 056 public class EMailMessage implements java.io.Serializable, MailMessage { 057 058 private String sender; 059 060 private String subject; 061 062 private String htmlContents; 063 064 private String emailReceiver; 065 066 private String mimeType; 067 068 /** 069 * Creates an empty email message with the default MIME type plain text. 070 */ 071 private EMailMessage() { 072 try { 073 this.setMimeType( MailMessage.PLAIN_TEXT ); 074 } catch ( Exception ex ) { 075 // nothing to do 076 } 077 } 078 079 /** 080 * Creates a new mail message with MIME type text/plain. 081 * 082 * @param from 083 * the sender 084 * @param to 085 * the receiver list 086 * @param subject 087 * the subject 088 * @param messageBody 089 * the content of the message 090 */ 091 public EMailMessage( String from, String to, String subject, String messageBody ) { 092 this(); 093 094 this.setSender( from ); 095 this.setReceiver( to ); 096 this.setSubject( subject ); 097 this.setMessageBody( messageBody ); 098 } 099 100 /** 101 * Creates a new mail message with the given MIME type. 102 * 103 * @param from 104 * the sender 105 * @param to 106 * the receiver list 107 * @param subject 108 * the subject 109 * @param messageBody 110 * the content of the message 111 * @param mimeType 112 * the MIME type of the message body 113 * @throws UnknownMimeTypeException 114 * if the given mimeType is not supported 115 */ 116 public EMailMessage( String from, String to, String subject, String messageBody, String mimeType ) 117 throws UnknownMimeTypeException { 118 this( from, to, subject, messageBody ); 119 this.setMimeType( mimeType ); 120 } 121 122 /** 123 * Returns the state of this message. If sender and receiver are unequal null then this message 124 * is valid otherwise invalid. 125 * 126 * @return validation state, <code>true</code> if sender and receiver are not 127 * <code>null</code>, otherwise <code>false</code> 128 */ 129 public boolean isValid() { 130 if ( this.getSender() != null && this.getReceiver() != null ) { 131 return true; 132 } 133 return false; 134 } 135 136 /** 137 * Return mail header including sender, receiver and subject. 138 * 139 * @return string with sender, receiver and subject 140 */ 141 public String getHeader() { 142 return ( "From:" + this.getSender() + ", To:" + this.getReceiver() + ", Subject:" + this.getSubject() ); 143 } 144 145 /** 146 * Description of the Method 147 * 148 * @return Description of the Return Value 149 */ 150 public String toString() { 151 return ( "From:" + this.getSender() + ", To:" + this.getReceiver() + ", Subject:" 152 + this.getSubject() + ",Body: " + this.getMessageBody() ); 153 } 154 155 /** 156 * Method declaration 157 * 158 * @return sender 159 */ 160 public String getSender() { 161 return this.sender; 162 } 163 164 /** 165 * Method declaration 166 * 167 * @return The messageBody value 168 */ 169 public String getMessageBody() { 170 return this.htmlContents; 171 } 172 173 /** 174 * Method declaration 175 * 176 * @return emailReceiver 177 */ 178 public String getReceiver() { 179 return this.emailReceiver; 180 } 181 182 /** 183 * Method declaration 184 * 185 * @param to 186 */ 187 public void setReceiver( String to ) { 188 this.emailReceiver = to; 189 } 190 191 /** 192 * Method declaration 193 * 194 * @param message 195 */ 196 public void setMessageBody( String message ) { 197 this.htmlContents = message; 198 } 199 200 /** 201 * Method declaration 202 * 203 * @param from 204 */ 205 public void setSender( String from ) { 206 this.sender = from; 207 } 208 209 /** 210 * Method declaration 211 * 212 * @param title 213 */ 214 public void setSubject( String title ) { 215 this.subject = title; 216 } 217 218 /** 219 * Gets the subject attribute of the EMailMessage object 220 * 221 * @return The subject value 222 */ 223 public String getSubject() { 224 return subject; 225 } 226 227 /** 228 * Sets the mimeType attribute of the EMailMessage object 229 * 230 * @param mimeType 231 * The new mimeType value 232 * @throws UnknownMimeTypeException 233 * if the given MIME type is not supported 234 */ 235 public void setMimeType( String mimeType ) 236 throws UnknownMimeTypeException { 237 if ( mimeType.equalsIgnoreCase( MailMessage.PLAIN_TEXT ) ) { 238 this.mimeType = mimeType; 239 } else if ( mimeType.equalsIgnoreCase( MailMessage.TEXT_HTML ) ) { 240 this.mimeType = mimeType; 241 } else { 242 throw new UnknownMimeTypeException( getClass().getName(), mimeType ); 243 } 244 } 245 246 /** 247 * Gets the mimeType attribute of the EMailMessage object 248 * 249 * @return The mimeType value 250 */ 251 public String getMimeType() { 252 return this.mimeType; 253 } 254 255 } 256 257 /*************************************************************************************************** 258 * <code> 259 Changes to this class. What the people have been up to: 260 261 $Log$ 262 Revision 1.9 2007/03/06 10:41:39 wanhoff 263 Fixed Javadoc (@testcase removed) 264 265 Revision 1.8 2007/01/26 13:27:42 wanhoff 266 fixed Javadoc @return tag and footer 267 268 Revision 1.7 2006/07/12 14:46:19 poth 269 comment footer added 270 271 </code> 272 **************************************************************************************************/