KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > jforum > entities > Post


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

43 package net.jforum.entities;
44
45 import java.io.Serializable JavaDoc;
46 import java.util.Date JavaDoc;
47
48 import net.jforum.view.forum.common.ViewCommon;
49
50 /**
51  * Represents every message post in the system.
52  *
53  * @author Rafael Steil
54  * @version $Id: Post.java,v 1.14 2005/10/02 19:06:41 rafaelsteil Exp $
55  */

56 public class Post implements Serializable JavaDoc
57 {
58     private int id;
59     private int topicId;
60     private int forumId;
61     private String JavaDoc formatedTime;
62     private int userId;
63     private Date JavaDoc time;
64     private String JavaDoc text;
65     private String JavaDoc subject;
66     private String JavaDoc postUsername;
67     private boolean bbCodeEnabled = true;
68     private boolean htmlEnabled = true;
69     private boolean smiliesEnabled = true;
70     private boolean signatureEnabled = true;
71     private Date JavaDoc editTime;
72     private int editCount;
73     private String JavaDoc userIp;
74     private boolean canEdit;
75     private KarmaStatus karma;
76     private boolean hasAttachments;
77     private boolean moderate;
78
79     public Post() { }
80     
81     /**
82      * Copy constructor
83      *
84      * @param p The Post to make a copy from
85      */

86     public Post(Post p)
87     {
88         this.setBbCodeEnabled(p.isBbCodeEnabled());
89         this.setCanEdit(p.getCanEdit());
90         this.setEditCount(p.getEditCount());
91         this.setEditTime(p.getEditTime());
92         this.setFormatedTime(p.getFormatedTime());
93         this.setForumId(p.getForumId());
94         this.setHtmlEnabled(p.isHtmlEnabled());
95         this.setId(p.getId());
96         this.setPostUsername(p.getPostUsername());
97         this.setSignatureEnabled(p.isSignatureEnabled());
98         this.setSmiliesEnabled(p.isSmiliesEnabled());
99         this.setSubject(p.getSubject());
100         this.setText(p.getText());
101         this.setTime(p.getTime());
102         this.setTopicId(p.getTopicId());
103         this.setUserId(p.getUserId());
104         this.setUserIp(p.getUserIp());
105         this.setKarma(new KarmaStatus(p.getKarma()));
106         this.setModerate(p.isModerationNeeded());
107         this.hasAttachments(p.hasAttachments());
108     }
109     
110     public void setModerate(boolean status)
111     {
112         this.moderate = status;
113     }
114     
115     public boolean isModerate()
116     {
117         return this.isModerationNeeded();
118     }
119     
120     public boolean isModerationNeeded()
121     {
122         return this.moderate;
123     }
124     
125     public KarmaStatus getKarma()
126     {
127         return this.karma;
128     }
129     
130     public void setKarma(KarmaStatus karma)
131     {
132         this.karma = karma;
133     }
134     
135     /**
136      * Checks if the BB code is enabled
137      *
138      * @return boolean value representing the result
139      */

140     public boolean isBbCodeEnabled() {
141         return this.bbCodeEnabled;
142     }
143
144     /**
145      * Gets the total number of times the post was edited
146      *
147      * @return int value with the total number of times the post was edited
148      */

149     public int getEditCount() {
150         return this.editCount;
151     }
152
153     /**
154      * Gets the edit time of the post
155      *
156      * @return long value representing the time
157      */

158     public Date JavaDoc getEditTime() {
159         return this.editTime;
160     }
161
162     /**
163      * Gets the forum's id the post is associated
164      *
165      * @return int value with the id of the forum
166      */

167     public int getForumId() {
168         return this.forumId;
169     }
170
171     /**
172      * Checks if HTML is enabled in the topic
173      *
174      * @return boolean value representing the result
175      */

176     public boolean isHtmlEnabled() {
177         return this.htmlEnabled;
178     }
179
180     /**
181      * Gets the ID of the post
182      *
183      * @return int value with the ID
184      */

185     public int getId() {
186         return this.id;
187     }
188
189     /**
190      * Gets the username of the user ( an anonymous user ) that have posted the message
191      *
192      * @return String with the username
193      */

194     public String JavaDoc getPostUsername() {
195         return this.postUsername;
196     }
197
198     /**
199      * Checks if signature is allowd in the message
200      *
201      * @return boolean representing the result
202      */

203     public boolean isSignatureEnabled() {
204         return this.signatureEnabled;
205     }
206
207     /**
208      * Checks if smart Smilies are enabled :)
209      *
210      * @return boolean representing the result
211      */

212     public boolean isSmiliesEnabled() {
213         return this.smiliesEnabled;
214     }
215
216     /**
217      * Gets the time, represented as long, of the message post
218      *
219      * @return long representing the post time
220      */

221     public Date JavaDoc getTime() {
222         return this.time;
223     }
224
225     /**
226      * Gets the id of the topic this message is associated
227      *
228      * @return int value with the topic id
229      */

230     public int getTopicId() {
231         return this.topicId;
232     }
233
234     /**
235      * Gets the ID of the user that have posted the message
236      *
237      * @return int value with the user id
238      */

239     public int getUserId() {
240         return this.userId;
241     }
242
243     /**
244      * Gets the IP of the user who have posted the message
245      *
246      * @return String value with the user IP
247      */

248     public String JavaDoc getUserIp() {
249         return this.userIp;
250     }
251     /**
252      * Sets the status for BB code in the message
253      *
254      * @param bbCodeEnabled <code>true</code> or <code>false</code>, depending the intention
255      */

256     public void setBbCodeEnabled(boolean bbCodeEnabled) {
257         this.bbCodeEnabled = bbCodeEnabled;
258     }
259
260     /**
261      * Sets the count times the message was edited
262      *
263      * @param editCount The count time
264      */

265     public void setEditCount(int editCount) {
266         this.editCount = editCount;
267     }
268
269     /**
270      * Sets the edit time the message was last edited
271      *
272      * @param editTime long value representing the time
273      */

274     public void setEditTime(Date JavaDoc editTime) {
275         this.editTime = editTime;
276     }
277
278     /**
279      * Sets the id of the forum this message belongs to
280      *
281      * @param forumId The forum's id
282      */

283     public void setForumId(int forumId) {
284         this.forumId = forumId;
285     }
286
287     /**
288      * Sets the status for HTML code in the message
289      *
290      * @param htmlEnabled <code>true</code> or <code>false</code>, depending the intention
291      */

292     public void setHtmlEnabled(boolean htmlEnabled) {
293         this.htmlEnabled = htmlEnabled;
294     }
295
296     /**
297      * Sets the id for the message
298      *
299      * @param id The id
300      */

301     public void setId(int id) {
302         this.id = id;
303     }
304
305     /**
306      * Sets the username of the anonymous user that have sent the message
307      *
308      * @param postUsername String with the username
309      */

310     public void setPostUsername(String JavaDoc postUsername) {
311         this.postUsername = postUsername;
312     }
313
314     /**
315      * Sets the status for signatures in the message
316      *
317      * @param signatureEnabled <code>true</code> or <code>false</code>, depending the intention
318      */

319     public void setSignatureEnabled(boolean signatureEnabled) {
320         this.signatureEnabled = signatureEnabled;
321     }
322
323     /**
324      * Sets the status for smilies in the message
325      *
326      * @param smiliesEnabled <code>true</code> or <code>false</code>, depending the intention
327      */

328     public void setSmiliesEnabled(boolean smiliesEnabled) {
329         this.smiliesEnabled = smiliesEnabled;
330     }
331
332     /**
333      * Sets the time the message was sent
334      *
335      * @param time The time
336      */

337     public void setTime(Date JavaDoc time) {
338         this.time = time;
339     }
340     
341     public void setFormatedTime(String JavaDoc t)
342     {
343         this.formatedTime = t;
344     }
345     
346     public String JavaDoc getFormatedTime()
347     {
348         if (this.formatedTime == null && this.time != null) {
349             this.formatedTime = ViewCommon.formatDate(this.time);
350         }
351         
352         return this.formatedTime;
353     }
354
355     /**
356      * Sets the id of the topic that the message belongs to
357      *
358      * @param topicId The id of the topic
359      */

360     public void setTopicId(int topicId) {
361         this.topicId = topicId;
362     }
363
364     /**
365      * Sets the id of the user that sent the message
366      *
367      * @param userId The user Id
368      */

369     public void setUserId(int userId) {
370         this.userId = userId;
371     }
372     
373     /**
374      * Gets the message of the post
375      *
376      * @return String containing the text
377      */

378     public String JavaDoc getText() {
379         return this.text;
380     }
381
382     /**
383      * Sets the text of the post
384      *
385      * @param text The text to set
386      */

387     public void setText(String JavaDoc text) {
388         this.text = text;
389     }
390     
391     /**
392      * Gets the subject of the post
393      *
394      * @return String with the subject
395      */

396     public String JavaDoc getSubject() {
397         return this.subject;
398     }
399
400     /**
401      * Sets the subject for the message
402      *
403      * @param subject The subject to set
404      */

405     public void setSubject(String JavaDoc subject) {
406         this.subject = subject;
407     }
408
409     /**
410      * Sets the IP of the user
411      *
412      * @param userIP The IP address of the user
413      */

414     public void setUserIp(String JavaDoc userIp) {
415         this.userIp = userIp;
416     }
417     public boolean getCanEdit() {
418         return this.canEdit;
419     }
420     
421     public void setCanEdit(boolean canEdit) {
422         this.canEdit = canEdit;
423     }
424     
425     /**
426      * @return Returns the hasAttachments.
427      */

428     public boolean hasAttachments()
429     {
430         return this.hasAttachments;
431     }
432     
433     /**
434      * @param hasAttachments The hasAttachments to set.
435      */

436     public void hasAttachments(boolean hasAttachments)
437     {
438         this.hasAttachments = hasAttachments;
439     }
440     
441     /**
442      * @see java.lang.Object#equals(java.lang.Object)
443      */

444     public boolean equals(Object JavaDoc o)
445     {
446         if (!(o instanceof Post)) {
447             return false;
448         }
449         
450         return ((Post)o).getId() == this.id;
451     }
452     
453     /**
454      * @see java.lang.Object#hashCode()
455      */

456     public int hashCode()
457     {
458         return this.id;
459     }
460 }
461
Popular Tags