KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > blojsom > blog > database > DatabaseComment


1 /**
2  * Copyright (c) 2003-2006, David A. Czarnecki
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * Redistributions of source code must retain the above copyright notice, this list of conditions and the
9  * following disclaimer.
10  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
11  * following disclaimer in the documentation and/or other materials provided with the distribution.
12  * Neither the name of "David A. Czarnecki" and "blojsom" nor the names of its contributors may be used to
13  * endorse or promote products derived from this software without specific prior written permission.
14  * Products derived from this software may not be called "blojsom", nor may "blojsom" appear in their name,
15  * without prior written permission of David A. Czarnecki.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
18  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
19  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
21  * EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */

31 package org.blojsom.blog.database;
32
33 import org.blojsom.blog.Comment;
34 import org.blojsom.blog.Entry;
35 import org.blojsom.util.BlojsomUtils;
36
37 import java.io.Serializable JavaDoc;
38 import java.util.Date JavaDoc;
39 import java.util.Map JavaDoc;
40 import java.util.HashMap JavaDoc;
41 import java.util.Locale JavaDoc;
42 import java.text.SimpleDateFormat JavaDoc;
43
44 /**
45  * DatabaseComment
46  *
47  * @author David Czarnecki
48  * @since blojsom 3.0
49  * @version $Id: DatabaseComment.java,v 1.7 2006/09/26 02:55:21 czarneckid Exp $
50  */

