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