| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
package net.sourceforge.pebble.domain; |
| 33 | |
|
| 34 | |
import net.sourceforge.pebble.api.event.blogentry.BlogEntryEvent; |
| 35 | |
import net.sourceforge.pebble.api.event.comment.CommentEvent; |
| 36 | |
import net.sourceforge.pebble.api.event.trackback.TrackBackEvent; |
| 37 | |
import net.sourceforge.pebble.comparator.ResponseByDateComparator; |
| 38 | |
import net.sourceforge.pebble.web.validation.ValidationContext; |
| 39 | |
import net.sourceforge.pebble.trackback.TrackBackTokenManager; |
| 40 | |
import org.apache.commons.logging.Log; |
| 41 | |
import org.apache.commons.logging.LogFactory; |
| 42 | |
|
| 43 | |
import java.util.*; |
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
|
| 50 | |
public class BlogEntry extends PageBasedContent { |
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | 4 | private static Log log = LogFactory.getLog(BlogEntry.class); |
| 56 | |
|
| 57 | |
public static final String EXCERPT_PROPERTY = "excerpt"; |
| 58 | |
public static final String COMMENTS_ENABLED_PROPERTY = "commentsEnabed"; |
| 59 | |
public static final String TRACKBACKS_ENABLED_PROPERTY = "trackBacksEnabled"; |
| 60 | |
public static final String ATTACHMENT_PROPERTY = "attachment"; |
| 61 | |
public static final String CATEGORIES_PROPERTY = "categories"; |
| 62 | |
|
| 63 | |
|
| 64 | |
private String permalink; |
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | 3076 | private Set categories = new HashSet(); |
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
|
| 74 | 3076 | private String excerpt = ""; |
| 75 | |
|
| 76 | |
|
| 77 | |
|
| 78 | |
|
| 79 | 3076 | private boolean commentsEnabled = true; |
| 80 | |
|
| 81 | |
|
| 82 | |
|
| 83 | |
|
| 84 | 3076 | private boolean trackBacksEnabled = true; |
| 85 | |
|
| 86 | |
|
| 87 | |
|
| 88 | |
|
| 89 | 3076 | private List comments = new ArrayList(); |
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | 3076 | private List trackBacks = new ArrayList(); |
| 95 | |
|
| 96 | |
|
| 97 | |
private Attachment attachment; |
| 98 | |
|
| 99 | |
|
| 100 | |
private String timeZoneId; |
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
public BlogEntry(Blog blog) { |
| 108 | 3076 | super(blog); |
| 109 | 3076 | setPublished(false); |
| 110 | 3076 | } |
| 111 | |
|
| 112 | |
|
| 113 | |
|
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
public void setTitle(String newTitle) { |
| 118 | 2520 | super.setTitle(newTitle); |
| 119 | |
|
| 120 | |
|
| 121 | 2520 | this.permalink = null; |
| 122 | 2520 | } |
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
public Set<Category> getCategories() { |
| 130 | 3028 | return new HashSet<Category>(categories); |
| 131 | |
} |
| 132 | |
|
| 133 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
public List<Tag> getAllTags() { |
| 139 | 2220 | List<Tag> list = new ArrayList<Tag>(); |
| 140 | |
|
| 141 | 2220 | if (getCategories().size() > 0) { |
| 142 | 256 | Iterator it = getCategories().iterator(); |
| 143 | 552 | while (it.hasNext()) { |
| 144 | 296 | Category category = (Category)it.next(); |
| 145 | 296 | List tagsForCategory = category.getAllTags(); |
| 146 | 296 | Collections.reverse(tagsForCategory); |
| 147 | 296 | Iterator jt = tagsForCategory.iterator(); |
| 148 | 400 | while (jt.hasNext()) { |
| 149 | 104 | Tag tag = (Tag)jt.next(); |
| 150 | 104 | if (!list.contains(tag)) { |
| 151 | 92 | list.add(tag); |
| 152 | |
} |
| 153 | 104 | } |
| 154 | 296 | } |
| 155 | 256 | } else { |
| 156 | 1964 | List tagsForCategory = getBlog().getRootCategory().getAllTags(); |
| 157 | 1964 | Iterator it = tagsForCategory.iterator(); |
| 158 | 1968 | while (it.hasNext()) { |
| 159 | 4 | Tag tag = (Tag)it.next(); |
| 160 | 4 | if (!list.contains(tag)) { |
| 161 | 4 | list.add(tag); |
| 162 | |
} |
| 163 | 4 | } |
| 164 | |
} |
| 165 | |
|
| 166 | 2220 | Iterator it = getTagsAsList().iterator(); |
| 167 | 3294 | while (it.hasNext()) { |
| 168 | 1074 | Tag tag = (Tag)it.next(); |
| 169 | 1074 | if (!list.contains(tag)) { |
| 170 | 1074 | list.add(tag); |
| 171 | |
} |
| 172 | 1074 | } |
| 173 | |
|
| 174 | 2220 | Collections.sort(list); |
| 175 | 2220 | return list; |
| 176 | |
} |
| 177 | |
|
| 178 | |
|
| 179 | |
|
| 180 | |
|
| 181 | |
|
| 182 | |
|
| 183 | |
public synchronized void addCategory(Category category) { |
| 184 | 400 | if (category != null && !categories.contains(category)) { |
| 185 | 304 | Set oldCategories = new HashSet(categories); |
| 186 | 304 | categories.add(category); |
| 187 | 304 | Set newCategories = new HashSet(categories); |
| 188 | 304 | propertyChangeSupport.firePropertyChange(CATEGORIES_PROPERTY, oldCategories, newCategories); |
| 189 | |
} |
| 190 | 400 | } |
| 191 | |
|
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
public synchronized void removeAllCategories() { |
| 196 | 16 | propertyChangeSupport.firePropertyChange(CATEGORIES_PROPERTY, new HashSet(categories), new HashSet()); |
| 197 | 16 | categories.clear(); |
| 198 | 16 | } |
| 199 | |
|
| 200 | |
|
| 201 | |
|
| 202 | |
|
| 203 | |
|
| 204 | |
|
| 205 | |
public synchronized void setCategories(Collection newCategories) { |
| 206 | 12 | if (newCategories != null) { |
| 207 | 12 | Set oldCategories = new HashSet(categories); |
| 208 | 12 | categories.clear(); |
| 209 | 12 | Iterator it = newCategories.iterator(); |
| 210 | 28 | while (it.hasNext()) { |
| 211 | 16 | categories.add(it.next()); |
| 212 | |
} |
| 213 | 12 | propertyChangeSupport.firePropertyChange(CATEGORIES_PROPERTY, oldCategories, new HashSet(newCategories)); |
| 214 | |
} |
| 215 | 12 | } |
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | |
|
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | |
|
| 224 | |
public boolean inCategory(Category category) { |
| 225 | 104 | if (category != null) { |
| 226 | 52 | Iterator it = categories.iterator(); |
| 227 | 68 | while (it.hasNext()) { |
| 228 | 60 | Category c = (Category)it.next(); |
| 229 | 60 | if (c.equals(category) || c.hasParent(category)) { |
| 230 | 44 | return true; |
| 231 | |
} |
| 232 | 16 | } |
| 233 | |
|
| 234 | 8 | return false; |
| 235 | |
} else { |
| 236 | 52 | return true; |
| 237 | |
} |
| 238 | |
} |
| 239 | |
|
| 240 | |
|
| 241 | |
|
| 242 | |
|
| 243 | |
|
| 244 | |
|
| 245 | |
|
| 246 | |
|
| 247 | |
public boolean hasTag(String s) { |
| 248 | 72 | if (s != null) { |
| 249 | 68 | return getAllTags().contains(new Tag(s, getBlog())); |
| 250 | |
} else { |
| 251 | 4 | return false; |
| 252 | |
} |
| 253 | |
} |
| 254 | |
|
| 255 | |
|
| 256 | |
|
| 257 | |
|
| 258 | |
|
| 259 | |
|
| 260 | |
public String getContent() { |
| 261 | 152 | if (excerpt != null && excerpt.length() > 0) { |
| 262 | 76 | return excerpt; |
| 263 | |
} else { |
| 264 | 76 | return getBody(); |
| 265 | |
} |
| 266 | |
} |
| 267 | |
|
| 268 | |
|
| 269 | |
|
| 270 | |
|
| 271 | |
|
| 272 | |
|
| 273 | |
public String getExcerpt() { |
| 274 | 2288 | return excerpt; |
| 275 | |
} |
| 276 | |
|
| 277 | |
|
| 278 | |
|
| 279 | |
|
| 280 | |
|
| 281 | |
|
| 282 | |
public void setExcerpt(String newExcerpt) { |
| 283 | 2336 | if (newExcerpt != null) { |
| 284 | 2328 | newExcerpt = newExcerpt.trim(); |
| 285 | |
} |
| 286 | 2336 | propertyChangeSupport.firePropertyChange(EXCERPT_PROPERTY, excerpt, newExcerpt); |
| 287 | 2336 | this.excerpt = newExcerpt; |
| 288 | 2336 | } |
| 289 | |
|
| 290 | |
|
| 291 | |
|
| 292 | |
|
| 293 | |
|
| 294 | |
|
| 295 | |
public Date getLastModified() { |
| 296 | 16 | Date date = getDate(); |
| 297 | |
|
| 298 | 16 | Iterator it = comments.iterator(); |
| 299 | 40 | while (it.hasNext()) { |
| 300 | 24 | Comment comment = (Comment)it.next(); |
| 301 | 24 | if (comment.getDate().after(date)) { |
| 302 | 24 | date = comment.getDate(); |
| 303 | |
} |
| 304 | 24 | } |
| 305 | |
|
| 306 | 16 | it = trackBacks.iterator(); |
| 307 | 28 | while (it.hasNext()) { |
| 308 | 12 | TrackBack trackBack = (TrackBack)it.next(); |
| 309 | 12 | if (trackBack.getDate().after(date)) { |
| 310 | 4 | date = trackBack.getDate(); |
| 311 | |
} |
| 312 | 12 | } |
| 313 | |
|
| 314 | 16 | return date; |
| 315 | |
} |
| 316 | |
|
| 317 | |
|
| 318 | |
|
| 319 | |
|
| 320 | |
|
| 321 | |
|
| 322 | |
public void setDate(Date newDate) { |
| 323 | 5408 | super.setDate(newDate); |
| 324 | |
|
| 325 | |
|
| 326 | 5408 | this.permalink = null; |
| 327 | 5408 | } |
| 328 | |
|
| 329 | |
|
| 330 | |
|
| 331 | |
|
| 332 | |
|
| 333 | |
|
| 334 | |
|
| 335 | |
|
| 336 | |
public String getLocalPermalink() { |
| 337 | 408 | if (this.permalink == null) { |
| 338 | 308 | String s = getBlog().getPermalinkProvider().getPermalink(this); |
| 339 | 308 | if (s != null && s.length() > 0) { |
| 340 | 308 | this.permalink = getBlog().getUrl() + s.substring(1); |
| 341 | |
} |
| 342 | |
} |
| 343 | |
|
| 344 | 408 | return permalink; |
| 345 | |
} |
| 346 | |
|
| 347 | |
|
| 348 | |
|
| 349 | |
|
| 350 | |
|
| 351 | |
|
| 352 | |
public Attachment getAttachment() { |
| 353 | 224 | return attachment; |
| 354 | |
} |
| 355 | |
|
| 356 | |
|
| 357 | |
|
| 358 | |
|
| 359 | |
|
| 360 | |
|
| 361 | |
public void setAttachment(Attachment newAttachment) { |
| 362 | 32 | propertyChangeSupport.firePropertyChange(ATTACHMENT_PROPERTY, attachment, newAttachment); |
| 363 | 32 | this.attachment = newAttachment; |
| 364 | 32 | } |
| 365 | |
|
| 366 | |
|
| 367 | |
|
| 368 | |
|
| 369 | |
|
| 370 | |
|
| 371 | |
public boolean isCommentsEnabled() { |
| 372 | 184 | return this.commentsEnabled; |
| 373 | |
} |
| 374 | |
|
| 375 | |
|
| 376 | |
|
| 377 | |
|
| 378 | |
|
| 379 | |
|
| 380 | |
|
| 381 | |
public void setCommentsEnabled(boolean newCommentsEnabled) { |
| 382 | 1700 | propertyChangeSupport.firePropertyChange(COMMENTS_ENABLED_PROPERTY, commentsEnabled, newCommentsEnabled); |
| 383 | 1700 | this.commentsEnabled = newCommentsEnabled; |
| 384 | 1700 | } |
| 385 | |
|
| 386 | |
|
| 387 | |
|
| 388 | |
|
| 389 | |
|
| 390 | |
|
| 391 | |
public String getCommentsLink() { |
| 392 | 4 | return getLocalPermalink() + "#comments"; |
| 393 | |
} |
| 394 | |
|
| 395 | |
|
| 396 | |
|
| 397 | |
|
| 398 | |
|
| 399 | |
|
| 400 | |
public boolean isTrackBacksEnabled() { |
| 401 | 152 | return this.trackBacksEnabled; |
| 402 | |
} |
| 403 | |
|
| 404 | |
|
| 405 | |
|
| 406 | |
|
| 407 | |
|
| 408 | |
|
| 409 | |
|
| 410 | |
public void setTrackBacksEnabled(boolean newTrackBacksEnabled) { |
| 411 | 1692 | propertyChangeSupport.firePropertyChange(TRACKBACKS_ENABLED_PROPERTY, trackBacksEnabled, newTrackBacksEnabled); |
| 412 | 1692 | this.trackBacksEnabled = newTrackBacksEnabled; |
| 413 | 1692 | } |
| 414 | |
|
| 415 | |
|
| 416 | |
|
| 417 | |
|
| 418 | |
|
| 419 | |
|
| 420 | |
public String getTrackBacksLink() { |
| 421 | 4 | return getLocalPermalink() + "#trackbacks"; |
| 422 | |
} |
| 423 | |
|
| 424 | |
|
| 425 | |
|
| 426 | |
|
| 427 | |
public String getTrackBackLink() { |
| 428 | 4 | StringBuffer link = new StringBuffer(); |
| 429 | 4 | link.append(getBlog().getUrl()); |
| 430 | 4 | link.append("addTrackBack.action?entry="); |
| 431 | 4 | link.append(getId()); |
| 432 | 4 | link.append("&token="); |
| 433 | 4 | link.append(TrackBackTokenManager.getInstance().generateToken()); |
| 434 | |
|
| 435 | 4 | return link.toString(); |
| 436 | |
} |
| 437 | |
|
| 438 | |
|
| 439 | |
|
| 440 | |
|
| 441 | |
|
| 442 | |
|
| 443 | |
public List<Response> getResponses() { |
| 444 | 5292 | List<Response> responses = new ArrayList(); |
| 445 | 5292 | responses.addAll(getComments()); |
| 446 | 5292 | responses.addAll(getTrackBacks()); |
| 447 | 5292 | Collections.sort(responses, new ResponseByDateComparator()); |
| 448 | 5292 | return responses; |
| 449 | |
} |
| 450 | |
|
| 451 | |
|
| 452 | |
|
| 453 | |
|
| 454 | |
|
| 455 | |
|
| 456 | |
public List<Comment> getComments() { |
| 457 | 9036 | List<Comment> allComments = new ArrayList(); |
| 458 | 9036 | Iterator it = comments.iterator(); |
| 459 | 15862 | while (it.hasNext()) { |
| 460 | 6826 | allComments.addAll(getComments((Comment)it.next())); |
| 461 | |
} |
| 462 | |
|
| 463 | 9036 | return allComments; |
| 464 | |
} |
| 465 | |
|
| 466 | |
private List<Comment> getComments(Comment comment) { |
| 467 | 7004 | List<Comment> allComments = new ArrayList(); |
| 468 | 7004 | allComments.add(comment); |
| 469 | 7004 | Iterator it = comment.getComments().iterator(); |
| 470 | 7182 | while (it.hasNext()) { |
| 471 | 178 | allComments.addAll(getComments((Comment)it.next())); |
| 472 | |
} |
| 473 | |
|
| 474 | 7004 | return allComments; |
| 475 | |
} |
| 476 | |
|
| 477 | |
|
| 478 | |
|
| 479 | |
|
| 480 | |
|
| 481 | |
|
| 482 | |
public int getNumberOfComments() { |
| 483 | 60 | return getComments().size(); |
| 484 | |
} |
| 485 | |
|
| 486 | |
|
| 487 | |
|
| 488 | |
|
| 489 | |
|
| 490 | |
|
| 491 | |
public List<TrackBack> getTrackBacks() { |
| 492 | 7764 | return new ArrayList<TrackBack>(trackBacks); |
| 493 | |
} |
| 494 | |
|
| 495 | |
|
| 496 | |
|
| 497 | |
|
| 498 | |
|
| 499 | |
|
| 500 | |
public int getNumberOfTrackBacks() { |
| 501 | 12 | return trackBacks.size(); |
| 502 | |
} |
| 503 | |
|
| 504 | |
|
| 505 | |
|
| 506 | |
|
| 507 | |
|
| 508 | |
|
| 509 | |
public int getNumberOfResponses() { |
| 510 | 0 | return getResponses().size(); |
| 511 | |
} |
| 512 | |
|
| 513 | |
|
| 514 | |
|
| 515 | |
|
| 516 | |
|
| 517 | |
|
| 518 | |
|
| 519 | |
|
| 520 | |
|
| 521 | |
|
| 522 | |
|
| 523 | |
|
| 524 | |
|
| 525 | |
|
| 526 | |
|
| 527 | |
public Comment createComment(String title, String body, String author, String email, String website, String avatar, String ipAddress, Date date, State state) { |
| 528 | 608 | return new Comment(title, body, author, email, website, avatar, ipAddress, date, state, this); |
| 529 | |
} |
| 530 | |
|
| 531 | |
|
| 532 | |
|
| 533 | |
|
| 534 | |
|
| 535 | |
|
| 536 | |
|
| 537 | |
|
| 538 | |
|
| 539 | |
|
| 540 | |
|
| 541 | |
|
| 542 | |
|
| 543 | |
public Comment createComment(String title, String body, String author, String email, String website, String avatar, String ipAddress) { |
| 544 | 500 | Calendar cal = getBlog().getCalendar(); |
| 545 | 500 | return createComment(title, body, author, email, website, avatar, ipAddress, cal.getTime(), State.APPROVED); |
| 546 | |
} |
| 547 | |
|
| 548 | |
|
| 549 | |
|
| 550 | |
|
| 551 | |
|
| 552 | |
|
| 553 | |
public synchronized void addComment(Comment comment) { |
| 554 | 924 | if (comment == null) { |
| 555 | 0 | return; |
| 556 | |
} |
| 557 | |
|
| 558 | 924 | Comment existingComment = getComment(comment.getId()); |
| 559 | 924 | if (existingComment != null && existingComment != comment) { |
| 560 | |
|
| 561 | |
|
| 562 | 364 | comment.setDate(new Date(comment.getDate().getTime() + 1)); |
| 563 | 364 | addComment(comment); |
| 564 | 560 | } else if (existingComment != null) { |
| 565 | 4 | return; |
| 566 | |
} else { |
| 567 | 556 | if (comment.getParent() != null) { |
| 568 | 68 | Comment parent = getComment(comment.getParent().getId()); |
| 569 | 68 | if (parent != null) { |
| 570 | 68 | parent.addComment(comment); |
| 571 | |
} else { |
| 572 | 0 | comments.add(comment); |
| 573 | |
} |
| 574 | 68 | } else { |
| 575 | 488 | comments.add(comment); |
| 576 | |
} |
| 577 | 556 | comment.setBlogEntry(this); |
| 578 | |
|
| 579 | 556 | if (areEventsEnabled()) { |
| 580 | 212 | addEvent(new CommentEvent(comment, CommentEvent.COMMENT_ADDED)); |
| 581 | 212 | comment.setEventsEnabled(true); |
| 582 | |
} |
| 583 | |
} |
| 584 | 920 | } |
| 585 | |
|
| 586 | |
|
| 587 | |
|
| 588 | |
|
| 589 | |
|
| 590 | |
|
| 591 | |
|
| 592 | |
|
| 593 | |
|
| 594 | |
|
| 595 | |
|
| 596 | |
|
| 597 | |
|
| 598 | |
public TrackBack createTrackBack(String title, String excerpt, String url, String blogName, String ipAddress, Date date, State state) { |
| 599 | 288 | return new TrackBack(title, excerpt, url, blogName, ipAddress, date, state, this); |
| 600 | |
} |
| 601 | |
|
| 602 | |
|
| 603 | |
|
| 604 | |
|
| 605 | |
|
| 606 | |
|
| 607 | |
|
| 608 | |
|
| 609 | |
|
| 610 | |
|
| 611 | |
|
| 612 | |
|
| 613 | |
public TrackBack createTrackBack(String title, String excerpt, String url, String blogName, String ipAddress) { |
| 614 | 264 | Calendar cal = getBlog().getCalendar(); |
| 615 | 264 | return createTrackBack(title, excerpt, url, blogName, ipAddress, cal.getTime(), State.APPROVED); |
| 616 | |
} |
| 617 | |
|
| 618 | |
|
| 619 | |
|
| 620 | |
|
| 621 | |
|
| 622 | |
|
| 623 | |
public synchronized void addTrackBack(TrackBack trackBack) { |
| 624 | 96 | if (trackBack == null || trackBacks.contains(trackBack)) { |
| 625 | 0 | return; |
| 626 | |
} |
| 627 | |
|
| 628 | 96 | trackBacks.add(trackBack); |
| 629 | |
|
| 630 | 96 | if (areEventsEnabled()) { |
| 631 | 20 | addEvent(new TrackBackEvent(trackBack, TrackBackEvent.TRACKBACK_ADDED)); |
| 632 | 20 | trackBack.setEventsEnabled(true); |
| 633 | |
} |
| 634 | 96 | } |
| 635 | |
|
| 636 | |
|
| 637 | |
|
| 638 | |
|
| 639 | |
|
| 640 | |
|
| 641 | |
public synchronized void removeComment(long id) { |
| 642 | 48 | Comment comment = getComment(id); |
| 643 | 48 | if (comment != null) { |
| 644 | |
|
| 645 | |
|
| 646 | 48 | for (Comment child : comment.getComments()) { |
| 647 | 12 | comment.removeComment(child); |
| 648 | |
} |
| 649 | |
|
| 650 | 48 | if (comment.getParent() != null) { |
| 651 | 8 | comment.getParent().removeComment(comment); |
| 652 | |
} else { |
| 653 | 40 | comments.remove(comment); |
| 654 | |
} |
| 655 | |
|
| 656 | 48 | if (areEventsEnabled()) { |
| 657 | 28 | addEvent(new CommentEvent(comment, CommentEvent.COMMENT_REMOVED)); |
| 658 | |
} |
| 659 | |
} else { |
| 660 | 0 | log.warn("A comment with id=" + id + " could not be found - " + |
| 661 | |
"perhaps it has been removed already."); |
| 662 | |
} |
| 663 | 48 | } |
| 664 | |
|
| 665 | |
|
| 666 | |
|
| 667 | |
|
| 668 | |
|
| 669 | |
|
| 670 | |
public Comment getComment(long id) { |
| 671 | 1060 | Iterator it = getComments().iterator(); |
| 672 | 5352 | while (it.hasNext()) { |
| 673 | 4788 | Comment comment = (Comment) it.next(); |
| 674 | 4788 | if (comment.getId() == id) { |
| 675 | 496 | return comment; |
| 676 | |
} |
| 677 | 4292 | } |
| 678 | |
|
| 679 | 564 | return null; |
| 680 | |
} |
| 681 | |
|
| 682 | |
|
| 683 | |
|
| 684 | |
|
| 685 | |
|
| 686 | |
|
| 687 | |
public TrackBack getTrackBack(long id) { |
| 688 | 24 | Iterator it = getTrackBacks().iterator(); |
| 689 | 24 | while (it.hasNext()) { |
| 690 | 24 | TrackBack trackBack = (TrackBack)it.next(); |
| 691 | 24 | if (trackBack.getId() == id) { |
| 692 | 24 | return trackBack; |
| 693 | |
} |
| 694 | 0 | } |
| 695 | |
|
| 696 | 0 | return null; |
| 697 | |
} |
| 698 | |
|
| 699 | |
|
| 700 | |
|
| 701 | |
|
| 702 | |
|
| 703 | |
|
| 704 | |
|
| 705 | |
public Response getResponse(String guid) { |
| 706 | 0 | long id = Long.parseLong(guid.substring(guid.lastIndexOf("/")+1)); |
| 707 | 0 | if (guid.startsWith("c")) { |
| 708 | 0 | return getComment(id); |
| 709 | |
} else { |
| 710 | 0 | return getTrackBack(id); |
| 711 | |
} |
| 712 | |
} |
| 713 | |
|
| 714 | |
|
| 715 | |
|
| 716 | |
|
| 717 | |
|
| 718 | |
|
| 719 | |
public synchronized void removeTrackBack(long id) { |
| 720 | 24 | TrackBack trackBack = getTrackBack(id); |
| 721 | 24 | if (trackBack != null) { |
| 722 | 24 | trackBacks.remove(trackBack); |
| 723 | |
|
| 724 | 24 | if (areEventsEnabled()) { |
| 725 | 8 | addEvent(new TrackBackEvent(trackBack, TrackBackEvent.TRACKBACK_REMOVED)); |
| 726 | |
} |
| 727 | |
} else { |
| 728 | 0 | log.warn("A TrackBack with id=" + id + " could not be found - " + |
| 729 | |
"perhaps it has been removed already."); |
| 730 | |
} |
| 731 | 24 | } |
| 732 | |
|
| 733 | |
|
| 734 | |
|
| 735 | |
|
| 736 | |
|
| 737 | |
|
| 738 | |
public void removeResponse(Response response) { |
| 739 | 16 | if (response instanceof Comment) { |
| 740 | 8 | removeComment(response.getId()); |
| 741 | 8 | } else if (response instanceof TrackBack) { |
| 742 | 8 | removeTrackBack(response.getId()); |
| 743 | |
} |
| 744 | 16 | } |
| 745 | |
|
| 746 | |
|
| 747 | |
|
| 748 | |
|
| 749 | |
|
| 750 | |
|
| 751 | |
public BlogEntry getPreviousBlogEntry() { |
| 752 | 12 | return getBlog().getPreviousBlogEntry(this); |
| 753 | |
} |
| 754 | |
|
| 755 | |
|
| 756 | |
|
| 757 | |
|
| 758 | |
|
| 759 | |
|
| 760 | |
public BlogEntry getNextBlogEntry() { |
| 761 | 12 | return getBlog().getNextBlogEntry(this); |
| 762 | |
} |
| 763 | |
|
| 764 | |
public void validate(ValidationContext context) { |
| 765 | 0 | } |
| 766 | |
|
| 767 | |
|
| 768 | |
|
| 769 | |
|
| 770 | |
|
| 771 | |
|
| 772 | |
|
| 773 | |
|
| 774 | |
|
| 775 | |
|
| 776 | |
public boolean equals(Object o) { |
| 777 | 168 | if (this == o) { |
| 778 | 80 | return true; |
| 779 | |
} |
| 780 | |
|
| 781 | 88 | if (!(o instanceof BlogEntry)) { |
| 782 | 0 | return false; |
| 783 | |
} |
| 784 | |
|
| 785 | 88 | BlogEntry blogEntry = (BlogEntry)o; |
| 786 | 88 | return getGuid().equals(blogEntry.getGuid()); |
| 787 | |
} |
| 788 | |
|
| 789 | |
public String getGuid() { |
| 790 | 896 | return "blogEntry/" + getBlog().getId() + "/" + getId(); |
| 791 | |
} |
| 792 | |
|
| 793 | |
public int hashCode() { |
| 794 | 32 | return getGuid().hashCode(); |
| 795 | |
} |
| 796 | |
|
| 797 | |
|
| 798 | |
|
| 799 | |
|
| 800 | |
|
| 801 | |
|
| 802 | |
|
| 803 | |
public Object clone() { |
| 804 | 1520 | BlogEntry entry = new BlogEntry(getBlog()); |
| 805 | 1520 | entry.setEventsEnabled(false); |
| 806 | 1520 | entry.setPersistent(isPersistent()); |
| 807 | 1520 | entry.setPublished(isPublished()); |
| 808 | 1520 | entry.setTitle(getTitle()); |
| 809 | 1520 | entry.setSubtitle(getSubtitle()); |
| 810 | 1520 | entry.setExcerpt(getExcerpt()); |
| 811 | 1520 | entry.setBody(getBody()); |
| 812 | 1520 | entry.setDate(getDate()); |
| 813 | 1520 | entry.setTimeZoneId(timeZoneId); |
| 814 | 1520 | entry.setState(getState()); |
| 815 | 1520 | entry.setAuthor(getAuthor()); |
| 816 | 1520 | entry.setOriginalPermalink(getOriginalPermalink()); |
| 817 | 1520 | entry.setCommentsEnabled(commentsEnabled); |
| 818 | 1520 | entry.setTrackBacksEnabled(trackBacksEnabled); |
| 819 | |
|
| 820 | 1520 | if (attachment != null) { |
| 821 | 4 | entry.setAttachment((Attachment)attachment.clone()); |
| 822 | |
} |
| 823 | |
|
| 824 | |
|
| 825 | 1520 | Iterator it = categories.iterator(); |
| 826 | 1620 | while (it.hasNext()) { |
| 827 | 100 | entry.addCategory((Category)it.next()); |
| 828 | |
} |
| 829 | |
|
| 830 | 1520 | entry.setTags(getTags()); |
| 831 | |
|
| 832 | |
|
| 833 | 1520 | it = getComments().iterator(); |
| 834 | 1760 | while (it.hasNext()) { |
| 835 | 240 | Comment comment = (Comment)it.next(); |
| 836 | 240 | Comment clonedComment = (Comment)comment.clone(); |
| 837 | 240 | entry.addComment(clonedComment); |
| 838 | 240 | } |
| 839 | |
|
| 840 | |
|
| 841 | 1520 | it = getTrackBacks().iterator(); |
| 842 | 1532 | while (it.hasNext()) { |
| 843 | 12 | TrackBack trackBack = (TrackBack)it.next(); |
| 844 | 12 | TrackBack clonedTrackBack = (TrackBack)trackBack.clone(); |
| 845 | 12 | clonedTrackBack.setBlogEntry(entry); |
| 846 | 12 | entry.addTrackBack(clonedTrackBack); |
| 847 | 12 | } |
| 848 | |
|
| 849 | 1520 | return entry; |
| 850 | |
} |
| 851 | |
|
| 852 | |
|
| 853 | |
|
| 854 | |
|
| 855 | |
|
| 856 | |
|
| 857 | |
void setEventsEnabled(boolean b) { |
| 858 | 4224 | super.setEventsEnabled(b); |
| 859 | |
|
| 860 | |
|
| 861 | 4224 | for (Response response : getResponses()) { |
| 862 | 524 | response.setEventsEnabled(b); |
| 863 | |
} |
| 864 | 4224 | } |
| 865 | |
|
| 866 | |
public void clearEvents() { |
| 867 | 1032 | super.clearEvents(); |
| 868 | |
|
| 869 | 1032 | for (Response response : getResponses()) { |
| 870 | 300 | response.clearEvents(); |
| 871 | |
} |
| 872 | 1032 | } |
| 873 | |
|
| 874 | |
|
| 875 | |
|
| 876 | |
|
| 877 | |
void setState(State state) { |
| 878 | 6532 | State previousState = getState(); |
| 879 | 6532 | super.setState(state); |
| 880 | |
|
| 881 | 6532 | if (areEventsEnabled()) { |
| 882 | 36 | if (isPublished() && previousState == State.UNPUBLISHED) { |
| 883 | 28 | addEvent(new BlogEntryEvent(this, BlogEntryEvent.BLOG_ENTRY_PUBLISHED)); |
| 884 | 8 | } else if (isUnpublished() && previousState == State.PUBLISHED) { |
| 885 | 8 | addEvent(new BlogEntryEvent(this, BlogEntryEvent.BLOG_ENTRY_UNPUBLISHED)); |
| 886 | |
} |
| 887 | |
} |
| 888 | 6532 | } |
| 889 | |
|
| 890 | |
public String toString() { |
| 891 | 0 | return getGuid() + ":" + super.hashCode(); |
| 892 | |
} |
| 893 | |
|
| 894 | |
public TimeZone getTimeZone() { |
| 895 | 0 | return TimeZone.getTimeZone(getTimeZoneId()); |
| 896 | |
} |
| 897 | |
|
| 898 | |
public String getTimeZoneId() { |
| 899 | 144 | if (this.timeZoneId != null) { |
| 900 | 12 | return timeZoneId; |
| 901 | |
} else { |
| 902 | 132 | return getBlog().getTimeZoneId(); |
| 903 | |
} |
| 904 | |
} |
| 905 | |
|
| 906 | |
public void setTimeZoneId(String timeZoneId) { |
| 907 | 1632 | this.timeZoneId = timeZoneId; |
| 908 | 1632 | } |
| 909 | |
|
| 910 | |
} |