1 41 package com.mvnforum.db; 42 43 import java.sql.Timestamp ; 44 import java.util.Collection ; 45 import java.util.Iterator ; 46 47 import net.myvietnam.mvncore.util.StringUtil; 48 49 56 public class ThreadBean { 57 61 64 public final static int THREAD_STATUS_DEFAULT = 0; 65 66 69 public final static int THREAD_STATUS_DISABLED = 1; 70 71 75 public final static int THREAD_STATUS_LOCKED = 2; 76 77 80 public final static int THREAD_STATUS_CLOSED = 3; 81 82 85 public final static int THREAD_TYPE_DEFAULT = 0; 86 87 public final static int THREAD_TYPE_STICKY = 1; 88 89 public final static int THREAD_TYPE_FORUM_ANNOUNCEMENT = 2; 90 91 public final static int THREAD_TYPE_GLOBAL_ANNOUNCEMENT = 3; 92 93 private int threadID; 94 private int forumID; 95 private String memberName; 96 private String lastPostMemberName; 97 private String threadTopic; 98 private String threadBody; 99 private int threadVoteCount; 100 private int threadVoteTotalStars; 101 private Timestamp threadCreationDate; 102 private Timestamp threadLastPostDate; 103 private int threadType; 104 private int threadOption; 105 private int threadStatus; 106 private int threadHasPoll; 107 private int threadViewCount; 108 private int threadReplyCount; 109 private String threadIcon; 110 private int threadDuration; 111 private int threadAttachCount; 112 113 public int getThreadID() { 114 return threadID; 115 } 116 public void setThreadID(int threadID) { 117 this.threadID = threadID; 118 } 119 120 public int getForumID() { 121 return forumID; 122 } 123 public void setForumID(int forumID) { 124 this.forumID = forumID; 125 } 126 127 public String getMemberName() { 128 return memberName; 129 } 130 public void setMemberName(String memberName) { 131 this.memberName = memberName; 132 } 133 134 public String getLastPostMemberName() { 135 return lastPostMemberName; 136 } 137 public void setLastPostMemberName(String lastPostMemberName) { 138 this.lastPostMemberName = lastPostMemberName; 139 } 140 141 public String getThreadTopic() { 142 return threadTopic; 143 } 144 public void setThreadTopic(String threadTopic) { 145 this.threadTopic = threadTopic; 146 } 147 148 public String getThreadBody() { 149 return threadBody; 150 } 151 public void setThreadBody(String threadBody) { 152 this.threadBody = threadBody; 153 } 154 155 public int getThreadVoteCount() { 156 return threadVoteCount; 157 } 158 public void setThreadVoteCount(int threadVoteCount) { 159 this.threadVoteCount = threadVoteCount; 160 } 161 162 public int getThreadVoteTotalStars() { 163 return threadVoteTotalStars; 164 } 165 public void setThreadVoteTotalStars(int threadVoteTotalStars) { 166 this.threadVoteTotalStars = threadVoteTotalStars; 167 } 168 169 public Timestamp getThreadCreationDate() { 170 return threadCreationDate; 171 } 172 public void setThreadCreationDate(Timestamp threadCreationDate) { 173 this.threadCreationDate = threadCreationDate; 174 } 175 176 public Timestamp getThreadLastPostDate() { 177 return threadLastPostDate; 178 } 179 public void setThreadLastPostDate(Timestamp threadLastPostDate) { 180 this.threadLastPostDate = threadLastPostDate; 181 } 182 183 public int getThreadType() { 184 return threadType; 185 } 186 public void setThreadType(int threadType) { 187 this.threadType = threadType; 188 } 189 190 public int getThreadOption() { 191 return threadOption; 192 } 193 public void setThreadOption(int threadOption) { 194 this.threadOption = threadOption; 195 } 196 197 public int getThreadStatus() { 198 return threadStatus; 199 } 200 public void setThreadStatus(int threadStatus) { 201 this.threadStatus = threadStatus; 202 } 203 204 public int getThreadHasPoll() { 205 return threadHasPoll; 206 } 207 public void setThreadHasPoll(int threadHasPoll) { 208 this.threadHasPoll = threadHasPoll; 209 } 210 211 public int getThreadViewCount() { 212 return threadViewCount; 213 } 214 public void setThreadViewCount(int threadViewCount) { 215 this.threadViewCount = threadViewCount; 216 } 217 218 public int getThreadReplyCount() { 219 return threadReplyCount; 220 } 221 public void setThreadReplyCount(int threadReplyCount) { 222 this.threadReplyCount = threadReplyCount; 223 } 224 225 public String getThreadIcon() { 226 return threadIcon; 227 } 228 public void setThreadIcon(String threadIcon) { 229 this.threadIcon = StringUtil.getEmptyStringIfNull(threadIcon); 230 } 231 232 public int getThreadDuration() { 233 return threadDuration; 234 } 235 public void setThreadDuration(int threadDuration) { 236 this.threadDuration = threadDuration; 237 } 238 239 public int getThreadAttachCount() { 240 return this.threadAttachCount; 241 } 242 public void setThreadAttachCount(int attachCount) { 243 this.threadAttachCount = attachCount; 244 } 245 246 public String getXMLTag() { 247 StringBuffer xml = new StringBuffer (1024); 248 xml.append("<Thread"); 249 xml.append(" threadID=\"").append(String.valueOf(threadID)).append("\""); 250 xml.append(" forumID=\"").append(String.valueOf(forumID)).append("\""); 251 xml.append(" memberName=\"").append(String.valueOf(memberName)).append("\""); 252 xml.append(" lastPostMemberName=\"").append(String.valueOf(lastPostMemberName)).append("\""); 253 xml.append(" threadTopic=\"").append(String.valueOf(threadTopic)).append("\""); 254 xml.append(" threadBody=\"").append(String.valueOf(threadBody)).append("\""); 255 xml.append(" threadVoteCount=\"").append(String.valueOf(threadVoteCount)).append("\""); 256 xml.append(" threadVoteTotalStars=\"").append(String.valueOf(threadVoteTotalStars)).append("\""); 257 xml.append(" threadCreationDate=\"").append(String.valueOf(threadCreationDate)).append("\""); 258 xml.append(" threadLastPostDate=\"").append(String.valueOf(threadLastPostDate)).append("\""); 259 xml.append(" threadType=\"").append(String.valueOf(threadType)).append("\""); 260 xml.append(" threadOption=\"").append(String.valueOf(threadOption)).append("\""); 261 xml.append(" threadStatus=\"").append(String.valueOf(threadStatus)).append("\""); 262 xml.append(" threadHasPoll=\"").append(String.valueOf(threadHasPoll)).append("\""); 263 xml.append(" threadViewCount=\"").append(String.valueOf(threadViewCount)).append("\""); 264 xml.append(" threadReplyCount=\"").append(String.valueOf(threadReplyCount)).append("\""); 265 xml.append(" threadIcon=\"").append(String.valueOf(threadIcon)).append("\""); 266 xml.append(" threadDuration=\"").append(String.valueOf(threadDuration)).append("\""); 267 xml.append(" threadAttachCount=\"").append(String.valueOf(threadAttachCount)).append("\""); 268 xml.append(">"); 269 return xml.toString(); 270 } 271 272 public String getXML() { 273 StringBuffer xml = new StringBuffer (1024); 274 xml.append("<ThreadSection>\n"); 275 xml.append(" <Rows>\n"); 276 xml.append(" <Row>\n"); 277 xml.append(" <Column>\n"); 278 xml.append(" <Name>ThreadID</Name>\n"); 279 xml.append(" <Value>").append(String.valueOf(threadID)).append("</Value>\n"); 280 xml.append(" </Column>\n"); 281 xml.append(" <Column>\n"); 282 xml.append(" <Name>ForumID</Name>\n"); 283 xml.append(" <Value>").append(String.valueOf(forumID)).append("</Value>\n"); 284 xml.append(" </Column>\n"); 285 xml.append(" <Column>\n"); 286 xml.append(" <Name>MemberName</Name>\n"); 287 xml.append(" <Value>").append(String.valueOf(memberName)).append("</Value>\n"); 288 xml.append(" </Column>\n"); 289 xml.append(" <Column>\n"); 290 xml.append(" <Name>LastPostMemberName</Name>\n"); 291 xml.append(" <Value>").append(String.valueOf(lastPostMemberName)).append("</Value>\n"); 292 xml.append(" </Column>\n"); 293 xml.append(" <Column>\n"); 294 xml.append(" <Name>ThreadTopic</Name>\n"); 295 xml.append(" <Value>").append(String.valueOf(threadTopic)).append("</Value>\n"); 296 xml.append(" </Column>\n"); 297 xml.append(" <Column>\n"); 298 xml.append(" <Name>ThreadBody</Name>\n"); 299 xml.append(" <Value>").append(String.valueOf(threadBody)).append("</Value>\n"); 300 xml.append(" </Column>\n"); 301 xml.append(" <Column>\n"); 302 xml.append(" <Name>ThreadVoteCount</Name>\n"); 303 xml.append(" <Value>").append(String.valueOf(threadVoteCount)).append("</Value>\n"); 304 xml.append(" </Column>\n"); 305 xml.append(" <Column>\n"); 306 xml.append(" <Name>ThreadVoteTotalStars</Name>\n"); 307 xml.append(" <Value>").append(String.valueOf(threadVoteTotalStars)).append("</Value>\n"); 308 xml.append(" </Column>\n"); 309 xml.append(" <Column>\n"); 310 xml.append(" <Name>ThreadCreationDate</Name>\n"); 311 xml.append(" <Value>").append(String.valueOf(threadCreationDate)).append("</Value>\n"); 312 xml.append(" </Column>\n"); 313 xml.append(" <Column>\n"); 314 xml.append(" <Name>ThreadLastPostDate</Name>\n"); 315 xml.append(" <Value>").append(String.valueOf(threadLastPostDate)).append("</Value>\n"); 316 xml.append(" </Column>\n"); 317 xml.append(" <Column>\n"); 318 xml.append(" <Name>ThreadType</Name>\n"); 319 xml.append(" <Value>").append(String.valueOf(threadType)).append("</Value>\n"); 320 xml.append(" </Column>\n"); 321 xml.append(" <Column>\n"); 322 xml.append(" <Name>ThreadOption</Name>\n"); 323 xml.append(" <Value>").append(String.valueOf(threadOption)).append("</Value>\n"); 324 xml.append(" </Column>\n"); 325 xml.append(" <Column>\n"); 326 xml.append(" <Name>ThreadStatus</Name>\n"); 327 xml.append(" <Value>").append(String.valueOf(threadStatus)).append("</Value>\n"); 328 xml.append(" </Column>\n"); 329 xml.append(" <Column>\n"); 330 xml.append(" <Name>ThreadHasPoll</Name>\n"); 331 xml.append(" <Value>").append(String.valueOf(threadHasPoll)).append("</Value>\n"); 332 xml.append(" </Column>\n"); 333 xml.append(" <Column>\n"); 334 xml.append(" <Name>ThreadViewCount</Name>\n"); 335 xml.append(" <Value>").append(String.valueOf(threadViewCount)).append("</Value>\n"); 336 xml.append(" </Column>\n"); 337 xml.append(" <Column>\n"); 338 xml.append(" <Name>ThreadReplyCount</Name>\n"); 339 xml.append(" <Value>").append(String.valueOf(threadReplyCount)).append("</Value>\n"); 340 xml.append(" </Column>\n"); 341 xml.append(" <Column>\n"); 342 xml.append(" <Name>ThreadIcon</Name>\n"); 343 xml.append(" <Value>").append(String.valueOf(threadIcon)).append("</Value>\n"); 344 xml.append(" </Column>\n"); 345 xml.append(" <Column>\n"); 346 xml.append(" <Name>ThreadDuration</Name>\n"); 347 xml.append(" <Value>").append(String.valueOf(threadDuration)).append("</Value>\n"); 348 xml.append(" </Column>\n"); 349 xml.append(" <Column>\n"); 350 xml.append(" <Name>ThreadAttachCount</Name>\n"); 351 xml.append(" <Value>").append(String.valueOf(threadAttachCount)).append("</Value>\n"); 352 xml.append(" </Column>\n"); 353 xml.append(" </Row>\n"); 354 xml.append(" </Rows>\n"); 355 xml.append("</ThreadSection>\n"); 356 return xml.toString(); 357 } 358 359 public static String getXML(Collection objThreadBeans) { 360 StringBuffer xml = new StringBuffer (1024); 361 Iterator iterator = objThreadBeans.iterator(); 362 xml.append("<ThreadSection>\n"); 363 xml.append(" <Rows>\n"); 364 while (iterator.hasNext()) { 365 ThreadBean objThreadBean = (ThreadBean)iterator.next(); 366 xml.append(" <Row>\n"); 367 xml.append(" <Column>\n"); 368 xml.append(" <Name>ThreadID</Name>\n"); 369 xml.append(" <Value>").append(String.valueOf(objThreadBean.threadID)).append("</Value>\n"); 370 xml.append(" </Column>\n"); 371 xml.append(" <Column>\n"); 372 xml.append(" <Name>ForumID</Name>\n"); 373 xml.append(" <Value>").append(String.valueOf(objThreadBean.forumID)).append("</Value>\n"); 374 xml.append(" </Column>\n"); 375 xml.append(" <Column>\n"); 376 xml.append(" <Name>MemberName</Name>\n"); 377 xml.append(" <Value>").append(String.valueOf(objThreadBean.memberName)).append("</Value>\n"); 378 xml.append(" </Column>\n"); 379 xml.append(" <Column>\n"); 380 xml.append(" <Name>LastPostMemberName</Name>\n"); 381 xml.append(" <Value>").append(String.valueOf(objThreadBean.lastPostMemberName)).append("</Value>\n"); 382 xml.append(" </Column>\n"); 383 xml.append(" <Column>\n"); 384 xml.append(" <Name>ThreadTopic</Name>\n"); 385 xml.append(" <Value>").append(String.valueOf(objThreadBean.threadTopic)).append("</Value>\n"); 386 xml.append(" </Column>\n"); 387 xml.append(" <Column>\n"); 388 xml.append(" <Name>ThreadBody</Name>\n"); 389 xml.append(" <Value>").append(String.valueOf(objThreadBean.threadBody)).append("</Value>\n"); 390 xml.append(" </Column>\n"); 391 xml.append(" <Column>\n"); 392 xml.append(" <Name>ThreadVoteCount</Name>\n"); 393 xml.append(" <Value>").append(String.valueOf(objThreadBean.threadVoteCount)).append("</Value>\n"); 394 xml.append(" </Column>\n"); 395 xml.append(" <Column>\n"); 396 xml.append(" <Name>ThreadVoteTotalStars</Name>\n"); 397 xml.append(" <Value>").append(String.valueOf(objThreadBean.threadVoteTotalStars)).append("</Value>\n"); 398 xml.append(" </Column>\n"); 399 xml.append(" <Column>\n"); 400 xml.append(" <Name>ThreadCreationDate</Name>\n"); 401 xml.append(" <Value>").append(String.valueOf(objThreadBean.threadCreationDate)).append("</Value>\n"); 402 xml.append(" </Column>\n"); 403 xml.append(" <Column>\n"); 404 xml.append(" <Name>ThreadLastPostDate</Name>\n"); 405 xml.append(" <Value>").append(String.valueOf(objThreadBean.threadLastPostDate)).append("</Value>\n"); 406 xml.append(" </Column>\n"); 407 xml.append(" <Column>\n"); 408 xml.append(" <Name>ThreadType</Name>\n"); 409 xml.append(" <Value>").append(String.valueOf(objThreadBean.threadType)).append("</Value>\n"); 410 xml.append(" </Column>\n"); 411 xml.append(" <Column>\n"); 412 xml.append(" <Name>ThreadOption</Name>\n"); 413 xml.append(" <Value>").append(String.valueOf(objThreadBean.threadOption)).append("</Value>\n"); 414 xml.append(" </Column>\n"); 415 xml.append(" <Column>\n"); 416 xml.append(" <Name>ThreadStatus</Name>\n"); 417 xml.append(" <Value>").append(String.valueOf(objThreadBean.threadStatus)).append("</Value>\n"); 418 xml.append(" </Column>\n"); 419 xml.append(" <Column>\n"); 420 xml.append(" <Name>ThreadHasPoll</Name>\n"); 421 xml.append(" <Value>").append(String.valueOf(objThreadBean.threadHasPoll)).append("</Value>\n"); 422 xml.append(" </Column>\n"); 423 xml.append(" <Column>\n"); 424 xml.append(" <Name>ThreadViewCount</Name>\n"); 425 xml.append(" <Value>").append(String.valueOf(objThreadBean.threadViewCount)).append("</Value>\n"); 426 xml.append(" </Column>\n"); 427 xml.append(" <Column>\n"); 428 xml.append(" <Name>ThreadReplyCount</Name>\n"); 429 xml.append(" <Value>").append(String.valueOf(objThreadBean.threadReplyCount)).append("</Value>\n"); 430 xml.append(" </Column>\n"); 431 xml.append(" <Column>\n"); 432 xml.append(" <Name>ThreadIcon</Name>\n"); 433 xml.append(" <Value>").append(String.valueOf(objThreadBean.threadIcon)).append("</Value>\n"); 434 xml.append(" </Column>\n"); 435 xml.append(" <Column>\n"); 436 xml.append(" <Name>ThreadDuration</Name>\n"); 437 xml.append(" <Value>").append(String.valueOf(objThreadBean.threadDuration)).append("</Value>\n"); 438 xml.append(" </Column>\n"); 439 xml.append(" <Column>\n"); 440 xml.append(" <Name>ThreadAttachCount</Name>\n"); 441 xml.append(" <Value>").append(String.valueOf(objThreadBean.threadAttachCount)).append("</Value>\n"); 442 xml.append(" </Column>\n"); 443 xml.append(" </Row>\n"); 444 } xml.append(" </Rows>\n"); 446 xml.append("</ThreadSection>\n"); 447 return xml.toString(); 448 } 449 450 453 private int threadPendingPostCount; 454 455 public int getThreadPendingPostCount() { 456 return threadPendingPostCount; 457 } 458 public void setThreadPendingPostCount(int threadPendingPostCount) { 459 this.threadPendingPostCount = threadPendingPostCount; 460 } 461 462 private Collection pendingPosts; 463 464 public Collection getPendingPosts() { 465 return pendingPosts; 466 } 467 public void setPendingPosts(Collection pendingPosts) { 468 this.pendingPosts = pendingPosts; 469 } 470 471 static public void validateThreadStatus(int status) throws IllegalArgumentException { 472 if ((status < 0) || (status > THREAD_STATUS_CLOSED)) { 473 throw new IllegalArgumentException ("Invalid ThreadStatus = " + status); 474 } 475 } 476 477 static public void validateThreadType(int type) throws IllegalArgumentException { 478 if ((type < 0) || (type > THREAD_TYPE_GLOBAL_ANNOUNCEMENT)) { 479 throw new IllegalArgumentException ("Invalid ThreadType = " + type); 480 } 481 } 482 483 public void ensureStatusCanReply() throws IllegalArgumentException { 484 if ( (getThreadStatus() == ThreadBean.THREAD_STATUS_LOCKED) || 485 (getThreadStatus() == ThreadBean.THREAD_STATUS_CLOSED)) { 486 throw new IllegalStateException ("Cannot reply when the thread is closed or locked."); 489 } 490 } 491 492 public void ensureStatusCanEdit() throws IllegalArgumentException { 493 if ( (getThreadStatus() == ThreadBean.THREAD_STATUS_LOCKED) ) { 494 throw new IllegalStateException ("Cannot edit post when the thread is locked."); 497 } 498 } 499 500 } | Popular Tags |