Post.java
Upload User: gdxydsw
Upload Date: 2019-01-29
Package Size: 16721k
Code Size: 10k
Category:

Java Develop

Development Platform:

Java

  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. import java.io.Serializable;
  45. import java.util.Date;
  46. import net.jforum.view.forum.common.ViewCommon;
  47. /**
  48.  * Represents every message post in the system.
  49.  * 
  50.  * @author Rafael Steil
  51.  * @version $Id: Post.java,v 1.15 2007/07/25 03:08:15 rafaelsteil Exp $
  52.  */
  53. public class Post implements Serializable 
  54. {
  55. private int id;
  56. private int topicId;
  57. private int forumId;
  58. private String formatedTime;
  59. private int userId;
  60. private Date time;
  61. private String text;
  62. private String subject;
  63. private String postUsername;
  64. private boolean bbCodeEnabled = true;
  65. private boolean htmlEnabled = true;
  66. private boolean smiliesEnabled = true;
  67. private boolean signatureEnabled = true;
  68. private Date editTime;
  69. private int editCount;
  70. private String userIp;
  71. private boolean canEdit;
  72. private KarmaStatus karma;
  73. private boolean hasAttachments;
  74. private boolean moderate;
  75. public Post() { }
  76. public Post(int postId)
  77. {
  78. this.id = postId;
  79. }
  80. /**
  81.  * Copy constructor
  82.  * 
  83.  * @param p The Post to make a copy from
  84.  */
  85. public Post(Post p)
  86. {
  87. this.setBbCodeEnabled(p.isBbCodeEnabled());
  88. this.setCanEdit(p.getCanEdit());
  89. this.setEditCount(p.getEditCount());
  90. this.setEditTime(p.getEditTime());
  91. this.setFormatedTime(p.getFormatedTime());
  92. this.setForumId(p.getForumId());
  93. this.setHtmlEnabled(p.isHtmlEnabled());
  94. this.setId(p.getId());
  95. this.setPostUsername(p.getPostUsername());
  96. this.setSignatureEnabled(p.isSignatureEnabled());
  97. this.setSmiliesEnabled(p.isSmiliesEnabled());
  98. this.setSubject(p.getSubject());
  99. this.setText(p.getText());
  100. this.setTime(p.getTime());
  101. this.setTopicId(p.getTopicId());
  102. this.setUserId(p.getUserId());
  103. this.setUserIp(p.getUserIp());
  104. this.setKarma(new KarmaStatus(p.getKarma()));
  105. this.setModerate(p.isModerationNeeded());
  106. this.hasAttachments(p.hasAttachments());
  107. }
  108. public void setModerate(boolean status)
  109. {
  110. this.moderate = status;
  111. }
  112. public boolean isModerate()
  113. {
  114. return this.isModerationNeeded();
  115. }
  116. public boolean isModerationNeeded()
  117. {
  118. return this.moderate;
  119. }
  120. public KarmaStatus getKarma()
  121. {
  122. return this.karma;
  123. }
  124. public void setKarma(KarmaStatus karma)
  125. {
  126. this.karma = karma;
  127. }
  128. /**
  129.  * Checks if the BB code is enabled
  130.  * 
  131.  * @return boolean value representing the result
  132.  */
  133. public boolean isBbCodeEnabled() {
  134. return this.bbCodeEnabled;
  135. }
  136. /**
  137.  * Gets the total number of times the post was edited
  138.  * 
  139.  * @return int value with the total number of times the post was edited
  140.  */
  141. public int getEditCount() {
  142. return this.editCount;
  143. }
  144. /**
  145.  * Gets the edit time of the post
  146.  * 
  147.  * @return long value representing the time
  148.  */
  149. public Date getEditTime() {
  150. return this.editTime;
  151. }
  152. /**
  153.  * Gets the forum's id the post is associated
  154.  * 
  155.  * @return int value with the id of the forum
  156.  */
  157. public int getForumId() {
  158. return this.forumId;
  159. }
  160. /**
  161.  * Checks if HTML is enabled in the topic
  162.  * 
  163.  * @return boolean value representing the result
  164.  */
  165. public boolean isHtmlEnabled() {
  166. return this.htmlEnabled;
  167. }
  168. /**
  169.  * Gets the ID of the post
  170.  * 
  171.  * @return int value with the ID
  172.  */
  173. public int getId() {
  174. return this.id;
  175. }
  176. /**
  177.  * Gets the username of the user ( an anonymous user ) that have posted the message
  178.  * 
  179.  * @return String with the username
  180.  */
  181. public String getPostUsername() {
  182. return this.postUsername;
  183. }
  184. /**
  185.  * Checks if signature is allowd in the message
  186.  * 
  187.  * @return boolean representing the result
  188.  */
  189. public boolean isSignatureEnabled() {
  190. return this.signatureEnabled;
  191. }
  192. /**
  193.  * Checks if smart Smilies are enabled :)
  194.  * 
  195.  * @return boolean representing the result
  196.  */
  197. public boolean isSmiliesEnabled() {
  198. return this.smiliesEnabled;
  199. }
  200. /**
  201.  * Gets the time, represented as long, of the message post
  202.  * 
  203.  * @return long representing the post time
  204.  */
  205. public Date getTime() {
  206. return this.time;
  207. }
  208. /**
  209.  * Gets the id of the topic this message is associated
  210.  * 
  211.  * @return int value with the topic id
  212.  */
  213. public int getTopicId() {
  214. return this.topicId;
  215. }
  216. /**
  217.  * Gets the ID of the user that have posted the message
  218.  * 
  219.  * @return int value with the user id
  220.  */
  221. public int getUserId() {
  222. return this.userId;
  223. }
  224. /**
  225.  * Gets the IP of the user who have posted the message
  226.  * 
  227.  * @return String value with the user IP
  228.  */
  229. public String getUserIp() {
  230. return this.userIp;
  231. }
  232. /**
  233.  * Sets the status for BB code in the message
  234.  * 
  235.  * @param bbCodeEnabled <code>true</code> or <code>false</code>, depending the intention
  236.  */
  237. public void setBbCodeEnabled(boolean bbCodeEnabled) {
  238. this.bbCodeEnabled = bbCodeEnabled;
  239. }
  240. /**
  241.  * Sets the count times the message was edited
  242.  * 
  243.  * @param editCount The count time
  244.  */
  245. public void setEditCount(int editCount) {
  246. this.editCount = editCount;
  247. }
  248. /**
  249.  * Sets the edit time the message was last edited
  250.  * 
  251.  * @param editTime long value representing the time
  252.  */
  253. public void setEditTime(Date editTime) {
  254. this.editTime = editTime;
  255. }
  256. /**
  257.  * Sets the id of the forum this message belongs to
  258.  * 
  259.  * @param forumId The forum's id
  260.  */
  261. public void setForumId(int forumId) {
  262. this.forumId = forumId;
  263. }
  264. /**
  265.  * Sets the status for HTML code in the message
  266.  * 
  267.  * @param htmlEnabled <code>true</code> or <code>false</code>, depending the intention
  268.  */
  269. public void setHtmlEnabled(boolean htmlEnabled) {
  270. this.htmlEnabled = htmlEnabled;
  271. }
  272. /**
  273.  * Sets the id for the message
  274.  * 
  275.  * @param id The id
  276.  */
  277. public void setId(int id) {
  278. this.id = id;
  279. }
  280. /**
  281.  * Sets the username of the anonymous user that have sent the message
  282.  * 
  283.  * @param postUsername String with the username
  284.  */
  285. public void setPostUsername(String postUsername) {
  286. this.postUsername = postUsername;
  287. }
  288. /**
  289.  * Sets the status for signatures in the message
  290.  * 
  291.  * @param signatureEnabled <code>true</code> or <code>false</code>, depending the intention
  292.  */
  293. public void setSignatureEnabled(boolean signatureEnabled) {
  294. this.signatureEnabled = signatureEnabled;
  295. }
  296. /**
  297.  * Sets the status for smilies in the message
  298.  * 
  299.  * @param smiliesEnabled <code>true</code> or <code>false</code>, depending the intention
  300.  */
  301. public void setSmiliesEnabled(boolean smiliesEnabled) {
  302. this.smiliesEnabled = smiliesEnabled;
  303. }
  304. /**
  305.  * Sets the time the message was sent
  306.  * 
  307.  * @param time The time 
  308.  */
  309. public void setTime(Date time) {
  310. this.time = time;
  311. }
  312. public void setFormatedTime(String t)
  313. {
  314. this.formatedTime = t;
  315. }
  316. public String getFormatedTime()
  317. {
  318. if (this.formatedTime == null && this.time != null) {
  319. this.formatedTime = ViewCommon.formatDate(this.time);
  320. }
  321. return this.formatedTime;
  322. }
  323. /**
  324.  * Sets the id of the topic that the message belongs to
  325.  * 
  326.  * @param topicId The id of the topic
  327.  */
  328. public void setTopicId(int topicId) {
  329. this.topicId = topicId;
  330. }
  331. /**
  332.  * Sets the id of the user that sent the message
  333.  * 
  334.  * @param userId The user Id
  335.  */
  336. public void setUserId(int userId) {
  337. this.userId = userId;
  338. }
  339. /**
  340.  * Gets the message of the post
  341.  * 
  342.  * @return String containing the text
  343.  */
  344. public String getText() {
  345. return this.text;
  346. }
  347. /**
  348.  * Sets the text of the post
  349.  * 
  350.  * @param text The text to set
  351.  */
  352. public void setText(String text) {
  353. this.text = text;
  354. }
  355. /**
  356.  * Gets the subject of the post 
  357.  * 
  358.  * @return String with the subject
  359.  */
  360. public String getSubject() {
  361. return this.subject;
  362. }
  363. /**
  364.  * Sets the subject for the message
  365.  * 
  366.  * @param subject The subject to set
  367.  */
  368. public void setSubject(String subject) {
  369. this.subject = subject;
  370. }
  371. /**
  372.  * Sets the IP of the user
  373.  * 
  374.  * @param userIP The IP address of the user
  375.  */
  376. public void setUserIp(String userIp) {
  377. this.userIp = userIp;
  378. }
  379. public boolean getCanEdit() {
  380. return this.canEdit;
  381. }
  382. public void setCanEdit(boolean canEdit) {
  383. this.canEdit = canEdit;
  384. }
  385. /**
  386.  * @return Returns the hasAttachments.
  387.  */
  388. public boolean hasAttachments()
  389. {
  390. return this.hasAttachments;
  391. }
  392. /**
  393.  * @param hasAttachments The hasAttachments to set.
  394.  */
  395. public void hasAttachments(boolean hasAttachments)
  396. {
  397. this.hasAttachments = hasAttachments;
  398. }
  399. /**
  400.  * @see java.lang.Object#equals(java.lang.Object)
  401.  */
  402. public boolean equals(Object o)
  403. {
  404. if (!(o instanceof Post)) {
  405. return false;
  406. }
  407. return ((Post)o).getId() == this.id;
  408. }
  409. /**
  410.  * @see java.lang.Object#hashCode()
  411.  */
  412. public int hashCode()
  413. {
  414. return this.id;
  415. }
  416. }