001: /*
002: * Copyright (c)Rafael Steil
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms,
006: * with or without modification, are permitted provided
007: * that the following conditions are met:
008: *
009: * 1) Redistributions of source code must retain the above
010: * copyright notice, this list of conditions and the
011: * following disclaimer.
012: * 2) Redistributions in binary form must reproduce the
013: * above copyright notice, this list of conditions and
014: * the following disclaimer in the documentation and/or
015: * other materials provided with the distribution.
016: * 3) Neither the name of "Rafael Steil" nor
017: * the names of its contributors may be used to endorse
018: * or promote products derived from this software without
019: * specific prior written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
022: * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
023: * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
024: * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
025: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR
026: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
027: * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
028: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
029: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES
030: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
031: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
032: * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
033: * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
034: * IN CONTRACT, STRICT LIABILITY, OR TORT
035: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
036: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
037: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
038: *
039: * This file creating date: Feb 23, 2003 / 1:02:01 PM
040: * The JForum Project
041: * http://www.jforum.net
042: */
043: package net.jforum.entities;
044:
045: import java.io.Serializable;
046: import java.util.Date;
047:
048: import net.jforum.view.forum.common.ViewCommon;
049:
050: /**
051: * Represents every message post in the system.
052: *
053: * @author Rafael Steil
054: * @version $Id: Post.java,v 1.15 2007/07/25 03:08:15 rafaelsteil Exp $
055: */
056: public class Post implements Serializable {
057: private int id;
058: private int topicId;
059: private int forumId;
060: private String formatedTime;
061: private int userId;
062: private Date time;
063: private String text;
064: private String subject;
065: private String postUsername;
066: private boolean bbCodeEnabled = true;
067: private boolean htmlEnabled = true;
068: private boolean smiliesEnabled = true;
069: private boolean signatureEnabled = true;
070: private Date editTime;
071: private int editCount;
072: private String userIp;
073: private boolean canEdit;
074: private KarmaStatus karma;
075: private boolean hasAttachments;
076: private boolean moderate;
077:
078: public Post() {
079: }
080:
081: public Post(int postId) {
082: this .id = postId;
083: }
084:
085: /**
086: * Copy constructor
087: *
088: * @param p The Post to make a copy from
089: */
090: public Post(Post p) {
091: this .setBbCodeEnabled(p.isBbCodeEnabled());
092: this .setCanEdit(p.getCanEdit());
093: this .setEditCount(p.getEditCount());
094: this .setEditTime(p.getEditTime());
095: this .setFormatedTime(p.getFormatedTime());
096: this .setForumId(p.getForumId());
097: this .setHtmlEnabled(p.isHtmlEnabled());
098: this .setId(p.getId());
099: this .setPostUsername(p.getPostUsername());
100: this .setSignatureEnabled(p.isSignatureEnabled());
101: this .setSmiliesEnabled(p.isSmiliesEnabled());
102: this .setSubject(p.getSubject());
103: this .setText(p.getText());
104: this .setTime(p.getTime());
105: this .setTopicId(p.getTopicId());
106: this .setUserId(p.getUserId());
107: this .setUserIp(p.getUserIp());
108: this .setKarma(new KarmaStatus(p.getKarma()));
109: this .setModerate(p.isModerationNeeded());
110: this .hasAttachments(p.hasAttachments());
111: }
112:
113: public void setModerate(boolean status) {
114: this .moderate = status;
115: }
116:
117: public boolean isModerate() {
118: return this .isModerationNeeded();
119: }
120:
121: public boolean isModerationNeeded() {
122: return this .moderate;
123: }
124:
125: public KarmaStatus getKarma() {
126: return this .karma;
127: }
128:
129: public void setKarma(KarmaStatus karma) {
130: this .karma = karma;
131: }
132:
133: /**
134: * Checks if the BB code is enabled
135: *
136: * @return boolean value representing the result
137: */
138: public boolean isBbCodeEnabled() {
139: return this .bbCodeEnabled;
140: }
141:
142: /**
143: * Gets the total number of times the post was edited
144: *
145: * @return int value with the total number of times the post was edited
146: */
147: public int getEditCount() {
148: return this .editCount;
149: }
150:
151: /**
152: * Gets the edit time of the post
153: *
154: * @return long value representing the time
155: */
156: public Date getEditTime() {
157: return this .editTime;
158: }
159:
160: /**
161: * Gets the forum's id the post is associated
162: *
163: * @return int value with the id of the forum
164: */
165: public int getForumId() {
166: return this .forumId;
167: }
168:
169: /**
170: * Checks if HTML is enabled in the topic
171: *
172: * @return boolean value representing the result
173: */
174: public boolean isHtmlEnabled() {
175: return this .htmlEnabled;
176: }
177:
178: /**
179: * Gets the ID of the post
180: *
181: * @return int value with the ID
182: */
183: public int getId() {
184: return this .id;
185: }
186:
187: /**
188: * Gets the username of the user ( an anonymous user ) that have posted the message
189: *
190: * @return String with the username
191: */
192: public String getPostUsername() {
193: return this .postUsername;
194: }
195:
196: /**
197: * Checks if signature is allowd in the message
198: *
199: * @return boolean representing the result
200: */
201: public boolean isSignatureEnabled() {
202: return this .signatureEnabled;
203: }
204:
205: /**
206: * Checks if smart Smilies are enabled :)
207: *
208: * @return boolean representing the result
209: */
210: public boolean isSmiliesEnabled() {
211: return this .smiliesEnabled;
212: }
213:
214: /**
215: * Gets the time, represented as long, of the message post
216: *
217: * @return long representing the post time
218: */
219: public Date getTime() {
220: return this .time;
221: }
222:
223: /**
224: * Gets the id of the topic this message is associated
225: *
226: * @return int value with the topic id
227: */
228: public int getTopicId() {
229: return this .topicId;
230: }
231:
232: /**
233: * Gets the ID of the user that have posted the message
234: *
235: * @return int value with the user id
236: */
237: public int getUserId() {
238: return this .userId;
239: }
240:
241: /**
242: * Gets the IP of the user who have posted the message
243: *
244: * @return String value with the user IP
245: */
246: public String getUserIp() {
247: return this .userIp;
248: }
249:
250: /**
251: * Sets the status for BB code in the message
252: *
253: * @param bbCodeEnabled <code>true</code> or <code>false</code>, depending the intention
254: */
255: public void setBbCodeEnabled(boolean bbCodeEnabled) {
256: this .bbCodeEnabled = bbCodeEnabled;
257: }
258:
259: /**
260: * Sets the count times the message was edited
261: *
262: * @param editCount The count time
263: */
264: public void setEditCount(int editCount) {
265: this .editCount = editCount;
266: }
267:
268: /**
269: * Sets the edit time the message was last edited
270: *
271: * @param editTime long value representing the time
272: */
273: public void setEditTime(Date editTime) {
274: this .editTime = editTime;
275: }
276:
277: /**
278: * Sets the id of the forum this message belongs to
279: *
280: * @param forumId The forum's id
281: */
282: public void setForumId(int forumId) {
283: this .forumId = forumId;
284: }
285:
286: /**
287: * Sets the status for HTML code in the message
288: *
289: * @param htmlEnabled <code>true</code> or <code>false</code>, depending the intention
290: */
291: public void setHtmlEnabled(boolean htmlEnabled) {
292: this .htmlEnabled = htmlEnabled;
293: }
294:
295: /**
296: * Sets the id for the message
297: *
298: * @param id The id
299: */
300: public void setId(int id) {
301: this .id = id;
302: }
303:
304: /**
305: * Sets the username of the anonymous user that have sent the message
306: *
307: * @param postUsername String with the username
308: */
309: public void setPostUsername(String postUsername) {
310: this .postUsername = postUsername;
311: }
312:
313: /**
314: * Sets the status for signatures in the message
315: *
316: * @param signatureEnabled <code>true</code> or <code>false</code>, depending the intention
317: */
318: public void setSignatureEnabled(boolean signatureEnabled) {
319: this .signatureEnabled = signatureEnabled;
320: }
321:
322: /**
323: * Sets the status for smilies in the message
324: *
325: * @param smiliesEnabled <code>true</code> or <code>false</code>, depending the intention
326: */
327: public void setSmiliesEnabled(boolean smiliesEnabled) {
328: this .smiliesEnabled = smiliesEnabled;
329: }
330:
331: /**
332: * Sets the time the message was sent
333: *
334: * @param time The time
335: */
336: public void setTime(Date time) {
337: this .time = time;
338: }
339:
340: public void setFormatedTime(String t) {
341: this .formatedTime = t;
342: }
343:
344: public String getFormatedTime() {
345: if (this .formatedTime == null && this .time != null) {
346: this .formatedTime = ViewCommon.formatDate(this .time);
347: }
348:
349: return this .formatedTime;
350: }
351:
352: /**
353: * Sets the id of the topic that the message belongs to
354: *
355: * @param topicId The id of the topic
356: */
357: public void setTopicId(int topicId) {
358: this .topicId = topicId;
359: }
360:
361: /**
362: * Sets the id of the user that sent the message
363: *
364: * @param userId The user Id
365: */
366: public void setUserId(int userId) {
367: this .userId = userId;
368: }
369:
370: /**
371: * Gets the message of the post
372: *
373: * @return String containing the text
374: */
375: public String getText() {
376: return this .text;
377: }
378:
379: /**
380: * Sets the text of the post
381: *
382: * @param text The text to set
383: */
384: public void setText(String text) {
385: this .text = text;
386: }
387:
388: /**
389: * Gets the subject of the post
390: *
391: * @return String with the subject
392: */
393: public String getSubject() {
394: return this .subject;
395: }
396:
397: /**
398: * Sets the subject for the message
399: *
400: * @param subject The subject to set
401: */
402: public void setSubject(String subject) {
403: this .subject = subject;
404: }
405:
406: /**
407: * Sets the IP of the user
408: *
409: * @param userIP The IP address of the user
410: */
411: public void setUserIp(String userIp) {
412: this .userIp = userIp;
413: }
414:
415: public boolean getCanEdit() {
416: return this .canEdit;
417: }
418:
419: public void setCanEdit(boolean canEdit) {
420: this .canEdit = canEdit;
421: }
422:
423: /**
424: * @return Returns the hasAttachments.
425: */
426: public boolean hasAttachments() {
427: return this .hasAttachments;
428: }
429:
430: /**
431: * @param hasAttachments The hasAttachments to set.
432: */
433: public void hasAttachments(boolean hasAttachments) {
434: this .hasAttachments = hasAttachments;
435: }
436:
437: /**
438: * @see java.lang.Object#equals(java.lang.Object)
439: */
440: public boolean equals(Object o) {
441: if (!(o instanceof Post)) {
442: return false;
443: }
444:
445: return ((Post) o).getId() == this .id;
446: }
447:
448: /**
449: * @see java.lang.Object#hashCode()
450: */
451: public int hashCode() {
452: return this.id;
453: }
454: }
|