001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/framework/mail/EMailMessage.java $
002: /*---------------- FILE HEADER ------------------------------------------
003:
004: This file is part of deegree.
005: Copyright (C) 2001-2008 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: 9339 $,$Date: 2007-12-27 04:31:52 -0800 (Thu, 27 Dec 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,
092: String messageBody) {
093: this ();
094:
095: this .setSender(from);
096: this .setReceiver(to);
097: this .setSubject(subject);
098: this .setMessageBody(messageBody);
099: }
100:
101: /**
102: * Creates a new mail message with the given MIME type.
103: *
104: * @param from
105: * the sender
106: * @param to
107: * the receiver list
108: * @param subject
109: * the subject
110: * @param messageBody
111: * the content of the message
112: * @param mimeType
113: * the MIME type of the message body
114: * @throws UnknownMimeTypeException
115: * if the given mimeType is not supported
116: */
117: public EMailMessage(String from, String to, String subject,
118: String messageBody, String mimeType)
119: throws UnknownMimeTypeException {
120: this (from, to, subject, messageBody);
121: this .setMimeType(mimeType);
122: }
123:
124: /**
125: * Returns the state of this message. If sender and receiver are unequal null then this message
126: * is valid otherwise invalid.
127: *
128: * @return validation state, <code>true</code> if sender and receiver are not
129: * <code>null</code>, otherwise <code>false</code>
130: */
131: public boolean isValid() {
132: if (this .getSender() != null && this .getReceiver() != null) {
133: return true;
134: }
135: return false;
136: }
137:
138: /**
139: * Return mail header including sender, receiver and subject.
140: *
141: * @return string with sender, receiver and subject
142: */
143: public String getHeader() {
144: return ("From:" + this .getSender() + ", To:"
145: + this .getReceiver() + ", Subject:" + this .getSubject());
146: }
147:
148: /**
149: * Description of the Method
150: *
151: * @return Description of the Return Value
152: */
153: public String toString() {
154: return ("From:" + this .getSender() + ", To:"
155: + this .getReceiver() + ", Subject:" + this .getSubject()
156: + ",Body: " + this .getMessageBody());
157: }
158:
159: /**
160: * Method declaration
161: *
162: * @return sender
163: */
164: public String getSender() {
165: return this .sender;
166: }
167:
168: /**
169: * Method declaration
170: *
171: * @return The messageBody value
172: */
173: public String getMessageBody() {
174: return this .htmlContents;
175: }
176:
177: /**
178: * Method declaration
179: *
180: * @return emailReceiver
181: */
182: public String getReceiver() {
183: return this .emailReceiver;
184: }
185:
186: /**
187: * Method declaration
188: *
189: * @param to
190: */
191: public void setReceiver(String to) {
192: this .emailReceiver = to;
193: }
194:
195: /**
196: * Method declaration
197: *
198: * @param message
199: */
200: public void setMessageBody(String message) {
201: this .htmlContents = message;
202: }
203:
204: /**
205: * Method declaration
206: *
207: * @param from
208: */
209: public void setSender(String from) {
210: this .sender = from;
211: }
212:
213: /**
214: * Method declaration
215: *
216: * @param title
217: */
218: public void setSubject(String title) {
219: this .subject = title;
220: }
221:
222: /**
223: * Gets the subject attribute of the EMailMessage object
224: *
225: * @return The subject value
226: */
227: public String getSubject() {
228: return subject;
229: }
230:
231: /**
232: * Sets the mimeType attribute of the EMailMessage object
233: *
234: * @param mimeType
235: * The new mimeType value
236: * @throws UnknownMimeTypeException
237: * if the given MIME type is not supported
238: */
239: public void setMimeType(String mimeType)
240: throws UnknownMimeTypeException {
241: if (mimeType.equalsIgnoreCase(MailMessage.PLAIN_TEXT)) {
242: this .mimeType = mimeType;
243: } else if (mimeType.equalsIgnoreCase(MailMessage.TEXT_HTML)) {
244: this .mimeType = mimeType;
245: } else {
246: throw new UnknownMimeTypeException(getClass().getName(),
247: mimeType);
248: }
249: }
250:
251: /**
252: * Gets the mimeType attribute of the EMailMessage object
253: *
254: * @return The mimeType value
255: */
256: public String getMimeType() {
257: return this.mimeType;
258: }
259:
260: }
|