1 31 package org.blojsom.plugin.admin; 32 33 import org.apache.commons.logging.Log; 34 import org.apache.commons.logging.LogFactory; 35 import org.blojsom.blog.*; 36 import org.blojsom.event.EventBroadcaster; 37 import org.blojsom.fetcher.Fetcher; 38 import org.blojsom.fetcher.FetcherException; 39 import org.blojsom.plugin.PluginException; 40 import org.blojsom.plugin.weblogsping.WeblogsPingPlugin; 41 import org.blojsom.plugin.pingback.event.*; 42 import org.blojsom.plugin.pingback.PingbackPlugin; 43 import org.blojsom.plugin.trackback.event.*; 44 import org.blojsom.plugin.trackback.TrackbackPlugin; 45 import org.blojsom.plugin.common.ResponseConstants; 46 import org.blojsom.plugin.comment.event.*; 47 import org.blojsom.plugin.admin.event.EntryAddedEvent; 48 import org.blojsom.plugin.admin.event.ProcessEntryEvent; 49 import org.blojsom.plugin.admin.event.EntryDeletedEvent; 50 import org.blojsom.plugin.admin.event.EntryUpdatedEvent; 51 import org.blojsom.util.BlojsomMetaDataConstants; 52 import org.blojsom.util.BlojsomUtils; 53 import org.blojsom.util.BlojsomConstants; 54 55 import javax.servlet.http.HttpServletRequest ; 56 import javax.servlet.http.HttpServletResponse ; 57 import java.text.ParseException ; 58 import java.text.SimpleDateFormat ; 59 import java.util.Date ; 60 import java.util.HashMap ; 61 import java.util.Map ; 62 import java.net.HttpURLConnection ; 63 import java.net.URLEncoder ; 64 import java.net.URL ; 65 import java.io.InputStreamReader ; 66 import java.io.BufferedReader ; 67 import java.io.IOException ; 68 import java.io.UnsupportedEncodingException ; 69 70 77 public class EditBlogEntriesPlugin extends BaseAdminPlugin { 78 79 private Log _logger = LogFactory.getLog(EditBlogEntriesPlugin.class); 80 81 private static final String EDIT_BLOG_ENTRIES_PAGE = "/org/blojsom/plugin/admin/templates/admin-edit-blog-entries"; 83 private static final String EDIT_BLOG_ENTRIES_LIST_PAGE = "/org/blojsom/plugin/admin/templates/admin-edit-blog-entries-list"; 84 private static final String EDIT_BLOG_ENTRY_PAGE = "/org/blojsom/plugin/admin/templates/admin-edit-blog-entry"; 85 private static final String ADD_BLOG_ENTRY_PAGE = "/org/blojsom/plugin/admin/templates/admin-add-blog-entry"; 86 private static final String MANAGE_BLOG_ENTRIES_PAGE = "/org/blojsom/plugin/admin/templates/admin-manage-blog-entries"; 87 88 private static final String BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_LIST = "BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_LIST"; 90 private static final String BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_CATEGORY = "BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_CATEGORY"; 91 private static final String BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_ENTRY = "BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_ENTRY"; 92 private static final String BLOJSOM_PLUGIN_TOTAL_ENTRIES_PAGES = "BLOJSOM_PLUGIN_TOTAL_ENTRIES_PAGES"; 93 private static final String BLOJSOM_USER_OBJECT = "BLOJSOM_USER_OBJECT"; 94 95 private static final String FAILED_PERMISSION_EDIT_KEY = "failed.permission.edit.text"; 97 private static final String FAILED_RETRIEVE_BLOG_ENTRY_KEY = "failed.retrieve.entry.text"; 98 private static final String FAILED_DELETE_BLOG_ENTRY_KEY = "failed.delete.entry.text"; 99 private static final String FAILED_ADD_BLOG_ENTRY_KEY = "failed.add.entry.text"; 100 private static final String UPDATED_BLOG_ENTRY_KEY = "updated.blog.entry.text"; 101 private static final String DELETED_BLOG_ENTRY_KEY = "deleted.blog.entry.text"; 102 private static final String ADDED_BLOG_ENTRY_KEY = "added.blog.entry.text"; 103 private static final String DELETED_COMMENTS_KEY = "deleted.comments.text"; 104 private static final String APPROVED_COMMENTS_KEY = "approved.comments.text"; 105 private static final String DELETED_TRACKBACKS_KEY = "deleted.trackbacks.text"; 106 private static final String APPROVED_TRACKBACKS_KEY = "approved.trackbacks.text"; 107 private static final String APPROVED_PINGBACKS_KEY = "approved.pingbacks.text"; 108 private static final String DELETED_PINGBACKS_KEY = "deleted.pingbacks.text"; 109 private static final String BLANK_ENTRY_KEY = "blank.entry.text"; 110 private static final String INVALID_CATEGORYID_KEY = "invalid.categoryid.text"; 111 112 private static final String EDIT_BLOG_ENTRIES_ACTION = "edit-blog-entries"; 114 private static final String EDIT_BLOG_ENTRY_ACTION = "edit-blog-entry"; 115 private static final String UPDATE_BLOG_ENTRY_ACTION = "update-blog-entry"; 116 private static final String DELETE_BLOG_ENTRY_ACTION = "delete-blog-entry"; 117 private static final String NEW_BLOG_ENTRY_ACTION = "new-blog-entry"; 118 private static final String ADD_BLOG_ENTRY_ACTION = "add-blog-entry"; 119 private static final String DELETE_BLOG_COMMENTS = "delete-blog-comments"; 120 private static final String DELETE_BLOG_TRACKBACKS = "delete-blog-trackbacks"; 121 private static final String DELETE_BLOG_PINGBACKS = "delete-blog-pingbacks"; 122 private static final String APPROVE_BLOG_COMMENTS = "approve-blog-comments"; 123 private static final String APPROVE_BLOG_TRACKBACKS = "approve-blog-trackbacks"; 124 private static final String APPROVE_BLOG_PINGBACKS = "approve-blog-pingbacks"; 125 private static final String EDIT_ENTRIES_LIST = "edit-entries-list"; 126 private static final String DELETE_BLOG_ENTRY_LIST = "delete-blog-entry-list"; 127 128 private static final String AJAX_DELETE_RESPONSE = "ajax-delete-response"; 130 private static final String AJAX_APPROVE_RESPONSE = "ajax-approve-response"; 131 private static final String AJAX_UNAPPROVE_RESPONSE = "ajax-unapprove-response"; 132 private static final String AJAX_MARK_SPAM_RESPONSE = "ajax-mark-spam-response"; 133 private static final String AJAX_UNMARK_SPAM_RESPONSE = "ajax-unmark-spam-response"; 134 135 private static final String BLOG_CATEGORY_ID = "blog-category-id"; 137 private static final String BLOG_ENTRY_ID = "blog-entry-id"; 138 private static final String BLOG_ENTRY_TITLE = "blog-entry-title"; 139 private static final String BLOG_ENTRY_DESCRIPTION = "blog-entry-description"; 140 private static final String BLOG_COMMENT_ID = "blog-comment-id"; 141 private static final String BLOG_TRACKBACK_ID = "blog-trackback-id"; 142 private static final String BLOG_PINGBACK_ID = "blog-pingback-id"; 143 private static final String BLOG_ENTRY_PUBLISH_DATETIME = "blog-entry-publish-datetime"; 144 private static final String BLOG_TRACKBACK_URLS = "blog-trackback-urls"; 145 private static final String POST_SLUG = "post-slug"; 146 private static final String PING_BLOG_URLS = "ping-blog-urls"; 147 private static final String RESPONSE_TYPE = "response-type"; 148 private static final String RESPONSE_ID = "response-id"; 149 private static final String STATUS = "status"; 150 private static final String QUERY = "query"; 151 152 private static final String EDIT_BLOG_ENTRIES_PERMISSION = "edit_blog_entries_permission"; 154 155 private Fetcher _fetcher; 156 private EventBroadcaster _eventBroadcaster; 157 158 161 public EditBlogEntriesPlugin() { 162 } 163 164 169 public void setFetcher(Fetcher fetcher) { 170 _fetcher = fetcher; 171 } 172 173 178 public void setEventBroadcaster(EventBroadcaster eventBroadcaster) { 179 _eventBroadcaster = eventBroadcaster; 180 } 181 182 189 protected boolean deleteBlogEntry(HttpServletRequest httpServletRequest, Blog blog, Map context) { 190 String blogEntryId = BlojsomUtils.getRequestValue(BLOG_ENTRY_ID, httpServletRequest); 191 Integer entryId; 192 try { 193 entryId = Integer.valueOf(blogEntryId); 194 } catch (NumberFormatException e) { 195 addOperationResultMessage(context, formatAdminResource(FAILED_RETRIEVE_BLOG_ENTRY_KEY, FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog.getBlogAdministrationLocale(), new Object []{blogEntryId})); 196 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADMIN_ADMINISTRATION_PAGE); 197 198 return false; 199 } 200 201 try { 202 Entry entryToDelete = _fetcher.newEntry(); 203 entryToDelete.setId(entryId); 204 205 _fetcher.loadEntry(blog, entryToDelete); 206 String title = entryToDelete.getTitle(); 207 _fetcher.deleteEntry(blog,entryToDelete); 208 209 addOperationResultMessage(context, formatAdminResource(DELETED_BLOG_ENTRY_KEY, DELETED_BLOG_ENTRY_KEY, blog.getBlogAdministrationLocale(), new Object []{title})); 210 211 EntryDeletedEvent deleteEvent = new EntryDeletedEvent(this, new Date (), entryToDelete, blog); 212 _eventBroadcaster.broadcastEvent(deleteEvent); 213 } catch (FetcherException e) { 214 if (_logger.isErrorEnabled()) { 215 _logger.error(e); 216 } 217 218 addOperationResultMessage(context, formatAdminResource(FAILED_DELETE_BLOG_ENTRY_KEY, FAILED_DELETE_BLOG_ENTRY_KEY, blog.getBlogAdministrationLocale(), new Object []{blogEntryId})); 219 return false; 220 } 221 222 return true; 223 } 224 225 236 public Entry[] process(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Blog blog, Map context, Entry[] entries) throws PluginException { 237 if (!authenticateUser(httpServletRequest, httpServletResponse, context, blog)) { 238 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADMIN_LOGIN_PAGE); 239 240 return entries; 241 } 242 243 String username = getUsernameFromSession(httpServletRequest, blog); 244 if (!checkPermission(blog, null, username, EDIT_BLOG_ENTRIES_PERMISSION)) { 245 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADMIN_ADMINISTRATION_PAGE); 246 addOperationResultMessage(context, getAdminResource(FAILED_PERMISSION_EDIT_KEY, FAILED_PERMISSION_EDIT_KEY, blog.getBlogAdministrationLocale())); 247 248 return entries; 249 } 250 251 try { 252 context.put(BLOJSOM_USER_OBJECT, _fetcher.loadUser(blog, username)); 253 } catch (FetcherException e) { 254 if (_logger.isErrorEnabled()) { 255 _logger.error(e); 256 } 257 } 258 259 String action = BlojsomUtils.getRequestValue(ACTION_PARAM, httpServletRequest); 260 String subAction = BlojsomUtils.getRequestValue(SUBACTION_PARAM, httpServletRequest); 261 262 if (BlojsomUtils.checkNullOrBlank(action)) { 263 if (_logger.isDebugEnabled()) { 264 _logger.debug("User did not request edit action"); 265 } 266 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADMIN_ADMINISTRATION_PAGE); 267 } else if (PAGE_ACTION.equals(action)) { 268 if (_logger.isDebugEnabled()) { 269 _logger.debug("User requested edit blog entries page"); 270 } 271 272 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, EDIT_BLOG_ENTRIES_PAGE); 273 } else if (EDIT_BLOG_ENTRIES_ACTION.equals(action)) { 274 if (_logger.isDebugEnabled()) { 275 _logger.debug("User requested edit blog entries list page"); 276 } 277 278 String blogCategoryId = BlojsomUtils.getRequestValue(BLOG_CATEGORY_ID, httpServletRequest); 279 Integer categoryId; 280 Category category = null; 281 try { 282 categoryId = Integer.valueOf(blogCategoryId); 283 } catch (NumberFormatException e) { 284 addOperationResultMessage(context, formatAdminResource(INVALID_CATEGORYID_KEY, INVALID_CATEGORYID_KEY, blog.getBlogAdministrationLocale(), new Object [] {blogCategoryId})); 285 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADMIN_ADMINISTRATION_PAGE); 286 287 return entries; 288 } 289 290 try { 291 entries = _fetcher.loadAllEntriesForCategory(blog, categoryId); 292 category = _fetcher.loadCategory(blog, categoryId); 293 } catch (FetcherException e) { 294 if (_logger.isErrorEnabled()) { 295 _logger.error(e); 296 } 297 298 entries = new Entry[0]; 299 } 300 301 context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_CATEGORY, category); 302 context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_LIST, entries); 303 304 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, EDIT_BLOG_ENTRIES_LIST_PAGE); 305 } else if (EDIT_BLOG_ENTRY_ACTION.equals(action)) { 306 if (_logger.isDebugEnabled()) { 307 _logger.debug("User requested edit blog entry action"); 308 } 309 310 String blogEntryId = BlojsomUtils.getRequestValue(BLOG_ENTRY_ID, httpServletRequest); 311 Integer entryId; 312 try { 313 entryId = Integer.valueOf(blogEntryId); 314 } catch (NumberFormatException e) { 315 addOperationResultMessage(context, formatAdminResource(FAILED_RETRIEVE_BLOG_ENTRY_KEY, FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog.getBlogAdministrationLocale(), new Object []{blogEntryId})); 316 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADMIN_ADMINISTRATION_PAGE); 317 318 return entries; 319 } 320 321 try { 322 Entry entry = _fetcher.newEntry(); 323 entry.setId(entryId); 324 _fetcher.loadEntry(blog, entry); 325 context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_ENTRY, entry); 326 327 _eventBroadcaster.processEvent(new ProcessEntryEvent(this, new Date (), entry, blog, httpServletRequest, httpServletResponse, context)); 328 } catch (FetcherException e) { 329 if (_logger.isErrorEnabled()) { 330 _logger.error(e); 331 } 332 333 addOperationResultMessage(context, formatAdminResource(FAILED_RETRIEVE_BLOG_ENTRY_KEY, FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog.getBlogAdministrationLocale(), new Object []{blogEntryId})); 334 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADMIN_ADMINISTRATION_PAGE); 335 336 return entries; 337 } 338 339 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, EDIT_BLOG_ENTRY_PAGE); 340 } else if (UPDATE_BLOG_ENTRY_ACTION.equals(action)) { 341 if (_logger.isDebugEnabled()) { 342 _logger.debug("User requested update blog entry action"); 343 } 344 345 String blogEntryId = BlojsomUtils.getRequestValue(BLOG_ENTRY_ID, httpServletRequest); 346 Integer entryId; 347 try { 348 entryId = Integer.valueOf(blogEntryId); 349 } catch (NumberFormatException e) { 350 addOperationResultMessage(context, formatAdminResource(FAILED_RETRIEVE_BLOG_ENTRY_KEY, FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog.getBlogAdministrationLocale(), new Object []{blogEntryId})); 351 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADMIN_ADMINISTRATION_PAGE); 352 353 return entries; 354 } 355 356 String blogCategoryId = BlojsomUtils.getRequestValue(BLOG_CATEGORY_ID, httpServletRequest); 357 Integer categoryId; 358 try { 359 categoryId = Integer.valueOf(blogCategoryId); 360 } catch (NumberFormatException e) { 361 addOperationResultMessage(context, formatAdminResource(INVALID_CATEGORYID_KEY, INVALID_CATEGORYID_KEY, blog.getBlogAdministrationLocale(), new Object []{blogCategoryId})); 362 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADMIN_ADMINISTRATION_PAGE); 363 364 return entries; 365 } 366 367 String blogEntryDescription = BlojsomUtils.getRequestValue(BLOG_ENTRY_DESCRIPTION, httpServletRequest); 368 String blogEntryTitle = BlojsomUtils.getRequestValue(BLOG_ENTRY_TITLE, httpServletRequest); 369 if (BlojsomUtils.checkNullOrBlank(blogEntryTitle)) { 370 blogEntryDescription = BlojsomUtils.LINE_SEPARATOR + blogEntryDescription; 371 } 372 373 String allowComments = BlojsomUtils.getRequestValue(BlojsomMetaDataConstants.BLOG_METADATA_COMMENTS_DISABLED, httpServletRequest); 374 String allowTrackbacks = BlojsomUtils.getRequestValue(BlojsomMetaDataConstants.BLOG_METADATA_TRACKBACKS_DISABLED, httpServletRequest); 375 String allowPingbacks = BlojsomUtils.getRequestValue(BlojsomMetaDataConstants.BLOG_METADATA_PINGBACKS_DISABLED, httpServletRequest); 376 String blogTrackbackURLs = BlojsomUtils.getRequestValue(BLOG_TRACKBACK_URLS, httpServletRequest); 377 String pingBlogURLS = BlojsomUtils.getRequestValue(PING_BLOG_URLS, httpServletRequest); 378 String sendPingbacks = BlojsomUtils.getRequestValue(PingbackPlugin.PINGBACK_PLUGIN_METADATA_SEND_PINGBACKS, httpServletRequest); 379 String status = BlojsomUtils.getRequestValue(STATUS, httpServletRequest); 380 381 try { 382 Entry entryToUpdate = _fetcher.newEntry(); 383 entryToUpdate.setId(entryId); 384 _fetcher.loadEntry(blog, entryToUpdate); 385 386 entryToUpdate.setTitle(blogEntryTitle); 387 entryToUpdate.setDescription(blogEntryDescription); 388 entryToUpdate.setBlogCategoryId(categoryId); 389 390 Map entryMetaData = entryToUpdate.getMetaData(); 391 if (entryMetaData == null) { 392 entryMetaData = new HashMap (); 393 } 394 395 if (!BlojsomUtils.checkNullOrBlank(allowComments)) { 396 entryToUpdate.setAllowComments(new Integer (0)); 397 } else { 398 entryToUpdate.setAllowComments(new Integer (1)); 399 } 400 401 if (!BlojsomUtils.checkNullOrBlank(allowTrackbacks)) { 402 entryToUpdate.setAllowTrackbacks(new Integer (0)); 403 } else { 404 entryToUpdate.setAllowTrackbacks(new Integer (1)); 405 } 406 407 if (!BlojsomUtils.checkNullOrBlank(allowPingbacks)) { 408 entryToUpdate.setAllowPingbacks(new Integer (0)); 409 } else { 410 entryToUpdate.setAllowPingbacks(new Integer (1)); 411 } 412 413 if (BlojsomUtils.checkNullOrBlank(pingBlogURLS)) { 414 entryMetaData.put(WeblogsPingPlugin.NO_PING_WEBLOGS_METADATA, "true"); 415 } else { 416 entryMetaData.remove(WeblogsPingPlugin.NO_PING_WEBLOGS_METADATA); 417 } 418 419 if (!BlojsomUtils.checkNullOrBlank(sendPingbacks)) { 420 entryMetaData.put(PingbackPlugin.PINGBACK_PLUGIN_METADATA_SEND_PINGBACKS, "true"); 421 } else { 422 entryMetaData.remove(PingbackPlugin.PINGBACK_PLUGIN_METADATA_SEND_PINGBACKS); 423 } 424 425 String entryPublishDateTime = httpServletRequest.getParameter(BLOG_ENTRY_PUBLISH_DATETIME); 426 if (!BlojsomUtils.checkNullOrBlank(entryPublishDateTime)) { 427 SimpleDateFormat simpleDateFormat = new SimpleDateFormat ("MM/dd/yyyy HH:mm:ss"); 428 try { 429 Date publishDateTime = simpleDateFormat.parse(entryPublishDateTime); 430 entryToUpdate.setDate(publishDateTime); 431 entryToUpdate.setModifiedDate(publishDateTime); 432 } catch (ParseException e) { 433 } 434 } else { 435 entryToUpdate.setModifiedDate(new Date ()); 436 } 437 438 if (BlojsomUtils.checkNullOrBlank(status)) { 439 status = BlojsomMetaDataConstants.DRAFT_STATUS; 440 } 441 442 entryToUpdate.setStatus(status); 443 entryToUpdate.setMetaData(entryMetaData); 444 445 _eventBroadcaster.processEvent(new ProcessEntryEvent(this, new Date (), entryToUpdate, blog, httpServletRequest, httpServletResponse, context)); 446 447 _fetcher.saveEntry(blog, entryToUpdate); 448 _fetcher.loadEntry(blog, entryToUpdate); 449 450 if (_logger.isDebugEnabled()) { 451 _logger.debug("Updated blog entry: " + entryToUpdate.getId()); 452 } 453 454 StringBuffer entryLink = new StringBuffer (); 455 entryLink.append("<a HREF=\"").append(blog.getBlogURL()).append(entryToUpdate.getBlogCategory().getName()).append(entryToUpdate.getPostSlug()).append("\">").append(entryToUpdate.getEscapedTitle()).append("</a>"); 456 addOperationResultMessage(context, formatAdminResource(UPDATED_BLOG_ENTRY_KEY, UPDATED_BLOG_ENTRY_KEY, blog.getBlogAdministrationLocale(), new Object [] {entryLink.toString()})); 457 458 EntryUpdatedEvent updateEvent = new EntryUpdatedEvent(this, new Date (), entryToUpdate, blog); 459 _eventBroadcaster.broadcastEvent(updateEvent); 460 461 if (!BlojsomUtils.checkNullOrBlank(blogTrackbackURLs)) { 463 sendTrackbackPings(blog, entryToUpdate, blogTrackbackURLs); 464 } 465 466 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, EDIT_BLOG_ENTRY_PAGE); 467 context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_ENTRY, entryToUpdate); 468 } catch (FetcherException e) { 469 if (_logger.isErrorEnabled()) { 470 _logger.error(e); 471 } 472 473 addOperationResultMessage(context, formatAdminResource(FAILED_RETRIEVE_BLOG_ENTRY_KEY, FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog.getBlogAdministrationLocale(), new Object [] {blogEntryId})); 474 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, EDIT_BLOG_ENTRIES_PAGE); 475 entries = new Entry[0]; 476 } 477 } else if (DELETE_BLOG_ENTRY_ACTION.equals(action)) { 478 if (_logger.isDebugEnabled()) { 479 _logger.debug("User requested delete blog entry action"); 480 } 481 482 String blogEntryId = BlojsomUtils.getRequestValue(BLOG_ENTRY_ID, httpServletRequest); 483 Integer entryId; 484 try { 485 entryId = Integer.valueOf(blogEntryId); 486 } catch (NumberFormatException e) { 487 addOperationResultMessage(context, formatAdminResource(FAILED_RETRIEVE_BLOG_ENTRY_KEY, FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog.getBlogAdministrationLocale(), new Object []{blogEntryId})); 488 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADMIN_ADMINISTRATION_PAGE); 489 490 return entries; 491 } 492 493 try { 494 Entry entryToDelete = _fetcher.newEntry(); 495 entryToDelete.setId(entryId); 496 497 _fetcher.loadEntry(blog, entryToDelete); 498 String title = entryToDelete.getTitle(); 499 _fetcher.deleteEntry(blog,entryToDelete); 500 501 addOperationResultMessage(context, formatAdminResource(DELETED_BLOG_ENTRY_KEY, DELETED_BLOG_ENTRY_KEY, blog.getBlogAdministrationLocale(), new Object []{title})); 502 503 EntryDeletedEvent deleteEvent = new EntryDeletedEvent(this, new Date (), entryToDelete, blog); 504 _eventBroadcaster.broadcastEvent(deleteEvent); 505 } catch (FetcherException e) { 506 if (_logger.isErrorEnabled()) { 507 _logger.error(e); 508 } 509 510 addOperationResultMessage(context, formatAdminResource(FAILED_DELETE_BLOG_ENTRY_KEY, FAILED_DELETE_BLOG_ENTRY_KEY, blog.getBlogAdministrationLocale(), new Object []{blogEntryId})); 511 entries = new Entry[0]; 512 } 513 514 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, EDIT_BLOG_ENTRIES_PAGE); 515 } else if (NEW_BLOG_ENTRY_ACTION.equals(action)) { 516 if (_logger.isDebugEnabled()) { 517 _logger.debug("User requested new blog entry action"); 518 } 519 520 _eventBroadcaster.processEvent(new ProcessEntryEvent(this, new Date (), null, blog, httpServletRequest, httpServletResponse, context)); 521 522 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADD_BLOG_ENTRY_PAGE); 523 } else if (ADD_BLOG_ENTRY_ACTION.equals(action)) { 524 if (_logger.isDebugEnabled()) { 525 _logger.debug("User requested add blog entry action"); 526 } 527 528 String blogCategoryId = BlojsomUtils.getRequestValue(BLOG_CATEGORY_ID, httpServletRequest); 529 530 if (BlojsomUtils.checkNullOrBlank(blogCategoryId)) { 532 Category category = _fetcher.newCategory(); 533 category.setBlogId(blog.getId()); 534 category.setDescription("Uncategorized"); 535 category.setName("uncategorized"); 536 category.setParentCategoryId(null); 537 538 try { 539 _fetcher.saveCategory(blog, category); 540 blogCategoryId = category.getId().toString(); 541 } catch (FetcherException e) { 542 if (_logger.isErrorEnabled()) { 543 _logger.error(e); 544 } 545 546 addOperationResultMessage(context, formatAdminResource(FAILED_ADD_BLOG_ENTRY_KEY, FAILED_ADD_BLOG_ENTRY_KEY, blog.getBlogAdministrationLocale(), new Object []{blogCategoryId})); 547 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADMIN_ADMINISTRATION_PAGE); 548 549 return entries; 550 } 551 } 552 553 Integer categoryId; 554 try { 555 categoryId = Integer.valueOf(blogCategoryId); 556 } catch (NumberFormatException e) { 557 addOperationResultMessage(context, formatAdminResource(INVALID_CATEGORYID_KEY, INVALID_CATEGORYID_KEY, blog.getBlogAdministrationLocale(), new Object []{blogCategoryId})); 558 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADMIN_ADMINISTRATION_PAGE); 559 560 return entries; 561 } 562 563 String blogEntryDescription = BlojsomUtils.getRequestValue(BLOG_ENTRY_DESCRIPTION, httpServletRequest); 564 String blogEntryTitle = BlojsomUtils.getRequestValue(BLOG_ENTRY_TITLE, httpServletRequest); 565 566 if (BlojsomUtils.checkNullOrBlank(blogEntryTitle) && BlojsomUtils.checkNullOrBlank(blogEntryDescription)) { 567 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADD_BLOG_ENTRY_PAGE); 568 _eventBroadcaster.processEvent(new ProcessEntryEvent(this, new Date (), null, blog, httpServletRequest, httpServletResponse, context)); 569 570 addOperationResultMessage(context, getAdminResource(BLANK_ENTRY_KEY, BLANK_ENTRY_KEY, blog.getBlogAdministrationLocale())); 571 572 return entries; 573 } 574 575 if (BlojsomUtils.checkNullOrBlank(blogEntryTitle)) { 576 blogEntryDescription = BlojsomUtils.LINE_SEPARATOR + blogEntryDescription; 577 } 578 579 String allowComments = BlojsomUtils.getRequestValue(BlojsomMetaDataConstants.BLOG_METADATA_COMMENTS_DISABLED, httpServletRequest); 580 String allowTrackbacks = BlojsomUtils.getRequestValue(BlojsomMetaDataConstants.BLOG_METADATA_TRACKBACKS_DISABLED, httpServletRequest); 581 String allowPingbacks = BlojsomUtils.getRequestValue(BlojsomMetaDataConstants.BLOG_METADATA_PINGBACKS_DISABLED, httpServletRequest); 582 String blogTrackbackURLs = BlojsomUtils.getRequestValue(BLOG_TRACKBACK_URLS, httpServletRequest); 583 String pingBlogURLS = BlojsomUtils.getRequestValue(PING_BLOG_URLS, httpServletRequest); 584 String postSlug = BlojsomUtils.getRequestValue(POST_SLUG, httpServletRequest); 585 String sendPingbacks = BlojsomUtils.getRequestValue(PingbackPlugin.PINGBACK_PLUGIN_METADATA_SEND_PINGBACKS, httpServletRequest); 586 String status = BlojsomUtils.getRequestValue(STATUS, httpServletRequest); 587 588 Entry entry; 589 entry = _fetcher.newEntry(); 590 591 entry.setBlogId(blog.getId()); 592 entry.setTitle(blogEntryTitle); 593 entry.setBlogCategoryId(categoryId); 594 entry.setDescription(blogEntryDescription); 595 entry.setDate(new Date ()); 596 entry.setModifiedDate(entry.getDate()); 597 entry.setBlogCategoryId(categoryId); 598 599 if (!BlojsomUtils.checkNullOrBlank(postSlug)) { 600 entry.setPostSlug(postSlug); 601 } 602 603 Map entryMetaData = new HashMap (); 604 username = (String ) httpServletRequest.getSession().getAttribute(blog.getBlogAdminURL() + "_" + BLOJSOM_ADMIN_PLUGIN_USERNAME_KEY); 605 entry.setAuthor(username); 606 607 String entryPublishDateTime = httpServletRequest.getParameter(BLOG_ENTRY_PUBLISH_DATETIME); 608 if (!BlojsomUtils.checkNullOrBlank(entryPublishDateTime)) { 609 SimpleDateFormat simpleDateFormat = new SimpleDateFormat ("MM/dd/yyyy HH:mm:ss"); 610 try { 611 Date publishDateTime = simpleDateFormat.parse(entryPublishDateTime); 612 entry.setDate(publishDateTime); 613 entry.setModifiedDate(publishDateTime); 614 } catch (ParseException e) { 615 } 616 } 617 618 if (!BlojsomUtils.checkNullOrBlank(allowComments)) { 619 entry.setAllowComments(new Integer (0)); 620 } else { 621 entry.setAllowComments(new Integer (1)); 622 } 623 624 if (!BlojsomUtils.checkNullOrBlank(allowTrackbacks)) { 625 entry.setAllowTrackbacks(new Integer (0)); 626 } else { 627 entry.setAllowTrackbacks(new Integer (1)); 628 } 629 630 if (!BlojsomUtils.checkNullOrBlank(allowPingbacks)) { 631 entry.setAllowPingbacks(new Integer (0)); 632 } else { 633 entry.setAllowPingbacks(new Integer (1)); 634 } 635 636 if (BlojsomUtils.checkNullOrBlank(pingBlogURLS)) { 637 entryMetaData.put(WeblogsPingPlugin.NO_PING_WEBLOGS_METADATA, "true"); 638 } else { 639 entryMetaData.remove(WeblogsPingPlugin.NO_PING_WEBLOGS_METADATA); 640 } 641 642 if (!BlojsomUtils.checkNullOrBlank(sendPingbacks)) { 643 entryMetaData.put(PingbackPlugin.PINGBACK_PLUGIN_METADATA_SEND_PINGBACKS, "true"); 644 } else { 645 entryMetaData.remove(PingbackPlugin.PINGBACK_PLUGIN_METADATA_SEND_PINGBACKS); 646 } 647 648 if (BlojsomUtils.checkNullOrBlank(status)) { 649 status = BlojsomMetaDataConstants.DRAFT_STATUS; 650 } 651 652 entry.setStatus(status); 653 entry.setMetaData(entryMetaData); 654 655 try { 656 _eventBroadcaster.processEvent(new ProcessEntryEvent(this, new Date (), entry, blog, httpServletRequest, httpServletResponse, context)); 657 658 _fetcher.saveEntry(blog, entry); 659 _fetcher.loadEntry(blog, entry); 660 661 StringBuffer entryLink = new StringBuffer (); 662 entryLink.append("<a HREF=\"").append(blog.getBlogURL()).append(entry.getBlogCategory().getName()).append(entry.getPostSlug()).append("\">").append(entry.getEscapedTitle()).append("</a>"); 663 addOperationResultMessage(context, formatAdminResource(ADDED_BLOG_ENTRY_KEY, ADDED_BLOG_ENTRY_KEY, blog.getBlogAdministrationLocale(), new Object []{entryLink.toString()})); 664 665 EntryAddedEvent addedEvent = new EntryAddedEvent(this, new Date (), entry, blog); 666 _eventBroadcaster.broadcastEvent(addedEvent); 667 } catch (FetcherException e) { 668 if (_logger.isErrorEnabled()) { 669 _logger.error(e); 670 } 671 672 addOperationResultMessage(context, formatAdminResource(FAILED_ADD_BLOG_ENTRY_KEY, FAILED_ADD_BLOG_ENTRY_KEY, blog.getBlogAdministrationLocale(), new Object []{blogCategoryId})); 673 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADMIN_ADMINISTRATION_PAGE); 674 675 return entries; 676 } 677 678 if (!BlojsomUtils.checkNullOrBlank(blogTrackbackURLs)) { 680 sendTrackbackPings(blog, entry, blogTrackbackURLs); 681 } 682 683 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, EDIT_BLOG_ENTRY_ACTION); 684 context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_ENTRY, entry); 685 } else if (EDIT_ENTRIES_LIST.equals(action)) { 686 if (_logger.isDebugEnabled()) { 687 _logger.debug("User requested edit entries list action"); 688 } 689 690 String page = BlojsomUtils.getRequestValue(BlojsomConstants.PAGE_NUMBER_PARAM, httpServletRequest); 691 int pgNum; 692 try { 693 pgNum = Integer.parseInt(page); 694 } catch (NumberFormatException e) { 695 pgNum = 1; 696 } 697 698 if (pgNum < 1) { 699 pgNum = 1; 700 } 701 702 try { 703 if (DELETE_BLOG_ENTRY_LIST.equals(subAction)) { 704 deleteBlogEntry(httpServletRequest, blog, context); 705 } 706 707 String query = BlojsomUtils.getRequestValue(QUERY, httpServletRequest); 708 if (!BlojsomUtils.checkNullOrBlank(query)) { 709 context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_LIST, _fetcher.findEntries(blog, query)); 710 context.put(QUERY, BlojsomUtils.escapeString(query)); 711 } else { 712 context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_LIST, _fetcher.loadEntries(blog, 10, pgNum)); 713 } 714 715 Integer totalEntries = _fetcher.countEntries(blog); 716 int totalPages = (totalEntries.intValue() / 10); 717 int totalRemaining = (totalEntries.intValue() % 10); 718 if (totalRemaining > 0) { 719 totalPages += 1; 720 } 721 722 context.put(BLOJSOM_PLUGIN_TOTAL_ENTRIES_PAGES, new Integer (totalPages)); 723 } catch (FetcherException e) { 724 if (_logger.isErrorEnabled()) { 725 _logger.error(e); 726 } 727 } 728 729 context.put(BlojsomConstants.PAGE_NUMBER_PARAM, new Integer (pgNum)); 730 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, MANAGE_BLOG_ENTRIES_PAGE); 731 } else if (AJAX_DELETE_RESPONSE.equals(action)) { 732 if (_logger.isDebugEnabled()) { 733 _logger.debug("User requested AJAX delete response action"); 734 } 735 736 String responseId = BlojsomUtils.getRequestValue(RESPONSE_ID, httpServletRequest); 737 Integer responseID; 738 try { 739 responseID = Integer.valueOf(responseId); 740 } catch (NumberFormatException e) { 741 context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS, BlojsomConstants.FAILURE); 742 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADMIN_AJAX_RESPONSE); 743 744 return entries; 745 } 746 747 String responseType = BlojsomUtils.getRequestValue(RESPONSE_TYPE, httpServletRequest); 748 try { 749 if (Response.COMMENT_TYPE.equals(responseType)) { 750 Comment comment = _fetcher.newComment(); 751 comment.setBlogId(blog.getId()); 752 comment.setId(responseID); 753 _fetcher.loadComment(blog, comment); 754 _fetcher.deleteComment(blog, comment); 755 756 _eventBroadcaster.broadcastEvent(new CommentDeletedEvent(this, new Date (), comment, blog)); 757 758 if (_logger.isDebugEnabled()) { 759 _logger.debug("AJAX delete comment response complete: " + responseId); 760 } 761 } else if (Response.TRACKBACK_TYPE.equals(responseType)) { 762 Trackback trackback = _fetcher.newTrackback(); 763 trackback.setBlogId(blog.getId()); 764 trackback.setId(responseID); 765 _fetcher.loadTrackback(blog, trackback); 766 _fetcher.deleteTrackback(blog, trackback); 767 768 _eventBroadcaster.broadcastEvent(new TrackbackDeletedEvent(this, new Date (), trackback, blog)); 769 770 if (_logger.isDebugEnabled()) { 771 _logger.debug("AJAX delete trackback response complete: " + responseId); 772 } 773 } else if (Response.PINGBACK_TYPE.equals(responseType)) { 774 Pingback pingback = _fetcher.newPingback(); 775 pingback.setBlogId(blog.getId()); 776 pingback.setId(responseID); 777 _fetcher.loadPingback(blog, pingback); 778 _fetcher.deletePingback(blog, pingback); 779 780 _eventBroadcaster.broadcastEvent(new PingbackDeletedEvent(this, new Date (), pingback, blog)); 781 782 if (_logger.isDebugEnabled()) { 783 _logger.debug("AJAX delete pingback response complete: " + responseId); 784 } 785 } else { 786 if (_logger.isErrorEnabled()) { 787 _logger.error("Unknown response type for AJAX delete response: " + responseType); 788 } 789 } 790 791 context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS, BlojsomConstants.SUCCESS); 792 793 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADMIN_AJAX_RESPONSE); 794 } catch (FetcherException e) { 795 if (_logger.isErrorEnabled()) { 796 _logger.error(e); 797 } 798 799 context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS, BlojsomConstants.FAILURE); 800 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADMIN_AJAX_RESPONSE); 801 802 entries = new Entry[0]; 803 } 804 } else if (AJAX_APPROVE_RESPONSE.equals(action)) { 805 if (_logger.isDebugEnabled()) { 806 _logger.debug("User requested AJAX approve response action"); 807 } 808 809 String responseId = BlojsomUtils.getRequestValue(RESPONSE_ID, httpServletRequest); 810 Integer responseID; 811 try { 812 responseID = Integer.valueOf(responseId); 813 } catch (NumberFormatException e) { 814 context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS, BlojsomConstants.FAILURE); 815 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADMIN_AJAX_RESPONSE); 816 817 return entries; 818 } 819 820 String responseType = BlojsomUtils.getRequestValue(RESPONSE_TYPE, httpServletRequest); 821 try { 822 if (Response.COMMENT_TYPE.equals(responseType)) { 823 Comment comment = _fetcher.newComment(); 824 comment.setBlogId(blog.getId()); 825 comment.setId(responseID); 826 _fetcher.loadComment(blog, comment); 827 comment.setStatus(ResponseConstants.APPROVED_STATUS); 828 _fetcher.saveComment(blog, comment); 829 830 _eventBroadcaster.broadcastEvent(new CommentApprovedEvent(this, new Date (), comment, blog)); 831 832 if (_logger.isDebugEnabled()) { 833 _logger.debug("AJAX approve comment response complete: " + responseId); 834 } 835 } else if (Response.TRACKBACK_TYPE.equals(responseType)) { 836 Trackback trackback = _fetcher.newTrackback(); 837 trackback.setBlogId(blog.getId()); 838 trackback.setId(responseID); 839 _fetcher.loadTrackback(blog, trackback); 840 trackback.setStatus(ResponseConstants.APPROVED_STATUS); 841 _fetcher.saveTrackback(blog, trackback); 842 843 _eventBroadcaster.broadcastEvent(new TrackbackApprovedEvent(this, new Date (), trackback, blog)); 844 845 if (_logger.isDebugEnabled()) { 846 _logger.debug("AJAX approve trackback response complete: " + responseId); 847 } 848 } else if (Response.PINGBACK_TYPE.equals(responseType)) { 849 Pingback pingback = _fetcher.newPingback(); 850 pingback.setBlogId(blog.getId()); 851 pingback.setId(responseID); 852 _fetcher.loadPingback(blog, pingback); 853 pingback.setStatus(ResponseConstants.APPROVED_STATUS); 854 _fetcher.savePingback(blog, pingback); 855 856 _eventBroadcaster.broadcastEvent(new PingbackApprovedEvent(this, new Date (), pingback, blog)); 857 858 if (_logger.isDebugEnabled()) { 859 _logger.debug("AJAX approve pingback response complete: " + responseId); 860 } 861 } else { 862 if (_logger.isErrorEnabled()) { 863 _logger.error("Unknown response type for AJAX approve response: " + responseType); 864 } 865 } 866 867 context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS, BlojsomConstants.SUCCESS); 868 869 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADMIN_AJAX_RESPONSE); 870 } catch (FetcherException e) { 871 if (_logger.isErrorEnabled()) { 872 _logger.error(e); 873 } 874 875 context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS, BlojsomConstants.FAILURE); 876 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADMIN_AJAX_RESPONSE); 877 878 entries = new Entry[0]; 879 } 880 } else if (AJAX_UNAPPROVE_RESPONSE.equals(action)) { 881 if (_logger.isDebugEnabled()) { 882 _logger.debug("User requested AJAX unapprove response action"); 883 } 884 885 String responseId = BlojsomUtils.getRequestValue(RESPONSE_ID, httpServletRequest); 886 Integer responseID; 887 try { 888 responseID = Integer.valueOf(responseId); 889 } catch (NumberFormatException e) { 890 context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS, BlojsomConstants.FAILURE); 891 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADMIN_AJAX_RESPONSE); 892 893 return entries; 894 } 895 896 String responseType = BlojsomUtils.getRequestValue(RESPONSE_TYPE, httpServletRequest); 897 try { 898 if (Response.COMMENT_TYPE.equals(responseType)) { 899 Comment comment = _fetcher.newComment(); 900 comment.setBlogId(blog.getId()); 901 comment.setId(responseID); 902 _fetcher.loadComment(blog, comment); 903 comment.setStatus(ResponseConstants.NEW_STATUS); 904 _fetcher.saveComment(blog, comment); 905 906 _eventBroadcaster.broadcastEvent(new CommentUnapprovedEvent(this, new Date (), comment, blog)); 907 908 if (_logger.isDebugEnabled()) { 909 _logger.debug("AJAX unapprove comment response complete: " + responseId); 910 } 911 } else if (Response.TRACKBACK_TYPE.equals(responseType)) { 912 Trackback trackback = _fetcher.newTrackback(); 913 trackback.setBlogId(blog.getId()); 914 trackback.setId(responseID); 915 _fetcher.loadTrackback(blog, trackback); 916 trackback.setStatus(ResponseConstants.NEW_STATUS); 917 _fetcher.saveTrackback(blog, trackback); 918 919 _eventBroadcaster.broadcastEvent(new TrackbackUnapprovedEvent(this, new Date (), trackback, blog)); 920 921 if (_logger.isDebugEnabled()) { 922 _logger.debug("AJAX unapprove trackback response complete: " + responseId); 923 } 924 } else if (Response.PINGBACK_TYPE.equals(responseType)) { 925 Pingback pingback = _fetcher.newPingback(); 926 pingback.setBlogId(blog.getId()); 927 pingback.setId(responseID); 928 _fetcher.loadPingback(blog, pingback); 929 pingback.setStatus(ResponseConstants.NEW_STATUS); 930 _fetcher.savePingback(blog, pingback); 931 932 _eventBroadcaster.broadcastEvent(new PingbackUnapprovedEvent(this, new Date (), pingback, blog)); 933 934 if (_logger.isDebugEnabled()) { 935 _logger.debug("AJAX unapprove pingback response complete: " + responseId); 936 } 937 } else { 938 if (_logger.isErrorEnabled()) { 939 _logger.error("Unknown response type for AJAX unapprove response: " + responseType); 940 } 941 } 942 943 context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS, BlojsomConstants.SUCCESS); 944 945 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADMIN_AJAX_RESPONSE); 946 } catch (FetcherException e) { 947 if (_logger.isErrorEnabled()) { 948 _logger.error(e); 949 } 950 951 context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS, BlojsomConstants.FAILURE); 952 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADMIN_AJAX_RESPONSE); 953 954 entries = new Entry[0]; 955 } 956 } else if (AJAX_MARK_SPAM_RESPONSE.equals(action)) { 957 if (_logger.isDebugEnabled()) { 958 _logger.debug("User requested AJAX mark spam response action"); 959 } 960 961 String responseId = BlojsomUtils.getRequestValue(RESPONSE_ID, httpServletRequest); 962 Integer responseID; 963 try { 964 responseID = Integer.valueOf(responseId); 965 } catch (NumberFormatException e) { 966 context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS, BlojsomConstants.FAILURE); 967 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADMIN_AJAX_RESPONSE); 968 969 return entries; 970 } 971 972 String responseType = BlojsomUtils.getRequestValue(RESPONSE_TYPE, httpServletRequest); 973 try { 974 if (Response.COMMENT_TYPE.equals(responseType)) { 975 Comment comment = _fetcher.newComment(); 976 comment.setBlogId(blog.getId()); 977 comment.setId(responseID); 978 _fetcher.loadComment(blog, comment); 979 comment.setStatus(ResponseConstants.SPAM_STATUS); 980 _fetcher.saveComment(blog, comment); 981 982 _eventBroadcaster.broadcastEvent(new CommentMarkedSpamEvent(this, new Date (), comment, blog)); 983 984 if (_logger.isDebugEnabled()) { 985 _logger.debug("AJAX mark comment spam response complete: " + responseId); 986 } 987 } else if (Response.TRACKBACK_TYPE.equals(responseType)) { 988 Trackback trackback = _fetcher.newTrackback(); 989 trackback.setBlogId(blog.getId()); 990 trackback.setId(responseID); 991 _fetcher.loadTrackback(blog, trackback); 992 trackback.setStatus(ResponseConstants.SPAM_STATUS); 993 _fetcher.saveTrackback(blog, trackback); 994 995 _eventBroadcaster.broadcastEvent(new TrackbackMarkedSpamEvent(this, new Date (), trackback, blog)); 996 997 if (_logger.isDebugEnabled()) { 998 _logger.debug("AJAX mark trackback spam response complete: " + responseId); 999 } 1000 } else if (Response.PINGBACK_TYPE.equals(responseType)) { 1001 Pingback pingback = _fetcher.newPingback(); 1002 pingback.setBlogId(blog.getId()); 1003 pingback.setId(responseID); 1004 _fetcher.loadPingback(blog, pingback); 1005 pingback.setStatus(ResponseConstants.SPAM_STATUS); 1006 _fetcher.savePingback(blog, pingback); 1007 1008 _eventBroadcaster.broadcastEvent(new PingbackMarkedSpamEvent(this, new Date (), pingback, blog)); 1009 1010 if (_logger.isDebugEnabled()) { 1011 _logger.debug("AJAX mark pingback spam response complete: " + responseId); 1012 } 1013 } else { 1014 if (_logger.isErrorEnabled()) { 1015 _logger.error("Unknown response type for AJAX mark spam response: " + responseType); 1016 } 1017 } 1018 1019 context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS, BlojsomConstants.SUCCESS); 1020 1021 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADMIN_AJAX_RESPONSE); 1022 } catch (FetcherException e) { 1023 if (_logger.isErrorEnabled()) { 1024 _logger.error(e); 1025 } 1026 1027 context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS, BlojsomConstants.FAILURE); 1028 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADMIN_AJAX_RESPONSE); 1029 1030 entries = new Entry[0]; 1031 } 1032 } else if (AJAX_UNMARK_SPAM_RESPONSE.equals(action)) { 1033 if (_logger.isDebugEnabled()) { 1034 _logger.debug("User requested AJAX unmark spam response action"); 1035 } 1036 1037 String responseId = BlojsomUtils.getRequestValue(RESPONSE_ID, httpServletRequest); 1038 Integer responseID; 1039 try { 1040 responseID = Integer.valueOf(responseId); 1041 } catch (NumberFormatException e) { 1042 context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS, BlojsomConstants.FAILURE); 1043 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADMIN_AJAX_RESPONSE); 1044 1045 return entries; 1046 } 1047 1048 String responseType = BlojsomUtils.getRequestValue(RESPONSE_TYPE, httpServletRequest); 1049 try { 1050 if (Response.COMMENT_TYPE.equals(responseType)) { 1051 Comment comment = _fetcher.newComment(); 1052 comment.setBlogId(blog.getId()); 1053 comment.setId(responseID); 1054 _fetcher.loadComment(blog, comment); 1055 comment.setStatus(ResponseConstants.NEW_STATUS); 1056 _fetcher.saveComment(blog, comment); 1057 1058 _eventBroadcaster.broadcastEvent(new CommentUnmarkedSpamEvent(this, new Date (), comment, blog)); 1059 1060 if (_logger.isDebugEnabled()) { 1061 _logger.debug("AJAX unmark comment spam response complete: " + responseId); 1062 } 1063 } else if (Response.TRACKBACK_TYPE.equals(responseType)) { 1064 Trackback trackback = _fetcher.newTrackback(); 1065 trackback.setBlogId(blog.getId()); 1066 trackback.setId(responseID); 1067 _fetcher.loadTrackback(blog, trackback); 1068 trackback.setStatus(ResponseConstants.NEW_STATUS); 1069 _fetcher.saveTrackback(blog, trackback); 1070 1071 _eventBroadcaster.broadcastEvent(new TrackbackUnmarkedSpamEvent(this, new Date (), trackback, blog)); 1072 1073 if (_logger.isDebugEnabled()) { 1074 _logger.debug("AJAX unmark trackback spam response complete: " + responseId); 1075 } 1076 } else if (Response.PINGBACK_TYPE.equals(responseType)) { 1077 Pingback pingback = _fetcher.newPingback(); 1078 pingback.setBlogId(blog.getId()); 1079 pingback.setId(responseID); 1080 _fetcher.loadPingback(blog, pingback); 1081 pingback.setStatus(ResponseConstants.NEW_STATUS); 1082 _fetcher.savePingback(blog, pingback); 1083 1084 _eventBroadcaster.broadcastEvent(new PingbackUnmarkedSpamEvent(this, new Date (), pingback, blog)); 1085 1086 if (_logger.isDebugEnabled()) { 1087 _logger.debug("AJAX unmark pingback spam response complete: " + responseId); 1088 } 1089 } else { 1090 if (_logger.isErrorEnabled()) { 1091 _logger.error("Unknown response type for AJAX mark spam response: " + responseType); 1092 } 1093 } 1094 1095 context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS, BlojsomConstants.SUCCESS); 1096 1097 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADMIN_AJAX_RESPONSE); 1098 } catch (FetcherException e) { 1099 if (_logger.isErrorEnabled()) { 1100 _logger.error(e); 1101 } 1102 1103 context.put(BlojsomConstants.BLOJSOM_AJAX_STATUS, BlojsomConstants.FAILURE); 1104 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, ADMIN_AJAX_RESPONSE); 1105 1106 entries = new Entry[0]; 1107 } 1108 } else if (DELETE_BLOG_COMMENTS.equals(action)) { 1109 if (_logger.isDebugEnabled()) { 1110 _logger.debug("User requested delete comments action"); 1111 } 1112 1113 String blogEntryId = BlojsomUtils.getRequestValue(BLOG_ENTRY_ID, httpServletRequest); 1114 Integer entryId; 1115 try { 1116 entryId = Integer.valueOf(blogEntryId); 1117 } catch (NumberFormatException e) { 1118 addOperationResultMessage(context, formatAdminResource(FAILED_RETRIEVE_BLOG_ENTRY_KEY, FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog.getBlogAdministrationLocale(), new Object []{blogEntryId})); 1119 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, EDIT_BLOG_ENTRY_PAGE); 1120 1121 return entries; 1122 } 1123 1124 Entry entry; 1125 try { 1126 entry = _fetcher.loadEntry(blog, entryId); 1127 String [] blogCommentIDs = httpServletRequest.getParameterValues(BLOG_COMMENT_ID); 1128 1129 if (blogCommentIDs != null && blogCommentIDs.length > 0) { 1130 for (int i = 0; i < blogCommentIDs.length; i++) { 1131 String blogCommentID = blogCommentIDs[i]; 1132 Comment[] blogComments = entry.getCommentsAsArray(); 1133 for (int j = 0; j < blogComments.length; j++) { 1134 Comment blogComment = blogComments[j]; 1135 if (blogComment.getId().equals(Integer.valueOf(blogCommentID))) { 1136 try { 1137 _fetcher.deleteComment(blog, blogComment); 1138 1139 _eventBroadcaster.broadcastEvent(new CommentDeletedEvent(this, new Date (), blogComment, blog)); 1140 } catch (FetcherException e) { 1141 if (_logger.isErrorEnabled()) { 1142 _logger.error(e); 1143 } 1144 } 1145 } 1146 } 1147 } 1148 1149 addOperationResultMessage(context, formatAdminResource(DELETED_COMMENTS_KEY, DELETED_COMMENTS_KEY, blog.getBlogAdministrationLocale(), new Object [] {new Integer (blogCommentIDs.length)})); 1150 } 1151 1152 _fetcher.loadEntry(blog, entry); 1153 1154 context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_ENTRY, entry); 1155 } catch (FetcherException e) { 1156 if (_logger.isErrorEnabled()) { 1157 _logger.error(e); 1158 } 1159 1160 addOperationResultMessage(context, formatAdminResource(FAILED_RETRIEVE_BLOG_ENTRY_KEY, FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog.getBlogAdministrationLocale(), new Object []{blogEntryId})); 1161 entries = new Entry[0]; 1162 } 1163 1164 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, EDIT_BLOG_ENTRY_PAGE); 1165 } else if (APPROVE_BLOG_COMMENTS.equals(action)) { 1166 if (_logger.isDebugEnabled()) { 1167 _logger.debug("User requested approve comments action"); 1168 } 1169 1170 String blogEntryId = BlojsomUtils.getRequestValue(BLOG_ENTRY_ID, httpServletRequest); 1171 Integer entryId; 1172 try { 1173 entryId = Integer.valueOf(blogEntryId); 1174 } catch (NumberFormatException e) { 1175 addOperationResultMessage(context, formatAdminResource(FAILED_RETRIEVE_BLOG_ENTRY_KEY, FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog.getBlogAdministrationLocale(), new Object []{blogEntryId})); 1176 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, EDIT_BLOG_ENTRY_PAGE); 1177 1178 return entries; 1179 } 1180 1181 Entry entry; 1182 try { 1183 entry = _fetcher.loadEntry(blog, entryId); 1184 String [] blogCommentIDs = httpServletRequest.getParameterValues(BLOG_COMMENT_ID); 1185 1186 if (blogCommentIDs != null && blogCommentIDs.length > 0) { 1187 for (int i = 0; i < blogCommentIDs.length; i++) { 1188 String blogCommentID = blogCommentIDs[i]; 1189 Comment[] blogComments = entry.getCommentsAsArray(); 1190 for (int j = 0; j < blogComments.length; j++) { 1191 Comment blogComment = blogComments[j]; 1192 if (blogComment.getId().equals(Integer.valueOf(blogCommentID))) { 1193 try { 1194 blogComment.setStatus(ResponseConstants.APPROVED_STATUS); 1195 _fetcher.saveComment(blog, blogComment); 1196 1197 _eventBroadcaster.broadcastEvent(new CommentApprovedEvent(this, new Date (), blogComment, blog)); 1198 } catch (FetcherException e) { 1199 _logger.error(e); 1200 } 1201 } 1202 } 1203 } 1204 1205 addOperationResultMessage(context, formatAdminResource(APPROVED_COMMENTS_KEY, APPROVED_COMMENTS_KEY, blog.getBlogAdministrationLocale(), new Object [] {new Integer (blogCommentIDs.length)})); 1206 } 1207 1208 _fetcher.loadEntry(blog, entry); 1209 1210 context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_ENTRY, entry); 1211 } catch (FetcherException e) { 1212 if (_logger.isErrorEnabled()) { 1213 _logger.error(e); 1214 } 1215 1216 addOperationResultMessage(context, formatAdminResource(FAILED_RETRIEVE_BLOG_ENTRY_KEY, FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog.getBlogAdministrationLocale(), new Object []{blogEntryId})); 1217 entries = new Entry[0]; 1218 } 1219 1220 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, EDIT_BLOG_ENTRY_PAGE); 1221 } else if (DELETE_BLOG_TRACKBACKS.equals(action)) { 1222 if (_logger.isDebugEnabled()) { 1223 _logger.debug("User requested delete blog trackbacks action"); 1224 } 1225 1226 String blogEntryId = BlojsomUtils.getRequestValue(BLOG_ENTRY_ID, httpServletRequest); 1227 Integer entryId; 1228 try { 1229 entryId = Integer.valueOf(blogEntryId); 1230 } catch (NumberFormatException e) { 1231 addOperationResultMessage(context, formatAdminResource(FAILED_RETRIEVE_BLOG_ENTRY_KEY, FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog.getBlogAdministrationLocale(), new Object []{blogEntryId})); 1232 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, EDIT_BLOG_ENTRY_PAGE); 1233 1234 return entries; 1235 } 1236 1237 Entry entry; 1238 try { 1239 entry = _fetcher.loadEntry(blog, entryId); 1240 String [] blogTrackbackIDs = httpServletRequest.getParameterValues(BLOG_TRACKBACK_ID); 1241 1242 if (blogTrackbackIDs != null && blogTrackbackIDs.length > 0) { 1243 for (int i = 0; i < blogTrackbackIDs.length; i++) { 1244 String blogTrackbackID = blogTrackbackIDs[i]; 1245 Trackback[] trackbacks = entry.getTrackbacksAsArray(); 1246 for (int j = 0; j < trackbacks.length; j++) { 1247 Trackback trackback = trackbacks[j]; 1248 if (trackback.getId().equals(Integer.valueOf(blogTrackbackID))) { 1249 try { 1250 _fetcher.deleteTrackback(blog, trackback); 1251 1252 _eventBroadcaster.broadcastEvent(new TrackbackDeletedEvent(this, new Date (), trackback, blog)); 1253 } catch (FetcherException e) { 1254 if (_logger.isErrorEnabled()) { 1255 _logger.error(e); 1256 } 1257 } 1258 } 1259 } 1260 } 1261 1262 addOperationResultMessage(context, formatAdminResource(DELETED_TRACKBACKS_KEY, DELETED_TRACKBACKS_KEY, blog.getBlogAdministrationLocale(), new Object [] {new Integer (blogTrackbackIDs.length)})); 1263 } 1264 1265 _fetcher.loadEntry(blog, entry); 1266 1267 context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_ENTRY, entry); 1268 } catch (FetcherException e) { 1269 if (_logger.isErrorEnabled()) { 1270 _logger.error(e); 1271 } 1272 1273 addOperationResultMessage(context, formatAdminResource(FAILED_RETRIEVE_BLOG_ENTRY_KEY, FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog.getBlogAdministrationLocale(), new Object []{blogEntryId})); 1274 entries = new Entry[0]; 1275 } 1276 1277 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, EDIT_BLOG_ENTRY_PAGE); 1278 } else if (APPROVE_BLOG_TRACKBACKS.equals(action)) { 1279 if (_logger.isDebugEnabled()) { 1280 _logger.debug("User requested approve blog trackbacks action"); 1281 } 1282 1283 String blogEntryId = BlojsomUtils.getRequestValue(BLOG_ENTRY_ID, httpServletRequest); 1284 Integer entryId; 1285 try { 1286 entryId = Integer.valueOf(blogEntryId); 1287 } catch (NumberFormatException e) { 1288 addOperationResultMessage(context, formatAdminResource(FAILED_RETRIEVE_BLOG_ENTRY_KEY, FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog.getBlogAdministrationLocale(), new Object []{blogEntryId})); 1289 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, EDIT_BLOG_ENTRY_PAGE); 1290 1291 return entries; 1292 } 1293 1294 Entry entry; 1295 try { 1296 entry = _fetcher.loadEntry(blog, entryId); 1297 String [] blogTrackbackIDs = httpServletRequest.getParameterValues(BLOG_TRACKBACK_ID); 1298 1299 if (blogTrackbackIDs != null && blogTrackbackIDs.length > 0) { 1300 for (int i = 0; i < blogTrackbackIDs.length; i++) { 1301 String blogTrackbackID = blogTrackbackIDs[i]; 1302 Trackback[] trackbacks = entry.getTrackbacksAsArray(); 1303 for (int j = 0; j < trackbacks.length; j++) { 1304 Trackback trackback = trackbacks[j]; 1305 if (trackback.getId().equals(Integer.valueOf(blogTrackbackID))) { 1306 try { 1307 trackback.setStatus(ResponseConstants.APPROVED_STATUS); 1308 _fetcher.saveTrackback(blog, trackback); 1309 1310 _eventBroadcaster.broadcastEvent(new TrackbackApprovedEvent(this, new Date (), trackback, blog)); 1311 } catch (FetcherException e) { 1312 if (_logger.isErrorEnabled()) { 1313 _logger.error(e); 1314 } 1315 } 1316 } 1317 } 1318 } 1319 1320 addOperationResultMessage(context, formatAdminResource(APPROVED_TRACKBACKS_KEY, APPROVED_TRACKBACKS_KEY, blog.getBlogAdministrationLocale(), new Object [] {new Integer (blogTrackbackIDs.length)})); 1321 } 1322 1323 _fetcher.loadEntry(blog, entry); 1324 1325 context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_ENTRY, entry); 1326 } catch (FetcherException e) { 1327 if (_logger.isErrorEnabled()) { 1328 _logger.error(e); 1329 } 1330 1331 addOperationResultMessage(context, formatAdminResource(FAILED_RETRIEVE_BLOG_ENTRY_KEY, FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog.getBlogAdministrationLocale(), new Object []{blogEntryId})); 1332 entries = new Entry[0]; 1333 } 1334 1335 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, EDIT_BLOG_ENTRY_PAGE); 1336 } else if (DELETE_BLOG_PINGBACKS.equals(action)) { 1337 if (_logger.isDebugEnabled()) { 1338 _logger.debug("User requested delete blog pingbacks action"); 1339 } 1340 1341 String blogEntryId = BlojsomUtils.getRequestValue(BLOG_ENTRY_ID, httpServletRequest); 1342 Integer entryId; 1343 try { 1344 entryId = Integer.valueOf(blogEntryId); 1345 } catch (NumberFormatException e) { 1346 addOperationResultMessage(context, formatAdminResource(FAILED_RETRIEVE_BLOG_ENTRY_KEY, FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog.getBlogAdministrationLocale(), new Object []{blogEntryId})); 1347 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, EDIT_BLOG_ENTRY_PAGE); 1348 1349 return entries; 1350 } 1351 1352 Entry entry; 1353 try { 1354 entry = _fetcher.loadEntry(blog, entryId); 1355 String [] blogPingbackIDs = httpServletRequest.getParameterValues(BLOG_PINGBACK_ID); 1356 1357 if (blogPingbackIDs != null && blogPingbackIDs.length > 0) { 1358 for (int i = 0; i < blogPingbackIDs.length; i++) { 1359 String blogPingbackID = blogPingbackIDs[i]; 1360 Pingback[] pingbacks = entry.getPingbacksAsArray(); 1361 for (int j = 0; j < pingbacks.length; j++) { 1362 Pingback pingback = pingbacks[j]; 1363 if (pingback.getId().equals(Integer.valueOf(blogPingbackID))) { 1364 try { 1365 _fetcher.deletePingback(blog, pingback); 1366 1367 _eventBroadcaster.broadcastEvent(new PingbackDeletedEvent(this, new Date (), pingback, blog)); 1368 } catch (FetcherException e) { 1369 if (_logger.isErrorEnabled()) { 1370 _logger.error(e); 1371 } 1372 } 1373 } 1374 } 1375 } 1376 1377 addOperationResultMessage(context, formatAdminResource(DELETED_PINGBACKS_KEY, DELETED_PINGBACKS_KEY, blog.getBlogAdministrationLocale(), new Object [] {new Integer (blogPingbackIDs.length)})); 1378 } 1379 1380 _fetcher.loadEntry(blog, entry); 1381 1382 context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_ENTRY, entry); 1383 } catch (FetcherException e) { 1384 if (_logger.isErrorEnabled()) { 1385 _logger.error(e); 1386 } 1387 1388 addOperationResultMessage(context, formatAdminResource(FAILED_RETRIEVE_BLOG_ENTRY_KEY, FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog.getBlogAdministrationLocale(), new Object []{blogEntryId})); 1389 entries = new Entry[0]; 1390 } 1391 1392 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, EDIT_BLOG_ENTRY_PAGE); 1393 } else if (APPROVE_BLOG_PINGBACKS.equals(action)) { 1394 if (_logger.isDebugEnabled()) { 1395 _logger.debug("User requested approve blog pingbacks action"); 1396 } 1397 1398 String blogEntryId = BlojsomUtils.getRequestValue(BLOG_ENTRY_ID, httpServletRequest); 1399 Integer entryId; 1400 try { 1401 entryId = Integer.valueOf(blogEntryId); 1402 } catch (NumberFormatException e) { 1403 1404 addOperationResultMessage(context, formatAdminResource(FAILED_RETRIEVE_BLOG_ENTRY_KEY, FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog.getBlogAdministrationLocale(), new Object []{blogEntryId})); 1405 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, EDIT_BLOG_ENTRY_PAGE); 1406 1407 return entries; 1408 } 1409 1410 Entry entry; 1411 try { 1412 entry = _fetcher.loadEntry(blog, entryId); 1413 String [] blogPingbackIDs = httpServletRequest.getParameterValues(BLOG_PINGBACK_ID); 1414 1415 if (blogPingbackIDs != null && blogPingbackIDs.length > 0) { 1416 for (int i = 0; i < blogPingbackIDs.length; i++) { 1417 String blogPingbackID = blogPingbackIDs[i]; 1418 Pingback[] pingbacks = entry.getPingbacksAsArray(); 1419 for (int j = 0; j < pingbacks.length; j++) { 1420 Pingback pingback = pingbacks[j]; 1421 if (pingback.getId().equals(Integer.valueOf(blogPingbackID))) { 1422 try { 1423 pingback.setStatus(ResponseConstants.APPROVED_STATUS); 1424 _fetcher.savePingback(blog, pingback); 1425 1426 _eventBroadcaster.broadcastEvent(new PingbackApprovedEvent(this, new Date (), pingback, blog)); 1427 } catch (FetcherException e) { 1428 if (_logger.isErrorEnabled()) { 1429 _logger.error(e); 1430 } 1431 } 1432 } 1433 } 1434 } 1435 1436 addOperationResultMessage(context, formatAdminResource(APPROVED_PINGBACKS_KEY, APPROVED_PINGBACKS_KEY, blog.getBlogAdministrationLocale(), new Object [] {new Integer (blogPingbackIDs.length)})); 1437 } 1438 1439 _fetcher.loadEntry(blog, entry); 1440 1441 context.put(BLOJSOM_PLUGIN_EDIT_BLOG_ENTRIES_ENTRY, entry); 1442 } catch (FetcherException e) { 1443 if (_logger.isErrorEnabled()) { 1444 _logger.error(e); 1445 } 1446 1447 addOperationResultMessage(context, formatAdminResource(FAILED_RETRIEVE_BLOG_ENTRY_KEY, FAILED_RETRIEVE_BLOG_ENTRY_KEY, blog.getBlogAdministrationLocale(), new Object []{blogEntryId})); 1448 entries = new Entry[0]; 1449 } 1450 1451 httpServletRequest.setAttribute(BlojsomConstants.PAGE_PARAM, EDIT_BLOG_ENTRY_PAGE); 1452 } 1453 1454 return entries; 1455 } 1456 1457 1464 protected void sendTrackbackPings(Blog blog, Entry entry, String blogTrackbackURLs) { 1465 StringBuffer trackbackPingURLParameters = new StringBuffer (); 1467 try { 1468 StringBuffer entryLink = new StringBuffer (blog.getBlogURL()).append(entry.getBlogCategory().getName()).append(entry.getPostSlug()); 1469 trackbackPingURLParameters.append("&").append(TrackbackPlugin.TRACKBACK_URL_PARAM).append("=").append(entryLink); 1470 trackbackPingURLParameters.append("&").append(TrackbackPlugin.TRACKBACK_TITLE_PARAM).append("=").append(URLEncoder.encode(entry.getTitle(), BlojsomConstants.UTF8)); 1471 trackbackPingURLParameters.append("&").append(TrackbackPlugin.TRACKBACK_BLOG_NAME_PARAM).append("=").append(URLEncoder.encode(blog.getBlogName(), BlojsomConstants.UTF8)); 1472 1473 String excerpt = entry.getDescription().replaceAll("<.*?>", ""); 1474 if (excerpt.length() > 255) { 1475 excerpt = excerpt.substring(0, 251); 1476 excerpt += "..."; 1477 } 1478 trackbackPingURLParameters.append("&").append(TrackbackPlugin.TRACKBACK_EXCERPT_PARAM).append("=").append(URLEncoder.encode(excerpt, BlojsomConstants.UTF8)); 1479 } catch (UnsupportedEncodingException e) { 1480 if (_logger.isErrorEnabled()) { 1481 _logger.error(e); 1482 } 1483 } 1484 1485 String [] trackbackURLs = BlojsomUtils.parseDelimitedList(blogTrackbackURLs, BlojsomConstants.WHITESPACE); 1486 if (trackbackURLs != null && trackbackURLs.length > 0) { 1487 for (int i = 0; i < trackbackURLs.length; i++) { 1488 String trackbackURL = trackbackURLs[i].trim(); 1489 StringBuffer trackbackPingURL = new StringBuffer (trackbackURL); 1490 1491 if (_logger.isDebugEnabled()) { 1492 _logger.debug("Automatically sending trackback ping to URL: " + trackbackPingURL.toString()); 1493 } 1494 1495 try { 1496 URL trackbackUrl = new URL (trackbackPingURL.toString()); 1497 1498 HttpURLConnection trackbackUrlConnection = (HttpURLConnection ) trackbackUrl.openConnection(); 1500 trackbackUrlConnection.setRequestMethod("POST"); 1501 trackbackUrlConnection.setRequestProperty("Content-Encoding", BlojsomConstants.UTF8); 1502 trackbackUrlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); 1503 trackbackUrlConnection.setRequestProperty("Content-Length", "" + trackbackPingURLParameters.length()); 1504 trackbackUrlConnection.setDoOutput(true); 1505 trackbackUrlConnection.getOutputStream().write(trackbackPingURLParameters.toString().getBytes(BlojsomConstants.UTF8)); 1506 trackbackUrlConnection.connect(); 1507 BufferedReader trackbackStatus = new BufferedReader (new InputStreamReader (trackbackUrlConnection.getInputStream())); 1508 String line; 1509 StringBuffer status = new StringBuffer (); 1510 while ((line = trackbackStatus.readLine()) != null) { 1511 status.append(line).append("\n"); 1512 } 1513 trackbackUrlConnection.disconnect(); 1514 1515 if (_logger.isDebugEnabled()) { 1516 _logger.debug("Trackback status for ping to " + trackbackURL + ": " + status.toString()); 1517 } 1518 } catch (IOException e) { 1519 if (_logger.isErrorEnabled()) { 1520 _logger.error(e); 1521 } 1522 } 1523 } 1524 } 1525 } 1526} 1527 | Popular Tags |