51 public class DatabaseComment implements Comment, Serializable JavaDoc {
52
53     protected Integer JavaDoc _id;
54     protected Integer JavaDoc _blogId;
55     protected Integer JavaDoc _blogEntryId;
56     protected Entry _entry;
57
58     protected String JavaDoc _author;
59     protected String JavaDoc _authorEmail;
60     protected String JavaDoc _authorURL;
61     protected String JavaDoc _comment;
62     protected Date JavaDoc _commentDate;
63     protected Map JavaDoc _metaData;
64     protected Integer JavaDoc _parentId;
65     protected String JavaDoc _status;
66     protected String JavaDoc _ip;
67
68     /**
69      * Create a new instance of the database comment
70      */

71     public DatabaseComment() {
72     }
73
74     /**
75      * Get the id of this blog comment
76      *
77      * @return Id
78      */

79     public Integer JavaDoc getId() {
80         return _id;
81     }
82
83     /**
84      * Set the id of this blog comment. This method can only be called if the id has not been set.
85      *
86      * @param id New id
87      */

88     public void setId(Integer JavaDoc id) {
89         if (_id == null) {
90             _id = id;
91         }
92     }
93
94     /**
95      * Set the blog ID
96      *
97      * @param blogId Blog ID
98      */

99     public void setBlogId(Integer JavaDoc blogId) {
100         _blogId = blogId;
101     }
102
103     /**
104      * Get the blog ID
105      *
106      * @return Blog ID
107      */

108     public Integer JavaDoc getBlogId() {
109         return _blogId;
110     }
111
112     /**
113      * Get the blog entry ID
114      *
115      * @return Blog entry ID
116      */

117     public Integer JavaDoc getBlogEntryId() {
118         return _blogEntryId;
119     }
120
121     /**
122      * Set the blog entry ID
123      *
124      * @param blogEntryId Blog entry ID
125      */

126     public void setBlogEntryId(Integer JavaDoc blogEntryId) {
127         _blogEntryId = blogEntryId;
128     }
129
130     /**
131      * Get the {@link Entry}
132      *
133      * @return {@link Entry}
134      */

135     public Entry getEntry() {
136         return _entry;
137     }
138
139     /**
140      * Set the {@link Entry}
141      *
142      * @param entry {@link Entry}
143      */

144     public void setEntry(Entry entry) {
145         _entry = entry;
146         _blogEntryId = _entry.getId();
147     }
148
149     /**
150      * Get the author of the comment
151      *
152      * @return Comment author
153      */

154     public String JavaDoc getAuthor() {
155         return _author;
156     }
157
158     /**
159      * Get the author as an escaped string
160      *
161      * @return Escaped author
162      */

163     public String JavaDoc getEscapedAuthor() {
164         return BlojsomUtils.escapeString(_author);
165     }
166
167     /**
168      * Set the author of the comment
169      *
170      * @param author Comment's new author
171      */

172     public void setAuthor(String JavaDoc author) {
173         _author = author;
174     }
175
176     /**
177      * Get the e-mail of the author of the comment
178      *
179      * @return Author's e-mail
180      */

181     public String JavaDoc getAuthorEmail() {
182         return _authorEmail;
183     }
184
185     /**
186      * Get the escaped e-mail of the author of the comment
187      *
188      * @return Escaped author e-mail
189      */

190     public String JavaDoc getEscapedAuthorEmail() {
191         return BlojsomUtils.escapeString(_authorEmail);
192     }
193
194     /**
195      * Set the e-mail of the author of the comment
196      *
197      * @param authorEmail Author's new e-mail
198      */

199     public void setAuthorEmail(String JavaDoc authorEmail) {
200         _authorEmail = authorEmail;
201     }
202
203     /**
204      * Get the URL of the author
205      *
206      * @return Author's URL
207      */

208     public String JavaDoc getAuthorURL() {
209         return _authorURL;
210     }
211
212     /**
213      * Get the escaped URL of the author
214      *
215      * @return Escaped URL
216      */

217     public String JavaDoc getEscapedAuthorURL() {
218         return BlojsomUtils.escapeString(_authorURL);
219     }
220
221     /**
222      * Set the URL for the author
223      *
224      * @param authorURL New URL for the author
225      */

226     public void setAuthorURL(String JavaDoc authorURL) {
227         _authorURL = authorURL;
228     }
229
230     /**
231      * Get the comment as a escaped string
232      * @return Escaped Comment
233      */

234     public String JavaDoc getEscapedComment() {
235         return BlojsomUtils.escapeString(_comment);
236     }
237
238     /**
239      * Get the comment
240      *
241      * @return Comment
242      */

243     public String JavaDoc getComment() {
244         return _comment;
245     }
246
247     /**
248      * Set the new comment
249      *
250      * @param comment New comment
251      */

252     public void setComment(String JavaDoc comment) {
253         _comment = comment;
254     }
255
256     /**
257      * Get the date the comment was entered
258      *
259      * @return Comment date
260      */

261     public Date JavaDoc getCommentDate() {
262         return _commentDate;
263     }
264
265     /**
266      * Return an ISO 8601 style date
267      * http://www.w3.org/TR/NOTE-datetime
268      *
269      * @return Date formatted in ISO 8601 format
270      */

271     public String JavaDoc getISO8601Date() {
272         return BlojsomUtils.getISO8601Date(_commentDate);
273     }
274
275     /**
276      * Return an RFC 822 style date
277      *
278      * @return Date formatted in RFC 822 format
279      */

280     public String JavaDoc getRFC822Date() {
281         return BlojsomUtils.getRFC822Date(_commentDate);
282     }
283
284     /**
285      * Get the comment meta-data
286      *
287      * @return Meta-data as a {@link Map}
288      */

289     public Map JavaDoc getMetaData() {
290         if (_metaData == null) {
291             return new HashMap JavaDoc();
292         }
293
294         return _metaData;
295     }
296
297     /**
298      * Set the date for the comment
299      *
300      * @param commentDate Comment date
301      */

302     public void setCommentDate(Date JavaDoc commentDate) {
303         _commentDate = commentDate;
304     }
305
306     /**
307      * Set the comment meta-data
308      *
309      * @param metaData {@link Map} containing meta-data for this comment
310      */

311     public void setMetaData(Map JavaDoc metaData) {
312         _metaData = metaData;
313     }
314
315     /**
316      * Return the comment date formatted with a specified date format
317      *
318      * @param format Date format
319      * @return <code>null</code> if the comment date or format is null, otherwise returns the comment date
320      * formatted to the specified format. If the format is invalid, returns <tt>commentDate.toString()</tt>
321      */

322     public String JavaDoc getDateAsFormat(String JavaDoc format) {
323         return getDateAsFormat(format, null);
324     }
325
326     /**
327      * Return the comment date formatted with a specified date format
328      *
329      * @param format Date format
330      * @param locale Locale for date formatting
331      * @return <code>null</code> if the entry date or format is null, otherwise returns the entry date formatted to the specified format. If the format is invalid, returns <tt>commentDate.toString()</tt>
332      */

333     public String JavaDoc getDateAsFormat(String JavaDoc format, Locale JavaDoc locale) {
334         if (_commentDate == null || format == null) {
335             return null;
336         }
337
338         SimpleDateFormat JavaDoc sdf;
339         try {
340             if (locale == null) {
341                 sdf = new SimpleDateFormat JavaDoc(format);
342             } else {
343                 sdf = new SimpleDateFormat JavaDoc(format, locale);
344             }
345
346             return sdf.format(_commentDate);
347         } catch (IllegalArgumentException JavaDoc e) {
348             return _commentDate.toString();
349         }
350     }
351
352     /**
353      * Get the comment parent ID
354      *
355      * @return Comment parent ID
356      */

357     public Integer JavaDoc getParentId() {
358         return _parentId;
359     }
360
361     /**
362      * Set the comment parent ID
363      *
364      * @param parentId Comment parent ID
365      */

366     public void setParentId(Integer JavaDoc parentId) {
367         _parentId = parentId;
368     }
369
370     /**
371      * Get the IP
372      *
373      * @return IP
374      */

375     public String JavaDoc getIp() {
376         return _ip;
377     }
378
379     /**
380      * Set the IP
381      *
382      * @param ip IP
383      */

384     public void setIp(String JavaDoc ip) {
385         _ip = ip;
386     }
387
388     /**
389      * Get the status
390      *
391      * @return Status
392      */

393     public String JavaDoc getStatus() {
394         return _status;
395     }
396
397     /**
398      * Set the status
399      *
400      * @param status Status
401      */

402     public void setStatus(String JavaDoc status) {
403         _status = status;
404     }
405
406     /**
407      * Retrieve the date for this object
408      *
409      * @return Date
410      */

411     public Date JavaDoc getDate() {
412         return _commentDate;
413     }
414
415     /**
416      * Get the response type
417      *
418      * @return Response type
419      */

420     public String JavaDoc getType() {
421         return COMMENT_TYPE;
422     }
423 }
424
Popular Tags