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 import net.myvietnam.mvncore.exception.BadInputException; 49 import com.mvnforum.MVNForumConfig; 50 51 58 public class ForumBean { 59 63 64 65 public final static int FORUM_STATUS_DEFAULT = 0; 66 67 68 public final static int FORUM_STATUS_DISABLED = 1; 69 70 74 public final static int FORUM_STATUS_LOCKED = 2; 75 76 77 public final static int FORUM_STATUS_CLOSED = 3; 78 79 80 81 public final static int FORUM_TYPE_DEFAULT = 0; 82 83 84 public final static int FORUM_TYPE_PRIVATE = 1; 85 86 87 88 public final static int FORUM_MODERATION_MODE_SYSTEM_DEFAULT = 0; 89 90 91 public final static int FORUM_MODERATION_MODE_NO_MODERATION = 1; 92 93 94 public final static int FORUM_MODERATION_MODE_THREAD_AND_POST = 2; 95 96 97 public final static int FORUM_MODERATION_MODE_THREAD_ONLY = 3; 98 99 100 public final static int FORUM_MODERATION_MODE_POST_ONLY = 4; 101 102 public final static String TYPE_NAMES[] = {"Default", "Private"}; 103 104 public final static String MODE_NAMES[] = {"System Default", "No Moderation", "Thread and Post Moderation", "Thread Only Moderation", "Post Only Moderation"}; 105 106 private int forumID; 107 private int categoryID; 108 private String lastPostMemberName; 109 private String forumName; 110 private String forumDesc; 111 private Timestamp forumCreationDate; 112 private Timestamp forumModifiedDate; 113 private Timestamp forumLastPostDate; 114 private int forumOrder; 115 private int forumType; 116 private int forumFormatOption; 117 private int forumOption; 118 private int forumStatus; 119 private int forumModerationMode; 120 private String forumPassword; 121 private int forumThreadCount; 122 private int forumPostCount; 123 124 public int getForumID() { 125 return forumID; 126 } 127 public void setForumID(int forumID) { 128 this.forumID = forumID; 129 } 130 131 public int getCategoryID() { 132 return categoryID; 133 } 134 public void setCategoryID(int categoryID) { 135 this.categoryID = categoryID; 136 } 137 138 public String getLastPostMemberName() { 139 return lastPostMemberName; 140 } 141 public void setLastPostMemberName(String lastPostMemberName) { 142 this.lastPostMemberName = StringUtil.getEmptyStringIfNull(lastPostMemberName); 143 } 144 145 public String getForumName() { 146 return forumName; 147 } 148 public void setForumName(String forumName) { 149 this.forumName = forumName; 150 } 151 152 public String getForumDesc() { 153 return forumDesc; 154 } 155 public void setForumDesc(String forumDesc) { 156 this.forumDesc = StringUtil.getEmptyStringIfNull(forumDesc); 157 } 158 159 public Timestamp getForumCreationDate() { 160 return forumCreationDate; 161 } 162 public void setForumCreationDate(Timestamp forumCreationDate) { 163 this.forumCreationDate = forumCreationDate; 164 } 165 166 public Timestamp getForumModifiedDate() { 167 return forumModifiedDate; 168 } 169 public void setForumModifiedDate(Timestamp forumModifiedDate) { 170 this.forumModifiedDate = forumModifiedDate; 171 } 172 173 public Timestamp getForumLastPostDate() { 174 return forumLastPostDate; 175 } 176 public void setForumLastPostDate(Timestamp forumLastPostDate) { 177 this.forumLastPostDate = forumLastPostDate; 178 } 179 180 public int getForumOrder() { 181 return forumOrder; 182 } 183 public void setForumOrder(int forumOrder) { 184 this.forumOrder = forumOrder; 185 } 186 187 public int getForumType() { 188 return forumType; 189 } 190 public void setForumType(int forumType) { 191 this.forumType = forumType; 192 } 193 194 public int getForumFormatOption() { 195 return forumFormatOption; 196 } 197 public void setForumFormatOption(int forumFormatOption) { 198 this.forumFormatOption = forumFormatOption; 199 } 200 201 public int getForumOption() { 202 return forumOption; 203 } 204 public void setForumOption(int forumOption) { 205 this.forumOption = forumOption; 206 } 207 208 public int getForumStatus() { 209 return forumStatus; 210 } 211 public void setForumStatus(int forumStatus) { 212 this.forumStatus = forumStatus; 213 } 214 215 public int getForumModerationMode() { 216 return forumModerationMode; 217 } 218 public void setForumModerationMode(int forumModerationMode) { 219 this.forumModerationMode = forumModerationMode; 220 } 221 222 public String getForumPassword() { 223 return forumPassword; 224 } 225 public void setForumPassword(String forumPassword) { 226 this.forumPassword = StringUtil.getEmptyStringIfNull(forumPassword); 227 } 228 229 public int getForumThreadCount() { 230 return forumThreadCount; 231 } 232 public void setForumThreadCount(int forumThreadCount) { 233 this.forumThreadCount = forumThreadCount; 234 } 235 236 public int getForumPostCount() { 237 return forumPostCount; 238 } 239 public void setForumPostCount(int forumPostCount) { 240 this.forumPostCount = forumPostCount; 241 } 242 243 public String getXMLTag() { 244 StringBuffer xml = new StringBuffer (1024); 245 xml.append("<Forum"); 246 xml.append(" forumID=\"").append(String.valueOf(forumID)).append("\""); 247 xml.append(" categoryID=\"").append(String.valueOf(categoryID)).append("\""); 248 xml.append(" lastPostMemberName=\"").append(String.valueOf(lastPostMemberName)).append("\""); 249 xml.append(" forumName=\"").append(String.valueOf(forumName)).append("\""); 250 xml.append(" forumDesc=\"").append(String.valueOf(forumDesc)).append("\""); 251 xml.append(" forumCreationDate=\"").append(String.valueOf(forumCreationDate)).append("\""); 252 xml.append(" forumModifiedDate=\"").append(String.valueOf(forumModifiedDate)).append("\""); 253 xml.append(" forumLastPostDate=\"").append(String.valueOf(forumLastPostDate)).append("\""); 254 xml.append(" forumOrder=\"").append(String.valueOf(forumOrder)).append("\""); 255 xml.append(" forumType=\"").append(String.valueOf(forumType)).append("\""); 256 xml.append(" forumFormatOption=\"").append(String.valueOf(forumFormatOption)).append("\""); 257 xml.append(" forumOption=\"").append(String.valueOf(forumOption)).append("\""); 258 xml.append(" forumStatus=\"").append(String.valueOf(forumStatus)).append("\""); 259 xml.append(" forumModerationMode=\"").append(String.valueOf(forumModerationMode)).append("\""); 260 xml.append(" forumPassword=\"").append(String.valueOf(forumPassword)).append("\""); 261 xml.append(" forumThreadCount=\"").append(String.valueOf(forumThreadCount)).append("\""); 262 xml.append(" forumPostCount=\"").append(String.valueOf(forumPostCount)).append("\""); 263 xml.append(">"); 264 return xml.toString(); 265 } 266 267 public String getXML() { 268 StringBuffer xml = new StringBuffer (1024); 269 xml.append("<ForumSection>\n"); 270 xml.append(" <Rows>\n"); 271 xml.append(" <Row>\n"); 272 xml.append(" <Column>\n"); 273 xml.append(" <Name>ForumID</Name>\n"); 274 xml.append(" <Value>").append(String.valueOf(forumID)).append("</Value>\n"); 275 xml.append(" </Column>\n"); 276 xml.append(" <Column>\n"); 277 xml.append(" <Name>CategoryID</Name>\n"); 278 xml.append(" <Value>").append(String.valueOf(categoryID)).append("</Value>\n"); 279 xml.append(" </Column>\n"); 280 xml.append(" <Column>\n"); 281 xml.append(" <Name>LastPostMemberName</Name>\n"); 282 xml.append(" <Value>").append(String.valueOf(lastPostMemberName)).append("</Value>\n"); 283 xml.append(" </Column>\n"); 284 xml.append(" <Column>\n"); 285 xml.append(" <Name>ForumName</Name>\n"); 286 xml.append(" <Value>").append(String.valueOf(forumName)).append("</Value>\n"); 287 xml.append(" </Column>\n"); 288 xml.append(" <Column>\n"); 289 xml.append(" <Name>ForumDesc</Name>\n"); 290 xml.append(" <Value>").append(String.valueOf(forumDesc)).append("</Value>\n"); 291 xml.append(" </Column>\n"); 292 xml.append(" <Column>\n"); 293 xml.append(" <Name>ForumCreationDate</Name>\n"); 294 xml.append(" <Value>").append(String.valueOf(forumCreationDate)).append("</Value>\n"); 295 xml.append(" </Column>\n"); 296 xml.append(" <Column>\n"); 297 xml.append(" <Name>ForumModifiedDate</Name>\n"); 298 xml.append(" <Value>").append(String.valueOf(forumModifiedDate)).append("</Value>\n"); 299 xml.append(" </Column>\n"); 300 xml.append(" <Column>\n"); 301 xml.append(" <Name>ForumLastPostDate</Name>\n"); 302 xml.append(" <Value>").append(String.valueOf(forumLastPostDate)).append("</Value>\n"); 303 xml.append(" </Column>\n"); 304 xml.append(" <Column>\n"); 305 xml.append(" <Name>ForumOrder</Name>\n"); 306 xml.append(" <Value>").append(String.valueOf(forumOrder)).append("</Value>\n"); 307 xml.append(" </Column>\n"); 308 xml.append(" <Column>\n"); 309 xml.append(" <Name>ForumType</Name>\n"); 310 xml.append(" <Value>").append(String.valueOf(forumType)).append("</Value>\n"); 311 xml.append(" </Column>\n"); 312 xml.append(" <Column>\n"); 313 xml.append(" <Name>ForumFormatOption</Name>\n"); 314 xml.append(" <Value>").append(String.valueOf(forumFormatOption)).append("</Value>\n"); 315 xml.append(" </Column>\n"); 316 xml.append(" <Column>\n"); 317 xml.append(" <Name>ForumOption</Name>\n"); 318 xml.append(" <Value>").append(String.valueOf(forumOption)).append("</Value>\n"); 319 xml.append(" </Column>\n"); 320 xml.append(" <Column>\n"); 321 xml.append(" <Name>ForumStatus</Name>\n"); 322 xml.append(" <Value>").append(String.valueOf(forumStatus)).append("</Value>\n"); 323 xml.append(" </Column>\n"); 324 xml.append(" <Column>\n"); 325 xml.append(" <Name>ForumModerationMode</Name>\n"); 326 xml.append(" <Value>").append(String.valueOf(forumModerationMode)).append("</Value>\n"); 327 xml.append(" </Column>\n"); 328 xml.append(" <Column>\n"); 329 xml.append(" <Name>ForumPassword</Name>\n"); 330 xml.append(" <Value>").append(String.valueOf(forumPassword)).append("</Value>\n"); 331 xml.append(" </Column>\n"); 332 xml.append(" <Column>\n"); 333 xml.append(" <Name>ForumThreadCount</Name>\n"); 334 xml.append(" <Value>").append(String.valueOf(forumThreadCount)).append("</Value>\n"); 335 xml.append(" </Column>\n"); 336 xml.append(" <Column>\n"); 337 xml.append(" <Name>ForumPostCount</Name>\n"); 338 xml.append(" <Value>").append(String.valueOf(forumPostCount)).append("</Value>\n"); 339 xml.append(" </Column>\n"); 340 xml.append(" </Row>\n"); 341 xml.append(" </Rows>\n"); 342 xml.append("</ForumSection>\n"); 343 return xml.toString(); 344 } 345 346 public static String getXML(Collection objForumBeans) { 347 StringBuffer xml = new StringBuffer (1024); 348 Iterator iterator = objForumBeans.iterator(); 349 xml.append("<ForumSection>\n"); 350 xml.append(" <Rows>\n"); 351 while (iterator.hasNext()) { 352 ForumBean objForumBean = (ForumBean)iterator.next(); 353 xml.append(" <Row>\n"); 354 xml.append(" <Column>\n"); 355 xml.append(" <Name>ForumID</Name>\n"); 356 xml.append(" <Value>").append(String.valueOf(objForumBean.forumID)).append("</Value>\n"); 357 xml.append(" </Column>\n"); 358 xml.append(" <Column>\n"); 359 xml.append(" <Name>CategoryID</Name>\n"); 360 xml.append(" <Value>").append(String.valueOf(objForumBean.categoryID)).append("</Value>\n"); 361 xml.append(" </Column>\n"); 362 xml.append(" <Column>\n"); 363 xml.append(" <Name>LastPostMemberName</Name>\n"); 364 xml.append(" <Value>").append(String.valueOf(objForumBean.lastPostMemberName)).append("</Value>\n"); 365 xml.append(" </Column>\n"); 366 xml.append(" <Column>\n"); 367 xml.append(" <Name>ForumName</Name>\n"); 368 xml.append(" <Value>").append(String.valueOf(objForumBean.forumName)).append("</Value>\n"); 369 xml.append(" </Column>\n"); 370 xml.append(" <Column>\n"); 371 xml.append(" <Name>ForumDesc</Name>\n"); 372 xml.append(" <Value>").append(String.valueOf(objForumBean.forumDesc)).append("</Value>\n"); 373 xml.append(" </Column>\n"); 374 xml.append(" <Column>\n"); 375 xml.append(" <Name>ForumCreationDate</Name>\n"); 376 xml.append(" <Value>").append(String.valueOf(objForumBean.forumCreationDate)).append("</Value>\n"); 377 xml.append(" </Column>\n"); 378 xml.append(" <Column>\n"); 379 xml.append(" <Name>ForumModifiedDate</Name>\n"); 380 xml.append(" <Value>").append(String.valueOf(objForumBean.forumModifiedDate)).append("</Value>\n"); 381 xml.append(" </Column>\n"); 382 xml.append(" <Column>\n"); 383 xml.append(" <Name>ForumLastPostDate</Name>\n"); 384 xml.append(" <Value>").append(String.valueOf(objForumBean.forumLastPostDate)).append("</Value>\n"); 385 xml.append(" </Column>\n"); 386 xml.append(" <Column>\n"); 387 xml.append(" <Name>ForumOrder</Name>\n"); 388 xml.append(" <Value>").append(String.valueOf(objForumBean.forumOrder)).append("</Value>\n"); 389 xml.append(" </Column>\n"); 390 xml.append(" <Column>\n"); 391 xml.append(" <Name>ForumType</Name>\n"); 392 xml.append(" <Value>").append(String.valueOf(objForumBean.forumType)).append("</Value>\n"); 393 xml.append(" </Column>\n"); 394 xml.append(" <Column>\n"); 395 xml.append(" <Name>ForumFormatOption</Name>\n"); 396 xml.append(" <Value>").append(String.valueOf(objForumBean.forumFormatOption)).append("</Value>\n"); 397 xml.append(" </Column>\n"); 398 xml.append(" <Column>\n"); 399 xml.append(" <Name>ForumOption</Name>\n"); 400 xml.append(" <Value>").append(String.valueOf(objForumBean.forumOption)).append("</Value>\n"); 401 xml.append(" </Column>\n"); 402 xml.append(" <Column>\n"); 403 xml.append(" <Name>ForumStatus</Name>\n"); 404 xml.append(" <Value>").append(String.valueOf(objForumBean.forumStatus)).append("</Value>\n"); 405 xml.append(" </Column>\n"); 406 xml.append(" <Column>\n"); 407 xml.append(" <Name>ForumModerationMode</Name>\n"); 408 xml.append(" <Value>").append(String.valueOf(objForumBean.forumModerationMode)).append("</Value>\n"); 409 xml.append(" </Column>\n"); 410 xml.append(" <Column>\n"); 411 xml.append(" <Name>ForumPassword</Name>\n"); 412 xml.append(" <Value>").append(String.valueOf(objForumBean.forumPassword)).append("</Value>\n"); 413 xml.append(" </Column>\n"); 414 xml.append(" <Column>\n"); 415 xml.append(" <Name>ForumThreadCount</Name>\n"); 416 xml.append(" <Value>").append(String.valueOf(objForumBean.forumThreadCount)).append("</Value>\n"); 417 xml.append(" </Column>\n"); 418 xml.append(" <Column>\n"); 419 xml.append(" <Name>ForumPostCount</Name>\n"); 420 xml.append(" <Value>").append(String.valueOf(objForumBean.forumPostCount)).append("</Value>\n"); 421 xml.append(" </Column>\n"); 422 xml.append(" </Row>\n"); 423 } xml.append(" </Rows>\n"); 425 xml.append("</ForumSection>\n"); 426 return xml.toString(); 427 } 428 429 432 private int pendingThreadCount = 0; 433 private int threadsWithPendingPostsCount = 0; 434 private int pendingPostCount = 0; 435 436 public int getPendingPostCount() { 437 return pendingPostCount; 438 } 439 public void setPendingPostCount(int pendingPostCount) { 440 this.pendingPostCount = pendingPostCount; 441 } 442 443 public int getPendingThreadCount() { 444 return pendingThreadCount; 445 } 446 public void setPendingThreadCount(int pendingThreadCount) { 447 this.pendingThreadCount = pendingThreadCount; 448 } 449 450 public int getThreadsWithPendingPostsCount() { 451 return threadsWithPendingPostsCount; 452 } 453 public void setThreadsWithPendingPostsCount(int threadsWithPendingPostsCount) { 454 this.threadsWithPendingPostsCount = threadsWithPendingPostsCount; 455 } 456 457 static public void validateForumType(int type) throws IllegalArgumentException { 458 if ((type < 0) || (type > FORUM_TYPE_PRIVATE)) { 459 throw new IllegalArgumentException ("Invalid ForumType = " + type); 460 } 461 } 462 463 static public void validateForumModerationMode(int moderationMod) throws IllegalArgumentException { 464 if ((moderationMod < 0) || (moderationMod > FORUM_MODERATION_MODE_POST_ONLY)) { 465 throw new IllegalArgumentException ("Invalid ForumModerationMod = " + moderationMod); 466 } 467 } 468 469 static public void validateForumStatus(int status) throws IllegalArgumentException { 470 if ((status < 0) || (status > FORUM_STATUS_CLOSED)) { 471 throw new IllegalArgumentException ("Invalid ForumStatus = " + status); 472 } 473 } 474 475 static public void validateForumOption(int option) throws IllegalArgumentException { 476 if ((option < 0) || (option > 0)) { 477 throw new IllegalArgumentException ("Invalid ForumOption = " + option); 478 } 479 } 480 481 static public void validateForumFormatOption(int option) throws IllegalArgumentException { 482 if ((option < 0) || (option > 0)) { 483 throw new IllegalArgumentException ("Invalid ForumFormatOption = " + option); 484 } 485 } 486 487 public void ensureNotDisabledForum() throws BadInputException { 488 if (forumStatus == ForumBean.FORUM_STATUS_DISABLED) { 489 throw new BadInputException("Cannot process this action in a disabled forum."); } 491 } 492 493 public void ensureNotLockedForum() throws BadInputException { 494 if (forumStatus == ForumBean.FORUM_STATUS_LOCKED) { 495 throw new BadInputException("Cannot process this action in a locked forum."); } 497 } 498 499 public void ensureNotClosedForum() throws BadInputException { 500 if (forumStatus == ForumBean.FORUM_STATUS_CLOSED) { 501 throw new BadInputException("Cannot process this action in a closed forum."); } 503 } 504 505 public boolean shouldModeratePost() { 506 int mode = forumModerationMode; 507 if (mode == FORUM_MODERATION_MODE_SYSTEM_DEFAULT) { 508 mode = MVNForumConfig.getDefaultModerationOption(); 509 } 510 if ((mode == FORUM_MODERATION_MODE_POST_ONLY) || (mode == FORUM_MODERATION_MODE_THREAD_AND_POST)) { 511 return true; 512 } 513 return false; 514 } 515 516 public boolean shouldModerateThread() { 517 int mode = forumModerationMode; 518 if (mode == FORUM_MODERATION_MODE_SYSTEM_DEFAULT) { 519 mode = MVNForumConfig.getDefaultModerationOption(); 520 } 521 if ((mode == FORUM_MODERATION_MODE_THREAD_ONLY) || (mode == FORUM_MODERATION_MODE_THREAD_AND_POST)) { 522 return true; 523 } 524 return false; 525 } 526 527 public String getForumModeName() { 528 return MODE_NAMES[this.forumModerationMode]; 529 } 530 531 public String getForumTypeName() { 532 return TYPE_NAMES[this.forumType]; 533 } 534 535 536 } | Popular Tags |