1 31 package org.blojsom.blog.database; 32 33 import org.blojsom.blog.*; 34 import org.blojsom.util.BlojsomUtils; 35 36 import java.io.Serializable ; 37 import java.util.*; 38 import java.text.SimpleDateFormat ; 39 40 47 public class DatabaseEntry implements Entry, Serializable { 48 49 protected Integer _id; 50 protected Integer _blogCategoryId; 51 protected Integer _blogId; 52 53 protected String _title; 54 protected String _link; 55 protected String _description; 56 protected Date _entryDate; 57 protected Date _modifiedDate; 58 protected List _comments; 59 protected List _trackbacks; 60 protected List _pingbacks; 61 protected Category _category; 62 protected Map _metaData; 63 protected Integer _allowComments; 64 protected Integer _allowTrackbacks; 65 protected Integer _allowPingbacks; 66 protected String _status; 67 protected String _author; 68 protected String _postSlug; 69 70 73 public DatabaseEntry() { 74 } 75 76 81 public void setId(Integer id) { 82 _id = id; 83 } 84 85 90 public Integer getId() { 91 return _id; 92 } 93 94 99 public Integer getBlogCategoryId() { 100 return _blogCategoryId; 101 } 102 103 108 public void setBlogCategoryId(Integer blogCategoryId) { 109 _blogCategoryId = blogCategoryId; 110 } 111 112 117 public Integer getBlogId() { 118 return _blogId; 119 } 120 121 126 public void setBlogId(Integer blogId) { 127 _blogId = blogId; 128 } 129 130 137 public Date getDate() { 138 return _entryDate; 139 } 140 141 146 public void setDate(Date entryDate) { 147 _entryDate = entryDate; 148 } 149 150 155 public Date getModifiedDate() { 156 return _modifiedDate; 157 } 158 159 164 public void setModifiedDate(Date modifiedDate) { 165 _modifiedDate = modifiedDate; 166 } 167 168 173 public String getRFC822Date() { 174 return BlojsomUtils.getRFC822Date(_entryDate); 175 } 176 177 182 public String getUTCDate() { 183 return BlojsomUtils.getUTCDate(_entryDate); 184 } 185 186 192 public String getISO8601Date() { 193 return BlojsomUtils.getISO8601Date(_entryDate); 194 } 195 196 202 public String getDateAsFormat(String format) { 203 return getDateAsFormat(format, null); 204 } 205 206 213 public String getDateAsFormat(String format, Locale locale) { 214 if (_entryDate == null || format == null) { 215 return null; 216 } 217 218 SimpleDateFormat sdf; 219 try { 220 if (locale == null) { 221 sdf = new SimpleDateFormat (format); 222 } else { 223 sdf = new SimpleDateFormat (format, locale); 224 } 225 226 return sdf.format(_entryDate); 227 } catch (IllegalArgumentException e) { 228 return _entryDate.toString(); 229 } 230 } 231 232 237 public String getTitle() { 238 return _title; 239 } 240 241 246 public void setTitle(String title) { 247 _title = title; 248 } 249 250 255 public String getEscapedTitle() { 256 return BlojsomUtils.escapeString(_title); 257 } 258 259 264 public String getDescription() { 265 return _description; 266 } 267 268 274 public String getEscapedDescription() { 275 return BlojsomUtils.escapeString(_description); 276 } 277 278 283 public void setDescription(String description) { 284 _description = description; 285 } 286 287 292 public String getCategory() { 293 return _category.getName(); 294 } 295 296 301 public String getEncodedCategory() { 302 return _category.getEncodedName(); 303 } 304 305 310 public Integer getAllowComments() { 311 return _allowComments; 312 } 313 314 319 public List getComments() { 320 if (_comments == null) { 321 return new ArrayList(); 322 } 323 324 return _comments; 325 } 326 327 333 public void setComments(List comments) { 334 _comments = comments; 335 } 336 337 342 public Comment[] getCommentsAsArray() { 343 if (_comments == null) { 344 return new Comment[0]; 345 } else { 346 return (Comment[]) _comments.toArray(new Comment[_comments.size()]); 347 } 348 } 349 350 355 public int getNumComments() { 356 if (_comments == null) { 357 return 0; 358 } else { 359 return _comments.size(); 360 } 361 } 362 363 368 public Integer getAllowTrackbacks() { 369 return _allowTrackbacks; 370 } 371 372 377 public List getTrackbacks() { 378 if (_trackbacks == null) { 379 return new ArrayList(); 380 } 381 382 return _trackbacks; 383 } 384 385 391 public void setTrackbacks(List trackbacks) { 392 _trackbacks = trackbacks; 393 } 394 395 400 public Trackback[] getTrackbacksAsArray() { 401 if (_trackbacks == null) { 402 return new Trackback[0]; 403 } else { 404 return (Trackback[]) _trackbacks.toArray(new Trackback[_trackbacks.size()]); 405 } 406 } 407 408 413 public int getNumTrackbacks() { 414 if (_trackbacks == null) { 415 return 0; 416 } else { 417 return _trackbacks.size(); 418 } 419 } 420 421 426 public Category getBlogCategory() { 427 return _category; 428 } 429 430 435 public void setBlogCategory(Category blogCategory) { 436 _category = blogCategory; 437 } 438 439 444 public Map getMetaData() { 445 if (_metaData == null) { 446 return new HashMap(); 447 } 448 449 return _metaData; 450 } 451 452 457 public void setMetaData(Map metaData) { 458 _metaData = metaData; 459 } 460 461 466 public Integer getAllowPingbacks() { 467 return _allowPingbacks; 468 } 469 470 475 public List getPingbacks() { 476 if (_pingbacks == null) { 477 return new ArrayList(); 478 } 479 480 return _pingbacks; 481 } 482 483 489 public void setPingbacks(List pingbacks) { 490 _pingbacks = pingbacks; 491 } 492 493 498 public Pingback[] getPingbacksAsArray() { 499 if (_pingbacks == null) { 500 return new Pingback[0]; 501 } else { 502 return (Pingback[]) _pingbacks.toArray(new Pingback[_pingbacks.size()]); 503 } 504 } 505 506 511 public int getNumPingbacks() { 512 if (_pingbacks == null) { 513 return 0; 514 } else { 515 return _pingbacks.size(); 516 } 517 } 518 519 524 public void setAllowComments(Integer allowComments) { 525 _allowComments = allowComments; 526 } 527 528 533 public void setAllowTrackbacks(Integer allowTrackbacks) { 534 _allowTrackbacks = allowTrackbacks; 535 } 536 541 public void setAllowPingbacks(Integer allowPingbacks) { 542 _allowPingbacks = allowPingbacks; 543 } 544 545 550 public String getStatus() { 551 return _status; 552 } 553 554 559 public void setStatus(String status) { 560 _status = status; 561 } 562 563 568 public String getAuthor() { 569 return _author; 570 } 571 572 577 public void setAuthor(String author) { 578 _author = author; 579 } 580 581 586 public Boolean allowsComments() { 587 if (_allowComments == null) { 588 return Boolean.TRUE; 589 } 590 591 return Boolean.valueOf((_allowComments.intValue() == 1)); 592 } 593 594 599 public Boolean allowsTrackbacks() { 600 if (_allowTrackbacks == null) { 601 return Boolean.TRUE; 602 } 603 604 return Boolean.valueOf((_allowTrackbacks.intValue() == 1)); 605 } 606 607 612 public Boolean allowsPingbacks() { 613 if (_allowPingbacks == null) { 614 return Boolean.TRUE; 615 } 616 617 return Boolean.valueOf((_allowPingbacks.intValue() == 1)); 618 } 619 620 625 public String getPostSlug() { 626 return _postSlug; 627 } 628 629 634 public void setPostSlug(String postSlug) { 635 _postSlug = postSlug; 636 } 637 638 643 public List getResponses() { 644 List responses = new ArrayList(); 645 646 responses.addAll(getComments()); 647 responses.addAll(getTrackbacks()); 648 responses.addAll(getPingbacks()); 649 650 Collections.sort(responses, BlojsomUtils.RESPONSE_COMPARATOR); 651 652 return responses; 653 } 654 655 661 public List getResponsesMatchingStatus(String status) { 662 List responses = getResponses(); 663 664 for (int i = 0; i < responses.size(); i++) { 665 Response response = (Response) responses.get(i); 666 if (!status.equals(response.getStatus())) { 667 responses.set(i, null); 668 } 669 } 670 671 return BlojsomUtils.removeNullValues(responses); 672 } 673 674 680 public List getResponsesNotMatchingStatus(String status) { 681 List responses = getResponses(); 682 683 for (int i = 0; i < responses.size(); i++) { 684 Response response = (Response) responses.get(i); 685 if (status.equals(response.getStatus())) { 686 responses.set(i, null); 687 } 688 } 689 690 return BlojsomUtils.removeNullValues(responses); 691 } 692 } 693 | Popular Tags |