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