KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > model > core > MailTemplate


1 /*
2  * Copyright 2004 Blandware (http://www.blandware.com)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package com.blandware.atleap.model.core;
17
18 import com.blandware.atleap.common.Constants;
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.HashMap JavaDoc;
22 import java.util.List JavaDoc;
23 import java.util.Map JavaDoc;
24
25 /**
26  * <p>Represents template of mail message. This is a special {@link Localizable}
27  * which defines some internal fields (from, subject, body, charset) that will be
28  * used when preparing mail message.
29  * </p>
30  * <p>
31  * Those may contain variables like this: $message.
32  * </p>
33  * <p>
34  * Also, mime type is specified for template. It defines mime type of generated
35  * mail messages. This can be 'text/html' or 'text/plain'.
36  * </p>
37  * <p><a HREF="MailTemplate.java.htm"><i>View Source</i></a>
38  * </p>
39  *
40  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
41  * @version $Revision: 1.13 $ $Date: 2005/10/19 07:27:40 $
42  * @struts.form include-all="false" extends="BaseForm"
43  * @hibernate.joined-subclass table="`al_core_mail_template`" lazy="false"
44  * @hibernate.joined-subclass-key column="`localizable_id`"
45  */

46 public class MailTemplate extends Localizable {
47
48     //~ Instance variables
49

50     /**
51      * The identifier of this template
52      */

53     protected String JavaDoc identifier;
54     /**
55      * Mime-type of this template
56      */

57     protected String JavaDoc mimeType = Constants.MIME_TYPE_PLAIN;
58
59     /**
60      * List of available variables to use in template body. It is taken from configuration file and is not persistent.
61      */

62     protected List JavaDoc availableVariables = new ArrayList JavaDoc();
63
64     /**
65      * Value of <code>from</code> field in mail message
66      */

67     protected Map JavaDoc from = new HashMap JavaDoc();
68
69     /**
70      * Message subject
71      */

72     protected Map JavaDoc subject = new HashMap JavaDoc();
73
74     /**
75      * Template body
76      */

77     protected Map JavaDoc body = new HashMap JavaDoc();
78
79     /**
80      * Template charset
81      */

82     protected Map JavaDoc charset = new HashMap JavaDoc();
83
84     //~ Constructors
85

86     /**
87      * Creates new instance of MailTemplate
88      */

89     public MailTemplate() {
90     }
91
92     //~ Methods
93

94     /**
95      * Gets identifier of this mail template
96      *
97      * @return the identifier
98      * @hibernate.property column="`identifier`" not-null="true" unique="true" length="252"
99      */

100     public String JavaDoc getIdentifier() {
101         return identifier;
102     }
103
104     /**
105      * Sets identifier of this mail template
106      *
107      * @param identifier the identifier to set
108      */

109     public void setIdentifier(String JavaDoc identifier) {
110         this.identifier = identifier;
111     }
112
113     /**
114      * Gets mime-type of messages that are based on this mail template
115      *
116      * @return mime-type
117      * @struts.form-field
118      * @hibernate.property column="`mime_type`" not-null="true" unique="false" length="252"
119      */

120     public String JavaDoc getMimeType() {
121         return mimeType;
122     }
123
124     /**
125      * Sets mime-type of messages that are based on this mail template
126      *
127      * @param mimeType the mime-type to set
128      */

129     public void setMimeType(String JavaDoc mimeType) {
130         this.mimeType = mimeType;
131     }
132
133     /**
134      * Returns <code>true</code>, if mime-type of this template is text/plain
135      *
136      * @return <code>true</code> if this template is plain
137      */

138     public boolean isPlain() {
139         return this.mimeType.equalsIgnoreCase(Constants.MIME_TYPE_PLAIN);
140     }
141
142     // Internal field values
143

144     /**
145      * Gets 'from' value (it's used in messages that are based on this template).
146      * This is a map from locale identifiers to strings that are specific to
147      * locales.
148      *
149      * @return map of 'from' values
150      * @struts.form-field
151      */

152     public Map JavaDoc getFrom() {
153         return from;
154     }
155
156     /**
157      * Sets 'from' map
158      *
159      * @param from map of 'from' values to set
160      * @see MailTemplate#getFrom()
161      */

162     public void setFrom(Map JavaDoc from) {
163         this.from = from;
164     }
165
166     /**
167      * Gets map of subjects that will be used in messages that are based on this
168      * template. This is a map from locale identifiers to strings that are specific to
169      * locales.
170      *
171      * @return subject map of 'subject' values
172      * @struts.form-field
173      */

174     public Map JavaDoc getSubject() {
175         return subject;
176     }
177
178     /**
179      * Sets map of 'subject' values
180      *
181      * @param subject map of 'subject' values
182      * @see MailTemplate#getSubject()
183      */

184     public void setSubject(Map JavaDoc subject) {
185         this.subject = subject;
186     }
187
188     /**
189      * Gets map of bodies that will be used in messages that are based on this
190      * template. This is a map from locale identifiers to bodies that are specific to
191      * locales.
192      *
193      * @return map of 'body' values
194      * @struts.form-field
195      */

196     public Map JavaDoc getBody() {
197         return body;
198     }
199
200     /**
201      * Sets map of 'body' values
202      *
203      * @param body map of 'body' values
204      * @see MailTemplate#getBody()
205      */

206     public void setBody(Map JavaDoc body) {
207         this.body = body;
208     }
209
210     /**
211      * Gets map of charsets that will be used in messages that are based on this
212      * template. This is a map from locale identifiers to charsets that are specific to
213      * locales.
214      *
215      * @return map from locale identifiers to charsets
216      * @struts.form-field
217      */

218     public Map JavaDoc getCharset() {
219         return charset;
220     }
221
222     /**
223      * Sets map of charsets
224      *
225      * @param charset map from locale identifiers to charsets
226      * @see MailTemplate#getCharset()
227      */

228     public void setCharset(Map JavaDoc charset) {
229         this.charset = charset;
230     }
231
232     /**
233      * Gets list of variables that can be used in template body
234      *
235      * @return list of variables
236      */

237     public List JavaDoc getAvailableVariables() {
238         return availableVariables;
239     }
240
241     /**
242      * Sets list of variables that can be used in template body
243      *
244      * @param availableVariables list of variables
245      */

246     public void setAvailableVariables(List JavaDoc availableVariables) {
247         this.availableVariables = availableVariables;
248     }
249
250     public boolean equals(Object JavaDoc o) {
251         if ( this == o ) {
252             return true;
253         }
254         if ( !(o instanceof MailTemplate) ) {
255             return false;
256         }
257
258         final MailTemplate mailTemplate = (MailTemplate) o;
259
260         if ( identifier != null ? !identifier.equals(mailTemplate.identifier) : mailTemplate.identifier != null ) {
261             return false;
262         }
263
264         return true;
265     }
266
267     public int hashCode() {
268         return (identifier != null ? identifier.hashCode() : 0);
269     }
270
271 }
272
273
Popular Tags