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